Commits

Anonymous committed 3ee0703

forgot to minify the file...
include uncompressed file

  • Participants
  • Parent commits debb3be

Comments (0)

Files changed (2)

File taggit_autosuggest/static/jquery-autosuggest/js/jquery.autoSuggest.js

+ /*
+ * AutoSuggest
+ * Copyright 2009-2010 Drew Wilson
+ * www.drewwilson.com
+ * code.drewwilson.com/entry/autosuggest-jquery-plugin
+ *
+ * Forked by Wu Yuntao
+ * github.com/wuyuntao/jquery-autosuggest
+ *
+ * Version 1.6.2
+ *
+ * This Plug-In will auto-complete or auto-suggest completed search queries
+ * for you as you type. You can add multiple selections and remove them on
+ * the fly. It supports keybord navigation (UP + DOWN + RETURN), as well
+ * as multiple AutoSuggest fields on the same page.
+ *
+ * Inspired by the Autocomplete plugin by: Joern Zaefferer
+ * and the Facelist plugin by: Ian Tearle (iantearle.com)
+ *
+ * This AutoSuggest jQuery plug-in is dual licensed under the MIT and GPL licenses:
+ *   http://www.opensource.org/licenses/mit-license.php
+ *   http://www.gnu.org/licenses/gpl.html
+ */
+
+(function($){
+    $.fn.autoSuggest = function(data, options) {
+        var defaults = {
+            asHtmlID: false,
+            startText: "Enter Name Here",
+            usePlaceholder: false,
+            emptyText: "No Results Found",
+            preFill: {},
+            limitText: "No More Selections Are Allowed",
+            selectedItemProp: "value", //name of object property
+            selectedValuesProp: "value", //name of object property
+            searchObjProps: "value", //comma separated list of object property names
+            queryParam: "q",
+            retrieveLimit: false, //number for 'limit' param on ajax request
+            extraParams: "",
+            matchCase: false,
+            minChars: 1,
+            keyDelay: 400,
+            resultsHighlight: true,
+            neverSubmit: false,
+            selectionLimit: false,
+            showResultList: true,
+            showResultListWhenNoMatch: false,
+            canGenerateNewSelections: true,
+            start: function(){},
+            selectionClick: function(elem){},
+            selectionAdded: function(elem){},
+            selectionRemoved: function(elem){ elem.remove(); },
+            formatList: false, //callback function
+            beforeRetrieve: function(string){ return string; },
+            retrieveComplete: function(data){ return data; },
+            resultClick: function(data){},
+            resultsComplete: function(){}
+        };
+        var opts = $.extend(defaults, options);
+
+        function countValidItems(data) { var n = 0; for (k in data) if (data.hasOwnProperty(k)) n++; return n; }
+
+        function getExtraParams() {
+            var params = opts.extraParams;
+            if($.isFunction(params)) {
+                return params();
+            }
+            return params;
+        }
+
+        var d_fetcher;
+        var request = null;
+        if(typeof data == "function") {
+            d_fetcher = data;
+        } else if(typeof data == "string") {
+            d_fetcher = function(query, next) {
+                var limit = "";
+                if(opts.retrieveLimit){
+                    limit = "&limit="+encodeURIComponent(opts.retrieveLimit);
+                }
+                request = $.getJSON(data+"?"+opts.queryParam+"="+encodeURIComponent(query)+limit+getExtraParams(), function(data){
+                    var new_data = opts.retrieveComplete.call(this, data);
+                    next(new_data, query);
+                });
+            };
+        } else if(typeof data == "object" && countValidItems(data) > 0) {
+            d_fetcher = function(query, next) { next(data, query); };
+        }
+
+        if(d_fetcher) {
+            return this.each(function(x){
+                if(!opts.asHtmlID){
+                    x = x+""+Math.floor(Math.random()*100); //this ensures there will be unique IDs on the page if autoSuggest() is called multiple times
+                    var x_id = "as-input-"+x;
+                } else {
+                    x = opts.asHtmlID;
+                    var x_id = x;
+                }
+                opts.start.call(this, {
+                    add: function(data) {
+                             add_selected_item(data, 'u' + $('li', selections_holder).length).addClass('blur');
+                         },
+                    remove: function(value) {
+                                values_input.val(values_input.val().replace(","+value+",",","));
+                                selections_holder.find('li[data-value = "' + value + '"]').remove();
+                            }
+                });
+                var input = $(this);
+                input.attr("autocomplete","off").addClass("as-input").attr("id",x_id);
+                if (opts.usePlaceholder) {
+                    input.attr('placeholder', opts.startText);
+                } else {
+                    input.val(opts.startText);
+                }
+                var input_focus = false;
+
+                // Setup basic elements and render them to the DOM
+                input.wrap('<ul class="as-selections" id="as-selections-'+x+'"></ul>').wrap('<li class="as-original" id="as-original-'+x+'"></li>');
+                var selections_holder = $("#as-selections-"+x);
+                var org_li = $("#as-original-"+x);
+                var results_holder = $('<div class="as-results" id="as-results-'+x+'"></div>').hide();
+                var results_ul =  $('<ul class="as-list"></ul>');
+                var values_input = $('<input type="hidden" class="as-values" name="as_values_'+x+'" id="as-values-'+x+'" />');
+                var prefill_value = "";
+                if(typeof opts.preFill == "string"){
+                    var vals = opts.preFill.split(",");
+                    for(var i=0; i < vals.length; i++){
+                        var v_data = {};
+                        v_data[opts.selectedValuesProp] = vals[i];
+                        if(vals[i] != ""){
+                            add_selected_item(v_data, "000"+i);
+                        }
+                    }
+                    prefill_value = opts.preFill;
+                } else {
+                    prefill_value = "";
+                    var prefill_count = 0;
+                    for (k in opts.preFill) if (opts.preFill.hasOwnProperty(k)) prefill_count++;
+                    if(prefill_count > 0){
+                        for(var i=0; i < prefill_count; i++){
+                            var new_v = opts.preFill[i][opts.selectedValuesProp];
+                            if(new_v == undefined){ new_v = ""; }
+                            prefill_value = prefill_value+new_v+",";
+                            if(new_v != ""){
+                                add_selected_item(opts.preFill[i], "000"+i);
+                            }
+                        }
+                    }
+                }
+                if(prefill_value != ""){
+                    input.val("");
+                    var lastChar = prefill_value.substring(prefill_value.length-1);
+                    if(lastChar != ","){ prefill_value = prefill_value+","; }
+                    values_input.val(","+prefill_value);
+                    $("li.as-selection-item", selections_holder).addClass("blur").removeClass("selected");
+                }
+                input.after(values_input);
+                selections_holder.click(function(){
+                    input_focus = true;
+                    input.focus();
+                }).mousedown(function(){ input_focus = false; }).after(results_holder);
+
+                var interval = null;
+                var timeout = null;
+                var prev = "";
+                var totalSelections = 0;
+                var tab_press = false;
+                var lastKeyPressCode = null;
+
+                // Handle input field events
+                input.focus(function(){
+                    if(!opts.usePlaceholder && $(this).val() == opts.startText && values_input.val() == ""){
+                        $(this).val("");
+                    } else if(input_focus){
+                        $("li.as-selection-item", selections_holder).removeClass("blur");
+                        if($(this).val() != ""){
+                            results_ul.css("width",selections_holder.outerWidth());
+                            results_holder.show();
+                        }
+                    }
+                    if (interval) clearInterval(interval);
+                    interval = setInterval(function() {
+                        if(opts.showResultList){
+                            if(opts.selectionLimit && $("li.as-selection-item", selections_holder).length >= opts.selectionLimit){
+                                results_ul.html('<li class="as-message">'+opts.limitText+'</li>');
+                                results_holder.show();
+                            } else {
+                                keyChange();
+                            }
+                        }
+                    }, opts.keyDelay);
+                    input_focus = true;
+                    if (opts.minChars == 0){
+                      processRequest($(this).val());
+                    }
+                    return true;
+                }).blur(function(){
+                    if (!opts.usePlaceholder && $(this).val() == "" && values_input.val() == "" && prefill_value == "" && opts.minChars > 0) {
+                        $(this).val(opts.startText);
+                    } else if(input_focus){
+                        $("li.as-selection-item", selections_holder).addClass("blur").removeClass("selected");
+                        results_holder.hide();
+                    }
+                    if (interval) clearInterval(interval);
+                }).keydown(function(e) {
+                    // track last key pressed
+                    lastKeyPressCode = e.keyCode;
+                    first_focus = false;
+                    switch(e.keyCode) {
+                        case 38: // up
+                            e.preventDefault();
+                            moveSelection("up");
+                            break;
+                        case 40: // down
+                            e.preventDefault();
+                            moveSelection("down");
+                            break;
+                        case 8:  // delete
+                            if(input.val() == ""){
+                                var last = values_input.val().split(",");
+                                last = last[last.length - 2];
+                                selections_holder.children().not(org_li.prev()).removeClass("selected");
+                                if(org_li.prev().hasClass("selected")){
+                                    values_input.val(values_input.val().replace(","+last+",",","));
+                                    opts.selectionRemoved.call(this, org_li.prev());
+                                } else {
+                                    opts.selectionClick.call(this, org_li.prev());
+                                    org_li.prev().addClass("selected");
+                                }
+                            }
+                            if(input.val().length == 1){
+                                results_holder.hide();
+                                prev = "";
+                                abortRequest();
+                            }
+                            if($(":visible",results_holder).length > 0){
+                                if (timeout){ clearTimeout(timeout); }
+                                timeout = setTimeout(function(){ keyChange(); }, opts.keyDelay);
+                            }
+                            break;
+                        case 9: case 188:  // tab or comm
+                            if(opts.canGenerateNewSelections){
+                                tab_press = true;
+                                var i_input = input.val().replace(/(,)/g, "");
+                                var active = $("li.active:first", results_holder);
+                                // Generate a new bubble with text when no suggestion selected
+                                if(i_input !== "" && values_input.val().search(","+i_input+",") < 0 && i_input.length >= opts.minChars && active.length === 0){
+                                    e.preventDefault();
+                                    var n_data = {};
+                                    n_data[opts.selectedItemProp] = i_input;
+                                    n_data[opts.selectedValuesProp] = i_input;
+                                    var lis = $("li", selections_holder).length;
+                                    add_selected_item(n_data, "00"+(lis+1));
+                                    input.val("");
+                                    // Cancel previous request when new tag is added
+                                    abortRequest();
+                                    break;
+                                }
+                            }
+                        case 13: // return
+                            tab_press = false;
+                            var active = $("li.active:first", results_holder);
+                            if(active.length > 0){
+                                active.click();
+                                results_holder.hide();
+                            }
+                            if(opts.neverSubmit || active.length > 0){
+                                e.preventDefault();
+                            }
+                            break;
+                        // ignore if the following keys are pressed: [escape] [shift] [capslock]
+                        case 27: // escape
+                        case 16: // shift
+                        case 20: // capslock
+                            abortRequest();
+                            results_holder.hide();
+                            break;
+                    }
+                });
+
+                function keyChange() {
+                    // Since most IME does not trigger any key events, if we press [del]
+                    // and type some chinese character, `lastKeyPressCode` will still be [del].
+                    // This might cause problem so we move the line to key events section;
+                    // ignore if the following keys are pressed: [del] [shift] [capslock]
+                    // if( lastKeyPressCode == 46 || (lastKeyPressCode > 8 && lastKeyPressCode < 32) ){ return results_holder.hide(); }
+                    var string = input.val().replace(/[\\]+|[\/]+/g,"");
+                    if (string == prev) return;
+                    prev = string;
+                    if (string.length >= opts.minChars) {
+                        selections_holder.addClass("loading");
+                        processRequest(string);
+                    } else {
+                        selections_holder.removeClass("loading");
+                        results_holder.hide();
+                    }
+                }
+                function processRequest(string){
+                  if(opts.beforeRetrieve){
+                      string = opts.beforeRetrieve.call(this, string);
+                  }
+                  abortRequest();
+                  d_fetcher(string, processData);
+                }
+                var num_count = 0;
+                function processData(data, query){
+                    if (!opts.matchCase){ query = query.toLowerCase(); }
+                    query = query.replace("(", "\\(", "g").replace(")", "\\)", "g");
+                    var matchCount = 0;
+                    results_holder.html(results_ul.html("")).hide();
+                    var d_count = countValidItems(data);
+                    for(var i=0;i<d_count;i++){
+                        var num = i;
+                        num_count++;
+                        var forward = false;
+                        if(opts.searchObjProps == "value") {
+                            var str = data[num].value;
+                        } else {
+                            var str = "";
+                            var names = opts.searchObjProps.split(",");
+                            for(var y=0;y<names.length;y++){
+                                var name = $.trim(names[y]);
+                                str = str+data[num][name]+" ";
+                            }
+                        }
+                        if(str){
+                            if (!opts.matchCase){ str = str.toLowerCase(); }
+                            if(str.search(query) != -1 && values_input.val().search(","+data[num][opts.selectedValuesProp]+",") == -1){
+                                forward = true;
+                            }
+                        }
+                        if(forward){
+                            var formatted = $('<li class="as-result-item" id="as-result-item-'+num+'"></li>').click(function(){
+                                    var raw_data = $(this).data("data");
+                                    var number = raw_data.num;
+                                    if($("#as-selection-"+number, selections_holder).length <= 0 && !tab_press){
+                                        var data = raw_data.attributes;
+                                        input.val("").focus();
+                                        prev = "";
+                                        add_selected_item(data, number);
+                                        opts.resultClick.call(this, raw_data);
+                                        results_holder.hide();
+                                    }
+                                    tab_press = false;
+                                }).mousedown(function(){ input_focus = false; }).mouseover(function(){
+                                    $("li", results_ul).removeClass("active");
+                                    $(this).addClass("active");
+                                }).data("data",{attributes: data[num], num: num_count});
+                            var this_data = $.extend({},data[num]);
+                            if (!opts.matchCase){
+                                var regx = new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + query + ")(?![^<>]*>)(?![^&;]+;)", "gi");
+                            } else {
+                                var regx = new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + query + ")(?![^<>]*>)(?![^&;]+;)", "g");
+                            }
+
+                            if(opts.resultsHighlight && query.length > 0){
+                                this_data[opts.selectedItemProp] = this_data[opts.selectedItemProp].replace(regx,"<em>$1</em>");
+                            }
+                            if(!opts.formatList){
+                                formatted = formatted.html(this_data[opts.selectedItemProp]);
+                            } else {
+                                formatted = opts.formatList.call(this, this_data, formatted);
+                            }
+                            results_ul.append(formatted);
+                            delete this_data;
+                            matchCount++;
+                            if(opts.retrieveLimit && opts.retrieveLimit == matchCount ){ break; }
+                        }
+                    }
+                    selections_holder.removeClass("loading");
+                    if(matchCount <= 0){
+                        results_ul.html('<li class="as-message">'+opts.emptyText+'</li>');
+                    }
+                    results_ul.css("width", selections_holder.outerWidth());
+                    if (matchCount > 0 || !opts.showResultListWhenNoMatch) {
+                        results_holder.show();
+                    }
+                    opts.resultsComplete.call(this);
+                }
+
+                function add_selected_item(data, num){
+                    values_input.val((values_input.val()||",")+data[opts.selectedValuesProp]+",");
+                    var item = $('<li class="as-selection-item" id="as-selection-'+num+'" data-value="' + data[opts.selectedValuesProp] + '"></li>').click(function(){
+                            opts.selectionClick.call(this, $(this));
+                            selections_holder.children().removeClass("selected");
+                            $(this).addClass("selected");
+                        }).mousedown(function(){ input_focus = false; });
+                    var close = $('<a class="as-close">&times;</a>').click(function(){
+                            values_input.val(values_input.val().replace(","+data[opts.selectedValuesProp]+",",","));
+                            opts.selectionRemoved.call(this, item);
+                            input_focus = true;
+                            input.focus();
+                            return false;
+                        });
+                    org_li.before(item.html(data[opts.selectedItemProp]).prepend(close));
+                    opts.selectionAdded.call(this, org_li.prev(), data[opts.selectedValuesProp]);
+                    return org_li.prev();
+                }
+
+                function moveSelection(direction){
+                    if($(":visible",results_holder).length > 0){
+                        var lis = $("li", results_holder);
+                        if(direction == "down"){
+                            var start = lis.eq(0);
+                        } else {
+                            var start = lis.filter(":last");
+                        }
+                        var active = $("li.active:first", results_holder);
+                        if(active.length > 0){
+                            if(direction == "down"){
+                            start = active.next();
+                            } else {
+                                start = active.prev();
+                            }
+                        }
+                        lis.removeClass("active");
+                        start.addClass("active");
+                    }
+                }
+
+                function abortRequest() {
+                    if (request) {
+                        request.abort();
+                        request = null;
+                    }
+                }
+
+            });
+        }
+    };
+})(jQuery);

