Mercurial > code > home > repos > href
view static/gui.js @ 8:be339aa223bf
tag/filter autocompelte
Ignore-this: f6235de879c1ce62a8fc41e890edd0d2
author | Drew Perttula <drewp@bigasterisk.com> |
---|---|
date | Wed, 06 Mar 2013 23:22:24 -0800 |
parents | f8c4c7ce5f4a |
children | e054949143e9 |
line wrap: on
line source
$("#filterTag").focus(); var model = { filterTags: ko.observableArray(currentFilter()) }; function currentFilter() { var p = window.location.pathname; var comps = p.split("/"); if (toRoot == ".") { return []; } else { return (comps[comps.length-1] || "").split("+"); } } function toggleTag(tag) { var selected = currentFilter(); if (selected.indexOf(tag) == -1) { selected.push(tag); } else { selected.splice(selected.indexOf(tag), 1); } setPageTags(selected); } function setPageTags(tags) { var newPath = window.location.pathname; if (toRoot == ".") { newPath += "/"; } else { newPath = newPath.replace( /(.*\/)[^\/]*$/, "$1") } console.log("user root", newPath); if (tags.length) { newPath += tags.join("+") } else { newPath = newPath.substr(0, newPath.length - 1); } console.log("done", newPath); window.location.pathname = newPath; } function backspaceLastTag() { var p = window.location.pathname; var comps = p.split("/"); var selected = (comps[comps.length-1] || "").split("+"); if (selected.length == 0) { return; } toggleTag(selected[selected.length-1]); } $("a.tag").click(function () { var tag = $(this).text(); toggleTag(tag); return false; }); $("#filterTag").change(function () { var tags = $(this).val(); setPageTags(tags); return false; }); $("#filterTag").keydown(function (ev) { if ($(this).val() == "" && ev.which == 8) { backspaceLastTag(); } }); $("#filterTag").chosen({ }); ko.applyBindings(model); $("#filterTag").trigger("liszt:updated");