select2.amd.js 103 KB

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