﻿var cache = {}, lastXhr; $(document).ready(function () { $("#notification").click(function () { hideResult() }); $("#query").autocomplete({ minLength: 3, delay: 100, select: function (a, b) { hideResult(); window.location.href = b.item.url }, focus: function (a, b) { showSearchResult(b.item) }, close: hideResult(), source: function (d, e) { var f = d.term.replace(/"/g, '\\"'); if (f in cache) { e(cache[f]); return } document.title = "Dominik Amon's Weblog - Search for " + f; lastXhr = $.ajax({ type: "POST", url: "/AjaxService.asmx/Search", data: '{ "query": "' + f + '"}', contentType: "application/json; charset=utf-8", dataType: "json", success: function (a, b, c) { cache[f] = a; if (c === lastXhr) { e(a.d) } }, error: function (a, b, c) { } }) } }) }); function showSearchResult(a) { var b = $("#notification"); b.empty(); $("<h1>" + a.label + "</h1><span>" + a.teaser + "</span><br/><br/><strong>To open this article, simply select it from the list</strong>").appendTo(b); if (!b.is(":visible")) { b.slideDown("slow") } } function hideResult() { if ($("#notification").is(":visible")) { $("#notification").slideUp("fast") } }
