Added cache, result counter, fixed bugs

This commit is contained in:
Giulia Alfonsi 2014-08-19 14:37:48 +01:00
parent b4b56cdbc2
commit fcb2e1c39f
4 changed files with 30 additions and 12 deletions

View File

@ -5535,6 +5535,15 @@ a[data-pro]:hover:after {
background: rgba(0, 0, 0, 0.04);
}
#result-count {
color: #aaa;
left: -80px;
position: relative;
text-align: right;
width: 60px;
display: inline-block;
}
#results a {
display: block;
overflow: hidden;

View File

@ -1,16 +1,22 @@
(function () {
'use strict';
var results = $('#results');
var resultCount = $('#result-count');
var searchTerms = [];
var search = $('#helpsearch');
var position = -1;
search.on('input', throttle(function () {
if (searchTerms.length === 0) {
$.getJSON('/help/search.json', function (data) {
searchTerms = data;
searchFor(this.value, searchTerms);
}.bind(this));
$.ajax({
url: '/help/search.json?' + (new Date()).toString().split(' ').slice(0, 4).join('-'),
dataType: 'json',
cache: true,
success: function (data) {
searchTerms = data;
searchFor(this.value, searchTerms);
}.bind(this)
});
} else {
searchFor(this.value, searchTerms);
}
@ -64,9 +70,9 @@
}
});
search.on('focus', function () {
results.hide();
});
// search.on('focus', function () {
// results.hide();
// });
function wordmap(input) {
var ignore = "a an and on in it of if for the i is i'm i'd it's or to me be not was do so at are what bin bins".split(' ');
@ -121,6 +127,11 @@
}).join('\n'));
results.show();
var s = '';
if (matches.length !== 1) {
s = 's';
}
resultCount.html(matches.length + ' result' + s);
}

View File

@ -187,8 +187,7 @@ $body.bind('mousedown', function (event) {
var fromClick = false;
var $dropdownLinks = $('.dropdownmenu a, .dropdownmenu .button').mouseup(function (e) {
if (e.target.nodeName === 'INPUT') {
e.preventDefault();
return false;
return;
}
setTimeout(closedropdown, 0);
@ -212,8 +211,7 @@ var $dropdownLinks = $('.dropdownmenu a, .dropdownmenu .button').mouseup(functio
$(this).addClass('hover');
}).mousedown(function (e) {
if (e.target.nodeName === 'INPUT') {
e.preventDefault();
return false;
return;
}
fromClick = true;
});

View File

@ -309,7 +309,7 @@ if(top != self) {
<a data-desc="Shortcut & direct access JS Bin URLs" id="showurls" href="#urls">JS Bin URLs</a>
<hr data-desc="">
{{#if settings.[ui showblog]}}
<input placeholder="Search help..." class="button" id="helpsearch"><span id="results"></span>
<input placeholder="Search help..." class="button" id="helpsearch"><span id="result-count"></span><span id="results"></span>
<a data-desc="Learn about JS Bin features & tricks" target="_blank" href="http://jsbin.com/help">All help topics</a>
{{else}}
<a data-desc="Learn about JS Bin features & tricks" target="_blank" href="http://jsbin.com/help">Help topics</a>