select2.js 114 KB

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