top_search.js 1.87 KB
/**
 * @description top_seatch on diligrp-website
 *
 * @author <a href="mailto:akhuting@hotmail.com">Alex Yang</a>
 * @date 2014年06月24日 17:29
 */
$(function () {
    $(".sear-li").bind("click", function () {
        var i = $(this).text();
        var s = $(".sear-d").text();
        var t = $(this).attr("data-searchtype");
        var k = $(".sear-d").attr("data-searchtype");
        $(".sear-d").text(i).attr("data-searchtype", t);
        $(".sear-li").text(s).attr("data-searchtype", k);
        $(".sea-tab-ul2").hide();
    });// 搜索下拉+点击切换文字
    $("#autocomplete").attr("placeholder", search.keywords[(Math.ceil(Math.random() * 2) - 1)]);

    // 搜索框智能提示
    $('#autocomplete').autocomplete({
        serviceUrl: DiliPath.homePath + "tip.html",
        paramName: "key",
        dataType: "jsonp",
        appendTo: ".mo-fn2 span.sp5",
        triggerSelectOnValidInput: false,
        onSelect: function (suggestion) {
            search.topSearch();
        }
    });

    $("#autocomplete").keypress(function (event) {
        if (event.which == 13) {
            search.topSearch();
        }
    });

    $("#search").click(function () {
        search.topSearch();
    });

});

var search = {
    // top search function
    topSearch: function () {
        var keyword = $("#autocomplete").val();
        keyword = $.trim(keyword);
        keyword = encodeURIComponent(keyword);
        if (jQuery.trim(keyword) == "") {
            var def = $("#autocomplete").attr("placeholder");
            keyword = def.substring(2, def.indexOf("”"));
        }
        var searchtype = $(".sear-d").attr("data-searchtype");
        window.location.href = DiliPath.homePath + "search.html?" + searchtype
            + "=&key=" + keyword;
    },
    keywords: ["搜“黄瓜”试试,大黄瓜小黄瓜应有尽有", "搜“四川”试试,保证多快好省"]
};