Sha256: a077eb4c545d60d8dcc76d318375c179188eac481c18b7c6d23dc011d96a47ec
Contents?: true
Size: 1.64 KB
Versions: 1
Compression:
Stored size: 1.64 KB
Contents
$(function(){ var searchIndex = lunr(function() { this.ref('url'); this.field('name'); this.field('abstract'); }); var $typeahead = $('[data-typeahead]'); var $form = $typeahead.parents('form'); var searchURL = $form.attr('action'); function displayTemplate(result) { return result.name; } function suggestionTemplate(result) { var t = '<div class="list-group-item clearfix">'; t += '<span class="doc-name">' + result.name + '</span>'; if (result.parent_name) { t += '<span class="doc-parent-name label">' + result.parent_name + '</span>'; } t += '</div>'; return t; } $typeahead.one('focus', function() { $form.addClass('loading'); $.getJSON(searchURL).then(function(searchData) { $.each(searchData, function (url, doc) { searchIndex.add({url: url, name: doc.name, abstract: doc.abstract}); }); $typeahead.typeahead( { highlight: true, minLength: 3 }, { limit: 10, display: displayTemplate, templates: { suggestion: suggestionTemplate }, source: function(query, sync) { var results = searchIndex.search(query).map(function(result) { var doc = searchData[result.ref]; doc.url = result.ref; return doc; }); sync(results); } } ); $form.removeClass('loading'); $typeahead.trigger('focus'); }); }); var baseURL = searchURL.slice(0, -"search.json".length); $typeahead.on('typeahead:select', function(e, result) { window.location = baseURL + result.url; }); });
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
jazzy-0.9.5 | lib/jazzy/themes/fullwidth/assets/js/jazzy.search.js |