otwarchive-symphonyarchive/public/javascripts/jquery.tokeninput.min.js

2 lines
9.1 KiB
JavaScript
Raw Normal View History

2026-03-11 22:22:11 +00:00
(x=>{var R,e,t,n,o={hintText:"Type in a search term",noResultsText:"No results",searchingText:"Searching...",deleteText:"&times;",searchDelay:500,minChars:1,tokenLimit:null,jsonContainer:null,method:"GET",contentType:"json",queryParam:"q",tokenDelimiter:",",preventDuplicates:!1,prePopulate:null,processPrePopulate:!1,makeSortable:!1,escapeHTML:!0,animateDropdown:!0,onResult:null,onAdd:null,onDelete:null,noCache:!1},O={tokenList:"autocomplete",sortable:"sortable",token:"added tag",tokenDelete:"delete",selectedToken:"selected",highlightedToken:"highlighted",dropdown:"autocomplete dropdown",dropdownItem:"even",dropdownItem2:"odd",selectedDropdownItem:"selected",inputToken:"input",insertBefore:"selected",insertAfter:"selected"},N=0,_=1,j=2;KeyboardEvent.prototype.hasOwnProperty("key")?(e=!0,R={BACKSPACE:"Backspace",TAB:"Tab",ENTER:"Enter",ESCAPE:"Escape",SPACE:" ",PAGE_UP:"PageUp",PAGE_DOWN:"PageDown",END:"End",HOME:"Home",LEFT:"ArrowLeft",UP:"ArrowUp",RIGHT:"ArrowRight",DOWN:"ArrowDown",DELETE:"Delete",NUMPAD_ENTER:"Enter",COMMA:","}):(R={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,DELETE:46,NUMPAD_ENTER:108,COMMA:188},Object.defineProperty(KeyboardEvent.prototype,"key",{configurable:!0,enumerable:!0,get:function(){return this.keyCode}})),e&&(e=KeyboardEvent.prototype,t=Object.getOwnPropertyDescriptor(e,"key"),n={Spacebar:" ",Esc:"Escape",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete"},Object.defineProperty(e,"key",{configurable:!0,enumerable:!0,get:function(){var e=t.get.call(this);return n.hasOwnProperty(e)?n[e]:e}})),x.fn.tokenInput=function(e,t){var n=x.extend({},o,t||{});return this.each(function(){new x.TokenList(this,e,n)})},x.TokenList=function(e,t,l){"string"==typeof t?(l.url=t,void 0===l.crossDomain&&(-1===l.url.indexOf("://")?l.crossDomain=!1:l.crossDomain=location.href.split(/\/+/g)[1]!==l.url.split(/\/+/g)[1])):"object"==typeof t&&(l.local_data=t),l.classes?l.classes=x.extend({},O,l.classes):l.theme?(l.classes={},x.each(O,function(e,t){l.classes[e]=t+"-"+l.theme})):l.classes=O;var a,i=[],s=0,r=new x.TokenList.Cache,t=x(e).attr("id"),c=(x('label[for="'+t+'"]').attr({for:t+"_autocomplete"}),x('<input type="text" class="text" autocomplete="off" role="combobox" aria-expanded="true" aria-autocomplete="list">').attr({id:t+"_autocomplete"}).focus(function(){(null===l.tokenLimit||s<l.tokenLimit)&&(x(this).val().length>=l.minChars?setTimeout(function(){b()},5):l.hintText&&(g.html("<p class='notice'>"+l.hintText+"</p>"),n()))}).blur(function(){D()}).keydown(function(e){var t,n,o;switch(e.key){case R.LEFT:case R.RIGHT:case R.UP:case R.DOWN:if(h&&!h.is(":hidden"))return e.key===R.LEFT||e.key===R.RIGHT||(o=null,(o=f?e.key===R.DOWN?x(f).next():x(f).prev():h).length?(P(o),x(g).scrollTo(x(o))):e.key===R.UP&&f&&A(x(f)),!1);d?(t=x(d).prev(),n=x(d).next(),e.key===R.LEFT||e.key===R.UP?C(x(d),N):C(x(d),_)):(t=k.prev(),n=k.next()),e.key!==R.LEFT&&e.key!==R.UP||!t.length?e.key!==R.RIGHT&&e.key!==R.DOWN||!n.length||E(x(n.get(0))):E(x(t.get(0)));break;case R.BACKSPACE:case R.DELETE:if(t=k.prev(),!x(this).val().length)return d?y(x(d)):t.length&&E(x(t.get(0))),!1;1===x(this).val().length?D():setTimeout(function(){b()},25);break;case R.COMMA:case R.TAB:case R.ENTER:case R.NUMPAD_ENTER:if(f){if(T(x(f)),A(x(f)),D(),e.keyCode===R.TAB&&l.tokenLimit&&l.tokenLimit===s)break;return!1}if(c.val()){if(x.each(c.val().split(l.tokenDelimiter),function(e,t){T(x.trim(t))}),D(),e.keyCode===R.TAB&&l.tokenLimit&&l.tokenLimit===s)break;return!1}break;case R.ESCAPE:return D(),!0;default:String.fromCharCode(e.which)&&setTimeout(function(){b()},25)}}).keyup(function(){x(this).val().length<l.minChars&&(D(),clearTimeout(a))})),u=(x(e).closest("form").submit(function(){c.val()&&x.each(c.val().split(l.tokenDelimiter),function(e,t){T(x.trim(t))})}),x(e).hide().focus(function(){c.focus()}).blur(function(){c.blur()})),d=null,p=0,f=null,h=null,m=x("<ul />").addClass(l.classes.tokenList).click(function(e){e=x(e.target).closest("li");if(e&&e.get(0)&&x.data(e.get(0),"t