You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

5844 lines
143 KiB

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