racket-pkg-website/static/site.js
2014-11-09 17:39:26 -05:00

48 lines
1.2 KiB
JavaScript

PkgSite = (function () {
function preventTabMovingDuringSelection(x) {
return x.bind("keydown", function (e) {
if (e.which === $.ui.keyCode.TAB && $(this).autocomplete("instance").menu.active) {
e.preventDefault();
}
});
}
function multiTermComplete(x, completions) {
return x.autocomplete({
source: function (req, resp) {
resp($.ui.autocomplete.filter(completions, req.term.split(/\s+/).pop()));
},
focus: function () {
return false;
},
select: function (event, ui) {
var terms = this.value.split(/\s+/);
terms.pop();
terms.push(ui.item.value);
this.value = terms.join(" ") + " ";
return false;
}
});
}
return {
multiTermComplete: multiTermComplete,
preventTabMovingDuringSelection: preventTabMovingDuringSelection
};
})();
$(document).ready(function () {
$("table.sortable").tablesorter();
if ($("#tags").length) {
$.getJSON((document.body.className === "package-form")
? "/json/formal-tags"
: "/json/tag-search-completions",
function (completions) {
completions.sort();
PkgSite.multiTermComplete(PkgSite.preventTabMovingDuringSelection($("#tags")),
completions);
});
}
});