select2.js 94 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046
  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. return Utils;
  488. });
  489. define('select2/results',[
  490. './utils'
  491. ], function (Utils) {
  492. function Results ($element, options, dataAdapter) {
  493. this.$element = $element;
  494. this.data = dataAdapter;
  495. this.options = options;
  496. Results.__super__.constructor.call(this);
  497. }
  498. Utils.Extend(Results, Utils.Observable);
  499. Results.prototype.render = function () {
  500. var $results = $(
  501. '<ul class="select2-results__options" role="tree"></ul>'
  502. );
  503. if (this.options.get('multiple')) {
  504. $results.attr('aria-multiselectable', 'true');
  505. }
  506. this.$results = $results;
  507. return $results;
  508. };
  509. Results.prototype.clear = function () {
  510. this.$results.empty();
  511. };
  512. Results.prototype.displayMessage = function (params) {
  513. this.clear();
  514. this.hideLoading();
  515. var $message = $(
  516. '<li role="treeitem" class="select2-results__option"></li>'
  517. );
  518. var message = this.options.get('translations').get(params.message);
  519. $message.text(message(params.args));
  520. this.$results.append($message);
  521. };
  522. Results.prototype.append = function (data) {
  523. this.hideLoading();
  524. var $options = [];
  525. if (data.length === 0) {
  526. if (this.$results.children().length === 0) {
  527. this.trigger('results:message', {
  528. message: 'noResults'
  529. });
  530. }
  531. return;
  532. }
  533. data = this.sort(data);
  534. for (var d = 0; d < data.length; d++) {
  535. var item = data[d];
  536. var $option = this.option(item);
  537. $options.push($option);
  538. }
  539. this.$results.append($options);
  540. };
  541. Results.prototype.position = function ($results, $dropdown) {
  542. var $resultsContainer = $dropdown.find('.select2-results');
  543. $resultsContainer.append($results);
  544. };
  545. Results.prototype.sort = function (data) {
  546. return data;
  547. };
  548. Results.prototype.setClasses = function () {
  549. var self = this;
  550. this.data.current(function (selected) {
  551. var selectedIds = $.map(selected, function (s) {
  552. return s.id.toString();
  553. });
  554. var $options = self.$results
  555. .find('.select2-results__option[aria-selected]');
  556. $options.each(function () {
  557. var $option = $(this);
  558. var item = $.data(this, 'data');
  559. if (item.id != null && selectedIds.indexOf(item.id.toString()) > -1) {
  560. $option.attr('aria-selected', 'true');
  561. } else {
  562. $option.attr('aria-selected', 'false');
  563. }
  564. });
  565. var $selected = $options.filter('[aria-selected=true]');
  566. // Check if there are any selected options
  567. if ($selected.length > 0) {
  568. // If there are selected options, highlight the first
  569. $selected.first().trigger('mouseenter');
  570. } else {
  571. // If there are no selected options, highlight the first option
  572. // in the dropdown
  573. $options.first().trigger('mouseenter');
  574. }
  575. });
  576. };
  577. Results.prototype.showLoading = function (params) {
  578. this.hideLoading();
  579. var loadingMore = this.options.get('translations').get('searching');
  580. var loading = {
  581. disabled: true,
  582. loading: true,
  583. text: loadingMore(params)
  584. };
  585. var $loading = this.option(loading);
  586. $loading.className += ' loading-results';
  587. this.$results.prepend($loading);
  588. };
  589. Results.prototype.hideLoading = function () {
  590. this.$results.find('.loading-results').remove();
  591. };
  592. Results.prototype.option = function (data) {
  593. var option = document.createElement('li');
  594. option.className = 'select2-results__option';
  595. var attrs = {
  596. 'role': 'treeitem',
  597. 'aria-selected': 'false'
  598. };
  599. if (data.disabled) {
  600. delete attrs['aria-selected'];
  601. attrs['aria-disabled'] = 'true';
  602. }
  603. if (data.id == null) {
  604. delete attrs['aria-selected'];
  605. }
  606. if (data._resultId != null) {
  607. option.id = data._resultId;
  608. }
  609. if (data.children) {
  610. attrs.role = 'group';
  611. attrs['aria-label'] = data.text;
  612. delete attrs['aria-selected'];
  613. }
  614. for (var attr in attrs) {
  615. var val = attrs[attr];
  616. option.setAttribute(attr, val);
  617. }
  618. if (data.children) {
  619. var $option = $(option);
  620. var label = document.createElement('strong');
  621. label.className = 'select2-results__group';
  622. var $label = $(label);
  623. this.template(data, label);
  624. var $children = [];
  625. for (var c = 0; c < data.children.length; c++) {
  626. var child = data.children[c];
  627. var $child = this.option(child);
  628. $children.push($child);
  629. }
  630. var $childrenContainer = $('<ul></ul>', {
  631. 'class': 'select2-results__options select2-results__options--nested'
  632. });
  633. $childrenContainer.append($children);
  634. $option.append(label);
  635. $option.append($childrenContainer);
  636. } else {
  637. this.template(data, option);
  638. }
  639. $.data(option, 'data', data);
  640. return option;
  641. };
  642. Results.prototype.bind = function (container, $container) {
  643. var self = this;
  644. var id = container.id + '-results';
  645. this.$results.attr('id', id);
  646. container.on('results:all', function (params) {
  647. self.clear();
  648. self.append(params.data);
  649. if (container.isOpen()) {
  650. self.setClasses();
  651. }
  652. });
  653. container.on('results:append', function (params) {
  654. self.append(params.data);
  655. if (container.isOpen()) {
  656. self.setClasses();
  657. }
  658. });
  659. container.on('query', function (params) {
  660. self.showLoading(params);
  661. });
  662. container.on('select', function () {
  663. if (!container.isOpen()) {
  664. return;
  665. }
  666. self.setClasses();
  667. });
  668. container.on('unselect', function () {
  669. if (!container.isOpen()) {
  670. return;
  671. }
  672. self.setClasses();
  673. });
  674. container.on('open', function () {
  675. // When the dropdown is open, aria-expended="true"
  676. self.$results.attr('aria-expanded', 'true');
  677. self.$results.attr('aria-hidden', 'false');
  678. self.setClasses();
  679. self.ensureHighlightVisible();
  680. });
  681. container.on('close', function () {
  682. // When the dropdown is closed, aria-expended="false"
  683. self.$results.attr('aria-expanded', 'false');
  684. self.$results.attr('aria-hidden', 'true');
  685. self.$results.removeAttr('aria-activedescendant');
  686. });
  687. container.on('results:select', function () {
  688. var $highlighted = self.getHighlightedResults();
  689. if ($highlighted.length === 0) {
  690. return;
  691. }
  692. var data = $highlighted.data('data');
  693. if ($highlighted.attr('aria-selected') == 'true') {
  694. self.trigger('unselected', {
  695. data: data
  696. });
  697. } else {
  698. self.trigger('selected', {
  699. data: data
  700. });
  701. }
  702. });
  703. container.on('results:previous', function () {
  704. var $highlighted = self.getHighlightedResults();
  705. var $options = self.$results.find('[aria-selected]');
  706. var currentIndex = $options.index($highlighted);
  707. // If we are already at te top, don't move further
  708. if (currentIndex === 0) {
  709. return;
  710. }
  711. var nextIndex = currentIndex - 1;
  712. // If none are highlighted, highlight the first
  713. if ($highlighted.length === 0) {
  714. nextIndex = 0;
  715. }
  716. var $next = $options.eq(nextIndex);
  717. $next.trigger('mouseenter');
  718. var currentOffset = self.$results.offset().top;
  719. var nextTop = $next.offset().top;
  720. var nextOffset = self.$results.scrollTop() + (nextTop - currentOffset);
  721. if (nextIndex === 0) {
  722. self.$results.scrollTop(0);
  723. } else if (nextTop - currentOffset < 0) {
  724. self.$results.scrollTop(nextOffset);
  725. }
  726. });
  727. container.on('results:next', function () {
  728. var $highlighted = self.getHighlightedResults();
  729. var $options = self.$results.find('[aria-selected]');
  730. var currentIndex = $options.index($highlighted);
  731. var nextIndex = currentIndex + 1;
  732. // If we are at the last option, stay there
  733. if (nextIndex >= $options.length) {
  734. return;
  735. }
  736. var $next = $options.eq(nextIndex);
  737. $next.trigger('mouseenter');
  738. var currentOffset = self.$results.offset().top +
  739. self.$results.outerHeight(false);
  740. var nextBottom = $next.offset().top + $next.outerHeight(false);
  741. var nextOffset = self.$results.scrollTop() + nextBottom - currentOffset;
  742. if (nextIndex === 0) {
  743. self.$results.scrollTop(0);
  744. } else if (nextBottom > currentOffset) {
  745. self.$results.scrollTop(nextOffset);
  746. }
  747. });
  748. container.on('results:focus', function (params) {
  749. params.element.addClass('select2-results__option--highlighted');
  750. });
  751. container.on('results:message', function (params) {
  752. self.trigger('results:message', params);
  753. });
  754. this.on('results:message', function (params) {
  755. self.displayMessage(params);
  756. });
  757. this.$results.on('mouseup', '.select2-results__option[aria-selected]',
  758. function (evt) {
  759. var $this = $(this);
  760. var data = $this.data('data');
  761. if ($this.attr('aria-selected') === 'true') {
  762. self.trigger('unselected', {
  763. originalEvent: evt,
  764. data: data
  765. });
  766. return;
  767. }
  768. self.trigger('selected', {
  769. originalEvent: evt,
  770. data: data
  771. });
  772. });
  773. this.$results.on('mouseenter', '.select2-results__option[aria-selected]',
  774. function (evt) {
  775. var data = $(this).data('data');
  776. self.getHighlightedResults()
  777. .removeClass('select2-results__option--highlighted');
  778. self.trigger('results:focus', {
  779. data: data,
  780. element: $(this)
  781. });
  782. });
  783. };
  784. Results.prototype.getHighlightedResults = function () {
  785. var $highlighted = this.$results
  786. .find('.select2-results__option--highlighted');
  787. return $highlighted;
  788. };
  789. Results.prototype.destroy = function () {
  790. this.$results.remove();
  791. };
  792. Results.prototype.ensureHighlightVisible = function () {
  793. var $highlighted = this.getHighlightedResults();
  794. if ($highlighted.length === 0) {
  795. return;
  796. }
  797. var $options = this.$results.find('[aria-selected]');
  798. var currentIndex = $options.index($highlighted);
  799. var currentOffset = this.$results.offset().top;
  800. var nextTop = $highlighted.offset().top;
  801. var nextOffset = this.$results.scrollTop() + (nextTop - currentOffset);
  802. var offsetDelta = nextTop - currentOffset;
  803. nextOffset -= $highlighted.outerHeight(false) * 2;
  804. if (currentIndex <= 2) {
  805. this.$results.scrollTop(0);
  806. } else if (offsetDelta > this.$results.outerHeight() || offsetDelta < 0) {
  807. this.$results.scrollTop(nextOffset);
  808. }
  809. };
  810. Results.prototype.template = function (result, container) {
  811. var template = this.options.get('templateResult');
  812. container.innerHTML = template(result);
  813. };
  814. return Results;
  815. });
  816. define('select2/keys',[
  817. ], function () {
  818. var KEYS = {
  819. BACKSPACE: 8,
  820. TAB: 9,
  821. ENTER: 13,
  822. SHIFT: 16,
  823. CTRL: 17,
  824. ALT: 18,
  825. ESC: 27,
  826. SPACE: 32,
  827. PAGE_UP: 33,
  828. PAGE_DOWN: 34,
  829. END: 35,
  830. HOME: 36,
  831. LEFT: 37,
  832. UP: 38,
  833. RIGHT: 39,
  834. DOWN: 40,
  835. DELETE: 46,
  836. isArrow: function (k) {
  837. k = k.which ? k.which : k;
  838. switch (k) {
  839. case KEY.LEFT:
  840. case KEY.RIGHT:
  841. case KEY.UP:
  842. case KEY.DOWN:
  843. return true;
  844. }
  845. return false;
  846. }
  847. };
  848. return KEYS;
  849. });
  850. define('select2/selection/base',[
  851. '../utils',
  852. '../keys'
  853. ], function (Utils, KEYS) {
  854. function BaseSelection ($element, options) {
  855. this.$element = $element;
  856. this.options = options;
  857. BaseSelection.__super__.constructor.call(this);
  858. }
  859. Utils.Extend(BaseSelection, Utils.Observable);
  860. BaseSelection.prototype.render = function () {
  861. throw new Error('The `render` method must be defined in child classes.');
  862. };
  863. BaseSelection.prototype.bind = function (container, $container) {
  864. var self = this;
  865. var id = container.id + '-container';
  866. var resultsId = container.id + '-results';
  867. this.container = container;
  868. this.$selection.attr('aria-owns', resultsId);
  869. this.$selection.on('keydown', function (evt) {
  870. self.trigger('keypress', evt);
  871. if (evt.which === KEYS.SPACE) {
  872. evt.preventDefault();
  873. }
  874. });
  875. container.on('results:focus', function (params) {
  876. self.$selection.attr('aria-activedescendant', params.data._resultId);
  877. });
  878. container.on('selection:update', function (params) {
  879. self.update(params.data);
  880. });
  881. container.on('open', function () {
  882. // When the dropdown is open, aria-expanded="true"
  883. self.$selection.attr('aria-expanded', 'true');
  884. self._attachCloseHandler(container);
  885. });
  886. container.on('close', function () {
  887. // When the dropdown is closed, aria-expanded="false"
  888. self.$selection.attr('aria-expanded', 'false');
  889. self.$selection.removeAttr('aria-activedescendant');
  890. self.$selection.focus();
  891. self._detachCloseHandler(container);
  892. });
  893. };
  894. BaseSelection.prototype._attachCloseHandler = function (container) {
  895. var self = this;
  896. $(document.body).on('mousedown.select2.' + container.id, function (e) {
  897. var $target = $(e.target);
  898. var $select = $target.closest('.select2');
  899. var $all = $('.select2.select2-container--open');
  900. $all.each(function () {
  901. var $this = $(this);
  902. if (this == $select[0]) {
  903. return;
  904. }
  905. var $element = $this.data('element');
  906. $element.select2('close');
  907. });
  908. });
  909. $(window).on('scroll.select2.' + container.id, function (e) {
  910. self.trigger('close');
  911. });
  912. };
  913. BaseSelection.prototype._detachCloseHandler = function (container) {
  914. $(document.body).off('mousedown.select2.' + container.id);
  915. $(window).off('scroll.select2.' + container.id);
  916. };
  917. BaseSelection.prototype.position = function ($selection, $container) {
  918. var $selectionContainer = $container.find('.selection');
  919. $selectionContainer.append($selection);
  920. };
  921. BaseSelection.prototype.destroy = function () {
  922. this._detachCloseHandler();
  923. };
  924. BaseSelection.prototype.update = function (data) {
  925. throw new Error('The `update` method must be defined in child classes.');
  926. };
  927. return BaseSelection;
  928. });
  929. define('select2/selection/single',[
  930. './base',
  931. '../utils',
  932. '../keys'
  933. ], function (BaseSelection, Utils, KEYS) {
  934. function SingleSelection () {
  935. SingleSelection.__super__.constructor.apply(this, arguments);
  936. }
  937. Utils.Extend(SingleSelection, BaseSelection);
  938. SingleSelection.prototype.render = function () {
  939. var $selection = $(
  940. '<span class="select2-selection select2-selection--single" tabindex="0"' +
  941. ' role="combobox" aria-autocomplete="list" aria-haspopup="true"' +
  942. ' aria-expanded="false">' +
  943. '<span class="select2-selection__rendered"></span>' +
  944. '<span class="select2-selection__arrow" role="presentation">' +
  945. '<b role="presentation"></b>' +
  946. '</span>' +
  947. '</span>'
  948. );
  949. $selection.attr('title', this.$element.attr('title'));
  950. this.$selection = $selection;
  951. return $selection;
  952. };
  953. SingleSelection.prototype.bind = function (container, $container) {
  954. var self = this;
  955. SingleSelection.__super__.bind.apply(this, arguments);
  956. var id = container.id + '-container';
  957. this.$selection.find('.select2-selection__rendered').attr('id', id);
  958. this.$selection.attr('aria-labelledby', id);
  959. this.$selection.on('mousedown', function (evt) {
  960. // Only respond to left clicks
  961. if (evt.which !== 1) {
  962. return;
  963. }
  964. self.trigger('toggle', {
  965. originalEvent: evt
  966. });
  967. });
  968. this.$selection.on('focus', function (evt) {
  969. // User focuses on the container
  970. });
  971. this.$selection.on('blur', function (evt) {
  972. // User exits the container
  973. });
  974. container.on('selection:update', function (params) {
  975. self.update(params.data);
  976. });
  977. };
  978. SingleSelection.prototype.clear = function () {
  979. this.$selection.find('.select2-selection__rendered').empty();
  980. };
  981. SingleSelection.prototype.display = function (data) {
  982. var template = this.options.get('templateSelection');
  983. return template(data);
  984. };
  985. SingleSelection.prototype.selectionContainer = function () {
  986. return $('<span></span>');
  987. };
  988. SingleSelection.prototype.update = function (data) {
  989. if (data.length === 0) {
  990. this.clear();
  991. return;
  992. }
  993. var selection = data[0];
  994. var formatted = this.display(selection);
  995. this.$selection.find('.select2-selection__rendered').html(formatted);
  996. };
  997. return SingleSelection;
  998. });
  999. define('select2/selection/multiple',[
  1000. './base',
  1001. '../utils'
  1002. ], function (BaseSelection, Utils) {
  1003. function MultipleSelection ($element, options) {
  1004. MultipleSelection.__super__.constructor.apply(this, arguments);
  1005. }
  1006. Utils.Extend(MultipleSelection, BaseSelection);
  1007. MultipleSelection.prototype.render = function () {
  1008. var $selection = $(
  1009. '<span class="select2-selection select2-selection--multiple"' +
  1010. ' tabindex="0" role="combobox" aria-autocomplete="list"' +
  1011. ' aria-haspopup="true" aria-expanded="false">' +
  1012. '<ul class="select2-selection__rendered"></ul>' +
  1013. '</span>'
  1014. );
  1015. $selection.attr('title', this.$element.attr('title'));
  1016. this.$selection = $selection;
  1017. return $selection;
  1018. };
  1019. MultipleSelection.prototype.bind = function (container, $container) {
  1020. var self = this;
  1021. MultipleSelection.__super__.bind.apply(this, arguments);
  1022. this.$selection.on('click', function (evt) {
  1023. self.trigger('toggle', {
  1024. originalEvent: evt
  1025. });
  1026. });
  1027. this.$selection.on('click', '.select2-selection__choice__remove',
  1028. function (evt) {
  1029. var $remove = $(this);
  1030. var $selection = $remove.parent();
  1031. var data = $selection.data('data');
  1032. self.trigger('unselected', {
  1033. originalEvent: evt,
  1034. data: data
  1035. });
  1036. });
  1037. };
  1038. MultipleSelection.prototype.clear = function () {
  1039. this.$selection.find('.select2-selection__rendered').empty();
  1040. };
  1041. MultipleSelection.prototype.display = function (data) {
  1042. var template = this.options.get('templateSelection');
  1043. return template(data);
  1044. };
  1045. MultipleSelection.prototype.selectionContainer = function () {
  1046. var $container = $(
  1047. '<li class="select2-selection__choice">' +
  1048. '<span class="select2-selection__choice__remove" role="presentation">' +
  1049. '&times;' +
  1050. '</span>' +
  1051. '</li>'
  1052. );
  1053. return $container;
  1054. };
  1055. MultipleSelection.prototype.update = function (data) {
  1056. this.clear();
  1057. if (data.length === 0) {
  1058. return;
  1059. }
  1060. var $selections = [];
  1061. for (var d = 0; d < data.length; d++) {
  1062. var selection = data[d];
  1063. var formatted = this.display(selection);
  1064. var $selection = this.selectionContainer();
  1065. $selection.append(formatted);
  1066. $selection.data('data', selection);
  1067. $selections.push($selection);
  1068. }
  1069. this.$selection.find('.select2-selection__rendered').append($selections);
  1070. };
  1071. return MultipleSelection;
  1072. });
  1073. define('select2/selection/placeholder',[
  1074. '../utils'
  1075. ], function (Utils) {
  1076. function Placeholder (decorated, $element, options) {
  1077. this.placeholder = this.normalizePlaceholder(options.get('placeholder'));
  1078. decorated.call(this, $element, options);
  1079. }
  1080. Placeholder.prototype.normalizePlaceholder = function (_, placeholder) {
  1081. if (typeof placeholder === 'string') {
  1082. placeholder = {
  1083. id: '',
  1084. text: placeholder
  1085. };
  1086. }
  1087. return placeholder;
  1088. };
  1089. Placeholder.prototype.createPlaceholder = function (decorated, placeholder) {
  1090. var $placeholder = this.selectionContainer();
  1091. $placeholder.html(this.display(placeholder));
  1092. $placeholder.addClass('select2-selection__placeholder')
  1093. .removeClass('select2-selection__choice');
  1094. return $placeholder;
  1095. };
  1096. Placeholder.prototype.update = function (decorated, data) {
  1097. var singlePlaceholder = (
  1098. data.length == 1 && data[0].id != this.placeholder.id
  1099. );
  1100. var multipleSelections = data.length > 1;
  1101. if (multipleSelections || singlePlaceholder) {
  1102. return decorated.call(this, data);
  1103. }
  1104. this.clear();
  1105. var $placeholder = this.createPlaceholder(this.placeholder);
  1106. this.$selection.find('.select2-selection__rendered').append($placeholder);
  1107. };
  1108. return Placeholder;
  1109. });
  1110. define('select2/selection/allowClear',[
  1111. ], function () {
  1112. function AllowClear () { }
  1113. AllowClear.prototype.bind = function (decorated, container, $container) {
  1114. var self = this;
  1115. decorated.call(this, container, $container);
  1116. this.$selection.on('mousedown', '.select2-selection__clear',
  1117. function (evt) {
  1118. evt.stopPropagation();
  1119. self.$element.val(self.placeholder.id).trigger('change');
  1120. self.trigger('toggle');
  1121. });
  1122. };
  1123. AllowClear.prototype.update = function (decorated, data) {
  1124. decorated.call(this, data);
  1125. if (this.$selection.find('.select2-selection__placeholder').length > 0) {
  1126. return;
  1127. }
  1128. var $remove = $(
  1129. '<span class="select2-selection__clear">' +
  1130. '&times;' +
  1131. '</span>'
  1132. );
  1133. this.$selection.find('.select2-selection__rendered').append($remove);
  1134. };
  1135. return AllowClear;
  1136. });
  1137. define('select2/selection/search',[
  1138. '../utils'
  1139. ], function (Utils) {
  1140. function Search (decorated, $element, options) {
  1141. decorated.call(this, $element, options);
  1142. }
  1143. Search.prototype.render = function (decorated) {
  1144. var $search = $(
  1145. '<li class="select2-search select2-search--inline">' +
  1146. '<input class="select2-search__field" type="search" tabindex="-1"' +
  1147. ' role="textbox" />' +
  1148. '</li>'
  1149. );
  1150. this.$searchContainer = $search;
  1151. this.$search = $search.find('input');
  1152. var $rendered = decorated.call(this);
  1153. return $rendered;
  1154. };
  1155. Search.prototype.bind = function (decorated, container, $container) {
  1156. var self = this;
  1157. decorated.call(this, container, $container);
  1158. container.on('open', function () {
  1159. self.$search.attr('tabindex', 0);
  1160. self.$search.focus();
  1161. });
  1162. container.on('close', function () {
  1163. self.$search.attr('tabindex', -1);
  1164. self.$search.val('');
  1165. });
  1166. this.$selection.on('keydown', '.select2-search--inline', function (evt) {
  1167. evt.stopPropagation();
  1168. self.trigger('keypress', evt);
  1169. self._keyUpPrevented = evt.isDefaultPrevented();
  1170. });
  1171. this.$selection.on('keyup', '.select2-search--inline', function (evt) {
  1172. self.handleSearch(evt);
  1173. });
  1174. };
  1175. Search.prototype.createPlaceholder = function (decorated, placeholder) {
  1176. this.$search.attr('placeholder', placeholder.text);
  1177. };
  1178. Search.prototype.update = function (decorated, data) {
  1179. this.$search.attr('placeholder', '');
  1180. decorated.call(this, data);
  1181. this.$selection.find('.select2-selection__rendered')
  1182. .append(this.$searchContainer);
  1183. this.resizeSearch();
  1184. };
  1185. Search.prototype.handleSearch = function (evt) {
  1186. this.resizeSearch();
  1187. if (!this._keyUpPrevented) {
  1188. var input = this.$search.val();
  1189. this.trigger('query', {
  1190. term: input
  1191. });
  1192. }
  1193. this._keyUpPrevented = false;
  1194. };
  1195. Search.prototype.resizeSearch = function () {
  1196. this.$search.css('width', '25px');
  1197. var width = '';
  1198. if (this.$search.attr('placeholder') !== '') {
  1199. width = this.$selection.innerWidth();
  1200. width -= this.$selection.find('.select2-selection__rendered')
  1201. .innerWidth();
  1202. width = width + 'px';
  1203. } else {
  1204. var minimumWidth = this.$search.val().length + 1;
  1205. width = (minimumWidth * 0.75) + 'em';
  1206. }
  1207. this.$search.css('width', width);
  1208. };
  1209. return Search;
  1210. });
  1211. define('select2/translation',[
  1212. ], function () {
  1213. function Translation (dict) {
  1214. this.dict = dict || {};
  1215. }
  1216. Translation.prototype.all = function () {
  1217. return this.dict;
  1218. };
  1219. Translation.prototype.get = function (key) {
  1220. return this.dict[key];
  1221. };
  1222. Translation.prototype.extend = function (translation) {
  1223. this.dict = $.extend({}, translation.all(), this.dict);
  1224. };
  1225. // Static functions
  1226. Translation._cache = {};
  1227. Translation.loadPath = function (path) {
  1228. if (!(path in Translation._cache)) {
  1229. var translations = require(path);
  1230. Translation._cache[path] = translations;
  1231. }
  1232. return new Translation(Translation._cache[path]);
  1233. };
  1234. return Translation;
  1235. });
  1236. define('select2/diacritics',[
  1237. ], function () {
  1238. var diacritics = {
  1239. '\u24B6': 'A',
  1240. '\uFF21': 'A',
  1241. '\u00C0': 'A',
  1242. '\u00C1': 'A',
  1243. '\u00C2': 'A',
  1244. '\u1EA6': 'A',
  1245. '\u1EA4': 'A',
  1246. '\u1EAA': 'A',
  1247. '\u1EA8': 'A',
  1248. '\u00C3': 'A',
  1249. '\u0100': 'A',
  1250. '\u0102': 'A',
  1251. '\u1EB0': 'A',
  1252. '\u1EAE': 'A',
  1253. '\u1EB4': 'A',
  1254. '\u1EB2': 'A',
  1255. '\u0226': 'A',
  1256. '\u01E0': 'A',
  1257. '\u00C4': 'A',
  1258. '\u01DE': 'A',
  1259. '\u1EA2': 'A',
  1260. '\u00C5': 'A',
  1261. '\u01FA': 'A',
  1262. '\u01CD': 'A',
  1263. '\u0200': 'A',
  1264. '\u0202': 'A',
  1265. '\u1EA0': 'A',
  1266. '\u1EAC': 'A',
  1267. '\u1EB6': 'A',
  1268. '\u1E00': 'A',
  1269. '\u0104': 'A',
  1270. '\u023A': 'A',
  1271. '\u2C6F': 'A',
  1272. '\uA732': 'AA',
  1273. '\u00C6': 'AE',
  1274. '\u01FC': 'AE',
  1275. '\u01E2': 'AE',
  1276. '\uA734': 'AO',
  1277. '\uA736': 'AU',
  1278. '\uA738': 'AV',
  1279. '\uA73A': 'AV',
  1280. '\uA73C': 'AY',
  1281. '\u24B7': 'B',
  1282. '\uFF22': 'B',
  1283. '\u1E02': 'B',
  1284. '\u1E04': 'B',
  1285. '\u1E06': 'B',
  1286. '\u0243': 'B',
  1287. '\u0182': 'B',
  1288. '\u0181': 'B',
  1289. '\u24B8': 'C',
  1290. '\uFF23': 'C',
  1291. '\u0106': 'C',
  1292. '\u0108': 'C',
  1293. '\u010A': 'C',
  1294. '\u010C': 'C',
  1295. '\u00C7': 'C',
  1296. '\u1E08': 'C',
  1297. '\u0187': 'C',
  1298. '\u023B': 'C',
  1299. '\uA73E': 'C',
  1300. '\u24B9': 'D',
  1301. '\uFF24': 'D',
  1302. '\u1E0A': 'D',
  1303. '\u010E': 'D',
  1304. '\u1E0C': 'D',
  1305. '\u1E10': 'D',
  1306. '\u1E12': 'D',
  1307. '\u1E0E': 'D',
  1308. '\u0110': 'D',
  1309. '\u018B': 'D',
  1310. '\u018A': 'D',
  1311. '\u0189': 'D',
  1312. '\uA779': 'D',
  1313. '\u01F1': 'DZ',
  1314. '\u01C4': 'DZ',
  1315. '\u01F2': 'Dz',
  1316. '\u01C5': 'Dz',
  1317. '\u24BA': 'E',
  1318. '\uFF25': 'E',
  1319. '\u00C8': 'E',
  1320. '\u00C9': 'E',
  1321. '\u00CA': 'E',
  1322. '\u1EC0': 'E',
  1323. '\u1EBE': 'E',
  1324. '\u1EC4': 'E',
  1325. '\u1EC2': 'E',
  1326. '\u1EBC': 'E',
  1327. '\u0112': 'E',
  1328. '\u1E14': 'E',
  1329. '\u1E16': 'E',
  1330. '\u0114': 'E',
  1331. '\u0116': 'E',
  1332. '\u00CB': 'E',
  1333. '\u1EBA': 'E',
  1334. '\u011A': 'E',
  1335. '\u0204': 'E',
  1336. '\u0206': 'E',
  1337. '\u1EB8': 'E',
  1338. '\u1EC6': 'E',
  1339. '\u0228': 'E',
  1340. '\u1E1C': 'E',
  1341. '\u0118': 'E',
  1342. '\u1E18': 'E',
  1343. '\u1E1A': 'E',
  1344. '\u0190': 'E',
  1345. '\u018E': 'E',
  1346. '\u24BB': 'F',
  1347. '\uFF26': 'F',
  1348. '\u1E1E': 'F',
  1349. '\u0191': 'F',
  1350. '\uA77B': 'F',
  1351. '\u24BC': 'G',
  1352. '\uFF27': 'G',
  1353. '\u01F4': 'G',
  1354. '\u011C': 'G',
  1355. '\u1E20': 'G',
  1356. '\u011E': 'G',
  1357. '\u0120': 'G',
  1358. '\u01E6': 'G',
  1359. '\u0122': 'G',
  1360. '\u01E4': 'G',
  1361. '\u0193': 'G',
  1362. '\uA7A0': 'G',
  1363. '\uA77D': 'G',
  1364. '\uA77E': 'G',
  1365. '\u24BD': 'H',
  1366. '\uFF28': 'H',
  1367. '\u0124': 'H',
  1368. '\u1E22': 'H',
  1369. '\u1E26': 'H',
  1370. '\u021E': 'H',
  1371. '\u1E24': 'H',
  1372. '\u1E28': 'H',
  1373. '\u1E2A': 'H',
  1374. '\u0126': 'H',
  1375. '\u2C67': 'H',
  1376. '\u2C75': 'H',
  1377. '\uA78D': 'H',
  1378. '\u24BE': 'I',
  1379. '\uFF29': 'I',
  1380. '\u00CC': 'I',
  1381. '\u00CD': 'I',
  1382. '\u00CE': 'I',
  1383. '\u0128': 'I',
  1384. '\u012A': 'I',
  1385. '\u012C': 'I',
  1386. '\u0130': 'I',
  1387. '\u00CF': 'I',
  1388. '\u1E2E': 'I',
  1389. '\u1EC8': 'I',
  1390. '\u01CF': 'I',
  1391. '\u0208': 'I',
  1392. '\u020A': 'I',
  1393. '\u1ECA': 'I',
  1394. '\u012E': 'I',
  1395. '\u1E2C': 'I',
  1396. '\u0197': 'I',
  1397. '\u24BF': 'J',
  1398. '\uFF2A': 'J',
  1399. '\u0134': 'J',
  1400. '\u0248': 'J',
  1401. '\u24C0': 'K',
  1402. '\uFF2B': 'K',
  1403. '\u1E30': 'K',
  1404. '\u01E8': 'K',
  1405. '\u1E32': 'K',
  1406. '\u0136': 'K',
  1407. '\u1E34': 'K',
  1408. '\u0198': 'K',
  1409. '\u2C69': 'K',
  1410. '\uA740': 'K',
  1411. '\uA742': 'K',
  1412. '\uA744': 'K',
  1413. '\uA7A2': 'K',
  1414. '\u24C1': 'L',
  1415. '\uFF2C': 'L',
  1416. '\u013F': 'L',
  1417. '\u0139': 'L',
  1418. '\u013D': 'L',
  1419. '\u1E36': 'L',
  1420. '\u1E38': 'L',
  1421. '\u013B': 'L',
  1422. '\u1E3C': 'L',
  1423. '\u1E3A': 'L',
  1424. '\u0141': 'L',
  1425. '\u023D': 'L',
  1426. '\u2C62': 'L',
  1427. '\u2C60': 'L',
  1428. '\uA748': 'L',
  1429. '\uA746': 'L',
  1430. '\uA780': 'L',
  1431. '\u01C7': 'LJ',
  1432. '\u01C8': 'Lj',
  1433. '\u24C2': 'M',
  1434. '\uFF2D': 'M',
  1435. '\u1E3E': 'M',
  1436. '\u1E40': 'M',
  1437. '\u1E42': 'M',
  1438. '\u2C6E': 'M',
  1439. '\u019C': 'M',
  1440. '\u24C3': 'N',
  1441. '\uFF2E': 'N',
  1442. '\u01F8': 'N',
  1443. '\u0143': 'N',
  1444. '\u00D1': 'N',
  1445. '\u1E44': 'N',
  1446. '\u0147': 'N',
  1447. '\u1E46': 'N',
  1448. '\u0145': 'N',
  1449. '\u1E4A': 'N',
  1450. '\u1E48': 'N',
  1451. '\u0220': 'N',
  1452. '\u019D': 'N',
  1453. '\uA790': 'N',
  1454. '\uA7A4': 'N',
  1455. '\u01CA': 'NJ',
  1456. '\u01CB': 'Nj',
  1457. '\u24C4': 'O',
  1458. '\uFF2F': 'O',
  1459. '\u00D2': 'O',
  1460. '\u00D3': 'O',
  1461. '\u00D4': 'O',
  1462. '\u1ED2': 'O',
  1463. '\u1ED0': 'O',
  1464. '\u1ED6': 'O',
  1465. '\u1ED4': 'O',
  1466. '\u00D5': 'O',
  1467. '\u1E4C': 'O',
  1468. '\u022C': 'O',
  1469. '\u1E4E': 'O',
  1470. '\u014C': 'O',
  1471. '\u1E50': 'O',
  1472. '\u1E52': 'O',
  1473. '\u014E': 'O',
  1474. '\u022E': 'O',
  1475. '\u0230': 'O',
  1476. '\u00D6': 'O',
  1477. '\u022A': 'O',
  1478. '\u1ECE': 'O',
  1479. '\u0150': 'O',
  1480. '\u01D1': 'O',
  1481. '\u020C': 'O',
  1482. '\u020E': 'O',
  1483. '\u01A0': 'O',
  1484. '\u1EDC': 'O',
  1485. '\u1EDA': 'O',
  1486. '\u1EE0': 'O',
  1487. '\u1EDE': 'O',
  1488. '\u1EE2': 'O',
  1489. '\u1ECC': 'O',
  1490. '\u1ED8': 'O',
  1491. '\u01EA': 'O',
  1492. '\u01EC': 'O',
  1493. '\u00D8': 'O',
  1494. '\u01FE': 'O',
  1495. '\u0186': 'O',
  1496. '\u019F': 'O',
  1497. '\uA74A': 'O',
  1498. '\uA74C': 'O',
  1499. '\u01A2': 'OI',
  1500. '\uA74E': 'OO',
  1501. '\u0222': 'OU',
  1502. '\u24C5': 'P',
  1503. '\uFF30': 'P',
  1504. '\u1E54': 'P',
  1505. '\u1E56': 'P',
  1506. '\u01A4': 'P',
  1507. '\u2C63': 'P',
  1508. '\uA750': 'P',
  1509. '\uA752': 'P',
  1510. '\uA754': 'P',
  1511. '\u24C6': 'Q',
  1512. '\uFF31': 'Q',
  1513. '\uA756': 'Q',
  1514. '\uA758': 'Q',
  1515. '\u024A': 'Q',
  1516. '\u24C7': 'R',
  1517. '\uFF32': 'R',
  1518. '\u0154': 'R',
  1519. '\u1E58': 'R',
  1520. '\u0158': 'R',
  1521. '\u0210': 'R',
  1522. '\u0212': 'R',
  1523. '\u1E5A': 'R',
  1524. '\u1E5C': 'R',
  1525. '\u0156': 'R',
  1526. '\u1E5E': 'R',
  1527. '\u024C': 'R',
  1528. '\u2C64': 'R',
  1529. '\uA75A': 'R',
  1530. '\uA7A6': 'R',
  1531. '\uA782': 'R',
  1532. '\u24C8': 'S',
  1533. '\uFF33': 'S',
  1534. '\u1E9E': 'S',
  1535. '\u015A': 'S',
  1536. '\u1E64': 'S',
  1537. '\u015C': 'S',
  1538. '\u1E60': 'S',
  1539. '\u0160': 'S',
  1540. '\u1E66': 'S',
  1541. '\u1E62': 'S',
  1542. '\u1E68': 'S',
  1543. '\u0218': 'S',
  1544. '\u015E': 'S',
  1545. '\u2C7E': 'S',
  1546. '\uA7A8': 'S',
  1547. '\uA784': 'S',
  1548. '\u24C9': 'T',
  1549. '\uFF34': 'T',
  1550. '\u1E6A': 'T',
  1551. '\u0164': 'T',
  1552. '\u1E6C': 'T',
  1553. '\u021A': 'T',
  1554. '\u0162': 'T',
  1555. '\u1E70': 'T',
  1556. '\u1E6E': 'T',
  1557. '\u0166': 'T',
  1558. '\u01AC': 'T',
  1559. '\u01AE': 'T',
  1560. '\u023E': 'T',
  1561. '\uA786': 'T',
  1562. '\uA728': 'TZ',
  1563. '\u24CA': 'U',
  1564. '\uFF35': 'U',
  1565. '\u00D9': 'U',
  1566. '\u00DA': 'U',
  1567. '\u00DB': 'U',
  1568. '\u0168': 'U',
  1569. '\u1E78': 'U',
  1570. '\u016A': 'U',
  1571. '\u1E7A': 'U',
  1572. '\u016C': 'U',
  1573. '\u00DC': 'U',
  1574. '\u01DB': 'U',
  1575. '\u01D7': 'U',
  1576. '\u01D5': 'U',
  1577. '\u01D9': 'U',
  1578. '\u1EE6': 'U',
  1579. '\u016E': 'U',
  1580. '\u0170': 'U',
  1581. '\u01D3': 'U',
  1582. '\u0214': 'U',
  1583. '\u0216': 'U',
  1584. '\u01AF': 'U',
  1585. '\u1EEA': 'U',
  1586. '\u1EE8': 'U',
  1587. '\u1EEE': 'U',
  1588. '\u1EEC': 'U',
  1589. '\u1EF0': 'U',
  1590. '\u1EE4': 'U',
  1591. '\u1E72': 'U',
  1592. '\u0172': 'U',
  1593. '\u1E76': 'U',
  1594. '\u1E74': 'U',
  1595. '\u0244': 'U',
  1596. '\u24CB': 'V',
  1597. '\uFF36': 'V',
  1598. '\u1E7C': 'V',
  1599. '\u1E7E': 'V',
  1600. '\u01B2': 'V',
  1601. '\uA75E': 'V',
  1602. '\u0245': 'V',
  1603. '\uA760': 'VY',
  1604. '\u24CC': 'W',
  1605. '\uFF37': 'W',
  1606. '\u1E80': 'W',
  1607. '\u1E82': 'W',
  1608. '\u0174': 'W',
  1609. '\u1E86': 'W',
  1610. '\u1E84': 'W',
  1611. '\u1E88': 'W',
  1612. '\u2C72': 'W',
  1613. '\u24CD': 'X',
  1614. '\uFF38': 'X',
  1615. '\u1E8A': 'X',
  1616. '\u1E8C': 'X',
  1617. '\u24CE': 'Y',
  1618. '\uFF39': 'Y',
  1619. '\u1EF2': 'Y',
  1620. '\u00DD': 'Y',
  1621. '\u0176': 'Y',
  1622. '\u1EF8': 'Y',
  1623. '\u0232': 'Y',
  1624. '\u1E8E': 'Y',
  1625. '\u0178': 'Y',
  1626. '\u1EF6': 'Y',
  1627. '\u1EF4': 'Y',
  1628. '\u01B3': 'Y',
  1629. '\u024E': 'Y',
  1630. '\u1EFE': 'Y',
  1631. '\u24CF': 'Z',
  1632. '\uFF3A': 'Z',
  1633. '\u0179': 'Z',
  1634. '\u1E90': 'Z',
  1635. '\u017B': 'Z',
  1636. '\u017D': 'Z',
  1637. '\u1E92': 'Z',
  1638. '\u1E94': 'Z',
  1639. '\u01B5': 'Z',
  1640. '\u0224': 'Z',
  1641. '\u2C7F': 'Z',
  1642. '\u2C6B': 'Z',
  1643. '\uA762': 'Z',
  1644. '\u24D0': 'a',
  1645. '\uFF41': 'a',
  1646. '\u1E9A': 'a',
  1647. '\u00E0': 'a',
  1648. '\u00E1': 'a',
  1649. '\u00E2': 'a',
  1650. '\u1EA7': 'a',
  1651. '\u1EA5': 'a',
  1652. '\u1EAB': 'a',
  1653. '\u1EA9': 'a',
  1654. '\u00E3': 'a',
  1655. '\u0101': 'a',
  1656. '\u0103': 'a',
  1657. '\u1EB1': 'a',
  1658. '\u1EAF': 'a',
  1659. '\u1EB5': 'a',
  1660. '\u1EB3': 'a',
  1661. '\u0227': 'a',
  1662. '\u01E1': 'a',
  1663. '\u00E4': 'a',
  1664. '\u01DF': 'a',
  1665. '\u1EA3': 'a',
  1666. '\u00E5': 'a',
  1667. '\u01FB': 'a',
  1668. '\u01CE': 'a',
  1669. '\u0201': 'a',
  1670. '\u0203': 'a',
  1671. '\u1EA1': 'a',
  1672. '\u1EAD': 'a',
  1673. '\u1EB7': 'a',
  1674. '\u1E01': 'a',
  1675. '\u0105': 'a',
  1676. '\u2C65': 'a',
  1677. '\u0250': 'a',
  1678. '\uA733': 'aa',
  1679. '\u00E6': 'ae',
  1680. '\u01FD': 'ae',
  1681. '\u01E3': 'ae',
  1682. '\uA735': 'ao',
  1683. '\uA737': 'au',
  1684. '\uA739': 'av',
  1685. '\uA73B': 'av',
  1686. '\uA73D': 'ay',
  1687. '\u24D1': 'b',
  1688. '\uFF42': 'b',
  1689. '\u1E03': 'b',
  1690. '\u1E05': 'b',
  1691. '\u1E07': 'b',
  1692. '\u0180': 'b',
  1693. '\u0183': 'b',
  1694. '\u0253': 'b',
  1695. '\u24D2': 'c',
  1696. '\uFF43': 'c',
  1697. '\u0107': 'c',
  1698. '\u0109': 'c',
  1699. '\u010B': 'c',
  1700. '\u010D': 'c',
  1701. '\u00E7': 'c',
  1702. '\u1E09': 'c',
  1703. '\u0188': 'c',
  1704. '\u023C': 'c',
  1705. '\uA73F': 'c',
  1706. '\u2184': 'c',
  1707. '\u24D3': 'd',
  1708. '\uFF44': 'd',
  1709. '\u1E0B': 'd',
  1710. '\u010F': 'd',
  1711. '\u1E0D': 'd',
  1712. '\u1E11': 'd',
  1713. '\u1E13': 'd',
  1714. '\u1E0F': 'd',
  1715. '\u0111': 'd',
  1716. '\u018C': 'd',
  1717. '\u0256': 'd',
  1718. '\u0257': 'd',
  1719. '\uA77A': 'd',
  1720. '\u01F3': 'dz',
  1721. '\u01C6': 'dz',
  1722. '\u24D4': 'e',
  1723. '\uFF45': 'e',
  1724. '\u00E8': 'e',
  1725. '\u00E9': 'e',
  1726. '\u00EA': 'e',
  1727. '\u1EC1': 'e',
  1728. '\u1EBF': 'e',
  1729. '\u1EC5': 'e',
  1730. '\u1EC3': 'e',
  1731. '\u1EBD': 'e',
  1732. '\u0113': 'e',
  1733. '\u1E15': 'e',
  1734. '\u1E17': 'e',
  1735. '\u0115': 'e',
  1736. '\u0117': 'e',
  1737. '\u00EB': 'e',
  1738. '\u1EBB': 'e',
  1739. '\u011B': 'e',
  1740. '\u0205': 'e',
  1741. '\u0207': 'e',
  1742. '\u1EB9': 'e',
  1743. '\u1EC7': 'e',
  1744. '\u0229': 'e',
  1745. '\u1E1D': 'e',
  1746. '\u0119': 'e',
  1747. '\u1E19': 'e',
  1748. '\u1E1B': 'e',
  1749. '\u0247': 'e',
  1750. '\u025B': 'e',
  1751. '\u01DD': 'e',
  1752. '\u24D5': 'f',
  1753. '\uFF46': 'f',
  1754. '\u1E1F': 'f',
  1755. '\u0192': 'f',
  1756. '\uA77C': 'f',
  1757. '\u24D6': 'g',
  1758. '\uFF47': 'g',
  1759. '\u01F5': 'g',
  1760. '\u011D': 'g',
  1761. '\u1E21': 'g',
  1762. '\u011F': 'g',
  1763. '\u0121': 'g',
  1764. '\u01E7': 'g',
  1765. '\u0123': 'g',
  1766. '\u01E5': 'g',
  1767. '\u0260': 'g',
  1768. '\uA7A1': 'g',
  1769. '\u1D79': 'g',
  1770. '\uA77F': 'g',
  1771. '\u24D7': 'h',
  1772. '\uFF48': 'h',
  1773. '\u0125': 'h',
  1774. '\u1E23': 'h',
  1775. '\u1E27': 'h',
  1776. '\u021F': 'h',
  1777. '\u1E25': 'h',
  1778. '\u1E29': 'h',
  1779. '\u1E2B': 'h',
  1780. '\u1E96': 'h',
  1781. '\u0127': 'h',
  1782. '\u2C68': 'h',
  1783. '\u2C76': 'h',
  1784. '\u0265': 'h',
  1785. '\u0195': 'hv',
  1786. '\u24D8': 'i',
  1787. '\uFF49': 'i',
  1788. '\u00EC': 'i',
  1789. '\u00ED': 'i',
  1790. '\u00EE': 'i',
  1791. '\u0129': 'i',
  1792. '\u012B': 'i',
  1793. '\u012D': 'i',
  1794. '\u00EF': 'i',
  1795. '\u1E2F': 'i',
  1796. '\u1EC9': 'i',
  1797. '\u01D0': 'i',
  1798. '\u0209': 'i',
  1799. '\u020B': 'i',
  1800. '\u1ECB': 'i',
  1801. '\u012F': 'i',
  1802. '\u1E2D': 'i',
  1803. '\u0268': 'i',
  1804. '\u0131': 'i',
  1805. '\u24D9': 'j',
  1806. '\uFF4A': 'j',
  1807. '\u0135': 'j',
  1808. '\u01F0': 'j',
  1809. '\u0249': 'j',
  1810. '\u24DA': 'k',
  1811. '\uFF4B': 'k',
  1812. '\u1E31': 'k',
  1813. '\u01E9': 'k',
  1814. '\u1E33': 'k',
  1815. '\u0137': 'k',
  1816. '\u1E35': 'k',
  1817. '\u0199': 'k',
  1818. '\u2C6A': 'k',
  1819. '\uA741': 'k',
  1820. '\uA743': 'k',
  1821. '\uA745': 'k',
  1822. '\uA7A3': 'k',
  1823. '\u24DB': 'l',
  1824. '\uFF4C': 'l',
  1825. '\u0140': 'l',
  1826. '\u013A': 'l',
  1827. '\u013E': 'l',
  1828. '\u1E37': 'l',
  1829. '\u1E39': 'l',
  1830. '\u013C': 'l',
  1831. '\u1E3D': 'l',
  1832. '\u1E3B': 'l',
  1833. '\u017F': 'l',
  1834. '\u0142': 'l',
  1835. '\u019A': 'l',
  1836. '\u026B': 'l',
  1837. '\u2C61': 'l',
  1838. '\uA749': 'l',
  1839. '\uA781': 'l',
  1840. '\uA747': 'l',
  1841. '\u01C9': 'lj',
  1842. '\u24DC': 'm',
  1843. '\uFF4D': 'm',
  1844. '\u1E3F': 'm',
  1845. '\u1E41': 'm',
  1846. '\u1E43': 'm',
  1847. '\u0271': 'm',
  1848. '\u026F': 'm',
  1849. '\u24DD': 'n',
  1850. '\uFF4E': 'n',
  1851. '\u01F9': 'n',
  1852. '\u0144': 'n',
  1853. '\u00F1': 'n',
  1854. '\u1E45': 'n',
  1855. '\u0148': 'n',
  1856. '\u1E47': 'n',
  1857. '\u0146': 'n',
  1858. '\u1E4B': 'n',
  1859. '\u1E49': 'n',
  1860. '\u019E': 'n',
  1861. '\u0272': 'n',
  1862. '\u0149': 'n',
  1863. '\uA791': 'n',
  1864. '\uA7A5': 'n',
  1865. '\u01CC': 'nj',
  1866. '\u24DE': 'o',
  1867. '\uFF4F': 'o',
  1868. '\u00F2': 'o',
  1869. '\u00F3': 'o',
  1870. '\u00F4': 'o',
  1871. '\u1ED3': 'o',
  1872. '\u1ED1': 'o',
  1873. '\u1ED7': 'o',
  1874. '\u1ED5': 'o',
  1875. '\u00F5': 'o',
  1876. '\u1E4D': 'o',
  1877. '\u022D': 'o',
  1878. '\u1E4F': 'o',
  1879. '\u014D': 'o',
  1880. '\u1E51': 'o',
  1881. '\u1E53': 'o',
  1882. '\u014F': 'o',
  1883. '\u022F': 'o',
  1884. '\u0231': 'o',
  1885. '\u00F6': 'o',
  1886. '\u022B': 'o',
  1887. '\u1ECF': 'o',
  1888. '\u0151': 'o',
  1889. '\u01D2': 'o',
  1890. '\u020D': 'o',
  1891. '\u020F': 'o',
  1892. '\u01A1': 'o',
  1893. '\u1EDD': 'o',
  1894. '\u1EDB': 'o',
  1895. '\u1EE1': 'o',
  1896. '\u1EDF': 'o',
  1897. '\u1EE3': 'o',
  1898. '\u1ECD': 'o',
  1899. '\u1ED9': 'o',
  1900. '\u01EB': 'o',
  1901. '\u01ED': 'o',
  1902. '\u00F8': 'o',
  1903. '\u01FF': 'o',
  1904. '\u0254': 'o',
  1905. '\uA74B': 'o',
  1906. '\uA74D': 'o',
  1907. '\u0275': 'o',
  1908. '\u01A3': 'oi',
  1909. '\u0223': 'ou',
  1910. '\uA74F': 'oo',
  1911. '\u24DF': 'p',
  1912. '\uFF50': 'p',
  1913. '\u1E55': 'p',
  1914. '\u1E57': 'p',
  1915. '\u01A5': 'p',
  1916. '\u1D7D': 'p',
  1917. '\uA751': 'p',
  1918. '\uA753': 'p',
  1919. '\uA755': 'p',
  1920. '\u24E0': 'q',
  1921. '\uFF51': 'q',
  1922. '\u024B': 'q',
  1923. '\uA757': 'q',
  1924. '\uA759': 'q',
  1925. '\u24E1': 'r',
  1926. '\uFF52': 'r',
  1927. '\u0155': 'r',
  1928. '\u1E59': 'r',
  1929. '\u0159': 'r',
  1930. '\u0211': 'r',
  1931. '\u0213': 'r',
  1932. '\u1E5B': 'r',
  1933. '\u1E5D': 'r',
  1934. '\u0157': 'r',
  1935. '\u1E5F': 'r',
  1936. '\u024D': 'r',
  1937. '\u027D': 'r',
  1938. '\uA75B': 'r',
  1939. '\uA7A7': 'r',
  1940. '\uA783': 'r',
  1941. '\u24E2': 's',
  1942. '\uFF53': 's',
  1943. '\u00DF': 's',
  1944. '\u015B': 's',
  1945. '\u1E65': 's',
  1946. '\u015D': 's',
  1947. '\u1E61': 's',
  1948. '\u0161': 's',
  1949. '\u1E67': 's',
  1950. '\u1E63': 's',
  1951. '\u1E69': 's',
  1952. '\u0219': 's',
  1953. '\u015F': 's',
  1954. '\u023F': 's',
  1955. '\uA7A9': 's',
  1956. '\uA785': 's',
  1957. '\u1E9B': 's',
  1958. '\u24E3': 't',
  1959. '\uFF54': 't',
  1960. '\u1E6B': 't',
  1961. '\u1E97': 't',
  1962. '\u0165': 't',
  1963. '\u1E6D': 't',
  1964. '\u021B': 't',
  1965. '\u0163': 't',
  1966. '\u1E71': 't',
  1967. '\u1E6F': 't',
  1968. '\u0167': 't',
  1969. '\u01AD': 't',
  1970. '\u0288': 't',
  1971. '\u2C66': 't',
  1972. '\uA787': 't',
  1973. '\uA729': 'tz',
  1974. '\u24E4': 'u',
  1975. '\uFF55': 'u',
  1976. '\u00F9': 'u',
  1977. '\u00FA': 'u',
  1978. '\u00FB': 'u',
  1979. '\u0169': 'u',
  1980. '\u1E79': 'u',
  1981. '\u016B': 'u',
  1982. '\u1E7B': 'u',
  1983. '\u016D': 'u',
  1984. '\u00FC': 'u',
  1985. '\u01DC': 'u',
  1986. '\u01D8': 'u',
  1987. '\u01D6': 'u',
  1988. '\u01DA': 'u',
  1989. '\u1EE7': 'u',
  1990. '\u016F': 'u',
  1991. '\u0171': 'u',
  1992. '\u01D4': 'u',
  1993. '\u0215': 'u',
  1994. '\u0217': 'u',
  1995. '\u01B0': 'u',
  1996. '\u1EEB': 'u',
  1997. '\u1EE9': 'u',
  1998. '\u1EEF': 'u',
  1999. '\u1EED': 'u',
  2000. '\u1EF1': 'u',
  2001. '\u1EE5': 'u',
  2002. '\u1E73': 'u',
  2003. '\u0173': 'u',
  2004. '\u1E77': 'u',
  2005. '\u1E75': 'u',
  2006. '\u0289': 'u',
  2007. '\u24E5': 'v',
  2008. '\uFF56': 'v',
  2009. '\u1E7D': 'v',
  2010. '\u1E7F': 'v',
  2011. '\u028B': 'v',
  2012. '\uA75F': 'v',
  2013. '\u028C': 'v',
  2014. '\uA761': 'vy',
  2015. '\u24E6': 'w',
  2016. '\uFF57': 'w',
  2017. '\u1E81': 'w',
  2018. '\u1E83': 'w',
  2019. '\u0175': 'w',
  2020. '\u1E87': 'w',
  2021. '\u1E85': 'w',
  2022. '\u1E98': 'w',
  2023. '\u1E89': 'w',
  2024. '\u2C73': 'w',
  2025. '\u24E7': 'x',
  2026. '\uFF58': 'x',
  2027. '\u1E8B': 'x',
  2028. '\u1E8D': 'x',
  2029. '\u24E8': 'y',
  2030. '\uFF59': 'y',
  2031. '\u1EF3': 'y',
  2032. '\u00FD': 'y',
  2033. '\u0177': 'y',
  2034. '\u1EF9': 'y',
  2035. '\u0233': 'y',
  2036. '\u1E8F': 'y',
  2037. '\u00FF': 'y',
  2038. '\u1EF7': 'y',
  2039. '\u1E99': 'y',
  2040. '\u1EF5': 'y',
  2041. '\u01B4': 'y',
  2042. '\u024F': 'y',
  2043. '\u1EFF': 'y',
  2044. '\u24E9': 'z',
  2045. '\uFF5A': 'z',
  2046. '\u017A': 'z',
  2047. '\u1E91': 'z',
  2048. '\u017C': 'z',
  2049. '\u017E': 'z',
  2050. '\u1E93': 'z',
  2051. '\u1E95': 'z',
  2052. '\u01B6': 'z',
  2053. '\u0225': 'z',
  2054. '\u0240': 'z',
  2055. '\u2C6C': 'z',
  2056. '\uA763': 'z',
  2057. '\u0386': '\u0391',
  2058. '\u0388': '\u0395',
  2059. '\u0389': '\u0397',
  2060. '\u038A': '\u0399',
  2061. '\u03AA': '\u0399',
  2062. '\u038C': '\u039F',
  2063. '\u038E': '\u03A5',
  2064. '\u03AB': '\u03A5',
  2065. '\u038F': '\u03A9',
  2066. '\u03AC': '\u03B1',
  2067. '\u03AD': '\u03B5',
  2068. '\u03AE': '\u03B7',
  2069. '\u03AF': '\u03B9',
  2070. '\u03CA': '\u03B9',
  2071. '\u0390': '\u03B9',
  2072. '\u03CC': '\u03BF',
  2073. '\u03CD': '\u03C5',
  2074. '\u03CB': '\u03C5',
  2075. '\u03B0': '\u03C5',
  2076. '\u03C9': '\u03C9',
  2077. '\u03C2': '\u03C3'
  2078. };
  2079. return diacritics;
  2080. });
  2081. define('select2/data/base',[
  2082. '../utils'
  2083. ], function (Utils) {
  2084. function BaseAdapter ($element, options) {
  2085. BaseAdapter.__super__.constructor.call(this);
  2086. }
  2087. Utils.Extend(BaseAdapter, Utils.Observable);
  2088. BaseAdapter.prototype.current = function (callback) {
  2089. throw new Error('The `current` method must be defined in child classes.');
  2090. };
  2091. BaseAdapter.prototype.query = function (params, callback) {
  2092. throw new Error('The `query` method must be defined in child classes.');
  2093. };
  2094. BaseAdapter.prototype.bind = function (container, $container) {
  2095. // Can be implemented in subclasses
  2096. };
  2097. BaseAdapter.prototype.destroy = function () {
  2098. // Can be implemented in subclasses
  2099. };
  2100. BaseAdapter.prototype.generateResultId = function (container, data) {
  2101. var id = container.id + '-result-';
  2102. id += Utils.generateChars(4);
  2103. if (data.id != null) {
  2104. id += '-' + data.id.toString();
  2105. } else {
  2106. id += '-' + Utils.generateChars(4);
  2107. }
  2108. return id;
  2109. };
  2110. return BaseAdapter;
  2111. });
  2112. define('select2/data/select',[
  2113. './base',
  2114. '../utils',
  2115. 'jquery'
  2116. ], function (BaseAdapter, Utils, $) {
  2117. function SelectAdapter ($element, options) {
  2118. this.$element = $element;
  2119. this.options = options;
  2120. SelectAdapter.__super__.constructor.call(this);
  2121. }
  2122. Utils.Extend(SelectAdapter, BaseAdapter);
  2123. SelectAdapter.prototype.current = function (callback) {
  2124. var data = [];
  2125. var self = this;
  2126. this.$element.find(':selected').each(function () {
  2127. var $option = $(this);
  2128. var option = self.item($option);
  2129. data.push(option);
  2130. });
  2131. callback(data);
  2132. };
  2133. SelectAdapter.prototype.select = function (data) {
  2134. var self = this;
  2135. if (this.$element.prop('multiple')) {
  2136. this.current(function (currentData) {
  2137. var val = [];
  2138. data = [data];
  2139. data.push.apply(data, currentData);
  2140. for (var d = 0; d < data.length; d++) {
  2141. id = data[d].id;
  2142. if (val.indexOf(id) === -1) {
  2143. val.push(id);
  2144. }
  2145. }
  2146. self.$element.val(val);
  2147. self.$element.trigger('change');
  2148. });
  2149. } else {
  2150. var val = data.id;
  2151. this.$element.val(val);
  2152. this.$element.trigger('change');
  2153. }
  2154. };
  2155. SelectAdapter.prototype.unselect = function (data) {
  2156. var self = this;
  2157. if (!this.$element.prop('multiple')) {
  2158. return;
  2159. }
  2160. this.current(function (currentData) {
  2161. var val = [];
  2162. for (var d = 0; d < currentData.length; d++) {
  2163. id = currentData[d].id;
  2164. if (id !== data.id && val.indexOf(id) === -1) {
  2165. val.push(id);
  2166. }
  2167. }
  2168. self.$element.val(val);
  2169. self.$element.trigger('change');
  2170. });
  2171. };
  2172. SelectAdapter.prototype.bind = function (container, $container) {
  2173. var self = this;
  2174. this.container = container;
  2175. container.on('select', function (params) {
  2176. self.select(params.data);
  2177. });
  2178. container.on('unselect', function (params) {
  2179. self.unselect(params.data);
  2180. });
  2181. };
  2182. SelectAdapter.prototype.destroy = function () {
  2183. // Remove anything added to child elements
  2184. this.$element.find('*').each(function () {
  2185. // Remove any custom data set by Select2
  2186. $.removeData(this, 'data');
  2187. });
  2188. };
  2189. SelectAdapter.prototype.query = function (params, callback) {
  2190. var data = [];
  2191. var self = this;
  2192. var $options = this.$element.children();
  2193. $options.each(function () {
  2194. var $option = $(this);
  2195. if (!$option.is('option') && !$option.is('optgroup')) {
  2196. return;
  2197. }
  2198. var option = self.item($option);
  2199. var matches = self.matches(params, option);
  2200. if (matches !== null) {
  2201. data.push(matches);
  2202. }
  2203. });
  2204. callback(data);
  2205. };
  2206. SelectAdapter.prototype.option = function (data) {
  2207. var option = document.createElement('option');
  2208. option.value = data.id;
  2209. if (data.disabled) {
  2210. option.disabled = true;
  2211. }
  2212. if (data.selected) {
  2213. option.selected = true;
  2214. }
  2215. option.innerText = data.text;
  2216. var $option = $(option);
  2217. var normalizedData = this._normalizeItem(data);
  2218. // Override the option's data with the combined data
  2219. $.data(option, 'data', normalizedData);
  2220. return $option;
  2221. };
  2222. SelectAdapter.prototype.item = function ($option) {
  2223. var data = {};
  2224. data = $.data($option[0], 'data');
  2225. if (data != null) {
  2226. return data;
  2227. }
  2228. if ($option.is('option')) {
  2229. data = {
  2230. id: $option.val(),
  2231. text: $option.html(),
  2232. disabled: $option.prop('disabled'),
  2233. selected: $option.prop('selected')
  2234. };
  2235. } else if ($option.is('optgroup')) {
  2236. data = {
  2237. text: $option.attr('label'),
  2238. children: []
  2239. };
  2240. var $children = $option.children('option');
  2241. var children = [];
  2242. for (var c = 0; c < $children.length; c++) {
  2243. var $child = $($children[c]);
  2244. var child = this.item($child);
  2245. children.push(child);
  2246. }
  2247. data.children = children;
  2248. }
  2249. data = this._normalizeItem(data);
  2250. $.data($option[0], 'data', data);
  2251. return data;
  2252. };
  2253. SelectAdapter.prototype._normalizeItem = function (item) {
  2254. if (item.text == null) {
  2255. item = {
  2256. id: item,
  2257. text: item
  2258. };
  2259. }
  2260. var defaults = {
  2261. selected: false,
  2262. disabled: false
  2263. };
  2264. if (item.id != null) {
  2265. item.id = item.id.toString();
  2266. }
  2267. if (item.text != null) {
  2268. item.text = item.text.toString();
  2269. }
  2270. if (item._resultId == null && item.id && this.container != null) {
  2271. item._resultId = this.generateResultId(this.container, item);
  2272. }
  2273. return $.extend({}, defaults, item);
  2274. };
  2275. SelectAdapter.prototype.matches = function (params, data) {
  2276. var matcher = this.options.get('matcher');
  2277. return matcher(params, data);
  2278. };
  2279. return SelectAdapter;
  2280. });
  2281. define('select2/data/array',[
  2282. './select',
  2283. '../utils',
  2284. 'jquery'
  2285. ], function (SelectAdapter, Utils, $) {
  2286. function ArrayAdapter ($element, options) {
  2287. var data = options.get('data');
  2288. ArrayAdapter.__super__.constructor.call(this, $element, options);
  2289. this.convertToOptions(data);
  2290. }
  2291. Utils.Extend(ArrayAdapter, SelectAdapter);
  2292. ArrayAdapter.prototype.select = function (data) {
  2293. var $option = this.$element.find('option[value="' + data.id + '"]');
  2294. if ($option.length === 0) {
  2295. $option = this.option(data);
  2296. this.$element.append($option);
  2297. }
  2298. ArrayAdapter.__super__.select.call(this, data);
  2299. };
  2300. ArrayAdapter.prototype.convertToOptions = function (data) {
  2301. var self = this;
  2302. var $existing = this.$element.find('option');
  2303. var existingIds = $existing.map(function () {
  2304. return self.item($(this)).id;
  2305. }).get();
  2306. // Filter out all items except for the one passed in the argument
  2307. function onlyItem (item) {
  2308. return function () {
  2309. return $(this).val() == item.id;
  2310. };
  2311. }
  2312. for (var d = 0; d < data.length; d++) {
  2313. var item = data[d];
  2314. item.id = item.id.toString();
  2315. // Skip items which were pre-loaded, only merge the data
  2316. if (existingIds.indexOf(item.id) >= 0) {
  2317. var $existingOption = $existing.filter(onlyItem(item));
  2318. var existingData = this.item($existingOption);
  2319. var newData = $.extend(true, {}, existingData, item);
  2320. var $newOption = this.option(existingData);
  2321. $existingOption.replaceWith($newOption);
  2322. continue;
  2323. }
  2324. var $option = this.option(item);
  2325. this.$element.append($option);
  2326. }
  2327. };
  2328. return ArrayAdapter;
  2329. });
  2330. define('select2/data/ajax',[
  2331. './array',
  2332. '../utils',
  2333. 'jquery'
  2334. ], function (ArrayAdapter, Utils, $) {
  2335. function AjaxAdapter ($element, options) {
  2336. this.ajaxOptions = options.get('ajax');
  2337. if (this.ajaxOptions.processResults != null) {
  2338. this.processResults = this.ajaxOptions.processResults;
  2339. }
  2340. ArrayAdapter.__super__.constructor.call(this, $element, options);
  2341. }
  2342. Utils.Extend(AjaxAdapter, ArrayAdapter);
  2343. AjaxAdapter.prototype.processResults = function (results) {
  2344. return results;
  2345. };
  2346. AjaxAdapter.prototype.query = function (params, callback) {
  2347. var matches = [];
  2348. var self = this;
  2349. if (this._request) {
  2350. this._request.abort();
  2351. this._request = null;
  2352. }
  2353. var options = $.extend({
  2354. type: 'GET'
  2355. }, this.ajaxOptions);
  2356. if (typeof options.url === 'function') {
  2357. options.url = options.url(params);
  2358. }
  2359. if (typeof options.data === 'function') {
  2360. options.data = options.data(params);
  2361. }
  2362. function request () {
  2363. var $request = $.ajax(options);
  2364. $request.success(function (data) {
  2365. var results = self.processResults(data);
  2366. callback(results);
  2367. });
  2368. self._request = $request;
  2369. }
  2370. if (this.ajaxOptions.delay && params.term !== '') {
  2371. if (this._queryTimeout) {
  2372. window.clearTimeout(this._queryTimeout);
  2373. }
  2374. this._queryTimeout = window.setTimeout(request, this.ajaxOptions.delay);
  2375. } else {
  2376. request();
  2377. }
  2378. };
  2379. return AjaxAdapter;
  2380. });
  2381. define('select2/data/tags',[
  2382. ], function () {
  2383. function Tags (decorated, $element, options) {
  2384. var tags = options.get('tags');
  2385. decorated.call(this, $element, options);
  2386. if ($.isArray(tags)) {
  2387. for (var t = 0; t < tags.length; t++) {
  2388. var tag = tags[t];
  2389. var item = this._normalizeItem(tag);
  2390. var $option = this.option(item);
  2391. this.$element.append($option);
  2392. }
  2393. }
  2394. }
  2395. Tags.prototype.query = function (decorated, params, callback) {
  2396. var self = this;
  2397. this._removeOldTags();
  2398. if (params.term == null || params.term === '' || params.page != null) {
  2399. decorated.call(this, params, callback);
  2400. return;
  2401. }
  2402. function wrapper (data, child) {
  2403. for (var i = 0; i < data.length; i++) {
  2404. var option = data[i];
  2405. var checkChildren = (
  2406. option.children != null && !wrapper(option.children, true)
  2407. );
  2408. var checkText = option.text === params.term;
  2409. if (checkText || checkChildren) {
  2410. if (child) {
  2411. return false;
  2412. }
  2413. callback(data);
  2414. return;
  2415. }
  2416. }
  2417. if (child) {
  2418. return true;
  2419. }
  2420. var tag = self.createTag(params);
  2421. if (tag != null) {
  2422. var $option = self.option(tag);
  2423. $option.attr('data-select2-tag', true);
  2424. self.$element.append($option);
  2425. self.insertTag(data, tag);
  2426. }
  2427. callback(data);
  2428. }
  2429. decorated.call(this, params, wrapper);
  2430. };
  2431. Tags.prototype.createTag = function (decorated, params) {
  2432. return {
  2433. id: params.term,
  2434. text: params.term
  2435. };
  2436. };
  2437. Tags.prototype.insertTag = function (_, data, tag) {
  2438. data.unshift(tag);
  2439. };
  2440. Tags.prototype._removeOldTags = function (_) {
  2441. var tag = this._lastTag;
  2442. var $options = this.$element.find('option[data-select2-tag]');
  2443. $options.each(function () {
  2444. if (this.selected) {
  2445. return;
  2446. }
  2447. $(this).remove();
  2448. });
  2449. };
  2450. return Tags;
  2451. });
  2452. define('select2/data/minimumInputLength',[
  2453. ], function () {
  2454. function MinimumInputLength (decorated, $e, options) {
  2455. this.minimumInputLength = options.get('minimumInputLength');
  2456. decorated.call(this, $e, options);
  2457. }
  2458. MinimumInputLength.prototype.query = function (decorated, params, callback) {
  2459. params.term = params.term || '';
  2460. if (params.term.length < this.minimumInputLength) {
  2461. this.trigger('results:message', {
  2462. message: 'inputTooShort',
  2463. args: {
  2464. minimum: this.minimumInputLength,
  2465. input: params.term,
  2466. params: params
  2467. }
  2468. });
  2469. return;
  2470. }
  2471. decorated.call(this, params, callback);
  2472. };
  2473. return MinimumInputLength;
  2474. });
  2475. define('select2/data/maximumInputLength',[
  2476. ], function () {
  2477. function MaximumInputLength (decorated, $e, options) {
  2478. this.maximumInputLength = options.get('maximumInputLength');
  2479. decorated.call(this, $e, options);
  2480. }
  2481. MaximumInputLength.prototype.query = function (decorated, params, callback) {
  2482. params.term = params.term || '';
  2483. if (this.maximumInputLength > 0 &&
  2484. params.term.length > this.maximumInputLength) {
  2485. this.trigger('results:message', {
  2486. message: 'inputTooLong',
  2487. args: {
  2488. minimum: this.maximumInputLength,
  2489. input: params.term,
  2490. params: params
  2491. }
  2492. });
  2493. return;
  2494. }
  2495. decorated.call(this, params, callback);
  2496. };
  2497. return MaximumInputLength;
  2498. });
  2499. define('select2/dropdown',[
  2500. './utils'
  2501. ], function (Utils) {
  2502. function Dropdown ($element, options) {
  2503. this.$element = $element;
  2504. }
  2505. Utils.Extend(Dropdown, Utils.Observable);
  2506. Dropdown.prototype.render = function () {
  2507. var $dropdown = $(
  2508. '<span class="select2-dropdown">' +
  2509. '<span class="select2-results"></span>' +
  2510. '</span>'
  2511. );
  2512. this.$dropdown = $dropdown;
  2513. return $dropdown;
  2514. };
  2515. Dropdown.prototype.position = function ($dropdown, $container) {
  2516. // Should be implmented in subclasses
  2517. };
  2518. Dropdown.prototype.destroy = function () {
  2519. // Remove the dropdown from the DOM
  2520. this.$dropdown.remove();
  2521. };
  2522. Dropdown.prototype.bind = function (container, $container) {
  2523. // Can be implemented in subclasses
  2524. };
  2525. return Dropdown;
  2526. });
  2527. define('select2/dropdown/search',[
  2528. '../utils'
  2529. ], function (Utils) {
  2530. function Search () { }
  2531. Search.prototype.render = function (decorated) {
  2532. var $rendered = decorated.call(this);
  2533. var $search = $(
  2534. '<span class="select2-search select2-search--dropdown">' +
  2535. '<input class="select2-search__field" type="search" tabindex="-1"' +
  2536. ' role="textbox" />' +
  2537. '</span>'
  2538. );
  2539. this.$searchContainer = $search;
  2540. this.$search = $search.find('input');
  2541. $rendered.prepend($search);
  2542. return $rendered;
  2543. };
  2544. Search.prototype.bind = function (decorated, container, $container) {
  2545. var self = this;
  2546. decorated.call(this, container, $container);
  2547. this.$search.on('keydown', function (evt) {
  2548. self.trigger('keypress', evt);
  2549. self._keyUpPrevented = evt.isDefaultPrevented();
  2550. });
  2551. this.$search.on('keyup', function (evt) {
  2552. self.handleSearch(evt);
  2553. });
  2554. container.on('open', function () {
  2555. self.$search.attr('tabindex', 0);
  2556. self.$search.focus();
  2557. });
  2558. container.on('close', function () {
  2559. self.$search.attr('tabindex', -1);
  2560. self.$search.val('');
  2561. });
  2562. container.on('results:all', function (params) {
  2563. if (params.query.term == null || params.query.term === '') {
  2564. var showSearch = self.showSearch(params);
  2565. if (showSearch) {
  2566. self.$searchContainer.removeClass('select2-search--hide');
  2567. } else {
  2568. self.$searchContainer.addClass('select2-search--hide');
  2569. }
  2570. }
  2571. });
  2572. };
  2573. Search.prototype.handleSearch = function (evt) {
  2574. if (!this._keyUpPrevented) {
  2575. var input = this.$search.val();
  2576. this.trigger('query', {
  2577. term: input
  2578. });
  2579. }
  2580. this._keyUpPrevented = false;
  2581. };
  2582. Search.prototype.showSearch = function (_, params) {
  2583. return true;
  2584. };
  2585. return Search;
  2586. });
  2587. define('select2/dropdown/hidePlaceholder',[
  2588. ], function () {
  2589. function HidePlaceholder (decorated, $element, options, dataAdapter) {
  2590. this.placeholder = this.normalizePlaceholder(options.get('placeholder'));
  2591. decorated.call(this, $element, options, dataAdapter);
  2592. }
  2593. HidePlaceholder.prototype.append = function (decorated, data) {
  2594. data = this.removePlaceholder(data);
  2595. decorated.call(this, data);
  2596. };
  2597. HidePlaceholder.prototype.normalizePlaceholder = function (_, placeholder) {
  2598. if (typeof placeholder === 'string') {
  2599. placeholder = {
  2600. id: '',
  2601. text: placeholder
  2602. };
  2603. }
  2604. return placeholder;
  2605. };
  2606. HidePlaceholder.prototype.removePlaceholder = function (_, data) {
  2607. var modifiedData = data.slice(0);
  2608. for (var d = data.length - 1; d >= 0; d--) {
  2609. var item = data[d];
  2610. if (this.placeholder.id === item.id) {
  2611. modifiedData.splice(d, 1);
  2612. }
  2613. }
  2614. return modifiedData;
  2615. };
  2616. return HidePlaceholder;
  2617. });
  2618. define('select2/dropdown/infiniteScroll',[
  2619. 'jquery'
  2620. ], function ($) {
  2621. function InfiniteScroll (decorated, $element, options, dataAdapter) {
  2622. this.lastParams = {};
  2623. decorated.call(this, $element, options, dataAdapter);
  2624. this.$loadingMore = this.createLoadingMore();
  2625. this.loading = false;
  2626. }
  2627. InfiniteScroll.prototype.append = function (decorated, data) {
  2628. this.$loadingMore.remove();
  2629. decorated.call(this, data);
  2630. if (data.length > 0) {
  2631. this.$results.append(this.$loadingMore);
  2632. }
  2633. this.loading = false;
  2634. };
  2635. InfiniteScroll.prototype.bind = function (decorated, container, $container) {
  2636. var self = this;
  2637. decorated.call(this, container, $container);
  2638. container.on('query', function (params) {
  2639. self.lastParams = params;
  2640. self.loading = true;
  2641. });
  2642. container.on('query:append', function (params) {
  2643. self.lastParams = params;
  2644. self.loading = true;
  2645. });
  2646. this.$results.on('scroll', function () {
  2647. var loadMoreVisible = $.contains(
  2648. document.documentElement,
  2649. self.$loadingMore[0]
  2650. );
  2651. if (self.loading || !loadMoreVisible) {
  2652. return;
  2653. }
  2654. var currentOffset = self.$results.offset().top +
  2655. self.$results.outerHeight(false);
  2656. var loadingMoreOffset = self.$loadingMore.offset().top +
  2657. self.$loadingMore.outerHeight(false);
  2658. if (currentOffset + 50 >= loadingMoreOffset) {
  2659. self.loadMore();
  2660. }
  2661. });
  2662. };
  2663. InfiniteScroll.prototype.loadMore = function () {
  2664. this.loading = true;
  2665. var params = $.extend({}, {page: 1}, this.lastParams);
  2666. params.page++;
  2667. this.trigger('query:append', params);
  2668. };
  2669. InfiniteScroll.prototype.createLoadingMore = function () {
  2670. var $option = $(
  2671. '<li class="option load-more" role="treeitem"></li>'
  2672. );
  2673. var message = this.options.get('translations').get('loadingMore');
  2674. $option.html(message(this.lastParams));
  2675. return $option;
  2676. };
  2677. return InfiniteScroll;
  2678. });
  2679. define('select2/dropdown/attachBody',[
  2680. ], function () {
  2681. function AttachBody (decorated, $element, options) {
  2682. decorated.call(this, $element, options);
  2683. }
  2684. AttachBody.prototype.bind = function (decorated, container, $container) {
  2685. var self = this;
  2686. decorated.call(this, container, $container);
  2687. container.on('open', function () {
  2688. self._showDropdown();
  2689. });
  2690. container.on('close', function () {
  2691. self._hideDropdown();
  2692. });
  2693. this.$dropdownContainer.on('mousedown', function (evt) {
  2694. evt.stopPropagation();
  2695. });
  2696. };
  2697. AttachBody.prototype.position = function (decorated, $dropdown, $container) {
  2698. // Clone all of the container classes
  2699. $dropdown.attr('class', $container.attr('class'));
  2700. $dropdown.removeClass('select2');
  2701. $dropdown.addClass('select2-container--open');
  2702. $dropdown.css({
  2703. position: 'absolute'
  2704. });
  2705. $dropdown.width($container.outerWidth(false));
  2706. this.$container = $container;
  2707. };
  2708. AttachBody.prototype.render = function (decorated) {
  2709. var $container = $('<span></span>');
  2710. var $dropdown = decorated.call(this);
  2711. $container.append($dropdown);
  2712. this.$dropdownContainer = $container;
  2713. return $container;
  2714. };
  2715. AttachBody.prototype._hideDropdown = function (decorated) {
  2716. this.$dropdownContainer.detach();
  2717. };
  2718. AttachBody.prototype._positionDropdown = function () {
  2719. var css = this.$container.offset();
  2720. css.top += this.$container.outerHeight(true);
  2721. this.$dropdownContainer.css(css);
  2722. };
  2723. AttachBody.prototype._showDropdown = function (decorated) {
  2724. this.$dropdownContainer.appendTo(document.body);
  2725. this._positionDropdown();
  2726. };
  2727. return AttachBody;
  2728. });
  2729. define('select2/i18n/en',[],function () {
  2730. return {
  2731. errorLoading: function () {
  2732. return 'The results could not be loaded.';
  2733. },
  2734. inputTooLong: function (args) {
  2735. var overChars = args.input.length - args.maximum;
  2736. var message = 'Please delete ' + overChars + ' character';
  2737. if (overChars != 1) {
  2738. message += 's';
  2739. }
  2740. return message;
  2741. },
  2742. inputTooShort: function (args) {
  2743. var remainingChars = args.minimum - args.input.length;
  2744. var message = 'Please enter ' + remainingChars + ' or more character';
  2745. if (remainingChars != 1) {
  2746. message += 's';
  2747. }
  2748. return message;
  2749. },
  2750. loadingMore: function () {
  2751. return 'Loading more results…';
  2752. },
  2753. maximumSelected: function (args) {
  2754. var message = 'You can only select ' + args.maximum + ' item';
  2755. if (args.maximum != 1) {
  2756. message += 's';
  2757. }
  2758. return message;
  2759. },
  2760. noResults: function () {
  2761. return 'No results found';
  2762. },
  2763. searching: function () {
  2764. return 'Searching…';
  2765. }
  2766. };
  2767. });
  2768. define('select2/defaults',[
  2769. 'jquery',
  2770. './results',
  2771. './selection/single',
  2772. './selection/multiple',
  2773. './selection/placeholder',
  2774. './selection/allowClear',
  2775. './selection/search',
  2776. './utils',
  2777. './translation',
  2778. './diacritics',
  2779. './data/select',
  2780. './data/array',
  2781. './data/ajax',
  2782. './data/tags',
  2783. './data/minimumInputLength',
  2784. './data/maximumInputLength',
  2785. './dropdown',
  2786. './dropdown/search',
  2787. './dropdown/hidePlaceholder',
  2788. './dropdown/infiniteScroll',
  2789. './dropdown/attachBody',
  2790. './i18n/en'
  2791. ], function ($, ResultsList,
  2792. SingleSelection, MultipleSelection, Placeholder, AllowClear,
  2793. SelectionSearch,
  2794. Utils, Translation, DIACRITICS,
  2795. SelectData, ArrayData, AjaxData, Tags,
  2796. MinimumInputLength, MaximumInputLength,
  2797. Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll,
  2798. AttachBody,
  2799. EnglishTranslation) {
  2800. function Defaults () {
  2801. this.reset();
  2802. }
  2803. Defaults.prototype.apply = function (options) {
  2804. options = $.extend({}, this.defaults, options);
  2805. if (options.dataAdapter == null) {
  2806. if (options.ajax != null) {
  2807. options.dataAdapter = AjaxData;
  2808. } else if (options.data != null) {
  2809. options.dataAdapter = ArrayData;
  2810. } else {
  2811. options.dataAdapter = SelectData;
  2812. }
  2813. }
  2814. if (options.minimumInputLength > 0) {
  2815. options.dataAdapter = Utils.Decorate(
  2816. options.dataAdapter,
  2817. MinimumInputLength
  2818. );
  2819. }
  2820. if (options.maximumInputLength > 0) {
  2821. options.dataAdapter = Utils.Decorate(
  2822. options.dataAdapter,
  2823. MaximumInputLength
  2824. );
  2825. }
  2826. if (options.tags != null) {
  2827. options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
  2828. }
  2829. if (options.resultsAdapter == null) {
  2830. options.resultsAdapter = ResultsList;
  2831. if (options.ajax != null) {
  2832. options.resultsAdapter = Utils.Decorate(
  2833. options.resultsAdapter,
  2834. InfiniteScroll
  2835. );
  2836. }
  2837. if (options.placeholder != null) {
  2838. options.resultsAdapter = Utils.Decorate(
  2839. options.resultsAdapter,
  2840. HidePlaceholder
  2841. );
  2842. }
  2843. }
  2844. if (options.dropdownAdapter == null) {
  2845. if (options.multiple) {
  2846. options.dropdownAdapter = Dropdown;
  2847. } else {
  2848. var SearchableDropdown = Utils.Decorate(Dropdown, DropdownSearch);
  2849. options.dropdownAdapter = SearchableDropdown;
  2850. }
  2851. options.dropdownAdapter = Utils.Decorate(
  2852. options.dropdownAdapter,
  2853. AttachBody
  2854. );
  2855. }
  2856. if (options.selectionAdapter == null) {
  2857. if (options.multiple) {
  2858. options.selectionAdapter = MultipleSelection;
  2859. } else {
  2860. options.selectionAdapter = SingleSelection;
  2861. }
  2862. // Add the placeholder mixin if a placeholder was specified
  2863. if (options.placeholder != null) {
  2864. options.selectionAdapter = Utils.Decorate(
  2865. options.selectionAdapter,
  2866. Placeholder
  2867. );
  2868. if (options.allowClear) {
  2869. options.selectionAdapter = Utils.Decorate(
  2870. options.selectionAdapter,
  2871. AllowClear
  2872. );
  2873. }
  2874. }
  2875. if (options.multiple) {
  2876. options.selectionAdapter = Utils.Decorate(
  2877. options.selectionAdapter,
  2878. SelectionSearch
  2879. );
  2880. }
  2881. }
  2882. if (typeof options.language === 'string') {
  2883. options.language = [options.language];
  2884. }
  2885. if ($.isArray(options.language)) {
  2886. var languages = new Translation();
  2887. options.language.push('en');
  2888. var languageNames = options.language;
  2889. for (var l = 0; l < languageNames.length; l++) {
  2890. var name = languageNames[l];
  2891. var language = {};
  2892. try {
  2893. // Try to load it with the original name
  2894. language = Translation.loadPath(name);
  2895. } catch (e) {
  2896. // If we couldn't load it, check if it wasn't the full path
  2897. name = 'select2/i18n/' + name;
  2898. language = Translation.loadPath(name);
  2899. }
  2900. languages.extend(language);
  2901. }
  2902. options.translations = languages;
  2903. } else {
  2904. options.translations = new Translation(options.language);
  2905. }
  2906. return options;
  2907. };
  2908. Defaults.prototype.reset = function () {
  2909. function stripDiacritics (text) {
  2910. // Used 'uni range + named function' from http://jsperf.com/diacritics/18
  2911. function match(a) {
  2912. return DIACRITICS[a] || a;
  2913. }
  2914. return text.replace(/[^\u0000-\u007E]/g, match);
  2915. }
  2916. function matcher (params, data) {
  2917. // Always return the object if there is nothing to compare
  2918. if ($.trim(params.term) === '') {
  2919. return data;
  2920. }
  2921. // Do a recursive check for options with children
  2922. if (data.children && data.children.length > 0) {
  2923. // Clone the data object if there are children
  2924. // This is required as we modify the object to remove any non-matches
  2925. var match = $.extend(true, {}, data);
  2926. // Check each child of the option
  2927. for (var c = data.children.length - 1; c >= 0; c--) {
  2928. var child = data.children[c];
  2929. var matches = matcher(params, child);
  2930. // If there wasn't a match, remove the object in the array
  2931. if (matches == null) {
  2932. match.children.splice(c, 1);
  2933. }
  2934. }
  2935. // If any children matched, return the new object
  2936. if (match.children.length > 0) {
  2937. return match;
  2938. }
  2939. // If there were no matching children, check just the plain object
  2940. return matcher(params, match);
  2941. }
  2942. var original = stripDiacritics(data.text).toUpperCase();
  2943. var term = stripDiacritics(params.term).toUpperCase();
  2944. // Check if the text contains the term
  2945. if (original.indexOf(term) > -1) {
  2946. return data;
  2947. }
  2948. // If it doesn't contain the term, don't return anything
  2949. return null;
  2950. }
  2951. this.defaults = {
  2952. language: EnglishTranslation,
  2953. matcher: matcher,
  2954. minimumInputLength: 0,
  2955. maximumInputLength: 0,
  2956. theme: 'default',
  2957. templateResult: function (result) {
  2958. return result.text;
  2959. },
  2960. templateSelection: function (selection) {
  2961. return selection.text;
  2962. }
  2963. };
  2964. };
  2965. var defaults = new Defaults();
  2966. return defaults;
  2967. });
  2968. define('select2/options',[
  2969. './defaults'
  2970. ], function (Defaults) {
  2971. function Options (options, $element) {
  2972. this.options = options;
  2973. if ($element != null) {
  2974. this.fromElement($element);
  2975. }
  2976. this.options = Defaults.apply(this.options);
  2977. }
  2978. Options.prototype.fromElement = function ($e) {
  2979. if (this.options.multiple == null) {
  2980. this.options.multiple = $e.prop('multiple');
  2981. }
  2982. return this;
  2983. };
  2984. Options.prototype.get = function (key) {
  2985. return this.options[key];
  2986. };
  2987. Options.prototype.set = function (key, val) {
  2988. this.options[key] = val;
  2989. };
  2990. return Options;
  2991. });
  2992. define('select2/core',[
  2993. 'jquery',
  2994. './options',
  2995. './utils',
  2996. './keys'
  2997. ], function ($, Options, Utils, KEYS) {
  2998. var Select2 = function ($element, options) {
  2999. if ($element.data('select2') != null) {
  3000. $element.select2('destroy');
  3001. }
  3002. this.$element = $element;
  3003. this.id = this._generateId($element);
  3004. options = options || {};
  3005. this.options = new Options(options, $element);
  3006. Select2.__super__.constructor.call(this);
  3007. // Set up containers and adapters
  3008. var DataAdapter = this.options.get('dataAdapter');
  3009. this.data = new DataAdapter($element, this.options);
  3010. var $container = this.render();
  3011. this._placeContainer($container);
  3012. var SelectionAdapter = this.options.get('selectionAdapter');
  3013. this.selection = new SelectionAdapter($element, this.options);
  3014. this.$selection = this.selection.render();
  3015. this.selection.position(this.$selection, $container);
  3016. var DropdownAdapter = this.options.get('dropdownAdapter');
  3017. this.dropdown = new DropdownAdapter($element, this.options);
  3018. this.$dropdown = this.dropdown.render();
  3019. this.dropdown.position(this.$dropdown, $container);
  3020. var ResultsAdapter = this.options.get('resultsAdapter');
  3021. this.results = new ResultsAdapter($element, this.options, this.data);
  3022. this.$results = this.results.render();
  3023. this.results.position(this.$results, this.$dropdown);
  3024. // Bind events
  3025. var self = this;
  3026. // Bind the container to all of the adapters
  3027. this._bindAdapters();
  3028. // Register any DOM event handlers
  3029. this._registerDomEvents();
  3030. // Register any internal event handlers
  3031. this._registerDataEvents();
  3032. this._registerSelectionEvents();
  3033. this._registerDropdownEvents();
  3034. this._registerResultsEvents();
  3035. this._registerEvents();
  3036. // Set the initial state
  3037. this.data.current(function (initialData) {
  3038. self.trigger('selection:update', {
  3039. data: initialData
  3040. });
  3041. });
  3042. // Hide the original select
  3043. $element.hide();
  3044. this._tabindex = $element.attr('tabindex') || 0;
  3045. $element.attr('tabindex', '-1');
  3046. $element.data('select2', this);
  3047. };
  3048. Utils.Extend(Select2, Utils.Observable);
  3049. Select2.prototype._generateId = function ($element) {
  3050. var id = '';
  3051. if ($element.attr('id') != null) {
  3052. id = $element.attr('id');
  3053. } else if ($element.attr('name') != null) {
  3054. id = $element.attr('name') + '-' + Utils.generateChars(2);
  3055. } else {
  3056. id = Utils.generateChars(4);
  3057. }
  3058. id = 'select2-' + id;
  3059. return id;
  3060. };
  3061. Select2.prototype._placeContainer = function ($container) {
  3062. $container.insertAfter(this.$element);
  3063. $container.width(this.$element.outerWidth(false));
  3064. };
  3065. Select2.prototype._bindAdapters = function () {
  3066. this.data.bind(this, this.$container);
  3067. this.selection.bind(this, this.$container);
  3068. this.dropdown.bind(this, this.$container);
  3069. this.results.bind(this, this.$container);
  3070. };
  3071. Select2.prototype._registerDomEvents = function () {
  3072. var self = this;
  3073. this.$element.on('change.select2', function () {
  3074. self.data.current(function (data) {
  3075. self.trigger('selection:update', {
  3076. data: data
  3077. });
  3078. });
  3079. });
  3080. };
  3081. Select2.prototype._registerDataEvents = function () {
  3082. var self = this;
  3083. this.data.on('results:message', function (params) {
  3084. self.trigger('results:message', params);
  3085. });
  3086. };
  3087. Select2.prototype._registerSelectionEvents = function () {
  3088. var self = this;
  3089. this.selection.on('open', function () {
  3090. self.open();
  3091. });
  3092. this.selection.on('close', function () {
  3093. self.close();
  3094. });
  3095. this.selection.on('toggle', function () {
  3096. self.toggleDropdown();
  3097. });
  3098. this.selection.on('results:select', function () {
  3099. self.trigger('results:select');
  3100. });
  3101. this.selection.on('results:previous', function () {
  3102. self.trigger('results:previous');
  3103. });
  3104. this.selection.on('results:next', function () {
  3105. self.trigger('results:next');
  3106. });
  3107. this.selection.on('unselected', function (params) {
  3108. self.trigger('unselect', params);
  3109. self.close();
  3110. });
  3111. this.selection.on('query', function (params) {
  3112. self.trigger('query', params);
  3113. });
  3114. this.selection.on('keypress', function (e) {
  3115. self.trigger('keypress', e);
  3116. });
  3117. };
  3118. Select2.prototype._registerDropdownEvents = function () {
  3119. var self = this;
  3120. this.dropdown.on('query', function (params) {
  3121. self.trigger('query', params);
  3122. });
  3123. this.dropdown.on('keypress', function (e) {
  3124. self.trigger('keypress', e);
  3125. });
  3126. };
  3127. Select2.prototype._registerResultsEvents = function () {
  3128. var self = this;
  3129. this.results.on('query:append', function (params) {
  3130. self.trigger('query:append', params);
  3131. });
  3132. this.results.on('selected', function (params) {
  3133. self.trigger('select', params);
  3134. self.close();
  3135. });
  3136. this.results.on('unselected', function (params) {
  3137. self.trigger('unselect', params);
  3138. self.close();
  3139. });
  3140. this.results.on('results:focus', function (params) {
  3141. self.trigger('results:focus', params);
  3142. });
  3143. };
  3144. Select2.prototype._registerEvents = function () {
  3145. var self = this;
  3146. this.on('open', function () {
  3147. self.$container.addClass('select2-container--open');
  3148. });
  3149. this.on('close', function () {
  3150. self.$container.removeClass('select2-container--open');
  3151. });
  3152. this.on('query', function (params) {
  3153. this.data.query(params, function (data) {
  3154. self.trigger('results:all', {
  3155. data: data,
  3156. query: params
  3157. });
  3158. });
  3159. });
  3160. this.on('query:append', function (params) {
  3161. this.data.query(params, function (data) {
  3162. self.trigger('results:append', {
  3163. data: data,
  3164. query: params
  3165. });
  3166. });
  3167. });
  3168. this.on('keypress', function (evt) {
  3169. var key = evt.which;
  3170. if (self.isOpen()) {
  3171. if (key === KEYS.ENTER) {
  3172. self.trigger('results:select');
  3173. evt.preventDefault();
  3174. } else if (key === KEYS.UP) {
  3175. self.trigger('results:previous');
  3176. evt.preventDefault();
  3177. } else if (key === KEYS.DOWN) {
  3178. self.trigger('results:next');
  3179. evt.preventDefault();
  3180. } else if (key === KEYS.ESC || key === KEYS.TAB) {
  3181. self.close();
  3182. evt.preventDefault();
  3183. }
  3184. } else {
  3185. if (key === KEYS.ENTER || key === KEYS.SPACE) {
  3186. self.open();
  3187. evt.preventDefault();
  3188. }
  3189. }
  3190. });
  3191. };
  3192. Select2.prototype.toggleDropdown = function () {
  3193. if (this.isOpen()) {
  3194. this.close();
  3195. } else {
  3196. this.open();
  3197. }
  3198. };
  3199. Select2.prototype.open = function () {
  3200. if (this.isOpen()) {
  3201. return;
  3202. }
  3203. this.trigger('query', {});
  3204. this.trigger('open');
  3205. };
  3206. Select2.prototype.close = function () {
  3207. if (!this.isOpen()) {
  3208. return;
  3209. }
  3210. this.trigger('close');
  3211. };
  3212. Select2.prototype.isOpen = function () {
  3213. return this.$container.hasClass('select2-container--open');
  3214. };
  3215. Select2.prototype.destroy = function () {
  3216. this.$container.remove();
  3217. this.$element.off('.select2');
  3218. this.$element.attr('tabindex', this._tabindex);
  3219. this.$element.show();
  3220. this.$element.removeData('select2');
  3221. this.data.destroy();
  3222. this.selection.destroy();
  3223. this.dropdown.destroy();
  3224. this.results.destroy();
  3225. this.data = null;
  3226. this.selection = null;
  3227. this.dropdown = null;
  3228. this.results = null;
  3229. };
  3230. Select2.prototype.render = function () {
  3231. var $container = $(
  3232. '<span class="select2 select2-container">' +
  3233. '<span class="selection"></span>' +
  3234. '<span class="dropdown-wrapper" aria-hidden="true"></span>' +
  3235. '</span>'
  3236. );
  3237. this.$container = $container;
  3238. this.$container.addClass('select2-container--' + this.options.get('theme'));
  3239. $container.data('element', this.$element);
  3240. return $container;
  3241. };
  3242. return Select2;
  3243. });
  3244. define('jquery.select2',[
  3245. 'jquery',
  3246. 'select2/core'
  3247. ], function ($, Select2) {
  3248. if ($.fn.select2 == null) {
  3249. $.fn.select2 = function (options) {
  3250. options = options || {};
  3251. if (typeof options === 'object') {
  3252. this.each(function () {
  3253. var instance = new Select2($(this), options);
  3254. });
  3255. } else if (typeof options === 'string') {
  3256. var instance = this.data('select2');
  3257. var args = Array.prototype.slice.call(arguments, 1);
  3258. instance[options](args);
  3259. } else {
  3260. throw new Error('Invalid arguments for Select2: ' + options);
  3261. }
  3262. };
  3263. }
  3264. return Select2;
  3265. });
  3266. require('jquery.select2'); $.fn.select2.amd = { define: define, require: require };}());