search.js
3.66 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
116
117
118
119
120
121
122
123
var $=require("jquery");
require("jquery.autocomplete");
var box=require('yoho-box');
if ($("#search-content").find(".content-item").length==0) {
var clientHeight=document.body.clientHeight;
$("#search-content").height(clientHeight-704);
}
$("#search-button-search").click(function(){
var input=$("#input-search-search");
if($.trim(input.val())=="")
{
box.alert("请输入搜索内容后继续");
}
else if (input.val().length>150) {
box.alert("搜索内容超长,最多150个字");
}
else
{
window.location.href=YohoConfig.mainUrl+"/search?q="+input.val();
}
});
$("#input-search-search").autocomplete('/search/default/words', {
resultsClass: "search-suggest helveticaneue",
loadingClass:"loading",
width:249,
scrollHeight:360,
max:10,
selectFirst:false,
autoFill:false,
formatResult: function(row, data)
{
return data.replace(/<\/?[^>]*>/g,'');
}
}).result(function(event, data, formatted)
{
if (data.length>150) {
box.alert("搜索内容超长,最多150个字");
}
else
{
window.location.href = YohoConfig.mainUrl+'./search?q=' + encodeURIComponent(formatted.replace(/<\/?[^>]*>/g,''));
}
// window.location.href =YohoConfig.mainUrl+"/search?q="+encodeURIComponent(formatted.replace(/<\/?[^>]*>/g,''));
})
.keydown(function(event){
if(event.keyCode==13)
{
$("#search-button-search").trigger("click");
}
});
//首页碎片交互=================================================================================================
function dealItems() {
var citems = $(".content-item,.content-item-without-border");
if (!citems.length) {
return;
}
var totalLineNum = 7;
// 7 行
var maxTitleStrNum = 45;
// 15个字
var maxDetailStrNum = 24;
// 22个字
if (document.body.clientWidth < 1190) {
totalLineNum = 6;
// 6 行
maxTitleStrNum = 39;
// 13个字
maxDetailStrNum = 54;
// 18个字
}
var titleLineNum = 0;
var subTitleLineNum = 0;
var detailLineNum = 0;
var detailStr = "";
var self = null;
citems.each(function() {
self = $(this);
var itemTitleObj= self.find(".content-item-title");
// 主标题行数
if(typeof(itemTitleObj.attr("_title"))==="undefined"||itemTitleObj.attr("_title")===null)
return;
titleLineNum = 1;
if (maxTitleStrNum < itemTitleObj.attr("_title").length) {
titleLineNum = 2;
}
// 副标题行数
subTitleLineNum = 1;
if (maxTitleStrNum < $(".content-item-subtitle").attr("_title").length) {
subTitleLineNum = 2;
}
// 摘要内容行数
detailLineNum = totalLineNum - titleLineNum - subTitleLineNum;
if(itemTitleObj.text()=="sports"){
console.log((maxDetailStrNum * detailLineNum) );
}
if ((maxDetailStrNum * detailLineNum) < self.find(".content-item-detail").attr("_title").length) {
detailStr = self.find(".content-item-detail").attr("_title").substring(0, maxDetailStrNum * detailLineNum ) + " ...";
self.find(".content-item-detail").text(detailStr.replace(/[a-zA-Z]+?\s{1}\.\.\.\$/, " ..."));
}
else
{
self.find(".content-item-detail").text(self.find(".content-item-detail").attr("_title"));
}
});
citems = null;
}
dealItems();
//=============================================================