PageSourceSearch

https://www.geexek.com/resources/common/js/search.js

js geexek.com collected 2026-10-02 18:48:37 UTC 6,602 bytes, 205 lines download raw bytes

1$(document).ready(function () {
2	//检索框获取焦点后显示搜索遮罩,并且获取热门搜索,显示历史记录
3	$("#pageHeadLeftSearch-input").focus(function (e) {
4		pcgetHotKeyword();
5		pcshowHistoryItemView();
6	});
7	$("#pageHeadLeftSearch-input").blur(function () {
8		setTimeout(function () {
9			$("#pc-searchMask").hide();
10		}, 1000);
11	});
12	$("#pageHeadLeftSearch-input").unbind("keydown").keydown(function (e) { //按下enter键
13		if (e.keyCode == 13) {
14			var value = $.trim($("#pageHeadLeftSearch-input").val());
15			if (value == "") { return; }
16			pcsetHistoryItems(value);
17			pcsearch(value);
18		}
19	});
20	$("#search-input").unbind("keydown").keydown(function (e) { //按下enter键
21		if (e.keyCode == 13) {
22			var value = $.trim($("#search-input").val());
23			if (value == "") { return; }
24			pcsetHistoryItems(value);
25			$('#left-right-div').trigger('click');
26		}
27	});
28	//搜索
29	$(".pageHeadLeftSearch-btn").unbind("click").click(function (e) {
30		var value = $.trim($("#pageHeadLeftSearch-input").val());
31		pcsetHistoryItems(value);
32		pcsearch(value);
33	});
34
35	$("#pc-searchMask").unbind("click").on("click", ".pc-hot_search span", function (e) {
36		var value = $(this).text();
37		$("#pageHeadLeftSearch-input").val(value);
38		pcsearch(value);
39	});
40
41	$("#pc-searchMask").unbind("click").on("click", ".pc-history_search_list li", function (e) {
42		var value = $(this).children(".pc-history_name").text();
43		$("#pageHeadLeftSearch-input").val(value);
44		pcsearch(value);
45	});
46
47	//清除所有的历史记录
48	$('#pc-clearHistoryList').click(function (e) {
49		window.localStorage.removeItem("history");
50		$(".pc-history_search_list ul").empty();
51	});
52	//清除单个历史记录
53	$("#pc-searchMask").on("click", ".pc-history_delete", function (e) {
54		e.stopPropagation();
55		var id = parseInt($(this).parents("li").attr("id"));
56		var history = window.localStorage.getItem("history");
57		var array = history.split(",");
58		var len = array.length;
59		var newArray = new Array();
60		if (id == 0) { //第一个
61			if (len > 1) {
62				newArray.push(array.slice(1));
63			}
64		} else if (id == len - 1) {//最后一个
65			newArray.push(array.slice(0, len - 1));
66		} else { //中间值
67			if (id == len - 2) { //倒数第二个
68				newArray.push(array.slice(0, id));
69				newArray.push(array[len - 1]);
70			} else {
71				var test1 = array.splice(id + 1, len - 1 - id);
72				var test2 = array.slice(id + 1, len); //获取到的值全部是空数组,why?
73				var dss = id + 1;
74				var test3 = array.slice(id + 1);
75
76				newArray.push(array.slice(0, id));
77				newArray.push(test1);
78			}
79
80		}
81		if (newArray.length > 0) {
82			window.localStorage.setItem("history", newArray.join(','));
83		} else {
84			window.localStorage.removeItem("history");
85		}
86
87		pcshowHistoryItemView();
88	});
89
90
91});
92
93/**设置历史记录**/
94function pcsetHistoryItems(value) {
95	//var value = $.trim($("#pageHeadLeftSearch-input").val());
96	/*$("#pageHeadLeftSearch-input").val("");*/
97	var history = window.localStorage.getItem("history");
98	if (history == null) {
99		window.localStorage.setItem("history", value);
100	} else {
101		var array = history.split(",");
102		var flag = true;
103		for (var i = 0; i < array.length; i++) {
104			var item = array[i];
105			if (value == item) {
106				flag = false;
107				break;
108			}
109		}
110		if (flag) {
111			if (array.length >= 6) {//最多保存6个历史记录
112				array = array.slice(0, 5);
113				var newArray = new Array();
114				newArray.push(value);
115				newArray.push(array);
116				window.localStorage.setItem("history", newArray.join(','));
117			} else {
118				var historyItems = value + ',' + array.join(',');
119				window.localStorage.setItem("history", historyItems);
120			}
121		}
122	}
123}
124
125function pcshowHistoryItemView() {
126	$("#pc-searchMask").show();
127	//显示历史记录
128	$(".pc-history_search_list ul").empty();
129	var history = window.localStorage.getItem("history");
130	if (history != null) {
131		var array = history.split(",");
132		for (var i = 0, len = array.length; i < len; i++) {
133			var _hisItem;
134			if (array[i].length > 18) {
135				_hisItem = array[i].substring(0, 17) + '...';
136			} else {
137				_hisItem = array[i];
138			}
139			var str = '<li id="' + i + '" class="pageClearfix"> <span class="pc-history_name">' + _hisItem
140				+ '</span> <span class="pc-history_delete"></span></li>';
141			$(".pc-history_search_list ul").append(str);
142		}
143	}
144}
145
146function pcgetHotKeyword() {
147	$(".pc-hot_search").empty();
148	$.ajax({
149		type: 'get',
150		url: baseURL + 'search/getHotKeyword',
151		data: { order: 1 },
152		dataType: 'json',
153		success: function (data) {
154			if (data.code == 1) {
155				var keywords = data.result;
156				if (keywords.length <= 0) {
157					$(".pc-search_mask_div").eq(0).hide();
158					return;
159				} else {
160					$(".pc-search_mask_div").eq(0).show();
161					$(".pc-hot_search").empty();
162					$.each(keywords, function (index, e) {
163						$(".pc-hot_search").append('<span>' + e + '</span>');
164					});
165				}
166			} else {
167				$(".pc-search_mask_div").eq(0).hide();
168			}
169		}
170	});
171}
172function pcsearch(keyword) {
173	$.ajax({
174		type: 'get', url: baseURL + 'search/saveKeyword', data: { keyword: keyword }, dataType: 'json',
175	});
176	$("#pc-searchMask").hide();
177	//跳转到全局搜索页
178	var Names = location.href.split("/");
179	var indexName = Names[Names.length - 1];
180	var index = indexName.indexOf("indexSearch");
181	var index_cmpt = indexName.indexOf("cmpt");
182	var cmpf = indexName.length > "cmpt".length ? false : true;
183	var index_live = indexName.indexOf("live");
184	var livf = indexName.length > "live".length ? false : true;
185	var index_score = indexName.indexOf("score");
186	var scof = indexName.length > "score".length ? false : true;
187	var index_topic = indexName.indexOf("topic");
188	var topf = indexName.length > "topic".length ? false : true;
189	var index_article = indexName.indexOf("article");
190	var artf = indexName.length > "article".length ? false : true;
191	var index_search = indexName.indexOf("search");
192	var index_geexekApp = indexName.indexOf("geexekApp");
193	if ((index_cmpt > -1 && cmpf) || (index_live > -1 && livf) || (index_topic > -1 && topf) ||
194		(index_article > -1 && artf) || (index_score > -1 && scof) || index_search > -1 || index_geexekApp > -1) {
195		_search.searchByType(keyword);
196	} else {
197		if (keyword == '' || keyword == null || keyword == undefined) {
198			alert("搜索的值不能为空!!");
199			return;
200		}
201		var href = baseURL + "search/indexSearch.html?keyword=" + encodeURIComponent(keyword);
202		window.location.href = href;
203	}
204}
205

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.