select2.amd.js 106 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685
  1. define(['jquery'], function ($) {define('select2/utils',[
  2. 'jquery'
  3. ], function ($) {
  4. var Utils = {};
  5. Utils.Extend = function (ChildClass, SuperClass) {
  6. var __hasProp = {}.hasOwnProperty;
  7. function BaseConstructor () {
  8. this.constructor = ChildClass;
  9. }
  10. for (var key in SuperClass) {
  11. if (__hasProp.call(SuperClass, key)) {
  12. ChildClass[key] = SuperClass[key];
  13. }
  14. }
  15. BaseConstructor.prototype = SuperClass.prototype;
  16. ChildClass.prototype = new BaseConstructor();
  17. ChildClass.__super__ = SuperClass.prototype;
  18. return ChildClass;
  19. };
  20. function getMethods (theClass) {
  21. var proto = theClass.prototype;
  22. var methods = [];
  23. for (var methodName in proto) {
  24. var m = proto[methodName];
  25. if (typeof m !== 'function') {
  26. continue;
  27. }
  28. if (methodName === 'constructor') {
  29. continue;
  30. }
  31. methods.push(methodName);
  32. }
  33. return methods;
  34. }
  35. Utils.Decorate = function (SuperClass, DecoratorClass) {
  36. var decoratedMethods = getMethods(DecoratorClass);
  37. var superMethods = getMethods(SuperClass);
  38. function DecoratedClass () {
  39. var unshift = Array.prototype.unshift;
  40. var argCount = DecoratorClass.prototype.constructor.length;
  41. var calledConstructor = SuperClass.prototype.constructor;
  42. if (argCount > 0) {
  43. unshift.call(arguments, SuperClass.prototype.constructor);
  44. calledConstructor = DecoratorClass.prototype.constructor;
  45. }
  46. calledConstructor.apply(this, arguments);
  47. }
  48. DecoratorClass.displayName = SuperClass.displayName;
  49. function ctr () {
  50. this.constructor = DecoratedClass;
  51. }
  52. DecoratedClass.prototype = new ctr();
  53. for (var m = 0; m < superMethods.length; m++) {
  54. var superMethod = superMethods[m];
  55. DecoratedClass.prototype[superMethod] =
  56. SuperClass.prototype[superMethod];
  57. }
  58. var calledMethod = function (methodName) {
  59. // Stub out the original method if it's not decorating an actual method
  60. var originalMethod = function () {};
  61. if (methodName in DecoratedClass.prototype) {
  62. originalMethod = DecoratedClass.prototype[methodName];
  63. }
  64. var decoratedMethod = DecoratorClass.prototype[methodName];
  65. return function () {
  66. var unshift = Array.prototype.unshift;
  67. unshift.call(arguments, originalMethod);
  68. return decoratedMethod.apply(this, arguments);
  69. };
  70. };
  71. for (var d = 0; d < decoratedMethods.length; d++) {
  72. var decoratedMethod = decoratedMethods[d];
  73. DecoratedClass.prototype[decoratedMethod] = calledMethod(decoratedMethod);
  74. }
  75. return DecoratedClass;
  76. };
  77. var Observable = function () {
  78. this.listeners = {};
  79. };
  80. Observable.prototype.on = function (event, callback) {
  81. this.listeners = this.listeners || {};
  82. if (event in this.listeners) {
  83. this.listeners[event].push(callback);
  84. } else {
  85. this.listeners[event] = [callback];
  86. }
  87. };
  88. Observable.prototype.trigger = function (event) {
  89. var slice = Array.prototype.slice;
  90. this.listeners = this.listeners || {};
  91. if (event in this.listeners) {
  92. this.invoke(this.listeners[event], slice.call(arguments, 1));
  93. }
  94. if ('*' in this.listeners) {
  95. this.invoke(this.listeners['*'], arguments);
  96. }
  97. };
  98. Observable.prototype.invoke = function (listeners, params) {
  99. for (var i = 0, len = listeners.length; i < len; i++) {
  100. listeners[i].apply(this, params);
  101. }
  102. };
  103. Utils.Observable = Observable;
  104. Utils.generateChars = function (length) {
  105. var chars = '';
  106. for (var i = 0; i < length; i++) {
  107. var randomChar = Math.floor(Math.random() * 36);
  108. chars += randomChar.toString(36);
  109. }
  110. return chars;
  111. };
  112. Utils.bind = function (func, context) {
  113. return function () {
  114. func.apply(context, arguments);
  115. };
  116. };
  117. Utils._convertData = function (data) {
  118. for (var originalKey in data) {
  119. var keys = originalKey.split('-');
  120. var dataLevel = data;
  121. if (keys.length === 1) {
  122. continue;
  123. }
  124. for (var k = 0; k < keys.length; k++) {
  125. var key = keys[k];
  126. // Lowercase the first letter
  127. // By default, dash-separated becomes camelCase
  128. key = key.substring(0, 1).toLowerCase() + key.substring(1);
  129. if (!(key in dataLevel)) {
  130. dataLevel[key] = {};
  131. }
  132. if (k == keys.length - 1) {
  133. dataLevel[key] = data[originalKey];
  134. }
  135. dataLevel = dataLevel[key];
  136. }
  137. delete data[originalKey];
  138. }
  139. return data;
  140. };
  141. Utils.hasScroll = function (index, el) {
  142. // Adapted from the function created by @ShadowScripter
  143. // and adapted by @BillBarry on the Stack Exchange Code Review website.
  144. // The original code can be found at
  145. // http://codereview.stackexchange.com/q/13338
  146. // and was designed to be used with the Sizzle selector engine.
  147. var $el = $(el);
  148. var overflowX = el.style.overflowX;
  149. var overflowY = el.style.overflowY;
  150. //Check both x and y declarations
  151. if (overflowX === overflowY &&
  152. (overflowY === 'hidden' || overflowY === 'visible')) {
  153. return false;
  154. }
  155. if (overflowX === 'scroll' || overflowY === 'scroll') {
  156. return true;
  157. }
  158. return ($el.innerHeight() < el.scrollHeight ||
  159. $el.innerWidth() < el.scrollWidth);
  160. };
  161. Utils.escapeMarkup = function (markup) {
  162. var replaceMap = {
  163. '\\': '&#92;',
  164. '&': '&amp;',
  165. '<': '&lt;',
  166. '>': '&gt;',
  167. '"': '&quot;',
  168. '\'': '&#39;',
  169. '/': '&#47;'
  170. };
  171. // Do not try to escape the markup if it's not a string
  172. if (typeof markup !== 'string') {
  173. return markup;
  174. }
  175. return String(markup).replace(/[&<>"'\/\\]/g, function (match) {
  176. return replaceMap[match];
  177. });
  178. };
  179. return Utils;
  180. });
  181. define('select2/results',[
  182. 'jquery',
  183. './utils'
  184. ], function ($, Utils) {
  185. function Results ($element, options, dataAdapter) {
  186. this.$element = $element;
  187. this.data = dataAdapter;
  188. this.options = options;
  189. Results.__super__.constructor.call(this);
  190. }
  191. Utils.Extend(Results, Utils.Observable);
  192. Results.prototype.render = function () {
  193. var $results = $(
  194. '<ul class="select2-results__options" role="tree"></ul>'
  195. );
  196. if (this.options.get('multiple')) {
  197. $results.attr('aria-multiselectable', 'true');
  198. }
  199. this.$results = $results;
  200. return $results;
  201. };
  202. Results.prototype.clear = function () {
  203. this.$results.empty();
  204. };
  205. Results.prototype.displayMessage = function (params) {
  206. var escapeMarkup = this.options.get('escapeMarkup');
  207. this.clear();
  208. this.hideLoading();
  209. var $message = $(
  210. '<li role="treeitem" class="select2-results__option"></li>'
  211. );
  212. var message = this.options.get('translations').get(params.message);
  213. $message.append(
  214. escapeMarkup(
  215. message(params.args)
  216. )
  217. );
  218. this.$results.append($message);
  219. };
  220. Results.prototype.append = function (data) {
  221. this.hideLoading();
  222. var $options = [];
  223. if (data.results == null || data.results.length === 0) {
  224. if (this.$results.children().length === 0) {
  225. this.trigger('results:message', {
  226. message: 'noResults'
  227. });
  228. }
  229. return;
  230. }
  231. data.results = this.sort(data.results);
  232. for (var d = 0; d < data.results.length; d++) {
  233. var item = data.results[d];
  234. var $option = this.option(item);
  235. $options.push($option);
  236. }
  237. this.$results.append($options);
  238. };
  239. Results.prototype.position = function ($results, $dropdown) {
  240. var $resultsContainer = $dropdown.find('.select2-results');
  241. $resultsContainer.append($results);
  242. };
  243. Results.prototype.sort = function (data) {
  244. var sorter = this.options.get('sorter');
  245. return sorter(data);
  246. };
  247. Results.prototype.setClasses = function () {
  248. var self = this;
  249. this.data.current(function (selected) {
  250. var selectedIds = $.map(selected, function (s) {
  251. return s.id.toString();
  252. });
  253. var $options = self.$results
  254. .find('.select2-results__option[aria-selected]');
  255. $options.each(function () {
  256. var $option = $(this);
  257. var item = $.data(this, 'data');
  258. if (item.id != null && selectedIds.indexOf(item.id.toString()) > -1) {
  259. $option.attr('aria-selected', 'true');
  260. } else {
  261. $option.attr('aria-selected', 'false');
  262. }
  263. });
  264. var $selected = $options.filter('[aria-selected=true]');
  265. // Check if there are any selected options
  266. if ($selected.length > 0) {
  267. // If there are selected options, highlight the first
  268. $selected.first().trigger('mouseenter');
  269. } else {
  270. // If there are no selected options, highlight the first option
  271. // in the dropdown
  272. $options.first().trigger('mouseenter');
  273. }
  274. });
  275. };
  276. Results.prototype.showLoading = function (params) {
  277. this.hideLoading();
  278. var loadingMore = this.options.get('translations').get('searching');
  279. var loading = {
  280. disabled: true,
  281. loading: true,
  282. text: loadingMore(params)
  283. };
  284. var $loading = this.option(loading);
  285. $loading.className += ' loading-results';
  286. this.$results.prepend($loading);
  287. };
  288. Results.prototype.hideLoading = function () {
  289. this.$results.find('.loading-results').remove();
  290. };
  291. Results.prototype.option = function (data) {
  292. var option = document.createElement('li');
  293. option.className = 'select2-results__option';
  294. var attrs = {
  295. 'role': 'treeitem',
  296. 'aria-selected': 'false'
  297. };
  298. if (data.disabled) {
  299. delete attrs['aria-selected'];
  300. attrs['aria-disabled'] = 'true';
  301. }
  302. if (data.id == null) {
  303. delete attrs['aria-selected'];
  304. }
  305. if (data._resultId != null) {
  306. option.id = data._resultId;
  307. }
  308. if (data.title) {
  309. option.title = data.title;
  310. }
  311. if (data.children) {
  312. attrs.role = 'group';
  313. attrs['aria-label'] = data.text;
  314. delete attrs['aria-selected'];
  315. }
  316. for (var attr in attrs) {
  317. var val = attrs[attr];
  318. option.setAttribute(attr, val);
  319. }
  320. if (data.children) {
  321. var $option = $(option);
  322. var label = document.createElement('strong');
  323. label.className = 'select2-results__group';
  324. var $label = $(label);
  325. this.template(data, label);
  326. var $children = [];
  327. for (var c = 0; c < data.children.length; c++) {
  328. var child = data.children[c];
  329. var $child = this.option(child);
  330. $children.push($child);
  331. }
  332. var $childrenContainer = $('<ul></ul>', {
  333. 'class': 'select2-results__options select2-results__options--nested'
  334. });
  335. $childrenContainer.append($children);
  336. $option.append(label);
  337. $option.append($childrenContainer);
  338. } else {
  339. this.template(data, option);
  340. }
  341. $.data(option, 'data', data);
  342. return option;
  343. };
  344. Results.prototype.bind = function (container, $container) {
  345. var self = this;
  346. var id = container.id + '-results';
  347. this.$results.attr('id', id);
  348. container.on('results:all', function (params) {
  349. self.clear();
  350. self.append(params.data);
  351. if (container.isOpen()) {
  352. self.setClasses();
  353. }
  354. });
  355. container.on('results:append', function (params) {
  356. self.append(params.data);
  357. if (container.isOpen()) {
  358. self.setClasses();
  359. }
  360. });
  361. container.on('query', function (params) {
  362. self.showLoading(params);
  363. });
  364. container.on('select', function () {
  365. if (!container.isOpen()) {
  366. return;
  367. }
  368. self.setClasses();
  369. });
  370. container.on('unselect', function () {
  371. if (!container.isOpen()) {
  372. return;
  373. }
  374. self.setClasses();
  375. });
  376. container.on('open', function () {
  377. // When the dropdown is open, aria-expended="true"
  378. self.$results.attr('aria-expanded', 'true');
  379. self.$results.attr('aria-hidden', 'false');
  380. self.setClasses();
  381. self.ensureHighlightVisible();
  382. });
  383. container.on('close', function () {
  384. // When the dropdown is closed, aria-expended="false"
  385. self.$results.attr('aria-expanded', 'false');
  386. self.$results.attr('aria-hidden', 'true');
  387. self.$results.removeAttr('aria-activedescendant');
  388. });
  389. container.on('results:select', function () {
  390. var $highlighted = self.getHighlightedResults();
  391. if ($highlighted.length === 0) {
  392. return;
  393. }
  394. var data = $highlighted.data('data');
  395. if ($highlighted.attr('aria-selected') == 'true') {
  396. if (self.options.get('multiple')) {
  397. self.trigger('unselect', {
  398. data: data
  399. });
  400. } else {
  401. self.trigger('close');
  402. }
  403. } else {
  404. self.trigger('select', {
  405. data: data
  406. });
  407. }
  408. });
  409. container.on('results:previous', function () {
  410. var $highlighted = self.getHighlightedResults();
  411. var $options = self.$results.find('[aria-selected]');
  412. var currentIndex = $options.index($highlighted);
  413. // If we are already at te top, don't move further
  414. if (currentIndex === 0) {
  415. return;
  416. }
  417. var nextIndex = currentIndex - 1;
  418. // If none are highlighted, highlight the first
  419. if ($highlighted.length === 0) {
  420. nextIndex = 0;
  421. }
  422. var $next = $options.eq(nextIndex);
  423. $next.trigger('mouseenter');
  424. var currentOffset = self.$results.offset().top;
  425. var nextTop = $next.offset().top;
  426. var nextOffset = self.$results.scrollTop() + (nextTop - currentOffset);
  427. if (nextIndex === 0) {
  428. self.$results.scrollTop(0);
  429. } else if (nextTop - currentOffset < 0) {
  430. self.$results.scrollTop(nextOffset);
  431. }
  432. });
  433. container.on('results:next', function () {
  434. var $highlighted = self.getHighlightedResults();
  435. var $options = self.$results.find('[aria-selected]');
  436. var currentIndex = $options.index($highlighted);
  437. var nextIndex = currentIndex + 1;
  438. // If we are at the last option, stay there
  439. if (nextIndex >= $options.length) {
  440. return;
  441. }
  442. var $next = $options.eq(nextIndex);
  443. $next.trigger('mouseenter');
  444. var currentOffset = self.$results.offset().top +
  445. self.$results.outerHeight(false);
  446. var nextBottom = $next.offset().top + $next.outerHeight(false);
  447. var nextOffset = self.$results.scrollTop() + nextBottom - currentOffset;
  448. if (nextIndex === 0) {
  449. self.$results.scrollTop(0);
  450. } else if (nextBottom > currentOffset) {
  451. self.$results.scrollTop(nextOffset);
  452. }
  453. });
  454. container.on('results:focus', function (params) {
  455. params.element.addClass('select2-results__option--highlighted');
  456. });
  457. container.on('results:message', function (params) {
  458. self.displayMessage(params);
  459. });
  460. if ($.fn.mousewheel) {
  461. this.$results.on('mousewheel', function (e) {
  462. var top = self.$results.scrollTop();
  463. var bottom = (
  464. self.$results.get(0).scrollHeight -
  465. self.$results.scrollTop() +
  466. e.deltaY
  467. );
  468. var isAtTop = e.deltaY > 0 && top - e.deltaY <= 0;
  469. var isAtBottom = e.deltaY < 0 && bottom <= self.$results.height();
  470. if (isAtTop) {
  471. self.$results.scrollTop(0);
  472. e.preventDefault();
  473. e.stopPropagation();
  474. } else if (isAtBottom) {
  475. self.$results.scrollTop(
  476. self.$results.get(0).scrollHeight - self.$results.height()
  477. );
  478. e.preventDefault();
  479. e.stopPropagation();
  480. }
  481. });
  482. }
  483. this.$results.on('mouseup', '.select2-results__option[aria-selected]',
  484. function (evt) {
  485. var $this = $(this);
  486. var data = $this.data('data');
  487. if ($this.attr('aria-selected') === 'true') {
  488. if (self.options.get('multiple')) {
  489. self.trigger('unselect', {
  490. originalEvent: evt,
  491. data: data
  492. });
  493. } else {
  494. self.trigger('close');
  495. }
  496. return;
  497. }
  498. self.trigger('select', {
  499. originalEvent: evt,
  500. data: data
  501. });
  502. });
  503. this.$results.on('mouseenter', '.select2-results__option[aria-selected]',
  504. function (evt) {
  505. var data = $(this).data('data');
  506. self.getHighlightedResults()
  507. .removeClass('select2-results__option--highlighted');
  508. self.trigger('results:focus', {
  509. data: data,
  510. element: $(this)
  511. });
  512. });
  513. };
  514. Results.prototype.getHighlightedResults = function () {
  515. var $highlighted = this.$results
  516. .find('.select2-results__option--highlighted');
  517. return $highlighted;
  518. };
  519. Results.prototype.destroy = function () {
  520. this.$results.remove();
  521. };
  522. Results.prototype.ensureHighlightVisible = function () {
  523. var $highlighted = this.getHighlightedResults();
  524. if ($highlighted.length === 0) {
  525. return;
  526. }
  527. var $options = this.$results.find('[aria-selected]');
  528. var currentIndex = $options.index($highlighted);
  529. var currentOffset = this.$results.offset().top;
  530. var nextTop = $highlighted.offset().top;
  531. var nextOffset = this.$results.scrollTop() + (nextTop - currentOffset);
  532. var offsetDelta = nextTop - currentOffset;
  533. nextOffset -= $highlighted.outerHeight(false) * 2;
  534. if (currentIndex <= 2) {
  535. this.$results.scrollTop(0);
  536. } else if (offsetDelta > this.$results.outerHeight() || offsetDelta < 0) {
  537. this.$results.scrollTop(nextOffset);
  538. }
  539. };
  540. Results.prototype.template = function (result, container) {
  541. var template = this.options.get('templateResult');
  542. var escapeMarkup = this.options.get('escapeMarkup');
  543. var content = template(result);
  544. if (content == null) {
  545. container.style.display = 'none';
  546. } else if (typeof content === 'string') {
  547. container.innerHTML = escapeMarkup(content);
  548. } else {
  549. $(container).append(content);
  550. }
  551. };
  552. return Results;
  553. });
  554. define('select2/keys',[
  555. ], function () {
  556. var KEYS = {
  557. BACKSPACE: 8,
  558. TAB: 9,
  559. ENTER: 13,
  560. SHIFT: 16,
  561. CTRL: 17,
  562. ALT: 18,
  563. ESC: 27,
  564. SPACE: 32,
  565. PAGE_UP: 33,
  566. PAGE_DOWN: 34,
  567. END: 35,
  568. HOME: 36,
  569. LEFT: 37,
  570. UP: 38,
  571. RIGHT: 39,
  572. DOWN: 40,
  573. DELETE: 46,
  574. isArrow: function (k) {
  575. k = k.which ? k.which : k;
  576. switch (k) {
  577. case KEY.LEFT:
  578. case KEY.RIGHT:
  579. case KEY.UP:
  580. case KEY.DOWN:
  581. return true;
  582. }
  583. return false;
  584. }
  585. };
  586. return KEYS;
  587. });
  588. define('select2/selection/base',[
  589. 'jquery',
  590. '../utils',
  591. '../keys'
  592. ], function ($, Utils, KEYS) {
  593. function BaseSelection ($element, options) {
  594. this.$element = $element;
  595. this.options = options;
  596. BaseSelection.__super__.constructor.call(this);
  597. }
  598. Utils.Extend(BaseSelection, Utils.Observable);
  599. BaseSelection.prototype.render = function () {
  600. var $selection = $(
  601. '<span class="select2-selection" tabindex="0" role="combobox" ' +
  602. 'aria-autocomplete="list" aria-haspopup="true" aria-expanded="false">' +
  603. '</span>'
  604. );
  605. $selection.attr('title', this.$element.attr('title'));
  606. this.$selection = $selection;
  607. return $selection;
  608. };
  609. BaseSelection.prototype.bind = function (container, $container) {
  610. var self = this;
  611. var id = container.id + '-container';
  612. var resultsId = container.id + '-results';
  613. this.container = container;
  614. this.$selection.attr('aria-owns', resultsId);
  615. this.$selection.on('keydown', function (evt) {
  616. self.trigger('keypress', evt);
  617. if (evt.which === KEYS.SPACE) {
  618. evt.preventDefault();
  619. }
  620. });
  621. container.on('results:focus', function (params) {
  622. self.$selection.attr('aria-activedescendant', params.data._resultId);
  623. });
  624. container.on('selection:update', function (params) {
  625. self.update(params.data);
  626. });
  627. container.on('open', function () {
  628. // When the dropdown is open, aria-expanded="true"
  629. self.$selection.attr('aria-expanded', 'true');
  630. self._attachCloseHandler(container);
  631. });
  632. container.on('close', function () {
  633. // When the dropdown is closed, aria-expanded="false"
  634. self.$selection.attr('aria-expanded', 'false');
  635. self.$selection.removeAttr('aria-activedescendant');
  636. self.$selection.focus();
  637. self._detachCloseHandler(container);
  638. });
  639. container.on('enable', function () {
  640. self.$selection.attr('tabindex', '0');
  641. });
  642. container.on('disable', function () {
  643. self.$selection.attr('tabindex', '-1');
  644. });
  645. };
  646. BaseSelection.prototype._attachCloseHandler = function (container) {
  647. var self = this;
  648. $(document.body).on('mousedown.select2.' + container.id, function (e) {
  649. var $target = $(e.target);
  650. var $select = $target.closest('.select2');
  651. var $all = $('.select2.select2-container--open');
  652. $all.each(function () {
  653. var $this = $(this);
  654. if (this == $select[0]) {
  655. return;
  656. }
  657. var $element = $this.data('element');
  658. $element.select2('close');
  659. });
  660. });
  661. };
  662. BaseSelection.prototype._detachCloseHandler = function (container) {
  663. $(document.body).off('mousedown.select2.' + container.id);
  664. };
  665. BaseSelection.prototype.position = function ($selection, $container) {
  666. var $selectionContainer = $container.find('.selection');
  667. $selectionContainer.append($selection);
  668. };
  669. BaseSelection.prototype.destroy = function () {
  670. this._detachCloseHandler(this.container);
  671. };
  672. BaseSelection.prototype.update = function (data) {
  673. throw new Error('The `update` method must be defined in child classes.');
  674. };
  675. return BaseSelection;
  676. });
  677. define('select2/selection/single',[
  678. 'jquery',
  679. './base',
  680. '../utils',
  681. '../keys'
  682. ], function ($, BaseSelection, Utils, KEYS) {
  683. function SingleSelection () {
  684. SingleSelection.__super__.constructor.apply(this, arguments);
  685. }
  686. Utils.Extend(SingleSelection, BaseSelection);
  687. SingleSelection.prototype.render = function () {
  688. var $selection = SingleSelection.__super__.render.call(this);
  689. $selection.addClass('select2-selection--single');
  690. $selection.html(
  691. '<span class="select2-selection__rendered"></span>' +
  692. '<span class="select2-selection__arrow" role="presentation">' +
  693. '<b role="presentation"></b>' +
  694. '</span>'
  695. );
  696. return $selection;
  697. };
  698. SingleSelection.prototype.bind = function (container, $container) {
  699. var self = this;
  700. SingleSelection.__super__.bind.apply(this, arguments);
  701. var id = container.id + '-container';
  702. this.$selection.find('.select2-selection__rendered').attr('id', id);
  703. this.$selection.attr('aria-labelledby', id);
  704. this.$selection.on('mousedown', function (evt) {
  705. // Only respond to left clicks
  706. if (evt.which !== 1) {
  707. return;
  708. }
  709. self.trigger('toggle', {
  710. originalEvent: evt
  711. });
  712. });
  713. this.$selection.on('focus', function (evt) {
  714. // User focuses on the container
  715. });
  716. this.$selection.on('blur', function (evt) {
  717. // User exits the container
  718. });
  719. container.on('selection:update', function (params) {
  720. self.update(params.data);
  721. });
  722. };
  723. SingleSelection.prototype.clear = function () {
  724. this.$selection.find('.select2-selection__rendered').empty();
  725. };
  726. SingleSelection.prototype.display = function (data) {
  727. var template = this.options.get('templateSelection');
  728. var escapeMarkup = this.options.get('escapeMarkup');
  729. return escapeMarkup(template(data));
  730. };
  731. SingleSelection.prototype.selectionContainer = function () {
  732. return $('<span></span>');
  733. };
  734. SingleSelection.prototype.update = function (data) {
  735. if (data.length === 0) {
  736. this.clear();
  737. return;
  738. }
  739. var selection = data[0];
  740. var formatted = this.display(selection);
  741. var $rendered = this.$selection.find('.select2-selection__rendered');
  742. $rendered.empty().append(formatted);
  743. $rendered.prop('title', selection.title || selection.text);
  744. };
  745. return SingleSelection;
  746. });
  747. define('select2/selection/multiple',[
  748. 'jquery',
  749. './base',
  750. '../utils'
  751. ], function ($, BaseSelection, Utils) {
  752. function MultipleSelection ($element, options) {
  753. MultipleSelection.__super__.constructor.apply(this, arguments);
  754. }
  755. Utils.Extend(MultipleSelection, BaseSelection);
  756. MultipleSelection.prototype.render = function () {
  757. var $selection = MultipleSelection.__super__.render.call(this);
  758. $selection.addClass('select2-selection--multiple');
  759. $selection.html(
  760. '<ul class="select2-selection__rendered"></ul>'
  761. );
  762. return $selection;
  763. };
  764. MultipleSelection.prototype.bind = function (container, $container) {
  765. var self = this;
  766. MultipleSelection.__super__.bind.apply(this, arguments);
  767. this.$selection.on('click', function (evt) {
  768. self.trigger('toggle', {
  769. originalEvent: evt
  770. });
  771. });
  772. this.$selection.on('click', '.select2-selection__choice__remove',
  773. function (evt) {
  774. var $remove = $(this);
  775. var $selection = $remove.parent();
  776. var data = $selection.data('data');
  777. self.trigger('unselect', {
  778. originalEvent: evt,
  779. data: data
  780. });
  781. });
  782. };
  783. MultipleSelection.prototype.clear = function () {
  784. this.$selection.find('.select2-selection__rendered').empty();
  785. };
  786. MultipleSelection.prototype.display = function (data) {
  787. var template = this.options.get('templateSelection');
  788. var escapeMarkup = this.options.get('escapeMarkup');
  789. return escapeMarkup(template(data));
  790. };
  791. MultipleSelection.prototype.selectionContainer = function () {
  792. var $container = $(
  793. '<li class="select2-selection__choice">' +
  794. '<span class="select2-selection__choice__remove" role="presentation">' +
  795. '&times;' +
  796. '</span>' +
  797. '</li>'
  798. );
  799. return $container;
  800. };
  801. MultipleSelection.prototype.update = function (data) {
  802. this.clear();
  803. if (data.length === 0) {
  804. return;
  805. }
  806. var $selections = [];
  807. for (var d = 0; d < data.length; d++) {
  808. var selection = data[d];
  809. var formatted = this.display(selection);
  810. var $selection = this.selectionContainer();
  811. $selection.append(formatted);
  812. $selection.prop('title', selection.title);
  813. $selection.data('data', selection);
  814. $selections.push($selection);
  815. }
  816. this.$selection.find('.select2-selection__rendered').append($selections);
  817. };
  818. return MultipleSelection;
  819. });
  820. define('select2/selection/placeholder',[
  821. '../utils'
  822. ], function (Utils) {
  823. function Placeholder (decorated, $element, options) {
  824. this.placeholder = this.normalizePlaceholder(options.get('placeholder'));
  825. decorated.call(this, $element, options);
  826. }
  827. Placeholder.prototype.normalizePlaceholder = function (_, placeholder) {
  828. if (typeof placeholder === 'string') {
  829. placeholder = {
  830. id: '',
  831. text: placeholder
  832. };
  833. }
  834. return placeholder;
  835. };
  836. Placeholder.prototype.createPlaceholder = function (decorated, placeholder) {
  837. var $placeholder = this.selectionContainer();
  838. $placeholder.html(this.display(placeholder));
  839. $placeholder.addClass('select2-selection__placeholder')
  840. .removeClass('select2-selection__choice');
  841. return $placeholder;
  842. };
  843. Placeholder.prototype.update = function (decorated, data) {
  844. var singlePlaceholder = (
  845. data.length == 1 && data[0].id != this.placeholder.id
  846. );
  847. var multipleSelections = data.length > 1;
  848. if (multipleSelections || singlePlaceholder) {
  849. return decorated.call(this, data);
  850. }
  851. this.clear();
  852. var $placeholder = this.createPlaceholder(this.placeholder);
  853. this.$selection.find('.select2-selection__rendered').append($placeholder);
  854. };
  855. return Placeholder;
  856. });
  857. define('select2/selection/allowClear',[
  858. 'jquery'
  859. ], function ($) {
  860. function AllowClear () { }
  861. AllowClear.prototype.bind = function (decorated, container, $container) {
  862. var self = this;
  863. decorated.call(this, container, $container);
  864. if (self.placeholder == null) {
  865. if (console && console.error) {
  866. console.error(
  867. 'Select2: The `allowClear` option should be used in combination ' +
  868. 'with the `placeholder` option.'
  869. );
  870. }
  871. }
  872. this.$selection.on('mousedown', '.select2-selection__clear',
  873. function (evt) {
  874. // Ignore the event if it is disabled
  875. if (self.options.get('disabled')) {
  876. return;
  877. }
  878. evt.stopPropagation();
  879. var data = $(this).data('data');
  880. for (var d = 0; d < data.length; d++) {
  881. var unselectData = {
  882. data: data[d]
  883. };
  884. // Trigger the `unselect` event, so people can prevent it from being
  885. // cleared.
  886. self.trigger('unselect', unselectData);
  887. // If the event was prevented, don't clear it out.
  888. if (unselectData.prevented) {
  889. return;
  890. }
  891. }
  892. self.$element.val(self.placeholder.id).trigger('change');
  893. self.trigger('toggle');
  894. });
  895. };
  896. AllowClear.prototype.update = function (decorated, data) {
  897. decorated.call(this, data);
  898. if (this.$selection.find('.select2-selection__placeholder').length > 0 ||
  899. data.length === 0) {
  900. return;
  901. }
  902. var $remove = $(
  903. '<span class="select2-selection__clear">' +
  904. '&times;' +
  905. '</span>'
  906. );
  907. $remove.data('data', data);
  908. this.$selection.find('.select2-selection__rendered').append($remove);
  909. };
  910. return AllowClear;
  911. });
  912. define('select2/selection/search',[
  913. 'jquery',
  914. '../utils',
  915. '../keys'
  916. ], function ($, Utils, KEYS) {
  917. function Search (decorated, $element, options) {
  918. decorated.call(this, $element, options);
  919. }
  920. Search.prototype.render = function (decorated) {
  921. var $search = $(
  922. '<li class="select2-search select2-search--inline">' +
  923. '<input class="select2-search__field" type="search" tabindex="-1"' +
  924. ' autocomplete="off" autocorrect="off" autocapitalize="off"' +
  925. ' spellcheck="false" role="textbox" />' +
  926. '</li>'
  927. );
  928. this.$searchContainer = $search;
  929. this.$search = $search.find('input');
  930. var $rendered = decorated.call(this);
  931. return $rendered;
  932. };
  933. Search.prototype.bind = function (decorated, container, $container) {
  934. var self = this;
  935. decorated.call(this, container, $container);
  936. container.on('open', function () {
  937. self.$search.attr('tabindex', 0);
  938. self.$search.focus();
  939. });
  940. container.on('close', function () {
  941. self.$search.attr('tabindex', -1);
  942. self.$search.val('');
  943. self.$search.focus();
  944. });
  945. container.on('enable', function () {
  946. self.$search.prop('disabled', false);
  947. });
  948. container.on('disable', function () {
  949. self.$search.prop('disabled', true);
  950. });
  951. this.$selection.on('keydown', '.select2-search--inline', function (evt) {
  952. evt.stopPropagation();
  953. if (!container.isOpen()) {
  954. self.trigger('open');
  955. }
  956. self.trigger('keypress', evt);
  957. self._keyUpPrevented = evt.isDefaultPrevented();
  958. var key = evt.which;
  959. if (key === KEYS.BACKSPACE && self.$search.val() === '') {
  960. var $previousChoice = self.$searchContainer
  961. .prev('.select2-selection__choice');
  962. if ($previousChoice.length > 0) {
  963. var item = $previousChoice.data('data');
  964. self.searchRemoveChoice(item);
  965. }
  966. }
  967. });
  968. this.$selection.on('keyup', '.select2-search--inline', function (evt) {
  969. self.handleSearch(evt);
  970. });
  971. };
  972. Search.prototype.createPlaceholder = function (decorated, placeholder) {
  973. this.$search.attr('placeholder', placeholder.text);
  974. };
  975. Search.prototype.update = function (decorated, data) {
  976. this.$search.attr('placeholder', '');
  977. decorated.call(this, data);
  978. this.$selection.find('.select2-selection__rendered')
  979. .append(this.$searchContainer);
  980. this.resizeSearch();
  981. };
  982. Search.prototype.handleSearch = function () {
  983. this.resizeSearch();
  984. if (!this._keyUpPrevented) {
  985. var input = this.$search.val();
  986. this.trigger('query', {
  987. term: input
  988. });
  989. }
  990. this._keyUpPrevented = false;
  991. };
  992. Search.prototype.searchRemoveChoice = function (decorated, item) {
  993. this.trigger('unselect', {
  994. data: item
  995. });
  996. this.trigger('open');
  997. this.$search.val(item.text + ' ');
  998. };
  999. Search.prototype.resizeSearch = function () {
  1000. this.$search.css('width', '25px');
  1001. var width = '';
  1002. if (this.$search.attr('placeholder') !== '') {
  1003. width = this.$selection.find('.select2-selection__rendered').innerWidth();
  1004. } else {
  1005. var minimumWidth = this.$search.val().length + 1;
  1006. width = (minimumWidth * 0.75) + 'em';
  1007. }
  1008. this.$search.css('width', width);
  1009. };
  1010. return Search;
  1011. });
  1012. define('select2/selection/eventRelay',[
  1013. 'jquery'
  1014. ], function ($) {
  1015. function EventRelay () { }
  1016. EventRelay.prototype.bind = function (decorated, container, $container) {
  1017. var self = this;
  1018. var relayEvents = [
  1019. 'open', 'opening',
  1020. 'close', 'closing',
  1021. 'select', 'selecting',
  1022. 'unselect', 'unselecting'
  1023. ];
  1024. var preventableEvents = ['opening', 'closing', 'selecting', 'unselecting'];
  1025. decorated.call(this, container, $container);
  1026. container.on('*', function (name, params) {
  1027. // Ignore events that should not be relayed
  1028. if ($.inArray(name, relayEvents) === -1) {
  1029. return;
  1030. }
  1031. // The parameters should always be an object
  1032. params = params || {};
  1033. // Generate the jQuery event for the Select2 event
  1034. var evt = $.Event('select2:' + name, {
  1035. params: params
  1036. });
  1037. self.$element.trigger(evt);
  1038. // Only handle preventable events if it was one
  1039. if ($.inArray(name, preventableEvents) === -1) {
  1040. return;
  1041. }
  1042. params.prevented = evt.isDefaultPrevented();
  1043. });
  1044. };
  1045. return EventRelay;
  1046. });
  1047. define('select2/translation',[
  1048. 'jquery'
  1049. ], function ($) {
  1050. function Translation (dict) {
  1051. this.dict = dict || {};
  1052. }
  1053. Translation.prototype.all = function () {
  1054. return this.dict;
  1055. };
  1056. Translation.prototype.get = function (key) {
  1057. return this.dict[key];
  1058. };
  1059. Translation.prototype.extend = function (translation) {
  1060. this.dict = $.extend({}, translation.all(), this.dict);
  1061. };
  1062. // Static functions
  1063. Translation._cache = {};
  1064. Translation.loadPath = function (path) {
  1065. if (!(path in Translation._cache)) {
  1066. var translations = require(path);
  1067. Translation._cache[path] = translations;
  1068. }
  1069. return new Translation(Translation._cache[path]);
  1070. };
  1071. return Translation;
  1072. });
  1073. define('select2/diacritics',[
  1074. ], function () {
  1075. var diacritics = {
  1076. '\u24B6': 'A',
  1077. '\uFF21': 'A',
  1078. '\u00C0': 'A',
  1079. '\u00C1': 'A',
  1080. '\u00C2': 'A',
  1081. '\u1EA6': 'A',
  1082. '\u1EA4': 'A',
  1083. '\u1EAA': 'A',
  1084. '\u1EA8': 'A',
  1085. '\u00C3': 'A',
  1086. '\u0100': 'A',
  1087. '\u0102': 'A',
  1088. '\u1EB0': 'A',
  1089. '\u1EAE': 'A',
  1090. '\u1EB4': 'A',
  1091. '\u1EB2': 'A',
  1092. '\u0226': 'A',
  1093. '\u01E0': 'A',
  1094. '\u00C4': 'A',
  1095. '\u01DE': 'A',
  1096. '\u1EA2': 'A',
  1097. '\u00C5': 'A',
  1098. '\u01FA': 'A',
  1099. '\u01CD': 'A',
  1100. '\u0200': 'A',
  1101. '\u0202': 'A',
  1102. '\u1EA0': 'A',
  1103. '\u1EAC': 'A',
  1104. '\u1EB6': 'A',
  1105. '\u1E00': 'A',
  1106. '\u0104': 'A',
  1107. '\u023A': 'A',
  1108. '\u2C6F': 'A',
  1109. '\uA732': 'AA',
  1110. '\u00C6': 'AE',
  1111. '\u01FC': 'AE',
  1112. '\u01E2': 'AE',
  1113. '\uA734': 'AO',
  1114. '\uA736': 'AU',
  1115. '\uA738': 'AV',
  1116. '\uA73A': 'AV',
  1117. '\uA73C': 'AY',
  1118. '\u24B7': 'B',
  1119. '\uFF22': 'B',
  1120. '\u1E02': 'B',
  1121. '\u1E04': 'B',
  1122. '\u1E06': 'B',
  1123. '\u0243': 'B',
  1124. '\u0182': 'B',
  1125. '\u0181': 'B',
  1126. '\u24B8': 'C',
  1127. '\uFF23': 'C',
  1128. '\u0106': 'C',
  1129. '\u0108': 'C',
  1130. '\u010A': 'C',
  1131. '\u010C': 'C',
  1132. '\u00C7': 'C',
  1133. '\u1E08': 'C',
  1134. '\u0187': 'C',
  1135. '\u023B': 'C',
  1136. '\uA73E': 'C',
  1137. '\u24B9': 'D',
  1138. '\uFF24': 'D',
  1139. '\u1E0A': 'D',
  1140. '\u010E': 'D',
  1141. '\u1E0C': 'D',
  1142. '\u1E10': 'D',
  1143. '\u1E12': 'D',
  1144. '\u1E0E': 'D',
  1145. '\u0110': 'D',
  1146. '\u018B': 'D',
  1147. '\u018A': 'D',
  1148. '\u0189': 'D',
  1149. '\uA779': 'D',
  1150. '\u01F1': 'DZ',
  1151. '\u01C4': 'DZ',
  1152. '\u01F2': 'Dz',
  1153. '\u01C5': 'Dz',
  1154. '\u24BA': 'E',
  1155. '\uFF25': 'E',
  1156. '\u00C8': 'E',
  1157. '\u00C9': 'E',
  1158. '\u00CA': 'E',
  1159. '\u1EC0': 'E',
  1160. '\u1EBE': 'E',
  1161. '\u1EC4': 'E',
  1162. '\u1EC2': 'E',
  1163. '\u1EBC': 'E',
  1164. '\u0112': 'E',
  1165. '\u1E14': 'E',
  1166. '\u1E16': 'E',
  1167. '\u0114': 'E',
  1168. '\u0116': 'E',
  1169. '\u00CB': 'E',
  1170. '\u1EBA': 'E',
  1171. '\u011A': 'E',
  1172. '\u0204': 'E',
  1173. '\u0206': 'E',
  1174. '\u1EB8': 'E',
  1175. '\u1EC6': 'E',
  1176. '\u0228': 'E',
  1177. '\u1E1C': 'E',
  1178. '\u0118': 'E',
  1179. '\u1E18': 'E',
  1180. '\u1E1A': 'E',
  1181. '\u0190': 'E',
  1182. '\u018E': 'E',
  1183. '\u24BB': 'F',
  1184. '\uFF26': 'F',
  1185. '\u1E1E': 'F',
  1186. '\u0191': 'F',
  1187. '\uA77B': 'F',
  1188. '\u24BC': 'G',
  1189. '\uFF27': 'G',
  1190. '\u01F4': 'G',
  1191. '\u011C': 'G',
  1192. '\u1E20': 'G',
  1193. '\u011E': 'G',
  1194. '\u0120': 'G',
  1195. '\u01E6': 'G',
  1196. '\u0122': 'G',
  1197. '\u01E4': 'G',
  1198. '\u0193': 'G',
  1199. '\uA7A0': 'G',
  1200. '\uA77D': 'G',
  1201. '\uA77E': 'G',
  1202. '\u24BD': 'H',
  1203. '\uFF28': 'H',
  1204. '\u0124': 'H',
  1205. '\u1E22': 'H',
  1206. '\u1E26': 'H',
  1207. '\u021E': 'H',
  1208. '\u1E24': 'H',
  1209. '\u1E28': 'H',
  1210. '\u1E2A': 'H',
  1211. '\u0126': 'H',
  1212. '\u2C67': 'H',
  1213. '\u2C75': 'H',
  1214. '\uA78D': 'H',
  1215. '\u24BE': 'I',
  1216. '\uFF29': 'I',
  1217. '\u00CC': 'I',
  1218. '\u00CD': 'I',
  1219. '\u00CE': 'I',
  1220. '\u0128': 'I',
  1221. '\u012A': 'I',
  1222. '\u012C': 'I',
  1223. '\u0130': 'I',
  1224. '\u00CF': 'I',
  1225. '\u1E2E': 'I',
  1226. '\u1EC8': 'I',
  1227. '\u01CF': 'I',
  1228. '\u0208': 'I',
  1229. '\u020A': 'I',
  1230. '\u1ECA': 'I',
  1231. '\u012E': 'I',
  1232. '\u1E2C': 'I',
  1233. '\u0197': 'I',
  1234. '\u24BF': 'J',
  1235. '\uFF2A': 'J',
  1236. '\u0134': 'J',
  1237. '\u0248': 'J',
  1238. '\u24C0': 'K',
  1239. '\uFF2B': 'K',
  1240. '\u1E30': 'K',
  1241. '\u01E8': 'K',
  1242. '\u1E32': 'K',
  1243. '\u0136': 'K',
  1244. '\u1E34': 'K',
  1245. '\u0198': 'K',
  1246. '\u2C69': 'K',
  1247. '\uA740': 'K',
  1248. '\uA742': 'K',
  1249. '\uA744': 'K',
  1250. '\uA7A2': 'K',
  1251. '\u24C1': 'L',
  1252. '\uFF2C': 'L',
  1253. '\u013F': 'L',
  1254. '\u0139': 'L',
  1255. '\u013D': 'L',
  1256. '\u1E36': 'L',
  1257. '\u1E38': 'L',
  1258. '\u013B': 'L',
  1259. '\u1E3C': 'L',
  1260. '\u1E3A': 'L',
  1261. '\u0141': 'L',
  1262. '\u023D': 'L',
  1263. '\u2C62': 'L',
  1264. '\u2C60': 'L',
  1265. '\uA748': 'L',
  1266. '\uA746': 'L',
  1267. '\uA780': 'L',
  1268. '\u01C7': 'LJ',
  1269. '\u01C8': 'Lj',
  1270. '\u24C2': 'M',
  1271. '\uFF2D': 'M',
  1272. '\u1E3E': 'M',
  1273. '\u1E40': 'M',
  1274. '\u1E42': 'M',
  1275. '\u2C6E': 'M',
  1276. '\u019C': 'M',
  1277. '\u24C3': 'N',
  1278. '\uFF2E': 'N',
  1279. '\u01F8': 'N',
  1280. '\u0143': 'N',
  1281. '\u00D1': 'N',
  1282. '\u1E44': 'N',
  1283. '\u0147': 'N',
  1284. '\u1E46': 'N',
  1285. '\u0145': 'N',
  1286. '\u1E4A': 'N',
  1287. '\u1E48': 'N',
  1288. '\u0220': 'N',
  1289. '\u019D': 'N',
  1290. '\uA790': 'N',
  1291. '\uA7A4': 'N',
  1292. '\u01CA': 'NJ',
  1293. '\u01CB': 'Nj',
  1294. '\u24C4': 'O',
  1295. '\uFF2F': 'O',
  1296. '\u00D2': 'O',
  1297. '\u00D3': 'O',
  1298. '\u00D4': 'O',
  1299. '\u1ED2': 'O',
  1300. '\u1ED0': 'O',
  1301. '\u1ED6': 'O',
  1302. '\u1ED4': 'O',
  1303. '\u00D5': 'O',
  1304. '\u1E4C': 'O',
  1305. '\u022C': 'O',
  1306. '\u1E4E': 'O',
  1307. '\u014C': 'O',
  1308. '\u1E50': 'O',
  1309. '\u1E52': 'O',
  1310. '\u014E': 'O',
  1311. '\u022E': 'O',
  1312. '\u0230': 'O',
  1313. '\u00D6': 'O',
  1314. '\u022A': 'O',
  1315. '\u1ECE': 'O',
  1316. '\u0150': 'O',
  1317. '\u01D1': 'O',
  1318. '\u020C': 'O',
  1319. '\u020E': 'O',
  1320. '\u01A0': 'O',
  1321. '\u1EDC': 'O',
  1322. '\u1EDA': 'O',
  1323. '\u1EE0': 'O',
  1324. '\u1EDE': 'O',
  1325. '\u1EE2': 'O',
  1326. '\u1ECC': 'O',
  1327. '\u1ED8': 'O',
  1328. '\u01EA': 'O',
  1329. '\u01EC': 'O',
  1330. '\u00D8': 'O',
  1331. '\u01FE': 'O',
  1332. '\u0186': 'O',
  1333. '\u019F': 'O',
  1334. '\uA74A': 'O',
  1335. '\uA74C': 'O',
  1336. '\u01A2': 'OI',
  1337. '\uA74E': 'OO',
  1338. '\u0222': 'OU',
  1339. '\u24C5': 'P',
  1340. '\uFF30': 'P',
  1341. '\u1E54': 'P',
  1342. '\u1E56': 'P',
  1343. '\u01A4': 'P',
  1344. '\u2C63': 'P',
  1345. '\uA750': 'P',
  1346. '\uA752': 'P',
  1347. '\uA754': 'P',
  1348. '\u24C6': 'Q',
  1349. '\uFF31': 'Q',
  1350. '\uA756': 'Q',
  1351. '\uA758': 'Q',
  1352. '\u024A': 'Q',
  1353. '\u24C7': 'R',
  1354. '\uFF32': 'R',
  1355. '\u0154': 'R',
  1356. '\u1E58': 'R',
  1357. '\u0158': 'R',
  1358. '\u0210': 'R',
  1359. '\u0212': 'R',
  1360. '\u1E5A': 'R',
  1361. '\u1E5C': 'R',
  1362. '\u0156': 'R',
  1363. '\u1E5E': 'R',
  1364. '\u024C': 'R',
  1365. '\u2C64': 'R',
  1366. '\uA75A': 'R',
  1367. '\uA7A6': 'R',
  1368. '\uA782': 'R',
  1369. '\u24C8': 'S',
  1370. '\uFF33': 'S',
  1371. '\u1E9E': 'S',
  1372. '\u015A': 'S',
  1373. '\u1E64': 'S',
  1374. '\u015C': 'S',
  1375. '\u1E60': 'S',
  1376. '\u0160': 'S',
  1377. '\u1E66': 'S',
  1378. '\u1E62': 'S',
  1379. '\u1E68': 'S',
  1380. '\u0218': 'S',
  1381. '\u015E': 'S',
  1382. '\u2C7E': 'S',
  1383. '\uA7A8': 'S',
  1384. '\uA784': 'S',
  1385. '\u24C9': 'T',
  1386. '\uFF34': 'T',
  1387. '\u1E6A': 'T',
  1388. '\u0164': 'T',
  1389. '\u1E6C': 'T',
  1390. '\u021A': 'T',
  1391. '\u0162': 'T',
  1392. '\u1E70': 'T',
  1393. '\u1E6E': 'T',
  1394. '\u0166': 'T',
  1395. '\u01AC': 'T',
  1396. '\u01AE': 'T',
  1397. '\u023E': 'T',
  1398. '\uA786': 'T',
  1399. '\uA728': 'TZ',
  1400. '\u24CA': 'U',
  1401. '\uFF35': 'U',
  1402. '\u00D9': 'U',
  1403. '\u00DA': 'U',
  1404. '\u00DB': 'U',
  1405. '\u0168': 'U',
  1406. '\u1E78': 'U',
  1407. '\u016A': 'U',
  1408. '\u1E7A': 'U',
  1409. '\u016C': 'U',
  1410. '\u00DC': 'U',
  1411. '\u01DB': 'U',
  1412. '\u01D7': 'U',
  1413. '\u01D5': 'U',
  1414. '\u01D9': 'U',
  1415. '\u1EE6': 'U',
  1416. '\u016E': 'U',
  1417. '\u0170': 'U',
  1418. '\u01D3': 'U',
  1419. '\u0214': 'U',
  1420. '\u0216': 'U',
  1421. '\u01AF': 'U',
  1422. '\u1EEA': 'U',
  1423. '\u1EE8': 'U',
  1424. '\u1EEE': 'U',
  1425. '\u1EEC': 'U',
  1426. '\u1EF0': 'U',
  1427. '\u1EE4': 'U',
  1428. '\u1E72': 'U',
  1429. '\u0172': 'U',
  1430. '\u1E76': 'U',
  1431. '\u1E74': 'U',
  1432. '\u0244': 'U',
  1433. '\u24CB': 'V',
  1434. '\uFF36': 'V',
  1435. '\u1E7C': 'V',
  1436. '\u1E7E': 'V',
  1437. '\u01B2': 'V',
  1438. '\uA75E': 'V',
  1439. '\u0245': 'V',
  1440. '\uA760': 'VY',
  1441. '\u24CC': 'W',
  1442. '\uFF37': 'W',
  1443. '\u1E80': 'W',
  1444. '\u1E82': 'W',
  1445. '\u0174': 'W',
  1446. '\u1E86': 'W',
  1447. '\u1E84': 'W',
  1448. '\u1E88': 'W',
  1449. '\u2C72': 'W',
  1450. '\u24CD': 'X',
  1451. '\uFF38': 'X',
  1452. '\u1E8A': 'X',
  1453. '\u1E8C': 'X',
  1454. '\u24CE': 'Y',
  1455. '\uFF39': 'Y',
  1456. '\u1EF2': 'Y',
  1457. '\u00DD': 'Y',
  1458. '\u0176': 'Y',
  1459. '\u1EF8': 'Y',
  1460. '\u0232': 'Y',
  1461. '\u1E8E': 'Y',
  1462. '\u0178': 'Y',
  1463. '\u1EF6': 'Y',
  1464. '\u1EF4': 'Y',
  1465. '\u01B3': 'Y',
  1466. '\u024E': 'Y',
  1467. '\u1EFE': 'Y',
  1468. '\u24CF': 'Z',
  1469. '\uFF3A': 'Z',
  1470. '\u0179': 'Z',
  1471. '\u1E90': 'Z',
  1472. '\u017B': 'Z',
  1473. '\u017D': 'Z',
  1474. '\u1E92': 'Z',
  1475. '\u1E94': 'Z',
  1476. '\u01B5': 'Z',
  1477. '\u0224': 'Z',
  1478. '\u2C7F': 'Z',
  1479. '\u2C6B': 'Z',
  1480. '\uA762': 'Z',
  1481. '\u24D0': 'a',
  1482. '\uFF41': 'a',
  1483. '\u1E9A': 'a',
  1484. '\u00E0': 'a',
  1485. '\u00E1': 'a',
  1486. '\u00E2': 'a',
  1487. '\u1EA7': 'a',
  1488. '\u1EA5': 'a',
  1489. '\u1EAB': 'a',
  1490. '\u1EA9': 'a',
  1491. '\u00E3': 'a',
  1492. '\u0101': 'a',
  1493. '\u0103': 'a',
  1494. '\u1EB1': 'a',
  1495. '\u1EAF': 'a',
  1496. '\u1EB5': 'a',
  1497. '\u1EB3': 'a',
  1498. '\u0227': 'a',
  1499. '\u01E1': 'a',
  1500. '\u00E4': 'a',
  1501. '\u01DF': 'a',
  1502. '\u1EA3': 'a',
  1503. '\u00E5': 'a',
  1504. '\u01FB': 'a',
  1505. '\u01CE': 'a',
  1506. '\u0201': 'a',
  1507. '\u0203': 'a',
  1508. '\u1EA1': 'a',
  1509. '\u1EAD': 'a',
  1510. '\u1EB7': 'a',
  1511. '\u1E01': 'a',
  1512. '\u0105': 'a',
  1513. '\u2C65': 'a',
  1514. '\u0250': 'a',
  1515. '\uA733': 'aa',
  1516. '\u00E6': 'ae',
  1517. '\u01FD': 'ae',
  1518. '\u01E3': 'ae',
  1519. '\uA735': 'ao',
  1520. '\uA737': 'au',
  1521. '\uA739': 'av',
  1522. '\uA73B': 'av',
  1523. '\uA73D': 'ay',
  1524. '\u24D1': 'b',
  1525. '\uFF42': 'b',
  1526. '\u1E03': 'b',
  1527. '\u1E05': 'b',
  1528. '\u1E07': 'b',
  1529. '\u0180': 'b',
  1530. '\u0183': 'b',
  1531. '\u0253': 'b',
  1532. '\u24D2': 'c',
  1533. '\uFF43': 'c',
  1534. '\u0107': 'c',
  1535. '\u0109': 'c',
  1536. '\u010B': 'c',
  1537. '\u010D': 'c',
  1538. '\u00E7': 'c',
  1539. '\u1E09': 'c',
  1540. '\u0188': 'c',
  1541. '\u023C': 'c',
  1542. '\uA73F': 'c',
  1543. '\u2184': 'c',
  1544. '\u24D3': 'd',
  1545. '\uFF44': 'd',
  1546. '\u1E0B': 'd',
  1547. '\u010F': 'd',
  1548. '\u1E0D': 'd',
  1549. '\u1E11': 'd',
  1550. '\u1E13': 'd',
  1551. '\u1E0F': 'd',
  1552. '\u0111': 'd',
  1553. '\u018C': 'd',
  1554. '\u0256': 'd',
  1555. '\u0257': 'd',
  1556. '\uA77A': 'd',
  1557. '\u01F3': 'dz',
  1558. '\u01C6': 'dz',
  1559. '\u24D4': 'e',
  1560. '\uFF45': 'e',
  1561. '\u00E8': 'e',
  1562. '\u00E9': 'e',
  1563. '\u00EA': 'e',
  1564. '\u1EC1': 'e',
  1565. '\u1EBF': 'e',
  1566. '\u1EC5': 'e',
  1567. '\u1EC3': 'e',
  1568. '\u1EBD': 'e',
  1569. '\u0113': 'e',
  1570. '\u1E15': 'e',
  1571. '\u1E17': 'e',
  1572. '\u0115': 'e',
  1573. '\u0117': 'e',
  1574. '\u00EB': 'e',
  1575. '\u1EBB': 'e',
  1576. '\u011B': 'e',
  1577. '\u0205': 'e',
  1578. '\u0207': 'e',
  1579. '\u1EB9': 'e',
  1580. '\u1EC7': 'e',
  1581. '\u0229': 'e',
  1582. '\u1E1D': 'e',
  1583. '\u0119': 'e',
  1584. '\u1E19': 'e',
  1585. '\u1E1B': 'e',
  1586. '\u0247': 'e',
  1587. '\u025B': 'e',
  1588. '\u01DD': 'e',
  1589. '\u24D5': 'f',
  1590. '\uFF46': 'f',
  1591. '\u1E1F': 'f',
  1592. '\u0192': 'f',
  1593. '\uA77C': 'f',
  1594. '\u24D6': 'g',
  1595. '\uFF47': 'g',
  1596. '\u01F5': 'g',
  1597. '\u011D': 'g',
  1598. '\u1E21': 'g',
  1599. '\u011F': 'g',
  1600. '\u0121': 'g',
  1601. '\u01E7': 'g',
  1602. '\u0123': 'g',
  1603. '\u01E5': 'g',
  1604. '\u0260': 'g',
  1605. '\uA7A1': 'g',
  1606. '\u1D79': 'g',
  1607. '\uA77F': 'g',
  1608. '\u24D7': 'h',
  1609. '\uFF48': 'h',
  1610. '\u0125': 'h',
  1611. '\u1E23': 'h',
  1612. '\u1E27': 'h',
  1613. '\u021F': 'h',
  1614. '\u1E25': 'h',
  1615. '\u1E29': 'h',
  1616. '\u1E2B': 'h',
  1617. '\u1E96': 'h',
  1618. '\u0127': 'h',
  1619. '\u2C68': 'h',
  1620. '\u2C76': 'h',
  1621. '\u0265': 'h',
  1622. '\u0195': 'hv',
  1623. '\u24D8': 'i',
  1624. '\uFF49': 'i',
  1625. '\u00EC': 'i',
  1626. '\u00ED': 'i',
  1627. '\u00EE': 'i',
  1628. '\u0129': 'i',
  1629. '\u012B': 'i',
  1630. '\u012D': 'i',
  1631. '\u00EF': 'i',
  1632. '\u1E2F': 'i',
  1633. '\u1EC9': 'i',
  1634. '\u01D0': 'i',
  1635. '\u0209': 'i',
  1636. '\u020B': 'i',
  1637. '\u1ECB': 'i',
  1638. '\u012F': 'i',
  1639. '\u1E2D': 'i',
  1640. '\u0268': 'i',
  1641. '\u0131': 'i',
  1642. '\u24D9': 'j',
  1643. '\uFF4A': 'j',
  1644. '\u0135': 'j',
  1645. '\u01F0': 'j',
  1646. '\u0249': 'j',
  1647. '\u24DA': 'k',
  1648. '\uFF4B': 'k',
  1649. '\u1E31': 'k',
  1650. '\u01E9': 'k',
  1651. '\u1E33': 'k',
  1652. '\u0137': 'k',
  1653. '\u1E35': 'k',
  1654. '\u0199': 'k',
  1655. '\u2C6A': 'k',
  1656. '\uA741': 'k',
  1657. '\uA743': 'k',
  1658. '\uA745': 'k',
  1659. '\uA7A3': 'k',
  1660. '\u24DB': 'l',
  1661. '\uFF4C': 'l',
  1662. '\u0140': 'l',
  1663. '\u013A': 'l',
  1664. '\u013E': 'l',
  1665. '\u1E37': 'l',
  1666. '\u1E39': 'l',
  1667. '\u013C': 'l',
  1668. '\u1E3D': 'l',
  1669. '\u1E3B': 'l',
  1670. '\u017F': 'l',
  1671. '\u0142': 'l',
  1672. '\u019A': 'l',
  1673. '\u026B': 'l',
  1674. '\u2C61': 'l',
  1675. '\uA749': 'l',
  1676. '\uA781': 'l',
  1677. '\uA747': 'l',
  1678. '\u01C9': 'lj',
  1679. '\u24DC': 'm',
  1680. '\uFF4D': 'm',
  1681. '\u1E3F': 'm',
  1682. '\u1E41': 'm',
  1683. '\u1E43': 'm',
  1684. '\u0271': 'm',
  1685. '\u026F': 'm',
  1686. '\u24DD': 'n',
  1687. '\uFF4E': 'n',
  1688. '\u01F9': 'n',
  1689. '\u0144': 'n',
  1690. '\u00F1': 'n',
  1691. '\u1E45': 'n',
  1692. '\u0148': 'n',
  1693. '\u1E47': 'n',
  1694. '\u0146': 'n',
  1695. '\u1E4B': 'n',
  1696. '\u1E49': 'n',
  1697. '\u019E': 'n',
  1698. '\u0272': 'n',
  1699. '\u0149': 'n',
  1700. '\uA791': 'n',
  1701. '\uA7A5': 'n',
  1702. '\u01CC': 'nj',
  1703. '\u24DE': 'o',
  1704. '\uFF4F': 'o',
  1705. '\u00F2': 'o',
  1706. '\u00F3': 'o',
  1707. '\u00F4': 'o',
  1708. '\u1ED3': 'o',
  1709. '\u1ED1': 'o',
  1710. '\u1ED7': 'o',
  1711. '\u1ED5': 'o',
  1712. '\u00F5': 'o',
  1713. '\u1E4D': 'o',
  1714. '\u022D': 'o',
  1715. '\u1E4F': 'o',
  1716. '\u014D': 'o',
  1717. '\u1E51': 'o',
  1718. '\u1E53': 'o',
  1719. '\u014F': 'o',
  1720. '\u022F': 'o',
  1721. '\u0231': 'o',
  1722. '\u00F6': 'o',
  1723. '\u022B': 'o',
  1724. '\u1ECF': 'o',
  1725. '\u0151': 'o',
  1726. '\u01D2': 'o',
  1727. '\u020D': 'o',
  1728. '\u020F': 'o',
  1729. '\u01A1': 'o',
  1730. '\u1EDD': 'o',
  1731. '\u1EDB': 'o',
  1732. '\u1EE1': 'o',
  1733. '\u1EDF': 'o',
  1734. '\u1EE3': 'o',
  1735. '\u1ECD': 'o',
  1736. '\u1ED9': 'o',
  1737. '\u01EB': 'o',
  1738. '\u01ED': 'o',
  1739. '\u00F8': 'o',
  1740. '\u01FF': 'o',
  1741. '\u0254': 'o',
  1742. '\uA74B': 'o',
  1743. '\uA74D': 'o',
  1744. '\u0275': 'o',
  1745. '\u01A3': 'oi',
  1746. '\u0223': 'ou',
  1747. '\uA74F': 'oo',
  1748. '\u24DF': 'p',
  1749. '\uFF50': 'p',
  1750. '\u1E55': 'p',
  1751. '\u1E57': 'p',
  1752. '\u01A5': 'p',
  1753. '\u1D7D': 'p',
  1754. '\uA751': 'p',
  1755. '\uA753': 'p',
  1756. '\uA755': 'p',
  1757. '\u24E0': 'q',
  1758. '\uFF51': 'q',
  1759. '\u024B': 'q',
  1760. '\uA757': 'q',
  1761. '\uA759': 'q',
  1762. '\u24E1': 'r',
  1763. '\uFF52': 'r',
  1764. '\u0155': 'r',
  1765. '\u1E59': 'r',
  1766. '\u0159': 'r',
  1767. '\u0211': 'r',
  1768. '\u0213': 'r',
  1769. '\u1E5B': 'r',
  1770. '\u1E5D': 'r',
  1771. '\u0157': 'r',
  1772. '\u1E5F': 'r',
  1773. '\u024D': 'r',
  1774. '\u027D': 'r',
  1775. '\uA75B': 'r',
  1776. '\uA7A7': 'r',
  1777. '\uA783': 'r',
  1778. '\u24E2': 's',
  1779. '\uFF53': 's',
  1780. '\u00DF': 's',
  1781. '\u015B': 's',
  1782. '\u1E65': 's',
  1783. '\u015D': 's',
  1784. '\u1E61': 's',
  1785. '\u0161': 's',
  1786. '\u1E67': 's',
  1787. '\u1E63': 's',
  1788. '\u1E69': 's',
  1789. '\u0219': 's',
  1790. '\u015F': 's',
  1791. '\u023F': 's',
  1792. '\uA7A9': 's',
  1793. '\uA785': 's',
  1794. '\u1E9B': 's',
  1795. '\u24E3': 't',
  1796. '\uFF54': 't',
  1797. '\u1E6B': 't',
  1798. '\u1E97': 't',
  1799. '\u0165': 't',
  1800. '\u1E6D': 't',
  1801. '\u021B': 't',
  1802. '\u0163': 't',
  1803. '\u1E71': 't',
  1804. '\u1E6F': 't',
  1805. '\u0167': 't',
  1806. '\u01AD': 't',
  1807. '\u0288': 't',
  1808. '\u2C66': 't',
  1809. '\uA787': 't',
  1810. '\uA729': 'tz',
  1811. '\u24E4': 'u',
  1812. '\uFF55': 'u',
  1813. '\u00F9': 'u',
  1814. '\u00FA': 'u',
  1815. '\u00FB': 'u',
  1816. '\u0169': 'u',
  1817. '\u1E79': 'u',
  1818. '\u016B': 'u',
  1819. '\u1E7B': 'u',
  1820. '\u016D': 'u',
  1821. '\u00FC': 'u',
  1822. '\u01DC': 'u',
  1823. '\u01D8': 'u',
  1824. '\u01D6': 'u',
  1825. '\u01DA': 'u',
  1826. '\u1EE7': 'u',
  1827. '\u016F': 'u',
  1828. '\u0171': 'u',
  1829. '\u01D4': 'u',
  1830. '\u0215': 'u',
  1831. '\u0217': 'u',
  1832. '\u01B0': 'u',
  1833. '\u1EEB': 'u',
  1834. '\u1EE9': 'u',
  1835. '\u1EEF': 'u',
  1836. '\u1EED': 'u',
  1837. '\u1EF1': 'u',
  1838. '\u1EE5': 'u',
  1839. '\u1E73': 'u',
  1840. '\u0173': 'u',
  1841. '\u1E77': 'u',
  1842. '\u1E75': 'u',
  1843. '\u0289': 'u',
  1844. '\u24E5': 'v',
  1845. '\uFF56': 'v',
  1846. '\u1E7D': 'v',
  1847. '\u1E7F': 'v',
  1848. '\u028B': 'v',
  1849. '\uA75F': 'v',
  1850. '\u028C': 'v',
  1851. '\uA761': 'vy',
  1852. '\u24E6': 'w',
  1853. '\uFF57': 'w',
  1854. '\u1E81': 'w',
  1855. '\u1E83': 'w',
  1856. '\u0175': 'w',
  1857. '\u1E87': 'w',
  1858. '\u1E85': 'w',
  1859. '\u1E98': 'w',
  1860. '\u1E89': 'w',
  1861. '\u2C73': 'w',
  1862. '\u24E7': 'x',
  1863. '\uFF58': 'x',
  1864. '\u1E8B': 'x',
  1865. '\u1E8D': 'x',
  1866. '\u24E8': 'y',
  1867. '\uFF59': 'y',
  1868. '\u1EF3': 'y',
  1869. '\u00FD': 'y',
  1870. '\u0177': 'y',
  1871. '\u1EF9': 'y',
  1872. '\u0233': 'y',
  1873. '\u1E8F': 'y',
  1874. '\u00FF': 'y',
  1875. '\u1EF7': 'y',
  1876. '\u1E99': 'y',
  1877. '\u1EF5': 'y',
  1878. '\u01B4': 'y',
  1879. '\u024F': 'y',
  1880. '\u1EFF': 'y',
  1881. '\u24E9': 'z',
  1882. '\uFF5A': 'z',
  1883. '\u017A': 'z',
  1884. '\u1E91': 'z',
  1885. '\u017C': 'z',
  1886. '\u017E': 'z',
  1887. '\u1E93': 'z',
  1888. '\u1E95': 'z',
  1889. '\u01B6': 'z',
  1890. '\u0225': 'z',
  1891. '\u0240': 'z',
  1892. '\u2C6C': 'z',
  1893. '\uA763': 'z',
  1894. '\u0386': '\u0391',
  1895. '\u0388': '\u0395',
  1896. '\u0389': '\u0397',
  1897. '\u038A': '\u0399',
  1898. '\u03AA': '\u0399',
  1899. '\u038C': '\u039F',
  1900. '\u038E': '\u03A5',
  1901. '\u03AB': '\u03A5',
  1902. '\u038F': '\u03A9',
  1903. '\u03AC': '\u03B1',
  1904. '\u03AD': '\u03B5',
  1905. '\u03AE': '\u03B7',
  1906. '\u03AF': '\u03B9',
  1907. '\u03CA': '\u03B9',
  1908. '\u0390': '\u03B9',
  1909. '\u03CC': '\u03BF',
  1910. '\u03CD': '\u03C5',
  1911. '\u03CB': '\u03C5',
  1912. '\u03B0': '\u03C5',
  1913. '\u03C9': '\u03C9',
  1914. '\u03C2': '\u03C3'
  1915. };
  1916. return diacritics;
  1917. });
  1918. define('select2/data/base',[
  1919. '../utils'
  1920. ], function (Utils) {
  1921. function BaseAdapter ($element, options) {
  1922. BaseAdapter.__super__.constructor.call(this);
  1923. }
  1924. Utils.Extend(BaseAdapter, Utils.Observable);
  1925. BaseAdapter.prototype.current = function (callback) {
  1926. throw new Error('The `current` method must be defined in child classes.');
  1927. };
  1928. BaseAdapter.prototype.query = function (params, callback) {
  1929. throw new Error('The `query` method must be defined in child classes.');
  1930. };
  1931. BaseAdapter.prototype.bind = function (container, $container) {
  1932. // Can be implemented in subclasses
  1933. };
  1934. BaseAdapter.prototype.destroy = function () {
  1935. // Can be implemented in subclasses
  1936. };
  1937. BaseAdapter.prototype.generateResultId = function (container, data) {
  1938. var id = container.id + '-result-';
  1939. id += Utils.generateChars(4);
  1940. if (data.id != null) {
  1941. id += '-' + data.id.toString();
  1942. } else {
  1943. id += '-' + Utils.generateChars(4);
  1944. }
  1945. return id;
  1946. };
  1947. return BaseAdapter;
  1948. });
  1949. define('select2/data/select',[
  1950. './base',
  1951. '../utils',
  1952. 'jquery'
  1953. ], function (BaseAdapter, Utils, $) {
  1954. function SelectAdapter ($element, options) {
  1955. this.$element = $element;
  1956. this.options = options;
  1957. SelectAdapter.__super__.constructor.call(this);
  1958. }
  1959. Utils.Extend(SelectAdapter, BaseAdapter);
  1960. SelectAdapter.prototype.current = function (callback) {
  1961. var data = [];
  1962. var self = this;
  1963. this.$element.find(':selected').each(function () {
  1964. var $option = $(this);
  1965. var option = self.item($option);
  1966. data.push(option);
  1967. });
  1968. callback(data);
  1969. };
  1970. SelectAdapter.prototype.select = function (data) {
  1971. var self = this;
  1972. // If data.element is a DOM nose, use it instead
  1973. if ($(data.element).is('option')) {
  1974. data.element.selected = true;
  1975. this.$element.trigger('change');
  1976. return;
  1977. }
  1978. if (this.$element.prop('multiple')) {
  1979. this.current(function (currentData) {
  1980. var val = [];
  1981. data = [data];
  1982. data.push.apply(data, currentData);
  1983. for (var d = 0; d < data.length; d++) {
  1984. id = data[d].id;
  1985. if (val.indexOf(id) === -1) {
  1986. val.push(id);
  1987. }
  1988. }
  1989. self.$element.val(val);
  1990. self.$element.trigger('change');
  1991. });
  1992. } else {
  1993. var val = data.id;
  1994. this.$element.val(val);
  1995. this.$element.trigger('change');
  1996. }
  1997. };
  1998. SelectAdapter.prototype.unselect = function (data) {
  1999. var self = this;
  2000. if (!this.$element.prop('multiple')) {
  2001. return;
  2002. }
  2003. if ($(data.element).is('option')) {
  2004. data.element.selected = false;
  2005. this.$element.trigger('change');
  2006. return;
  2007. }
  2008. this.current(function (currentData) {
  2009. var val = [];
  2010. for (var d = 0; d < currentData.length; d++) {
  2011. id = currentData[d].id;
  2012. if (id !== data.id && val.indexOf(id) === -1) {
  2013. val.push(id);
  2014. }
  2015. }
  2016. self.$element.val(val);
  2017. self.$element.trigger('change');
  2018. });
  2019. };
  2020. SelectAdapter.prototype.bind = function (container, $container) {
  2021. var self = this;
  2022. this.container = container;
  2023. container.on('select', function (params) {
  2024. self.select(params.data);
  2025. });
  2026. container.on('unselect', function (params) {
  2027. self.unselect(params.data);
  2028. });
  2029. };
  2030. SelectAdapter.prototype.destroy = function () {
  2031. // Remove anything added to child elements
  2032. this.$element.find('*').each(function () {
  2033. // Remove any custom data set by Select2
  2034. $.removeData(this, 'data');
  2035. });
  2036. };
  2037. SelectAdapter.prototype.query = function (params, callback) {
  2038. var data = [];
  2039. var self = this;
  2040. var $options = this.$element.children();
  2041. $options.each(function () {
  2042. var $option = $(this);
  2043. if (!$option.is('option') && !$option.is('optgroup')) {
  2044. return;
  2045. }
  2046. var option = self.item($option);
  2047. var matches = self.matches(params, option);
  2048. if (matches !== null) {
  2049. data.push(matches);
  2050. }
  2051. });
  2052. callback({
  2053. results: data
  2054. });
  2055. };
  2056. SelectAdapter.prototype.option = function (data) {
  2057. var option;
  2058. if (data.children) {
  2059. option = document.createElement('optgroup');
  2060. option.label = data.text;
  2061. } else {
  2062. option = document.createElement('option');
  2063. if (option.textContent !== undefined) {
  2064. option.textContent = data.text;
  2065. } else {
  2066. option.innerText = data.text;
  2067. }
  2068. }
  2069. if (data.id) {
  2070. option.value = data.id;
  2071. }
  2072. if (data.disabled) {
  2073. option.disabled = true;
  2074. }
  2075. if (data.selected) {
  2076. option.selected = true;
  2077. }
  2078. if (data.title) {
  2079. option.title = data.title;
  2080. }
  2081. var $option = $(option);
  2082. var normalizedData = this._normalizeItem(data);
  2083. normalizedData.element = option;
  2084. // Override the option's data with the combined data
  2085. $.data(option, 'data', normalizedData);
  2086. return $option;
  2087. };
  2088. SelectAdapter.prototype.item = function ($option) {
  2089. var data = {};
  2090. data = $.data($option[0], 'data');
  2091. if (data != null) {
  2092. return data;
  2093. }
  2094. if ($option.is('option')) {
  2095. data = {
  2096. id: $option.val(),
  2097. text: $option.html(),
  2098. disabled: $option.prop('disabled'),
  2099. selected: $option.prop('selected'),
  2100. title: $option.prop('title')
  2101. };
  2102. } else if ($option.is('optgroup')) {
  2103. data = {
  2104. text: $option.prop('label'),
  2105. children: [],
  2106. title: $option.prop('title')
  2107. };
  2108. var $children = $option.children('option');
  2109. var children = [];
  2110. for (var c = 0; c < $children.length; c++) {
  2111. var $child = $($children[c]);
  2112. var child = this.item($child);
  2113. children.push(child);
  2114. }
  2115. data.children = children;
  2116. }
  2117. data = this._normalizeItem(data);
  2118. data.element = $option[0];
  2119. $.data($option[0], 'data', data);
  2120. return data;
  2121. };
  2122. SelectAdapter.prototype._normalizeItem = function (item) {
  2123. if (!$.isPlainObject(item)) {
  2124. item = {
  2125. id: item,
  2126. text: item
  2127. };
  2128. }
  2129. item = $.extend({}, {
  2130. text: ''
  2131. }, item);
  2132. var defaults = {
  2133. selected: false,
  2134. disabled: false
  2135. };
  2136. if (item.id != null) {
  2137. item.id = item.id.toString();
  2138. }
  2139. if (item.text != null) {
  2140. item.text = item.text.toString();
  2141. }
  2142. if (item._resultId == null && item.id && this.container != null) {
  2143. item._resultId = this.generateResultId(this.container, item);
  2144. }
  2145. return $.extend({}, defaults, item);
  2146. };
  2147. SelectAdapter.prototype.matches = function (params, data) {
  2148. var matcher = this.options.get('matcher');
  2149. return matcher(params, data);
  2150. };
  2151. return SelectAdapter;
  2152. });
  2153. define('select2/data/array',[
  2154. './select',
  2155. '../utils',
  2156. 'jquery'
  2157. ], function (SelectAdapter, Utils, $) {
  2158. function ArrayAdapter ($element, options) {
  2159. var data = options.get('data') || [];
  2160. ArrayAdapter.__super__.constructor.call(this, $element, options);
  2161. $element.append(this.convertToOptions(data));
  2162. }
  2163. Utils.Extend(ArrayAdapter, SelectAdapter);
  2164. ArrayAdapter.prototype.select = function (data) {
  2165. var $option = this.$element.find('option[value="' + data.id + '"]');
  2166. if ($option.length === 0) {
  2167. $option = this.option(data);
  2168. this.$element.append($option);
  2169. }
  2170. ArrayAdapter.__super__.select.call(this, data);
  2171. };
  2172. ArrayAdapter.prototype.convertToOptions = function (data) {
  2173. var self = this;
  2174. var $existing = this.$element.find('option');
  2175. var existingIds = $existing.map(function () {
  2176. return self.item($(this)).id;
  2177. }).get();
  2178. var $options = [];
  2179. // Filter out all items except for the one passed in the argument
  2180. function onlyItem (item) {
  2181. return function () {
  2182. return $(this).val() == item.id;
  2183. };
  2184. }
  2185. for (var d = 0; d < data.length; d++) {
  2186. var item = this._normalizeItem(data[d]);
  2187. // Skip items which were pre-loaded, only merge the data
  2188. if ($.inArray(item.id, existingIds) >= 0) {
  2189. var $existingOption = $existing.filter(onlyItem(item));
  2190. var existingData = this.item($existingOption);
  2191. var newData = $.extend(true, {}, existingData, item);
  2192. var $newOption = this.option(existingData);
  2193. $existingOption.replaceWith($newOption);
  2194. continue;
  2195. }
  2196. var $option = this.option(item);
  2197. if (item.children) {
  2198. var $children = this.convertToOptions(item.children);
  2199. $option.append($children);
  2200. }
  2201. $options.push($option);
  2202. }
  2203. return $options;
  2204. };
  2205. return ArrayAdapter;
  2206. });
  2207. define('select2/data/ajax',[
  2208. './array',
  2209. '../utils',
  2210. 'jquery'
  2211. ], function (ArrayAdapter, Utils, $) {
  2212. function AjaxAdapter ($element, options) {
  2213. this.ajaxOptions = this._applyDefaults(options.get('ajax'));
  2214. if (this.ajaxOptions.processResults != null) {
  2215. this.processResults = this.ajaxOptions.processResults;
  2216. }
  2217. ArrayAdapter.__super__.constructor.call(this, $element, options);
  2218. }
  2219. Utils.Extend(AjaxAdapter, ArrayAdapter);
  2220. AjaxAdapter.prototype._applyDefaults = function (options) {
  2221. var defaults = {
  2222. data: function (params) {
  2223. return {
  2224. q: params.term
  2225. };
  2226. },
  2227. transport: function (params, success, failure) {
  2228. var $request = $.ajax(params);
  2229. $request.then(success);
  2230. $request.fail(failure);
  2231. return $request;
  2232. }
  2233. };
  2234. return $.extend({}, defaults, options, true);
  2235. };
  2236. AjaxAdapter.prototype.processResults = function (results) {
  2237. return results;
  2238. };
  2239. AjaxAdapter.prototype.query = function (params, callback) {
  2240. var matches = [];
  2241. var self = this;
  2242. if (this._request) {
  2243. this._request.abort();
  2244. this._request = null;
  2245. }
  2246. var options = $.extend({
  2247. type: 'GET'
  2248. }, this.ajaxOptions);
  2249. if (typeof options.url === 'function') {
  2250. options.url = options.url(params);
  2251. }
  2252. if (typeof options.data === 'function') {
  2253. options.data = options.data(params);
  2254. }
  2255. function request () {
  2256. var $request = options.transport(options, function (data) {
  2257. var results = self.processResults(data, params);
  2258. if (console && console.error) {
  2259. // Check to make sure that the response included a `results` key.
  2260. if (!results || !results.results || !$.isArray(results.results)) {
  2261. console.error(
  2262. 'Select2: The AJAX results did not return an array in the ' +
  2263. '`results` key of the response.'
  2264. );
  2265. }
  2266. }
  2267. callback(results);
  2268. }, function () {
  2269. // TODO: Handle AJAX errors
  2270. });
  2271. self._request = $request;
  2272. }
  2273. if (this.ajaxOptions.delay && params.term !== '') {
  2274. if (this._queryTimeout) {
  2275. window.clearTimeout(this._queryTimeout);
  2276. }
  2277. this._queryTimeout = window.setTimeout(request, this.ajaxOptions.delay);
  2278. } else {
  2279. request();
  2280. }
  2281. };
  2282. return AjaxAdapter;
  2283. });
  2284. define('select2/data/tags',[
  2285. 'jquery'
  2286. ], function ($) {
  2287. function Tags (decorated, $element, options) {
  2288. var tags = options.get('tags');
  2289. var createTag = options.get('createTag');
  2290. if (createTag !== undefined) {
  2291. this.createTag = createTag;
  2292. }
  2293. decorated.call(this, $element, options);
  2294. if ($.isArray(tags)) {
  2295. for (var t = 0; t < tags.length; t++) {
  2296. var tag = tags[t];
  2297. var item = this._normalizeItem(tag);
  2298. var $option = this.option(item);
  2299. this.$element.append($option);
  2300. }
  2301. }
  2302. }
  2303. Tags.prototype.query = function (decorated, params, callback) {
  2304. var self = this;
  2305. this._removeOldTags();
  2306. if (params.term == null || params.term === '' || params.page != null) {
  2307. decorated.call(this, params, callback);
  2308. return;
  2309. }
  2310. function wrapper (obj, child) {
  2311. var data = obj.results;
  2312. for (var i = 0; i < data.length; i++) {
  2313. var option = data[i];
  2314. var checkChildren = (
  2315. option.children != null &&
  2316. !wrapper({
  2317. results: option.children
  2318. }, true)
  2319. );
  2320. var checkText = option.text === params.term;
  2321. if (checkText || checkChildren) {
  2322. if (child) {
  2323. return false;
  2324. }
  2325. obj.data = data;
  2326. callback(obj);
  2327. return;
  2328. }
  2329. }
  2330. if (child) {
  2331. return true;
  2332. }
  2333. var tag = self.createTag(params);
  2334. if (tag != null) {
  2335. var $option = self.option(tag);
  2336. $option.attr('data-select2-tag', true);
  2337. self.$element.append($option);
  2338. self.insertTag(data, tag);
  2339. }
  2340. obj.results = data;
  2341. callback(obj);
  2342. }
  2343. decorated.call(this, params, wrapper);
  2344. };
  2345. Tags.prototype.createTag = function (decorated, params) {
  2346. return {
  2347. id: params.term,
  2348. text: params.term
  2349. };
  2350. };
  2351. Tags.prototype.insertTag = function (_, data, tag) {
  2352. data.unshift(tag);
  2353. };
  2354. Tags.prototype._removeOldTags = function (_) {
  2355. var tag = this._lastTag;
  2356. var $options = this.$element.find('option[data-select2-tag]');
  2357. $options.each(function () {
  2358. if (this.selected) {
  2359. return;
  2360. }
  2361. $(this).remove();
  2362. });
  2363. };
  2364. return Tags;
  2365. });
  2366. define('select2/data/tokenizer',[
  2367. 'jquery'
  2368. ], function ($) {
  2369. function Tokenizer (decorated, $element, options) {
  2370. var tokenizer = options.get('tokenizer');
  2371. if (tokenizer !== undefined) {
  2372. this.tokenizer = tokenizer;
  2373. }
  2374. decorated.call(this, $element, options);
  2375. }
  2376. Tokenizer.prototype.bind = function (decorated, container, $container) {
  2377. decorated.call(this, container, $container);
  2378. this.$search = container.dropdown.$search || container.selection.$search ||
  2379. $container.find('.select2-search__field');
  2380. };
  2381. Tokenizer.prototype.query = function (decorated, params, callback) {
  2382. var self = this;
  2383. function select (data) {
  2384. self.select(data);
  2385. }
  2386. params.term = params.term || '';
  2387. var tokenData = this.tokenizer(params, this.options, select);
  2388. if (tokenData.term !== params.term) {
  2389. // Replace the search term if we have the search box
  2390. if (this.$search.length) {
  2391. this.$search.val(tokenData.term);
  2392. this.$search.focus();
  2393. }
  2394. params.term = tokenData.term;
  2395. }
  2396. decorated.call(this, params, callback);
  2397. };
  2398. Tokenizer.prototype.tokenizer = function (_, params, options, callback) {
  2399. var separators = options.get('tokenSeparators') || [];
  2400. var term = params.term;
  2401. var i = 0;
  2402. var createTag = this.createTag || function (params) {
  2403. return {
  2404. id: params.term,
  2405. text: params.term
  2406. };
  2407. };
  2408. while (i < term.length) {
  2409. var termChar = term[i];
  2410. if (separators.indexOf(termChar) === -1) {
  2411. i++;
  2412. continue;
  2413. }
  2414. var part = term.substr(0, i);
  2415. var partParams = $.extend({}, params, {
  2416. term: part
  2417. });
  2418. var data = createTag(partParams);
  2419. callback(data);
  2420. // Reset the term to not include the tokenized portion
  2421. term = term.substr(i + 1) || '';
  2422. i = 0;
  2423. }
  2424. return {
  2425. term: term
  2426. };
  2427. };
  2428. return Tokenizer;
  2429. });
  2430. define('select2/data/minimumInputLength',[
  2431. ], function () {
  2432. function MinimumInputLength (decorated, $e, options) {
  2433. this.minimumInputLength = options.get('minimumInputLength');
  2434. decorated.call(this, $e, options);
  2435. }
  2436. MinimumInputLength.prototype.query = function (decorated, params, callback) {
  2437. params.term = params.term || '';
  2438. if (params.term.length < this.minimumInputLength) {
  2439. this.trigger('results:message', {
  2440. message: 'inputTooShort',
  2441. args: {
  2442. minimum: this.minimumInputLength,
  2443. input: params.term,
  2444. params: params
  2445. }
  2446. });
  2447. return;
  2448. }
  2449. decorated.call(this, params, callback);
  2450. };
  2451. return MinimumInputLength;
  2452. });
  2453. define('select2/data/maximumInputLength',[
  2454. ], function () {
  2455. function MaximumInputLength (decorated, $e, options) {
  2456. this.maximumInputLength = options.get('maximumInputLength');
  2457. decorated.call(this, $e, options);
  2458. }
  2459. MaximumInputLength.prototype.query = function (decorated, params, callback) {
  2460. params.term = params.term || '';
  2461. if (this.maximumInputLength > 0 &&
  2462. params.term.length > this.maximumInputLength) {
  2463. this.trigger('results:message', {
  2464. message: 'inputTooLong',
  2465. args: {
  2466. maximum: this.maximumInputLength,
  2467. input: params.term,
  2468. params: params
  2469. }
  2470. });
  2471. return;
  2472. }
  2473. decorated.call(this, params, callback);
  2474. };
  2475. return MaximumInputLength;
  2476. });
  2477. define('select2/data/maximumSelectionLength',[
  2478. ], function (){
  2479. function MaximumSelectionLength (decorated, $e, options) {
  2480. this.maximumSelectionLength = options.get('maximumSelectionLength');
  2481. decorated.call(this, $e, options);
  2482. }
  2483. MaximumSelectionLength.prototype.query =
  2484. function (decorated, params, callback) {
  2485. var self = this;
  2486. this.current(function (currentData) {
  2487. var count = currentData != null ? currentData.length : 0;
  2488. if (self.maximumSelectionLength > 0 &&
  2489. count >= self.maximumSelectionLength) {
  2490. self.trigger('results:message', {
  2491. message: 'maximumSelected',
  2492. args: {
  2493. maximum: self.maximumSelectionLength
  2494. }
  2495. });
  2496. return;
  2497. }
  2498. decorated.call(self, params, callback);
  2499. });
  2500. };
  2501. return MaximumSelectionLength;
  2502. });
  2503. define('select2/dropdown',[
  2504. 'jquery',
  2505. './utils'
  2506. ], function ($, Utils) {
  2507. function Dropdown ($element, options) {
  2508. this.$element = $element;
  2509. this.options = options;
  2510. Dropdown.__super__.constructor.call(this);
  2511. }
  2512. Utils.Extend(Dropdown, Utils.Observable);
  2513. Dropdown.prototype.render = function () {
  2514. var $dropdown = $(
  2515. '<span class="select2-dropdown">' +
  2516. '<span class="select2-results"></span>' +
  2517. '</span>'
  2518. );
  2519. $dropdown.attr('dir', this.options.get('dir'));
  2520. this.$dropdown = $dropdown;
  2521. return $dropdown;
  2522. };
  2523. Dropdown.prototype.position = function ($dropdown, $container) {
  2524. // Should be implmented in subclasses
  2525. };
  2526. Dropdown.prototype.destroy = function () {
  2527. // Remove the dropdown from the DOM
  2528. this.$dropdown.remove();
  2529. };
  2530. return Dropdown;
  2531. });
  2532. define('select2/dropdown/search',[
  2533. 'jquery',
  2534. '../utils'
  2535. ], function ($, Utils) {
  2536. function Search () { }
  2537. Search.prototype.render = function (decorated) {
  2538. var $rendered = decorated.call(this);
  2539. var $search = $(
  2540. '<span class="select2-search select2-search--dropdown">' +
  2541. '<input class="select2-search__field" type="search" tabindex="-1"' +
  2542. ' autocomplete="off" autocorrect="off" autocapitalize="off"' +
  2543. ' spellcheck="false" role="textbox" />' +
  2544. '</span>'
  2545. );
  2546. this.$searchContainer = $search;
  2547. this.$search = $search.find('input');
  2548. $rendered.prepend($search);
  2549. return $rendered;
  2550. };
  2551. Search.prototype.bind = function (decorated, container, $container) {
  2552. var self = this;
  2553. decorated.call(this, container, $container);
  2554. this.$search.on('keydown', function (evt) {
  2555. self.trigger('keypress', evt);
  2556. self._keyUpPrevented = evt.isDefaultPrevented();
  2557. });
  2558. this.$search.on('keyup', function (evt) {
  2559. self.handleSearch(evt);
  2560. });
  2561. container.on('open', function () {
  2562. self.$search.attr('tabindex', 0);
  2563. self.$search.focus();
  2564. window.setTimeout(function () {
  2565. self.$search.focus();
  2566. }, 0);
  2567. });
  2568. container.on('close', function () {
  2569. self.$search.attr('tabindex', -1);
  2570. self.$search.val('');
  2571. });
  2572. container.on('results:all', function (params) {
  2573. if (params.query.term == null || params.query.term === '') {
  2574. var showSearch = self.showSearch(params);
  2575. if (showSearch) {
  2576. self.$searchContainer.removeClass('select2-search--hide');
  2577. } else {
  2578. self.$searchContainer.addClass('select2-search--hide');
  2579. }
  2580. }
  2581. });
  2582. };
  2583. Search.prototype.handleSearch = function (evt) {
  2584. if (!this._keyUpPrevented) {
  2585. var input = this.$search.val();
  2586. this.trigger('query', {
  2587. term: input
  2588. });
  2589. }
  2590. this._keyUpPrevented = false;
  2591. };
  2592. Search.prototype.showSearch = function (_, params) {
  2593. return true;
  2594. };
  2595. return Search;
  2596. });
  2597. define('select2/dropdown/hidePlaceholder',[
  2598. ], function () {
  2599. function HidePlaceholder (decorated, $element, options, dataAdapter) {
  2600. this.placeholder = this.normalizePlaceholder(options.get('placeholder'));
  2601. decorated.call(this, $element, options, dataAdapter);
  2602. }
  2603. HidePlaceholder.prototype.append = function (decorated, data) {
  2604. data.results = this.removePlaceholder(data.results);
  2605. decorated.call(this, data);
  2606. };
  2607. HidePlaceholder.prototype.normalizePlaceholder = function (_, placeholder) {
  2608. if (typeof placeholder === 'string') {
  2609. placeholder = {
  2610. id: '',
  2611. text: placeholder
  2612. };
  2613. }
  2614. return placeholder;
  2615. };
  2616. HidePlaceholder.prototype.removePlaceholder = function (_, data) {
  2617. var modifiedData = data.slice(0);
  2618. for (var d = data.length - 1; d >= 0; d--) {
  2619. var item = data[d];
  2620. if (this.placeholder.id === item.id) {
  2621. modifiedData.splice(d, 1);
  2622. }
  2623. }
  2624. return modifiedData;
  2625. };
  2626. return HidePlaceholder;
  2627. });
  2628. define('select2/dropdown/infiniteScroll',[
  2629. 'jquery'
  2630. ], function ($) {
  2631. function InfiniteScroll (decorated, $element, options, dataAdapter) {
  2632. this.lastParams = {};
  2633. decorated.call(this, $element, options, dataAdapter);
  2634. this.$loadingMore = this.createLoadingMore();
  2635. this.loading = false;
  2636. }
  2637. InfiniteScroll.prototype.append = function (decorated, data) {
  2638. this.$loadingMore.remove();
  2639. this.loading = false;
  2640. decorated.call(this, data);
  2641. if (this.showLoadingMore(data)) {
  2642. this.$results.append(this.$loadingMore);
  2643. }
  2644. };
  2645. InfiniteScroll.prototype.bind = function (decorated, container, $container) {
  2646. var self = this;
  2647. decorated.call(this, container, $container);
  2648. container.on('query', function (params) {
  2649. self.lastParams = params;
  2650. self.loading = true;
  2651. });
  2652. container.on('query:append', function (params) {
  2653. self.lastParams = params;
  2654. self.loading = true;
  2655. });
  2656. this.$results.on('scroll', function () {
  2657. var isLoadMoreVisible = $.contains(
  2658. document.documentElement,
  2659. self.$loadingMore[0]
  2660. );
  2661. if (self.loading || !isLoadMoreVisible) {
  2662. return;
  2663. }
  2664. var currentOffset = self.$results.offset().top +
  2665. self.$results.outerHeight(false);
  2666. var loadingMoreOffset = self.$loadingMore.offset().top +
  2667. self.$loadingMore.outerHeight(false);
  2668. if (currentOffset + 50 >= loadingMoreOffset) {
  2669. self.loadMore();
  2670. }
  2671. });
  2672. };
  2673. InfiniteScroll.prototype.loadMore = function () {
  2674. this.loading = true;
  2675. var params = $.extend({}, {page: 1}, this.lastParams);
  2676. params.page++;
  2677. this.trigger('query:append', params);
  2678. };
  2679. InfiniteScroll.prototype.showLoadingMore = function (_, data) {
  2680. return data.pagination && data.pagination.more;
  2681. };
  2682. InfiniteScroll.prototype.createLoadingMore = function () {
  2683. var $option = $(
  2684. '<li class="option load-more" role="treeitem"></li>'
  2685. );
  2686. var message = this.options.get('translations').get('loadingMore');
  2687. $option.html(message(this.lastParams));
  2688. return $option;
  2689. };
  2690. return InfiniteScroll;
  2691. });
  2692. define('select2/dropdown/attachBody',[
  2693. 'jquery',
  2694. '../utils'
  2695. ], function ($, Utils) {
  2696. function AttachBody (decorated, $element, options) {
  2697. this.$dropdownParent = options.get('dropdownParent') || document.body;
  2698. decorated.call(this, $element, options);
  2699. }
  2700. AttachBody.prototype.bind = function (decorated, container, $container) {
  2701. var self = this;
  2702. var setupResultsEvents = false;
  2703. decorated.call(this, container, $container);
  2704. container.on('open', function () {
  2705. self._showDropdown();
  2706. self._attachPositioningHandler(container);
  2707. if (!setupResultsEvents) {
  2708. setupResultsEvents = true;
  2709. container.on('results:all', function () {
  2710. self._positionDropdown();
  2711. self._resizeDropdown();
  2712. });
  2713. container.on('results:append', function () {
  2714. self._positionDropdown();
  2715. self._resizeDropdown();
  2716. });
  2717. }
  2718. });
  2719. container.on('close', function () {
  2720. self._hideDropdown();
  2721. self._detachPositioningHandler(container);
  2722. });
  2723. this.$dropdownContainer.on('mousedown', function (evt) {
  2724. evt.stopPropagation();
  2725. });
  2726. };
  2727. AttachBody.prototype.position = function (decorated, $dropdown, $container) {
  2728. // Clone all of the container classes
  2729. $dropdown.attr('class', $container.attr('class'));
  2730. $dropdown.removeClass('select2');
  2731. $dropdown.addClass('select2-container--open');
  2732. $dropdown.css({
  2733. position: 'absolute',
  2734. top: -999999
  2735. });
  2736. this.$container = $container;
  2737. };
  2738. AttachBody.prototype.render = function (decorated) {
  2739. var $container = $('<span></span>');
  2740. var $dropdown = decorated.call(this);
  2741. $container.append($dropdown);
  2742. this.$dropdownContainer = $container;
  2743. return $container;
  2744. };
  2745. AttachBody.prototype._hideDropdown = function (decorated) {
  2746. this.$dropdownContainer.detach();
  2747. };
  2748. AttachBody.prototype._attachPositioningHandler = function (container) {
  2749. var self = this;
  2750. var scrollEvent = 'scroll.select2.' + container.id;
  2751. var resizeEvent = 'resize.select2.' + container.id;
  2752. var orientationEvent = 'orientationchange.select2.' + container.id;
  2753. $watchers = this.$container.parents().filter(Utils.hasScroll);
  2754. $watchers.each(function () {
  2755. $(this).data('select2-scroll-position', {
  2756. x: $(this).scrollLeft(),
  2757. y: $(this).scrollTop()
  2758. });
  2759. });
  2760. $watchers.on(scrollEvent, function (ev) {
  2761. var position = $(this).data('select2-scroll-position');
  2762. $(this).scrollTop(position.y);
  2763. });
  2764. $(window).on(scrollEvent + ' ' + resizeEvent + ' ' + orientationEvent,
  2765. function (e) {
  2766. self._positionDropdown();
  2767. self._resizeDropdown();
  2768. });
  2769. };
  2770. AttachBody.prototype._detachPositioningHandler = function (container) {
  2771. var scrollEvent = 'scroll.select2.' + container.id;
  2772. var resizeEvent = 'resize.select2.' + container.id;
  2773. var orientationEvent = 'orientationchange.select2.' + container.id;
  2774. $watchers = this.$container.parents().filter(Utils.hasScroll);
  2775. $watchers.off(scrollEvent);
  2776. $(window).off(scrollEvent + ' ' + resizeEvent + ' ' + orientationEvent);
  2777. };
  2778. AttachBody.prototype._positionDropdown = function () {
  2779. var $window = $(window);
  2780. var isCurrentlyAbove = this.$dropdown.hasClass('select2-dropdown--above');
  2781. var isCurrentlyBelow = this.$dropdown.hasClass('select2-dropdown--below');
  2782. var newDirection = null;
  2783. var position = this.$container.position();
  2784. var offset = this.$container.offset();
  2785. offset.bottom = offset.top + this.$container.outerHeight(false);
  2786. var container = {
  2787. height: this.$container.outerHeight(false)
  2788. };
  2789. container.top = offset.top;
  2790. container.bottom = offset.top + container.height;
  2791. var dropdown = {
  2792. height: this.$dropdown.outerHeight(false)
  2793. };
  2794. var viewport = {
  2795. top: $window.scrollTop(),
  2796. bottom: $window.scrollTop() + $window.height()
  2797. };
  2798. var enoughRoomAbove = viewport.top < (offset.top - dropdown.height);
  2799. var enoughRoomBelow = viewport.bottom > (offset.bottom + dropdown.height);
  2800. var css = {
  2801. left: offset.left,
  2802. top: container.bottom
  2803. };
  2804. if (!isCurrentlyAbove && !isCurrentlyBelow) {
  2805. newDirection = 'below';
  2806. }
  2807. if (!enoughRoomBelow && enoughRoomAbove && !isCurrentlyAbove) {
  2808. newDirection = 'above';
  2809. } else if (!enoughRoomAbove && enoughRoomBelow && isCurrentlyAbove) {
  2810. newDirection = 'below';
  2811. }
  2812. if (newDirection == 'above' ||
  2813. (isCurrentlyAbove && newDirection !== 'below')) {
  2814. css.top = container.top - dropdown.height;
  2815. }
  2816. if (newDirection != null) {
  2817. this.$dropdown
  2818. .removeClass('select2-dropdown--below select2-dropdown--above')
  2819. .addClass('select2-dropdown--' + newDirection);
  2820. this.$container
  2821. .removeClass('select2-container--below select2-container--above')
  2822. .addClass('select2-container--' + newDirection);
  2823. }
  2824. this.$dropdownContainer.css(css);
  2825. };
  2826. AttachBody.prototype._resizeDropdown = function () {
  2827. this.$dropdownContainer.width();
  2828. this.$dropdown.css({
  2829. width: this.$container.outerWidth(false) + 'px'
  2830. });
  2831. };
  2832. AttachBody.prototype._showDropdown = function (decorated) {
  2833. this.$dropdownContainer.appendTo(this.$dropdownParent);
  2834. this._positionDropdown();
  2835. this._resizeDropdown();
  2836. };
  2837. return AttachBody;
  2838. });
  2839. define('select2/dropdown/minimumResultsForSearch',[
  2840. ], function () {
  2841. function countResults (data) {
  2842. count = 0;
  2843. for (var d = 0; d < data.length; d++) {
  2844. var item = data[d];
  2845. if (item.children) {
  2846. count += countResults(item.children);
  2847. } else {
  2848. count++;
  2849. }
  2850. }
  2851. return count;
  2852. }
  2853. function MinimumResultsForSearch (decorated, $element, options, dataAdapter) {
  2854. this.minimumResultsForSearch = options.get('minimumResultsForSearch');
  2855. if (this.minimumResultsForSearch < 0) {
  2856. this.minimumResultsForSearch = Infinity;
  2857. }
  2858. decorated.call(this, $element, options, dataAdapter);
  2859. }
  2860. MinimumResultsForSearch.prototype.showSearch = function (decorated, params) {
  2861. if (countResults(params.data.results) < this.minimumResultsForSearch) {
  2862. return false;
  2863. }
  2864. return decorated.call(this, params);
  2865. };
  2866. return MinimumResultsForSearch;
  2867. });
  2868. define('select2/dropdown/selectOnClose',[
  2869. ], function () {
  2870. function SelectOnClose () { }
  2871. SelectOnClose.prototype.bind = function (decorated, container, $container) {
  2872. var self = this;
  2873. decorated.call(this, container, $container);
  2874. container.on('close', function () {
  2875. self._handleSelectOnClose();
  2876. });
  2877. };
  2878. SelectOnClose.prototype._handleSelectOnClose = function () {
  2879. var $highlightedResults = this.getHighlightedResults();
  2880. if ($highlightedResults.length < 1) {
  2881. return;
  2882. }
  2883. $highlightedResults.trigger('mouseup');
  2884. };
  2885. return SelectOnClose;
  2886. });
  2887. define('select2/dropdown/closeOnSelect',[
  2888. ], function () {
  2889. function CloseOnSelect () { }
  2890. CloseOnSelect.prototype.bind = function (decorated, container, $container) {
  2891. var self = this;
  2892. decorated.call(this, container, $container);
  2893. container.on('select', function (evt) {
  2894. var originalEvent = evt.originalEvent;
  2895. // Don't close if the control key is being held
  2896. if (originalEvent && originalEvent.ctrlKey) {
  2897. return;
  2898. }
  2899. self.trigger('close');
  2900. });
  2901. };
  2902. return CloseOnSelect;
  2903. });
  2904. define('select2/i18n/en',[],function () {
  2905. // English
  2906. return {
  2907. errorLoading: function () {
  2908. return 'The results could not be loaded.';
  2909. },
  2910. inputTooLong: function (args) {
  2911. var overChars = args.input.length - args.maximum;
  2912. var message = 'Please delete ' + overChars + ' character';
  2913. if (overChars != 1) {
  2914. message += 's';
  2915. }
  2916. return message;
  2917. },
  2918. inputTooShort: function (args) {
  2919. var remainingChars = args.minimum - args.input.length;
  2920. var message = 'Please enter ' + remainingChars + ' or more characters';
  2921. return message;
  2922. },
  2923. loadingMore: function () {
  2924. return 'Loading more results…';
  2925. },
  2926. maximumSelected: function (args) {
  2927. var message = 'You can only select ' + args.maximum + ' item';
  2928. if (args.maximum != 1) {
  2929. message += 's';
  2930. }
  2931. return message;
  2932. },
  2933. noResults: function () {
  2934. return 'No results found';
  2935. },
  2936. searching: function () {
  2937. return 'Searching…';
  2938. }
  2939. };
  2940. });
  2941. define('select2/defaults',[
  2942. 'jquery',
  2943. './results',
  2944. './selection/single',
  2945. './selection/multiple',
  2946. './selection/placeholder',
  2947. './selection/allowClear',
  2948. './selection/search',
  2949. './selection/eventRelay',
  2950. './utils',
  2951. './translation',
  2952. './diacritics',
  2953. './data/select',
  2954. './data/array',
  2955. './data/ajax',
  2956. './data/tags',
  2957. './data/tokenizer',
  2958. './data/minimumInputLength',
  2959. './data/maximumInputLength',
  2960. './data/maximumSelectionLength',
  2961. './dropdown',
  2962. './dropdown/search',
  2963. './dropdown/hidePlaceholder',
  2964. './dropdown/infiniteScroll',
  2965. './dropdown/attachBody',
  2966. './dropdown/minimumResultsForSearch',
  2967. './dropdown/selectOnClose',
  2968. './dropdown/closeOnSelect',
  2969. './i18n/en'
  2970. ], function ($, ResultsList,
  2971. SingleSelection, MultipleSelection, Placeholder, AllowClear,
  2972. SelectionSearch, EventRelay,
  2973. Utils, Translation, DIACRITICS,
  2974. SelectData, ArrayData, AjaxData, Tags, Tokenizer,
  2975. MinimumInputLength, MaximumInputLength, MaximumSelectionLength,
  2976. Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll,
  2977. AttachBody, MinimumResultsForSearch, SelectOnClose, CloseOnSelect,
  2978. EnglishTranslation) {
  2979. function Defaults () {
  2980. this.reset();
  2981. }
  2982. Defaults.prototype.apply = function (options) {
  2983. options = $.extend({}, this.defaults, options);
  2984. if (options.dataAdapter == null) {
  2985. if (options.ajax != null) {
  2986. options.dataAdapter = AjaxData;
  2987. } else if (options.data != null) {
  2988. options.dataAdapter = ArrayData;
  2989. } else {
  2990. options.dataAdapter = SelectData;
  2991. }
  2992. if (options.minimumInputLength > 0) {
  2993. options.dataAdapter = Utils.Decorate(
  2994. options.dataAdapter,
  2995. MinimumInputLength
  2996. );
  2997. }
  2998. if (options.maximumInputLength > 0) {
  2999. options.dataAdapter = Utils.Decorate(
  3000. options.dataAdapter,
  3001. MaximumInputLength
  3002. );
  3003. }
  3004. if (options.maximumSelectionLength > 0) {
  3005. options.dataAdapter = Utils.Decorate(
  3006. options.dataAdapter,
  3007. MaximumSelectionLength
  3008. );
  3009. }
  3010. if (options.tags != null) {
  3011. options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
  3012. }
  3013. if (options.tokenSeparators != null || options.tokenizer != null) {
  3014. options.dataAdapter = Utils.Decorate(
  3015. options.dataAdapter,
  3016. Tokenizer
  3017. );
  3018. }
  3019. if (options.query != null) {
  3020. var Query = require(options.amdBase + 'compat/query');
  3021. options.dataAdapter = Utils.Decorate(
  3022. options.dataAdapter,
  3023. Query
  3024. );
  3025. }
  3026. if (options.initSelection != null) {
  3027. var InitSelection = require(options.amdBase + 'compat/initSelection');
  3028. options.dataAdapter = Utils.Decorate(
  3029. options.dataAdapter,
  3030. InitSelection
  3031. );
  3032. }
  3033. }
  3034. if (options.resultsAdapter == null) {
  3035. options.resultsAdapter = ResultsList;
  3036. if (options.ajax != null) {
  3037. options.resultsAdapter = Utils.Decorate(
  3038. options.resultsAdapter,
  3039. InfiniteScroll
  3040. );
  3041. }
  3042. if (options.placeholder != null) {
  3043. options.resultsAdapter = Utils.Decorate(
  3044. options.resultsAdapter,
  3045. HidePlaceholder
  3046. );
  3047. }
  3048. if (options.selectOnClose) {
  3049. options.resultsAdapter = Utils.Decorate(
  3050. options.resultsAdapter,
  3051. SelectOnClose
  3052. );
  3053. }
  3054. }
  3055. if (options.dropdownAdapter == null) {
  3056. if (options.multiple) {
  3057. options.dropdownAdapter = Dropdown;
  3058. } else {
  3059. var SearchableDropdown = Utils.Decorate(Dropdown, DropdownSearch);
  3060. options.dropdownAdapter = SearchableDropdown;
  3061. }
  3062. if (options.minimumResultsForSearch > 0) {
  3063. options.dropdownAdapter = Utils.Decorate(
  3064. options.dropdownAdapter,
  3065. MinimumResultsForSearch
  3066. );
  3067. }
  3068. if (options.closeOnSelect) {
  3069. options.dropdownAdapter = Utils.Decorate(
  3070. options.dropdownAdapter,
  3071. CloseOnSelect
  3072. );
  3073. }
  3074. options.dropdownAdapter = Utils.Decorate(
  3075. options.dropdownAdapter,
  3076. AttachBody
  3077. );
  3078. }
  3079. if (options.selectionAdapter == null) {
  3080. if (options.multiple) {
  3081. options.selectionAdapter = MultipleSelection;
  3082. } else {
  3083. options.selectionAdapter = SingleSelection;
  3084. }
  3085. // Add the placeholder mixin if a placeholder was specified
  3086. if (options.placeholder != null) {
  3087. options.selectionAdapter = Utils.Decorate(
  3088. options.selectionAdapter,
  3089. Placeholder
  3090. );
  3091. }
  3092. if (options.allowClear) {
  3093. options.selectionAdapter = Utils.Decorate(
  3094. options.selectionAdapter,
  3095. AllowClear
  3096. );
  3097. }
  3098. if (options.multiple) {
  3099. options.selectionAdapter = Utils.Decorate(
  3100. options.selectionAdapter,
  3101. SelectionSearch
  3102. );
  3103. }
  3104. options.selectionAdapter = Utils.Decorate(
  3105. options.selectionAdapter,
  3106. EventRelay
  3107. );
  3108. }
  3109. if (typeof options.language === 'string') {
  3110. // Check if the lanugage is specified with a region
  3111. if (options.language.indexOf('-') > 0) {
  3112. // Extract the region information if it is included
  3113. var languageParts = options.language.split('-');
  3114. var baseLanguage = languageParts[0];
  3115. options.language = [options.language, baseLanguage];
  3116. } else {
  3117. options.language = [options.language];
  3118. }
  3119. }
  3120. if ($.isArray(options.language)) {
  3121. var languages = new Translation();
  3122. options.language.push('en');
  3123. var languageNames = options.language;
  3124. for (var l = 0; l < languageNames.length; l++) {
  3125. var name = languageNames[l];
  3126. var language = {};
  3127. try {
  3128. // Try to load it with the original name
  3129. language = Translation.loadPath(name);
  3130. } catch (e) {
  3131. try {
  3132. // If we couldn't load it, check if it wasn't the full path
  3133. name = this.defaults.amdLanguageBase + name;
  3134. language = Translation.loadPath(name);
  3135. } catch (ex) {
  3136. // The translation could not be loaded at all. Sometimes this is
  3137. // because of a configuration problem, other times this can be
  3138. // because of how Select2 helps load all possible translation files.
  3139. if (console && console.warn) {
  3140. console.warn(
  3141. 'Select2: The lanugage file for "' + name + '" could not be ' +
  3142. 'automatically loaded. A fallback will be used instead.'
  3143. );
  3144. }
  3145. continue;
  3146. }
  3147. }
  3148. languages.extend(language);
  3149. }
  3150. options.translations = languages;
  3151. } else {
  3152. options.translations = new Translation(options.language);
  3153. }
  3154. return options;
  3155. };
  3156. Defaults.prototype.reset = function () {
  3157. function stripDiacritics (text) {
  3158. // Used 'uni range + named function' from http://jsperf.com/diacritics/18
  3159. function match(a) {
  3160. return DIACRITICS[a] || a;
  3161. }
  3162. return text.replace(/[^\u0000-\u007E]/g, match);
  3163. }
  3164. function matcher (params, data) {
  3165. // Always return the object if there is nothing to compare
  3166. if ($.trim(params.term) === '') {
  3167. return data;
  3168. }
  3169. // Do a recursive check for options with children
  3170. if (data.children && data.children.length > 0) {
  3171. // Clone the data object if there are children
  3172. // This is required as we modify the object to remove any non-matches
  3173. var match = $.extend(true, {}, data);
  3174. // Check each child of the option
  3175. for (var c = data.children.length - 1; c >= 0; c--) {
  3176. var child = data.children[c];
  3177. var matches = matcher(params, child);
  3178. // If there wasn't a match, remove the object in the array
  3179. if (matches == null) {
  3180. match.children.splice(c, 1);
  3181. }
  3182. }
  3183. // If any children matched, return the new object
  3184. if (match.children.length > 0) {
  3185. return match;
  3186. }
  3187. // If there were no matching children, check just the plain object
  3188. return matcher(params, match);
  3189. }
  3190. var original = stripDiacritics(data.text).toUpperCase();
  3191. var term = stripDiacritics(params.term).toUpperCase();
  3192. // Check if the text contains the term
  3193. if (original.indexOf(term) > -1) {
  3194. return data;
  3195. }
  3196. // If it doesn't contain the term, don't return anything
  3197. return null;
  3198. }
  3199. this.defaults = {
  3200. amdBase: 'select2/',
  3201. amdLanguageBase: 'select2/i18n/',
  3202. closeOnSelect: true,
  3203. escapeMarkup: Utils.escapeMarkup,
  3204. language: EnglishTranslation,
  3205. matcher: matcher,
  3206. minimumInputLength: 0,
  3207. maximumInputLength: 0,
  3208. maximumSelectionLength: 0,
  3209. minimumResultsForSearch: 0,
  3210. selectOnClose: false,
  3211. sorter: function (data) {
  3212. return data;
  3213. },
  3214. templateResult: function (result) {
  3215. return result.text;
  3216. },
  3217. templateSelection: function (selection) {
  3218. return selection.text;
  3219. },
  3220. theme: 'default',
  3221. width: 'resolve'
  3222. };
  3223. };
  3224. Defaults.prototype.set = function (key, value) {
  3225. var camelKey = $.camelCase(key);
  3226. var data = {};
  3227. data[camelKey] = value;
  3228. var convertedData = Utils._convertData(data);
  3229. $.extend(this.defaults, convertedData);
  3230. };
  3231. var defaults = new Defaults();
  3232. return defaults;
  3233. });
  3234. define('select2/options',[
  3235. 'jquery',
  3236. './defaults',
  3237. './utils'
  3238. ], function ($, Defaults, Utils) {
  3239. function Options (options, $element) {
  3240. this.options = options;
  3241. if ($element != null) {
  3242. this.fromElement($element);
  3243. }
  3244. this.options = Defaults.apply(this.options);
  3245. }
  3246. Options.prototype.fromElement = function ($e) {
  3247. var excludedData = ['select2'];
  3248. if (this.options.multiple == null) {
  3249. this.options.multiple = $e.prop('multiple');
  3250. }
  3251. if (this.options.disabled == null) {
  3252. this.options.disabled = $e.prop('disabled');
  3253. }
  3254. if (this.options.language == null) {
  3255. if ($e.prop('lang')) {
  3256. this.options.language = $e.prop('lang').toLowerCase();
  3257. } else if ($e.closest('[lang]').prop('lang')) {
  3258. this.options.language = $e.closest('[lang]').prop('lang');
  3259. }
  3260. }
  3261. if (this.options.dir == null) {
  3262. if ($e.prop('dir')) {
  3263. this.options.dir = $e.prop('dir');
  3264. } else if ($e.closest('[dir]').prop('dir')) {
  3265. this.options.dir = $e.closest('[dir]').prop('dir');
  3266. } else {
  3267. this.options.dir = 'ltr';
  3268. }
  3269. }
  3270. $e.prop('disabled', this.options.disabled);
  3271. $e.prop('multiple', this.options.multiple);
  3272. if ($e.data('select2-tags')) {
  3273. if (console && console.warn) {
  3274. console.warn(
  3275. 'Select2: The `data-select2-tags` attribute has been changed to ' +
  3276. 'use the `data-data` and `data-tags="true"` attributes and will be ' +
  3277. 'removed in future versions of Select2.'
  3278. );
  3279. }
  3280. $e.data('data', $e.data('select2-tags'));
  3281. $e.data('tags', true);
  3282. }
  3283. if ($e.data('ajax-url')) {
  3284. if (console && console.warn) {
  3285. console.warn(
  3286. 'Select2: The `data-ajax-url` attribute has been changed to ' +
  3287. '`data-ajax--url` and support for the old attribute will be removed' +
  3288. ' in future versions of Select2.'
  3289. );
  3290. }
  3291. $e.data('ajax--url', $e.data('ajax-url'));
  3292. }
  3293. var data = $e.data();
  3294. data = Utils._convertData(data);
  3295. for (var key in data) {
  3296. if (excludedData.indexOf(key) > -1) {
  3297. continue;
  3298. }
  3299. if ($.isPlainObject(this.options[key])) {
  3300. $.extend(this.options[key], data[key]);
  3301. } else {
  3302. this.options[key] = data[key];
  3303. }
  3304. }
  3305. return this;
  3306. };
  3307. Options.prototype.get = function (key) {
  3308. return this.options[key];
  3309. };
  3310. Options.prototype.set = function (key, val) {
  3311. this.options[key] = val;
  3312. };
  3313. return Options;
  3314. });
  3315. define('select2/core',[
  3316. 'jquery',
  3317. './options',
  3318. './utils',
  3319. './keys'
  3320. ], function ($, Options, Utils, KEYS) {
  3321. var Select2 = function ($element, options) {
  3322. if ($element.data('select2') != null) {
  3323. $element.data('select2').destroy();
  3324. }
  3325. this.$element = $element;
  3326. this.id = this._generateId($element);
  3327. options = options || {};
  3328. this.options = new Options(options, $element);
  3329. Select2.__super__.constructor.call(this);
  3330. // Set up containers and adapters
  3331. var DataAdapter = this.options.get('dataAdapter');
  3332. this.data = new DataAdapter($element, this.options);
  3333. var $container = this.render();
  3334. this._placeContainer($container);
  3335. var SelectionAdapter = this.options.get('selectionAdapter');
  3336. this.selection = new SelectionAdapter($element, this.options);
  3337. this.$selection = this.selection.render();
  3338. this.selection.position(this.$selection, $container);
  3339. var DropdownAdapter = this.options.get('dropdownAdapter');
  3340. this.dropdown = new DropdownAdapter($element, this.options);
  3341. this.$dropdown = this.dropdown.render();
  3342. this.dropdown.position(this.$dropdown, $container);
  3343. var ResultsAdapter = this.options.get('resultsAdapter');
  3344. this.results = new ResultsAdapter($element, this.options, this.data);
  3345. this.$results = this.results.render();
  3346. this.results.position(this.$results, this.$dropdown);
  3347. // Bind events
  3348. var self = this;
  3349. // Bind the container to all of the adapters
  3350. this._bindAdapters();
  3351. // Register any DOM event handlers
  3352. this._registerDomEvents();
  3353. // Register any internal event handlers
  3354. this._registerDataEvents();
  3355. this._registerSelectionEvents();
  3356. this._registerDropdownEvents();
  3357. this._registerResultsEvents();
  3358. this._registerEvents();
  3359. // Set the initial state
  3360. this.data.current(function (initialData) {
  3361. self.trigger('selection:update', {
  3362. data: initialData
  3363. });
  3364. });
  3365. // Hide the original select
  3366. $element.hide();
  3367. // Synchronize any monitored attributes
  3368. this._syncAttributes();
  3369. this._tabindex = $element.attr('tabindex') || 0;
  3370. $element.attr('tabindex', '-1');
  3371. $element.data('select2', this);
  3372. };
  3373. Utils.Extend(Select2, Utils.Observable);
  3374. Select2.prototype._generateId = function ($element) {
  3375. var id = '';
  3376. if ($element.attr('id') != null) {
  3377. id = $element.attr('id');
  3378. } else if ($element.attr('name') != null) {
  3379. id = $element.attr('name') + '-' + Utils.generateChars(2);
  3380. } else {
  3381. id = Utils.generateChars(4);
  3382. }
  3383. id = 'select2-' + id;
  3384. return id;
  3385. };
  3386. Select2.prototype._placeContainer = function ($container) {
  3387. $container.insertAfter(this.$element);
  3388. var width = this._resolveWidth(this.$element, this.options.get('width'));
  3389. if (width != null) {
  3390. $container.css('width', width);
  3391. }
  3392. };
  3393. Select2.prototype._resolveWidth = function ($element, method) {
  3394. var WIDTH = /^width:(([-+]?([0-9]*\.)?[0-9]+)(px|em|ex|%|in|cm|mm|pt|pc))/i;
  3395. if (method == 'resolve') {
  3396. var styleWidth = this._resolveWidth($element, 'style');
  3397. if (styleWidth != null) {
  3398. return styleWidth;
  3399. }
  3400. return this._resolveWidth($element, 'element');
  3401. }
  3402. if (method == 'element') {
  3403. var elementWidth = $element.outerWidth(false);
  3404. if (elementWidth <= 0) {
  3405. return 'auto';
  3406. }
  3407. return elementWidth + 'px';
  3408. }
  3409. if (method == 'style') {
  3410. var style = $element.attr('style');
  3411. if (typeof(style) !== 'string') {
  3412. return null;
  3413. }
  3414. var attrs = style.split(';');
  3415. for (i = 0, l = attrs.length; i < l; i = i + 1) {
  3416. attr = attrs[i].replace(/\s/g, '');
  3417. var matches = attr.match(WIDTH);
  3418. if (matches !== null && matches.length >= 1) {
  3419. return matches[1];
  3420. }
  3421. }
  3422. return null;
  3423. }
  3424. return method;
  3425. };
  3426. Select2.prototype._bindAdapters = function () {
  3427. this.data.bind(this, this.$container);
  3428. this.selection.bind(this, this.$container);
  3429. this.dropdown.bind(this, this.$container);
  3430. this.results.bind(this, this.$container);
  3431. };
  3432. Select2.prototype._registerDomEvents = function () {
  3433. var self = this;
  3434. this.$element.on('change.select2', function () {
  3435. self.data.current(function (data) {
  3436. self.trigger('selection:update', {
  3437. data: data
  3438. });
  3439. });
  3440. });
  3441. this._sync = Utils.bind(this._syncAttributes, this);
  3442. if (this.$element[0].attachEvent) {
  3443. this.$element[0].attachEvent('onpropertychange', this._sync);
  3444. }
  3445. var observer = window.MutationObserver ||
  3446. window.WebKitMutationObserver ||
  3447. window.MozMutationObserver
  3448. ;
  3449. if (observer != null) {
  3450. this._observer = new observer(function (mutations) {
  3451. $.each(mutations, self._sync);
  3452. });
  3453. this._observer.observe(this.$element[0], {
  3454. attributes: true,
  3455. subtree: false
  3456. });
  3457. }
  3458. };
  3459. Select2.prototype._registerDataEvents = function () {
  3460. var self = this;
  3461. this.data.on('*', function (name, params) {
  3462. self.trigger(name, params);
  3463. });
  3464. };
  3465. Select2.prototype._registerSelectionEvents = function () {
  3466. var self = this;
  3467. var nonRelayEvents = ['toggle'];
  3468. this.selection.on('toggle', function () {
  3469. self.toggleDropdown();
  3470. });
  3471. this.selection.on('*', function (name, params) {
  3472. if ($.inArray(name, nonRelayEvents) !== -1) {
  3473. return;
  3474. }
  3475. self.trigger(name, params);
  3476. });
  3477. };
  3478. Select2.prototype._registerDropdownEvents = function () {
  3479. var self = this;
  3480. this.dropdown.on('*', function (name, params) {
  3481. self.trigger(name, params);
  3482. });
  3483. };
  3484. Select2.prototype._registerResultsEvents = function () {
  3485. var self = this;
  3486. this.results.on('*', function (name, params) {
  3487. self.trigger(name, params);
  3488. });
  3489. };
  3490. Select2.prototype._registerEvents = function () {
  3491. var self = this;
  3492. this.on('open', function () {
  3493. self.$container.addClass('select2-container--open');
  3494. });
  3495. this.on('close', function () {
  3496. self.$container.removeClass('select2-container--open');
  3497. });
  3498. this.on('enable', function () {
  3499. self.$container.removeClass('select2-container--disabled');
  3500. });
  3501. this.on('disable', function () {
  3502. self.$container.addClass('select2-container--disabled');
  3503. });
  3504. this.on('query', function (params) {
  3505. this.data.query(params, function (data) {
  3506. self.trigger('results:all', {
  3507. data: data,
  3508. query: params
  3509. });
  3510. });
  3511. });
  3512. this.on('query:append', function (params) {
  3513. this.data.query(params, function (data) {
  3514. self.trigger('results:append', {
  3515. data: data,
  3516. query: params
  3517. });
  3518. });
  3519. });
  3520. this.on('keypress', function (evt) {
  3521. var key = evt.which;
  3522. if (self.isOpen()) {
  3523. if (key === KEYS.ENTER) {
  3524. self.trigger('results:select');
  3525. evt.preventDefault();
  3526. } else if (key === KEYS.UP) {
  3527. self.trigger('results:previous');
  3528. evt.preventDefault();
  3529. } else if (key === KEYS.DOWN) {
  3530. self.trigger('results:next');
  3531. evt.preventDefault();
  3532. } else if (key === KEYS.ESC || key === KEYS.TAB) {
  3533. self.close();
  3534. evt.preventDefault();
  3535. }
  3536. } else {
  3537. if (key === KEYS.ENTER || key === KEYS.SPACE ||
  3538. ((key === KEYS.DOWN || key === KEYS.UP) && evt.altKey)) {
  3539. self.open();
  3540. evt.preventDefault();
  3541. }
  3542. }
  3543. });
  3544. };
  3545. Select2.prototype._syncAttributes = function () {
  3546. this.options.set('disabled', this.$element.prop('disabled'));
  3547. if (this.options.get('disabled')) {
  3548. if (this.isOpen()) {
  3549. this.close();
  3550. }
  3551. this.trigger('disable');
  3552. } else {
  3553. this.trigger('enable');
  3554. }
  3555. };
  3556. /**
  3557. * Override the trigger method to automatically trigger pre-events when
  3558. * there are events that can be prevented.
  3559. */
  3560. Select2.prototype.trigger = function (name, args) {
  3561. var actualTrigger = Select2.__super__.trigger;
  3562. var preTriggerMap = {
  3563. 'open': 'opening',
  3564. 'close': 'closing',
  3565. 'select': 'selecting',
  3566. 'unselect': 'unselecting'
  3567. };
  3568. if (name in preTriggerMap) {
  3569. var preTriggerName = preTriggerMap[name];
  3570. var preTriggerArgs = {
  3571. prevented: false,
  3572. name: name,
  3573. args: args
  3574. };
  3575. actualTrigger.call(this, preTriggerName, preTriggerArgs);
  3576. if (preTriggerArgs.prevented) {
  3577. args.prevented = true;
  3578. return;
  3579. }
  3580. }
  3581. actualTrigger.call(this, name, args);
  3582. };
  3583. Select2.prototype.toggleDropdown = function () {
  3584. if (this.options.get('disabled')) {
  3585. return;
  3586. }
  3587. if (this.isOpen()) {
  3588. this.close();
  3589. } else {
  3590. this.open();
  3591. }
  3592. };
  3593. Select2.prototype.open = function () {
  3594. if (this.isOpen()) {
  3595. return;
  3596. }
  3597. this.trigger('query', {});
  3598. this.trigger('open');
  3599. };
  3600. Select2.prototype.close = function () {
  3601. if (!this.isOpen()) {
  3602. return;
  3603. }
  3604. this.trigger('close');
  3605. };
  3606. Select2.prototype.isOpen = function () {
  3607. return this.$container.hasClass('select2-container--open');
  3608. };
  3609. Select2.prototype.enable = function (args) {
  3610. if (console && console.warn) {
  3611. console.warn(
  3612. 'Select2: The `select2("enable")` method has been deprecated and will' +
  3613. ' be removed in later Select2 versions. Use $element.prop("disabled")' +
  3614. ' instead.'
  3615. );
  3616. }
  3617. if (args.length === 0) {
  3618. args = [true];
  3619. }
  3620. var disabled = !args[0];
  3621. this.$element.prop('disabled', disabled);
  3622. };
  3623. Select2.prototype.data = function () {
  3624. if (arguments.length > 0 && console && console.warn) {
  3625. console.warn(
  3626. 'Select2: Data can no longer be set using `select2("data")`. You ' +
  3627. 'should consider setting the value instead using `$element.val()`.'
  3628. );
  3629. }
  3630. var data = [];
  3631. this.dataAdpater.current(function (currentData) {
  3632. data = currentData;
  3633. });
  3634. return data;
  3635. };
  3636. Select2.prototype.val = function (args) {
  3637. if (console && console.warn) {
  3638. console.warn(
  3639. 'Select2: The `select2("val")` method has been deprecated and will be' +
  3640. ' removed in later Select2 versions. Use $element.val() instead.'
  3641. );
  3642. }
  3643. if (args.length === 0) {
  3644. return this.$element.val();
  3645. }
  3646. var newVal = args[0];
  3647. if ($.isArray(newVal)) {
  3648. newVal = $.map(newVal, function (obj) {
  3649. return obj.toString();
  3650. });
  3651. }
  3652. this.$element.val(newVal).trigger('change');
  3653. };
  3654. Select2.prototype.destroy = function () {
  3655. this.$container.remove();
  3656. if (this.$element[0].detachEvent) {
  3657. this.$element[0].detachEvent('onpropertychange', this._sync);
  3658. }
  3659. if (this._observer != null) {
  3660. this._observer.disconnect();
  3661. this._observer = null;
  3662. }
  3663. this._sync = null;
  3664. this.$element.off('.select2');
  3665. this.$element.attr('tabindex', this._tabindex);
  3666. this.$element.show();
  3667. this.$element.removeData('select2');
  3668. this.data.destroy();
  3669. this.selection.destroy();
  3670. this.dropdown.destroy();
  3671. this.results.destroy();
  3672. this.data = null;
  3673. this.selection = null;
  3674. this.dropdown = null;
  3675. this.results = null;
  3676. };
  3677. Select2.prototype.render = function () {
  3678. var $container = $(
  3679. '<span class="select2 select2-container">' +
  3680. '<span class="selection"></span>' +
  3681. '<span class="dropdown-wrapper" aria-hidden="true"></span>' +
  3682. '</span>'
  3683. );
  3684. $container.attr('dir', this.options.get('dir'));
  3685. this.$container = $container;
  3686. this.$container.addClass('select2-container--' + this.options.get('theme'));
  3687. $container.data('element', this.$element);
  3688. return $container;
  3689. };
  3690. return Select2;
  3691. });
  3692. define('jquery.select2',[
  3693. 'jquery',
  3694. './select2/core',
  3695. './select2/defaults'
  3696. ], function ($, Select2, Defaults) {
  3697. // Force jQuery.mousewheel to be loaded if it hasn't already
  3698. try {
  3699. require('jquery.mousewheel');
  3700. } catch (Exception) { }
  3701. if ($.fn.select2 == null) {
  3702. $.fn.select2 = function (options) {
  3703. options = options || {};
  3704. if (typeof options === 'object') {
  3705. this.each(function () {
  3706. var instanceOptions = $.extend({}, options, true);
  3707. var instance = new Select2($(this), instanceOptions);
  3708. });
  3709. return this;
  3710. } else if (typeof options === 'string') {
  3711. var instance = this.data('select2');
  3712. var args = Array.prototype.slice.call(arguments, 1);
  3713. return instance[options](args);
  3714. } else {
  3715. throw new Error('Invalid arguments for Select2: ' + options);
  3716. }
  3717. };
  3718. }
  3719. if ($.fn.select2.defaults == null) {
  3720. $.fn.select2.defaults = Defaults;
  3721. }
  3722. return Select2;
  3723. });
  3724. return require('jquery.select2'); });