select2.amd.js 101 KB

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