help-search.js 1.48 KB
/**
 * [帮助中心 搜索]
 * @author: wsl(shuiling.wang@yoho.cn)
 * @date: 2016/12/02
 */
var helpSearch = {
    $search: $('.help-search'),
    init: function() {
        var _this = this;
        var $helpSearchForm = $('#help-search-form');
        var $searchBtn = $('.search-btn');

        _this.searchDefaultVal();

        $searchBtn.click(function() {
            if (_this.$search.val() === '请输入您想知道的帮助信息') {
                _this.$search.val('');
            }
            $helpSearchForm.submit();
        });

        _this.$search.keyup(function(e) {
            var key = $(this).val();

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

            if (e.which === 13) {
                if (key) {
                    $helpSearchForm.submit();
                }
            }
        });
    },
    searchDefaultVal: function() {
        var _this = this;
        var defaultVal = '请输入您想知道的帮助信息';

        _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(defaultVal).css('color', '#989898');
    }
};

module.exports = helpSearch;