diff options
author | Bharat Mediratta <bharat@menalto.com> | 2013-02-03 18:48:30 -0500 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2013-02-03 18:55:23 -0500 |
commit | 0494244e8068198707bf602199413cd216b0d515 (patch) | |
tree | 59d31d59047c85c13a8061165a453f86aa501510 /lib/gallery.common.js | |
parent | dece6dc5a5880c6267431ba3299c5758b38662ee (diff) |
Super first pass:
- jQuery 1.90
- jQuery UI 1.10
- Superfish 1.5.1 (minus all plugins)
- jQuery Form 3.26.0-2013.01.28
Deleted all other jQuery plugins for now.
- Reworked autocomplete to use the latest jQuery code.
- Deleted references to $.browser.msie, no longer supported
- Basic CSS support for autocomplete - lots more work needed there
Diffstat (limited to 'lib/gallery.common.js')
-rw-r--r-- | lib/gallery.common.js | 82 |
1 files changed, 59 insertions, 23 deletions
diff --git a/lib/gallery.common.js b/lib/gallery.common.js index 755218f5..e23f3fad 100644 --- a/lib/gallery.common.js +++ b/lib/gallery.common.js @@ -200,7 +200,7 @@ // Set the input value equal to label text if (input.val() == "") { input.val(label.html()); - button.enable(false); + button.attr("disabled", true); } // Attach event listeners to the input @@ -209,14 +209,14 @@ if ($(this).val() == label.html()) { $(this).val(""); } - button.enable(true); + button.attr("disabled", false); }); input.bind("blur", function(e){ // Reset the input value if it's empty if ($(this).val() == "") { $(this).val(label.html()); - button.enable(false); + button.attr("disabled", true); } }); }); @@ -225,29 +225,65 @@ // Augment jQuery autocomplete to expect the first response line to // be a <meta> tag that protects against UTF-7 attacks. $.fn.gallery_autocomplete = function(url, options) { - // Drop the first response - it should be a meta tag - options.parse = function(data) { - var parsed = []; - var rows = data.split("\n"); - if (rows[0].indexOf("<meta") == -1) { - throw 'Missing <meta> tag in first line of autocomplete response'; - } - rows.shift(); // drop <META> tag - for (var i=0; i < rows.length; i++) { - var row = $.trim(rows[i]); - if (row) { - row = row.split("|"); - parsed[parsed.length] = { - data: row, - value: row[0], - result: row[0] - }; + var autocomplete_options = { + source: function(request, response) { + var split = function(val) { + return val.split(/,\s*/); + } + + var extract_last = function(term) { + return split(term).pop(); + } + + var ajax_options = { + dataType: "json", + url: url, + success: function(data) { + response(data); + }, + }; + + if (options.multiple) { + + $.extend(ajax_options, { + dataFilter: function(data, dataType) { + // Drop the <meta> tag + return data.substring(data.indexOf("\n") + 1); + }, + data: { + term: extract_last(request.term) + } + }); } + + $.ajax(ajax_options, response); } - return parsed; - }; + } + + if (options.multiple) { + var split = function(val) { + return val.split(/,\s*/); + } + $.extend(autocomplete_options, { + focus: function(event, ui) { + var terms = split(this.value); + terms.pop(); + terms.push(ui.item.value); + this.value = terms.join(", "); + return false; + }, + select: function(event, ui) { + var terms = split(this.value); + terms.pop(); + terms.push(ui.item.value); + terms.push(""); + this.value = terms.join(", "); + return false; + } + }) + } - $(this).autocomplete(url, options); + $(this).autocomplete(autocomplete_options); }; })(jQuery); |