Blame view

public/js/help/help-search.js 2.29 KB
王水玲 authored
1 2 3 4 5
/**
 * [帮助中心 搜索]
 * @author: wsl(shuiling.wang@yoho.cn)
 * @date: 2016/12/02
 */
王水玲 authored
6 7
var yas = require('../common/data-yas');
王水玲 authored
8 9 10 11 12 13 14 15 16 17
var helpSearch = {
    $search: $('.help-search'),
    init: function() {
        var _this = this;
        var $helpSearchForm = $('#help-search-form');
        var $searchBtn = $('.search-btn');

        _this.searchDefaultVal();

        $searchBtn.click(function() {
王水玲 authored
18 19 20
            var key = _this.$search.val();

            if (key === '请输入您想知道的帮助信息') {
王水玲 authored
21 22
                _this.$search.val('');
            }
王水玲 authored
23 24

            _this.searchYas(key);
王水玲 authored
25 26 27 28
            $helpSearchForm.submit();
        });

        _this.$search.keyup(function(e) {
周少峰 authored
29
王水玲 authored
30 31 32 33 34 35 36 37
            var key = $(this).val();

            if (key === '请输入您想知道的帮助信息') {
                $(this).val('');
            }

            if (e.which === 13) {
                if (key) {
王水玲 authored
38
                    _this.searchYas(key);
周少峰 authored
39
                    $helpSearchForm.submit();
王水玲 authored
40 41 42
                }
            }
        });
王水玲 authored
43 44 45

        // 热搜词埋点
        $('.search-box .keyword a').on('click', function() {
46
            yas.yasEvent('YB_HELP_SEARCH_C', {
王水玲 authored
47 48 49
                POS_ID: 2,
                POS_NM: '热搜词 ',
                KEYWORD: $(this).html()
50
            }, false);
王水玲 authored
51 52 53
        });
    },
    searchYas: function(keyword) { // 搜索框埋点
54
        yas.yasEvent('YB_HELP_SEARCH_C', {
王水玲 authored
55 56 57
            POS_ID: 1,
            POS_NM: '搜索框',
            KEYWORD: keyword
58
        }, false);
王水玲 authored
59 60 61 62
    },
    searchDefaultVal: function() {
        var _this = this;
        var defaultVal = '请输入您想知道的帮助信息';
王水玲 authored
63 64 65 66 67 68 69
        var startVal = defaultVal;
        var defaultColor = '#989898';

        if (_this.$search.val()) {
            startVal = _this.$search.val();
            defaultColor = '#1b1b1b';
        }
王水玲 authored
70 71 72 73 74 75 76 77 78 79 80 81 82

        _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');
            }
王水玲 authored
83
        }).val(startVal).css('color', defaultColor);
王水玲 authored
84 85 86 87
    }
};

module.exports = helpSearch;