select2.js 89 KB

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