select2.js 127 KB

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