File taggit_autosuggest/static/jquery-autosuggest/js/jquery.autoSuggest.minified.js

- /*
- * AutoSuggest
- * Copyright 2009-2010 Drew Wilson
- * www.drewwilson.com
- * code.drewwilson.com/entry/autosuggest-jquery-plugin
- *
- * Forked by Wu Yuntao
- * github.com/wuyuntao/jquery-autosuggest
- *
- * Version 1.6.2
- *
- * This Plug-In will auto-complete or auto-suggest completed search queries
- * for you as you type. You can add multiple selections and remove them on
- * the fly. It supports keybord navigation (UP + DOWN + RETURN), as well
- * as multiple AutoSuggest fields on the same page.
- *
- * Inspired by the Autocomplete plugin by: Joern Zaefferer
- * and the Facelist plugin by: Ian Tearle (iantearle.com)
- *
- * This AutoSuggest jQuery plug-in is dual licensed under the MIT and GPL licenses:
- *   http://www.opensource.org/licenses/mit-license.php
- *   http://www.gnu.org/licenses/gpl.html
- */
-
-(function($){
-    $.fn.autoSuggest = function(data, options) {
-        var defaults = {
-            asHtmlID: false,
-            startText: "Enter Name Here",
-            usePlaceholder: false,
-            emptyText: "No Results Found",
-            preFill: {},
-            limitText: "No More Selections Are Allowed",
-            selectedItemProp: "value", //name of object property
-            selectedValuesProp: "value", //name of object property
-            searchObjProps: "value", //comma separated list of object property names
-            queryParam: "q",
-            retrieveLimit: false, //number for 'limit' param on ajax request
-            extraParams: "",
-            matchCase: false,
-            minChars: 1,
-            keyDelay: 400,
-            resultsHighlight: true,
-            neverSubmit: false,
-            selectionLimit: false,
-            showResultList: true,
-            showResultListWhenNoMatch: false,
-            canGenerateNewSelections: true,
-            start: function(){},
-            selectionClick: function(elem){},
-            selectionAdded: function(elem){},
-            selectionRemoved: function(elem){ elem.remove(); },
-            formatList: false, //callback function
-            beforeRetrieve: function(string){ return string; },
-            retrieveComplete: function(data){ return data; },
-            resultClick: function(data){},
-            resultsComplete: function(){}
-        };
-        var opts = $.extend(defaults, options);
-
-        function countValidItems(data) { var n = 0; for (k in data) if (data.hasOwnProperty(k)) n++; return n; }
-
-        function getExtraParams() {
-            var params = opts.extraParams;
-            if($.isFunction(params)) {
-                return params();
-            }
-            return params;
-        }
-
-        var d_fetcher;
-        var request = null;
-        if(typeof data == "function") {
-            d_fetcher = data;
-        } else if(typeof data == "string") {
-            d_fetcher = function(query, next) {
-                var limit = "";
-                if(opts.retrieveLimit){
-                    limit = "&limit="+encodeURIComponent(opts.retrieveLimit);
-                }
-                request = $.getJSON(data+"?"+opts.queryParam+"="+encodeURIComponent(query)+limit+getExtraParams(), function(data){
-                    var new_data = opts.retrieveComplete.call(this, data);
-                    next(new_data, query);
-                });
-            };
-        } else if(typeof data == "object" && countValidItems(data) > 0) {
-            d_fetcher = function(query, next) { next(data, query); };
-        }
-
-        if(d_fetcher) {
-            return this.each(function(x){
-                if(!opts.asHtmlID){
-                    x = x+""+Math.floor(Math.random()*100); //this ensures there will be unique IDs on the page if autoSuggest() is called multiple times
-                    var x_id = "as-input-"+x;
-                } else {
-                    x = opts.asHtmlID;
-                    var x_id = x;
-                }
-                opts.start.call(this, {
-                    add: function(data) {
-                             add_selected_item(data, 'u' + $('li', selections_holder).length).addClass('blur');
-                         },
-                    remove: function(value) {
-                                values_input.val(values_input.val().replace(","+value+",",","));
-                                selections_holder.find('li[data-value = "' + value + '"]').remove();
-                            }
-                });
-                var input = $(this);
-                input.attr("autocomplete","off").addClass("as-input").attr("id",x_id);
-                if (opts.usePlaceholder) {
-                    input.attr('placeholder', opts.startText);
-                } else {
-                    input.val(opts.startText);
-                }
-                var input_focus = false;
-
-                // Setup basic elements and render them to the DOM
-                input.wrap('<ul class="as-selections" id="as-selections-'+x+'"></ul>').wrap('<li class="as-original" id="as-original-'+x+'"></li>');
-                var selections_holder = $("#as-selections-"+x);
-                var org_li = $("#as-original-"+x);
-                var results_holder = $('<div class="as-results" id="as-results-'+x+'"></div>').hide();
-                var results_ul =  $('<ul class="as-list"></ul>');
-                var values_input = $('<input type="hidden" class="as-values" name="as_values_'+x+'" id="as-values-'+x+'" />');
-                var prefill_value = "";
-                if(typeof opts.preFill == "string"){
-                    var vals = opts.preFill.split(",");
-                    for(var i=0; i < vals.length; i++){
-                        var v_data = {};
-                        v_data[opts.selectedValuesProp] = vals[i];
-                        if(vals[i] != ""){
-                            add_selected_item(v_data, "000"+i);
-                        }
-                    }
-                    prefill_value = opts.preFill;
-                } else {
-                    prefill_value = "";
-                    var prefill_count = 0;
-                    for (k in opts.preFill) if (opts.preFill.hasOwnProperty(k)) prefill_count++;
-                    if(prefill_count > 0){
-                        for(var i=0; i < prefill_count; i++){
-                            var new_v = opts.preFill[i][opts.selectedValuesProp];
-                            if(new_v == undefined){ new_v = ""; }
-                            prefill_value = prefill_value+new_v+",";
-                            if(new_v != ""){
-                                add_selected_item(opts.preFill[i], "000"+i);
-                            }
-                        }
-                    }
-                }
-                if(prefill_value != ""){
-                    input.val("");
-                    var lastChar = prefill_value.substring(prefill_value.length-1);
-                    if(lastChar != ","){ prefill_value = prefill_value+","; }
-                    values_input.val(","+prefill_value);
-                    $("li.as-selection-item", selections_holder).addClass("blur").removeClass("selected");
-                }
-                input.after(values_input);
-                selections_holder.click(function(){
-                    input_focus = true;
-                    input.focus();
-                }).mousedown(function(){ input_focus = false; }).after(results_holder);
-
-                var interval = null;
-                var timeout = null;
-                var prev = "";
-                var totalSelections = 0;
-                var tab_press = false;
-                var lastKeyPressCode = null;
-
-                // Handle input field events
-                input.focus(function(){
-                    if(!opts.usePlaceholder && $(this).val() == opts.startText && values_input.val() == ""){
-                        $(this).val("");
-                    } else if(input_focus){
-                        $("li.as-selection-item", selections_holder).removeClass("blur");
-                        if($(this).val() != ""){
-                            results_ul.css("width",selections_holder.outerWidth());
-                            results_holder.show();
-                        }
-                    }
-                    if (interval) clearInterval(interval);
-                    interval = setInterval(function() {
-                        if(opts.showResultList){
-                            if(opts.selectionLimit && $("li.as-selection-item", selections_holder).length >= opts.selectionLimit){
-                                results_ul.html('<li class="as-message">'+opts.limitText+'</li>');
-                                results_holder.show();
-                            } else {
-                                keyChange();
-                            }
-                        }
-                    }, opts.keyDelay);
-                    input_focus = true;
-                    if (opts.minChars == 0){
-                      processRequest($(this).val());
-                    }
-                    return true;
-                }).blur(function(){
-                    if (!opts.usePlaceholder && $(this).val() == "" && values_input.val() == "" && prefill_value == "" && opts.minChars > 0) {
-                        $(this).val(opts.startText);
-                    } else if(input_focus){
-                        $("li.as-selection-item", selections_holder).addClass("blur").removeClass("selected");
-                        results_holder.hide();
-                    }
-                    if (interval) clearInterval(interval);
-                }).keydown(function(e) {
-                    // track last key pressed
-                    lastKeyPressCode = e.keyCode;
-                    first_focus = false;
-                    switch(e.keyCode) {
-                        case 38: // up
-                            e.preventDefault();
-                            moveSelection("up");
-                            break;
-                        case 40: // down
-                            e.preventDefault();
-                            moveSelection("down");
-                            break;
-                        case 8:  // delete
-                            if(input.val() == ""){
-                                var last = values_input.val().split(",");
-                                last = last[last.length - 2];
-                                selections_holder.children().not(org_li.prev()).removeClass("selected");
-                                if(org_li.prev().hasClass("selected")){
-                                    values_input.val(values_input.val().replace(","+last+",",","));
-                                    opts.selectionRemoved.call(this, org_li.prev());
-                                } else {
-                                    opts.selectionClick.call(this, org_li.prev());
-                                    org_li.prev().addClass("selected");
-                                }
-                            }
-                            if(input.val().length == 1){
-                                results_holder.hide();
-                                prev = "";
-                                abortRequest();
-                            }
-                            if($(":visible",results_holder).length > 0){
-                                if (timeout){ clearTimeout(timeout); }
-                                timeout = setTimeout(function(){ keyChange(); }, opts.keyDelay);
-                            }
-                            break;
-                        case 9: case 188:  // tab or comm
-                            if(opts.canGenerateNewSelections){
-                                tab_press = true;
-                                var i_input = input.val().replace(/(,)/g, "");
-                                var active = $("li.active:first", results_holder);
-                                // Generate a new bubble with text when no suggestion selected
-                                if(i_input !== "" && values_input.val().search(","+i_input+",") < 0 && i_input.length >= opts.minChars && active.length === 0){
-                                    e.preventDefault();
-                                    var n_data = {};
-                                    n_data[opts.selectedItemProp] = i_input;
-                                    n_data[opts.selectedValuesProp] = i_input;
-                                    var lis = $("li", selections_holder).length;
-                                    add_selected_item(n_data, "00"+(lis+1));
-                                    input.val("");
-                                    // Cancel previous request when new tag is added
-                                    abortRequest();
-                                    break;
-                                }
-                            }
-                        case 13: // return
-                            tab_press = false;
-                            var active = $("li.active:first", results_holder);
-                            if(active.length > 0){
-                                active.click();
-                                results_holder.hide();
-                            }
-                            if(opts.neverSubmit || active.length > 0){
-                                e.preventDefault();
-                            }
-                            break;
-                        // ignore if the following keys are pressed: [escape] [shift] [capslock]
-                        case 27: // escape
-                        case 16: // shift
-                        case 20: // capslock
-                            abortRequest();
-                            results_holder.hide();
-                            break;
-                    }
-                });
-
-                function keyChange() {
-                    // Since most IME does not trigger any key events, if we press [del]
-                    // and type some chinese character, `lastKeyPressCode` will still be [del].
-                    // This might cause problem so we move the line to key events section;
-                    // ignore if the following keys are pressed: [del] [shift] [capslock]
-                    // if( lastKeyPressCode == 46 || (lastKeyPressCode > 8 && lastKeyPressCode < 32) ){ return results_holder.hide(); }
-                    var string = input.val().replace(/[\\]+|[\/]+/g,"");
-                    if (string == prev) return;
-                    prev = string;
-                    if (string.length >= opts.minChars) {
-                        selections_holder.addClass("loading");
-                        processRequest(string);
-                    } else {
-                        selections_holder.removeClass("loading");
-                        results_holder.hide();
-                    }
-                }
-                function processRequest(string){
-                  if(opts.beforeRetrieve){
-                      string = opts.beforeRetrieve.call(this, string);
-                  }
-                  abortRequest();
-                  d_fetcher(string, processData);
-                }
-                var num_count = 0;
-                function processData(data, query){
-                    if (!opts.matchCase){ query = query.toLowerCase(); }
-                    query = query.replace("(", "\\(", "g").replace(")", "\\)", "g");
-                    var matchCount = 0;
-                    results_holder.html(results_ul.html("")).hide();
-                    var d_count = countValidItems(data);
-                    for(var i=0;i<d_count;i++){
-                        var num = i;
-                        num_count++;
-                        var forward = false;
-                        if(opts.searchObjProps == "value") {
-                            var str = data[num].value;
-                        } else {
-                            var str = "";
-                            var names = opts.searchObjProps.split(",");
-                            for(var y=0;y<names.length;y++){
-                                var name = $.trim(names[y]);
-                                str = str+data[num][name]+" ";
-                            }
-                        }
-                        if(str){
-                            if (!opts.matchCase){ str = str.toLowerCase(); }
-                            if(str.search(query) != -1 && values_input.val().search(","+data[num][opts.selectedValuesProp]+",") == -1){
-                                forward = true;
-                            }
-                        }
-                        if(forward){
-                            var formatted = $('<li class="as-result-item" id="as-result-item-'+num+'"></li>').click(function(){
-                                    var raw_data = $(this).data("data");
-                                    var number = raw_data.num;
-                                    if($("#as-selection-"+number, selections_holder).length <= 0 && !tab_press){
-                                        var data = raw_data.attributes;
-                                        input.val("").focus();
-                                        prev = "";
-                                        add_selected_item(data, number);
-                                        opts.resultClick.call(this, raw_data);
-                                        results_holder.hide();
-                                    }
-                                    tab_press = false;
-                                }).mousedown(function(){ input_focus = false; }).mouseover(function(){
-                                    $("li", results_ul).removeClass("active");
-                                    $(this).addClass("active");
-                                }).data("data",{attributes: data[num], num: num_count});
-                            var this_data = $.extend({},data[num]);
-                            if (!opts.matchCase){
-                                var regx = new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + query + ")(?![^<>]*>)(?![^&;]+;)", "gi");
-                            } else {
-                                var regx = new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + query + ")(?![^<>]*>)(?![^&;]+;)", "g");
-                            }
-
-                            if(opts.resultsHighlight && query.length > 0){
-                                this_data[opts.selectedItemProp] = this_data[opts.selectedItemProp].replace(regx,"<em>$1</em>");
-                            }
-                            if(!opts.formatList){
-                                formatted = formatted.html(this_data[opts.selectedItemProp]);
-                            } else {
-                                formatted = opts.formatList.call(this, this_data, formatted);
-                            }
-                            results_ul.append(formatted);
-                            delete this_data;
-                            matchCount++;
-                            if(opts.retrieveLimit && opts.retrieveLimit == matchCount ){ break; }
-                        }
-                    }
-                    selections_holder.removeClass("loading");
-                    if(matchCount <= 0){
-                        results_ul.html('<li class="as-message">'+opts.emptyText+'</li>');
-                    }
-                    results_ul.css("width", selections_holder.outerWidth());
-                    if (matchCount > 0 || !opts.showResultListWhenNoMatch) {
-                        results_holder.show();
-                    }
-                    opts.resultsComplete.call(this);
-                }
-
-                function add_selected_item(data, num){
-                    values_input.val((values_input.val()||",")+data[opts.selectedValuesProp]+",");
-                    var item = $('<li class="as-selection-item" id="as-selection-'+num+'" data-value="' + data[opts.selectedValuesProp] + '"></li>').click(function(){
-                            opts.selectionClick.call(this, $(this));
-                            selections_holder.children().removeClass("selected");
-                            $(this).addClass("selected");
-                        }).mousedown(function(){ input_focus = false; });
-                    var close = $('<a class="as-close">&times;</a>').click(function(){
-                            values_input.val(values_input.val().replace(","+data[opts.selectedValuesProp]+",",","));
-                            opts.selectionRemoved.call(this, item);
-                            input_focus = true;
-                            input.focus();
-                            return false;
-                        });
-                    org_li.before(item.html(data[opts.selectedItemProp]).prepend(close));
-                    opts.selectionAdded.call(this, org_li.prev(), data[opts.selectedValuesProp]);
-                    return org_li.prev();
-                }
-
-                function moveSelection(direction){
-                    if($(":visible",results_holder).length > 0){
-                        var lis = $("li", results_holder);
-                        if(direction == "down"){
-                            var start = lis.eq(0);
-                        } else {
-                            var start = lis.filter(":last");
-                        }
-                        var active = $("li.active:first", results_holder);
-                        if(active.length > 0){
-                            if(direction == "down"){
-                            start = active.next();
-                            } else {
-                                start = active.prev();
-                            }
-                        }
-                        lis.removeClass("active");
-                        start.addClass("active");
-                    }
-                }
-
-                function abortRequest() {
-                    if (request) {
-                        request.abort();
-                        request = null;
-                    }
-                }
-
-            });
-        }
-    };
-})(jQuery);
+(function(a){a.fn.autoSuggest=function(b,c){function f(a){var b=0;for(k in a)if(a.hasOwnProperty(k))b++;return b}function g(){var b=e.extraParams;if(a.isFunction(b)){return b()}return b}var d={asHtmlID:false,startText:"Enter Name Here",usePlaceholder:false,emptyText:"No Results Found",preFill:{},limitText:"No More Selections Are Allowed",selectedItemProp:"value",selectedValuesProp:"value",searchObjProps:"value",queryParam:"q",retrieveLimit:false,extraParams:"",matchCase:false,minChars:1,keyDelay:400,resultsHighlight:true,neverSubmit:false,selectionLimit:false,showResultList:true,showResultListWhenNoMatch:false,canGenerateNewSelections:true,start:function(){},selectionClick:function(a){},selectionAdded:function(a){},selectionRemoved:function(a){a.remove()},formatList:false,beforeRetrieve:function(a){return a},retrieveComplete:function(a){return a},resultClick:function(a){},resultsComplete:function(){}};var e=a.extend(d,c);var h;var i=null;if(typeof b=="function"){h=b}else if(typeof b=="string"){h=function(c,d){var f="";if(e.retrieveLimit){f="&limit="+encodeURIComponent(e.retrieveLimit)}i=a.getJSON(b+"?"+e.queryParam+"="+encodeURIComponent(c)+f+g(),function(a){var b=e.retrieveComplete.call(this,a);d(b,c)})}}else if(typeof b=="object"&&f(b)>0){h=function(a,c){c(b,a)}}if(h){return this.each(function(b){function C(){var a=d.val().replace(/[\\]+|[\/]+/g,"");if(a==y)return;y=a;if(a.length>=e.minChars){j.addClass("loading");D(a)}else{j.removeClass("loading");m.hide()}}function D(a){if(e.beforeRetrieve){a=e.beforeRetrieve.call(this,a)}I();h(a,F)}function F(b,c){if(!e.matchCase){c=c.toLowerCase()}c=c.replace("(","\\(","g").replace(")","\\)","g");var h=0;m.html(n.html("")).hide();var i=f(b);for(var k=0;k<i;k++){var l=k;E++;var p=false;if(e.searchObjProps=="value"){var q=b[l].value}else{var q="";var r=e.searchObjProps.split(",");for(var s=0;s<r.length;s++){var t=a.trim(r[s]);q=q+b[l][t]+" "}}if(q){if(!e.matchCase){q=q.toLowerCase()}if(q.search(c)!=-1&&o.val().search(","+b[l][e.selectedValuesProp]+",")==-1){p=true}}if(p){var u=a('<li class="as-result-item" id="as-result-item-'+l+'"></li>').click(function(){var b=a(this).data("data");var c=b.num;if(a("#as-selection-"+c,j).length<=0&&!A){var f=b.attributes;d.val("").focus();y="";G(f,c);e.resultClick.call(this,b);m.hide()}A=false}).mousedown(function(){g=false}).mouseover(function(){a("li",n).removeClass("active");a(this).addClass("active")}).data("data",{attributes:b[l],num:E});var v=a.extend({},b[l]);if(!e.matchCase){var w=new RegExp("(?![^&;]+;)(?!<[^<>]*)("+c+")(?![^<>]*>)(?![^&;]+;)","gi")}else{var w=new RegExp("(?![^&;]+;)(?!<[^<>]*)("+c+")(?![^<>]*>)(?![^&;]+;)","g")}if(e.resultsHighlight&&c.length>0){v[e.selectedItemProp]=v[e.selectedItemProp].replace(w,"<em>$1</em>")}if(!e.formatList){u=u.html(v[e.selectedItemProp])}else{u=e.formatList.call(this,v,u)}n.append(u);delete v;h++;if(e.retrieveLimit&&e.retrieveLimit==h){break}}}j.removeClass("loading");if(h<=0){n.html('<li class="as-message">'+e.emptyText+"</li>")}n.css("width",j.outerWidth());if(h>0||!e.showResultListWhenNoMatch){m.show()}e.resultsComplete.call(this)}function G(b,c){o.val((o.val()||",")+b[e.selectedValuesProp]+",");var f=a('<li class="as-selection-item" id="as-selection-'+c+'" data-value="'+b[e.selectedValuesProp]+'"></li>').click(function(){e.selectionClick.call(this,a(this));j.children().removeClass("selected");a(this).addClass("selected")}).mousedown(function(){g=false});var h=a('<a class="as-close">×</a>').click(function(){o.val(o.val().replace(","+b[e.selectedValuesProp]+",",","));e.selectionRemoved.call(this,f);g=true;d.focus();return false});l.before(f.html(b[e.selectedItemProp]).prepend(h));e.selectionAdded.call(this,l.prev(),b[e.selectedValuesProp]);return l.prev()}function H(b){if(a(":visible",m).length>0){var c=a("li",m);if(b=="down"){var d=c.eq(0)}else{var d=c.filter(":last")}var e=a("li.active:first",m);if(e.length>0){if(b=="down"){d=e.next()}else{d=e.prev()}}c.removeClass("active");d.addClass("active")}}function I(){if(i){i.abort();i=null}}if(!e.asHtmlID){b=b+""+Math.floor(Math.random()*100);var c="as-input-"+b}else{b=e.asHtmlID;var c=b}e.start.call(this,{add:function(b){G(b,"u"+a("li",j).length).addClass("blur")},remove:function(a){o.val(o.val().replace(","+a+",",","));j.find('li[data-value = "'+a+'"]').remove()}});var d=a(this);d.attr("autocomplete","off").addClass("as-input").attr("id",c);if(e.usePlaceholder){d.attr("placeholder",e.startText)}else{d.val(e.startText)}var g=false;d.wrap('<ul class="as-selections" id="as-selections-'+b+'"></ul>').wrap('<li class="as-original" id="as-original-'+b+'"></li>');var j=a("#as-selections-"+b);var l=a("#as-original-"+b);var m=a('<div class="as-results" id="as-results-'+b+'"></div>').hide();var n=a('<ul class="as-list"></ul>');var o=a('<input type="hidden" class="as-values" name="as_values_'+b+'" id="as-values-'+b+'" />');var p="";if(typeof e.preFill=="string"){var q=e.preFill.split(",");for(var r=0;r<q.length;r++){var s={};s[e.selectedValuesProp]=q[r];if(q[r]!=""){G(s,"000"+r)}}p=e.preFill}else{p="";var t=0;for(k in e.preFill)if(e.preFill.hasOwnProperty(k))t++;if(t>0){for(var r=0;r<t;r++){var u=e.preFill[r][e.selectedValuesProp];if(u==undefined){u=""}p=p+u+",";if(u!=""){G(e.preFill[r],"000"+r)}}}}if(p!=""){d.val("");var v=p.substring(p.length-1);if(v!=","){p=p+","}o.val(","+p);a("li.as-selection-item",j).addClass("blur").removeClass("selected")}d.after(o);j.click(function(){g=true;d.focus()}).mousedown(function(){g=false}).after(m);var w=null;var x=null;var y="";var z=0;var A=false;var B=null;d.focus(function(){if(!e.usePlaceholder&&a(this).val()==e.startText&&o.val()==""){a(this).val("")}else if(g){a("li.as-selection-item",j).removeClass("blur");if(a(this).val()!=""){n.css("width",j.outerWidth());m.show()}}if(w)clearInterval(w);w=setInterval(function(){if(e.showResultList){if(e.selectionLimit&&a("li.as-selection-item",j).length>=e.selectionLimit){n.html('<li class="as-message">'+e.limitText+"</li>");m.show()}else{C()}}},e.keyDelay);g=true;if(e.minChars==0){D(a(this).val())}return true}).blur(function(){if(!e.usePlaceholder&&a(this).val()==""&&o.val()==""&&p==""&&e.minChars>0){a(this).val(e.startText)}else if(g){a("li.as-selection-item",j).addClass("blur").removeClass("selected");m.hide()}if(w)clearInterval(w)}).keydown(function(b){B=b.keyCode;first_focus=false;switch(b.keyCode){case 38:b.preventDefault();H("up");break;case 40:b.preventDefault();H("down");break;case 8:if(d.val()==""){var c=o.val().split(",");c=c[c.length-2];j.children().not(l.prev()).removeClass("selected");if(l.prev().hasClass("selected")){o.val(o.val().replace(","+c+",",","));e.selectionRemoved.call(this,l.prev())}else{e.selectionClick.call(this,l.prev());l.prev().addClass("selected")}}if(d.val().length==1){m.hide();y="";I()}if(a(":visible",m).length>0){if(x){clearTimeout(x)}x=setTimeout(function(){C()},e.keyDelay)}break;case 9:case 188:if(e.canGenerateNewSelections){A=true;var f=d.val().replace(/(,)/g,"");var g=a("li.active:first",m);if(f!==""&&o.val().search(","+f+",")<0&&f.length>=e.minChars&&g.length===0){b.preventDefault();var h={};h[e.selectedItemProp]=f;h[e.selectedValuesProp]=f;var i=a("li",j).length;G(h,"00"+(i+1));d.val("");I();break}};case 13:A=false;var g=a("li.active:first",m);if(g.length>0){g.click();m.hide()}if(e.neverSubmit||g.length>0){b.preventDefault()}break;case 27:case 16:case 20:I();m.hide();break}});var E=0})}}})(jQuery)