1/*! 2 * Select2 4.0.8 3 * https://select2.github.io 4 * 5 * Released under the MIT license 6 * https://github.com/select2/select2/blob/master/LICENSE.md 7 */ 8;
vendor: 18,996 bytes, lines 8-577
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 } 44var S2;(function () { if (!S2 || !S2.requirejs) { 45if (!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 54var requirejs, require, define; 55(function (undef) { 56 var main, req, makeMap, handlers, 57 defined = {}, 58 waiting = {}, 59 config = {}, 60 defining = {}, 61 hasOwn = Object.prototype.hasOwnProperty, 62 aps = [].slice, 63 jsSuffixRegExp = /\.js$/; 64 65 function hasProp(obj, prop) { 66 return hasOwn.call(obj, prop); 67 } 68 69 /** 70 * Given a relative module name, like ./something, normalize it to 71 * a real name that can be mapped to a path. 72 * @param {String} name the relative name 73 * @param {String} baseName a real name that the name arg is relative 74 * to. 75 * @returns {String} normalized name 76 */ 77 function normalize(name, baseName) { 78 var nameParts, nameSegment, mapValue, foundMap, lastIndex, 79 foundI, foundStarMap, starI, i, j, part, normalizedBaseParts, 80 baseParts = baseName && baseName.split("/"), 81 map = config.map, 82 starMap = (map && map['*']) || {}; 83 84 //Adjust any relative paths. 85 if (name) { 86 name = name.split('/'); 87 lastIndex = name.length - 1; 88 89 // If wanting node ID compatibility, strip .js from end 90 // of IDs. Have to do this here, and not in nameToUrl 91 // because node allows either .js or non .js to map 92 // to same file. 93 if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) { 94 name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, ''); 95 } 96 97 // Starts with a '.' so need the baseName 98 if (name[0].charAt(0) === '.' && baseParts) { 99 //Convert baseName to array, and lop off the last part, 100 //so that . matches that 'directory' and not name of the baseName's 101 //module. For instance, baseName of 'one/two/three', maps to 102 //'one/two/three.js', but we want the directory, 'one/two' for 103 //this normalization. 104 normalizedBaseParts = baseParts.slice(0, baseParts.length - 1); 105 name = normalizedBaseParts.concat(name); 106 } 107 108 //start trimDots 109 for (i = 0; i < name.length; i++) { 110 part = name[i]; 111 if (part === '.') { 112 name.splice(i, 1); 113 i -= 1; 114 } else if (part === '..') { 115 // If at the start, or previous value is still .., 116 // keep them so that when converted to a path it may 117 // still work when converted to a path, even though 118 // as an ID it is less than ideal. In larger point 119 // releases, may be better to just kick out an error. 120 if (i === 0 || (i === 1 && name[2] === '..') || name[i - 1] === '..') { 121 continue; 122 } else if (i > 0) { 123 name.splice(i - 1, 2); 124 i -= 2; 125 } 126 } 127 } 128 //end trimDots 129 130 name = name.join('/'); 131 } 132 133 //Apply map config if available. 134 if ((baseParts || starMap) && map) { 135 nameParts = name.split('/'); 136 137 for (i = nameParts.length; i > 0; i -= 1) { 138 nameSegment = nameParts.slice(0, i).join("/"); 139 140 if (baseParts) { 141 //Find the longest baseName segment match in the config. 142 //So, do joins on the biggest to smallest lengths of baseParts. 143 for (j = baseParts.length; j > 0; j -= 1) { 144 mapValue = map[baseParts.slice(0, j).join('/')]; 145 146 //baseName segment has config, find if it has one for 147 //this name. 148 if (mapValue) { 149 mapValue = mapValue[nameSegment]; 150 if (mapValue) { 151 //Match, update name to the new value. 152 foundMap = mapValue; 153 foundI = i; 154 break; 155 } 156 } 157 } 158 } 159 160 if (foundMap) { 161 break; 162 } 163 164 //Check for a star map match, but just hold on to it, 165 //if there is a shorter segment match later in a matching 166 //config, then favor over this star map. 167 if (!foundStarMap && starMap && starMap[nameSegment]) { 168 foundStarMap = starMap[nameSegment]; 169 starI = i; 170 } 171 } 172 173 if (!foundMap && foundStarMap) { 174 foundMap = foundStarMap; 175 foundI = starI; 176 } 177 178 if (foundMap) { 179 nameParts.splice(0, foundI, foundMap); 180 name = nameParts.join('/'); 181 } 182 } 183 184 return name; 185 } 186 187 function makeRequire(relName, forceSync) { 188 return function () { 189 //A version of a require function that passes a moduleName 190 //value for items that may need to 191 //look up paths relative to the moduleName 192 var args = aps.call(arguments, 0); 193 194 //If first arg is not require('string'), and there is only 195 //one arg, it is the array form without a callback. Insert 196 //a null so that the following concat is correct. 197 if (typeof args[0] !== 'string' && args.length === 1) { 198 args.push(null); 199 } 200 return req.apply(undef, args.concat([relName, forceSync])); 201 }; 202 } 203 204 function makeNormalize(relName) { 205 return function (name) { 206 return normalize(name, relName); 207 }; 208 } 209 210 function makeLoad(depName) { 211 return function (value) { 212 defined[depName] = value; 213 }; 214 } 215 216 function callDep(name) { 217 if (hasProp(waiting, name)) { 218 var args = waiting[name]; 219 delete waiting[name]; 220 defining[name] = true; 221 main.apply(undef, args); 222 } 223 224 if (!hasProp(defined, name) && !hasProp(defining, name)) { 225 throw new Error('No ' + name); 226 } 227 return defined[name]; 228 } 229 230 //Turns a plugin!resource to [plugin, resource] 231 //with the plugin being undefined if the name 232 //did not have a plugin prefix. 233 function splitPrefix(name) { 234 var prefix, 235 index = name ? name.indexOf('!') : -1; 236 if (index > -1) { 237 prefix = name.substring(0, index); 238 name = name.substring(index + 1, name.length); 239 } 240 return [prefix, name]; 241 } 242 243 //Creates a parts array for a relName where first part is plugin ID, 244 //second part is resource ID. Assumes relName has already been normalized. 245 function makeRelParts(relName) { 246 return relName ? splitPrefix(relName) : []; 247 } 248 249 /** 250 * Makes a name map, normalizing the name, and using a plugin 251 * for normalization if necessary. Grabs a ref to plugin 252 * too, as an optimization. 253 */ 254 makeMap = function (name, relParts) { 255 var plugin, 256 parts = splitPrefix(name), 257 prefix = parts[0], 258 relResourceName = relParts[1]; 259 260 name = parts[1]; 261 262 if (prefix) { 263 prefix = normalize(prefix, relResourceName); 264 plugin = callDep(prefix); 265 } 266 267 //Normalize according 268 if (prefix) { 269 if (plugin && plugin.normalize) { 270 name = plugin.normalize(name, makeNormalize(relResourceName)); 271 } else { 272 name = normalize(name, relResourceName); 273 } 274 } else { 275 name = normalize(name, relResourceName); 276 parts = splitPrefix(name); 277 prefix = parts[0]; 278 name = parts[1]; 279 if (prefix) { 280 plugin = callDep(prefix); 281 } 282 } 283 284 //Using ridiculous property names for space reasons 285 return { 286 f: prefix ? prefix + '!' + name : name, //fullName 287 n: name, 288 pr: prefix, 289 p: plugin 290 }; 291 }; 292 293 function makeConfig(name) { 294 return function () { 295 return (config && config.config && config.config[name]) || {}; 296 }; 297 } 298 299 handlers = { 300 require: function (name) { 301 return makeRequire(name); 302 }, 303 exports: function (name) { 304 var e = defined[name]; 305 if (typeof e !== 'undefined') { 306 return e; 307 } else { 308 return (defined[name] = {}); 309 } 310 }, 311 module: function (name) { 312 return { 313 id: name, 314 uri: '', 315 exports: defined[name], 316 config: makeConfig(name) 317 }; 318 } 319 }; 320 321 main = function (name, deps, callback, relName) { 322 var cjsModule, depName, ret, map, i, relParts, 323 args = [], 324 callbackType = typeof callback, 325 usingExports; 326 327 //Use name if no relName 328 relName = relName || name; 329 relParts = makeRelParts(relName); 330 331 //Call the callback to define the module, if necessary. 332 if (callbackType === 'undefined' || callbackType === 'function') { 333 //Pull out the defined dependencies and pass the ordered 334 //values to the callback. 335 //Default to [require, exports, module] if no deps 336 deps = !deps.length && callback.length ? ['require', 'exports', 'module'] : deps; 337 for (i = 0; i < deps.length; i += 1) { 338 map = makeMap(deps[i], relParts); 339 depName = map.f; 340 341 //Fast path CommonJS standard dependencies. 342 if (depName === "require") { 343 args[i] = handlers.require(name); 344 } else if (depName === "exports") { 345 //CommonJS module spec 1.1 346 args[i] = handlers.exports(name); 347 usingExports = true; 348 } else if (depName === "module") { 349 //CommonJS module spec 1.1 350 cjsModule = args[i] = handlers.module(name); 351 } else if (hasProp(defined, depName) || 352 hasProp(waiting, depName) || 353 hasProp(defining, depName)) { 354 args[i] = callDep(depName); 355 } else if (map.p) { 356 map.p.load(map.n, makeRequire(relName, true), makeLoad(depName), {}); 357 args[i] = defined[depName]; 358 } else { 359 throw new Error(name + ' missing ' + depName); 360 } 361 } 362 363 ret = callback ? callback.apply(defined[name], args) : undefined; 364 365 if (name) { 366 //If setting exports via "module" is in play, 367 //favor that over return value and exports. After that, 368 //favor a non-undefined return value over exports use. 369 if (cjsModule && cjsModule.exports !== undef && 370 cjsModule.exports !== defined[name]) { 371 defined[name] = cjsModule.exports; 372 } else if (ret !== undef || !usingExports) { 373 //Use the return value from the function. 374 defined[name] = ret; 375 } 376 } 377 } else if (name) { 378 //May just be an object definition for the module. Only 379 //worry about defining if have a module name. 380 defined[name] = callback; 381 } 382 }; 383 384 requirejs = require = req = function (deps, callback, relName, forceSync, alt) { 385 if (typeof deps === "string") { 386 if (handlers[deps]) { 387 //callback in this case is really relName 388 return handlers[deps](callback); 389 } 390 //Just return the module wanted. In this scenario, the 391 //deps arg is the module name, and second arg (if passed) 392 //is just the relName. 393 //Normalize module name, if it contains . or .. 394 return callDep(makeMap(deps, makeRelParts(callback)).f); 395 } else if (!deps.splice) { 396 //deps is a config object, not an array. 397 config = deps; 398 if (config.deps) { 399 req(config.deps, config.callback); 400 } 401 if (!callback) { 402 return; 403 } 404 405 if (callback.splice) { 406 //callback is an array, which means it is a dependency list. 407 //Adjust args if there are dependencies 408 deps = callback; 409 callback = relName; 410 relName = null; 411 } else { 412 deps = undef; 413 } 414 } 415 416 //Support require(['a']) 417 callback = callback || function () {}; 418 419 //If relName is a function, it is an errback handler, 420 //so remove it. 421 if (typeof relName === 'function') { 422 relName = forceSync; 423 forceSync = alt; 424 } 425 426 //Simulate async callback; 427 if (forceSync) { 428 main(undef, deps, callback, relName); 429 } else { 430 //Using a non-zero value because of concern for what old browsers 431 //do, and latest browsers "upgrade" to 4 if lower value is used: 432 //http://www.whatwg.org/specs/web-apps/current-work/multipage/timers.html#dom-windowtimers-settimeout: 433 //If want a value immediately, use require('id') instead -- something 434 //that works in almond on the global level, but not guaranteed and 435 //unlikely to work in other AMD implementations. 436 setTimeout(function () { 437 main(undef, deps, callback, relName); 438 }, 4); 439 } 440 441 return req; 442 }; 443 444 /** 445 * Just drops the config on the floor, but returns req in case 446 * the config return value is used. 447 */ 448 req.config = function (cfg) { 449 return req(cfg); 450 }; 451 452 /** 453 * Expose module registry for debugging and tooling 454 */ 455 requirejs._defined = defined; 456 457 define = function (name, deps, callback) { 458 if (typeof name !== 'string') { 459 throw new Error('See almond README: incorrect module build, no module name'); 460 } 461 462 //This module may not have dependencies 463 if (!deps.splice) { 464 //deps is not an array, so probably means 465 //an object literal or factory function for 466 //the value. Adjust args. 467 callback = deps; 468 deps = []; 469 } 470 471 if (!hasProp(defined, name) && !hasProp(waiting, name)) { 472 waiting[name] = [name, deps, callback]; 473 } 474 }; 475 476 define.amd = { 477 jQuery: true 478 }; 479}()); 480 481S2.requirejs = requirejs;S2.require = require;S2.define = define; 482} 483}()); 484S2.define("almond", function(){}); 485 486/* global jQuery:false, $:false */ 487S2.define('jquery',[],function () { 488 var _$ = jQuery || $; 489 490 if (_$ == null && console && console.error) { 491 console.error( 492 'Select2: An instance of jQuery or a jQuery-compatible library was not ' + 493 'found. Make sure that you are including jQuery before Select2 on your ' + 494 'web page.' 495 ); 496 } 497 498 return _$; 499}); 500 501S2.define('select2/utils',[ 502 'jquery' 503], function ($) { 504 var Utils = {}; 505 506 Utils.Extend = function (ChildClass, SuperClass) { 507 var __hasProp = {}.hasOwnProperty; 508 509 function BaseConstructor () { 510 this.constructor = ChildClass; 511 } 512 513 for (var key in SuperClass) { 514 if (__hasProp.call(SuperClass, key)) { 515 ChildClass[key] = SuperClass[key]; 516 } 517 } 518 519 BaseConstructor.prototype = SuperClass.prototype; 520 ChildClass.prototype = new BaseConstructor(); 521 ChildClass.__super__ = SuperClass.prototype; 522 523 return ChildClass; 524 }; 525 526 function getMethods (theClass) { 527 var proto = theClass.prototype; 528 529 var methods = []; 530 531 for (var methodName in proto) { 532 var m = proto[methodName]; 533 534 if (typeof m !== 'function') { 535 continue; 536 } 537 538 if (methodName === 'constructor') { 539 continue; 540 } 541 542 methods.push(methodName); 543 } 544 545 return methods; 546 } 547 548 Utils.Decorate = function (SuperClass, DecoratorClass) { 549 var decoratedMethods = getMethods(DecoratorClass); 550 var superMethods = getMethods(SuperClass); 551 552 function DecoratedClass () { 553 var unshift = Array.prototype.unshift; 554 555 var argCount = DecoratorClass.prototype.constructor.length; 556 557 var calledConstructor = SuperClass.prototype.constructor; 558 559 if (argCount > 0) { 560 unshift.call(arguments, SuperClass.prototype.constructor); 561 562 calledConstructor = DecoratorClass.prototype.constructor; 563 } 564 565 calledConstructor.apply(this, arguments); 566 } 567 568 DecoratorClass.displayName = SuperClass.displayName; 569 570 function ctr () { 571 this.constructor = DecoratedClass; 572 } 573 574 DecoratedClass.prototype = new ctr(); 575 576 for (var m = 0; m < superMethods.length; m++) { 577
vendor: 3,385 bytes, lines 577-714
577var superMethod = superMethods[m]; 578 579 DecoratedClass.prototype[superMethod] = 580 SuperClass.prototype[superMethod]; 581 } 582 583 var calledMethod = function (methodName) { 584 // Stub out the original method if it's not decorating an actual method 585 var originalMethod = function () {}; 586 587 if (methodName in DecoratedClass.prototype) { 588 originalMethod = DecoratedClass.prototype[methodName]; 589 } 590 591 var decoratedMethod = DecoratorClass.prototype[methodName]; 592 593 return function () { 594 var unshift = Array.prototype.unshift; 595 596 unshift.call(arguments, originalMethod); 597 598 return decoratedMethod.apply(this, arguments); 599 }; 600 }; 601 602 for (var d = 0; d < decoratedMethods.length; d++) { 603 var decoratedMethod = decoratedMethods[d]; 604 605 DecoratedClass.prototype[decoratedMethod] = calledMethod(decoratedMethod); 606 } 607 608 return DecoratedClass; 609 }; 610 611 var Observable = function () { 612 this.listeners = {}; 613 }; 614 615 Observable.prototype.on = function (event, callback) { 616 this.listeners = this.listeners || {}; 617 618 if (event in this.listeners) { 619 this.listeners[event].push(callback); 620 } else { 621 this.listeners[event] = [callback]; 622 } 623 }; 624 625 Observable.prototype.trigger = function (event) { 626 var slice = Array.prototype.slice; 627 var params = slice.call(arguments, 1); 628 629 this.listeners = this.listeners || {}; 630 631 // Params should always come in as an array 632 if (params == null) { 633 params = []; 634 } 635 636 // If there are no arguments to the event, use a temporary object 637 if (params.length === 0) { 638 params.push({}); 639 } 640 641 // Set the `_type` of the first object to the event 642 params[0]._type = event; 643 644 if (event in this.listeners) { 645 this.invoke(this.listeners[event], slice.call(arguments, 1)); 646 } 647 648 if ('*' in this.listeners) { 649 this.invoke(this.listeners['*'], arguments); 650 } 651 }; 652 653 Observable.prototype.invoke = function (listeners, params) { 654 for (var i = 0, len = listeners.length; i < len; i++) { 655 listeners[i].apply(this, params); 656 } 657 }; 658 659 Utils.Observable = Observable; 660 661 Utils.generateChars = function (length) { 662 var chars = ''; 663 664 for (var i = 0; i < length; i++) { 665 var randomChar = Math.floor(Math.random() * 36); 666 chars += randomChar.toString(36); 667 } 668 669 return chars; 670 }; 671 672 Utils.bind = function (func, context) { 673 return function () { 674 func.apply(context, arguments); 675 }; 676 }; 677 678 Utils._convertData = function (data) { 679 for (var originalKey in data) { 680 var keys = originalKey.split('-'); 681 682 var dataLevel = data; 683 684 if (keys.length === 1) { 685 continue; 686 } 687 688 for (var k = 0; k < keys.length; k++) { 689 var key = keys[k]; 690 691 // Lowercase the first letter 692 // By default, dash-separated becomes camelCase 693 key = key.substring(0, 1).toLowerCase() + key.substring(1); 694 695 if (!(key in dataLevel)) { 696 dataLevel[key] = {}; 697 } 698 699 if (k == keys.length - 1) { 700 dataLevel[key] = data[originalKey]; 701 } 702 703 dataLevel = dataLevel[key]; 704 } 705 706 delete data[originalKey]; 707 } 708 709 return data; 710 }; 711 712 Utils.hasScroll = function (index, el) { 713 // Adapted from the function created by @ShadowScripter 714 // and adapted by @BillBarry on the Stack Exchange Code Review website.
715 // The original code can be found at 716 // http://codereview.stackexchange.com/q/13338 717 // and was designed to be used with the Sizzle selector engine. 718 719 var $el = $(el); 720 var overflowX = el.style.overflowX; 721 var overflowY = el.style.overflowY; 722 723 //Check both x and y declarations 724 if (overflowX === overflowY && 725 (overflowY === 'hidden' || overflowY === 'visible')) { 726 return false; 727 } 728 729 if (overflowX === 'scroll' || overflowY === 'scroll') { 730 return true; 731 } 732 733 return ($el.innerHeight() < el.scrollHeight || 734 $el.innerWidth() < el.scrollWidth); 735 }; 736 737 Utils.escapeMarkup = function (markup) { 738 var replaceMap = { 739 '\\': '\', 740 '&': '&', 741 '<': '<', 742 '>': '>', 743 '"': '"', 744 '\'': ''', 745 '/': '/' 746 }; 747 748 // Do not try to escape the markup if it's not a string 749 if (typeof markup !== 'string') { 750 return markup; 751 } 752 753 return String(markup).replace(/[&<>"'\/\\]/g, function (match) { 754 return replaceMap[match]; 755 }); 756 }; 757 758 // Append an array of jQuery nodes to a given element. 759 Utils.appendMany = function ($element, $nodes) { 760 // jQuery 1.7.x does not support $.fn.append() with an array 761 // Fall back to a jQuery object collection using $.fn.add() 762 if ($.fn.jquery.substr(0, 3) === '1.7') { 763 var $jqNodes = $(); 764 765 $.map($nodes, function (node) { 766 $jqNodes = $jqNodes.add(node); 767 }); 768 769 $nodes = $jqNodes; 770 } 771 772 $element.append($nodes); 773 }; 774 775 // Cache objects in Utils.__cache instead of $.data (see #4346) 776 Utils.__cache = {}; 777 778 var id = 0; 779 Utils.GetUniqueElementId = function (element) { 780 // Get a unique element Id. If element has no id, 781 // creates a new unique number, stores it in the id 782 // attribute and returns the new id. 783 // If an id already exists, it simply returns it. 784 785 var select2Id = element.getAttribute('data-select2-id'); 786 if (select2Id == null) { 787 // If element has id, use it. 788 if (element.id) { 789 select2Id = element.id; 790 element.setAttribute('data-select2-id', select2Id); 791 } else { 792 element.setAttribute('data-select2-id', ++id); 793 select2Id = id.toString(); 794 } 795 } 796 return select2Id; 797 }; 798 799 Utils.StoreData = function (element, name, value) { 800 // Stores an item in the cache for a specified element. 801 // name is the cache key. 802 var id = Utils.GetUniqueElementId(element); 803 if (!Utils.__cache[id]) { 804 Utils.__cache[id] = {}; 805 } 806 807 Utils.__cache[id][name] = value; 808 }; 809 810 Utils.GetData = function (element, name) { 811 // Retrieves a value from the cache by its key (name) 812 // name is optional. If no name specified, return 813 // all cache items for the specified element. 814 // and for a specified element. 815 var id = Utils.GetUniqueElementId(element); 816 if (name) { 817 if (Utils.__cache[id]) { 818 if (Utils.__cache[id][name] != null) { 819 return Utils.__cache[id][name]; 820 } 821 return $(element).data(name); // Fallback to HTML5 data attribs. 822 } 823 return $(element).data(name); // Fallback to HTML5 data attribs. 824 } else { 825 return Utils.__cache[id]; 826 } 827 }; 828 829 Utils.RemoveData = function (element) { 830 // Removes all cached items for a specified element. 831 var id = Utils.GetUniqueElementId(element); 832 if (Utils.__cache[id] != null) { 833 delete Utils.__cache[id]; 834 } 835 }; 836 837 return Utils; 838}); 839 840S2.define('select2/results',[ 841 'jquery', 842 './utils' 843], function ($, Utils) { 844 function Results ($element, options, dataAdapter) { 845 this.$element = $element; 846 this.data = dataAdapter; 847 this.options = options; 848 849 Results.__super__.constructor.call(this); 850 } 851 852 Utils.Extend(Results, Utils.Observable); 853 854 Results.prototype.render = function () { 855 var $results = $( 856 '<ul class="select2-results__options" role="tree"></ul>' 857 ); 858 859 if (this.options.get('multiple')) { 860 $results.attr('aria-multiselectable', 'true'); 861 } 862 863 this.$results = $results; 864 865 return $results; 866 }; 867 868 Results.prototype.clear = function () { 869 this.$results.empty(); 870 }; 871 872 Results.prototype.displayMessage = function (params) { 873 var escapeMarkup = this.options.get('escapeMarkup'); 874 875 this.clear(); 876 this.hideLoading(); 877 878 var $message = $( 879 '<li role="treeitem" aria-live="assertive"' + 880 ' class="select2-results__option"></li>' 881 ); 882 883 var message = this.options.get('translations').get(params.message); 884 885 $message.append( 886 escapeMarkup( 887 message(params.args) 888 ) 889 ); 890 891 $message[0].className += ' select2-results__message';
vendor: 84,282 bytes, lines 892-4493
892 893 this.$results.append($message); 894 }; 895 896 Results.prototype.hideMessages = function () { 897 this.$results.find('.select2-results__message').remove(); 898 }; 899 900 Results.prototype.append = function (data) { 901 this.hideLoading(); 902 903 var $options = []; 904 905 if (data.results == null || data.results.length === 0) { 906 if (this.$results.children().length === 0) { 907 this.trigger('results:message', { 908 message: 'noResults' 909 }); 910 } 911 912 return; 913 } 914 915 data.results = this.sort(data.results); 916 917 for (var d = 0; d < data.results.length; d++) { 918 var item = data.results[d]; 919 920 var $option = this.option(item); 921 922 $options.push($option); 923 } 924 925 this.$results.append($options); 926 }; 927 928 Results.prototype.position = function ($results, $dropdown) { 929 var $resultsContainer = $dropdown.find('.select2-results'); 930 $resultsContainer.append($results); 931 }; 932 933 Results.prototype.sort = function (data) { 934 var sorter = this.options.get('sorter'); 935 936 return sorter(data); 937 }; 938 939 Results.prototype.highlightFirstItem = function () { 940 var $options = this.$results 941 .find('.select2-results__option[aria-selected]'); 942 943 var $selected = $options.filter('[aria-selected=true]'); 944 945 // Check if there are any selected options 946 if ($selected.length > 0) { 947 // If there are selected options, highlight the first 948 $selected.first().trigger('mouseenter'); 949 } else { 950 // If there are no selected options, highlight the first option 951 // in the dropdown 952 $options.first().trigger('mouseenter'); 953 } 954 955 this.ensureHighlightVisible(); 956 }; 957 958 Results.prototype.setClasses = function () { 959 var self = this; 960 961 this.data.current(function (selected) { 962 var selectedIds = $.map(selected, function (s) { 963 return s.id.toString(); 964 }); 965 966 var $options = self.$results 967 .find('.select2-results__option[aria-selected]'); 968 969 $options.each(function () { 970 var $option = $(this); 971 972 var item = Utils.GetData(this, 'data'); 973 974 // id needs to be converted to a string when comparing 975 var id = '' + item.id; 976 977 if ((item.element != null && item.element.selected) || 978 (item.element == null && $.inArray(id, selectedIds) > -1)) { 979 $option.attr('aria-selected', 'true'); 980 } else { 981 $option.attr('aria-selected', 'false'); 982 } 983 }); 984 985 }); 986 }; 987 988 Results.prototype.showLoading = function (params) { 989 this.hideLoading(); 990 991 var loadingMore = this.options.get('translations').get('searching'); 992 993 var loading = { 994 disabled: true, 995 loading: true, 996 text: loadingMore(params) 997 }; 998 var $loading = this.option(loading); 999 $loading.className += ' loading-results'; 1000 1001 this.$results.prepend($loading); 1002 }; 1003 1004 Results.prototype.hideLoading = function () { 1005 this.$results.find('.loading-results').remove(); 1006 }; 1007 1008 Results.prototype.option = function (data) { 1009 var option = document.createElement('li'); 1010 option.className = 'select2-results__option'; 1011 1012 var attrs = { 1013 'role': 'treeitem', 1014 'aria-selected': 'false' 1015 }; 1016 1017 var matches = window.Element.prototype.matches || 1018 window.Element.prototype.msMatchesSelector || 1019 window.Element.prototype.webkitMatchesSelector; 1020 1021 if ((data.element != null && matches.call(data.element, ':disabled')) || 1022 (data.element == null && data.disabled)) { 1023 delete attrs['aria-selected']; 1024 attrs['aria-disabled'] = 'true'; 1025 } 1026 1027 if (data.id == null) { 1028 delete attrs['aria-selected']; 1029 } 1030 1031 if (data._resultId != null) { 1032 option.id = data._resultId; 1033 } 1034 1035 if (data.title) { 1036 option.title = data.title; 1037 } 1038 1039 if (data.children) { 1040 attrs.role = 'group'; 1041 attrs['aria-label'] = data.text; 1042 delete attrs['aria-selected']; 1043 } 1044 1045 for (var attr in attrs) { 1046 var val = attrs[attr]; 1047 1048 option.setAttribute(attr, val); 1049 } 1050 1051 if (data.children) { 1052 var $option = $(option); 1053 1054 var label = document.createElement('strong'); 1055 label.className = 'select2-results__group'; 1056 1057 var $label = $(label); 1058 this.template(data, label); 1059 1060 var $children = []; 1061 1062 for (var c = 0; c < data.children.length; c++) { 1063 var child = data.children[c]; 1064 1065 var $child = this.option(child); 1066 1067 $children.push($child); 1068 } 1069 1070 var $childrenContainer = $('<ul></ul>', { 1071 'class': 'select2-results__options select2-results__options--nested' 1072 }); 1073 1074 $childrenContainer.append($children); 1075 1076 $option.append(label); 1077 $option.append($childrenContainer); 1078 } else { 1079 this.template(data, option); 1080 } 1081 1082 Utils.StoreData(option, 'data', data); 1083 1084 return option; 1085 }; 1086 1087 Results.prototype.bind = function (container, $container) { 1088 var self = this; 1089 1090 var id = container.id + '-results'; 1091 1092 this.$results.attr('id', id); 1093 1094 container.on('results:all', function (params) { 1095 self.clear(); 1096 self.append(params.data); 1097 1098 if (container.isOpen()) { 1099 self.setClasses(); 1100 self.highlightFirstItem(); 1101 } 1102 }); 1103 1104 container.on('results:append', function (params) { 1105 self.append(params.data); 1106 1107 if (container.isOpen()) { 1108 self.setClasses(); 1109 } 1110 }); 1111 1112 container.on('query', function (params) { 1113 self.hideMessages(); 1114 self.showLoading(params); 1115 }); 1116 1117 container.on('select', function () { 1118 if (!container.isOpen()) { 1119 return; 1120 } 1121 1122 self.setClasses(); 1123 1124 if (self.options.get('scrollAfterSelect')) { 1125 self.highlightFirstItem(); 1126 } 1127 }); 1128 1129 container.on('unselect', function () { 1130 if (!container.isOpen()) { 1131 return; 1132 } 1133 1134 self.setClasses(); 1135 1136 if (self.options.get('scrollAfterSelect')) { 1137 self.highlightFirstItem(); 1138 } 1139 }); 1140 1141 container.on('open', function () { 1142 // When the dropdown is open, aria-expended="true" 1143 self.$results.attr('aria-expanded', 'true'); 1144 self.$results.attr('aria-hidden', 'false'); 1145 1146 self.setClasses(); 1147 self.ensureHighlightVisible(); 1148 }); 1149 1150 container.on('close', function () { 1151 // When the dropdown is closed, aria-expended="false" 1152 self.$results.attr('aria-expanded', 'false'); 1153 self.$results.attr('aria-hidden', 'true'); 1154 self.$results.removeAttr('aria-activedescendant'); 1155 }); 1156 1157 container.on('results:toggle', function () { 1158 var $highlighted = self.getHighlightedResults(); 1159 1160 if ($highlighted.length === 0) { 1161 return; 1162 } 1163 1164 $highlighted.trigger('mouseup'); 1165 }); 1166 1167 container.on('results:select', function () { 1168 var $highlighted = self.getHighlightedResults(); 1169 1170 if ($highlighted.length === 0) { 1171 return; 1172 } 1173 1174 var data = Utils.GetData($highlighted[0], 'data'); 1175 1176 if ($highlighted.attr('aria-selected') == 'true') { 1177 self.trigger('close', {}); 1178 } else { 1179 self.trigger('select', { 1180 data: data 1181 }); 1182 } 1183 }); 1184 1185 container.on('results:previous', function () { 1186 var $highlighted = self.getHighlightedResults(); 1187 1188 var $options = self.$results.find('[aria-selected]'); 1189 1190 var currentIndex = $options.index($highlighted); 1191 1192 // If we are already at the top, don't move further 1193 // If no options, currentIndex will be -1 1194 if (currentIndex <= 0) { 1195 return; 1196 } 1197 1198 var nextIndex = currentIndex - 1; 1199 1200 // If none are highlighted, highlight the first 1201 if ($highlighted.length === 0) { 1202 nextIndex = 0; 1203 } 1204 1205 var $next = $options.eq(nextIndex); 1206 1207 $next.trigger('mouseenter'); 1208 1209 var currentOffset = self.$results.offset().top; 1210 var nextTop = $next.offset().top; 1211 var nextOffset = self.$results.scrollTop() + (nextTop - currentOffset); 1212 1213 if (nextIndex === 0) { 1214 self.$results.scrollTop(0); 1215 } else if (nextTop - currentOffset < 0) { 1216 self.$results.scrollTop(nextOffset); 1217 } 1218 }); 1219 1220 container.on('results:next', function () { 1221 var $highlighted = self.getHighlightedResults(); 1222 1223 var $options = self.$results.find('[aria-selected]'); 1224 1225 var currentIndex = $options.index($highlighted); 1226 1227 var nextIndex = currentIndex + 1; 1228 1229 // If we are at the last option, stay there 1230 if (nextIndex >= $options.length) { 1231 return; 1232 } 1233 1234 var $next = $options.eq(nextIndex); 1235 1236 $next.trigger('mouseenter'); 1237 1238 var currentOffset = self.$results.offset().top + 1239 self.$results.outerHeight(false); 1240 var nextBottom = $next.offset().top + $next.outerHeight(false); 1241 var nextOffset = self.$results.scrollTop() + nextBottom - currentOffset; 1242 1243 if (nextIndex === 0) { 1244 self.$results.scrollTop(0); 1245 } else if (nextBottom > currentOffset) { 1246 self.$results.scrollTop(nextOffset); 1247 } 1248 }); 1249 1250 container.on('results:focus', function (params) { 1251 params.element.addClass('select2-results__option--highlighted'); 1252 }); 1253 1254 container.on('results:message', function (params) { 1255 self.displayMessage(params); 1256 }); 1257 1258 if ($.fn.mousewheel) { 1259 this.$results.on('mousewheel', function (e) { 1260 var top = self.$results.scrollTop(); 1261 1262 var bottom = self.$results.get(0).scrollHeight - top + e.deltaY; 1263 1264 var isAtTop = e.deltaY > 0 && top - e.deltaY <= 0; 1265 var isAtBottom = e.deltaY < 0 && bottom <= self.$results.height(); 1266 1267 if (isAtTop) { 1268 self.$results.scrollTop(0); 1269 1270 e.preventDefault(); 1271 e.stopPropagation(); 1272 } else if (isAtBottom) { 1273 self.$results.scrollTop( 1274 self.$results.get(0).scrollHeight - self.$results.height() 1275 ); 1276 1277 e.preventDefault(); 1278 e.stopPropagation(); 1279 } 1280 }); 1281 } 1282 1283 this.$results.on('mouseup', '.select2-results__option[aria-selected]', 1284 function (evt) { 1285 var $this = $(this); 1286 1287 var data = Utils.GetData(this, 'data'); 1288 1289 if ($this.attr('aria-selected') === 'true') { 1290 if (self.options.get('multiple')) { 1291 self.trigger('unselect', { 1292 originalEvent: evt, 1293 data: data 1294 }); 1295 } else { 1296 self.trigger('close', {}); 1297 } 1298 1299 return; 1300 } 1301 1302 self.trigger('select', { 1303 originalEvent: evt, 1304 data: data 1305 }); 1306 }); 1307 1308 this.$results.on('mouseenter', '.select2-results__option[aria-selected]', 1309 function (evt) { 1310 var data = Utils.GetData(this, 'data'); 1311 1312 self.getHighlightedResults() 1313 .removeClass('select2-results__option--highlighted'); 1314 1315 self.trigger('results:focus', { 1316 data: data, 1317 element: $(this) 1318 }); 1319 }); 1320 }; 1321 1322 Results.prototype.getHighlightedResults = function () { 1323 var $highlighted = this.$results 1324 .find('.select2-results__option--highlighted'); 1325 1326 return $highlighted; 1327 }; 1328 1329 Results.prototype.destroy = function () { 1330 this.$results.remove(); 1331 }; 1332 1333 Results.prototype.ensureHighlightVisible = function () { 1334 var $highlighted = this.getHighlightedResults(); 1335 1336 if ($highlighted.length === 0) { 1337 return; 1338 } 1339 1340 var $options = this.$results.find('[aria-selected]'); 1341 1342 var currentIndex = $options.index($highlighted); 1343 1344 var currentOffset = this.$results.offset().top; 1345 var nextTop = $highlighted.offset().top; 1346 var nextOffset = this.$results.scrollTop() + (nextTop - currentOffset); 1347 1348 var offsetDelta = nextTop - currentOffset; 1349 nextOffset -= $highlighted.outerHeight(false) * 2; 1350 1351 if (currentIndex <= 2) { 1352 this.$results.scrollTop(0); 1353 } else if (offsetDelta > this.$results.outerHeight() || offsetDelta < 0) { 1354 this.$results.scrollTop(nextOffset); 1355 } 1356 }; 1357 1358 Results.prototype.template = function (result, container) { 1359 var template = this.options.get('templateResult'); 1360 var escapeMarkup = this.options.get('escapeMarkup'); 1361 1362 var content = template(result, container); 1363 1364 if (content == null) { 1365 container.style.display = 'none'; 1366 } else if (typeof content === 'string') { 1367 container.innerHTML = escapeMarkup(content); 1368 } else { 1369 $(container).append(content); 1370 } 1371 }; 1372 1373 return Results; 1374}); 1375 1376S2.define('select2/keys',[ 1377 1378], function () { 1379 var KEYS = { 1380 BACKSPACE: 8, 1381 TAB: 9, 1382 ENTER: 13, 1383 SHIFT: 16, 1384 CTRL: 17, 1385 ALT: 18, 1386 ESC: 27, 1387 SPACE: 32, 1388 PAGE_UP: 33, 1389 PAGE_DOWN: 34, 1390 END: 35, 1391 HOME: 36, 1392 LEFT: 37, 1393 UP: 38, 1394 RIGHT: 39, 1395 DOWN: 40, 1396 DELETE: 46 1397 }; 1398 1399 return KEYS; 1400}); 1401 1402S2.define('select2/selection/base',[ 1403 'jquery', 1404 '../utils', 1405 '../keys' 1406], function ($, Utils, KEYS) { 1407 function BaseSelection ($element, options) { 1408 this.$element = $element; 1409 this.options = options; 1410 1411 BaseSelection.__super__.constructor.call(this); 1412 } 1413 1414 Utils.Extend(BaseSelection, Utils.Observable); 1415 1416 BaseSelection.prototype.render = function () { 1417 var $selection = $( 1418 '<span class="select2-selection" role="combobox" ' + 1419 ' aria-haspopup="true" aria-expanded="false">' + 1420 '</span>' 1421 ); 1422 1423 this._tabindex = 0; 1424 1425 if (Utils.GetData(this.$element[0], 'old-tabindex') != null) { 1426 this._tabindex = Utils.GetData(this.$element[0], 'old-tabindex'); 1427 } else if (this.$element.attr('tabindex') != null) { 1428 this._tabindex = this.$element.attr('tabindex'); 1429 } 1430 1431 $selection.attr('title', this.$element.attr('title')); 1432 $selection.attr('tabindex', this._tabindex); 1433 1434 this.$selection = $selection; 1435 1436 return $selection; 1437 }; 1438 1439 BaseSelection.prototype.bind = function (container, $container) { 1440 var self = this; 1441 1442 var id = container.id + '-container'; 1443 var resultsId = container.id + '-results'; 1444 1445 this.container = container; 1446 1447 this.$selection.on('focus', function (evt) { 1448 self.trigger('focus', evt); 1449 }); 1450 1451 this.$selection.on('blur', function (evt) { 1452 self._handleBlur(evt); 1453 }); 1454 1455 this.$selection.on('keydown', function (evt) { 1456 self.trigger('keypress', evt); 1457 1458 if (evt.which === KEYS.SPACE) { 1459 evt.preventDefault(); 1460 } 1461 }); 1462 1463 container.on('results:focus', function (params) { 1464 self.$selection.attr('aria-activedescendant', params.data._resultId); 1465 }); 1466 1467 container.on('selection:update', function (params) { 1468 self.update(params.data); 1469 }); 1470 1471 container.on('open', function () { 1472 // When the dropdown is open, aria-expanded="true" 1473 self.$selection.attr('aria-expanded', 'true'); 1474 self.$selection.attr('aria-owns', resultsId); 1475 1476 self._attachCloseHandler(container); 1477 }); 1478 1479 container.on('close', function () { 1480 // When the dropdown is closed, aria-expanded="false" 1481 self.$selection.attr('aria-expanded', 'false'); 1482 self.$selection.removeAttr('aria-activedescendant'); 1483 self.$selection.removeAttr('aria-owns'); 1484 1485 self.$selection.trigger('focus'); 1486 1487 self._detachCloseHandler(container); 1488 }); 1489 1490 container.on('enable', function () { 1491 self.$selection.attr('tabindex', self._tabindex); 1492 }); 1493 1494 container.on('disable', function () { 1495 self.$selection.attr('tabindex', '-1'); 1496 }); 1497 }; 1498 1499 BaseSelection.prototype._handleBlur = function (evt) { 1500 var self = this; 1501 1502 // This needs to be delayed as the active element is the body when the tab 1503 // key is pressed, possibly along with others. 1504 window.setTimeout(function () { 1505 // Don't trigger `blur` if the focus is still in the selection 1506 if ( 1507 (document.activeElement == self.$selection[0]) || 1508 ($.contains(self.$selection[0], document.activeElement)) 1509 ) { 1510 return; 1511 } 1512 1513 self.trigger('blur', evt); 1514 }, 1); 1515 }; 1516 1517 BaseSelection.prototype._attachCloseHandler = function (container) { 1518 var self = this; 1519 1520 $(document.body).on('mousedown.select2.' + container.id, function (e) { 1521 var $target = $(e.target); 1522 1523 var $select = $target.closest('.select2'); 1524 1525 var $all = $('.select2.select2-container--open'); 1526 1527 $all.each(function () { 1528 var $this = $(this); 1529 1530 if (this == $select[0]) { 1531 return; 1532 } 1533 1534 var $element = Utils.GetData(this, 'element'); 1535 1536 $element.select2('close'); 1537 }); 1538 }); 1539 }; 1540 1541 BaseSelection.prototype._detachCloseHandler = function (container) { 1542 $(document.body).off('mousedown.select2.' + container.id); 1543 }; 1544 1545 BaseSelection.prototype.position = function ($selection, $container) { 1546 var $selectionContainer = $container.find('.selection'); 1547 $selectionContainer.append($selection); 1548 }; 1549 1550 BaseSelection.prototype.destroy = function () { 1551 this._detachCloseHandler(this.container); 1552 }; 1553 1554 BaseSelection.prototype.update = function (data) { 1555 throw new Error('The `update` method must be defined in child classes.'); 1556 }; 1557 1558 return BaseSelection; 1559}); 1560 1561S2.define('select2/selection/single',[ 1562 'jquery', 1563 './base', 1564 '../utils', 1565 '../keys' 1566], function ($, BaseSelection, Utils, KEYS) { 1567 function SingleSelection () { 1568 SingleSelection.__super__.constructor.apply(this, arguments); 1569 } 1570 1571 Utils.Extend(SingleSelection, BaseSelection); 1572 1573 SingleSelection.prototype.render = function () { 1574 var $selection = SingleSelection.__super__.render.call(this); 1575 1576 $selection.addClass('select2-selection--single'); 1577 1578 $selection.html( 1579 '<span class="select2-selection__rendered"></span>' + 1580 '<span class="select2-selection__arrow" role="presentation">' + 1581 '<b role="presentation"></b>' + 1582 '</span>' 1583 ); 1584 1585 return $selection; 1586 }; 1587 1588 SingleSelection.prototype.bind = function (container, $container) { 1589 var self = this; 1590 1591 SingleSelection.__super__.bind.apply(this, arguments); 1592 1593 var id = container.id + '-container'; 1594 1595 this.$selection.find('.select2-selection__rendered') 1596 .attr('id', id) 1597 .attr('role', 'textbox') 1598 .attr('aria-readonly', 'true'); 1599 this.$selection.attr('aria-labelledby', id); 1600 1601 this.$selection.on('mousedown', function (evt) { 1602 // Only respond to left clicks 1603 if (evt.which !== 1) { 1604 return; 1605 } 1606 1607 self.trigger('toggle', { 1608 originalEvent: evt 1609 }); 1610 }); 1611 1612 this.$selection.on('focus', function (evt) { 1613 // User focuses on the container 1614 }); 1615 1616 this.$selection.on('blur', function (evt) { 1617 // User exits the container 1618 }); 1619 1620 container.on('focus', function (evt) { 1621 if (!container.isOpen()) { 1622 self.$selection.trigger('focus'); 1623 } 1624 }); 1625 }; 1626 1627 SingleSelection.prototype.clear = function () { 1628 var $rendered = this.$selection.find('.select2-selection__rendered'); 1629 $rendered.empty(); 1630 $rendered.removeAttr('title'); // clear tooltip on empty 1631 }; 1632 1633 SingleSelection.prototype.display = function (data, container) { 1634 var template = this.options.get('templateSelection'); 1635 var escapeMarkup = this.options.get('escapeMarkup'); 1636 1637 return escapeMarkup(template(data, container)); 1638 }; 1639 1640 SingleSelection.prototype.selectionContainer = function () { 1641 return $('<span></span>'); 1642 }; 1643 1644 SingleSelection.prototype.update = function (data) { 1645 if (data.length === 0) { 1646 this.clear(); 1647 return; 1648 } 1649 1650 var selection = data[0]; 1651 1652 var $rendered = this.$selection.find('.select2-selection__rendered'); 1653 var formatted = this.display(selection, $rendered); 1654 1655 $rendered.empty().append(formatted); 1656 $rendered.attr('title', selection.title || selection.text); 1657 }; 1658 1659 return SingleSelection; 1660}); 1661 1662S2.define('select2/selection/multiple',[ 1663 'jquery', 1664 './base', 1665 '../utils' 1666], function ($, BaseSelection, Utils) { 1667 function MultipleSelection ($element, options) { 1668 MultipleSelection.__super__.constructor.apply(this, arguments); 1669 } 1670 1671 Utils.Extend(MultipleSelection, BaseSelection); 1672 1673 MultipleSelection.prototype.render = function () { 1674 var $selection = MultipleSelection.__super__.render.call(this); 1675 1676 $selection.addClass('select2-selection--multiple'); 1677 1678 $selection.html( 1679 '<ul class="select2-selection__rendered"></ul>' 1680 ); 1681 1682 return $selection; 1683 }; 1684 1685 MultipleSelection.prototype.bind = function (container, $container) { 1686 var self = this; 1687 1688 MultipleSelection.__super__.bind.apply(this, arguments); 1689 1690 this.$selection.on('click', function (evt) { 1691 self.trigger('toggle', { 1692 originalEvent: evt 1693 }); 1694 }); 1695 1696 this.$selection.on( 1697 'click', 1698 '.select2-selection__choice__remove', 1699 function (evt) { 1700 // Ignore the event if it is disabled 1701 if (self.options.get('disabled')) { 1702 return; 1703 } 1704 1705 var $remove = $(this); 1706 var $selection = $remove.parent(); 1707 1708 var data = Utils.GetData($selection[0], 'data'); 1709 1710 self.trigger('unselect', { 1711 originalEvent: evt, 1712 data: data 1713 }); 1714 } 1715 ); 1716 }; 1717 1718 MultipleSelection.prototype.clear = function () { 1719 var $rendered = this.$selection.find('.select2-selection__rendered'); 1720 $rendered.empty(); 1721 $rendered.removeAttr('title'); 1722 }; 1723 1724 MultipleSelection.prototype.display = function (data, container) { 1725 var template = this.options.get('templateSelection'); 1726 var escapeMarkup = this.options.get('escapeMarkup'); 1727 1728 return escapeMarkup(template(data, container)); 1729 }; 1730 1731 MultipleSelection.prototype.selectionContainer = function () { 1732 var $container = $( 1733 '<li class="select2-selection__choice">' + 1734 '<span class="select2-selection__choice__remove" role="presentation">' + 1735 '×' + 1736 '</span>' + 1737 '</li>' 1738 ); 1739 1740 return $container; 1741 }; 1742 1743 MultipleSelection.prototype.update = function (data) { 1744 this.clear(); 1745 1746 if (data.length === 0) { 1747 return; 1748 } 1749 1750 var $selections = []; 1751 1752 for (var d = 0; d < data.length; d++) { 1753 var selection = data[d]; 1754 1755 var $selection = this.selectionContainer(); 1756 var formatted = this.display(selection, $selection); 1757 1758 $selection.append(formatted); 1759 $selection.attr('title', selection.title || selection.text); 1760 1761 Utils.StoreData($selection[0], 'data', selection); 1762 1763 $selections.push($selection); 1764 } 1765 1766 var $rendered = this.$selection.find('.select2-selection__rendered'); 1767 1768 Utils.appendMany($rendered, $selections); 1769 }; 1770 1771 return MultipleSelection; 1772}); 1773 1774S2.define('select2/selection/placeholder',[ 1775 '../utils' 1776], function (Utils) { 1777 function Placeholder (decorated, $element, options) { 1778 this.placeholder = this.normalizePlaceholder(options.get('placeholder')); 1779 1780 decorated.call(this, $element, options); 1781 } 1782 1783 Placeholder.prototype.normalizePlaceholder = function (_, placeholder) { 1784 if (typeof placeholder === 'string') { 1785 placeholder = { 1786 id: '', 1787 text: placeholder 1788 }; 1789 } 1790 1791 return placeholder; 1792 }; 1793 1794 Placeholder.prototype.createPlaceholder = function (decorated, placeholder) { 1795 var $placeholder = this.selectionContainer(); 1796 1797 $placeholder.html(this.display(placeholder)); 1798 $placeholder.addClass('select2-selection__placeholder') 1799 .removeClass('select2-selection__choice'); 1800 1801 return $placeholder; 1802 }; 1803 1804 Placeholder.prototype.update = function (decorated, data) { 1805 var singlePlaceholder = ( 1806 data.length == 1 && data[0].id != this.placeholder.id 1807 ); 1808 var multipleSelections = data.length > 1; 1809 1810 if (multipleSelections || singlePlaceholder) { 1811 return decorated.call(this, data); 1812 } 1813 1814 this.clear(); 1815 1816 var $placeholder = this.createPlaceholder(this.placeholder); 1817 1818 this.$selection.find('.select2-selection__rendered').append($placeholder); 1819 }; 1820 1821 return Placeholder; 1822}); 1823 1824S2.define('select2/selection/allowClear',[ 1825 'jquery', 1826 '../keys', 1827 '../utils' 1828], function ($, KEYS, Utils) { 1829 function AllowClear () { } 1830 1831 AllowClear.prototype.bind = function (decorated, container, $container) { 1832 var self = this; 1833 1834 decorated.call(this, container, $container); 1835 1836 if (this.placeholder == null) { 1837 if (this.options.get('debug') && window.console && console.error) { 1838 console.error( 1839 'Select2: The `allowClear` option should be used in combination ' + 1840 'with the `placeholder` option.' 1841 ); 1842 } 1843 } 1844 1845 this.$selection.on('mousedown', '.select2-selection__clear', 1846 function (evt) { 1847 self._handleClear(evt); 1848 }); 1849 1850 container.on('keypress', function (evt) { 1851 self._handleKeyboardClear(evt, container); 1852 }); 1853 }; 1854 1855 AllowClear.prototype._handleClear = function (_, evt) { 1856 // Ignore the event if it is disabled 1857 if (this.options.get('disabled')) { 1858 return; 1859 } 1860 1861 var $clear = this.$selection.find('.select2-selection__clear'); 1862 1863 // Ignore the event if nothing has been selected 1864 if ($clear.length === 0) { 1865 return; 1866 } 1867 1868 evt.stopPropagation(); 1869 1870 var data = Utils.GetData($clear[0], 'data'); 1871 1872 var previousVal = this.$element.val(); 1873 this.$element.val(this.placeholder.id); 1874 1875 var unselectData = { 1876 data: data 1877 }; 1878 this.trigger('clear', unselectData); 1879 if (unselectData.prevented) { 1880 this.$element.val(previousVal); 1881 return; 1882 } 1883 1884 for (var d = 0; d < data.length; d++) { 1885 unselectData = { 1886 data: data[d] 1887 }; 1888 1889 // Trigger the `unselect` event, so people can prevent it from being 1890 // cleared. 1891 this.trigger('unselect', unselectData); 1892 1893 // If the event was prevented, don't clear it out. 1894 if (unselectData.prevented) { 1895 this.$element.val(previousVal); 1896 return; 1897 } 1898 } 1899 1900 this.$element.trigger('change'); 1901 1902 this.trigger('toggle', {}); 1903 }; 1904 1905 AllowClear.prototype._handleKeyboardClear = function (_, evt, container) { 1906 if (container.isOpen()) { 1907 return; 1908 } 1909 1910 if (evt.which == KEYS.DELETE || evt.which == KEYS.BACKSPACE) { 1911 this._handleClear(evt); 1912 } 1913 }; 1914 1915 AllowClear.prototype.update = function (decorated, data) { 1916 decorated.call(this, data); 1917 1918 if (this.$selection.find('.select2-selection__placeholder').length > 0 || 1919 data.length === 0) { 1920 return; 1921 } 1922 1923 var removeAll = this.options.get('translations').get('removeAllItems'); 1924 1925 var $remove = $( 1926 '<span class="select2-selection__clear" title="' + removeAll() +'">' + 1927 '×' + 1928 '</span>' 1929 ); 1930 Utils.StoreData($remove[0], 'data', data); 1931 1932 this.$selection.find('.select2-selection__rendered').prepend($remove); 1933 }; 1934 1935 return AllowClear; 1936}); 1937 1938S2.define('select2/selection/search',[ 1939 'jquery', 1940 '../utils', 1941 '../keys' 1942], function ($, Utils, KEYS) { 1943 function Search (decorated, $element, options) { 1944 decorated.call(this, $element, options); 1945 } 1946 1947 Search.prototype.render = function (decorated) { 1948 var $search = $( 1949 '<li class="select2-search select2-search--inline">' + 1950 '<input class="select2-search__field" type="search" tabindex="-1"' + 1951 ' autocomplete="off" autocorrect="off" autocapitalize="none"' + 1952 ' spellcheck="false" role="textbox" aria-autocomplete="list" />' + 1953 '</li>' 1954 ); 1955 1956 this.$searchContainer = $search; 1957 this.$search = $search.find('input'); 1958 1959 var $rendered = decorated.call(this); 1960 1961 this._transferTabIndex(); 1962 1963 return $rendered; 1964 }; 1965 1966 Search.prototype.bind = function (decorated, container, $container) { 1967 var self = this; 1968 1969 decorated.call(this, container, $container); 1970 1971 container.on('open', function () { 1972 self.$search.trigger('focus'); 1973 }); 1974 1975 container.on('close', function () { 1976 self.$search.val(''); 1977 self.$search.removeAttr('aria-activedescendant'); 1978 self.$search.trigger('focus'); 1979 }); 1980 1981 container.on('enable', function () { 1982 self.$search.prop('disabled', false); 1983 1984 self._transferTabIndex(); 1985 }); 1986 1987 container.on('disable', function () { 1988 self.$search.prop('disabled', true); 1989 }); 1990 1991 container.on('focus', function (evt) { 1992 self.$search.trigger('focus'); 1993 }); 1994 1995 container.on('results:focus', function (params) { 1996 self.$search.attr('aria-activedescendant', params.id); 1997 }); 1998 1999 this.$selection.on('focusin', '.select2-search--inline', function (evt) { 2000 self.trigger('focus', evt); 2001 }); 2002 2003 this.$selection.on('focusout', '.select2-search--inline', function (evt) { 2004 self._handleBlur(evt); 2005 }); 2006 2007 this.$selection.on('keydown', '.select2-search--inline', function (evt) { 2008 evt.stopPropagation(); 2009 2010 self.trigger('keypress', evt); 2011 2012 self._keyUpPrevented = evt.isDefaultPrevented(); 2013 2014 var key = evt.which; 2015 2016 if (key === KEYS.BACKSPACE && self.$search.val() === '') { 2017 var $previousChoice = self.$searchContainer 2018 .prev('.select2-selection__choice'); 2019 2020 if ($previousChoice.length > 0) { 2021 var item = Utils.GetData($previousChoice[0], 'data'); 2022 2023 self.searchRemoveChoice(item); 2024 2025 evt.preventDefault(); 2026 } 2027 } 2028 }); 2029 2030 // Try to detect the IE version should the `documentMode` property that 2031 // is stored on the document. This is only implemented in IE and is 2032 // slightly cleaner than doing a user agent check. 2033 // This property is not available in Edge, but Edge also doesn't have 2034 // this bug. 2035 var msie = document.documentMode; 2036 var disableInputEvents = msie && msie <= 11; 2037 2038 // Workaround for browsers which do not support the `input` event 2039 // This will prevent double-triggering of events for browsers which support 2040 // both the `keyup` and `input` events. 2041 this.$selection.on( 2042 'input.searchcheck', 2043 '.select2-search--inline', 2044 function (evt) { 2045 // IE will trigger the `input` event when a placeholder is used on a 2046 // search box. To get around this issue, we are forced to ignore all 2047 // `input` events in IE and keep using `keyup`. 2048 if (disableInputEvents) { 2049 self.$selection.off('input.search input.searchcheck'); 2050 return; 2051 } 2052 2053 // Unbind the duplicated `keyup` event 2054 self.$selection.off('keyup.search'); 2055 } 2056 ); 2057 2058 this.$selection.on( 2059 'keyup.search input.search', 2060 '.select2-search--inline', 2061 function (evt) { 2062 // IE will trigger the `input` event when a placeholder is used on a 2063 // search box. To get around this issue, we are forced to ignore all 2064 // `input` events in IE and keep using `keyup`. 2065 if (disableInputEvents && evt.type === 'input') { 2066 self.$selection.off('input.search input.searchcheck'); 2067 return; 2068 } 2069 2070 var key = evt.which; 2071 2072 // We can freely ignore events from modifier keys 2073 if (key == KEYS.SHIFT || key == KEYS.CTRL || key == KEYS.ALT) { 2074 return; 2075 } 2076 2077 // Tabbing will be handled during the `keydown` phase 2078 if (key == KEYS.TAB) { 2079 return; 2080 } 2081 2082 self.handleSearch(evt); 2083 } 2084 ); 2085 }; 2086 2087 /** 2088 * This method will transfer the tabindex attribute from the rendered 2089 * selection to the search box. This allows for the search box to be used as 2090 * the primary focus instead of the selection container. 2091 * 2092 * @private 2093 */ 2094 Search.prototype._transferTabIndex = function (decorated) { 2095 this.$search.attr('tabindex', this.$selection.attr('tabindex')); 2096 this.$selection.attr('tabindex', '-1'); 2097 }; 2098 2099 Search.prototype.createPlaceholder = function (decorated, placeholder) { 2100 this.$search.attr('placeholder', placeholder.text); 2101 }; 2102 2103 Search.prototype.update = function (decorated, data) { 2104 var searchHadFocus = this.$search[0] == document.activeElement; 2105 2106 this.$search.attr('placeholder', ''); 2107 2108 decorated.call(this, data); 2109 2110 this.$selection.find('.select2-selection__rendered') 2111 .append(this.$searchContainer); 2112 2113 this.resizeSearch(); 2114 if (searchHadFocus) { 2115 this.$search.trigger('focus'); 2116 } 2117 }; 2118 2119 Search.prototype.handleSearch = function () { 2120 this.resizeSearch(); 2121 2122 if (!this._keyUpPrevented) { 2123 var input = this.$search.val(); 2124 2125 this.trigger('query', { 2126 term: input 2127 }); 2128 } 2129 2130 this._keyUpPrevented = false; 2131 }; 2132 2133 Search.prototype.searchRemoveChoice = function (decorated, item) { 2134 this.trigger('unselect', { 2135 data: item 2136 }); 2137 2138 this.$search.val(item.text); 2139 this.handleSearch(); 2140 }; 2141 2142 Search.prototype.resizeSearch = function () { 2143 this.$search.css('width', '25px'); 2144 2145 var width = ''; 2146 2147 if (this.$search.attr('placeholder') !== '') { 2148 width = this.$selection.find('.select2-selection__rendered').innerWidth(); 2149 } else { 2150 var minimumWidth = this.$search.val().length + 1; 2151 2152 width = (minimumWidth * 0.75) + 'em'; 2153 } 2154 2155 this.$search.css('width', width); 2156 }; 2157 2158 return Search; 2159}); 2160 2161S2.define('select2/selection/eventRelay',[ 2162 'jquery' 2163], function ($) { 2164 function EventRelay () { } 2165 2166 EventRelay.prototype.bind = function (decorated, container, $container) { 2167 var self = this; 2168 var relayEvents = [ 2169 'open', 'opening', 2170 'close', 'closing', 2171 'select', 'selecting', 2172 'unselect', 'unselecting', 2173 'clear', 'clearing' 2174 ]; 2175 2176 var preventableEvents = [ 2177 'opening', 'closing', 'selecting', 'unselecting', 'clearing' 2178 ]; 2179 2180 decorated.call(this, container, $container); 2181 2182 container.on('*', function (name, params) { 2183 // Ignore events that should not be relayed 2184 if ($.inArray(name, relayEvents) === -1) { 2185 return; 2186 } 2187 2188 // The parameters should always be an object 2189 params = params || {}; 2190 2191 // Generate the jQuery event for the Select2 event 2192 var evt = $.Event('select2:' + name, { 2193 params: params 2194 }); 2195 2196 self.$element.trigger(evt); 2197 2198 // Only handle preventable events if it was one 2199 if ($.inArray(name, preventableEvents) === -1) { 2200 return; 2201 } 2202 2203 params.prevented = evt.isDefaultPrevented(); 2204 }); 2205 }; 2206 2207 return EventRelay; 2208}); 2209 2210S2.define('select2/translation',[ 2211 'jquery', 2212 'require' 2213], function ($, require) { 2214 function Translation (dict) { 2215 this.dict = dict || {}; 2216 } 2217 2218 Translation.prototype.all = function () { 2219 return this.dict; 2220 }; 2221 2222 Translation.prototype.get = function (key) { 2223 return this.dict[key]; 2224 }; 2225 2226 Translation.prototype.extend = function (translation) { 2227 this.dict = $.extend({}, translation.all(), this.dict); 2228 }; 2229 2230 // Static functions 2231 2232 Translation._cache = {}; 2233 2234 Translation.loadPath = function (path) { 2235 if (!(path in Translation._cache)) { 2236 var translations = require(path); 2237 2238 Translation._cache[path] = translations; 2239 } 2240 2241 return new Translation(Translation._cache[path]); 2242 }; 2243 2244 return Translation; 2245}); 2246 2247S2.define('select2/diacritics',[ 2248 2249], function () { 2250 var diacritics = { 2251 '\u24B6': 'A', 2252 '\uFF21': 'A', 2253 '\u00C0': 'A', 2254 '\u00C1': 'A', 2255 '\u00C2': 'A', 2256 '\u1EA6': 'A', 2257 '\u1EA4': 'A', 2258 '\u1EAA': 'A', 2259 '\u1EA8': 'A', 2260 '\u00C3': 'A', 2261 '\u0100': 'A', 2262 '\u0102': 'A', 2263 '\u1EB0': 'A', 2264 '\u1EAE': 'A', 2265 '\u1EB4': 'A', 2266 '\u1EB2': 'A', 2267 '\u0226': 'A', 2268 '\u01E0': 'A', 2269 '\u00C4': 'A', 2270 '\u01DE': 'A', 2271 '\u1EA2': 'A', 2272 '\u00C5': 'A', 2273 '\u01FA': 'A', 2274 '\u01CD': 'A', 2275 '\u0200': 'A', 2276 '\u0202': 'A', 2277 '\u1EA0': 'A', 2278 '\u1EAC': 'A', 2279 '\u1EB6': 'A', 2280 '\u1E00': 'A', 2281 '\u0104': 'A', 2282 '\u023A': 'A', 2283 '\u2C6F': 'A', 2284 '\uA732': 'AA', 2285 '\u00C6': 'AE', 2286 '\u01FC': 'AE', 2287 '\u01E2': 'AE', 2288 '\uA734': 'AO', 2289 '\uA736': 'AU', 2290 '\uA738': 'AV', 2291 '\uA73A': 'AV', 2292 '\uA73C': 'AY', 2293 '\u24B7': 'B', 2294 '\uFF22': 'B', 2295 '\u1E02': 'B', 2296 '\u1E04': 'B', 2297 '\u1E06': 'B', 2298 '\u0243': 'B', 2299 '\u0182': 'B', 2300 '\u0181': 'B', 2301 '\u24B8': 'C', 2302 '\uFF23': 'C', 2303 '\u0106': 'C', 2304 '\u0108': 'C', 2305 '\u010A': 'C', 2306 '\u010C': 'C', 2307 '\u00C7': 'C', 2308 '\u1E08': 'C', 2309 '\u0187': 'C', 2310 '\u023B': 'C', 2311 '\uA73E': 'C', 2312 '\u24B9': 'D', 2313 '\uFF24': 'D', 2314 '\u1E0A': 'D', 2315 '\u010E': 'D', 2316 '\u1E0C': 'D', 2317 '\u1E10': 'D', 2318 '\u1E12': 'D', 2319 '\u1E0E': 'D', 2320 '\u0110': 'D', 2321 '\u018B': 'D', 2322 '\u018A': 'D', 2323 '\u0189': 'D', 2324 '\uA779': 'D', 2325 '\u01F1': 'DZ', 2326 '\u01C4': 'DZ', 2327 '\u01F2': 'Dz', 2328 '\u01C5': 'Dz', 2329 '\u24BA': 'E', 2330 '\uFF25': 'E', 2331 '\u00C8': 'E', 2332 '\u00C9': 'E', 2333 '\u00CA': 'E', 2334 '\u1EC0': 'E', 2335 '\u1EBE': 'E', 2336 '\u1EC4': 'E', 2337 '\u1EC2': 'E', 2338 '\u1EBC': 'E', 2339 '\u0112': 'E', 2340 '\u1E14': 'E', 2341 '\u1E16': 'E', 2342 '\u0114': 'E', 2343 '\u0116': 'E', 2344 '\u00CB': 'E', 2345 '\u1EBA': 'E', 2346 '\u011A': 'E', 2347 '\u0204': 'E', 2348 '\u0206': 'E', 2349 '\u1EB8': 'E', 2350 '\u1EC6': 'E', 2351 '\u0228': 'E', 2352 '\u1E1C': 'E', 2353 '\u0118': 'E', 2354 '\u1E18': 'E', 2355 '\u1E1A': 'E', 2356 '\u0190': 'E', 2357 '\u018E': 'E', 2358 '\u24BB': 'F', 2359 '\uFF26': 'F', 2360 '\u1E1E': 'F', 2361 '\u0191': 'F', 2362 '\uA77B': 'F', 2363 '\u24BC': 'G', 2364 '\uFF27': 'G', 2365 '\u01F4': 'G', 2366 '\u011C': 'G', 2367 '\u1E20': 'G', 2368 '\u011E': 'G', 2369 '\u0120': 'G', 2370 '\u01E6': 'G', 2371 '\u0122': 'G', 2372 '\u01E4': 'G', 2373 '\u0193': 'G', 2374 '\uA7A0': 'G', 2375 '\uA77D': 'G', 2376 '\uA77E': 'G', 2377 '\u24BD': 'H', 2378 '\uFF28': 'H', 2379 '\u0124': 'H', 2380 '\u1E22': 'H', 2381 '\u1E26': 'H', 2382 '\u021E': 'H', 2383 '\u1E24': 'H', 2384 '\u1E28': 'H', 2385 '\u1E2A': 'H', 2386 '\u0126': 'H', 2387 '\u2C67': 'H', 2388 '\u2C75': 'H', 2389 '\uA78D': 'H', 2390 '\u24BE': 'I', 2391 '\uFF29': 'I', 2392 '\u00CC': 'I', 2393 '\u00CD': 'I', 2394 '\u00CE': 'I', 2395 '\u0128': 'I', 2396 '\u012A': 'I', 2397 '\u012C': 'I', 2398 '\u0130': 'I', 2399 '\u00CF': 'I', 2400 '\u1E2E': 'I', 2401 '\u1EC8': 'I', 2402 '\u01CF': 'I', 2403 '\u0208': 'I', 2404 '\u020A': 'I', 2405 '\u1ECA': 'I', 2406 '\u012E': 'I', 2407 '\u1E2C': 'I', 2408 '\u0197': 'I', 2409 '\u24BF': 'J', 2410 '\uFF2A': 'J', 2411 '\u0134': 'J', 2412 '\u0248': 'J', 2413 '\u24C0': 'K', 2414 '\uFF2B': 'K', 2415 '\u1E30': 'K', 2416 '\u01E8': 'K', 2417 '\u1E32': 'K', 2418 '\u0136': 'K', 2419 '\u1E34': 'K', 2420 '\u0198': 'K', 2421 '\u2C69': 'K', 2422 '\uA740': 'K', 2423 '\uA742': 'K', 2424 '\uA744': 'K', 2425 '\uA7A2': 'K', 2426 '\u24C1': 'L', 2427 '\uFF2C': 'L', 2428 '\u013F': 'L', 2429 '\u0139': 'L', 2430 '\u013D': 'L', 2431 '\u1E36': 'L', 2432 '\u1E38': 'L', 2433 '\u013B': 'L', 2434 '\u1E3C': 'L', 2435 '\u1E3A': 'L', 2436 '\u0141': 'L', 2437 '\u023D': 'L', 2438 '\u2C62': 'L', 2439 '\u2C60': 'L', 2440 '\uA748': 'L', 2441 '\uA746': 'L', 2442 '\uA780': 'L', 2443 '\u01C7': 'LJ', 2444 '\u01C8': 'Lj', 2445 '\u24C2': 'M', 2446 '\uFF2D': 'M', 2447 '\u1E3E': 'M', 2448 '\u1E40': 'M', 2449 '\u1E42': 'M', 2450 '\u2C6E': 'M', 2451 '\u019C': 'M', 2452 '\u24C3': 'N', 2453 '\uFF2E': 'N', 2454 '\u01F8': 'N', 2455 '\u0143': 'N', 2456 '\u00D1': 'N', 2457 '\u1E44': 'N', 2458 '\u0147': 'N', 2459 '\u1E46': 'N', 2460 '\u0145': 'N', 2461 '\u1E4A': 'N', 2462 '\u1E48': 'N', 2463 '\u0220': 'N', 2464 '\u019D': 'N', 2465 '\uA790': 'N', 2466 '\uA7A4': 'N', 2467 '\u01CA': 'NJ', 2468 '\u01CB': 'Nj', 2469 '\u24C4': 'O', 2470 '\uFF2F': 'O', 2471 '\u00D2': 'O', 2472 '\u00D3': 'O', 2473 '\u00D4': 'O', 2474 '\u1ED2': 'O', 2475 '\u1ED0': 'O', 2476 '\u1ED6': 'O', 2477 '\u1ED4': 'O', 2478 '\u00D5': 'O', 2479 '\u1E4C': 'O', 2480 '\u022C': 'O', 2481 '\u1E4E': 'O', 2482 '\u014C': 'O', 2483 '\u1E50': 'O', 2484 '\u1E52': 'O', 2485 '\u014E': 'O', 2486 '\u022E': 'O', 2487 '\u0230': 'O', 2488 '\u00D6': 'O', 2489 '\u022A': 'O', 2490 '\u1ECE': 'O', 2491 '\u0150': 'O', 2492 '\u01D1': 'O', 2493 '\u020C': 'O', 2494 '\u020E': 'O', 2495 '\u01A0': 'O', 2496 '\u1EDC': 'O', 2497 '\u1EDA': 'O', 2498 '\u1EE0': 'O', 2499 '\u1EDE': 'O', 2500 '\u1EE2': 'O', 2501 '\u1ECC': 'O', 2502 '\u1ED8': 'O', 2503 '\u01EA': 'O', 2504 '\u01EC': 'O', 2505 '\u00D8': 'O', 2506 '\u01FE': 'O', 2507 '\u0186': 'O', 2508 '\u019F': 'O', 2509 '\uA74A': 'O', 2510 '\uA74C': 'O', 2511 '\u0152': 'OE', 2512 '\u01A2': 'OI', 2513 '\uA74E': 'OO', 2514 '\u0222': 'OU', 2515 '\u24C5': 'P', 2516 '\uFF30': 'P', 2517 '\u1E54': 'P', 2518 '\u1E56': 'P', 2519 '\u01A4': 'P', 2520 '\u2C63': 'P', 2521 '\uA750': 'P', 2522 '\uA752': 'P', 2523 '\uA754': 'P', 2524 '\u24C6': 'Q', 2525 '\uFF31': 'Q', 2526 '\uA756': 'Q', 2527 '\uA758': 'Q', 2528 '\u024A': 'Q', 2529 '\u24C7': 'R', 2530 '\uFF32': 'R', 2531 '\u0154': 'R', 2532 '\u1E58': 'R', 2533 '\u0158': 'R', 2534 '\u0210': 'R', 2535 '\u0212': 'R', 2536 '\u1E5A': 'R', 2537 '\u1E5C': 'R', 2538 '\u0156': 'R', 2539 '\u1E5E': 'R', 2540 '\u024C': 'R', 2541 '\u2C64': 'R', 2542 '\uA75A': 'R', 2543 '\uA7A6': 'R', 2544 '\uA782': 'R', 2545 '\u24C8': 'S', 2546 '\uFF33': 'S', 2547 '\u1E9E': 'S', 2548 '\u015A': 'S', 2549 '\u1E64': 'S', 2550 '\u015C': 'S', 2551 '\u1E60': 'S', 2552 '\u0160': 'S', 2553 '\u1E66': 'S', 2554 '\u1E62': 'S', 2555 '\u1E68': 'S', 2556 '\u0218': 'S', 2557 '\u015E': 'S', 2558 '\u2C7E': 'S', 2559 '\uA7A8': 'S', 2560 '\uA784': 'S', 2561 '\u24C9': 'T', 2562 '\uFF34': 'T', 2563 '\u1E6A': 'T', 2564 '\u0164': 'T', 2565 '\u1E6C': 'T', 2566 '\u021A': 'T', 2567 '\u0162': 'T', 2568 '\u1E70': 'T', 2569 '\u1E6E': 'T', 2570 '\u0166': 'T', 2571 '\u01AC': 'T', 2572 '\u01AE': 'T', 2573 '\u023E': 'T', 2574 '\uA786': 'T', 2575 '\uA728': 'TZ', 2576 '\u24CA': 'U', 2577 '\uFF35': 'U', 2578 '\u00D9': 'U', 2579 '\u00DA': 'U', 2580 '\u00DB': 'U', 2581 '\u0168': 'U', 2582 '\u1E78': 'U', 2583 '\u016A': 'U', 2584 '\u1E7A': 'U', 2585 '\u016C': 'U', 2586 '\u00DC': 'U', 2587 '\u01DB': 'U', 2588 '\u01D7': 'U', 2589 '\u01D5': 'U', 2590 '\u01D9': 'U', 2591 '\u1EE6': 'U', 2592 '\u016E': 'U', 2593 '\u0170': 'U', 2594 '\u01D3': 'U', 2595 '\u0214': 'U', 2596 '\u0216': 'U', 2597 '\u01AF': 'U', 2598 '\u1EEA': 'U', 2599 '\u1EE8': 'U', 2600 '\u1EEE': 'U', 2601 '\u1EEC': 'U', 2602 '\u1EF0': 'U', 2603 '\u1EE4': 'U', 2604 '\u1E72': 'U', 2605 '\u0172': 'U', 2606 '\u1E76': 'U', 2607 '\u1E74': 'U', 2608 '\u0244': 'U', 2609 '\u24CB': 'V', 2610 '\uFF36': 'V', 2611 '\u1E7C': 'V', 2612 '\u1E7E': 'V', 2613 '\u01B2': 'V', 2614 '\uA75E': 'V', 2615 '\u0245': 'V', 2616 '\uA760': 'VY', 2617 '\u24CC': 'W', 2618 '\uFF37': 'W', 2619 '\u1E80': 'W', 2620 '\u1E82': 'W', 2621 '\u0174': 'W', 2622 '\u1E86': 'W', 2623 '\u1E84': 'W', 2624 '\u1E88': 'W', 2625 '\u2C72': 'W', 2626 '\u24CD': 'X', 2627 '\uFF38': 'X', 2628 '\u1E8A': 'X', 2629 '\u1E8C': 'X', 2630 '\u24CE': 'Y', 2631 '\uFF39': 'Y', 2632 '\u1EF2': 'Y', 2633 '\u00DD': 'Y', 2634 '\u0176': 'Y', 2635 '\u1EF8': 'Y', 2636 '\u0232': 'Y', 2637 '\u1E8E': 'Y', 2638 '\u0178': 'Y', 2639 '\u1EF6': 'Y', 2640 '\u1EF4': 'Y', 2641 '\u01B3': 'Y', 2642 '\u024E': 'Y', 2643 '\u1EFE': 'Y', 2644 '\u24CF': 'Z', 2645 '\uFF3A': 'Z', 2646 '\u0179': 'Z', 2647 '\u1E90': 'Z', 2648 '\u017B': 'Z', 2649 '\u017D': 'Z', 2650 '\u1E92': 'Z', 2651 '\u1E94': 'Z', 2652 '\u01B5': 'Z', 2653 '\u0224': 'Z', 2654 '\u2C7F': 'Z', 2655 '\u2C6B': 'Z', 2656 '\uA762': 'Z', 2657 '\u24D0': 'a', 2658 '\uFF41': 'a', 2659 '\u1E9A': 'a', 2660 '\u00E0': 'a', 2661 '\u00E1': 'a', 2662 '\u00E2': 'a', 2663 '\u1EA7': 'a', 2664 '\u1EA5': 'a', 2665 '\u1EAB': 'a', 2666 '\u1EA9': 'a', 2667 '\u00E3': 'a', 2668 '\u0101': 'a', 2669 '\u0103': 'a', 2670 '\u1EB1': 'a', 2671 '\u1EAF': 'a', 2672 '\u1EB5': 'a', 2673 '\u1EB3': 'a', 2674 '\u0227': 'a', 2675 '\u01E1': 'a', 2676 '\u00E4': 'a', 2677 '\u01DF': 'a', 2678 '\u1EA3': 'a', 2679 '\u00E5': 'a', 2680 '\u01FB': 'a', 2681 '\u01CE': 'a', 2682 '\u0201': 'a', 2683 '\u0203': 'a', 2684 '\u1EA1': 'a', 2685 '\u1EAD': 'a', 2686 '\u1EB7': 'a', 2687 '\u1E01': 'a', 2688 '\u0105': 'a', 2689 '\u2C65': 'a', 2690 '\u0250': 'a', 2691 '\uA733': 'aa', 2692 '\u00E6': 'ae', 2693 '\u01FD': 'ae', 2694 '\u01E3': 'ae', 2695 '\uA735': 'ao', 2696 '\uA737': 'au', 2697 '\uA739': 'av', 2698 '\uA73B': 'av', 2699 '\uA73D': 'ay', 2700 '\u24D1': 'b', 2701 '\uFF42': 'b', 2702 '\u1E03': 'b', 2703 '\u1E05': 'b', 2704 '\u1E07': 'b', 2705 '\u0180': 'b', 2706 '\u0183': 'b', 2707 '\u0253': 'b', 2708 '\u24D2': 'c', 2709 '\uFF43': 'c', 2710 '\u0107': 'c', 2711 '\u0109': 'c', 2712 '\u010B': 'c', 2713 '\u010D': 'c', 2714 '\u00E7': 'c', 2715 '\u1E09': 'c', 2716 '\u0188': 'c', 2717 '\u023C': 'c', 2718 '\uA73F': 'c', 2719 '\u2184': 'c', 2720 '\u24D3': 'd', 2721 '\uFF44': 'd', 2722 '\u1E0B': 'd', 2723 '\u010F': 'd', 2724 '\u1E0D': 'd', 2725 '\u1E11': 'd', 2726 '\u1E13': 'd', 2727 '\u1E0F': 'd', 2728 '\u0111': 'd', 2729 '\u018C': 'd', 2730 '\u0256': 'd', 2731 '\u0257': 'd', 2732 '\uA77A': 'd', 2733 '\u01F3': 'dz', 2734 '\u01C6': 'dz', 2735 '\u24D4': 'e', 2736 '\uFF45': 'e', 2737 '\u00E8': 'e', 2738 '\u00E9': 'e', 2739 '\u00EA': 'e', 2740 '\u1EC1': 'e', 2741 '\u1EBF': 'e', 2742 '\u1EC5': 'e', 2743 '\u1EC3': 'e', 2744 '\u1EBD': 'e', 2745 '\u0113': 'e', 2746 '\u1E15': 'e', 2747 '\u1E17': 'e', 2748 '\u0115': 'e', 2749 '\u0117': 'e', 2750 '\u00EB': 'e', 2751 '\u1EBB': 'e', 2752 '\u011B': 'e', 2753 '\u0205': 'e', 2754 '\u0207': 'e', 2755 '\u1EB9': 'e', 2756 '\u1EC7': 'e', 2757 '\u0229': 'e', 2758 '\u1E1D': 'e', 2759 '\u0119': 'e', 2760 '\u1E19': 'e', 2761 '\u1E1B': 'e', 2762 '\u0247': 'e', 2763 '\u025B': 'e', 2764 '\u01DD': 'e', 2765 '\u24D5': 'f', 2766 '\uFF46': 'f', 2767 '\u1E1F': 'f', 2768 '\u0192': 'f', 2769 '\uA77C': 'f', 2770 '\u24D6': 'g', 2771 '\uFF47': 'g', 2772 '\u01F5': 'g', 2773 '\u011D': 'g', 2774 '\u1E21': 'g', 2775 '\u011F': 'g', 2776 '\u0121': 'g', 2777 '\u01E7': 'g', 2778 '\u0123': 'g', 2779 '\u01E5': 'g', 2780 '\u0260': 'g', 2781 '\uA7A1': 'g', 2782 '\u1D79': 'g', 2783 '\uA77F': 'g', 2784 '\u24D7': 'h', 2785 '\uFF48': 'h', 2786 '\u0125': 'h', 2787 '\u1E23': 'h', 2788 '\u1E27': 'h', 2789 '\u021F': 'h', 2790 '\u1E25': 'h', 2791 '\u1E29': 'h', 2792 '\u1E2B': 'h', 2793 '\u1E96': 'h', 2794 '\u0127': 'h', 2795 '\u2C68': 'h', 2796 '\u2C76': 'h', 2797 '\u0265': 'h', 2798 '\u0195': 'hv', 2799 '\u24D8': 'i', 2800 '\uFF49': 'i', 2801 '\u00EC': 'i', 2802 '\u00ED': 'i', 2803 '\u00EE': 'i', 2804 '\u0129': 'i', 2805 '\u012B': 'i', 2806 '\u012D': 'i', 2807 '\u00EF': 'i', 2808 '\u1E2F': 'i', 2809 '\u1EC9': 'i', 2810 '\u01D0': 'i', 2811 '\u0209': 'i', 2812 '\u020B': 'i', 2813 '\u1ECB': 'i', 2814 '\u012F': 'i', 2815 '\u1E2D': 'i', 2816 '\u0268': 'i', 2817 '\u0131': 'i', 2818 '\u24D9': 'j', 2819 '\uFF4A': 'j', 2820 '\u0135': 'j', 2821 '\u01F0': 'j', 2822 '\u0249': 'j', 2823 '\u24DA': 'k', 2824 '\uFF4B': 'k', 2825 '\u1E31': 'k', 2826 '\u01E9': 'k', 2827 '\u1E33': 'k', 2828 '\u0137': 'k', 2829 '\u1E35': 'k', 2830 '\u0199': 'k', 2831 '\u2C6A': 'k', 2832 '\uA741': 'k', 2833 '\uA743': 'k', 2834 '\uA745': 'k', 2835 '\uA7A3': 'k', 2836 '\u24DB': 'l', 2837 '\uFF4C': 'l', 2838 '\u0140': 'l', 2839 '\u013A': 'l', 2840 '\u013E': 'l', 2841 '\u1E37': 'l', 2842 '\u1E39': 'l', 2843 '\u013C': 'l', 2844 '\u1E3D': 'l', 2845 '\u1E3B': 'l', 2846 '\u017F': 'l', 2847 '\u0142': 'l', 2848 '\u019A': 'l', 2849 '\u026B': 'l', 2850 '\u2C61': 'l', 2851 '\uA749': 'l', 2852 '\uA781': 'l', 2853 '\uA747': 'l', 2854 '\u01C9': 'lj', 2855 '\u24DC': 'm', 2856 '\uFF4D': 'm', 2857 '\u1E3F': 'm', 2858 '\u1E41': 'm', 2859 '\u1E43': 'm', 2860 '\u0271': 'm', 2861 '\u026F': 'm', 2862 '\u24DD': 'n', 2863 '\uFF4E': 'n', 2864 '\u01F9': 'n', 2865 '\u0144': 'n', 2866 '\u00F1': 'n', 2867 '\u1E45': 'n', 2868 '\u0148': 'n', 2869 '\u1E47': 'n', 2870 '\u0146': 'n', 2871 '\u1E4B': 'n', 2872 '\u1E49': 'n', 2873 '\u019E': 'n', 2874 '\u0272': 'n', 2875 '\u0149': 'n', 2876 '\uA791': 'n', 2877 '\uA7A5': 'n', 2878 '\u01CC': 'nj', 2879 '\u24DE': 'o', 2880 '\uFF4F': 'o', 2881 '\u00F2': 'o', 2882 '\u00F3': 'o', 2883 '\u00F4': 'o', 2884 '\u1ED3': 'o', 2885 '\u1ED1': 'o', 2886 '\u1ED7': 'o', 2887 '\u1ED5': 'o', 2888 '\u00F5': 'o', 2889 '\u1E4D': 'o', 2890 '\u022D': 'o', 2891 '\u1E4F': 'o', 2892 '\u014D': 'o', 2893 '\u1E51': 'o', 2894 '\u1E53': 'o', 2895 '\u014F': 'o', 2896 '\u022F': 'o', 2897 '\u0231': 'o', 2898 '\u00F6': 'o', 2899 '\u022B': 'o', 2900 '\u1ECF': 'o', 2901 '\u0151': 'o', 2902 '\u01D2': 'o', 2903 '\u020D': 'o', 2904 '\u020F': 'o', 2905 '\u01A1': 'o', 2906 '\u1EDD': 'o', 2907 '\u1EDB': 'o', 2908 '\u1EE1': 'o', 2909 '\u1EDF': 'o', 2910 '\u1EE3': 'o', 2911 '\u1ECD': 'o', 2912 '\u1ED9': 'o', 2913 '\u01EB': 'o', 2914 '\u01ED': 'o', 2915 '\u00F8': 'o', 2916 '\u01FF': 'o', 2917 '\u0254': 'o', 2918 '\uA74B': 'o', 2919 '\uA74D': 'o', 2920 '\u0275': 'o', 2921 '\u0153': 'oe', 2922 '\u01A3': 'oi', 2923 '\u0223': 'ou', 2924 '\uA74F': 'oo', 2925 '\u24DF': 'p', 2926 '\uFF50': 'p', 2927 '\u1E55': 'p', 2928 '\u1E57': 'p', 2929 '\u01A5': 'p', 2930 '\u1D7D': 'p', 2931 '\uA751': 'p', 2932 '\uA753': 'p', 2933 '\uA755': 'p', 2934 '\u24E0': 'q', 2935 '\uFF51': 'q', 2936 '\u024B': 'q', 2937 '\uA757': 'q', 2938 '\uA759': 'q', 2939 '\u24E1': 'r', 2940 '\uFF52': 'r', 2941 '\u0155': 'r', 2942 '\u1E59': 'r', 2943 '\u0159': 'r', 2944 '\u0211': 'r', 2945 '\u0213': 'r', 2946 '\u1E5B': 'r', 2947 '\u1E5D': 'r', 2948 '\u0157': 'r', 2949 '\u1E5F': 'r', 2950 '\u024D': 'r', 2951 '\u027D': 'r', 2952 '\uA75B': 'r', 2953 '\uA7A7': 'r', 2954 '\uA783': 'r', 2955 '\u24E2': 's', 2956 '\uFF53': 's', 2957 '\u00DF': 's', 2958 '\u015B': 's', 2959 '\u1E65': 's', 2960 '\u015D': 's', 2961 '\u1E61': 's', 2962 '\u0161': 's', 2963 '\u1E67': 's', 2964 '\u1E63': 's', 2965 '\u1E69': 's', 2966 '\u0219': 's', 2967 '\u015F': 's', 2968 '\u023F': 's', 2969 '\uA7A9': 's', 2970 '\uA785': 's', 2971 '\u1E9B': 's', 2972 '\u24E3': 't', 2973 '\uFF54': 't', 2974 '\u1E6B': 't', 2975 '\u1E97': 't', 2976 '\u0165': 't', 2977 '\u1E6D': 't', 2978 '\u021B': 't', 2979 '\u0163': 't', 2980 '\u1E71': 't', 2981 '\u1E6F': 't', 2982 '\u0167': 't', 2983 '\u01AD': 't', 2984 '\u0288': 't', 2985 '\u2C66': 't', 2986 '\uA787': 't', 2987 '\uA729': 'tz', 2988 '\u24E4': 'u', 2989 '\uFF55': 'u', 2990 '\u00F9': 'u', 2991 '\u00FA': 'u', 2992 '\u00FB': 'u', 2993 '\u0169': 'u', 2994 '\u1E79': 'u', 2995 '\u016B': 'u', 2996 '\u1E7B': 'u', 2997 '\u016D': 'u', 2998 '\u00FC': 'u', 2999 '\u01DC': 'u', 3000 '\u01D8': 'u', 3001 '\u01D6': 'u', 3002 '\u01DA': 'u', 3003 '\u1EE7': 'u', 3004 '\u016F': 'u', 3005 '\u0171': 'u', 3006 '\u01D4': 'u', 3007 '\u0215': 'u', 3008 '\u0217': 'u', 3009 '\u01B0': 'u', 3010 '\u1EEB': 'u', 3011 '\u1EE9': 'u', 3012 '\u1EEF': 'u', 3013 '\u1EED': 'u', 3014 '\u1EF1': 'u', 3015 '\u1EE5': 'u', 3016 '\u1E73': 'u', 3017 '\u0173': 'u', 3018 '\u1E77': 'u', 3019 '\u1E75': 'u', 3020 '\u0289': 'u', 3021 '\u24E5': 'v', 3022 '\uFF56': 'v', 3023 '\u1E7D': 'v', 3024 '\u1E7F': 'v', 3025 '\u028B': 'v', 3026 '\uA75F': 'v', 3027 '\u028C': 'v', 3028 '\uA761': 'vy', 3029 '\u24E6': 'w', 3030 '\uFF57': 'w', 3031 '\u1E81': 'w', 3032 '\u1E83': 'w', 3033 '\u0175': 'w', 3034 '\u1E87': 'w', 3035 '\u1E85': 'w', 3036 '\u1E98': 'w', 3037 '\u1E89': 'w', 3038 '\u2C73': 'w', 3039 '\u24E7': 'x', 3040 '\uFF58': 'x', 3041 '\u1E8B': 'x', 3042 '\u1E8D': 'x', 3043 '\u24E8': 'y', 3044 '\uFF59': 'y', 3045 '\u1EF3': 'y', 3046 '\u00FD': 'y', 3047 '\u0177': 'y', 3048 '\u1EF9': 'y', 3049 '\u0233': 'y', 3050 '\u1E8F': 'y', 3051 '\u00FF': 'y', 3052 '\u1EF7': 'y', 3053 '\u1E99': 'y', 3054 '\u1EF5': 'y', 3055 '\u01B4': 'y', 3056 '\u024F': 'y', 3057 '\u1EFF': 'y', 3058 '\u24E9': 'z', 3059 '\uFF5A': 'z', 3060 '\u017A': 'z', 3061 '\u1E91': 'z', 3062 '\u017C': 'z', 3063 '\u017E': 'z', 3064 '\u1E93': 'z', 3065 '\u1E95': 'z', 3066 '\u01B6': 'z', 3067 '\u0225': 'z', 3068 '\u0240': 'z', 3069 '\u2C6C': 'z', 3070 '\uA763': 'z', 3071 '\u0386': '\u0391', 3072 '\u0388': '\u0395', 3073 '\u0389': '\u0397', 3074 '\u038A': '\u0399', 3075 '\u03AA': '\u0399', 3076 '\u038C': '\u039F', 3077 '\u038E': '\u03A5', 3078 '\u03AB': '\u03A5', 3079 '\u038F': '\u03A9', 3080 '\u03AC': '\u03B1', 3081 '\u03AD': '\u03B5', 3082 '\u03AE': '\u03B7', 3083 '\u03AF': '\u03B9', 3084 '\u03CA': '\u03B9', 3085 '\u0390': '\u03B9', 3086 '\u03CC': '\u03BF', 3087 '\u03CD': '\u03C5', 3088 '\u03CB': '\u03C5', 3089 '\u03B0': '\u03C5', 3090 '\u03CE': '\u03C9', 3091 '\u03C2': '\u03C3', 3092 '\u2019': '\'' 3093 }; 3094 3095 return diacritics; 3096}); 3097 3098S2.define('select2/data/base',[ 3099 '../utils' 3100], function (Utils) { 3101 function BaseAdapter ($element, options) { 3102 BaseAdapter.__super__.constructor.call(this); 3103 } 3104 3105 Utils.Extend(BaseAdapter, Utils.Observable); 3106 3107 BaseAdapter.prototype.current = function (callback) { 3108 throw new Error('The `current` method must be defined in child classes.'); 3109 }; 3110 3111 BaseAdapter.prototype.query = function (params, callback) { 3112 throw new Error('The `query` method must be defined in child classes.'); 3113 }; 3114 3115 BaseAdapter.prototype.bind = function (container, $container) { 3116 // Can be implemented in subclasses 3117 }; 3118 3119 BaseAdapter.prototype.destroy = function () { 3120 // Can be implemented in subclasses 3121 }; 3122 3123 BaseAdapter.prototype.generateResultId = function (container, data) { 3124 var id = container.id + '-result-'; 3125 3126 id += Utils.generateChars(4); 3127 3128 if (data.id != null) { 3129 id += '-' + data.id.toString(); 3130 } else { 3131 id += '-' + Utils.generateChars(4); 3132 } 3133 return id; 3134 }; 3135 3136 return BaseAdapter; 3137}); 3138 3139S2.define('select2/data/select',[ 3140 './base', 3141 '../utils', 3142 'jquery' 3143], function (BaseAdapter, Utils, $) { 3144 function SelectAdapter ($element, options) { 3145 this.$element = $element; 3146 this.options = options; 3147 3148 SelectAdapter.__super__.constructor.call(this); 3149 } 3150 3151 Utils.Extend(SelectAdapter, BaseAdapter); 3152 3153 SelectAdapter.prototype.current = function (callback) { 3154 var data = []; 3155 var self = this; 3156 3157 this.$element.find(':selected').each(function () { 3158 var $option = $(this); 3159 3160 var option = self.item($option); 3161 3162 data.push(option); 3163 }); 3164 3165 callback(data); 3166 }; 3167 3168 SelectAdapter.prototype.select = function (data) { 3169 var self = this; 3170 3171 data.selected = true; 3172 3173 // If data.element is a DOM node, use it instead 3174 if ($(data.element).is('option')) { 3175 data.element.selected = true; 3176 3177 this.$element.trigger('change'); 3178 3179 return; 3180 } 3181 3182 if (this.$element.prop('multiple')) { 3183 this.current(function (currentData) { 3184 var val = []; 3185 3186 data = [data]; 3187 data.push.apply(data, currentData); 3188 3189 for (var d = 0; d < data.length; d++) { 3190 var id = data[d].id; 3191 3192 if ($.inArray(id, val) === -1) { 3193 val.push(id); 3194 } 3195 } 3196 3197 self.$element.val(val); 3198 self.$element.trigger('change'); 3199 }); 3200 } else { 3201 var val = data.id; 3202 3203 this.$element.val(val); 3204 this.$element.trigger('change'); 3205 } 3206 }; 3207 3208 SelectAdapter.prototype.unselect = function (data) { 3209 var self = this; 3210 3211 if (!this.$element.prop('multiple')) { 3212 return; 3213 } 3214 3215 data.selected = false; 3216 3217 if ($(data.element).is('option')) { 3218 data.element.selected = false; 3219 3220 this.$element.trigger('change'); 3221 3222 return; 3223 } 3224 3225 this.current(function (currentData) { 3226 var val = []; 3227 3228 for (var d = 0; d < currentData.length; d++) { 3229 var id = currentData[d].id; 3230 3231 if (id !== data.id && $.inArray(id, val) === -1) { 3232 val.push(id); 3233 } 3234 } 3235 3236 self.$element.val(val); 3237 3238 self.$element.trigger('change'); 3239 }); 3240 }; 3241 3242 SelectAdapter.prototype.bind = function (container, $container) { 3243 var self = this; 3244 3245 this.container = container; 3246 3247 container.on('select', function (params) { 3248 self.select(params.data); 3249 }); 3250 3251 container.on('unselect', function (params) { 3252 self.unselect(params.data); 3253 }); 3254 }; 3255 3256 SelectAdapter.prototype.destroy = function () { 3257 // Remove anything added to child elements 3258 this.$element.find('*').each(function () { 3259 // Remove any custom data set by Select2 3260 Utils.RemoveData(this); 3261 }); 3262 }; 3263 3264 SelectAdapter.prototype.query = function (params, callback) { 3265 var data = []; 3266 var self = this; 3267 3268 var $options = this.$element.children(); 3269 3270 $options.each(function () { 3271 var $option = $(this); 3272 3273 if (!$option.is('option') && !$option.is('optgroup')) { 3274 return; 3275 } 3276 3277 var option = self.item($option); 3278 3279 var matches = self.matches(params, option); 3280 3281 if (matches !== null) { 3282 data.push(matches); 3283 } 3284 }); 3285 3286 callback({ 3287 results: data 3288 }); 3289 }; 3290 3291 SelectAdapter.prototype.addOptions = function ($options) { 3292 Utils.appendMany(this.$element, $options); 3293 }; 3294 3295 SelectAdapter.prototype.option = function (data) { 3296 var option; 3297 3298 if (data.children) { 3299 option = document.createElement('optgroup'); 3300 option.label = data.text; 3301 } else { 3302 option = document.createElement('option'); 3303 3304 if (option.textContent !== undefined) { 3305 option.textContent = data.text; 3306 } else { 3307 option.innerText = data.text; 3308 } 3309 } 3310 3311 if (data.id !== undefined) { 3312 option.value = data.id; 3313 } 3314 3315 if (data.disabled) { 3316 option.disabled = true; 3317 } 3318 3319 if (data.selected) { 3320 option.selected = true; 3321 } 3322 3323 if (data.title) { 3324 option.title = data.title; 3325 } 3326 3327 var $option = $(option); 3328 3329 var normalizedData = this._normalizeItem(data); 3330 normalizedData.element = option; 3331 3332 // Override the option's data with the combined data 3333 Utils.StoreData(option, 'data', normalizedData); 3334 3335 return $option; 3336 }; 3337 3338 SelectAdapter.prototype.item = function ($option) { 3339 var data = {}; 3340 3341 data = Utils.GetData($option[0], 'data'); 3342 3343 if (data != null) { 3344 return data; 3345 } 3346 3347 if ($option.is('option')) { 3348 data = { 3349 id: $option.val(), 3350 text: $option.text(), 3351 disabled: $option.prop('disabled'), 3352 selected: $option.prop('selected'), 3353 title: $option.prop('title') 3354 }; 3355 } else if ($option.is('optgroup')) { 3356 data = { 3357 text: $option.prop('label'), 3358 children: [], 3359 title: $option.prop('title') 3360 }; 3361 3362 var $children = $option.children('option'); 3363 var children = []; 3364 3365 for (var c = 0; c < $children.length; c++) { 3366 var $child = $($children[c]); 3367 3368 var child = this.item($child); 3369 3370 children.push(child); 3371 } 3372 3373 data.children = children; 3374 } 3375 3376 data = this._normalizeItem(data); 3377 data.element = $option[0]; 3378 3379 Utils.StoreData($option[0], 'data', data); 3380 3381 return data; 3382 }; 3383 3384 SelectAdapter.prototype._normalizeItem = function (item) { 3385 if (item !== Object(item)) { 3386 item = { 3387 id: item, 3388 text: item 3389 }; 3390 } 3391 3392 item = $.extend({}, { 3393 text: '' 3394 }, item); 3395 3396 var defaults = { 3397 selected: false, 3398 disabled: false 3399 }; 3400 3401 if (item.id != null) { 3402 item.id = item.id.toString(); 3403 } 3404 3405 if (item.text != null) { 3406 item.text = item.text.toString(); 3407 } 3408 3409 if (item._resultId == null && item.id && this.container != null) { 3410 item._resultId = this.generateResultId(this.container, item); 3411 } 3412 3413 return $.extend({}, defaults, item); 3414 }; 3415 3416 SelectAdapter.prototype.matches = function (params, data) { 3417 var matcher = this.options.get('matcher'); 3418 3419 return matcher(params, data); 3420 }; 3421 3422 return SelectAdapter; 3423}); 3424 3425S2.define('select2/data/array',[ 3426 './select', 3427 '../utils', 3428 'jquery' 3429], function (SelectAdapter, Utils, $) { 3430 function ArrayAdapter ($element, options) { 3431 var data = options.get('data') || []; 3432 3433 ArrayAdapter.__super__.constructor.call(this, $element, options); 3434 3435 this.addOptions(this.convertToOptions(data)); 3436 } 3437 3438 Utils.Extend(ArrayAdapter, SelectAdapter); 3439 3440 ArrayAdapter.prototype.select = function (data) { 3441 var $option = this.$element.find('option').filter(function (i, elm) { 3442 return elm.value == data.id.toString(); 3443 }); 3444 3445 if ($option.length === 0) { 3446 $option = this.option(data); 3447 3448 this.addOptions($option); 3449 } 3450 3451 ArrayAdapter.__super__.select.call(this, data); 3452 }; 3453 3454 ArrayAdapter.prototype.convertToOptions = function (data) { 3455 var self = this; 3456 3457 var $existing = this.$element.find('option'); 3458 var existingIds = $existing.map(function () { 3459 return self.item($(this)).id; 3460 }).get(); 3461 3462 var $options = []; 3463 3464 // Filter out all items except for the one passed in the argument 3465 function onlyItem (item) { 3466 return function () { 3467 return $(this).val() == item.id; 3468 }; 3469 } 3470 3471 for (var d = 0; d < data.length; d++) { 3472 var item = this._normalizeItem(data[d]); 3473 3474 // Skip items which were pre-loaded, only merge the data 3475 if ($.inArray(item.id, existingIds) >= 0) { 3476 var $existingOption = $existing.filter(onlyItem(item)); 3477 3478 var existingData = this.item($existingOption); 3479 var newData = $.extend(true, {}, item, existingData); 3480 3481 var $newOption = this.option(newData); 3482 3483 $existingOption.replaceWith($newOption); 3484 3485 continue; 3486 } 3487 3488 var $option = this.option(item); 3489 3490 if (item.children) { 3491 var $children = this.convertToOptions(item.children); 3492 3493 Utils.appendMany($option, $children); 3494 } 3495 3496 $options.push($option); 3497 } 3498 3499 return $options; 3500 }; 3501 3502 return ArrayAdapter; 3503}); 3504 3505S2.define('select2/data/ajax',[ 3506 './array', 3507 '../utils', 3508 'jquery' 3509], function (ArrayAdapter, Utils, $) { 3510 function AjaxAdapter ($element, options) { 3511 this.ajaxOptions = this._applyDefaults(options.get('ajax')); 3512 3513 if (this.ajaxOptions.processResults != null) { 3514 this.processResults = this.ajaxOptions.processResults; 3515 } 3516 3517 AjaxAdapter.__super__.constructor.call(this, $element, options); 3518 } 3519 3520 Utils.Extend(AjaxAdapter, ArrayAdapter); 3521 3522 AjaxAdapter.prototype._applyDefaults = function (options) { 3523 var defaults = { 3524 data: function (params) { 3525 return $.extend({}, params, { 3526 q: params.term 3527 }); 3528 }, 3529 transport: function (params, success, failure) { 3530 var $request = $.ajax(params); 3531 3532 $request.then(success); 3533 $request.fail(failure); 3534 3535 return $request; 3536 } 3537 }; 3538 3539 return $.extend({}, defaults, options, true); 3540 }; 3541 3542 AjaxAdapter.prototype.processResults = function (results) { 3543 return results; 3544 }; 3545 3546 AjaxAdapter.prototype.query = function (params, callback) { 3547 var matches = []; 3548 var self = this; 3549 3550 if (this._request != null) { 3551 // JSONP requests cannot always be aborted 3552 if ($.isFunction(this._request.abort)) { 3553 this._request.abort(); 3554 } 3555 3556 this._request = null; 3557 } 3558 3559 var options = $.extend({ 3560 type: 'GET' 3561 }, this.ajaxOptions); 3562 3563 if (typeof options.url === 'function') { 3564 options.url = options.url.call(this.$element, params); 3565 } 3566 3567 if (typeof options.data === 'function') { 3568 options.data = options.data.call(this.$element, params); 3569 } 3570 3571 function request () { 3572 var $request = options.transport(options, function (data) { 3573 var results = self.processResults(data, params); 3574 3575 if (self.options.get('debug') && window.console && console.error) { 3576 // Check to make sure that the response included a `results` key. 3577 if (!results || !results.results || !$.isArray(results.results)) { 3578 console.error( 3579 'Select2: The AJAX results did not return an array in the ' + 3580 '`results` key of the response.' 3581 ); 3582 } 3583 } 3584 3585 callback(results); 3586 }, function () { 3587 // Attempt to detect if a request was aborted 3588 // Only works if the transport exposes a status property 3589 if ('status' in $request && 3590 ($request.status === 0 || $request.status === '0')) { 3591 return; 3592 } 3593 3594 self.trigger('results:message', { 3595 message: 'errorLoading' 3596 }); 3597 }); 3598 3599 self._request = $request; 3600 } 3601 3602 if (this.ajaxOptions.delay && params.term != null) { 3603 if (this._queryTimeout) { 3604 window.clearTimeout(this._queryTimeout); 3605 } 3606 3607 this._queryTimeout = window.setTimeout(request, this.ajaxOptions.delay); 3608 } else { 3609 request(); 3610 } 3611 }; 3612 3613 return AjaxAdapter; 3614}); 3615 3616S2.define('select2/data/tags',[ 3617 'jquery' 3618], function ($) { 3619 function Tags (decorated, $element, options) { 3620 var tags = options.get('tags'); 3621 3622 var createTag = options.get('createTag'); 3623 3624 if (createTag !== undefined) { 3625 this.createTag = createTag; 3626 } 3627 3628 var insertTag = options.get('insertTag'); 3629 3630 if (insertTag !== undefined) { 3631 this.insertTag = insertTag; 3632 } 3633 3634 decorated.call(this, $element, options); 3635 3636 if ($.isArray(tags)) { 3637 for (var t = 0; t < tags.length; t++) { 3638 var tag = tags[t]; 3639 var item = this._normalizeItem(tag); 3640 3641 var $option = this.option(item); 3642 3643 this.$element.append($option); 3644 } 3645 } 3646 } 3647 3648 Tags.prototype.query = function (decorated, params, callback) { 3649 var self = this; 3650 3651 this._removeOldTags(); 3652 3653 if (params.term == null || params.page != null) { 3654 decorated.call(this, params, callback); 3655 return; 3656 } 3657 3658 function wrapper (obj, child) { 3659 var data = obj.results; 3660 3661 for (var i = 0; i < data.length; i++) { 3662 var option = data[i]; 3663 3664 var checkChildren = ( 3665 option.children != null && 3666 !wrapper({ 3667 results: option.children 3668 }, true) 3669 ); 3670 3671 var optionText = (option.text || '').toUpperCase(); 3672 var paramsTerm = (params.term || '').toUpperCase(); 3673 3674 var checkText = optionText === paramsTerm; 3675 3676 if (checkText || checkChildren) { 3677 if (child) { 3678 return false; 3679 } 3680 3681 obj.data = data; 3682 callback(obj); 3683 3684 return; 3685 } 3686 } 3687 3688 if (child) { 3689 return true; 3690 } 3691 3692 var tag = self.createTag(params); 3693 3694 if (tag != null) { 3695 var $option = self.option(tag); 3696 $option.attr('data-select2-tag', true); 3697 3698 self.addOptions([$option]); 3699 3700 self.insertTag(data, tag); 3701 } 3702 3703 obj.results = data; 3704 3705 callback(obj); 3706 } 3707 3708 decorated.call(this, params, wrapper); 3709 }; 3710 3711 Tags.prototype.createTag = function (decorated, params) { 3712 var term = $.trim(params.term); 3713 3714 if (term === '') { 3715 return null; 3716 } 3717 3718 return { 3719 id: term, 3720 text: term 3721 }; 3722 }; 3723 3724 Tags.prototype.insertTag = function (_, data, tag) { 3725 data.unshift(tag); 3726 }; 3727 3728 Tags.prototype._removeOldTags = function (_) { 3729 var tag = this._lastTag; 3730 3731 var $options = this.$element.find('option[data-select2-tag]'); 3732 3733 $options.each(function () { 3734 if (this.selected) { 3735 return; 3736 } 3737 3738 $(this).remove(); 3739 }); 3740 }; 3741 3742 return Tags; 3743}); 3744 3745S2.define('select2/data/tokenizer',[ 3746 'jquery' 3747], function ($) { 3748 function Tokenizer (decorated, $element, options) { 3749 var tokenizer = options.get('tokenizer'); 3750 3751 if (tokenizer !== undefined) { 3752 this.tokenizer = tokenizer; 3753 } 3754 3755 decorated.call(this, $element, options); 3756 } 3757 3758 Tokenizer.prototype.bind = function (decorated, container, $container) { 3759 decorated.call(this, container, $container); 3760 3761 this.$search = container.dropdown.$search || container.selection.$search || 3762 $container.find('.select2-search__field'); 3763 }; 3764 3765 Tokenizer.prototype.query = function (decorated, params, callback) { 3766 var self = this; 3767 3768 function createAndSelect (data) { 3769 // Normalize the data object so we can use it for checks 3770 var item = self._normalizeItem(data); 3771 3772 // Check if the data object already exists as a tag 3773 // Select it if it doesn't 3774 var $existingOptions = self.$element.find('option').filter(function () { 3775 return $(this).val() === item.id; 3776 }); 3777 3778 // If an existing option wasn't found for it, create the option 3779 if (!$existingOptions.length) { 3780 var $option = self.option(item); 3781 $option.attr('data-select2-tag', true); 3782 3783 self._removeOldTags(); 3784 self.addOptions([$option]); 3785 } 3786 3787 // Select the item, now that we know there is an option for it 3788 select(item); 3789 } 3790 3791 function select (data) { 3792 self.trigger('select', { 3793 data: data 3794 }); 3795 } 3796 3797 params.term = params.term || ''; 3798 3799 var tokenData = this.tokenizer(params, this.options, createAndSelect); 3800 3801 if (tokenData.term !== params.term) { 3802 // Replace the search term if we have the search box 3803 if (this.$search.length) { 3804 this.$search.val(tokenData.term); 3805 this.$search.trigger('focus'); 3806 } 3807 3808 params.term = tokenData.term; 3809 } 3810 3811 decorated.call(this, params, callback); 3812 }; 3813 3814 Tokenizer.prototype.tokenizer = function (_, params, options, callback) { 3815 var separators = options.get('tokenSeparators') || []; 3816 var term = params.term; 3817 var i = 0; 3818 3819 var createTag = this.createTag || function (params) { 3820 return { 3821 id: params.term, 3822 text: params.term 3823 }; 3824 }; 3825 3826 while (i < term.length) { 3827 var termChar = term[i]; 3828 3829 if ($.inArray(termChar, separators) === -1) { 3830 i++; 3831 3832 continue; 3833 } 3834 3835 var part = term.substr(0, i); 3836 var partParams = $.extend({}, params, { 3837 term: part 3838 }); 3839 3840 var data = createTag(partParams); 3841 3842 if (data == null) { 3843 i++; 3844 continue; 3845 } 3846 3847 callback(data); 3848 3849 // Reset the term to not include the tokenized portion 3850 term = term.substr(i + 1) || ''; 3851 i = 0; 3852 } 3853 3854 return { 3855 term: term 3856 }; 3857 }; 3858 3859 return Tokenizer; 3860}); 3861 3862S2.define('select2/data/minimumInputLength',[ 3863 3864], function () { 3865 function MinimumInputLength (decorated, $e, options) { 3866 this.minimumInputLength = options.get('minimumInputLength'); 3867 3868 decorated.call(this, $e, options); 3869 } 3870 3871 MinimumInputLength.prototype.query = function (decorated, params, callback) { 3872 params.term = params.term || ''; 3873 3874 if (params.term.length < this.minimumInputLength) { 3875 this.trigger('results:message', { 3876 message: 'inputTooShort', 3877 args: { 3878 minimum: this.minimumInputLength, 3879 input: params.term, 3880 params: params 3881 } 3882 }); 3883 3884 return; 3885 } 3886 3887 decorated.call(this, params, callback); 3888 }; 3889 3890 return MinimumInputLength; 3891}); 3892 3893S2.define('select2/data/maximumInputLength',[ 3894 3895], function () { 3896 function MaximumInputLength (decorated, $e, options) { 3897 this.maximumInputLength = options.get('maximumInputLength'); 3898 3899 decorated.call(this, $e, options); 3900 } 3901 3902 MaximumInputLength.prototype.query = function (decorated, params, callback) { 3903 params.term = params.term || ''; 3904 3905 if (this.maximumInputLength > 0 && 3906 params.term.length > this.maximumInputLength) { 3907 this.trigger('results:message', { 3908 message: 'inputTooLong', 3909 args: { 3910 maximum: this.maximumInputLength, 3911 input: params.term, 3912 params: params 3913 } 3914 }); 3915 3916 return; 3917 } 3918 3919 decorated.call(this, params, callback); 3920 }; 3921 3922 return MaximumInputLength; 3923}); 3924 3925S2.define('select2/data/maximumSelectionLength',[ 3926 3927], function (){ 3928 function MaximumSelectionLength (decorated, $e, options) { 3929 this.maximumSelectionLength = options.get('maximumSelectionLength'); 3930 3931 decorated.call(this, $e, options); 3932 } 3933 3934 MaximumSelectionLength.prototype.query = 3935 function (decorated, params, callback) { 3936 var self = this; 3937 3938 this.current(function (currentData) { 3939 var count = currentData != null ? currentData.length : 0; 3940 if (self.maximumSelectionLength > 0 && 3941 count >= self.maximumSelectionLength) { 3942 self.trigger('results:message', { 3943 message: 'maximumSelected', 3944 args: { 3945 maximum: self.maximumSelectionLength 3946 } 3947 }); 3948 return; 3949 } 3950 decorated.call(self, params, callback); 3951 }); 3952 }; 3953 3954 return MaximumSelectionLength; 3955}); 3956 3957S2.define('select2/dropdown',[ 3958 'jquery', 3959 './utils' 3960], function ($, Utils) { 3961 function Dropdown ($element, options) { 3962 this.$element = $element; 3963 this.options = options; 3964 3965 Dropdown.__super__.constructor.call(this); 3966 } 3967 3968 Utils.Extend(Dropdown, Utils.Observable); 3969 3970 Dropdown.prototype.render = function () { 3971 var $dropdown = $( 3972 '<span class="select2-dropdown">' + 3973 '<span class="select2-results"></span>' + 3974 '</span>' 3975 ); 3976 3977 $dropdown.attr('dir', this.options.get('dir')); 3978 3979 this.$dropdown = $dropdown; 3980 3981 return $dropdown; 3982 }; 3983 3984 Dropdown.prototype.bind = function () { 3985 // Should be implemented in subclasses 3986 }; 3987 3988 Dropdown.prototype.position = function ($dropdown, $container) { 3989 // Should be implemented in subclasses 3990 }; 3991 3992 Dropdown.prototype.destroy = function () { 3993 // Remove the dropdown from the DOM 3994 this.$dropdown.remove(); 3995 }; 3996 3997 return Dropdown; 3998}); 3999 4000S2.define('select2/dropdown/search',[ 4001 'jquery', 4002 '../utils' 4003], function ($, Utils) { 4004 function Search () { } 4005 4006 Search.prototype.render = function (decorated) { 4007 var $rendered = decorated.call(this); 4008 4009 var $search = $( 4010 '<span class="select2-search select2-search--dropdown">' + 4011 '<input class="select2-search__field" type="search" tabindex="-1"' + 4012 ' autocomplete="off" autocorrect="off" autocapitalize="none"' + 4013 ' spellcheck="false" role="textbox" />' + 4014 '</span>' 4015 ); 4016 4017 this.$searchContainer = $search; 4018 this.$search = $search.find('input'); 4019 4020 $rendered.prepend($search); 4021 4022 return $rendered; 4023 }; 4024 4025 Search.prototype.bind = function (decorated, container, $container) { 4026 var self = this; 4027 4028 decorated.call(this, container, $container); 4029 4030 this.$search.on('keydown', function (evt) { 4031 self.trigger('keypress', evt); 4032 4033 self._keyUpPrevented = evt.isDefaultPrevented(); 4034 }); 4035 4036 // Workaround for browsers which do not support the `input` event 4037 // This will prevent double-triggering of events for browsers which support 4038 // both the `keyup` and `input` events. 4039 this.$search.on('input', function (evt) { 4040 // Unbind the duplicated `keyup` event 4041 $(this).off('keyup'); 4042 }); 4043 4044 this.$search.on('keyup input', function (evt) { 4045 self.handleSearch(evt); 4046 }); 4047 4048 container.on('open', function () { 4049 self.$search.attr('tabindex', 0); 4050 4051 self.$search.trigger('focus'); 4052 4053 window.setTimeout(function () { 4054 self.$search.trigger('focus'); 4055 }, 0); 4056 }); 4057 4058 container.on('close', function () { 4059 self.$search.attr('tabindex', -1); 4060 4061 self.$search.val(''); 4062 self.$search.trigger('blur'); 4063 }); 4064 4065 container.on('focus', function () { 4066 if (!container.isOpen()) { 4067 self.$search.trigger('focus'); 4068 } 4069 }); 4070 4071 container.on('results:all', function (params) { 4072 if (params.query.term == null || params.query.term === '') { 4073 var showSearch = self.showSearch(params); 4074 4075 if (showSearch) { 4076 self.$searchContainer.removeClass('select2-search--hide'); 4077 } else { 4078 self.$searchContainer.addClass('select2-search--hide'); 4079 } 4080 } 4081 }); 4082 }; 4083 4084 Search.prototype.handleSearch = function (evt) { 4085 if (!this._keyUpPrevented) { 4086 var input = this.$search.val(); 4087 4088 this.trigger('query', { 4089 term: input 4090 }); 4091 } 4092 4093 this._keyUpPrevented = false; 4094 }; 4095 4096 Search.prototype.showSearch = function (_, params) { 4097 return true; 4098 }; 4099 4100 return Search; 4101}); 4102 4103S2.define('select2/dropdown/hidePlaceholder',[ 4104 4105], function () { 4106 function HidePlaceholder (decorated, $element, options, dataAdapter) { 4107 this.placeholder = this.normalizePlaceholder(options.get('placeholder')); 4108 4109 decorated.call(this, $element, options, dataAdapter); 4110 } 4111 4112 HidePlaceholder.prototype.append = function (decorated, data) { 4113 data.results = this.removePlaceholder(data.results); 4114 4115 decorated.call(this, data); 4116 }; 4117 4118 HidePlaceholder.prototype.normalizePlaceholder = function (_, placeholder) { 4119 if (typeof placeholder === 'string') { 4120 placeholder = { 4121 id: '', 4122 text: placeholder 4123 }; 4124 } 4125 4126 return placeholder; 4127 }; 4128 4129 HidePlaceholder.prototype.removePlaceholder = function (_, data) { 4130 var modifiedData = data.slice(0); 4131 4132 for (var d = data.length - 1; d >= 0; d--) { 4133 var item = data[d]; 4134 4135 if (this.placeholder.id === item.id) { 4136 modifiedData.splice(d, 1); 4137 } 4138 } 4139 4140 return modifiedData; 4141 }; 4142 4143 return HidePlaceholder; 4144}); 4145 4146S2.define('select2/dropdown/infiniteScroll',[ 4147 'jquery' 4148], function ($) { 4149 function InfiniteScroll (decorated, $element, options, dataAdapter) { 4150 this.lastParams = {}; 4151 4152 decorated.call(this, $element, options, dataAdapter); 4153 4154 this.$loadingMore = this.createLoadingMore(); 4155 this.loading = false; 4156 } 4157 4158 InfiniteScroll.prototype.append = function (decorated, data) { 4159 this.$loadingMore.remove(); 4160 this.loading = false; 4161 4162 decorated.call(this, data); 4163 4164 if (this.showLoadingMore(data)) { 4165 this.$results.append(this.$loadingMore); 4166 this.loadMoreIfNeeded(); 4167 } 4168 }; 4169 4170 InfiniteScroll.prototype.bind = function (decorated, container, $container) { 4171 var self = this; 4172 4173 decorated.call(this, container, $container); 4174 4175 container.on('query', function (params) { 4176 self.lastParams = params; 4177 self.loading = true; 4178 }); 4179 4180 container.on('query:append', function (params) { 4181 self.lastParams = params; 4182 self.loading = true; 4183 }); 4184 4185 this.$results.on('scroll', this.loadMoreIfNeeded.bind(this)); 4186 }; 4187 4188 InfiniteScroll.prototype.loadMoreIfNeeded = function () { 4189 var isLoadMoreVisible = $.contains( 4190 document.documentElement, 4191 this.$loadingMore[0] 4192 ); 4193 4194 if (this.loading || !isLoadMoreVisible) { 4195 return; 4196 } 4197 4198 var currentOffset = this.$results.offset().top + 4199 this.$results.outerHeight(false); 4200 var loadingMoreOffset = this.$loadingMore.offset().top + 4201 this.$loadingMore.outerHeight(false); 4202 4203 if (currentOffset + 50 >= loadingMoreOffset) { 4204 this.loadMore(); 4205 } 4206 }; 4207 4208 InfiniteScroll.prototype.loadMore = function () { 4209 this.loading = true; 4210 4211 var params = $.extend({}, {page: 1}, this.lastParams); 4212 4213 params.page++; 4214 4215 this.trigger('query:append', params); 4216 }; 4217 4218 InfiniteScroll.prototype.showLoadingMore = function (_, data) { 4219 return data.pagination && data.pagination.more; 4220 }; 4221 4222 InfiniteScroll.prototype.createLoadingMore = function () { 4223 var $option = $( 4224 '<li ' + 4225 'class="select2-results__option select2-results__option--load-more"' + 4226 'role="treeitem" aria-disabled="true"></li>' 4227 ); 4228 4229 var message = this.options.get('translations').get('loadingMore'); 4230 4231 $option.html(message(this.lastParams)); 4232 4233 return $option; 4234 }; 4235 4236 return InfiniteScroll; 4237}); 4238 4239S2.define('select2/dropdown/attachBody',[ 4240 'jquery', 4241 '../utils' 4242], function ($, Utils) { 4243 function AttachBody (decorated, $element, options) { 4244 this.$dropdownParent = options.get('dropdownParent') || $(document.body); 4245 4246 decorated.call(this, $element, options); 4247 } 4248 4249 AttachBody.prototype.bind = function (decorated, container, $container) { 4250 var self = this; 4251 4252 var setupResultsEvents = false; 4253 4254 decorated.call(this, container, $container); 4255 4256 container.on('open', function () { 4257 self._showDropdown(); 4258 self._attachPositioningHandler(container); 4259 4260 if (!setupResultsEvents) { 4261 setupResultsEvents = true; 4262 4263 container.on('results:all', function () { 4264 self._positionDropdown(); 4265 self._resizeDropdown(); 4266 }); 4267 4268 container.on('results:append', function () { 4269 self._positionDropdown(); 4270 self._resizeDropdown(); 4271 }); 4272 } 4273 }); 4274 4275 container.on('close', function () { 4276 self._hideDropdown(); 4277 self._detachPositioningHandler(container); 4278 }); 4279 4280 this.$dropdownContainer.on('mousedown', function (evt) { 4281 evt.stopPropagation(); 4282 }); 4283 }; 4284 4285 AttachBody.prototype.destroy = function (decorated) { 4286 decorated.call(this); 4287 4288 this.$dropdownContainer.remove(); 4289 }; 4290 4291 AttachBody.prototype.position = function (decorated, $dropdown, $container) { 4292 // Clone all of the container classes 4293 $dropdown.attr('class', $container.attr('class')); 4294 4295 $dropdown.removeClass('select2'); 4296 $dropdown.addClass('select2-container--open'); 4297 4298 $dropdown.css({ 4299 position: 'absolute', 4300 top: -999999 4301 }); 4302 4303 this.$container = $container; 4304 }; 4305 4306 AttachBody.prototype.render = function (decorated) { 4307 var $container = $('<span></span>'); 4308 4309 var $dropdown = decorated.call(this); 4310 $container.append($dropdown); 4311 4312 this.$dropdownContainer = $container; 4313 4314 return $container; 4315 }; 4316 4317 AttachBody.prototype._hideDropdown = function (decorated) { 4318 this.$dropdownContainer.detach(); 4319 }; 4320 4321 AttachBody.prototype._attachPositioningHandler = 4322 function (decorated, container) { 4323 var self = this; 4324 4325 var scrollEvent = 'scroll.select2.' + container.id; 4326 var resizeEvent = 'resize.select2.' + container.id; 4327 var orientationEvent = 'orientationchange.select2.' + container.id; 4328 4329 var $watchers = this.$container.parents().filter(Utils.hasScroll); 4330 $watchers.each(function () { 4331 Utils.StoreData(this, 'select2-scroll-position', { 4332 x: $(this).scrollLeft(), 4333 y: $(this).scrollTop() 4334 }); 4335 }); 4336 4337 $watchers.on(scrollEvent, function (ev) { 4338 var position = Utils.GetData(this, 'select2-scroll-position'); 4339 $(this).scrollTop(position.y); 4340 }); 4341 4342 $(window).on(scrollEvent + ' ' + resizeEvent + ' ' + orientationEvent, 4343 function (e) { 4344 self._positionDropdown(); 4345 self._resizeDropdown(); 4346 }); 4347 }; 4348 4349 AttachBody.prototype._detachPositioningHandler = 4350 function (decorated, container) { 4351 var scrollEvent = 'scroll.select2.' + container.id; 4352 var resizeEvent = 'resize.select2.' + container.id; 4353 var orientationEvent = 'orientationchange.select2.' + container.id; 4354 4355 var $watchers = this.$container.parents().filter(Utils.hasScroll); 4356 $watchers.off(scrollEvent); 4357 4358 $(window).off(scrollEvent + ' ' + resizeEvent + ' ' + orientationEvent); 4359 }; 4360 4361 AttachBody.prototype._positionDropdown = function () { 4362 var $window = $(window); 4363 4364 var isCurrentlyAbove = this.$dropdown.hasClass('select2-dropdown--above'); 4365 var isCurrentlyBelow = this.$dropdown.hasClass('select2-dropdown--below'); 4366 4367 var newDirection = null; 4368 4369 var offset = this.$container.offset(); 4370 4371 offset.bottom = offset.top + this.$container.outerHeight(false); 4372 4373 var container = { 4374 height: this.$container.outerHeight(false) 4375 }; 4376 4377 container.top = offset.top; 4378 container.bottom = offset.top + container.height; 4379 4380 var dropdown = { 4381 height: this.$dropdown.outerHeight(false) 4382 }; 4383 4384 var viewport = { 4385 top: $window.scrollTop(), 4386 bottom: $window.scrollTop() + $window.height() 4387 }; 4388 4389 var enoughRoomAbove = viewport.top < (offset.top - dropdown.height); 4390 var enoughRoomBelow = viewport.bottom > (offset.bottom + dropdown.height); 4391 4392 var css = { 4393 left: offset.left, 4394 top: container.bottom 4395 }; 4396 4397 // Determine what the parent element is to use for calculating the offset 4398 var $offsetParent = this.$dropdownParent; 4399 4400 // For statically positioned elements, we need to get the element 4401 // that is determining the offset 4402 if ($offsetParent.css('position') === 'static') { 4403 $offsetParent = $offsetParent.offsetParent(); 4404 } 4405 4406 var parentOffset = $offsetParent.offset(); 4407 4408 css.top -= parentOffset.top; 4409 css.left -= parentOffset.left; 4410 4411 if (!isCurrentlyAbove && !isCurrentlyBelow) { 4412 newDirection = 'below'; 4413 } 4414 4415 if (!enoughRoomBelow && enoughRoomAbove && !isCurrentlyAbove) { 4416 newDirection = 'above'; 4417 } else if (!enoughRoomAbove && enoughRoomBelow && isCurrentlyAbove) { 4418 newDirection = 'below'; 4419 } 4420 4421 if (newDirection == 'above' || 4422 (isCurrentlyAbove && newDirection !== 'below')) { 4423 css.top = container.top - parentOffset.top - dropdown.height; 4424 } 4425 4426 if (newDirection != null) { 4427 this.$dropdown 4428 .removeClass('select2-dropdown--below select2-dropdown--above') 4429 .addClass('select2-dropdown--' + newDirection); 4430 this.$container 4431 .removeClass('select2-container--below select2-container--above') 4432 .addClass('select2-container--' + newDirection); 4433 } 4434 4435 this.$dropdownContainer.css(css); 4436 }; 4437 4438 AttachBody.prototype._resizeDropdown = function () { 4439 var css = { 4440 width: this.$container.outerWidth(false) + 'px' 4441 }; 4442 4443 if (this.options.get('dropdownAutoWidth')) { 4444 css.minWidth = css.width; 4445 css.position = 'relative'; 4446 css.width = 'auto'; 4447 } 4448 4449 this.$dropdown.css(css); 4450 }; 4451 4452 AttachBody.prototype._showDropdown = function (decorated) { 4453 this.$dropdownContainer.appendTo(this.$dropdownParent); 4454 4455 this._positionDropdown(); 4456 this._resizeDropdown(); 4457 }; 4458 4459 return AttachBody; 4460}); 4461 4462S2.define('select2/dropdown/minimumResultsForSearch',[ 4463 4464], function () { 4465 function countResults (data) { 4466 var count = 0; 4467 4468 for (var d = 0; d < data.length; d++) { 4469 var item = data[d]; 4470 4471 if (item.children) { 4472 count += countResults(item.children); 4473 } else { 4474 count++; 4475 } 4476 } 4477 4478 return count; 4479 } 4480 4481 function MinimumResultsForSearch (decorated, $element, options, dataAdapter) { 4482 this.minimumResultsForSearch = options.get('minimumResultsForSearch'); 4483 4484 if (this.minimumResultsForSearch < 0) { 4485 this.minimumResultsForSearch = Infinity; 4486 } 4487 4488 decorated.call(this, $element, options, dataAdapter); 4489 } 4490 4491 MinimumResultsForSearch.prototype.showSearch = function (decorated, params) { 4492 if (countResults(params.data.results) < this.minimumResultsForSearch) { 4493 return false;
vendor: 3,261 bytes, lines 4494-4632
4494 } 4495 4496 return decorated.call(this, params); 4497 }; 4498 4499 return MinimumResultsForSearch; 4500}); 4501 4502S2.define('select2/dropdown/selectOnClose',[ 4503 '../utils' 4504], function (Utils) { 4505 function SelectOnClose () { } 4506 4507 SelectOnClose.prototype.bind = function (decorated, container, $container) { 4508 var self = this; 4509 4510 decorated.call(this, container, $container); 4511 4512 container.on('close', function (params) { 4513 self._handleSelectOnClose(params); 4514 }); 4515 }; 4516 4517 SelectOnClose.prototype._handleSelectOnClose = function (_, params) { 4518 if (params && params.originalSelect2Event != null) { 4519 var event = params.originalSelect2Event; 4520 4521 // Don't select an item if the close event was triggered from a select or 4522 // unselect event 4523 if (event._type === 'select' || event._type === 'unselect') { 4524 return; 4525 } 4526 } 4527 4528 var $highlightedResults = this.getHighlightedResults(); 4529 4530 // Only select highlighted results 4531 if ($highlightedResults.length < 1) { 4532 return; 4533 } 4534 4535 var data = Utils.GetData($highlightedResults[0], 'data'); 4536 4537 // Don't re-select already selected resulte 4538 if ( 4539 (data.element != null && data.element.selected) || 4540 (data.element == null && data.selected) 4541 ) { 4542 return; 4543 } 4544 4545 this.trigger('select', { 4546 data: data 4547 }); 4548 }; 4549 4550 return SelectOnClose; 4551}); 4552 4553S2.define('select2/dropdown/closeOnSelect',[ 4554 4555], function () { 4556 function CloseOnSelect () { } 4557 4558 CloseOnSelect.prototype.bind = function (decorated, container, $container) { 4559 var self = this; 4560 4561 decorated.call(this, container, $container); 4562 4563 container.on('select', function (evt) { 4564 self._selectTriggered(evt); 4565 }); 4566 4567 container.on('unselect', function (evt) { 4568 self._selectTriggered(evt); 4569 }); 4570 }; 4571 4572 CloseOnSelect.prototype._selectTriggered = function (_, evt) { 4573 var originalEvent = evt.originalEvent; 4574 4575 // Don't close if the control key is being held 4576 if (originalEvent && (originalEvent.ctrlKey || originalEvent.metaKey)) { 4577 return; 4578 } 4579 4580 this.trigger('close', { 4581 originalEvent: originalEvent, 4582 originalSelect2Event: evt 4583 }); 4584 }; 4585 4586 return CloseOnSelect; 4587}); 4588 4589S2.define('select2/i18n/en',[],function () { 4590 // English 4591 return { 4592 errorLoading: function () { 4593 return 'The results could not be loaded.'; 4594 }, 4595 inputTooLong: function (args) { 4596 var overChars = args.input.length - args.maximum; 4597 4598 var message = 'Please delete ' + overChars + ' character'; 4599 4600 if (overChars != 1) { 4601 message += 's'; 4602 } 4603 4604 return message; 4605 }, 4606 inputTooShort: function (args) { 4607 var remainingChars = args.minimum - args.input.length; 4608 4609 var message = 'Please enter ' + remainingChars + ' or more characters'; 4610 4611 return message; 4612 }, 4613 loadingMore: function () { 4614 return 'Loading more results…'; 4615 }, 4616 maximumSelected: function (args) { 4617 var message = 'You can only select ' + args.maximum + ' item'; 4618 4619 if (args.maximum != 1) { 4620 message += 's'; 4621 } 4622 4623 return message; 4624 }, 4625 noResults: function () { 4626 return 'No results found'; 4627 }, 4628 searching: function () { 4629 return 'Searching…'; 4630 }, 4631 removeAllItems: function () { 4632 return 'Remove all items
vendor: 10,072 bytes, lines 4632-5004
4632'; 4633 } 4634 }; 4635}); 4636 4637S2.define('select2/defaults',[ 4638 'jquery', 4639 'require', 4640 4641 './results', 4642 4643 './selection/single', 4644 './selection/multiple', 4645 './selection/placeholder', 4646 './selection/allowClear', 4647 './selection/search', 4648 './selection/eventRelay', 4649 4650 './utils', 4651 './translation', 4652 './diacritics', 4653 4654 './data/select', 4655 './data/array', 4656 './data/ajax', 4657 './data/tags', 4658 './data/tokenizer', 4659 './data/minimumInputLength', 4660 './data/maximumInputLength', 4661 './data/maximumSelectionLength', 4662 4663 './dropdown', 4664 './dropdown/search', 4665 './dropdown/hidePlaceholder', 4666 './dropdown/infiniteScroll', 4667 './dropdown/attachBody', 4668 './dropdown/minimumResultsForSearch', 4669 './dropdown/selectOnClose', 4670 './dropdown/closeOnSelect', 4671 4672 './i18n/en' 4673], function ($, require, 4674 4675 ResultsList, 4676 4677 SingleSelection, MultipleSelection, Placeholder, AllowClear, 4678 SelectionSearch, EventRelay, 4679 4680 Utils, Translation, DIACRITICS, 4681 4682 SelectData, ArrayData, AjaxData, Tags, Tokenizer, 4683 MinimumInputLength, MaximumInputLength, MaximumSelectionLength, 4684 4685 Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll, 4686 AttachBody, MinimumResultsForSearch, SelectOnClose, CloseOnSelect, 4687 4688 EnglishTranslation) { 4689 function Defaults () { 4690 this.reset(); 4691 } 4692 4693 Defaults.prototype.apply = function (options) { 4694 options = $.extend(true, {}, this.defaults, options); 4695 4696 if (options.dataAdapter == null) { 4697 if (options.ajax != null) { 4698 options.dataAdapter = AjaxData; 4699 } else if (options.data != null) { 4700 options.dataAdapter = ArrayData; 4701 } else { 4702 options.dataAdapter = SelectData; 4703 } 4704 4705 if (options.minimumInputLength > 0) { 4706 options.dataAdapter = Utils.Decorate( 4707 options.dataAdapter, 4708 MinimumInputLength 4709 ); 4710 } 4711 4712 if (options.maximumInputLength > 0) { 4713 options.dataAdapter = Utils.Decorate( 4714 options.dataAdapter, 4715 MaximumInputLength 4716 ); 4717 } 4718 4719 if (options.maximumSelectionLength > 0) { 4720 options.dataAdapter = Utils.Decorate( 4721 options.dataAdapter, 4722 MaximumSelectionLength 4723 ); 4724 } 4725 4726 if (options.tags) { 4727 options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags); 4728 } 4729 4730 if (options.tokenSeparators != null || options.tokenizer != null) { 4731 options.dataAdapter = Utils.Decorate( 4732 options.dataAdapter, 4733 Tokenizer 4734 ); 4735 } 4736 4737 if (options.query != null) { 4738 var Query = require(options.amdBase + 'compat/query'); 4739 4740 options.dataAdapter = Utils.Decorate( 4741 options.dataAdapter, 4742 Query 4743 ); 4744 } 4745 4746 if (options.initSelection != null) { 4747 var InitSelection = require(options.amdBase + 'compat/initSelection'); 4748 4749 options.dataAdapter = Utils.Decorate( 4750 options.dataAdapter, 4751 InitSelection 4752 ); 4753 } 4754 } 4755 4756 if (options.resultsAdapter == null) { 4757 options.resultsAdapter = ResultsList; 4758 4759 if (options.ajax != null) { 4760 options.resultsAdapter = Utils.Decorate( 4761 options.resultsAdapter, 4762 InfiniteScroll 4763 ); 4764 } 4765 4766 if (options.placeholder != null) { 4767 options.resultsAdapter = Utils.Decorate( 4768 options.resultsAdapter, 4769 HidePlaceholder 4770 ); 4771 } 4772 4773 if (options.selectOnClose) { 4774 options.resultsAdapter = Utils.Decorate( 4775 options.resultsAdapter, 4776 SelectOnClose 4777 ); 4778 } 4779 } 4780 4781 if (options.dropdownAdapter == null) { 4782 if (options.multiple) { 4783 options.dropdownAdapter = Dropdown; 4784 } else { 4785 var SearchableDropdown = Utils.Decorate(Dropdown, DropdownSearch); 4786 4787 options.dropdownAdapter = SearchableDropdown; 4788 } 4789 4790 if (options.minimumResultsForSearch !== 0) { 4791 options.dropdownAdapter = Utils.Decorate( 4792 options.dropdownAdapter, 4793 MinimumResultsForSearch 4794 ); 4795 } 4796 4797 if (options.closeOnSelect) { 4798 options.dropdownAdapter = Utils.Decorate( 4799 options.dropdownAdapter, 4800 CloseOnSelect 4801 ); 4802 } 4803 4804 if ( 4805 options.dropdownCssClass != null || 4806 options.dropdownCss != null || 4807 options.adaptDropdownCssClass != null 4808 ) { 4809 var DropdownCSS = require(options.amdBase + 'compat/dropdownCss'); 4810 4811 options.dropdownAdapter = Utils.Decorate( 4812 options.dropdownAdapter, 4813 DropdownCSS 4814 ); 4815 } 4816 4817 options.dropdownAdapter = Utils.Decorate( 4818 options.dropdownAdapter, 4819 AttachBody 4820 ); 4821 } 4822 4823 if (options.selectionAdapter == null) { 4824 if (options.multiple) { 4825 options.selectionAdapter = MultipleSelection; 4826 } else { 4827 options.selectionAdapter = SingleSelection; 4828 } 4829 4830 // Add the placeholder mixin if a placeholder was specified 4831 if (options.placeholder != null) { 4832 options.selectionAdapter = Utils.Decorate( 4833 options.selectionAdapter, 4834 Placeholder 4835 ); 4836 } 4837 4838 if (options.allowClear) { 4839 options.selectionAdapter = Utils.Decorate( 4840 options.selectionAdapter, 4841 AllowClear 4842 ); 4843 } 4844 4845 if (options.multiple) { 4846 options.selectionAdapter = Utils.Decorate( 4847 options.selectionAdapter, 4848 SelectionSearch 4849 ); 4850 } 4851 4852 if ( 4853 options.containerCssClass != null || 4854 options.containerCss != null || 4855 options.adaptContainerCssClass != null 4856 ) { 4857 var ContainerCSS = require(options.amdBase + 'compat/containerCss'); 4858 4859 options.selectionAdapter = Utils.Decorate( 4860 options.selectionAdapter, 4861 ContainerCSS 4862 ); 4863 } 4864 4865 options.selectionAdapter = Utils.Decorate( 4866 options.selectionAdapter, 4867 EventRelay 4868 ); 4869 } 4870 4871 if (typeof options.language === 'string') { 4872 // Check if the language is specified with a region 4873 if (options.language.indexOf('-') > 0) { 4874 // Extract the region information if it is included 4875 var languageParts = options.language.split('-'); 4876 var baseLanguage = languageParts[0]; 4877 4878 options.language = [options.language, baseLanguage]; 4879 } else { 4880 options.language = [options.language]; 4881 } 4882 } 4883 4884 if ($.isArray(options.language)) { 4885 var languages = new Translation(); 4886 options.language.push('en'); 4887 4888 var languageNames = options.language; 4889 4890 for (var l = 0; l < languageNames.length; l++) { 4891 var name = languageNames[l]; 4892 var language = {}; 4893 4894 try { 4895 // Try to load it with the original name 4896 language = Translation.loadPath(name); 4897 } catch (e) { 4898 try { 4899 // If we couldn't load it, check if it wasn't the full path 4900 name = this.defaults.amdLanguageBase + name; 4901 language = Translation.loadPath(name); 4902 } catch (ex) { 4903 // The translation could not be loaded at all. Sometimes this is 4904 // because of a configuration problem, other times this can be 4905 // because of how Select2 helps load all possible translation files. 4906 if (options.debug && window.console && console.warn) { 4907 console.warn( 4908 'Select2: The language file for "' + name + '" could not be ' + 4909 'automatically loaded. A fallback will be used instead.' 4910 ); 4911 } 4912 4913 continue; 4914 } 4915 } 4916 4917 languages.extend(language); 4918 } 4919 4920 options.translations = languages; 4921 } else { 4922 var baseTranslation = Translation.loadPath( 4923 this.defaults.amdLanguageBase + 'en' 4924 ); 4925 var customTranslation = new Translation(options.language); 4926 4927 customTranslation.extend(baseTranslation); 4928 4929 options.translations = customTranslation; 4930 } 4931 4932 return options; 4933 }; 4934 4935 Defaults.prototype.reset = function () { 4936 function stripDiacritics (text) { 4937 // Used 'uni range + named function' from http://jsperf.com/diacritics/18 4938 function match(a) { 4939 return DIACRITICS[a] || a; 4940 } 4941 4942 return text.replace(/[^\u0000-\u007E]/g, match); 4943 } 4944 4945 function matcher (params, data) { 4946 // Always return the object if there is nothing to compare 4947 if ($.trim(params.term) === '') { 4948 return data; 4949 } 4950 4951 // Do a recursive check for options with children 4952 if (data.children && data.children.length > 0) { 4953 // Clone the data object if there are children 4954 // This is required as we modify the object to remove any non-matches 4955 var match = $.extend(true, {}, data); 4956 4957 // Check each child of the option 4958 for (var c = data.children.length - 1; c >= 0; c--) { 4959 var child = data.children[c]; 4960 4961 var matches = matcher(params, child); 4962 4963 // If there wasn't a match, remove the object in the array 4964 if (matches == null) { 4965 match.children.splice(c, 1); 4966 } 4967 } 4968 4969 // If any children matched, return the new object 4970 if (match.children.length > 0) { 4971 return match; 4972 } 4973 4974 // If there were no matching children, check just the plain object 4975 return matcher(params, match); 4976 } 4977 4978 var original = stripDiacritics(data.text).toUpperCase(); 4979 var term = stripDiacritics(params.term).toUpperCase(); 4980 4981 // Check if the text contains the term 4982 if (original.indexOf(term) > -1) { 4983 return data; 4984 } 4985 4986 // If it doesn't contain the term, don't return anything 4987 return null; 4988 } 4989 4990 this.defaults = { 4991 amdBase: './', 4992 amdLanguageBase: './i18n/', 4993 closeOnSelect: true, 4994 debug: false, 4995 dropdownAutoWidth: false, 4996 escapeMarkup: Utils.escapeMarkup, 4997 language: EnglishTranslation, 4998 matcher: matcher, 4999 minimumInputLength: 0, 5000 maximumInputLength: 0, 5001 maximumSelectionLength: 0, 5002 minimumResultsForSearch: 0, 5003 selectOnClose: false, 5004 s
vendor: 20,708 bytes, lines 5004-5799
5004crollAfterSelect: false, 5005 sorter: function (data) { 5006 return data; 5007 }, 5008 templateResult: function (result) { 5009 return result.text; 5010 }, 5011 templateSelection: function (selection) { 5012 return selection.text; 5013 }, 5014 theme: 'default', 5015 width: 'resolve' 5016 }; 5017 }; 5018 5019 Defaults.prototype.set = function (key, value) { 5020 var camelKey = $.camelCase(key); 5021 5022 var data = {}; 5023 data[camelKey] = value; 5024 5025 var convertedData = Utils._convertData(data); 5026 5027 $.extend(true, this.defaults, convertedData); 5028 }; 5029 5030 var defaults = new Defaults(); 5031 5032 return defaults; 5033}); 5034 5035S2.define('select2/options',[ 5036 'require', 5037 'jquery', 5038 './defaults', 5039 './utils' 5040], function (require, $, Defaults, Utils) { 5041 function Options (options, $element) { 5042 this.options = options; 5043 5044 if ($element != null) { 5045 this.fromElement($element); 5046 } 5047 5048 this.options = Defaults.apply(this.options); 5049 5050 if ($element && $element.is('input')) { 5051 var InputCompat = require(this.get('amdBase') + 'compat/inputData'); 5052 5053 this.options.dataAdapter = Utils.Decorate( 5054 this.options.dataAdapter, 5055 InputCompat 5056 ); 5057 } 5058 } 5059 5060 Options.prototype.fromElement = function ($e) { 5061 var excludedData = ['select2']; 5062 5063 if (this.options.multiple == null) { 5064 this.options.multiple = $e.prop('multiple'); 5065 } 5066 5067 if (this.options.disabled == null) { 5068 this.options.disabled = $e.prop('disabled'); 5069 } 5070 5071 if (this.options.language == null) { 5072 if ($e.prop('lang')) { 5073 this.options.language = $e.prop('lang').toLowerCase(); 5074 } else if ($e.closest('[lang]').prop('lang')) { 5075 this.options.language = $e.closest('[lang]').prop('lang'); 5076 } 5077 } 5078 5079 if (this.options.dir == null) { 5080 if ($e.prop('dir')) { 5081 this.options.dir = $e.prop('dir'); 5082 } else if ($e.closest('[dir]').prop('dir')) { 5083 this.options.dir = $e.closest('[dir]').prop('dir'); 5084 } else { 5085 this.options.dir = 'ltr'; 5086 } 5087 } 5088 5089 $e.prop('disabled', this.options.disabled); 5090 $e.prop('multiple', this.options.multiple); 5091 5092 if (Utils.GetData($e[0], 'select2Tags')) { 5093 if (this.options.debug && window.console && console.warn) { 5094 console.warn( 5095 'Select2: The `data-select2-tags` attribute has been changed to ' + 5096 'use the `data-data` and `data-tags="true"` attributes and will be ' + 5097 'removed in future versions of Select2.' 5098 ); 5099 } 5100 5101 Utils.StoreData($e[0], 'data', Utils.GetData($e[0], 'select2Tags')); 5102 Utils.StoreData($e[0], 'tags', true); 5103 } 5104 5105 if (Utils.GetData($e[0], 'ajaxUrl')) { 5106 if (this.options.debug && window.console && console.warn) { 5107 console.warn( 5108 'Select2: The `data-ajax-url` attribute has been changed to ' + 5109 '`data-ajax--url` and support for the old attribute will be removed' + 5110 ' in future versions of Select2.' 5111 ); 5112 } 5113 5114 $e.attr('ajax--url', Utils.GetData($e[0], 'ajaxUrl')); 5115 Utils.StoreData($e[0], 'ajax-Url', Utils.GetData($e[0], 'ajaxUrl')); 5116 } 5117 5118 var dataset = {}; 5119 5120 function upperCaseLetter(_, letter) { 5121 return letter.toUpperCase(); 5122 } 5123 5124 // Pre-load all of the attributes which are prefixed with `data-` 5125 for (var attr = 0; attr < $e[0].attributes.length; attr++) { 5126 var attributeName = $e[0].attributes[attr].name; 5127 var prefix = 'data-'; 5128 5129 if (attributeName.substr(0, prefix.length) == prefix) { 5130 // Get the contents of the attribute after `data-` 5131 var dataName = attributeName.substring(prefix.length); 5132 5133 // Get the data contents from the consistent source 5134 // This is more than likely the jQuery data helper 5135 var dataValue = Utils.GetData($e[0], dataName); 5136 5137 // camelCase the attribute name to match the spec 5138 var camelDataName = dataName.replace(/-([a-z])/g, upperCaseLetter); 5139 5140 // Store the data attribute contents into the dataset since 5141 dataset[camelDataName] = dataValue; 5142 } 5143 } 5144 5145 // Prefer the element's `dataset` attribute if it exists 5146 // jQuery 1.x does not correctly handle data attributes with multiple dashes 5147 if ($.fn.jquery && $.fn.jquery.substr(0, 2) == '1.' && $e[0].dataset) { 5148 dataset = $.extend(true, {}, $e[0].dataset, dataset); 5149 } 5150 5151 // Prefer our internal data cache if it exists 5152 var data = $.extend(true, {}, Utils.GetData($e[0]), dataset); 5153 5154 data = Utils._convertData(data); 5155 5156 for (var key in data) { 5157 if ($.inArray(key, excludedData) > -1) { 5158 continue; 5159 } 5160 5161 if ($.isPlainObject(this.options[key])) { 5162 $.extend(this.options[key], data[key]); 5163 } else { 5164 this.options[key] = data[key]; 5165 } 5166 } 5167 5168 return this; 5169 }; 5170 5171 Options.prototype.get = function (key) { 5172 return this.options[key]; 5173 }; 5174 5175 Options.prototype.set = function (key, val) { 5176 this.options[key] = val; 5177 }; 5178 5179 return Options; 5180}); 5181 5182S2.define('select2/core',[ 5183 'jquery', 5184 './options', 5185 './utils', 5186 './keys' 5187], function ($, Options, Utils, KEYS) { 5188 var Select2 = function ($element, options) { 5189 if (Utils.GetData($element[0], 'select2') != null) { 5190 Utils.GetData($element[0], 'select2').destroy(); 5191 } 5192 5193 this.$element = $element; 5194 5195 this.id = this._generateId($element); 5196 5197 options = options || {}; 5198 5199 this.options = new Options(options, $element); 5200 5201 Select2.__super__.constructor.call(this); 5202 5203 // Set up the tabindex 5204 5205 var tabindex = $element.attr('tabindex') || 0; 5206 Utils.StoreData($element[0], 'old-tabindex', tabindex); 5207 $element.attr('tabindex', '-1'); 5208 5209 // Set up containers and adapters 5210 5211 var DataAdapter = this.options.get('dataAdapter'); 5212 this.dataAdapter = new DataAdapter($element, this.options); 5213 5214 var $container = this.render(); 5215 5216 this._placeContainer($container); 5217 5218 var SelectionAdapter = this.options.get('selectionAdapter'); 5219 this.selection = new SelectionAdapter($element, this.options); 5220 this.$selection = this.selection.render(); 5221 5222 this.selection.position(this.$selection, $container); 5223 5224 var DropdownAdapter = this.options.get('dropdownAdapter'); 5225 this.dropdown = new DropdownAdapter($element, this.options); 5226 this.$dropdown = this.dropdown.render(); 5227 5228 this.dropdown.position(this.$dropdown, $container); 5229 5230 var ResultsAdapter = this.options.get('resultsAdapter'); 5231 this.results = new ResultsAdapter($element, this.options, this.dataAdapter); 5232 this.$results = this.results.render(); 5233 5234 this.results.position(this.$results, this.$dropdown); 5235 5236 // Bind events 5237 5238 var self = this; 5239 5240 // Bind the container to all of the adapters 5241 this._bindAdapters(); 5242 5243 // Register any DOM event handlers 5244 this._registerDomEvents(); 5245 5246 // Register any internal event handlers 5247 this._registerDataEvents(); 5248 this._registerSelectionEvents(); 5249 this._registerDropdownEvents(); 5250 this._registerResultsEvents(); 5251 this._registerEvents(); 5252 5253 // Set the initial state 5254 this.dataAdapter.current(function (initialData) { 5255 self.trigger('selection:update', { 5256 data: initialData 5257 }); 5258 }); 5259 5260 // Hide the original select 5261 $element.addClass('select2-hidden-accessible'); 5262 $element.attr('aria-hidden', 'true'); 5263 5264 // Synchronize any monitored attributes 5265 this._syncAttributes(); 5266 5267 Utils.StoreData($element[0], 'select2', this); 5268 5269 // Ensure backwards compatibility with $element.data('select2'). 5270 $element.data('select2', this); 5271 }; 5272 5273 Utils.Extend(Select2, Utils.Observable); 5274 5275 Select2.prototype._generateId = function ($element) { 5276 var id = ''; 5277 5278 if ($element.attr('id') != null) { 5279 id = $element.attr('id'); 5280 } else if ($element.attr('name') != null) { 5281 id = $element.attr('name') + '-' + Utils.generateChars(2); 5282 } else { 5283 id = Utils.generateChars(4); 5284 } 5285 5286 id = id.replace(/(:|\.|\[|\]|,)/g, ''); 5287 id = 'select2-' + id; 5288 5289 return id; 5290 }; 5291 5292 Select2.prototype._placeContainer = function ($container) { 5293 $container.insertAfter(this.$element); 5294 5295 var width = this._resolveWidth(this.$element, this.options.get('width')); 5296 5297 if (width != null) { 5298 $container.css('width', width); 5299 } 5300 }; 5301 5302 Select2.prototype._resolveWidth = function ($element, method) { 5303 var WIDTH = /^width:(([-+]?([0-9]*\.)?[0-9]+)(px|em|ex|%|in|cm|mm|pt|pc))/i; 5304 5305 if (method == 'resolve') { 5306 var styleWidth = this._resolveWidth($element, 'style'); 5307 5308 if (styleWidth != null) { 5309 return styleWidth; 5310 } 5311 5312 return this._resolveWidth($element, 'element'); 5313 } 5314 5315 if (method == 'element') { 5316 var elementWidth = $element.outerWidth(false); 5317 5318 if (elementWidth <= 0) { 5319 return 'auto'; 5320 } 5321 5322 return elementWidth + 'px'; 5323 } 5324 5325 if (method == 'style') { 5326 var style = $element.attr('style'); 5327 5328 if (typeof(style) !== 'string') { 5329 return null; 5330 } 5331 5332 var attrs = style.split(';'); 5333 5334 for (var i = 0, l = attrs.length; i < l; i = i + 1) { 5335 var attr = attrs[i].replace(/\s/g, ''); 5336 var matches = attr.match(WIDTH); 5337 5338 if (matches !== null && matches.length >= 1) { 5339 return matches[1]; 5340 } 5341 } 5342 5343 return null; 5344 } 5345 5346 if (method == 'computedstyle') { 5347 var computedStyle = window.getComputedStyle($element[0]); 5348 5349 return computedStyle.width; 5350 } 5351 5352 return method; 5353 }; 5354 5355 Select2.prototype._bindAdapters = function () { 5356 this.dataAdapter.bind(this, this.$container); 5357 this.selection.bind(this, this.$container); 5358 5359 this.dropdown.bind(this, this.$container); 5360 this.results.bind(this, this.$container); 5361 }; 5362 5363 Select2.prototype._registerDomEvents = function () { 5364 var self = this; 5365 5366 this.$element.on('change.select2', function () { 5367 self.dataAdapter.current(function (data) { 5368 self.trigger('selection:update', { 5369 data: data 5370 }); 5371 }); 5372 }); 5373 5374 this.$element.on('focus.select2', function (evt) { 5375 self.trigger('focus', evt); 5376 }); 5377 5378 this._syncA = Utils.bind(this._syncAttributes, this); 5379 this._syncS = Utils.bind(this._syncSubtree, this); 5380 5381 if (this.$element[0].attachEvent) { 5382 this.$element[0].attachEvent('onpropertychange', this._syncA); 5383 } 5384 5385 var observer = window.MutationObserver || 5386 window.WebKitMutationObserver || 5387 window.MozMutationObserver 5388 ; 5389 5390 if (observer != null) { 5391 this._observer = new observer(function (mutations) { 5392 $.each(mutations, self._syncA); 5393 $.each(mutations, self._syncS); 5394 }); 5395 this._observer.observe(this.$element[0], { 5396 attributes: true, 5397 childList: true, 5398 subtree: false 5399 }); 5400 } else if (this.$element[0].addEventListener) { 5401 this.$element[0].addEventListener( 5402 'DOMAttrModified', 5403 self._syncA, 5404 false 5405 ); 5406 this.$element[0].addEventListener( 5407 'DOMNodeInserted', 5408 self._syncS, 5409 false 5410 ); 5411 this.$element[0].addEventListener( 5412 'DOMNodeRemoved', 5413 self._syncS, 5414 false 5415 ); 5416 } 5417 }; 5418 5419 Select2.prototype._registerDataEvents = function () { 5420 var self = this; 5421 5422 this.dataAdapter.on('*', function (name, params) { 5423 self.trigger(name, params); 5424 }); 5425 }; 5426 5427 Select2.prototype._registerSelectionEvents = function () { 5428 var self = this; 5429 var nonRelayEvents = ['toggle', 'focus']; 5430 5431 this.selection.on('toggle', function () { 5432 self.toggleDropdown(); 5433 }); 5434 5435 this.selection.on('focus', function (params) { 5436 self.focus(params); 5437 }); 5438 5439 this.selection.on('*', function (name, params) { 5440 if ($.inArray(name, nonRelayEvents) !== -1) { 5441 return; 5442 } 5443 5444 self.trigger(name, params); 5445 }); 5446 }; 5447 5448 Select2.prototype._registerDropdownEvents = function () { 5449 var self = this; 5450 5451 this.dropdown.on('*', function (name, params) { 5452 self.trigger(name, params); 5453 }); 5454 }; 5455 5456 Select2.prototype._registerResultsEvents = function () { 5457 var self = this; 5458 5459 this.results.on('*', function (name, params) { 5460 self.trigger(name, params); 5461 }); 5462 }; 5463 5464 Select2.prototype._registerEvents = function () { 5465 var self = this; 5466 5467 this.on('open', function () { 5468 self.$container.addClass('select2-container--open'); 5469 }); 5470 5471 this.on('close', function () { 5472 self.$container.removeClass('select2-container--open'); 5473 }); 5474 5475 this.on('enable', function () { 5476 self.$container.removeClass('select2-container--disabled'); 5477 }); 5478 5479 this.on('disable', function () { 5480 self.$container.addClass('select2-container--disabled'); 5481 }); 5482 5483 this.on('blur', function () { 5484 self.$container.removeClass('select2-container--focus'); 5485 }); 5486 5487 this.on('query', function (params) { 5488 if (!self.isOpen()) { 5489 self.trigger('open', {}); 5490 } 5491 5492 this.dataAdapter.query(params, function (data) { 5493 self.trigger('results:all', { 5494 data: data, 5495 query: params 5496 }); 5497 }); 5498 }); 5499 5500 this.on('query:append', function (params) { 5501 this.dataAdapter.query(params, function (data) { 5502 self.trigger('results:append', { 5503 data: data, 5504 query: params 5505 }); 5506 }); 5507 }); 5508 5509 this.on('keypress', function (evt) { 5510 var key = evt.which; 5511 5512 if (self.isOpen()) { 5513 if (key === KEYS.ESC || key === KEYS.TAB || 5514 (key === KEYS.UP && evt.altKey)) { 5515 self.close(); 5516 5517 evt.preventDefault(); 5518 } else if (key === KEYS.ENTER) { 5519 self.trigger('results:select', {}); 5520 5521 evt.preventDefault(); 5522 } else if ((key === KEYS.SPACE && evt.ctrlKey)) { 5523 self.trigger('results:toggle', {}); 5524 5525 evt.preventDefault(); 5526 } else if (key === KEYS.UP) { 5527 self.trigger('results:previous', {}); 5528 5529 evt.preventDefault(); 5530 } else if (key === KEYS.DOWN) { 5531 self.trigger('results:next', {}); 5532 5533 evt.preventDefault(); 5534 } 5535 } else { 5536 if (key === KEYS.ENTER || key === KEYS.SPACE || 5537 (key === KEYS.DOWN && evt.altKey)) { 5538 self.open(); 5539 5540 evt.preventDefault(); 5541 } 5542 } 5543 }); 5544 }; 5545 5546 Select2.prototype._syncAttributes = function () { 5547 this.options.set('disabled', this.$element.prop('disabled')); 5548 5549 if (this.options.get('disabled')) { 5550 if (this.isOpen()) { 5551 this.close(); 5552 } 5553 5554 this.trigger('disable', {}); 5555 } else { 5556 this.trigger('enable', {}); 5557 } 5558 }; 5559 5560 Select2.prototype._syncSubtree = function (evt, mutations) { 5561 var changed = false; 5562 var self = this; 5563 5564 // Ignore any mutation events raised for elements that aren't options or 5565 // optgroups. This handles the case when the select element is destroyed 5566 if ( 5567 evt && evt.target && ( 5568 evt.target.nodeName !== 'OPTION' && evt.target.nodeName !== 'OPTGROUP' 5569 ) 5570 ) { 5571 return; 5572 } 5573 5574 if (!mutations) { 5575 // If mutation events aren't supported, then we can only assume that the 5576 // change affected the selections 5577 changed = true; 5578 } else if (mutations.addedNodes && mutations.addedNodes.length > 0) { 5579 for (var n = 0; n < mutations.addedNodes.length; n++) { 5580 var node = mutations.addedNodes[n]; 5581 5582 if (node.selected) { 5583 changed = true; 5584 } 5585 } 5586 } else if (mutations.removedNodes && mutations.removedNodes.length > 0) { 5587 changed = true; 5588 } 5589 5590 // Only re-pull the data if we think there is a change 5591 if (changed) { 5592 this.dataAdapter.current(function (currentData) { 5593 self.trigger('selection:update', { 5594 data: currentData 5595 }); 5596 }); 5597 } 5598 }; 5599 5600 /** 5601 * Override the trigger method to automatically trigger pre-events when 5602 * there are events that can be prevented. 5603 */ 5604 Select2.prototype.trigger = function (name, args) { 5605 var actualTrigger = Select2.__super__.trigger; 5606 var preTriggerMap = { 5607 'open': 'opening', 5608 'close': 'closing', 5609 'select': 'selecting', 5610 'unselect': 'unselecting', 5611 'clear': 'clearing' 5612 }; 5613 5614 if (args === undefined) { 5615 args = {}; 5616 } 5617 5618 if (name in preTriggerMap) { 5619 var preTriggerName = preTriggerMap[name]; 5620 var preTriggerArgs = { 5621 prevented: false, 5622 name: name, 5623 args: args 5624 }; 5625 5626 actualTrigger.call(this, preTriggerName, preTriggerArgs); 5627 5628 if (preTriggerArgs.prevented) { 5629 args.prevented = true; 5630 5631 return; 5632 } 5633 } 5634 5635 actualTrigger.call(this, name, args); 5636 }; 5637 5638 Select2.prototype.toggleDropdown = function () { 5639 if (this.options.get('disabled')) { 5640 return; 5641 } 5642 5643 if (this.isOpen()) { 5644 this.close(); 5645 } else { 5646 this.open(); 5647 } 5648 }; 5649 5650 Select2.prototype.open = function () { 5651 if (this.isOpen()) { 5652 return; 5653 } 5654 5655 this.trigger('query', {}); 5656 }; 5657 5658 Select2.prototype.close = function () { 5659 if (!this.isOpen()) { 5660 return; 5661 } 5662 5663 this.trigger('close', {}); 5664 }; 5665 5666 Select2.prototype.isOpen = function () { 5667 return this.$container.hasClass('select2-container--open'); 5668 }; 5669 5670 Select2.prototype.hasFocus = function () { 5671 return this.$container.hasClass('select2-container--focus'); 5672 }; 5673 5674 Select2.prototype.focus = function (data) { 5675 // No need to re-trigger focus events if we are already focused 5676 if (this.hasFocus()) { 5677 return; 5678 } 5679 5680 this.$container.addClass('select2-container--focus'); 5681 this.trigger('focus', {}); 5682 }; 5683 5684 Select2.prototype.enable = function (args) { 5685 if (this.options.get('debug') && window.console && console.warn) { 5686 console.warn( 5687 'Select2: The `select2("enable")` method has been deprecated and will' + 5688 ' be removed in later Select2 versions. Use $element.prop("disabled")' + 5689 ' instead.' 5690 ); 5691 } 5692 5693 if (args == null || args.length === 0) { 5694 args = [true]; 5695 } 5696 5697 var disabled = !args[0]; 5698 5699 this.$element.prop('disabled', disabled); 5700 }; 5701 5702 Select2.prototype.data = function () { 5703 if (this.options.get('debug') && 5704 arguments.length > 0 && window.console && console.warn) { 5705 console.warn( 5706 'Select2: Data can no longer be set using `select2("data")`. You ' + 5707 'should consider setting the value instead using `$element.val()`.' 5708 ); 5709 } 5710 5711 var data = []; 5712 5713 this.dataAdapter.current(function (currentData) { 5714 data = currentData; 5715 }); 5716 5717 return data; 5718 }; 5719 5720 Select2.prototype.val = function (args) { 5721 if (this.options.get('debug') && window.console && console.warn) { 5722 console.warn( 5723 'Select2: The `select2("val")` method has been deprecated and will be' + 5724 ' removed in later Select2 versions. Use $element.val() instead.' 5725 ); 5726 } 5727 5728 if (args == null || args.length === 0) { 5729 return this.$element.val(); 5730 } 5731 5732 var newVal = args[0]; 5733 5734 if ($.isArray(newVal)) { 5735 newVal = $.map(newVal, function (obj) { 5736 return obj.toString(); 5737 }); 5738 } 5739 5740 this.$element.val(newVal).trigger('change'); 5741 }; 5742 5743 Select2.prototype.destroy = function () { 5744 this.$container.remove(); 5745 5746 if (this.$element[0].detachEvent) { 5747 this.$element[0].detachEvent('onpropertychange', this._syncA); 5748 } 5749 5750 if (this._observer != null) { 5751 this._observer.disconnect(); 5752 this._observer = null; 5753 } else if (this.$element[0].removeEventListener) { 5754 this.$element[0] 5755 .removeEventListener('DOMAttrModified', this._syncA, false); 5756 this.$element[0] 5757 .removeEventListener('DOMNodeInserted', this._syncS, false); 5758 this.$element[0] 5759 .removeEventListener('DOMNodeRemoved', this._syncS, false); 5760 } 5761 5762 this._syncA = null; 5763 this._syncS = null; 5764 5765 this.$element.off('.select2'); 5766 this.$element.attr('tabindex', 5767 Utils.GetData(this.$element[0], 'old-tabindex')); 5768 5769 this.$element.removeClass('select2-hidden-accessible'); 5770 this.$element.attr('aria-hidden', 'false'); 5771 Utils.RemoveData(this.$element[0]); 5772 this.$element.removeData('select2'); 5773 5774 this.dataAdapter.destroy(); 5775 this.selection.destroy(); 5776 this.dropdown.destroy(); 5777 this.results.destroy(); 5778 5779 this.dataAdapter = null; 5780 this.selection = null; 5781 this.dropdown = null; 5782 this.results = null; 5783 }; 5784 5785 Select2.prototype.render = function () { 5786 var $container = $( 5787 '<span class="select2 select2-container">' + 5788 '<span class="selection"></span>' + 5789 '<span class="dropdown-wrapper" aria-hidden="true"></span>' + 5790 '</span>' 5791 ); 5792 5793 $container.attr('dir', this.options.get('dir')); 5794 5795 this.$container = $container; 5796 5797 this.$container.addClass('select2-container--' + this.options.get('theme')); 5798 5799 Utils.StoreData($container[0],
vendor: 5,228 bytes, lines 5799-6009
5799'element', this.$element); 5800 5801 return $container; 5802 }; 5803 5804 return Select2; 5805}); 5806 5807S2.define('select2/compat/utils',[ 5808 'jquery' 5809], function ($) { 5810 function syncCssClasses ($dest, $src, adapter) { 5811 var classes, replacements = [], adapted; 5812 5813 classes = $.trim($dest.attr('class')); 5814 5815 if (classes) { 5816 classes = '' + classes; // for IE which returns object 5817 5818 $(classes.split(/\s+/)).each(function () { 5819 // Save all Select2 classes 5820 if (this.indexOf('select2-') === 0) { 5821 replacements.push(this); 5822 } 5823 }); 5824 } 5825 5826 classes = $.trim($src.attr('class')); 5827 5828 if (classes) { 5829 classes = '' + classes; // for IE which returns object 5830 5831 $(classes.split(/\s+/)).each(function () { 5832 // Only adapt non-Select2 classes 5833 if (this.indexOf('select2-') !== 0) { 5834 adapted = adapter(this); 5835 5836 if (adapted != null) { 5837 replacements.push(adapted); 5838 } 5839 } 5840 }); 5841 } 5842 5843 $dest.attr('class', replacements.join(' ')); 5844 } 5845 5846 return { 5847 syncCssClasses: syncCssClasses 5848 }; 5849}); 5850 5851S2.define('select2/compat/containerCss',[ 5852 'jquery', 5853 './utils' 5854], function ($, CompatUtils) { 5855 // No-op CSS adapter that discards all classes by default 5856 function _containerAdapter (clazz) { 5857 return null; 5858 } 5859 5860 function ContainerCSS () { } 5861 5862 ContainerCSS.prototype.render = function (decorated) { 5863 var $container = decorated.call(this); 5864 5865 var containerCssClass = this.options.get('containerCssClass') || ''; 5866 5867 if ($.isFunction(containerCssClass)) { 5868 containerCssClass = containerCssClass(this.$element); 5869 } 5870 5871 var containerCssAdapter = this.options.get('adaptContainerCssClass'); 5872 containerCssAdapter = containerCssAdapter || _containerAdapter; 5873 5874 if (containerCssClass.indexOf(':all:') !== -1) { 5875 containerCssClass = containerCssClass.replace(':all:', ''); 5876 5877 var _cssAdapter = containerCssAdapter; 5878 5879 containerCssAdapter = function (clazz) { 5880 var adapted = _cssAdapter(clazz); 5881 5882 if (adapted != null) { 5883 // Append the old one along with the adapted one 5884 return adapted + ' ' + clazz; 5885 } 5886 5887 return clazz; 5888 }; 5889 } 5890 5891 var containerCss = this.options.get('containerCss') || {}; 5892 5893 if ($.isFunction(containerCss)) { 5894 containerCss = containerCss(this.$element); 5895 } 5896 5897 CompatUtils.syncCssClasses($container, this.$element, containerCssAdapter); 5898 5899 $container.css(containerCss); 5900 $container.addClass(containerCssClass); 5901 5902 return $container; 5903 }; 5904 5905 return ContainerCSS; 5906}); 5907 5908S2.define('select2/compat/dropdownCss',[ 5909 'jquery', 5910 './utils' 5911], function ($, CompatUtils) { 5912 // No-op CSS adapter that discards all classes by default 5913 function _dropdownAdapter (clazz) { 5914 return null; 5915 } 5916 5917 function DropdownCSS () { } 5918 5919 DropdownCSS.prototype.render = function (decorated) { 5920 var $dropdown = decorated.call(this); 5921 5922 var dropdownCssClass = this.options.get('dropdownCssClass') || ''; 5923 5924 if ($.isFunction(dropdownCssClass)) { 5925 dropdownCssClass = dropdownCssClass(this.$element); 5926 } 5927 5928 var dropdownCssAdapter = this.options.get('adaptDropdownCssClass'); 5929 dropdownCssAdapter = dropdownCssAdapter || _dropdownAdapter; 5930 5931 if (dropdownCssClass.indexOf(':all:') !== -1) { 5932 dropdownCssClass = dropdownCssClass.replace(':all:', ''); 5933 5934 var _cssAdapter = dropdownCssAdapter; 5935 5936 dropdownCssAdapter = function (clazz) { 5937 var adapted = _cssAdapter(clazz); 5938 5939 if (adapted != null) { 5940 // Append the old one along with the adapted one 5941 return adapted + ' ' + clazz; 5942 } 5943 5944 return clazz; 5945 }; 5946 } 5947 5948 var dropdownCss = this.options.get('dropdownCss') || {}; 5949 5950 if ($.isFunction(dropdownCss)) { 5951 dropdownCss = dropdownCss(this.$element); 5952 } 5953 5954 CompatUtils.syncCssClasses($dropdown, this.$element, dropdownCssAdapter); 5955 5956 $dropdown.css(dropdownCss); 5957 $dropdown.addClass(dropdownCssClass); 5958 5959 return $dropdown; 5960 }; 5961 5962 return DropdownCSS; 5963}); 5964 5965S2.define('select2/compat/initSelection',[ 5966 'jquery' 5967], function ($) { 5968 function InitSelection (decorated, $element, options) { 5969 if (options.get('debug') && window.console && console.warn) { 5970 console.warn( 5971 'Select2: The `initSelection` option has been deprecated in favor' + 5972 ' of a custom data adapter that overrides the `current` method. ' + 5973 'This method is now called multiple times instead of a single ' + 5974 'time when the instance is initialized. Support will be removed ' + 5975 'for the `initSelection` option in future versions of Select2' 5976 ); 5977 } 5978 5979 this.initSelection = options.get('initSelection'); 5980 this._isInitialized = false; 5981 5982 decorated.call(this, $element, options); 5983 } 5984 5985 InitSelection.prototype.current = function (decorated, callback) { 5986 var self = this; 5987 5988 if (this._isInitialized) { 5989 decorated.call(this, callback); 5990 5991 return; 5992 } 5993 5994 this.initSelection.call(null, this.$element, function (data) { 5995 self._isInitialized = true; 5996 5997 if (!$.isArray(data)) { 5998 data = [data]; 5999 } 6000 6001 callback(data); 6002 }); 6003 }; 6004 6005 return InitSelection; 6006}); 6007 6008S2.define('select2/compat/inputData',[ 6009 'jquery'
vendor: 2,840 bytes, lines 6009-6128
6009, 6010 '../utils' 6011], function ($, Utils) { 6012 function InputData (decorated, $element, options) { 6013 this._currentData = []; 6014 this._valueSeparator = options.get('valueSeparator') || ','; 6015 6016 if ($element.prop('type') === 'hidden') { 6017 if (options.get('debug') && console && console.warn) { 6018 console.warn( 6019 'Select2: Using a hidden input with Select2 is no longer ' + 6020 'supported and may stop working in the future. It is recommended ' + 6021 'to use a `<select>` element instead.' 6022 ); 6023 } 6024 } 6025 6026 decorated.call(this, $element, options); 6027 } 6028 6029 InputData.prototype.current = function (_, callback) { 6030 function getSelected (data, selectedIds) { 6031 var selected = []; 6032 6033 if (data.selected || $.inArray(data.id, selectedIds) !== -1) { 6034 data.selected = true; 6035 selected.push(data); 6036 } else { 6037 data.selected = false; 6038 } 6039 6040 if (data.children) { 6041 selected.push.apply(selected, getSelected(data.children, selectedIds)); 6042 } 6043 6044 return selected; 6045 } 6046 6047 var selected = []; 6048 6049 for (var d = 0; d < this._currentData.length; d++) { 6050 var data = this._currentData[d]; 6051 6052 selected.push.apply( 6053 selected, 6054 getSelected( 6055 data, 6056 this.$element.val().split( 6057 this._valueSeparator 6058 ) 6059 ) 6060 ); 6061 } 6062 6063 callback(selected); 6064 }; 6065 6066 InputData.prototype.select = function (_, data) { 6067 if (!this.options.get('multiple')) { 6068 this.current(function (allData) { 6069 $.map(allData, function (data) { 6070 data.selected = false; 6071 }); 6072 }); 6073 6074 this.$element.val(data.id); 6075 this.$element.trigger('change'); 6076 } else { 6077 var value = this.$element.val(); 6078 value += this._valueSeparator + data.id; 6079 6080 this.$element.val(value); 6081 this.$element.trigger('change'); 6082 } 6083 }; 6084 6085 InputData.prototype.unselect = function (_, data) { 6086 var self = this; 6087 6088 data.selected = false; 6089 6090 this.current(function (allData) { 6091 var values = []; 6092 6093 for (var d = 0; d < allData.length; d++) { 6094 var item = allData[d]; 6095 6096 if (data.id == item.id) { 6097 continue; 6098 } 6099 6100 values.push(item.id); 6101 } 6102 6103 self.$element.val(values.join(self._valueSeparator)); 6104 self.$element.trigger('change'); 6105 }); 6106 }; 6107 6108 InputData.prototype.query = function (_, params, callback) { 6109 var results = []; 6110 6111 for (var d = 0; d < this._currentData.length; d++) { 6112 var data = this._currentData[d]; 6113 6114 var matches = this.matches(params, data); 6115 6116 if (matches !== null) { 6117 results.push(matches); 6118 } 6119 } 6120 6121 callback({ 6122 results: results 6123 }); 6124 }; 6125 6126 InputData.prototype.addOptions = function (_, $options) { 6127 var options = $.map($options, function ($option) { 6128 return Utils.GetD
vendor: 12,180 bytes, lines 6128-6531
6128ata($option[0], 'data'); 6129 }); 6130 6131 this._currentData.push.apply(this._currentData, options); 6132 }; 6133 6134 return InputData; 6135}); 6136 6137S2.define('select2/compat/matcher',[ 6138 'jquery' 6139], function ($) { 6140 function oldMatcher (matcher) { 6141 function wrappedMatcher (params, data) { 6142 var match = $.extend(true, {}, data); 6143 6144 if (params.term == null || $.trim(params.term) === '') { 6145 return match; 6146 } 6147 6148 if (data.children) { 6149 for (var c = data.children.length - 1; c >= 0; c--) { 6150 var child = data.children[c]; 6151 6152 // Check if the child object matches 6153 // The old matcher returned a boolean true or false 6154 var doesMatch = matcher(params.term, child.text, child); 6155 6156 // If the child didn't match, pop it off 6157 if (!doesMatch) { 6158 match.children.splice(c, 1); 6159 } 6160 } 6161 6162 if (match.children.length > 0) { 6163 return match; 6164 } 6165 } 6166 6167 if (matcher(params.term, data.text, data)) { 6168 return match; 6169 } 6170 6171 return null; 6172 } 6173 6174 return wrappedMatcher; 6175 } 6176 6177 return oldMatcher; 6178}); 6179 6180S2.define('select2/compat/query',[ 6181 6182], function () { 6183 function Query (decorated, $element, options) { 6184 if (options.get('debug') && window.console && console.warn) { 6185 console.warn( 6186 'Select2: The `query` option has been deprecated in favor of a ' + 6187 'custom data adapter that overrides the `query` method. Support ' + 6188 'will be removed for the `query` option in future versions of ' + 6189 'Select2.' 6190 ); 6191 } 6192 6193 decorated.call(this, $element, options); 6194 } 6195 6196 Query.prototype.query = function (_, params, callback) { 6197 params.callback = callback; 6198 6199 var query = this.options.get('query'); 6200 6201 query.call(null, params); 6202 }; 6203 6204 return Query; 6205}); 6206 6207S2.define('select2/dropdown/attachContainer',[ 6208 6209], function () { 6210 function AttachContainer (decorated, $element, options) { 6211 decorated.call(this, $element, options); 6212 } 6213 6214 AttachContainer.prototype.position = 6215 function (decorated, $dropdown, $container) { 6216 var $dropdownContainer = $container.find('.dropdown-wrapper'); 6217 $dropdownContainer.append($dropdown); 6218 6219 $dropdown.addClass('select2-dropdown--below'); 6220 $container.addClass('select2-container--below'); 6221 }; 6222 6223 return AttachContainer; 6224}); 6225 6226S2.define('select2/dropdown/stopPropagation',[ 6227 6228], function () { 6229 function StopPropagation () { } 6230 6231 StopPropagation.prototype.bind = function (decorated, container, $container) { 6232 decorated.call(this, container, $container); 6233 6234 var stoppedEvents = [ 6235 'blur', 6236 'change', 6237 'click', 6238 'dblclick', 6239 'focus', 6240 'focusin', 6241 'focusout', 6242 'input', 6243 'keydown', 6244 'keyup', 6245 'keypress', 6246 'mousedown', 6247 'mouseenter', 6248 'mouseleave', 6249 'mousemove', 6250 'mouseover', 6251 'mouseup', 6252 'search', 6253 'touchend', 6254 'touchstart' 6255 ]; 6256 6257 this.$dropdown.on(stoppedEvents.join(' '), function (evt) { 6258 evt.stopPropagation(); 6259 }); 6260 }; 6261 6262 return StopPropagation; 6263}); 6264 6265S2.define('select2/selection/stopPropagation',[ 6266 6267], function () { 6268 function StopPropagation () { } 6269 6270 StopPropagation.prototype.bind = function (decorated, container, $container) { 6271 decorated.call(this, container, $container); 6272 6273 var stoppedEvents = [ 6274 'blur', 6275 'change', 6276 'click', 6277 'dblclick', 6278 'focus', 6279 'focusin', 6280 'focusout', 6281 'input', 6282 'keydown', 6283 'keyup', 6284 'keypress', 6285 'mousedown', 6286 'mouseenter', 6287 'mouseleave', 6288 'mousemove', 6289 'mouseover', 6290 'mouseup', 6291 'search', 6292 'touchend', 6293 'touchstart' 6294 ]; 6295 6296 this.$selection.on(stoppedEvents.join(' '), function (evt) { 6297 evt.stopPropagation(); 6298 }); 6299 }; 6300 6301 return StopPropagation; 6302}); 6303 6304/*! 6305 * jQuery Mousewheel 3.1.13 6306 * 6307 * Copyright jQuery Foundation and other contributors 6308 * Released under the MIT license 6309 * http://jquery.org/license 6310 */ 6311 6312(function (factory) { 6313 if ( typeof S2.define === 'function' && S2.define.amd ) { 6314 // AMD. Register as an anonymous module. 6315 S2.define('jquery-mousewheel',['jquery'], factory); 6316 } else if (typeof exports === 'object') { 6317 // Node/CommonJS style for Browserify 6318 module.exports = factory; 6319 } else { 6320 // Browser globals 6321 factory(jQuery); 6322 } 6323}(function ($) { 6324 6325 var toFix = ['wheel', 'mousewheel', 'DOMMouseScroll', 'MozMousePixelScroll'], 6326 toBind = ( 'onwheel' in document || document.documentMode >= 9 ) ? 6327 ['wheel'] : ['mousewheel', 'DomMouseScroll', 'MozMousePixelScroll'], 6328 slice = Array.prototype.slice, 6329 nullLowestDeltaTimeout, lowestDelta; 6330 6331 if ( $.event.fixHooks ) { 6332 for ( var i = toFix.length; i; ) { 6333 $.event.fixHooks[ toFix[--i] ] = $.event.mouseHooks; 6334 } 6335 } 6336 6337 var special = $.event.special.mousewheel = { 6338 version: '3.1.12', 6339 6340 setup: function() { 6341 if ( this.addEventListener ) { 6342 for ( var i = toBind.length; i; ) { 6343 this.addEventListener( toBind[--i], handler, false ); 6344 } 6345 } else { 6346 this.onmousewheel = handler; 6347 } 6348 // Store the line height and page height for this particular element 6349 $.data(this, 'mousewheel-line-height', special.getLineHeight(this)); 6350 $.data(this, 'mousewheel-page-height', special.getPageHeight(this)); 6351 }, 6352 6353 teardown: function() { 6354 if ( this.removeEventListener ) { 6355 for ( var i = toBind.length; i; ) { 6356 this.removeEventListener( toBind[--i], handler, false ); 6357 } 6358 } else { 6359 this.onmousewheel = null; 6360 } 6361 // Clean up the data we added to the element 6362 $.removeData(this, 'mousewheel-line-height'); 6363 $.removeData(this, 'mousewheel-page-height'); 6364 }, 6365 6366 getLineHeight: function(elem) { 6367 var $elem = $(elem), 6368 $parent = $elem['offsetParent' in $.fn ? 'offsetParent' : 'parent'](); 6369 if (!$parent.length) { 6370 $parent = $('body'); 6371 } 6372 return parseInt($parent.css('fontSize'), 10) || parseInt($elem.css('fontSize'), 10) || 16; 6373 }, 6374 6375 getPageHeight: function(elem) { 6376 return $(elem).height(); 6377 }, 6378 6379 settings: { 6380 adjustOldDeltas: true, // see shouldAdjustOldDeltas() below 6381 normalizeOffset: true // calls getBoundingClientRect for each event 6382 } 6383 }; 6384 6385 $.fn.extend({ 6386 mousewheel: function(fn) { 6387 return fn ? this.bind('mousewheel', fn) : this.trigger('mousewheel'); 6388 }, 6389 6390 unmousewheel: function(fn) { 6391 return this.unbind('mousewheel', fn); 6392 } 6393 }); 6394 6395 6396 function handler(event) { 6397 var orgEvent = event || window.event, 6398 args = slice.call(arguments, 1), 6399 delta = 0, 6400 deltaX = 0, 6401 deltaY = 0, 6402 absDelta = 0, 6403 offsetX = 0, 6404 offsetY = 0; 6405 event = $.event.fix(orgEvent); 6406 event.type = 'mousewheel'; 6407 6408 // Old school scrollwheel delta 6409 if ( 'detail' in orgEvent ) { deltaY = orgEvent.detail * -1; } 6410 if ( 'wheelDelta' in orgEvent ) { deltaY = orgEvent.wheelDelta; } 6411 if ( 'wheelDeltaY' in orgEvent ) { deltaY = orgEvent.wheelDeltaY; } 6412 if ( 'wheelDeltaX' in orgEvent ) { deltaX = orgEvent.wheelDeltaX * -1; } 6413 6414 // Firefox < 17 horizontal scrolling related to DOMMouseScroll event 6415 if ( 'axis' in orgEvent && orgEvent.axis === orgEvent.HORIZONTAL_AXIS ) { 6416 deltaX = deltaY * -1; 6417 deltaY = 0; 6418 } 6419 6420 // Set delta to be deltaY or deltaX if deltaY is 0 for backwards compatabilitiy 6421 delta = deltaY === 0 ? deltaX : deltaY; 6422 6423 // New school wheel delta (wheel event) 6424 if ( 'deltaY' in orgEvent ) { 6425 deltaY = orgEvent.deltaY * -1; 6426 delta = deltaY; 6427 } 6428 if ( 'deltaX' in orgEvent ) { 6429 deltaX = orgEvent.deltaX; 6430 if ( deltaY === 0 ) { delta = deltaX * -1; } 6431 } 6432 6433 // No change actually happened, no reason to go any further 6434 if ( deltaY === 0 && deltaX === 0 ) { return; } 6435 6436 // Need to convert lines and pages to pixels if we aren't already in pixels 6437 // There are three delta modes: 6438 // * deltaMode 0 is by pixels, nothing to do 6439 // * deltaMode 1 is by lines 6440 // * deltaMode 2 is by pages 6441 if ( orgEvent.deltaMode === 1 ) { 6442 var lineHeight = $.data(this, 'mousewheel-line-height'); 6443 delta *= lineHeight; 6444 deltaY *= lineHeight; 6445 deltaX *= lineHeight; 6446 } else if ( orgEvent.deltaMode === 2 ) { 6447 var pageHeight = $.data(this, 'mousewheel-page-height'); 6448 delta *= pageHeight; 6449 deltaY *= pageHeight; 6450 deltaX *= pageHeight; 6451 } 6452 6453 // Store lowest absolute delta to normalize the delta values 6454 absDelta = Math.max( Math.abs(deltaY), Math.abs(deltaX) ); 6455 6456 if ( !lowestDelta || absDelta < lowestDelta ) { 6457 lowestDelta = absDelta; 6458 6459 // Adjust older deltas if necessary 6460 if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) { 6461 lowestDelta /= 40; 6462 } 6463 } 6464 6465 // Adjust older deltas if necessary 6466 if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) { 6467 // Divide all the things by 40! 6468 delta /= 40; 6469 deltaX /= 40; 6470 deltaY /= 40; 6471 } 6472 6473 // Get a whole, normalized value for the deltas 6474 delta = Math[ delta >= 1 ? 'floor' : 'ceil' ](delta / lowestDelta); 6475 deltaX = Math[ deltaX >= 1 ? 'floor' : 'ceil' ](deltaX / lowestDelta); 6476 deltaY = Math[ deltaY >= 1 ? 'floor' : 'ceil' ](deltaY / lowestDelta); 6477 6478 // Normalise offsetX and offsetY properties 6479 if ( special.settings.normalizeOffset && this.getBoundingClientRect ) { 6480 var boundingRect = this.getBoundingClientRect(); 6481 offsetX = event.clientX - boundingRect.left; 6482 offsetY = event.clientY - boundingRect.top; 6483 } 6484 6485 // Add information to the event object 6486 event.deltaX = deltaX; 6487 event.deltaY = deltaY; 6488 event.deltaFactor = lowestDelta; 6489 event.offsetX = offsetX; 6490 event.offsetY = offsetY; 6491 // Go ahead and set deltaMode to 0 since we converted to pixels 6492 // Although this is a little odd since we overwrite the deltaX/Y 6493 // properties with normalized deltas. 6494 event.deltaMode = 0; 6495 6496 // Add event and delta to the front of the arguments 6497 args.unshift(event, delta, deltaX, deltaY); 6498 6499 // Clearout lowestDelta after sometime to better 6500 // handle multiple device types that give different 6501 // a different lowestDelta 6502 // Ex: trackpad = 3 and mouse wheel = 120 6503 if (nullLowestDeltaTimeout) { clearTimeout(nullLowestDeltaTimeout); } 6504 nullLowestDeltaTimeout = setTimeout(nullLowestDelta, 200); 6505 6506 return ($.event.dispatch || $.event.handle).apply(this, args); 6507 } 6508 6509 function nullLowestDelta() { 6510 lowestDelta = null; 6511 } 6512 6513 function shouldAdjustOldDeltas(orgEvent, absDelta) { 6514 // If this is an older event and the delta is divisable by 120, 6515 // then we are assuming that the browser is treating this as an 6516 // older mouse wheel event and that we should divide the deltas 6517 // by 40 to try and get a more usable deltaFactor. 6518 // Side note, this actually impacts the reported scroll distance 6519 // in older browsers and can cause scrolling to be slower than native. 6520 // Turn this off by setting $.event.special.mousewheel.settings.adjustOldDeltas to false. 6521 return special.settings.adjustOldDeltas && orgEvent.type === 'mousewheel' && absDelta % 120 === 0; 6522 } 6523 6524})); 6525 6526S2.define('jquery.select2',[ 6527 'jquery', 6528 'jquery-mousewheel', 6529 6530 './select2/core', 6531 './select2/defaults'
vendor: 2,020 bytes, lines 6531-6603
6531, 6532 './select2/utils' 6533], function ($, _, Select2, Defaults, Utils) { 6534 if ($.fn.select2 == null) { 6535 // All methods that should return the element 6536 var thisMethods = ['open', 'close', 'destroy']; 6537 6538 $.fn.select2 = function (options) { 6539 options = options || {}; 6540 6541 if (typeof options === 'object') { 6542 this.each(function () { 6543 var instanceOptions = $.extend(true, {}, options); 6544 6545 var instance = new Select2($(this), instanceOptions); 6546 }); 6547 6548 return this; 6549 } else if (typeof options === 'string') { 6550 var ret; 6551 var args = Array.prototype.slice.call(arguments, 1); 6552 6553 this.each(function () { 6554 var instance = Utils.GetData(this, 'select2'); 6555 6556 if (instance == null && window.console && console.error) { 6557 console.error( 6558 'The select2(\'' + options + '\') method was called on an ' + 6559 'element that is not using Select2.' 6560 ); 6561 } 6562 6563 ret = instance[options].apply(instance, args); 6564 }); 6565 6566 // Check if we should be returning `this` 6567 if ($.inArray(options, thisMethods) > -1) { 6568 return this; 6569 } 6570 6571 return ret; 6572 } else { 6573 throw new Error('Invalid arguments for Select2: ' + options); 6574 } 6575 }; 6576 } 6577 6578 if ($.fn.select2.defaults == null) { 6579 $.fn.select2.defaults = Defaults; 6580 } 6581 6582 return Select2; 6583}); 6584 6585 // Return the AMD loader configuration so it can be used outside of this file 6586 return { 6587 define: S2.define, 6588 require: S2.require 6589 }; 6590}()); 6591 6592 // Autoload the jQuery bindings 6593 // We know that all of the modules exist above this, so we're safe 6594 var select2 = S2.require('jquery.select2'); 6595 6596 // Hold the AMD module references on the jQuery function that was just loaded 6597 // This allows Select2 to use the internal loader outside of this file, such 6598 // as in the language files. 6599 jQuery.fn.select2.amd = S2; 6600 6601 // Return the Select2 instance for anyone who is importing it. 6602 return select2; 6603}));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.