Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <script src='js/jquery-1.8.3.js'></script>
- <script src='js/jquery-ui-1.9.2.custom.min.js'></script>
- <script src='css/ui-darkness/jquery-ui-1.9.2.custom.min.css'></script>
- <script>
- var paths =
- {
- "bob" :
- {
- "alpha" :
- {
- "2013-01-01" : "",
- "2013-01-02" : "",
- "2013-01-03" : "",
- "2013-01-04" : "",
- "2013-01-05" : "",
- "previous" : "",
- "current" : ""
- },
- "beta" :
- {
- "2013-01-01" : "",
- "2013-02-01" : "",
- "previous" : "",
- "current" : ""
- }
- },
- "marcy" :
- {
- "white" :
- {
- "2012-01-01" : "",
- "2012-01-02" : "",
- "2012-01-03" : "",
- "2012-01-04" : "",
- "2012-01-05" : "",
- "previous" : "",
- "current" : ""
- },
- "black" :
- {
- "2012-01-01" : "",
- "2012-02-01" : "",
- "previous" : "",
- "current" : ""
- }
- }
- };
- $(function()
- {
- function split (val)
- {
- return val.split ("/");
- }
- function extractLast (val)
- {
- return split (val).pop ();
- }
- $("#path")
- // don't navigate away from the field on tab when selecting an item
- .bind ("keydown", function (event)
- {
- if (event.keyCode === $.ui.keyCode.TAB)
- event.preventDefault();
- $(this).autocomplete("search");
- })
- .bind ("focus", function()
- {
- $(this).autocomplete("search");
- })
- .autocomplete ({
- minLength: 0,
- delay: 0,
- source: function (request, response)
- {
- var path = request.term.split("/");
- var depth = path.length;
- var node = paths;
- var avail = new Array ();
- for (var n = 1; n < depth; n ++)
- {
- var cur = path[n-1];
- node = node[cur];
- }
- for (var k in node)
- {
- avail.push (k);
- }
- var last = path.pop ();
- // delegate back to autocomplete, but extract the last term
- response ($.ui.autocomplete.filter(avail, last));
- },
- focus: function ()
- {
- // prevent value inserted on focus
- return false;
- },
- select: function (event, ui)
- {
- var terms = split (this.value);
- // remove the current input
- terms.pop();
- // add the selected item
- terms.push( ui.item.value );
- terms.push("");
- this.value = terms.join( "/" );
- return false;
- }
- });
- });
- </script>
- </head>
- <body>
- <div class="ui-widget"><input id="path" /></div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement