select2.amd.js 74 KB

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