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.

5885 lines
144 KiB

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