2014-05-07 21:28:10 +02:00
|
|
|
var $ = require('unopinionate').selector,
|
|
|
|
template = require('../entry.handlebars');
|
|
|
|
|
|
|
|
$(function() {
|
|
|
|
var $form = $('#search-form'),
|
|
|
|
$input = $form.find('input'),
|
|
|
|
$searchResults = $("#search-results"),
|
|
|
|
$body = $('body'),
|
|
|
|
request;
|
|
|
|
|
|
|
|
$form.bind('submit keyup', function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
var q = $input.val();
|
|
|
|
|
|
|
|
$body.addClass('state-search');
|
|
|
|
|
|
|
|
if(q) {
|
|
|
|
if(request) {
|
|
|
|
request.abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
request = $.getJSON('/-/search/' + q, function(results) {
|
|
|
|
if(results.length) {
|
|
|
|
var html = '';
|
|
|
|
|
|
|
|
$.each(results, function(i, package) {
|
|
|
|
html += template(package);
|
|
|
|
});
|
|
|
|
|
|
|
|
$searchResults.html(html);
|
|
|
|
}
|
|
|
|
else {
|
2014-05-07 22:36:03 +02:00
|
|
|
$searchResults.html("<div class='no-results'><big>No Results</big></div>");
|
2014-05-07 21:28:10 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$searchResults.html('');
|
|
|
|
$body.removeClass('state-search');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$form.find('.clear').click(function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
$input.val('');
|
|
|
|
$form.keyup();
|
|
|
|
});
|
|
|
|
});
|