select2.amd.js 74 KB

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