top_search.js
3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/**
* @description top_seatch on diligrp-website
*
* @author <a href="mailto:akhuting@hotmail.com">Alex Yang</a>
* @date 2014年06月24日 17:29
*/
$(function () {
$(".sea-tab").hover(
function () {
$(".sea-tab b").addClass("hover");
$(this).children(".sea-tab-ul2").show();
},
function () {
$(".sea-tab b").removeClass("hover");
$(this).children(".sea-tab-ul2").hide();
}
);
var timer, sear_trigger, _objInput = $("#sear-input");
$(".inputbox").hover(function () {
_objInput.click(function () {
var _this = $(this);
sear_trigger = setTimeout(function () {
_this.val('');
//$('.g-sear-listbox').addClass("listboxhide");
$('.g-sear-listbox').removeClass("listboxhide").children('ul.sear-goods').show();
$('.g-sear-listbox').children('ul.sear-history').hide();
}, 200);
timer = setInterval('indexSearchTs(_objInput)', 200);
});
}, function () {
clearTimeout(sear_trigger);
clearInterval(timer);
$('.g-sear-listbox').addClass("listboxhide");
var sear_data = $("#sear-input").val();
if (sear_data != '' && sear_data != tipsname) {
$.noop();
} else {
_objInput.val(tipsname);
}
});
$(".sear-li").bind("click", function () {
var i = $(this).text();
var s = $(".sear-d").text();
var t = $(this).attr("data-searchtype");
var k = $(".sear-d").attr("data-searchtype");
$(".sear-d").text(i).attr("data-searchtype", t);
$(".sear-li").text(s).attr("data-searchtype", k);
$(".sea-tab-ul2").hide();
});// 搜索下拉+点击切换文字
$("#autocomplete").attr("placeholder", search.keywords[(Math.ceil(Math.random() * 2) - 1)]);
$("#autocomplete").attr("maxLength",50);
// 搜索框智能提示
$('#autocomplete').autocomplete({
serviceUrl: DiliPath.homePath + "tip.html",
paramName: "key",
dataType: "jsonp",
appendTo: ".mo-fn2 span.sp5",
triggerSelectOnValidInput: false,
extraParams : function(){
var self = this;
var searchtype = $(".sear-d").attr("data-searchtype");
var type = searchtype == 'goods'?'STG' : 'STORE';
self.params['type'] = type;
},
onSelect: function (suggestion) {
search.topSearch();
}
});
$("#autocomplete").keypress(function (event) {
if (event.which == 13) {
search.topSearch();
}
});
$("#search").click(function () {
search.topSearch();
});
});
var tipsname = '请输入商品关键字';
function indexSearchTs() {
var inputData = $("#sear-input").val();
if (inputData != '' && inputData != tipsname) {
$('.g-sear-listbox').removeClass("listboxhide");
$('.g-sear-listbox .sear-goods').hide();
$('.g-sear-listbox .sear-history').show();
}
};
var search = {
// top search function
topSearch: function () {
var keyword = $("#autocomplete").val();
keyword = $.trim(keyword);
keyword = encodeURIComponent(keyword);
if (jQuery.trim(keyword) == "") {
var def = $("#autocomplete").attr("placeholder");
keyword = def.substring(2, def.indexOf("”"));
}
var searchtype = $(".sear-d").attr("data-searchtype");
window.location.href = DiliPath.homePath + "search.html?" + searchtype
+ "=&key=" + keyword;
},
keywords: ["搜“黄瓜”试试,大黄瓜小黄瓜应有尽有", "搜“四川”试试,保证多快好省"]
};