2 lines
9.1 KiB
JavaScript
2 lines
9.1 KiB
JavaScript
|
(function(e){var t={method:"GET",contentType:"json",queryParam:"name",searchDelay:300,minChars:1,propertyToSearch:"name",jsonContainer:null,hintText:"Type in a search term",noResultsText:"No results",searchingText:"Searching...",deleteText:"×",animateDropdown:true,tokenLimit:null,tokenDelimiter:",",preventDuplicates:false,tokenValue:"id",prePopulate:null,processPrePopulate:false,idPrefix:"token-input-",resultsFormatter:function(e){return"<li>"+e[this.propertyToSearch]+"</li>"},tokenFormatter:function(e){return"<li><p>"+e[this.propertyToSearch]+"</p></li>"},onResult:null,onAdd:null,onDelete:null,onReady:null};var n={tokenList:"token-input-list",token:"token-input-token",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"};var r={BEFORE:0,AFTER:1,END:2};var i={BACKSPACE:8,TAB:9,ENTER:13,ESCAPE:27,SPACE:32,PAGE_UP:33,PAGE_DOWN:34,END:35,HOME:36,LEFT:37,UP:38,RIGHT:39,DOWN:40,NUMPAD_ENTER:108,COMMA:188};var s={init:function(n,r){var i=e.extend({},t,r||{});return this.each(function(){e(this).data("tokenInputObject",new e.TokenList(this,n,i))})},clear:function(){this.data("tokenInputObject").clear();return this},add:function(e){this.data("tokenInputObject").add(e);return this},remove:function(e){this.data("tokenInputObject").remove(e);return this},get:function(){return this.data("tokenInputObject").getTokens()}};e.fn.tokenInput=function(e){if(s[e]){return s[e].apply(this,Array.prototype.slice.call(arguments,1))}else{return s.init.apply(this,arguments)}};e.TokenList=function(t,s,o){function x(){if(o.tokenLimit!==null&&f>=o.tokenLimit){p.hide();D();return}}function T(){if(h===(h=p.val())){return}var e=h.replace(/&/g,"&").replace(/\s/g," ").replace(/</g,"<").replace(/>/g,">");E.html(e);p.width(E.width()+30)}function N(e){return e>=48&&e<=90||e>=96&&e<=111||e>=186&&e<=192||e>=219&&e<=222}function C(t){var n=o.tokenFormatter(t);n=e(n).addClass(o.classes.token).insertBefore(b);e("<span>"+o.deleteText+"</span>").addClass(o.classes.tokenDelete).appendTo(n).click(function(){M(e(this).parent());d.change();return false});var r={id:t.id};r[o.propertyToSearch]=t[o.propertyToSearch];e.data(n.get(0),"tokeninput",t);a=a.slice(0,m).concat([r]).concat(a.slice(m));m++;_(a,d);f+=1;if(o.tokenLimit!==null&&f>=o.tokenLimit){p.hide();D()}return n}function k(t){var n=o.onAdd;if(f>0&&o.preventDuplicates){var r=null;y.children().each(function(){var n=e(this);var i=e.data(n.get(0),"tokeninput");if(i&&i.id===t.id){r=n;return false}});if(r){L(r);b.insertAfter(r);return}}if(o.tokenLimit==null||f<o.tokenLimit){C(t);x()}p.val("");D();if(e.isFunction(n)){n.call(d,t)}}function L(e){e.addClass(o.classes.selectedToken);v=e.get(0);p.val("");D()}function A(e,t){e.removeClass(o.classes.selectedToken);v=null;if(t===r.BEFORE){b.insertBefore(e);m--}else if(t===r.AFTER){b.insertAfter(e);m++}else{b.appendTo(y);m=f}p.focus()}function O(t){var n=v;if(v){A(e(v),r.END)}if(n===t.get(0)){A(t,r.END)}else{L(t)}}function M(t){var n=e.data(t.get(0),"tokeninput");var r=o.onDelete;var i=t.prevAll().length;if(i>m)i--;t.remove();v=null;p.focus();a=a.slice(0,i).concat(a.slice(i+1));if(i<m)m--;_(a,d);f-=1;if(o.tokenLimit!==null){p.show().val("").focus()}if(e.isFunction(r)){r.call(d,n)}}function _(t,n){var r=e.map(t,function(e){return e[o.tokenValue]});n.val(r.join(o.tokenDelimiter))}function D(){w.hide().empty();g=null}function P(){w.css({position:"absolute",top:e(y).offset().top+e(y).outerHeight(),left:e(y).offset().left,zindex:999}).show()}function H(){if(o.searchingText){w.html("<p>"+o.searchingText+"</p>");P()}}function B(){if(o.hintText){w.html("<p>"+o.hintText+"</p>");P()}}function j(e,t){return e.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)("+t+")(?![^<>]*>)(?![^&;]+;)","gi"),"<b>$1</b>")}function F(e,t,n){return e.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)("+t+")(?![^<>]*>)(?![^&;]+;
|