...
|
...
|
@@ -10,18 +10,20 @@ var $input = $('#search-input input'); |
|
|
|
|
|
var $clear = $('#search-input .clear-input');
|
|
|
|
|
|
var $form = $('#search-form');
|
|
|
|
|
|
var $history = $('.history');
|
|
|
|
|
|
$('#clear-history').bind('tap', function() {
|
|
|
$.ajax({
|
|
|
type: 'POST',
|
|
|
url: '/search/clearHistory',
|
|
|
success: function(data) {
|
|
|
if (data.code === 200) {
|
|
|
$history.html(''); //clear search history items
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
var $clearHistory = $('#clear-history');
|
|
|
|
|
|
var writeSearch = require('./write-search');
|
|
|
|
|
|
var ranToken = writeSearch.getRanToken();
|
|
|
|
|
|
$clearHistory.bind('tap', function() {
|
|
|
localStorage.removeItem('historys');
|
|
|
|
|
|
$history.html('');
|
|
|
});
|
|
|
|
|
|
$input.bind('input', function() {
|
...
|
...
|
@@ -34,4 +36,33 @@ $input.bind('input', function() { |
|
|
|
|
|
$clear.bind('tap', function() {
|
|
|
$input.val('').trigger('input');
|
|
|
}); |
|
|
\ No newline at end of file |
|
|
});
|
|
|
|
|
|
//初始化历史搜索的内容
|
|
|
(function() {
|
|
|
var html = '',
|
|
|
history,
|
|
|
historys, i;
|
|
|
|
|
|
if (localStorage) {
|
|
|
historys = localStorage.getItem('historys');
|
|
|
|
|
|
if (historys && historys.length > 0) {
|
|
|
historys = historys.split(ranToken);
|
|
|
for (i = 0; i < historys.length; i++) {
|
|
|
history = historys[i];
|
|
|
|
|
|
if (history === '') {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
html += '<li><a href="?query=' + history + '">' + history + '</li>';
|
|
|
}
|
|
|
|
|
|
$history.html(html);
|
|
|
$clearHistory.removeClass('hide');
|
|
|
}
|
|
|
}
|
|
|
}());
|
|
|
|
|
|
writeSearch.bindWirteLocal($form); |
|
|
\ No newline at end of file |
...
|
...
|
|