Commits

Anonymous committed debb3be

remove django references so we can use it with standard jquery and not the old admin jquery

  • Participants
  • Parent commits ce03822

Comments (0)

Files changed (2)

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

  *   http://www.opensource.org/licenses/mit-license.php
  *   http://www.gnu.org/licenses/gpl.html
  */
-(function(a){a.fn.autoSuggest=function(h,e){var i={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(j){},selectionAdded:function(j){},selectionRemoved:function(j){j.remove()},formatList:false,beforeRetrieve:function(j){return j},retrieveComplete:function(j){return j},resultClick:function(j){},resultsComplete:function(){}};var g=a.extend(i,e);function d(j){var l=0;for(k in j){if(j.hasOwnProperty(k)){l++}}return l}function c(){var j=g.extraParams;if(a.isFunction(j)){return j()}return j}var b;var f=null;if(typeof h=="function"){b=h}else{if(typeof h=="string"){b=function(m,l){var j="";if(g.retrieveLimit){j="&limit="+encodeURIComponent(g.retrieveLimit)}f=a.getJSON(h+"?"+g.queryParam+"="+encodeURIComponent(m)+j+c(),function(o){var n=g.retrieveComplete.call(this,o);l(n,m)})}}else{if(typeof h=="object"&&d(h)>0){b=function(l,j){j(h,l)}}}}if(b){return this.each(function(z){if(!g.asHtmlID){z=z+""+Math.floor(Math.random()*100);var m="as-input-"+z}else{z=g.asHtmlID;var m=z}g.start.call(this,{add:function(x){K(x,"u"+a("li",G).length).addClass("blur")},remove:function(x){M.val(M.val().replace(","+x+",",","));G.find('li[data-value = "'+x+'"]').remove()}});var B=a(this);B.attr("autocomplete","off").addClass("as-input").attr("id",m);if(g.usePlaceholder){B.attr("placeholder",g.startText)}else{B.val(g.startText)}var F=false;B.wrap('<ul class="as-selections" id="as-selections-'+z+'"></ul>').wrap('<li class="as-original" id="as-original-'+z+'"></li>');var G=a("#as-selections-"+z);var v=a("#as-original-"+z);var o=a('<div class="as-results" id="as-results-'+z+'"></div>').hide();var p=a('<ul class="as-list"></ul>');var M=a('<input type="hidden" class="as-values" name="as_values_'+z+'" id="as-values-'+z+'" />');var u="";if(typeof g.preFill=="string"){var C=g.preFill.split(",");for(var I=0;I<C.length;I++){var n={};n[g.selectedValuesProp]=C[I];if(C[I]!=""){K(n,"000"+I)}}u=g.preFill}else{u="";var N=0;for(k in g.preFill){if(g.preFill.hasOwnProperty(k)){N++}}if(N>0){for(var I=0;I<N;I++){var D=g.preFill[I][g.selectedValuesProp];if(D==undefined){D=""}u=u+D+",";if(D!=""){K(g.preFill[I],"000"+I)}}}}if(u!=""){B.val("");var A=u.substring(u.length-1);if(A!=","){u=u+","}M.val(","+u);a("li.as-selection-item",G).addClass("blur").removeClass("selected")}B.after(M);G.click(function(){F=true;B.focus()}).mousedown(function(){F=false}).after(o);var J=null;var y=null;var E="";var q=0;var r=false;var H=null;B.focus(function(){if(!g.usePlaceholder&&a(this).val()==g.startText&&M.val()==""){a(this).val("")}else{if(F){a("li.as-selection-item",G).removeClass("blur");if(a(this).val()!=""){p.css("width",G.outerWidth());o.show()}}}if(J){clearInterval(J)}J=setInterval(function(){if(g.showResultList){if(g.selectionLimit&&a("li.as-selection-item",G).length>=g.selectionLimit){p.html('<li class="as-message">'+g.limitText+"</li>");o.show()}else{l()}}},g.keyDelay);F=true;if(g.minChars==0){L(a(this).val())}return true}).blur(function(){if(!g.usePlaceholder&&a(this).val()==""&&M.val()==""&&u==""&&g.minChars>0){a(this).val(g.startText)}else{if(F){a("li.as-selection-item",G).addClass("blur").removeClass("selected");o.hide()}}if(J){clearInterval(J)}}).keydown(function(S){H=S.keyCode;first_focus=false;switch(S.keyCode){case 38:S.preventDefault();w("up");break;case 40:S.preventDefault();w("down");break;case 8:if(B.val()==""){var O=M.val().split(",");O=O[O.length-2];G.children().not(v.prev()).removeClass("selected");if(v.prev().hasClass("selected")){M.val(M.val().replace(","+O+",",","));g.selectionRemoved.call(this,v.prev())}else{g.selectionClick.call(this,v.prev());v.prev().addClass("selected")}}if(B.val().length==1){o.hide();E="";j()}if(a(":visible",o).length>0){if(y){clearTimeout(y)}y=setTimeout(function(){l()},g.keyDelay)}break;case 9:case 188:if(g.canGenerateNewSelections){r=true;var Q=B.val().replace(/(,)/g,"");var R=a("li.active:first",o);if(Q!==""&&M.val().search(","+Q+",")<0&&Q.length>=g.minChars&&R.length===0){S.preventDefault();var P={};P[g.selectedItemProp]=Q;P[g.selectedValuesProp]=Q;var x=a("li",G).length;K(P,"00"+(x+1));B.val("");j();break}}case 13:r=false;var R=a("li.active:first",o);if(R.length>0){R.click();o.hide()}if(g.neverSubmit||R.length>0){S.preventDefault()}break;case 27:case 16:case 20:j();o.hide();break}});function l(){var x=B.val().replace(/[\\]+|[\/]+/g,"");if(x==E){return}E=x;if(x.length>=g.minChars){G.addClass("loading");L(x)}else{G.removeClass("loading");o.hide()}}function L(x){if(g.beforeRetrieve){x=g.beforeRetrieve.call(this,x)}j();b(x,s)}var t=0;function s(Q,W){if(!g.matchCase){W=W.toLowerCase()}W=W.replace("(","\\(","g").replace(")","\\)","g");var Y=0;o.html(p.html("")).hide();var aa=d(Q);for(var R=0;R<aa;R++){var S=R;t++;var T=false;if(g.searchObjProps=="value"){var V=Q[S].value}else{var V="";var U=g.searchObjProps.split(",");for(var X=0;X<U.length;X++){var x=a.trim(U[X]);V=V+Q[S][x]+" "}}if(V){if(!g.matchCase){V=V.toLowerCase()}if(V.search(W)!=-1&&M.val().search(","+Q[S][g.selectedValuesProp]+",")==-1){T=true}}if(T){var P=a('<li class="as-result-item" id="as-result-item-'+S+'"></li>').click(function(){var ad=a(this).data("data");var ab=ad.num;if(a("#as-selection-"+ab,G).length<=0&&!r){var ac=ad.attributes;B.val("").focus();E="";K(ac,ab);g.resultClick.call(this,ad);o.hide()}r=false}).mousedown(function(){F=false}).mouseover(function(){a("li",p).removeClass("active");a(this).addClass("active")}).data("data",{attributes:Q[S],num:t});var Z=a.extend({},Q[S]);if(!g.matchCase){var O=new RegExp("(?![^&;]+;)(?!<[^<>]*)("+W+")(?![^<>]*>)(?![^&;]+;)","gi")}else{var O=new RegExp("(?![^&;]+;)(?!<[^<>]*)("+W+")(?![^<>]*>)(?![^&;]+;)","g")}if(g.resultsHighlight&&W.length>0){Z[g.selectedItemProp]=Z[g.selectedItemProp].replace(O,"<em>$1</em>")}if(!g.formatList){P=P.html(Z[g.selectedItemProp])}else{P=g.formatList.call(this,Z,P)}p.append(P);delete Z;Y++;if(g.retrieveLimit&&g.retrieveLimit==Y){break}}}G.removeClass("loading");if(Y<=0){p.html('<li class="as-message">'+g.emptyText+"</li>")}p.css("width",G.outerWidth());if(Y>0||!g.showResultListWhenNoMatch){o.show()}g.resultsComplete.call(this)}function K(P,x){M.val((M.val()||",")+P[g.selectedValuesProp]+",");var O=a('<li class="as-selection-item" id="as-selection-'+x+'" data-value="'+P[g.selectedValuesProp]+'"></li>').click(function(){g.selectionClick.call(this,a(this));G.children().removeClass("selected");a(this).addClass("selected")}).mousedown(function(){F=false});var Q=a('<a class="as-close">&times;</a>').click(function(){M.val(M.val().replace(","+P[g.selectedValuesProp]+",",","));g.selectionRemoved.call(this,O);F=true;B.focus();return false});v.before(O.html(P[g.selectedItemProp]).prepend(Q));g.selectionAdded.call(this,v.prev(),P[g.selectedValuesProp]);return v.prev()}function w(P){if(a(":visible",o).length>0){var x=a("li",o);if(P=="down"){var Q=x.eq(0)}else{var Q=x.filter(":last")}var O=a("li.active:first",o);if(O.length>0){if(P=="down"){Q=O.next()}else{Q=O.prev()}}x.removeClass("active");Q.addClass("active")}}function j(){if(f){f.abort();f=null}}})}}})(django.jQuery);
+
+(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/widgets.py

                         $("#%(result_id)s").val(tags_as_string);
                     });
                 });
-            })(django.jQuery);
+            })(jQuery);
             </script>""" % {
                 'result_id': result_attrs['id'],
                 'widget_id': widget_attrs['id'],