-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathalgolia.min.js
More file actions
1 lines (1 loc) · 1.47 KB
/
algolia.min.js
File metadata and controls
1 lines (1 loc) · 1.47 KB
1
$(function(t){"use strict";var a=t.applicationId,e=t.apiKey,n=t.indexName,i=algoliasearch(a,e),o=algoliasearchHelper(i,n);o.setQueryParameter("distinct",!0),o.on("result",function(a){if(a.query!==c)return!1;var e=a.nbHits?function(a){return $.map(a.hits,function(a){return a.posted_at&&(a.posted_at_readable=moment.unix(a.posted_at).fromNow()),a.css_selector=encodeURI(a.css_selector),a.full_url=t.baseurl+a.url,u.render(a)}).join("")}(a):d;s.html(e)}),$(".js-algolia__input").on("keyup",function(){if(0===(c=$(this).val()).length)return _(),!1;o.setQuery(c).search(),window.scroll(0,0),l.addClass("algolia__initial-content--hidden"),r.addClass("algolia__search-content--active")});var l=$(".js-algolia__initial-content"),r=$(".js-algolia__search-content"),s=r.find(".algolia__results");s.on("click","a",function(t){var a=g(t.target.hash);if(t.target.pathname!==window.location.pathname||!a)return!0;return _(),f(a),t.preventDefault(),!1});var c,u=Hogan.compile($("#algolia__template").html()),d=$("#algolia__template--no-results").html();function _(){l.removeClass("algolia__initial-content--hidden"),r.removeClass("algolia__search-content--active")}function g(t){var a=t.substring(1);return!!a.match(/^algolia:/)&&decodeURI(a.replace(/^algolia:/,""))}function f(t){var a=$(".page,.post").find(t)[0].getBoundingClientRect().top+window.pageYOffset-20;window.setTimeout(function(){window.scroll(0,a)},100)}window.setTimeout(function(){var t=g(window.location.hash);t&&f(t)},100)}(window.ALGOLIA_CONFIG));