$((function(){var t=$('[data-bb-toggle="gs-modal"]'),n=$("#gs-no-result-template"),e=$('[data-bb-toggle="gs-form"]'),a=$('[data-bb-toggle="gs-input"]'),o="",r=function(t){t&&(t.addClass("active"),t.attr("aria-selected","true"))},i=function(t){t&&(t.removeClass("active"),t.attr("aria-selected","false"))},s=null,l=function(){return $('[data-bb-toggle="gs-result"]')},c=function(){var t=l(),n=t.find("a.active");return n.length<=0&&(n=t.find("a:first")),n},d=function(){var t=l().find("a");if(!(t.length<=0)){t.attr("aria-selected","false"),t.removeClass("active");var n=c();n.length<=0||n.hasClass("active")||r(n)}},f=function(n){if(n.preventDefault(),t.hasClass("show")){var r=a.val();if(r!==o){o=r;var i=l();$httpClient.make().withLoading(i).get(e.attr("action"),{keyword:r}).then((function(t){var n=t.data;i.html(n.data),d()}))}}};$(document).on("keydown",(function(n){t.hasClass("show")||(("Slash"===n.code||"KeyK"===n.code)&&(n.metaKey||n.ctrlKey)||"Slash"===n.code&&"BODY"===n.target.tagName)&&t.modal("show")})),$(document).on("keydown",(function(n){if(t.hasClass("show")&&("ArrowUp"===n.code||"ArrowDown"===n.code)){var e="ArrowDown"===n.code,a=c();if(!(a.length<=0))if(e){var o=a.next();if(i(a),o.length<=0){var s=l().find("a:first");return void r(s)}r(o)}else{var d=a.prev();if(i(a),d.length<=0){var f=l().find("a:last");return void r(f)}r(d)}}})),$(document).on("keydown",(function(n){if(t.hasClass("show")&&"Enter"===n.code){var e=c();e.length<=0||e[0].click()}})),e.on("submit",f),t.on("show.bs.modal",(function(){l().html(n.html())})),t.on("shown.bs.modal",(function(){a.focus(),d()})),t.on("hidden.bs.modal",(function(){a.val("")})),a.on("keydown",(function(t){"ArrowUp"!==t.key&&"ArrowDown"!==t.key&&"Enter"!==t.key?function(t){s&&clearTimeout(s),s=setTimeout((function(){return f(t)}),500)}(t):t.preventDefault()})),$('[data-bb-toggle="gs-navbar-input"]').on("focus",(function(){return t.modal("show")}))}));