/* * jQuery Plugin: Tokenizing Autocomplete Text Entry * Version 1.6.2 * * Copyright (c) 2009 James Smith (http://loopj.com) * Licensed jointly under the GPL and MIT licenses, * choose which one suits your project best * */ var $jscomp={scope:{},findInternal:function(a,h,g){a instanceof String&&(a=String(a));for(var q=a.length,l=0;l"+(this.enableHTML?a:h(a))+""},tokenFormatter:function(a){a=a[this.propertyToSearch];return"
  • "+(this.enableHTML?a:h(a))+"

  • "},tokenLimit:null,tokenDelimiter:",",preventDuplicates:!1,tokenValue:"id",allowFreeTagging:!1,allowTabOut:!1,autoSelectFirstResult:!1,onResult:null,onCachedResult:null,onAdd:null,onFreeTaggingAdd:null,onDelete:null,onReady:null,idPrefix:"token-input-",disabled:!1},q={tokenList:"token-input-list", token:"token-input-token",tokenReadOnly:"token-input-token-readonly",tokenDelete:"token-input-delete-token",selectedToken:"token-input-selected-token",highlightedToken:"token-input-highlighted-token",dropdown:"token-input-dropdown",dropdownItem:"token-input-dropdown-item",dropdownItem2:"token-input-dropdown-item2",selectedDropdownItem:"token-input-selected-dropdown-item",inputToken:"token-input-input-token",focused:"token-input-focused",disabled:"token-input-disabled"},l={"&":"&","<":"<",">":">", '"':""","'":"'","/":"/"},A=/[&<>"'\/]/g,C={init:function(b,p){var h=a.extend({},g,p||{});return this.each(function(){a(this).data("settings",h);a(this).data("tokenInputObject",new a.TokenList(this,b,h))})},clear:function(){this.data("tokenInputObject").clear();return this},add:function(a){this.data("tokenInputObject").add(a);return this},remove:function(a){this.data("tokenInputObject").remove(a);return this},get:function(){return this.data("tokenInputObject").getTokens()},toggleDisabled:function(a){this.data("tokenInputObject").toggleDisabled(a); return this},setOptions:function(b){a(this).data("settings",a.extend({},a(this).data("settings"),b||{}));return this},destroy:function(){if(this.data("tokenInputObject")){this.data("tokenInputObject").clear();var a=this.parent();a.empty();this.show();a.append(this);return this}}};a.fn.tokenInput=function(a){return C[a]?C[a].apply(this,Array.prototype.slice.call(arguments,1)):C.init.apply(this,arguments)};a.TokenList=function(b,p,g){function l(c){return a(b).data("settings").enableHTML?c:h(c)}function O(c){"boolean"=== typeof c?a(b).data("settings").disabled=c:a(b).data("settings").disabled=!a(b).data("settings").disabled;f.attr("disabled",a(b).data("settings").disabled);r.toggleClass(a(b).data("settings").classes.disabled,a(b).data("settings").disabled);m&&B(a(m),2);n.attr("disabled",a(b).data("settings").disabled)}function P(){null!==a(b).data("settings").tokenLimit&&x>=a(b).data("settings").tokenLimit&&(f.hide(),y())}function A(){if(I!==(I=f.val())){var a=r.width()-f.offset().left-r.offset().left;Q.html(h(I)|| h(g.placeholder));f.width(Math.min(r.width(),Math.max(a,Q.width()+30)))}}function N(){var c=a.trim(f.val()).split(a(b).data("settings").tokenDelimiter);a.each(c,function(c,d){if(d){a.isFunction(a(b).data("settings").onFreeTaggingAdd)&&(d=a(b).data("settings").onFreeTaggingAdd.call(n,d));var e={};e[a(b).data("settings").tokenValue]=e[a(b).data("settings").propertyToSearch]=d;F(e)}})}function C(c){var e=a(a(b).data("settings").tokenFormatter(c)),d=!0===c.readonly;d&&e.addClass(a(b).data("settings").classes.tokenReadOnly); e.addClass(a(b).data("settings").classes.token).insertBefore(z);d||a(""+a(b).data("settings").deleteText+"").addClass(a(b).data("settings").classes.tokenDelete).appendTo(e).click(function(){if(!a(b).data("settings").disabled)return G(a(this).parent()),n.change(),!1});a.data(e.get(0),"tokeninput",c);u=u.slice(0,v).concat([c]).concat(u.slice(v));v++;R(u,n);x+=1;null!==a(b).data("settings").tokenLimit&&x>=a(b).data("settings").tokenLimit&&(f.hide(),y());return e}function F(c){var e=a(b).data("settings").onAdd; if(0v&&k--;c.remove();m=null;D(f);u=u.slice(0,k).concat(u.slice(k+1));0==u.length&&f.attr("placeholder",g.placeholder);k]*)("+ b.replace(S,"\\$&")+")(?![^<>]*>)(?![^&;]+;)","gi"),function(a,b){return""+l(b)+""})}function W(c){if(a(b).data("settings").excludeCurrent){var e=a(b).data("tokenInputObject").getTokens(),d=[];e.length&&(a.each(c,function(c,f){var k=!0;a.each(e,function(c,e){if(f[a(b).data("settings").propertyToSearch]==e[a(b).data("settings").propertyToSearch])return k=!1});k&&d.push(f)}),c=d)}return c}function J(c,e){if((e=W(e))&&e.length){w.empty();var d=a("
      ").appendTo(w).mouseover(function(b){K(a(b.target).closest("li"))}).mousedown(function(b){F(a(b.target).closest("li").data("tokeninput")); n.change();return!1}).hide();a(b).data("settings").resultsLimit&&e.length>a(b).data("settings").resultsLimit&&(e=e.slice(0,a(b).data("settings").resultsLimit));a.each(e,function(e,f){var g=a(b).data("settings").resultsFormatter(f),k=f[a(b).data("settings").propertyToSearch],g=g.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)("+k.replace(S,"\\$&")+")(?![^<>]*>)(?![^&;]+;)","g"),V(k,c)),g=a(g).appendTo(d);e%2?g.addClass(a(b).data("settings").classes.dropdownItem):g.addClass(a(b).data("settings").classes.dropdownItem2); 0===e&&a(b).data("settings").autoSelectFirstResult&&K(g);a.data(g.get(0),"tokeninput",f)});H();a(b).data("settings").animateDropdown?d.slideDown("fast"):d.show()}else a(b).data("settings").noResultsText&&(w.html("

      "+l(a(b).data("settings").noResultsText)+"

      "),H())}function K(c){c&&(t&&(a(t).removeClass(a(b).data("settings").classes.selectedDropdownItem),t=null),c.addClass(a(b).data("settings").classes.selectedDropdownItem),t=c.get(0))}function T(){var c=f.val();c&&c.length&&(m&&B(a(m),1),c.length>= a(b).data("settings").minChars?(a(b).data("settings").searchingText&&(w.html("

      "+l(a(b).data("settings").searchingText)+"

      "),H()),clearTimeout(U),U=setTimeout(function(){X(c)},a(b).data("settings").searchDelay)):y())}function X(c){var e=c+L(),d=M.get(e);if(d)a.isFunction(a(b).data("settings").onCachedResult)&&(d=a(b).data("settings").onCachedResult.call(n,d)),J(c,d);else if(a(b).data("settings").url){var d=L(),k={data:{}};-1').css({outline:"none"}).attr("id", a(b).data("settings").idPrefix+b.id).focus(function(){if(a(b).data("settings").disabled)return!1;null!==a(b).data("settings").tokenLimit&&a(b).data("settings").tokenLimit===x||!a(b).data("settings").hintText||(w.html("

      "+l(a(b).data("settings").hintText)+"

      "),H());r.addClass(a(b).data("settings").classes.focused)}).blur(function(){y();a(b).data("settings").allowFreeTagging&&N();a(this).val("");r.removeClass(a(b).data("settings").classes.focused)}).bind("keyup keydown blur update",A).keydown(function(c){var e, d;switch(c.keyCode){case 37:case 39:case 38:case 40:0===this.value.length?(e=z.prev(),d=z.next(),e.length&&e.get(0)===m||d.length&&d.get(0)===m?37===c.keyCode||38===c.keyCode?B(a(m),0):B(a(m),1):37!==c.keyCode&&38!==c.keyCode||!e.length?39!==c.keyCode&&40!==c.keyCode||!d.length||E(a(d.get(0))):E(a(e.get(0)))):(e=null,40===c.keyCode||39===c.keyCode?(e=a(w).find("li").first(),t&&(e=a(t).next())):(e=a(w).find("li").last(),t&&(e=a(t).prev())),K(e));break;case 8:e=z.prev();if(0===this.value.length)return m? (G(a(m)),n.change()):e.length&&E(a(e.get(0))),!1;1===a(this).val().length?y():setTimeout(function(){T()},5);break;case 9:case 13:case 108:case 188:if(t)F(a(t).data("tokeninput")),n.change();else{if(a(b).data("settings").allowFreeTagging){if(a(b).data("settings").allowTabOut&&""===a(this).val())return!0;N()}else if(a(this).val(""),a(b).data("settings").allowTabOut)return!0;c.stopPropagation();c.preventDefault()}return!1;case 27:return y(),!0;default:String.fromCharCode(c.which)&&setTimeout(function(){T()}, 5)}});g.placeholder&&f.attr("placeholder",g.placeholder);var n=a(b).hide().val("").focus(function(){D(f)}).blur(function(){f.blur();return n}),m=null,v=0,t=null,r=a("
        ").addClass(a(b).data("settings").classes.tokenList).click(function(b){if((b=a(b.target).closest("li"))&&b.get(0)&&a.data(b.get(0),"tokeninput")){var c=m;m&&B(a(m),2);c===b.get(0)?B(b,2):E(b)}else m&&B(a(m),2),D(f)}).mouseover(function(c){(c=a(c.target).closest("li"))&&m!==this&&c.addClass(a(b).data("settings").classes.highlightedToken)}).mouseout(function(c){(c= a(c.target).closest("li"))&&m!==this&&c.removeClass(a(b).data("settings").classes.highlightedToken)}).insertBefore(n),z=a("
      • ").addClass(a(b).data("settings").classes.inputToken).appendTo(r).append(f),w=a("
        ").addClass(a(b).data("settings").classes.dropdown).appendTo("body").hide(),Q=a("").insertAfter(f).css({position:"absolute",top:-9999,left:-9999,width:"auto",fontSize:f.css("fontSize"),fontFamily:f.css("fontFamily"),fontWeight:f.css("fontWeight"),letterSpacing:f.css("letterSpacing"), whiteSpace:"nowrap"});n.val("");p=a(b).data("settings").prePopulate||n.data("pre");a(b).data("settings").processPrePopulate&&a.isFunction(a(b).data("settings").onResult)&&(p=a(b).data("settings").onResult.call(n,p));p&&p.length&&a.each(p,function(a,b){C(b);P();f.attr("placeholder",null)});a(b).data("settings").disabled&&O(!0);"function"===typeof a(b).data("settings").onReady&&a(b).data("settings").onReady.call();this.clear=function(){r.children("li").each(function(){0===a(this).children("input").length&& G(a(this))})};this.add=function(a){F(a)};this.remove=function(b){r.children("li").each(function(){if(0===a(this).children("input").length){var c=a(this).data("tokeninput"),d=!0,f;for(f in b)if(b[f]!==c[f]){d=!1;break}d&&G(a(this))}})};this.getTokens=function(){return u};this.toggleDisabled=function(a){O(a)};A();var S=RegExp("[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\-]","g")};a.TokenList.Cache=function(b){var g,h={},l=0,q;g=a.extend({max_size:500},b);q=function(){h={};l=0};this.add=function(a,b){l>g.max_size&& q();h[a]||(l+=1);h[a]=b};this.get=function(a){return h[a]}}})(jQuery);