select2.js 133 KB

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