select2.js 135 KB

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