help-search.js
2.29 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
/**
* [帮助中心 搜索]
* @author: wsl(shuiling.wang@yoho.cn)
* @date: 2016/12/02
*/
var yas = require('../common/data-yas');
var helpSearch = {
$search: $('.help-search'),
init: function() {
var _this = this;
var $helpSearchForm = $('#help-search-form');
var $searchBtn = $('.search-btn');
_this.searchDefaultVal();
$searchBtn.click(function() {
var key = _this.$search.val();
if (key === '请输入您想知道的帮助信息') {
_this.$search.val('');
}
_this.searchYas(key);
$helpSearchForm.submit();
});
_this.$search.keyup(function(e) {
var key = $(this).val();
if (key === '请输入您想知道的帮助信息') {
$(this).val('');
}
if (e.which === 13) {
if (key) {
_this.searchYas(key);
$helpSearchForm.submit();
}
}
});
// 热搜词埋点
$('.search-box .keyword a').on('click', function() {
yas.yasEvent('YB_HELP_SEARCH_C', {
POS_ID: 2,
POS_NM: '热搜词 ',
KEYWORD: $(this).html()
}, false);
});
},
searchYas: function(keyword) { // 搜索框埋点
yas.yasEvent('YB_HELP_SEARCH_C', {
POS_ID: 1,
POS_NM: '搜索框',
KEYWORD: keyword
}, false);
},
searchDefaultVal: function() {
var _this = this;
var defaultVal = '请输入您想知道的帮助信息';
var startVal = defaultVal;
var defaultColor = '#989898';
if (_this.$search.val()) {
startVal = _this.$search.val();
defaultColor = '#1b1b1b';
}
_this.$search.focus(function() {
var key = _this.$search.val();
if (key === defaultVal) {
_this.$search.val('').css('color', '#1b1b1b');
}
}).blur(function() {
var key = _this.$search.val();
if ($.trim(key) === '') {
_this.$search.val(defaultVal).css('color', '#989898');
}
}).val(startVal).css('color', defaultColor);
}
};
module.exports = helpSearch;