select2.amd.full.js 115 KB

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