select2.js 126 KB

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