write-search.js 1.69 KB
/**
 * 将搜索结果存localStorage
 * @author: xuqi<qi.xu@yoho.cn>
 * @date: 2015/10/29
 */

var ranToken = ' ??++ ';
var $ = require('jquery');

//获取分隔符
function getRanToken() {
    return ranToken;
}

//绑定提交前的存local操作
function bindWirteLocal($brandList) {
    $brandList.on('click','p', function(e) {

        e.preventDefault();

        var brandName = $(this).find('a').html();
        var query = brandName,
            historys;

        if (localStorage) {
            historys = localStorage.getItem('historys-brands');



            historys = historys ? historys : '';

            if (historys.indexOf(ranToken + query + ranToken) > -1) {
                return;
            }

            if (historys === '') {
                query = ranToken + query;
            }

            historys += query + ranToken;

            localStorage.setItem('historys-brands', historys);
        }
        //location.herf($(this).find('a').herf.tostring());
    });
}

//本地存储点击前的标签
function storeLocal($brandName,$brandUrl) {

    var query = $brandName,
        historys;
    //var brandName = $brandName;
    //var brandUrl = $brandUrl;
    //var query;

    if (localStorage) {
        historys = localStorage.getItem('historys-brand');

        historys = historys ? historys : '';

        if (historys.indexOf(ranToken + query + ranToken) > -1) {
            return;
        }

        if (historys === '') {
            query = ranToken + query;
        }


        historys += query + ranToken;

        localStorage.setItem('historys-brand', historys);
    }
}

exports.getRanToken = getRanToken;

exports.bindWirteLocal = bindWirteLocal;

exports.storeLocal = storeLocal;