tenon 1.1.6 → 1.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tenon/version.rb +1 -1
- data/vendor/assets/javascripts/select2.js +3 -3448
- data/vendor/assets/stylesheets/select2.css +1 -646
- metadata +3 -3
@@ -1,3448 +1,3 @@
|
|
1
|
-
/*
|
2
|
-
Copyright 2012 Igor Vaynberg
|
3
|
-
|
4
|
-
Version: 3.4.8 Timestamp: Thu May 1 09:50:32 EDT 2014
|
5
|
-
|
6
|
-
This software is licensed under the Apache License, Version 2.0 (the "Apache License") or the GNU
|
7
|
-
General Public License version 2 (the "GPL License"). You may choose either license to govern your
|
8
|
-
use of this software only upon the condition that you accept all of the terms of either the Apache
|
9
|
-
License or the GPL License.
|
10
|
-
|
11
|
-
You may obtain a copy of the Apache License and the GPL License at:
|
12
|
-
|
13
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
14
|
-
http://www.gnu.org/licenses/gpl-2.0.html
|
15
|
-
|
16
|
-
Unless required by applicable law or agreed to in writing, software distributed under the
|
17
|
-
Apache License or the GPL License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
18
|
-
CONDITIONS OF ANY KIND, either express or implied. See the Apache License and the GPL License for
|
19
|
-
the specific language governing permissions and limitations under the Apache License and the GPL License.
|
20
|
-
*/
|
21
|
-
(function ($) {
|
22
|
-
if(typeof $.fn.each2 == "undefined") {
|
23
|
-
$.extend($.fn, {
|
24
|
-
/*
|
25
|
-
* 4-10 times faster .each replacement
|
26
|
-
* use it carefully, as it overrides jQuery context of element on each iteration
|
27
|
-
*/
|
28
|
-
each2 : function (c) {
|
29
|
-
var j = $([0]), i = -1, l = this.length;
|
30
|
-
while (
|
31
|
-
++i < l
|
32
|
-
&& (j.context = j[0] = this[i])
|
33
|
-
&& c.call(j[0], i, j) !== false //"this"=DOM, i=index, j=jQuery object
|
34
|
-
);
|
35
|
-
return this;
|
36
|
-
}
|
37
|
-
});
|
38
|
-
}
|
39
|
-
})(jQuery);
|
40
|
-
|
41
|
-
(function ($, undefined) {
|
42
|
-
"use strict";
|
43
|
-
/*global document, window, jQuery, console */
|
44
|
-
|
45
|
-
if (window.Select2 !== undefined) {
|
46
|
-
return;
|
47
|
-
}
|
48
|
-
|
49
|
-
var KEY, AbstractSelect2, SingleSelect2, MultiSelect2, nextUid, sizer,
|
50
|
-
lastMousePosition={x:0,y:0}, $document, scrollBarDimensions,
|
51
|
-
|
52
|
-
KEY = {
|
53
|
-
TAB: 9,
|
54
|
-
ENTER: 13,
|
55
|
-
ESC: 27,
|
56
|
-
SPACE: 32,
|
57
|
-
LEFT: 37,
|
58
|
-
UP: 38,
|
59
|
-
RIGHT: 39,
|
60
|
-
DOWN: 40,
|
61
|
-
SHIFT: 16,
|
62
|
-
CTRL: 17,
|
63
|
-
ALT: 18,
|
64
|
-
PAGE_UP: 33,
|
65
|
-
PAGE_DOWN: 34,
|
66
|
-
HOME: 36,
|
67
|
-
END: 35,
|
68
|
-
BACKSPACE: 8,
|
69
|
-
DELETE: 46,
|
70
|
-
isArrow: function (k) {
|
71
|
-
k = k.which ? k.which : k;
|
72
|
-
switch (k) {
|
73
|
-
case KEY.LEFT:
|
74
|
-
case KEY.RIGHT:
|
75
|
-
case KEY.UP:
|
76
|
-
case KEY.DOWN:
|
77
|
-
return true;
|
78
|
-
}
|
79
|
-
return false;
|
80
|
-
},
|
81
|
-
isControl: function (e) {
|
82
|
-
var k = e.which;
|
83
|
-
switch (k) {
|
84
|
-
case KEY.SHIFT:
|
85
|
-
case KEY.CTRL:
|
86
|
-
case KEY.ALT:
|
87
|
-
return true;
|
88
|
-
}
|
89
|
-
|
90
|
-
if (e.metaKey) return true;
|
91
|
-
|
92
|
-
return false;
|
93
|
-
},
|
94
|
-
isFunctionKey: function (k) {
|
95
|
-
k = k.which ? k.which : k;
|
96
|
-
return k >= 112 && k <= 123;
|
97
|
-
}
|
98
|
-
},
|
99
|
-
MEASURE_SCROLLBAR_TEMPLATE = "<div class='select2-measure-scrollbar'></div>",
|
100
|
-
|
101
|
-
DIACRITICS = {"\u24B6":"A","\uFF21":"A","\u00C0":"A","\u00C1":"A","\u00C2":"A","\u1EA6":"A","\u1EA4":"A","\u1EAA":"A","\u1EA8":"A","\u00C3":"A","\u0100":"A","\u0102":"A","\u1EB0":"A","\u1EAE":"A","\u1EB4":"A","\u1EB2":"A","\u0226":"A","\u01E0":"A","\u00C4":"A","\u01DE":"A","\u1EA2":"A","\u00C5":"A","\u01FA":"A","\u01CD":"A","\u0200":"A","\u0202":"A","\u1EA0":"A","\u1EAC":"A","\u1EB6":"A","\u1E00":"A","\u0104":"A","\u023A":"A","\u2C6F":"A","\uA732":"AA","\u00C6":"AE","\u01FC":"AE","\u01E2":"AE","\uA734":"AO","\uA736":"AU","\uA738":"AV","\uA73A":"AV","\uA73C":"AY","\u24B7":"B","\uFF22":"B","\u1E02":"B","\u1E04":"B","\u1E06":"B","\u0243":"B","\u0182":"B","\u0181":"B","\u24B8":"C","\uFF23":"C","\u0106":"C","\u0108":"C","\u010A":"C","\u010C":"C","\u00C7":"C","\u1E08":"C","\u0187":"C","\u023B":"C","\uA73E":"C","\u24B9":"D","\uFF24":"D","\u1E0A":"D","\u010E":"D","\u1E0C":"D","\u1E10":"D","\u1E12":"D","\u1E0E":"D","\u0110":"D","\u018B":"D","\u018A":"D","\u0189":"D","\uA779":"D","\u01F1":"DZ","\u01C4":"DZ","\u01F2":"Dz","\u01C5":"Dz","\u24BA":"E","\uFF25":"E","\u00C8":"E","\u00C9":"E","\u00CA":"E","\u1EC0":"E","\u1EBE":"E","\u1EC4":"E","\u1EC2":"E","\u1EBC":"E","\u0112":"E","\u1E14":"E","\u1E16":"E","\u0114":"E","\u0116":"E","\u00CB":"E","\u1EBA":"E","\u011A":"E","\u0204":"E","\u0206":"E","\u1EB8":"E","\u1EC6":"E","\u0228":"E","\u1E1C":"E","\u0118":"E","\u1E18":"E","\u1E1A":"E","\u0190":"E","\u018E":"E","\u24BB":"F","\uFF26":"F","\u1E1E":"F","\u0191":"F","\uA77B":"F","\u24BC":"G","\uFF27":"G","\u01F4":"G","\u011C":"G","\u1E20":"G","\u011E":"G","\u0120":"G","\u01E6":"G","\u0122":"G","\u01E4":"G","\u0193":"G","\uA7A0":"G","\uA77D":"G","\uA77E":"G","\u24BD":"H","\uFF28":"H","\u0124":"H","\u1E22":"H","\u1E26":"H","\u021E":"H","\u1E24":"H","\u1E28":"H","\u1E2A":"H","\u0126":"H","\u2C67":"H","\u2C75":"H","\uA78D":"H","\u24BE":"I","\uFF29":"I","\u00CC":"I","\u00CD":"I","\u00CE":"I","\u0128":"I","\u012A":"I","\u012C":"I","\u0130":"I","\u00CF":"I","\u1E2E":"I","\u1EC8":"I","\u01CF":"I","\u0208":"I","\u020A":"I","\u1ECA":"I","\u012E":"I","\u1E2C":"I","\u0197":"I","\u24BF":"J","\uFF2A":"J","\u0134":"J","\u0248":"J","\u24C0":"K","\uFF2B":"K","\u1E30":"K","\u01E8":"K","\u1E32":"K","\u0136":"K","\u1E34":"K","\u0198":"K","\u2C69":"K","\uA740":"K","\uA742":"K","\uA744":"K","\uA7A2":"K","\u24C1":"L","\uFF2C":"L","\u013F":"L","\u0139":"L","\u013D":"L","\u1E36":"L","\u1E38":"L","\u013B":"L","\u1E3C":"L","\u1E3A":"L","\u0141":"L","\u023D":"L","\u2C62":"L","\u2C60":"L","\uA748":"L","\uA746":"L","\uA780":"L","\u01C7":"LJ","\u01C8":"Lj","\u24C2":"M","\uFF2D":"M","\u1E3E":"M","\u1E40":"M","\u1E42":"M","\u2C6E":"M","\u019C":"M","\u24C3":"N","\uFF2E":"N","\u01F8":"N","\u0143":"N","\u00D1":"N","\u1E44":"N","\u0147":"N","\u1E46":"N","\u0145":"N","\u1E4A":"N","\u1E48":"N","\u0220":"N","\u019D":"N","\uA790":"N","\uA7A4":"N","\u01CA":"NJ","\u01CB":"Nj","\u24C4":"O","\uFF2F":"O","\u00D2":"O","\u00D3":"O","\u00D4":"O","\u1ED2":"O","\u1ED0":"O","\u1ED6":"O","\u1ED4":"O","\u00D5":"O","\u1E4C":"O","\u022C":"O","\u1E4E":"O","\u014C":"O","\u1E50":"O","\u1E52":"O","\u014E":"O","\u022E":"O","\u0230":"O","\u00D6":"O","\u022A":"O","\u1ECE":"O","\u0150":"O","\u01D1":"O","\u020C":"O","\u020E":"O","\u01A0":"O","\u1EDC":"O","\u1EDA":"O","\u1EE0":"O","\u1EDE":"O","\u1EE2":"O","\u1ECC":"O","\u1ED8":"O","\u01EA":"O","\u01EC":"O","\u00D8":"O","\u01FE":"O","\u0186":"O","\u019F":"O","\uA74A":"O","\uA74C":"O","\u01A2":"OI","\uA74E":"OO","\u0222":"OU","\u24C5":"P","\uFF30":"P","\u1E54":"P","\u1E56":"P","\u01A4":"P","\u2C63":"P","\uA750":"P","\uA752":"P","\uA754":"P","\u24C6":"Q","\uFF31":"Q","\uA756":"Q","\uA758":"Q","\u024A":"Q","\u24C7":"R","\uFF32":"R","\u0154":"R","\u1E58":"R","\u0158":"R","\u0210":"R","\u0212":"R","\u1E5A":"R","\u1E5C":"R","\u0156":"R","\u1E5E":"R","\u024C":"R","\u2C64":"R","\uA75A":"R","\uA7A6":"R","\uA782":"R","\u24C8":"S","\uFF33":"S","\u1E9E":"S","\u015A":"S","\u1E64":"S","\u015C":"S","\u1E60":"S","\u0160":"S","\u1E66":"S","\u1E62":"S","\u1E68":"S","\u0218":"S","\u015E":"S","\u2C7E":"S","\uA7A8":"S","\uA784":"S","\u24C9":"T","\uFF34":"T","\u1E6A":"T","\u0164":"T","\u1E6C":"T","\u021A":"T","\u0162":"T","\u1E70":"T","\u1E6E":"T","\u0166":"T","\u01AC":"T","\u01AE":"T","\u023E":"T","\uA786":"T","\uA728":"TZ","\u24CA":"U","\uFF35":"U","\u00D9":"U","\u00DA":"U","\u00DB":"U","\u0168":"U","\u1E78":"U","\u016A":"U","\u1E7A":"U","\u016C":"U","\u00DC":"U","\u01DB":"U","\u01D7":"U","\u01D5":"U","\u01D9":"U","\u1EE6":"U","\u016E":"U","\u0170":"U","\u01D3":"U","\u0214":"U","\u0216":"U","\u01AF":"U","\u1EEA":"U","\u1EE8":"U","\u1EEE":"U","\u1EEC":"U","\u1EF0":"U","\u1EE4":"U","\u1E72":"U","\u0172":"U","\u1E76":"U","\u1E74":"U","\u0244":"U","\u24CB":"V","\uFF36":"V","\u1E7C":"V","\u1E7E":"V","\u01B2":"V","\uA75E":"V","\u0245":"V","\uA760":"VY","\u24CC":"W","\uFF37":"W","\u1E80":"W","\u1E82":"W","\u0174":"W","\u1E86":"W","\u1E84":"W","\u1E88":"W","\u2C72":"W","\u24CD":"X","\uFF38":"X","\u1E8A":"X","\u1E8C":"X","\u24CE":"Y","\uFF39":"Y","\u1EF2":"Y","\u00DD":"Y","\u0176":"Y","\u1EF8":"Y","\u0232":"Y","\u1E8E":"Y","\u0178":"Y","\u1EF6":"Y","\u1EF4":"Y","\u01B3":"Y","\u024E":"Y","\u1EFE":"Y","\u24CF":"Z","\uFF3A":"Z","\u0179":"Z","\u1E90":"Z","\u017B":"Z","\u017D":"Z","\u1E92":"Z","\u1E94":"Z","\u01B5":"Z","\u0224":"Z","\u2C7F":"Z","\u2C6B":"Z","\uA762":"Z","\u24D0":"a","\uFF41":"a","\u1E9A":"a","\u00E0":"a","\u00E1":"a","\u00E2":"a","\u1EA7":"a","\u1EA5":"a","\u1EAB":"a","\u1EA9":"a","\u00E3":"a","\u0101":"a","\u0103":"a","\u1EB1":"a","\u1EAF":"a","\u1EB5":"a","\u1EB3":"a","\u0227":"a","\u01E1":"a","\u00E4":"a","\u01DF":"a","\u1EA3":"a","\u00E5":"a","\u01FB":"a","\u01CE":"a","\u0201":"a","\u0203":"a","\u1EA1":"a","\u1EAD":"a","\u1EB7":"a","\u1E01":"a","\u0105":"a","\u2C65":"a","\u0250":"a","\uA733":"aa","\u00E6":"ae","\u01FD":"ae","\u01E3":"ae","\uA735":"ao","\uA737":"au","\uA739":"av","\uA73B":"av","\uA73D":"ay","\u24D1":"b","\uFF42":"b","\u1E03":"b","\u1E05":"b","\u1E07":"b","\u0180":"b","\u0183":"b","\u0253":"b","\u24D2":"c","\uFF43":"c","\u0107":"c","\u0109":"c","\u010B":"c","\u010D":"c","\u00E7":"c","\u1E09":"c","\u0188":"c","\u023C":"c","\uA73F":"c","\u2184":"c","\u24D3":"d","\uFF44":"d","\u1E0B":"d","\u010F":"d","\u1E0D":"d","\u1E11":"d","\u1E13":"d","\u1E0F":"d","\u0111":"d","\u018C":"d","\u0256":"d","\u0257":"d","\uA77A":"d","\u01F3":"dz","\u01C6":"dz","\u24D4":"e","\uFF45":"e","\u00E8":"e","\u00E9":"e","\u00EA":"e","\u1EC1":"e","\u1EBF":"e","\u1EC5":"e","\u1EC3":"e","\u1EBD":"e","\u0113":"e","\u1E15":"e","\u1E17":"e","\u0115":"e","\u0117":"e","\u00EB":"e","\u1EBB":"e","\u011B":"e","\u0205":"e","\u0207":"e","\u1EB9":"e","\u1EC7":"e","\u0229":"e","\u1E1D":"e","\u0119":"e","\u1E19":"e","\u1E1B":"e","\u0247":"e","\u025B":"e","\u01DD":"e","\u24D5":"f","\uFF46":"f","\u1E1F":"f","\u0192":"f","\uA77C":"f","\u24D6":"g","\uFF47":"g","\u01F5":"g","\u011D":"g","\u1E21":"g","\u011F":"g","\u0121":"g","\u01E7":"g","\u0123":"g","\u01E5":"g","\u0260":"g","\uA7A1":"g","\u1D79":"g","\uA77F":"g","\u24D7":"h","\uFF48":"h","\u0125":"h","\u1E23":"h","\u1E27":"h","\u021F":"h","\u1E25":"h","\u1E29":"h","\u1E2B":"h","\u1E96":"h","\u0127":"h","\u2C68":"h","\u2C76":"h","\u0265":"h","\u0195":"hv","\u24D8":"i","\uFF49":"i","\u00EC":"i","\u00ED":"i","\u00EE":"i","\u0129":"i","\u012B":"i","\u012D":"i","\u00EF":"i","\u1E2F":"i","\u1EC9":"i","\u01D0":"i","\u0209":"i","\u020B":"i","\u1ECB":"i","\u012F":"i","\u1E2D":"i","\u0268":"i","\u0131":"i","\u24D9":"j","\uFF4A":"j","\u0135":"j","\u01F0":"j","\u0249":"j","\u24DA":"k","\uFF4B":"k","\u1E31":"k","\u01E9":"k","\u1E33":"k","\u0137":"k","\u1E35":"k","\u0199":"k","\u2C6A":"k","\uA741":"k","\uA743":"k","\uA745":"k","\uA7A3":"k","\u24DB":"l","\uFF4C":"l","\u0140":"l","\u013A":"l","\u013E":"l","\u1E37":"l","\u1E39":"l","\u013C":"l","\u1E3D":"l","\u1E3B":"l","\u017F":"l","\u0142":"l","\u019A":"l","\u026B":"l","\u2C61":"l","\uA749":"l","\uA781":"l","\uA747":"l","\u01C9":"lj","\u24DC":"m","\uFF4D":"m","\u1E3F":"m","\u1E41":"m","\u1E43":"m","\u0271":"m","\u026F":"m","\u24DD":"n","\uFF4E":"n","\u01F9":"n","\u0144":"n","\u00F1":"n","\u1E45":"n","\u0148":"n","\u1E47":"n","\u0146":"n","\u1E4B":"n","\u1E49":"n","\u019E":"n","\u0272":"n","\u0149":"n","\uA791":"n","\uA7A5":"n","\u01CC":"nj","\u24DE":"o","\uFF4F":"o","\u00F2":"o","\u00F3":"o","\u00F4":"o","\u1ED3":"o","\u1ED1":"o","\u1ED7":"o","\u1ED5":"o","\u00F5":"o","\u1E4D":"o","\u022D":"o","\u1E4F":"o","\u014D":"o","\u1E51":"o","\u1E53":"o","\u014F":"o","\u022F":"o","\u0231":"o","\u00F6":"o","\u022B":"o","\u1ECF":"o","\u0151":"o","\u01D2":"o","\u020D":"o","\u020F":"o","\u01A1":"o","\u1EDD":"o","\u1EDB":"o","\u1EE1":"o","\u1EDF":"o","\u1EE3":"o","\u1ECD":"o","\u1ED9":"o","\u01EB":"o","\u01ED":"o","\u00F8":"o","\u01FF":"o","\u0254":"o","\uA74B":"o","\uA74D":"o","\u0275":"o","\u01A3":"oi","\u0223":"ou","\uA74F":"oo","\u24DF":"p","\uFF50":"p","\u1E55":"p","\u1E57":"p","\u01A5":"p","\u1D7D":"p","\uA751":"p","\uA753":"p","\uA755":"p","\u24E0":"q","\uFF51":"q","\u024B":"q","\uA757":"q","\uA759":"q","\u24E1":"r","\uFF52":"r","\u0155":"r","\u1E59":"r","\u0159":"r","\u0211":"r","\u0213":"r","\u1E5B":"r","\u1E5D":"r","\u0157":"r","\u1E5F":"r","\u024D":"r","\u027D":"r","\uA75B":"r","\uA7A7":"r","\uA783":"r","\u24E2":"s","\uFF53":"s","\u00DF":"s","\u015B":"s","\u1E65":"s","\u015D":"s","\u1E61":"s","\u0161":"s","\u1E67":"s","\u1E63":"s","\u1E69":"s","\u0219":"s","\u015F":"s","\u023F":"s","\uA7A9":"s","\uA785":"s","\u1E9B":"s","\u24E3":"t","\uFF54":"t","\u1E6B":"t","\u1E97":"t","\u0165":"t","\u1E6D":"t","\u021B":"t","\u0163":"t","\u1E71":"t","\u1E6F":"t","\u0167":"t","\u01AD":"t","\u0288":"t","\u2C66":"t","\uA787":"t","\uA729":"tz","\u24E4":"u","\uFF55":"u","\u00F9":"u","\u00FA":"u","\u00FB":"u","\u0169":"u","\u1E79":"u","\u016B":"u","\u1E7B":"u","\u016D":"u","\u00FC":"u","\u01DC":"u","\u01D8":"u","\u01D6":"u","\u01DA":"u","\u1EE7":"u","\u016F":"u","\u0171":"u","\u01D4":"u","\u0215":"u","\u0217":"u","\u01B0":"u","\u1EEB":"u","\u1EE9":"u","\u1EEF":"u","\u1EED":"u","\u1EF1":"u","\u1EE5":"u","\u1E73":"u","\u0173":"u","\u1E77":"u","\u1E75":"u","\u0289":"u","\u24E5":"v","\uFF56":"v","\u1E7D":"v","\u1E7F":"v","\u028B":"v","\uA75F":"v","\u028C":"v","\uA761":"vy","\u24E6":"w","\uFF57":"w","\u1E81":"w","\u1E83":"w","\u0175":"w","\u1E87":"w","\u1E85":"w","\u1E98":"w","\u1E89":"w","\u2C73":"w","\u24E7":"x","\uFF58":"x","\u1E8B":"x","\u1E8D":"x","\u24E8":"y","\uFF59":"y","\u1EF3":"y","\u00FD":"y","\u0177":"y","\u1EF9":"y","\u0233":"y","\u1E8F":"y","\u00FF":"y","\u1EF7":"y","\u1E99":"y","\u1EF5":"y","\u01B4":"y","\u024F":"y","\u1EFF":"y","\u24E9":"z","\uFF5A":"z","\u017A":"z","\u1E91":"z","\u017C":"z","\u017E":"z","\u1E93":"z","\u1E95":"z","\u01B6":"z","\u0225":"z","\u0240":"z","\u2C6C":"z","\uA763":"z"};
|
102
|
-
|
103
|
-
$document = $(document);
|
104
|
-
|
105
|
-
nextUid=(function() { var counter=1; return function() { return counter++; }; }());
|
106
|
-
|
107
|
-
|
108
|
-
function reinsertElement(element) {
|
109
|
-
var placeholder = $(document.createTextNode(''));
|
110
|
-
|
111
|
-
element.before(placeholder);
|
112
|
-
placeholder.before(element);
|
113
|
-
placeholder.remove();
|
114
|
-
}
|
115
|
-
|
116
|
-
function stripDiacritics(str) {
|
117
|
-
// Used 'uni range + named function' from http://jsperf.com/diacritics/18
|
118
|
-
function match(a) {
|
119
|
-
return DIACRITICS[a] || a;
|
120
|
-
}
|
121
|
-
|
122
|
-
return str.replace(/[^\u0000-\u007E]/g, match);
|
123
|
-
}
|
124
|
-
|
125
|
-
function indexOf(value, array) {
|
126
|
-
var i = 0, l = array.length;
|
127
|
-
for (; i < l; i = i + 1) {
|
128
|
-
if (equal(value, array[i])) return i;
|
129
|
-
}
|
130
|
-
return -1;
|
131
|
-
}
|
132
|
-
|
133
|
-
function measureScrollbar () {
|
134
|
-
var $template = $( MEASURE_SCROLLBAR_TEMPLATE );
|
135
|
-
$template.appendTo('body');
|
136
|
-
|
137
|
-
var dim = {
|
138
|
-
width: $template.width() - $template[0].clientWidth,
|
139
|
-
height: $template.height() - $template[0].clientHeight
|
140
|
-
};
|
141
|
-
$template.remove();
|
142
|
-
|
143
|
-
return dim;
|
144
|
-
}
|
145
|
-
|
146
|
-
/**
|
147
|
-
* Compares equality of a and b
|
148
|
-
* @param a
|
149
|
-
* @param b
|
150
|
-
*/
|
151
|
-
function equal(a, b) {
|
152
|
-
if (a === b) return true;
|
153
|
-
if (a === undefined || b === undefined) return false;
|
154
|
-
if (a === null || b === null) return false;
|
155
|
-
// Check whether 'a' or 'b' is a string (primitive or object).
|
156
|
-
// The concatenation of an empty string (+'') converts its argument to a string's primitive.
|
157
|
-
if (a.constructor === String) return a+'' === b+''; // a+'' - in case 'a' is a String object
|
158
|
-
if (b.constructor === String) return b+'' === a+''; // b+'' - in case 'b' is a String object
|
159
|
-
return false;
|
160
|
-
}
|
161
|
-
|
162
|
-
/**
|
163
|
-
* Splits the string into an array of values, trimming each value. An empty array is returned for nulls or empty
|
164
|
-
* strings
|
165
|
-
* @param string
|
166
|
-
* @param separator
|
167
|
-
*/
|
168
|
-
function splitVal(string, separator) {
|
169
|
-
var val, i, l;
|
170
|
-
if (string === null || string.length < 1) return [];
|
171
|
-
val = string.split(separator);
|
172
|
-
for (i = 0, l = val.length; i < l; i = i + 1) val[i] = $.trim(val[i]);
|
173
|
-
return val;
|
174
|
-
}
|
175
|
-
|
176
|
-
function getSideBorderPadding(element) {
|
177
|
-
return element.outerWidth(false) - element.width();
|
178
|
-
}
|
179
|
-
|
180
|
-
function installKeyUpChangeEvent(element) {
|
181
|
-
var key="keyup-change-value";
|
182
|
-
element.on("keydown", function () {
|
183
|
-
if ($.data(element, key) === undefined) {
|
184
|
-
$.data(element, key, element.val());
|
185
|
-
}
|
186
|
-
});
|
187
|
-
element.on("keyup", function () {
|
188
|
-
var val= $.data(element, key);
|
189
|
-
if (val !== undefined && element.val() !== val) {
|
190
|
-
$.removeData(element, key);
|
191
|
-
element.trigger("keyup-change");
|
192
|
-
}
|
193
|
-
});
|
194
|
-
}
|
195
|
-
|
196
|
-
$document.on("mousemove", function (e) {
|
197
|
-
lastMousePosition.x = e.pageX;
|
198
|
-
lastMousePosition.y = e.pageY;
|
199
|
-
});
|
200
|
-
|
201
|
-
/**
|
202
|
-
* filters mouse events so an event is fired only if the mouse moved.
|
203
|
-
*
|
204
|
-
* filters out mouse events that occur when mouse is stationary but
|
205
|
-
* the elements under the pointer are scrolled.
|
206
|
-
*/
|
207
|
-
function installFilteredMouseMove(element) {
|
208
|
-
element.on("mousemove", function (e) {
|
209
|
-
var lastpos = lastMousePosition;
|
210
|
-
if (lastpos === undefined || lastpos.x !== e.pageX || lastpos.y !== e.pageY) {
|
211
|
-
$(e.target).trigger("mousemove-filtered", e);
|
212
|
-
}
|
213
|
-
});
|
214
|
-
}
|
215
|
-
|
216
|
-
/**
|
217
|
-
* Debounces a function. Returns a function that calls the original fn function only if no invocations have been made
|
218
|
-
* within the last quietMillis milliseconds.
|
219
|
-
*
|
220
|
-
* @param quietMillis number of milliseconds to wait before invoking fn
|
221
|
-
* @param fn function to be debounced
|
222
|
-
* @param ctx object to be used as this reference within fn
|
223
|
-
* @return debounced version of fn
|
224
|
-
*/
|
225
|
-
function debounce(quietMillis, fn, ctx) {
|
226
|
-
ctx = ctx || undefined;
|
227
|
-
var timeout;
|
228
|
-
return function () {
|
229
|
-
var args = arguments;
|
230
|
-
window.clearTimeout(timeout);
|
231
|
-
timeout = window.setTimeout(function() {
|
232
|
-
fn.apply(ctx, args);
|
233
|
-
}, quietMillis);
|
234
|
-
};
|
235
|
-
}
|
236
|
-
|
237
|
-
function installDebouncedScroll(threshold, element) {
|
238
|
-
var notify = debounce(threshold, function (e) { element.trigger("scroll-debounced", e);});
|
239
|
-
element.on("scroll", function (e) {
|
240
|
-
if (indexOf(e.target, element.get()) >= 0) notify(e);
|
241
|
-
});
|
242
|
-
}
|
243
|
-
|
244
|
-
function focus($el) {
|
245
|
-
if ($el[0] === document.activeElement) return;
|
246
|
-
|
247
|
-
/* set the focus in a 0 timeout - that way the focus is set after the processing
|
248
|
-
of the current event has finished - which seems like the only reliable way
|
249
|
-
to set focus */
|
250
|
-
window.setTimeout(function() {
|
251
|
-
var el=$el[0], pos=$el.val().length, range;
|
252
|
-
|
253
|
-
$el.focus();
|
254
|
-
|
255
|
-
/* make sure el received focus so we do not error out when trying to manipulate the caret.
|
256
|
-
sometimes modals or others listeners may steal it after its set */
|
257
|
-
var isVisible = (el.offsetWidth > 0 || el.offsetHeight > 0);
|
258
|
-
if (isVisible && el === document.activeElement) {
|
259
|
-
|
260
|
-
/* after the focus is set move the caret to the end, necessary when we val()
|
261
|
-
just before setting focus */
|
262
|
-
if(el.setSelectionRange)
|
263
|
-
{
|
264
|
-
el.setSelectionRange(pos, pos);
|
265
|
-
}
|
266
|
-
else if (el.createTextRange) {
|
267
|
-
range = el.createTextRange();
|
268
|
-
range.collapse(false);
|
269
|
-
range.select();
|
270
|
-
}
|
271
|
-
}
|
272
|
-
}, 0);
|
273
|
-
}
|
274
|
-
|
275
|
-
function getCursorInfo(el) {
|
276
|
-
el = $(el)[0];
|
277
|
-
var offset = 0;
|
278
|
-
var length = 0;
|
279
|
-
if ('selectionStart' in el) {
|
280
|
-
offset = el.selectionStart;
|
281
|
-
length = el.selectionEnd - offset;
|
282
|
-
} else if ('selection' in document) {
|
283
|
-
el.focus();
|
284
|
-
var sel = document.selection.createRange();
|
285
|
-
length = document.selection.createRange().text.length;
|
286
|
-
sel.moveStart('character', -el.value.length);
|
287
|
-
offset = sel.text.length - length;
|
288
|
-
}
|
289
|
-
return { offset: offset, length: length };
|
290
|
-
}
|
291
|
-
|
292
|
-
function killEvent(event) {
|
293
|
-
event.preventDefault();
|
294
|
-
event.stopPropagation();
|
295
|
-
}
|
296
|
-
function killEventImmediately(event) {
|
297
|
-
event.preventDefault();
|
298
|
-
event.stopImmediatePropagation();
|
299
|
-
}
|
300
|
-
|
301
|
-
function measureTextWidth(e) {
|
302
|
-
if (!sizer){
|
303
|
-
var style = e[0].currentStyle || window.getComputedStyle(e[0], null);
|
304
|
-
sizer = $(document.createElement("div")).css({
|
305
|
-
position: "absolute",
|
306
|
-
left: "-10000px",
|
307
|
-
top: "-10000px",
|
308
|
-
display: "none",
|
309
|
-
fontSize: style.fontSize,
|
310
|
-
fontFamily: style.fontFamily,
|
311
|
-
fontStyle: style.fontStyle,
|
312
|
-
fontWeight: style.fontWeight,
|
313
|
-
letterSpacing: style.letterSpacing,
|
314
|
-
textTransform: style.textTransform,
|
315
|
-
whiteSpace: "nowrap"
|
316
|
-
});
|
317
|
-
sizer.attr("class","select2-sizer");
|
318
|
-
$("body").append(sizer);
|
319
|
-
}
|
320
|
-
sizer.text(e.val());
|
321
|
-
return sizer.width();
|
322
|
-
}
|
323
|
-
|
324
|
-
function syncCssClasses(dest, src, adapter) {
|
325
|
-
var classes, replacements = [], adapted;
|
326
|
-
|
327
|
-
classes = dest.attr("class");
|
328
|
-
if (classes) {
|
329
|
-
classes = '' + classes; // for IE which returns object
|
330
|
-
$(classes.split(" ")).each2(function() {
|
331
|
-
if (this.indexOf("select2-") === 0) {
|
332
|
-
replacements.push(this);
|
333
|
-
}
|
334
|
-
});
|
335
|
-
}
|
336
|
-
classes = src.attr("class");
|
337
|
-
if (classes) {
|
338
|
-
classes = '' + classes; // for IE which returns object
|
339
|
-
$(classes.split(" ")).each2(function() {
|
340
|
-
if (this.indexOf("select2-") !== 0) {
|
341
|
-
adapted = adapter(this);
|
342
|
-
if (adapted) {
|
343
|
-
replacements.push(adapted);
|
344
|
-
}
|
345
|
-
}
|
346
|
-
});
|
347
|
-
}
|
348
|
-
dest.attr("class", replacements.join(" "));
|
349
|
-
}
|
350
|
-
|
351
|
-
|
352
|
-
function markMatch(text, term, markup, escapeMarkup) {
|
353
|
-
var match=stripDiacritics(text.toUpperCase()).indexOf(stripDiacritics(term.toUpperCase())),
|
354
|
-
tl=term.length;
|
355
|
-
|
356
|
-
if (match<0) {
|
357
|
-
markup.push(escapeMarkup(text));
|
358
|
-
return;
|
359
|
-
}
|
360
|
-
|
361
|
-
markup.push(escapeMarkup(text.substring(0, match)));
|
362
|
-
markup.push("<span class='select2-match'>");
|
363
|
-
markup.push(escapeMarkup(text.substring(match, match + tl)));
|
364
|
-
markup.push("</span>");
|
365
|
-
markup.push(escapeMarkup(text.substring(match + tl, text.length)));
|
366
|
-
}
|
367
|
-
|
368
|
-
function defaultEscapeMarkup(markup) {
|
369
|
-
var replace_map = {
|
370
|
-
'\\': '\',
|
371
|
-
'&': '&',
|
372
|
-
'<': '<',
|
373
|
-
'>': '>',
|
374
|
-
'"': '"',
|
375
|
-
"'": ''',
|
376
|
-
"/": '/'
|
377
|
-
};
|
378
|
-
|
379
|
-
return String(markup).replace(/[&<>"'\/\\]/g, function (match) {
|
380
|
-
return replace_map[match];
|
381
|
-
});
|
382
|
-
}
|
383
|
-
|
384
|
-
/**
|
385
|
-
* Produces an ajax-based query function
|
386
|
-
*
|
387
|
-
* @param options object containing configuration parameters
|
388
|
-
* @param options.params parameter map for the transport ajax call, can contain such options as cache, jsonpCallback, etc. see $.ajax
|
389
|
-
* @param options.transport function that will be used to execute the ajax request. must be compatible with parameters supported by $.ajax
|
390
|
-
* @param options.url url for the data
|
391
|
-
* @param options.data a function(searchTerm, pageNumber, context) that should return an object containing query string parameters for the above url.
|
392
|
-
* @param options.dataType request data type: ajax, jsonp, other datatypes supported by jQuery's $.ajax function or the transport function if specified
|
393
|
-
* @param options.quietMillis (optional) milliseconds to wait before making the ajaxRequest, helps debounce the ajax function if invoked too often
|
394
|
-
* @param options.results a function(remoteData, pageNumber) that converts data returned form the remote request to the format expected by Select2.
|
395
|
-
* The expected format is an object containing the following keys:
|
396
|
-
* results array of objects that will be used as choices
|
397
|
-
* more (optional) boolean indicating whether there are more results available
|
398
|
-
* Example: {results:[{id:1, text:'Red'},{id:2, text:'Blue'}], more:true}
|
399
|
-
*/
|
400
|
-
function ajax(options) {
|
401
|
-
var timeout, // current scheduled but not yet executed request
|
402
|
-
handler = null,
|
403
|
-
quietMillis = options.quietMillis || 100,
|
404
|
-
ajaxUrl = options.url,
|
405
|
-
self = this;
|
406
|
-
|
407
|
-
return function (query) {
|
408
|
-
window.clearTimeout(timeout);
|
409
|
-
timeout = window.setTimeout(function () {
|
410
|
-
var data = options.data, // ajax data function
|
411
|
-
url = ajaxUrl, // ajax url string or function
|
412
|
-
transport = options.transport || $.fn.select2.ajaxDefaults.transport,
|
413
|
-
// deprecated - to be removed in 4.0 - use params instead
|
414
|
-
deprecated = {
|
415
|
-
type: options.type || 'GET', // set type of request (GET or POST)
|
416
|
-
cache: options.cache || false,
|
417
|
-
jsonpCallback: options.jsonpCallback||undefined,
|
418
|
-
dataType: options.dataType||"json"
|
419
|
-
},
|
420
|
-
params = $.extend({}, $.fn.select2.ajaxDefaults.params, deprecated);
|
421
|
-
|
422
|
-
data = data ? data.call(self, query.term, query.page, query.context) : null;
|
423
|
-
url = (typeof url === 'function') ? url.call(self, query.term, query.page, query.context) : url;
|
424
|
-
|
425
|
-
if (handler && typeof handler.abort === "function") { handler.abort(); }
|
426
|
-
|
427
|
-
if (options.params) {
|
428
|
-
if ($.isFunction(options.params)) {
|
429
|
-
$.extend(params, options.params.call(self));
|
430
|
-
} else {
|
431
|
-
$.extend(params, options.params);
|
432
|
-
}
|
433
|
-
}
|
434
|
-
|
435
|
-
$.extend(params, {
|
436
|
-
url: url,
|
437
|
-
dataType: options.dataType,
|
438
|
-
data: data,
|
439
|
-
success: function (data) {
|
440
|
-
// TODO - replace query.page with query so users have access to term, page, etc.
|
441
|
-
var results = options.results(data, query.page);
|
442
|
-
query.callback(results);
|
443
|
-
}
|
444
|
-
});
|
445
|
-
handler = transport.call(self, params);
|
446
|
-
}, quietMillis);
|
447
|
-
};
|
448
|
-
}
|
449
|
-
|
450
|
-
/**
|
451
|
-
* Produces a query function that works with a local array
|
452
|
-
*
|
453
|
-
* @param options object containing configuration parameters. The options parameter can either be an array or an
|
454
|
-
* object.
|
455
|
-
*
|
456
|
-
* If the array form is used it is assumed that it contains objects with 'id' and 'text' keys.
|
457
|
-
*
|
458
|
-
* If the object form is used it is assumed that it contains 'data' and 'text' keys. The 'data' key should contain
|
459
|
-
* an array of objects that will be used as choices. These objects must contain at least an 'id' key. The 'text'
|
460
|
-
* key can either be a String in which case it is expected that each element in the 'data' array has a key with the
|
461
|
-
* value of 'text' which will be used to match choices. Alternatively, text can be a function(item) that can extract
|
462
|
-
* the text.
|
463
|
-
*/
|
464
|
-
function local(options) {
|
465
|
-
var data = options, // data elements
|
466
|
-
dataText,
|
467
|
-
tmp,
|
468
|
-
text = function (item) { return ""+item.text; }; // function used to retrieve the text portion of a data item that is matched against the search
|
469
|
-
|
470
|
-
if ($.isArray(data)) {
|
471
|
-
tmp = data;
|
472
|
-
data = { results: tmp };
|
473
|
-
}
|
474
|
-
|
475
|
-
if ($.isFunction(data) === false) {
|
476
|
-
tmp = data;
|
477
|
-
data = function() { return tmp; };
|
478
|
-
}
|
479
|
-
|
480
|
-
var dataItem = data();
|
481
|
-
if (dataItem.text) {
|
482
|
-
text = dataItem.text;
|
483
|
-
// if text is not a function we assume it to be a key name
|
484
|
-
if (!$.isFunction(text)) {
|
485
|
-
dataText = dataItem.text; // we need to store this in a separate variable because in the next step data gets reset and data.text is no longer available
|
486
|
-
text = function (item) { return item[dataText]; };
|
487
|
-
}
|
488
|
-
}
|
489
|
-
|
490
|
-
return function (query) {
|
491
|
-
var t = query.term, filtered = { results: [] }, process;
|
492
|
-
if (t === "") {
|
493
|
-
query.callback(data());
|
494
|
-
return;
|
495
|
-
}
|
496
|
-
|
497
|
-
process = function(datum, collection) {
|
498
|
-
var group, attr;
|
499
|
-
datum = datum[0];
|
500
|
-
if (datum.children) {
|
501
|
-
group = {};
|
502
|
-
for (attr in datum) {
|
503
|
-
if (datum.hasOwnProperty(attr)) group[attr]=datum[attr];
|
504
|
-
}
|
505
|
-
group.children=[];
|
506
|
-
$(datum.children).each2(function(i, childDatum) { process(childDatum, group.children); });
|
507
|
-
if (group.children.length || query.matcher(t, text(group), datum)) {
|
508
|
-
collection.push(group);
|
509
|
-
}
|
510
|
-
} else {
|
511
|
-
if (query.matcher(t, text(datum), datum)) {
|
512
|
-
collection.push(datum);
|
513
|
-
}
|
514
|
-
}
|
515
|
-
};
|
516
|
-
|
517
|
-
$(data().results).each2(function(i, datum) { process(datum, filtered.results); });
|
518
|
-
query.callback(filtered);
|
519
|
-
};
|
520
|
-
}
|
521
|
-
|
522
|
-
// TODO javadoc
|
523
|
-
function tags(data) {
|
524
|
-
var isFunc = $.isFunction(data);
|
525
|
-
return function (query) {
|
526
|
-
var t = query.term, filtered = {results: []};
|
527
|
-
var result = isFunc ? data(query) : data;
|
528
|
-
if ($.isArray(result)) {
|
529
|
-
$(result).each(function () {
|
530
|
-
var isObject = this.text !== undefined,
|
531
|
-
text = isObject ? this.text : this;
|
532
|
-
if (t === "" || query.matcher(t, text)) {
|
533
|
-
filtered.results.push(isObject ? this : {id: this, text: this});
|
534
|
-
}
|
535
|
-
});
|
536
|
-
query.callback(filtered);
|
537
|
-
}
|
538
|
-
};
|
539
|
-
}
|
540
|
-
|
541
|
-
/**
|
542
|
-
* Checks if the formatter function should be used.
|
543
|
-
*
|
544
|
-
* Throws an error if it is not a function. Returns true if it should be used,
|
545
|
-
* false if no formatting should be performed.
|
546
|
-
*
|
547
|
-
* @param formatter
|
548
|
-
*/
|
549
|
-
function checkFormatter(formatter, formatterName) {
|
550
|
-
if ($.isFunction(formatter)) return true;
|
551
|
-
if (!formatter) return false;
|
552
|
-
if (typeof(formatter) === 'string') return true;
|
553
|
-
throw new Error(formatterName +" must be a string, function, or falsy value");
|
554
|
-
}
|
555
|
-
|
556
|
-
function evaluate(val) {
|
557
|
-
if ($.isFunction(val)) {
|
558
|
-
var args = Array.prototype.slice.call(arguments, 1);
|
559
|
-
return val.apply(null, args);
|
560
|
-
}
|
561
|
-
return val;
|
562
|
-
}
|
563
|
-
|
564
|
-
function countResults(results) {
|
565
|
-
var count = 0;
|
566
|
-
$.each(results, function(i, item) {
|
567
|
-
if (item.children) {
|
568
|
-
count += countResults(item.children);
|
569
|
-
} else {
|
570
|
-
count++;
|
571
|
-
}
|
572
|
-
});
|
573
|
-
return count;
|
574
|
-
}
|
575
|
-
|
576
|
-
/**
|
577
|
-
* Default tokenizer. This function uses breaks the input on substring match of any string from the
|
578
|
-
* opts.tokenSeparators array and uses opts.createSearchChoice to create the choice object. Both of those
|
579
|
-
* two options have to be defined in order for the tokenizer to work.
|
580
|
-
*
|
581
|
-
* @param input text user has typed so far or pasted into the search field
|
582
|
-
* @param selection currently selected choices
|
583
|
-
* @param selectCallback function(choice) callback tho add the choice to selection
|
584
|
-
* @param opts select2's opts
|
585
|
-
* @return undefined/null to leave the current input unchanged, or a string to change the input to the returned value
|
586
|
-
*/
|
587
|
-
function defaultTokenizer(input, selection, selectCallback, opts) {
|
588
|
-
var original = input, // store the original so we can compare and know if we need to tell the search to update its text
|
589
|
-
dupe = false, // check for whether a token we extracted represents a duplicate selected choice
|
590
|
-
token, // token
|
591
|
-
index, // position at which the separator was found
|
592
|
-
i, l, // looping variables
|
593
|
-
separator; // the matched separator
|
594
|
-
|
595
|
-
if (!opts.createSearchChoice || !opts.tokenSeparators || opts.tokenSeparators.length < 1) return undefined;
|
596
|
-
|
597
|
-
while (true) {
|
598
|
-
index = -1;
|
599
|
-
|
600
|
-
for (i = 0, l = opts.tokenSeparators.length; i < l; i++) {
|
601
|
-
separator = opts.tokenSeparators[i];
|
602
|
-
index = input.indexOf(separator);
|
603
|
-
if (index >= 0) break;
|
604
|
-
}
|
605
|
-
|
606
|
-
if (index < 0) break; // did not find any token separator in the input string, bail
|
607
|
-
|
608
|
-
token = input.substring(0, index);
|
609
|
-
input = input.substring(index + separator.length);
|
610
|
-
|
611
|
-
if (token.length > 0) {
|
612
|
-
token = opts.createSearchChoice.call(this, token, selection);
|
613
|
-
if (token !== undefined && token !== null && opts.id(token) !== undefined && opts.id(token) !== null) {
|
614
|
-
dupe = false;
|
615
|
-
for (i = 0, l = selection.length; i < l; i++) {
|
616
|
-
if (equal(opts.id(token), opts.id(selection[i]))) {
|
617
|
-
dupe = true; break;
|
618
|
-
}
|
619
|
-
}
|
620
|
-
|
621
|
-
if (!dupe) selectCallback(token);
|
622
|
-
}
|
623
|
-
}
|
624
|
-
}
|
625
|
-
|
626
|
-
if (original!==input) return input;
|
627
|
-
}
|
628
|
-
|
629
|
-
function cleanupJQueryElements() {
|
630
|
-
var self = this;
|
631
|
-
|
632
|
-
Array.prototype.forEach.call(arguments, function (element) {
|
633
|
-
self[element].remove();
|
634
|
-
self[element] = null;
|
635
|
-
});
|
636
|
-
}
|
637
|
-
|
638
|
-
/**
|
639
|
-
* Creates a new class
|
640
|
-
*
|
641
|
-
* @param superClass
|
642
|
-
* @param methods
|
643
|
-
*/
|
644
|
-
function clazz(SuperClass, methods) {
|
645
|
-
var constructor = function () {};
|
646
|
-
constructor.prototype = new SuperClass;
|
647
|
-
constructor.prototype.constructor = constructor;
|
648
|
-
constructor.prototype.parent = SuperClass.prototype;
|
649
|
-
constructor.prototype = $.extend(constructor.prototype, methods);
|
650
|
-
return constructor;
|
651
|
-
}
|
652
|
-
|
653
|
-
AbstractSelect2 = clazz(Object, {
|
654
|
-
|
655
|
-
// abstract
|
656
|
-
bind: function (func) {
|
657
|
-
var self = this;
|
658
|
-
return function () {
|
659
|
-
func.apply(self, arguments);
|
660
|
-
};
|
661
|
-
},
|
662
|
-
|
663
|
-
// abstract
|
664
|
-
init: function (opts) {
|
665
|
-
var results, search, resultsSelector = ".select2-results";
|
666
|
-
|
667
|
-
// prepare options
|
668
|
-
this.opts = opts = this.prepareOpts(opts);
|
669
|
-
|
670
|
-
this.id=opts.id;
|
671
|
-
|
672
|
-
// destroy if called on an existing component
|
673
|
-
if (opts.element.data("select2") !== undefined &&
|
674
|
-
opts.element.data("select2") !== null) {
|
675
|
-
opts.element.data("select2").destroy();
|
676
|
-
}
|
677
|
-
|
678
|
-
this.container = this.createContainer();
|
679
|
-
|
680
|
-
this.liveRegion = $("<span>", {
|
681
|
-
role: "status",
|
682
|
-
"aria-live": "polite"
|
683
|
-
})
|
684
|
-
.addClass("select2-hidden-accessible")
|
685
|
-
.appendTo(document.body);
|
686
|
-
|
687
|
-
this.containerId="s2id_"+(opts.element.attr("id") || "autogen"+nextUid());
|
688
|
-
this.containerEventName= this.containerId
|
689
|
-
.replace(/([.])/g, '_')
|
690
|
-
.replace(/([;&,\-\.\+\*\~':"\!\^#$%@\[\]\(\)=>\|])/g, '\\$1');
|
691
|
-
this.container.attr("id", this.containerId);
|
692
|
-
|
693
|
-
this.container.attr("title", opts.element.attr("title"));
|
694
|
-
|
695
|
-
this.body = $("body");
|
696
|
-
|
697
|
-
syncCssClasses(this.container, this.opts.element, this.opts.adaptContainerCssClass);
|
698
|
-
|
699
|
-
this.container.attr("style", opts.element.attr("style"));
|
700
|
-
this.container.css(evaluate(opts.containerCss));
|
701
|
-
this.container.addClass(evaluate(opts.containerCssClass));
|
702
|
-
|
703
|
-
this.elementTabIndex = this.opts.element.attr("tabindex");
|
704
|
-
|
705
|
-
// swap container for the element
|
706
|
-
this.opts.element
|
707
|
-
.data("select2", this)
|
708
|
-
.attr("tabindex", "-1")
|
709
|
-
.before(this.container)
|
710
|
-
.on("click.select2", killEvent); // do not leak click events
|
711
|
-
|
712
|
-
this.container.data("select2", this);
|
713
|
-
|
714
|
-
this.dropdown = this.container.find(".select2-drop");
|
715
|
-
|
716
|
-
syncCssClasses(this.dropdown, this.opts.element, this.opts.adaptDropdownCssClass);
|
717
|
-
|
718
|
-
this.dropdown.addClass(evaluate(opts.dropdownCssClass));
|
719
|
-
this.dropdown.data("select2", this);
|
720
|
-
this.dropdown.on("click", killEvent);
|
721
|
-
|
722
|
-
this.results = results = this.container.find(resultsSelector);
|
723
|
-
this.search = search = this.container.find("input.select2-input");
|
724
|
-
|
725
|
-
this.queryCount = 0;
|
726
|
-
this.resultsPage = 0;
|
727
|
-
this.context = null;
|
728
|
-
|
729
|
-
// initialize the container
|
730
|
-
this.initContainer();
|
731
|
-
|
732
|
-
this.container.on("click", killEvent);
|
733
|
-
|
734
|
-
installFilteredMouseMove(this.results);
|
735
|
-
|
736
|
-
this.dropdown.on("mousemove-filtered", resultsSelector, this.bind(this.highlightUnderEvent));
|
737
|
-
this.dropdown.on("touchstart touchmove touchend", resultsSelector, this.bind(function (event) {
|
738
|
-
this._touchEvent = true;
|
739
|
-
this.highlightUnderEvent(event);
|
740
|
-
}));
|
741
|
-
this.dropdown.on("touchmove", resultsSelector, this.bind(this.touchMoved));
|
742
|
-
this.dropdown.on("touchstart touchend", resultsSelector, this.bind(this.clearTouchMoved));
|
743
|
-
|
744
|
-
// Waiting for a click event on touch devices to select option and hide dropdown
|
745
|
-
// otherwise click will be triggered on an underlying element
|
746
|
-
this.dropdown.on('click', this.bind(function (event) {
|
747
|
-
if (this._touchEvent) {
|
748
|
-
this._touchEvent = false;
|
749
|
-
this.selectHighlighted();
|
750
|
-
}
|
751
|
-
}));
|
752
|
-
|
753
|
-
installDebouncedScroll(80, this.results);
|
754
|
-
this.dropdown.on("scroll-debounced", resultsSelector, this.bind(this.loadMoreIfNeeded));
|
755
|
-
|
756
|
-
// do not propagate change event from the search field out of the component
|
757
|
-
$(this.container).on("change", ".select2-input", function(e) {e.stopPropagation();});
|
758
|
-
$(this.dropdown).on("change", ".select2-input", function(e) {e.stopPropagation();});
|
759
|
-
|
760
|
-
// if jquery.mousewheel plugin is installed we can prevent out-of-bounds scrolling of results via mousewheel
|
761
|
-
if ($.fn.mousewheel) {
|
762
|
-
results.mousewheel(function (e, delta, deltaX, deltaY) {
|
763
|
-
var top = results.scrollTop();
|
764
|
-
if (deltaY > 0 && top - deltaY <= 0) {
|
765
|
-
results.scrollTop(0);
|
766
|
-
killEvent(e);
|
767
|
-
} else if (deltaY < 0 && results.get(0).scrollHeight - results.scrollTop() + deltaY <= results.height()) {
|
768
|
-
results.scrollTop(results.get(0).scrollHeight - results.height());
|
769
|
-
killEvent(e);
|
770
|
-
}
|
771
|
-
});
|
772
|
-
}
|
773
|
-
|
774
|
-
installKeyUpChangeEvent(search);
|
775
|
-
search.on("keyup-change input paste", this.bind(this.updateResults));
|
776
|
-
search.on("focus", function () { search.addClass("select2-focused"); });
|
777
|
-
search.on("blur", function () { search.removeClass("select2-focused");});
|
778
|
-
|
779
|
-
this.dropdown.on("mouseup", resultsSelector, this.bind(function (e) {
|
780
|
-
if ($(e.target).closest(".select2-result-selectable").length > 0) {
|
781
|
-
this.highlightUnderEvent(e);
|
782
|
-
this.selectHighlighted(e);
|
783
|
-
}
|
784
|
-
}));
|
785
|
-
|
786
|
-
// trap all mouse events from leaving the dropdown. sometimes there may be a modal that is listening
|
787
|
-
// for mouse events outside of itself so it can close itself. since the dropdown is now outside the select2's
|
788
|
-
// dom it will trigger the popup close, which is not what we want
|
789
|
-
// focusin can cause focus wars between modals and select2 since the dropdown is outside the modal.
|
790
|
-
this.dropdown.on("click mouseup mousedown touchstart touchend focusin", function (e) { e.stopPropagation(); });
|
791
|
-
|
792
|
-
this.nextSearchTerm = undefined;
|
793
|
-
|
794
|
-
if ($.isFunction(this.opts.initSelection)) {
|
795
|
-
// initialize selection based on the current value of the source element
|
796
|
-
this.initSelection();
|
797
|
-
|
798
|
-
// if the user has provided a function that can set selection based on the value of the source element
|
799
|
-
// we monitor the change event on the element and trigger it, allowing for two way synchronization
|
800
|
-
this.monitorSource();
|
801
|
-
}
|
802
|
-
|
803
|
-
if (opts.maximumInputLength !== null) {
|
804
|
-
this.search.attr("maxlength", opts.maximumInputLength);
|
805
|
-
}
|
806
|
-
|
807
|
-
var disabled = opts.element.prop("disabled");
|
808
|
-
if (disabled === undefined) disabled = false;
|
809
|
-
this.enable(!disabled);
|
810
|
-
|
811
|
-
var readonly = opts.element.prop("readonly");
|
812
|
-
if (readonly === undefined) readonly = false;
|
813
|
-
this.readonly(readonly);
|
814
|
-
|
815
|
-
// Calculate size of scrollbar
|
816
|
-
scrollBarDimensions = scrollBarDimensions || measureScrollbar();
|
817
|
-
|
818
|
-
this.autofocus = opts.element.prop("autofocus");
|
819
|
-
opts.element.prop("autofocus", false);
|
820
|
-
if (this.autofocus) this.focus();
|
821
|
-
|
822
|
-
this.search.attr("placeholder", opts.searchInputPlaceholder);
|
823
|
-
},
|
824
|
-
|
825
|
-
// abstract
|
826
|
-
destroy: function () {
|
827
|
-
var element=this.opts.element, select2 = element.data("select2");
|
828
|
-
|
829
|
-
this.close();
|
830
|
-
|
831
|
-
if (this.propertyObserver) {
|
832
|
-
this.propertyObserver.disconnect();
|
833
|
-
this.propertyObserver = null;
|
834
|
-
}
|
835
|
-
|
836
|
-
if (select2 !== undefined) {
|
837
|
-
select2.container.remove();
|
838
|
-
select2.liveRegion.remove();
|
839
|
-
select2.dropdown.remove();
|
840
|
-
element
|
841
|
-
.removeClass("select2-offscreen")
|
842
|
-
.removeData("select2")
|
843
|
-
.off(".select2")
|
844
|
-
.prop("autofocus", this.autofocus || false);
|
845
|
-
if (this.elementTabIndex) {
|
846
|
-
element.attr({tabindex: this.elementTabIndex});
|
847
|
-
} else {
|
848
|
-
element.removeAttr("tabindex");
|
849
|
-
}
|
850
|
-
element.show();
|
851
|
-
}
|
852
|
-
|
853
|
-
cleanupJQueryElements.call(this,
|
854
|
-
"container",
|
855
|
-
"liveRegion",
|
856
|
-
"dropdown",
|
857
|
-
"results",
|
858
|
-
"search"
|
859
|
-
);
|
860
|
-
},
|
861
|
-
|
862
|
-
// abstract
|
863
|
-
optionToData: function(element) {
|
864
|
-
if (element.is("option")) {
|
865
|
-
return {
|
866
|
-
id:element.prop("value"),
|
867
|
-
text:element.text(),
|
868
|
-
element: element.get(),
|
869
|
-
css: element.attr("class"),
|
870
|
-
disabled: element.prop("disabled"),
|
871
|
-
locked: equal(element.attr("locked"), "locked") || equal(element.data("locked"), true)
|
872
|
-
};
|
873
|
-
} else if (element.is("optgroup")) {
|
874
|
-
return {
|
875
|
-
text:element.attr("label"),
|
876
|
-
children:[],
|
877
|
-
element: element.get(),
|
878
|
-
css: element.attr("class")
|
879
|
-
};
|
880
|
-
}
|
881
|
-
},
|
882
|
-
|
883
|
-
// abstract
|
884
|
-
prepareOpts: function (opts) {
|
885
|
-
var element, select, idKey, ajaxUrl, self = this;
|
886
|
-
|
887
|
-
element = opts.element;
|
888
|
-
|
889
|
-
if (element.get(0).tagName.toLowerCase() === "select") {
|
890
|
-
this.select = select = opts.element;
|
891
|
-
}
|
892
|
-
|
893
|
-
if (select) {
|
894
|
-
// these options are not allowed when attached to a select because they are picked up off the element itself
|
895
|
-
$.each(["id", "multiple", "ajax", "query", "createSearchChoice", "initSelection", "data", "tags"], function () {
|
896
|
-
if (this in opts) {
|
897
|
-
throw new Error("Option '" + this + "' is not allowed for Select2 when attached to a <select> element.");
|
898
|
-
}
|
899
|
-
});
|
900
|
-
}
|
901
|
-
|
902
|
-
opts = $.extend({}, {
|
903
|
-
populateResults: function(container, results, query) {
|
904
|
-
var populate, id=this.opts.id, liveRegion=this.liveRegion;
|
905
|
-
|
906
|
-
populate=function(results, container, depth) {
|
907
|
-
|
908
|
-
var i, l, result, selectable, disabled, compound, node, label, innerContainer, formatted;
|
909
|
-
|
910
|
-
results = opts.sortResults(results, container, query);
|
911
|
-
|
912
|
-
for (i = 0, l = results.length; i < l; i = i + 1) {
|
913
|
-
|
914
|
-
result=results[i];
|
915
|
-
|
916
|
-
disabled = (result.disabled === true);
|
917
|
-
selectable = (!disabled) && (id(result) !== undefined);
|
918
|
-
|
919
|
-
compound=result.children && result.children.length > 0;
|
920
|
-
|
921
|
-
node=$("<li></li>");
|
922
|
-
node.addClass("select2-results-dept-"+depth);
|
923
|
-
node.addClass("select2-result");
|
924
|
-
node.addClass(selectable ? "select2-result-selectable" : "select2-result-unselectable");
|
925
|
-
if (disabled) { node.addClass("select2-disabled"); }
|
926
|
-
if (compound) { node.addClass("select2-result-with-children"); }
|
927
|
-
node.addClass(self.opts.formatResultCssClass(result));
|
928
|
-
node.attr("role", "presentation");
|
929
|
-
|
930
|
-
label=$(document.createElement("div"));
|
931
|
-
label.addClass("select2-result-label");
|
932
|
-
label.attr("id", "select2-result-label-" + nextUid());
|
933
|
-
label.attr("role", "option");
|
934
|
-
|
935
|
-
formatted=opts.formatResult(result, label, query, self.opts.escapeMarkup);
|
936
|
-
if (formatted!==undefined) {
|
937
|
-
label.html(formatted);
|
938
|
-
node.append(label);
|
939
|
-
}
|
940
|
-
|
941
|
-
|
942
|
-
if (compound) {
|
943
|
-
|
944
|
-
innerContainer=$("<ul></ul>");
|
945
|
-
innerContainer.addClass("select2-result-sub");
|
946
|
-
populate(result.children, innerContainer, depth+1);
|
947
|
-
node.append(innerContainer);
|
948
|
-
}
|
949
|
-
|
950
|
-
node.data("select2-data", result);
|
951
|
-
container.append(node);
|
952
|
-
}
|
953
|
-
|
954
|
-
liveRegion.text(opts.formatMatches(results.length));
|
955
|
-
};
|
956
|
-
|
957
|
-
populate(results, container, 0);
|
958
|
-
}
|
959
|
-
}, $.fn.select2.defaults, opts);
|
960
|
-
|
961
|
-
if (typeof(opts.id) !== "function") {
|
962
|
-
idKey = opts.id;
|
963
|
-
opts.id = function (e) { return e[idKey]; };
|
964
|
-
}
|
965
|
-
|
966
|
-
if ($.isArray(opts.element.data("select2Tags"))) {
|
967
|
-
if ("tags" in opts) {
|
968
|
-
throw "tags specified as both an attribute 'data-select2-tags' and in options of Select2 " + opts.element.attr("id");
|
969
|
-
}
|
970
|
-
opts.tags=opts.element.data("select2Tags");
|
971
|
-
}
|
972
|
-
|
973
|
-
if (select) {
|
974
|
-
opts.query = this.bind(function (query) {
|
975
|
-
var data = { results: [], more: false },
|
976
|
-
term = query.term,
|
977
|
-
children, placeholderOption, process;
|
978
|
-
|
979
|
-
process=function(element, collection) {
|
980
|
-
var group;
|
981
|
-
if (element.is("option")) {
|
982
|
-
if (query.matcher(term, element.text(), element)) {
|
983
|
-
collection.push(self.optionToData(element));
|
984
|
-
}
|
985
|
-
} else if (element.is("optgroup")) {
|
986
|
-
group=self.optionToData(element);
|
987
|
-
element.children().each2(function(i, elm) { process(elm, group.children); });
|
988
|
-
if (group.children.length>0) {
|
989
|
-
collection.push(group);
|
990
|
-
}
|
991
|
-
}
|
992
|
-
};
|
993
|
-
|
994
|
-
children=element.children();
|
995
|
-
|
996
|
-
// ignore the placeholder option if there is one
|
997
|
-
if (this.getPlaceholder() !== undefined && children.length > 0) {
|
998
|
-
placeholderOption = this.getPlaceholderOption();
|
999
|
-
if (placeholderOption) {
|
1000
|
-
children=children.not(placeholderOption);
|
1001
|
-
}
|
1002
|
-
}
|
1003
|
-
|
1004
|
-
children.each2(function(i, elm) { process(elm, data.results); });
|
1005
|
-
|
1006
|
-
query.callback(data);
|
1007
|
-
});
|
1008
|
-
// this is needed because inside val() we construct choices from options and there id is hardcoded
|
1009
|
-
opts.id=function(e) { return e.id; };
|
1010
|
-
} else {
|
1011
|
-
if (!("query" in opts)) {
|
1012
|
-
|
1013
|
-
if ("ajax" in opts) {
|
1014
|
-
ajaxUrl = opts.element.data("ajax-url");
|
1015
|
-
if (ajaxUrl && ajaxUrl.length > 0) {
|
1016
|
-
opts.ajax.url = ajaxUrl;
|
1017
|
-
}
|
1018
|
-
opts.query = ajax.call(opts.element, opts.ajax);
|
1019
|
-
} else if ("data" in opts) {
|
1020
|
-
opts.query = local(opts.data);
|
1021
|
-
} else if ("tags" in opts) {
|
1022
|
-
opts.query = tags(opts.tags);
|
1023
|
-
if (opts.createSearchChoice === undefined) {
|
1024
|
-
opts.createSearchChoice = function (term) { return {id: $.trim(term), text: $.trim(term)}; };
|
1025
|
-
}
|
1026
|
-
if (opts.initSelection === undefined) {
|
1027
|
-
opts.initSelection = function (element, callback) {
|
1028
|
-
var data = [];
|
1029
|
-
$(splitVal(element.val(), opts.separator)).each(function () {
|
1030
|
-
var obj = { id: this, text: this },
|
1031
|
-
tags = opts.tags;
|
1032
|
-
if ($.isFunction(tags)) tags=tags();
|
1033
|
-
$(tags).each(function() { if (equal(this.id, obj.id)) { obj = this; return false; } });
|
1034
|
-
data.push(obj);
|
1035
|
-
});
|
1036
|
-
|
1037
|
-
callback(data);
|
1038
|
-
};
|
1039
|
-
}
|
1040
|
-
}
|
1041
|
-
}
|
1042
|
-
}
|
1043
|
-
if (typeof(opts.query) !== "function") {
|
1044
|
-
throw "query function not defined for Select2 " + opts.element.attr("id");
|
1045
|
-
}
|
1046
|
-
|
1047
|
-
if (opts.createSearchChoicePosition === 'top') {
|
1048
|
-
opts.createSearchChoicePosition = function(list, item) { list.unshift(item); };
|
1049
|
-
}
|
1050
|
-
else if (opts.createSearchChoicePosition === 'bottom') {
|
1051
|
-
opts.createSearchChoicePosition = function(list, item) { list.push(item); };
|
1052
|
-
}
|
1053
|
-
else if (typeof(opts.createSearchChoicePosition) !== "function") {
|
1054
|
-
throw "invalid createSearchChoicePosition option must be 'top', 'bottom' or a custom function";
|
1055
|
-
}
|
1056
|
-
|
1057
|
-
return opts;
|
1058
|
-
},
|
1059
|
-
|
1060
|
-
/**
|
1061
|
-
* Monitor the original element for changes and update select2 accordingly
|
1062
|
-
*/
|
1063
|
-
// abstract
|
1064
|
-
monitorSource: function () {
|
1065
|
-
var el = this.opts.element, sync, observer;
|
1066
|
-
|
1067
|
-
el.on("change.select2", this.bind(function (e) {
|
1068
|
-
if (this.opts.element.data("select2-change-triggered") !== true) {
|
1069
|
-
this.initSelection();
|
1070
|
-
}
|
1071
|
-
}));
|
1072
|
-
|
1073
|
-
sync = this.bind(function () {
|
1074
|
-
|
1075
|
-
// sync enabled state
|
1076
|
-
var disabled = el.prop("disabled");
|
1077
|
-
if (disabled === undefined) disabled = false;
|
1078
|
-
this.enable(!disabled);
|
1079
|
-
|
1080
|
-
var readonly = el.prop("readonly");
|
1081
|
-
if (readonly === undefined) readonly = false;
|
1082
|
-
this.readonly(readonly);
|
1083
|
-
|
1084
|
-
syncCssClasses(this.container, this.opts.element, this.opts.adaptContainerCssClass);
|
1085
|
-
this.container.addClass(evaluate(this.opts.containerCssClass));
|
1086
|
-
|
1087
|
-
syncCssClasses(this.dropdown, this.opts.element, this.opts.adaptDropdownCssClass);
|
1088
|
-
this.dropdown.addClass(evaluate(this.opts.dropdownCssClass));
|
1089
|
-
|
1090
|
-
});
|
1091
|
-
|
1092
|
-
// IE8-10 (IE9/10 won't fire propertyChange via attachEventListener)
|
1093
|
-
if (el.length && el[0].attachEvent) {
|
1094
|
-
el.each(function() {
|
1095
|
-
this.attachEvent("onpropertychange", sync);
|
1096
|
-
});
|
1097
|
-
}
|
1098
|
-
|
1099
|
-
// safari, chrome, firefox, IE11
|
1100
|
-
observer = window.MutationObserver || window.WebKitMutationObserver|| window.MozMutationObserver;
|
1101
|
-
if (observer !== undefined) {
|
1102
|
-
if (this.propertyObserver) { delete this.propertyObserver; this.propertyObserver = null; }
|
1103
|
-
this.propertyObserver = new observer(function (mutations) {
|
1104
|
-
mutations.forEach(sync);
|
1105
|
-
});
|
1106
|
-
this.propertyObserver.observe(el.get(0), { attributes:true, subtree:false });
|
1107
|
-
}
|
1108
|
-
},
|
1109
|
-
|
1110
|
-
// abstract
|
1111
|
-
triggerSelect: function(data) {
|
1112
|
-
var evt = $.Event("select2-selecting", { val: this.id(data), object: data });
|
1113
|
-
this.opts.element.trigger(evt);
|
1114
|
-
return !evt.isDefaultPrevented();
|
1115
|
-
},
|
1116
|
-
|
1117
|
-
/**
|
1118
|
-
* Triggers the change event on the source element
|
1119
|
-
*/
|
1120
|
-
// abstract
|
1121
|
-
triggerChange: function (details) {
|
1122
|
-
|
1123
|
-
details = details || {};
|
1124
|
-
details= $.extend({}, details, { type: "change", val: this.val() });
|
1125
|
-
// prevents recursive triggering
|
1126
|
-
this.opts.element.data("select2-change-triggered", true);
|
1127
|
-
this.opts.element.trigger(details);
|
1128
|
-
this.opts.element.data("select2-change-triggered", false);
|
1129
|
-
|
1130
|
-
// some validation frameworks ignore the change event and listen instead to keyup, click for selects
|
1131
|
-
// so here we trigger the click event manually
|
1132
|
-
this.opts.element.click();
|
1133
|
-
|
1134
|
-
// ValidationEngine ignores the change event and listens instead to blur
|
1135
|
-
// so here we trigger the blur event manually if so desired
|
1136
|
-
if (this.opts.blurOnChange)
|
1137
|
-
this.opts.element.blur();
|
1138
|
-
},
|
1139
|
-
|
1140
|
-
//abstract
|
1141
|
-
isInterfaceEnabled: function()
|
1142
|
-
{
|
1143
|
-
return this.enabledInterface === true;
|
1144
|
-
},
|
1145
|
-
|
1146
|
-
// abstract
|
1147
|
-
enableInterface: function() {
|
1148
|
-
var enabled = this._enabled && !this._readonly,
|
1149
|
-
disabled = !enabled;
|
1150
|
-
|
1151
|
-
if (enabled === this.enabledInterface) return false;
|
1152
|
-
|
1153
|
-
this.container.toggleClass("select2-container-disabled", disabled);
|
1154
|
-
this.close();
|
1155
|
-
this.enabledInterface = enabled;
|
1156
|
-
|
1157
|
-
return true;
|
1158
|
-
},
|
1159
|
-
|
1160
|
-
// abstract
|
1161
|
-
enable: function(enabled) {
|
1162
|
-
if (enabled === undefined) enabled = true;
|
1163
|
-
if (this._enabled === enabled) return;
|
1164
|
-
this._enabled = enabled;
|
1165
|
-
|
1166
|
-
this.opts.element.prop("disabled", !enabled);
|
1167
|
-
this.enableInterface();
|
1168
|
-
},
|
1169
|
-
|
1170
|
-
// abstract
|
1171
|
-
disable: function() {
|
1172
|
-
this.enable(false);
|
1173
|
-
},
|
1174
|
-
|
1175
|
-
// abstract
|
1176
|
-
readonly: function(enabled) {
|
1177
|
-
if (enabled === undefined) enabled = false;
|
1178
|
-
if (this._readonly === enabled) return;
|
1179
|
-
this._readonly = enabled;
|
1180
|
-
|
1181
|
-
this.opts.element.prop("readonly", enabled);
|
1182
|
-
this.enableInterface();
|
1183
|
-
},
|
1184
|
-
|
1185
|
-
// abstract
|
1186
|
-
opened: function () {
|
1187
|
-
return this.container.hasClass("select2-dropdown-open");
|
1188
|
-
},
|
1189
|
-
|
1190
|
-
// abstract
|
1191
|
-
positionDropdown: function() {
|
1192
|
-
var $dropdown = this.dropdown,
|
1193
|
-
offset = this.container.offset(),
|
1194
|
-
height = this.container.outerHeight(false),
|
1195
|
-
width = this.container.outerWidth(false),
|
1196
|
-
dropHeight = $dropdown.outerHeight(false),
|
1197
|
-
$window = $(window),
|
1198
|
-
windowWidth = $window.width(),
|
1199
|
-
windowHeight = $window.height(),
|
1200
|
-
viewPortRight = $window.scrollLeft() + windowWidth,
|
1201
|
-
viewportBottom = $window.scrollTop() + windowHeight,
|
1202
|
-
dropTop = offset.top + height,
|
1203
|
-
dropLeft = offset.left,
|
1204
|
-
enoughRoomBelow = dropTop + dropHeight <= viewportBottom,
|
1205
|
-
enoughRoomAbove = (offset.top - dropHeight) >= $window.scrollTop(),
|
1206
|
-
dropWidth = $dropdown.outerWidth(false),
|
1207
|
-
enoughRoomOnRight = dropLeft + dropWidth <= viewPortRight,
|
1208
|
-
aboveNow = $dropdown.hasClass("select2-drop-above"),
|
1209
|
-
bodyOffset,
|
1210
|
-
above,
|
1211
|
-
changeDirection,
|
1212
|
-
css,
|
1213
|
-
resultsListNode;
|
1214
|
-
|
1215
|
-
// always prefer the current above/below alignment, unless there is not enough room
|
1216
|
-
if (aboveNow) {
|
1217
|
-
above = true;
|
1218
|
-
if (!enoughRoomAbove && enoughRoomBelow) {
|
1219
|
-
changeDirection = true;
|
1220
|
-
above = false;
|
1221
|
-
}
|
1222
|
-
} else {
|
1223
|
-
above = false;
|
1224
|
-
if (!enoughRoomBelow && enoughRoomAbove) {
|
1225
|
-
changeDirection = true;
|
1226
|
-
above = true;
|
1227
|
-
}
|
1228
|
-
}
|
1229
|
-
|
1230
|
-
//if we are changing direction we need to get positions when dropdown is hidden;
|
1231
|
-
if (changeDirection) {
|
1232
|
-
$dropdown.hide();
|
1233
|
-
offset = this.container.offset();
|
1234
|
-
height = this.container.outerHeight(false);
|
1235
|
-
width = this.container.outerWidth(false);
|
1236
|
-
dropHeight = $dropdown.outerHeight(false);
|
1237
|
-
viewPortRight = $window.scrollLeft() + windowWidth;
|
1238
|
-
viewportBottom = $window.scrollTop() + windowHeight;
|
1239
|
-
dropTop = offset.top + height;
|
1240
|
-
dropLeft = offset.left;
|
1241
|
-
dropWidth = $dropdown.outerWidth(false);
|
1242
|
-
enoughRoomOnRight = dropLeft + dropWidth <= viewPortRight;
|
1243
|
-
$dropdown.show();
|
1244
|
-
|
1245
|
-
// fix so the cursor does not move to the left within the search-textbox in IE
|
1246
|
-
this.focusSearch();
|
1247
|
-
}
|
1248
|
-
|
1249
|
-
if (this.opts.dropdownAutoWidth) {
|
1250
|
-
resultsListNode = $('.select2-results', $dropdown)[0];
|
1251
|
-
$dropdown.addClass('select2-drop-auto-width');
|
1252
|
-
$dropdown.css('width', '');
|
1253
|
-
// Add scrollbar width to dropdown if vertical scrollbar is present
|
1254
|
-
dropWidth = $dropdown.outerWidth(false) + (resultsListNode.scrollHeight === resultsListNode.clientHeight ? 0 : scrollBarDimensions.width);
|
1255
|
-
dropWidth > width ? width = dropWidth : dropWidth = width;
|
1256
|
-
dropHeight = $dropdown.outerHeight(false);
|
1257
|
-
enoughRoomOnRight = dropLeft + dropWidth <= viewPortRight;
|
1258
|
-
}
|
1259
|
-
else {
|
1260
|
-
this.container.removeClass('select2-drop-auto-width');
|
1261
|
-
}
|
1262
|
-
|
1263
|
-
//console.log("below/ droptop:", dropTop, "dropHeight", dropHeight, "sum", (dropTop+dropHeight)+" viewport bottom", viewportBottom, "enough?", enoughRoomBelow);
|
1264
|
-
//console.log("above/ offset.top", offset.top, "dropHeight", dropHeight, "top", (offset.top-dropHeight), "scrollTop", this.body.scrollTop(), "enough?", enoughRoomAbove);
|
1265
|
-
|
1266
|
-
// fix positioning when body has an offset and is not position: static
|
1267
|
-
if (this.body.css('position') !== 'static') {
|
1268
|
-
bodyOffset = this.body.offset();
|
1269
|
-
dropTop -= bodyOffset.top;
|
1270
|
-
dropLeft -= bodyOffset.left;
|
1271
|
-
}
|
1272
|
-
|
1273
|
-
if (!enoughRoomOnRight) {
|
1274
|
-
dropLeft = offset.left + this.container.outerWidth(false) - dropWidth;
|
1275
|
-
}
|
1276
|
-
|
1277
|
-
css = {
|
1278
|
-
left: dropLeft,
|
1279
|
-
width: width
|
1280
|
-
};
|
1281
|
-
|
1282
|
-
if (above) {
|
1283
|
-
css.top = offset.top - dropHeight;
|
1284
|
-
css.bottom = 'auto';
|
1285
|
-
this.container.addClass("select2-drop-above");
|
1286
|
-
$dropdown.addClass("select2-drop-above");
|
1287
|
-
}
|
1288
|
-
else {
|
1289
|
-
css.top = dropTop;
|
1290
|
-
css.bottom = 'auto';
|
1291
|
-
this.container.removeClass("select2-drop-above");
|
1292
|
-
$dropdown.removeClass("select2-drop-above");
|
1293
|
-
}
|
1294
|
-
css = $.extend(css, evaluate(this.opts.dropdownCss));
|
1295
|
-
|
1296
|
-
$dropdown.css(css);
|
1297
|
-
},
|
1298
|
-
|
1299
|
-
// abstract
|
1300
|
-
shouldOpen: function() {
|
1301
|
-
var event;
|
1302
|
-
|
1303
|
-
if (this.opened()) return false;
|
1304
|
-
|
1305
|
-
if (this._enabled === false || this._readonly === true) return false;
|
1306
|
-
|
1307
|
-
event = $.Event("select2-opening");
|
1308
|
-
this.opts.element.trigger(event);
|
1309
|
-
return !event.isDefaultPrevented();
|
1310
|
-
},
|
1311
|
-
|
1312
|
-
// abstract
|
1313
|
-
clearDropdownAlignmentPreference: function() {
|
1314
|
-
// clear the classes used to figure out the preference of where the dropdown should be opened
|
1315
|
-
this.container.removeClass("select2-drop-above");
|
1316
|
-
this.dropdown.removeClass("select2-drop-above");
|
1317
|
-
},
|
1318
|
-
|
1319
|
-
/**
|
1320
|
-
* Opens the dropdown
|
1321
|
-
*
|
1322
|
-
* @return {Boolean} whether or not dropdown was opened. This method will return false if, for example,
|
1323
|
-
* the dropdown is already open, or if the 'open' event listener on the element called preventDefault().
|
1324
|
-
*/
|
1325
|
-
// abstract
|
1326
|
-
open: function () {
|
1327
|
-
|
1328
|
-
if (!this.shouldOpen()) return false;
|
1329
|
-
|
1330
|
-
this.opening();
|
1331
|
-
|
1332
|
-
return true;
|
1333
|
-
},
|
1334
|
-
|
1335
|
-
/**
|
1336
|
-
* Performs the opening of the dropdown
|
1337
|
-
*/
|
1338
|
-
// abstract
|
1339
|
-
opening: function() {
|
1340
|
-
var cid = this.containerEventName,
|
1341
|
-
scroll = "scroll." + cid,
|
1342
|
-
resize = "resize."+cid,
|
1343
|
-
orient = "orientationchange."+cid,
|
1344
|
-
mask;
|
1345
|
-
|
1346
|
-
this.container.addClass("select2-dropdown-open").addClass("select2-container-active");
|
1347
|
-
|
1348
|
-
this.clearDropdownAlignmentPreference();
|
1349
|
-
|
1350
|
-
if(this.dropdown[0] !== this.body.children().last()[0]) {
|
1351
|
-
this.dropdown.detach().appendTo(this.body);
|
1352
|
-
}
|
1353
|
-
|
1354
|
-
// create the dropdown mask if doesn't already exist
|
1355
|
-
mask = $("#select2-drop-mask");
|
1356
|
-
if (mask.length == 0) {
|
1357
|
-
mask = $(document.createElement("div"));
|
1358
|
-
mask.attr("id","select2-drop-mask").attr("class","select2-drop-mask");
|
1359
|
-
mask.hide();
|
1360
|
-
mask.appendTo(this.body);
|
1361
|
-
mask.on("mousedown touchstart click", function (e) {
|
1362
|
-
// Prevent IE from generating a click event on the body
|
1363
|
-
reinsertElement(mask);
|
1364
|
-
|
1365
|
-
var dropdown = $("#select2-drop"), self;
|
1366
|
-
if (dropdown.length > 0) {
|
1367
|
-
self=dropdown.data("select2");
|
1368
|
-
if (self.opts.selectOnBlur) {
|
1369
|
-
self.selectHighlighted({noFocus: true});
|
1370
|
-
}
|
1371
|
-
self.close();
|
1372
|
-
e.preventDefault();
|
1373
|
-
e.stopPropagation();
|
1374
|
-
}
|
1375
|
-
});
|
1376
|
-
}
|
1377
|
-
|
1378
|
-
// ensure the mask is always right before the dropdown
|
1379
|
-
if (this.dropdown.prev()[0] !== mask[0]) {
|
1380
|
-
this.dropdown.before(mask);
|
1381
|
-
}
|
1382
|
-
|
1383
|
-
// move the global id to the correct dropdown
|
1384
|
-
$("#select2-drop").removeAttr("id");
|
1385
|
-
this.dropdown.attr("id", "select2-drop");
|
1386
|
-
|
1387
|
-
// show the elements
|
1388
|
-
mask.show();
|
1389
|
-
|
1390
|
-
this.positionDropdown();
|
1391
|
-
this.dropdown.show();
|
1392
|
-
this.positionDropdown();
|
1393
|
-
|
1394
|
-
this.dropdown.addClass("select2-drop-active");
|
1395
|
-
|
1396
|
-
// attach listeners to events that can change the position of the container and thus require
|
1397
|
-
// the position of the dropdown to be updated as well so it does not come unglued from the container
|
1398
|
-
var that = this;
|
1399
|
-
this.container.parents().add(window).each(function () {
|
1400
|
-
$(this).on(resize+" "+scroll+" "+orient, function (e) {
|
1401
|
-
if (that.opened()) that.positionDropdown();
|
1402
|
-
});
|
1403
|
-
});
|
1404
|
-
|
1405
|
-
|
1406
|
-
},
|
1407
|
-
|
1408
|
-
// abstract
|
1409
|
-
close: function () {
|
1410
|
-
if (!this.opened()) return;
|
1411
|
-
|
1412
|
-
var cid = this.containerEventName,
|
1413
|
-
scroll = "scroll." + cid,
|
1414
|
-
resize = "resize."+cid,
|
1415
|
-
orient = "orientationchange."+cid;
|
1416
|
-
|
1417
|
-
// unbind event listeners
|
1418
|
-
this.container.parents().add(window).each(function () { $(this).off(scroll).off(resize).off(orient); });
|
1419
|
-
|
1420
|
-
this.clearDropdownAlignmentPreference();
|
1421
|
-
|
1422
|
-
$("#select2-drop-mask").hide();
|
1423
|
-
this.dropdown.removeAttr("id"); // only the active dropdown has the select2-drop id
|
1424
|
-
this.dropdown.hide();
|
1425
|
-
this.container.removeClass("select2-dropdown-open").removeClass("select2-container-active");
|
1426
|
-
this.results.empty();
|
1427
|
-
|
1428
|
-
|
1429
|
-
this.clearSearch();
|
1430
|
-
this.search.removeClass("select2-active");
|
1431
|
-
this.opts.element.trigger($.Event("select2-close"));
|
1432
|
-
},
|
1433
|
-
|
1434
|
-
/**
|
1435
|
-
* Opens control, sets input value, and updates results.
|
1436
|
-
*/
|
1437
|
-
// abstract
|
1438
|
-
externalSearch: function (term) {
|
1439
|
-
this.open();
|
1440
|
-
this.search.val(term);
|
1441
|
-
this.updateResults(false);
|
1442
|
-
},
|
1443
|
-
|
1444
|
-
// abstract
|
1445
|
-
clearSearch: function () {
|
1446
|
-
|
1447
|
-
},
|
1448
|
-
|
1449
|
-
//abstract
|
1450
|
-
getMaximumSelectionSize: function() {
|
1451
|
-
return evaluate(this.opts.maximumSelectionSize);
|
1452
|
-
},
|
1453
|
-
|
1454
|
-
// abstract
|
1455
|
-
ensureHighlightVisible: function () {
|
1456
|
-
var results = this.results, children, index, child, hb, rb, y, more;
|
1457
|
-
|
1458
|
-
index = this.highlight();
|
1459
|
-
|
1460
|
-
if (index < 0) return;
|
1461
|
-
|
1462
|
-
if (index == 0) {
|
1463
|
-
|
1464
|
-
// if the first element is highlighted scroll all the way to the top,
|
1465
|
-
// that way any unselectable headers above it will also be scrolled
|
1466
|
-
// into view
|
1467
|
-
|
1468
|
-
results.scrollTop(0);
|
1469
|
-
return;
|
1470
|
-
}
|
1471
|
-
|
1472
|
-
children = this.findHighlightableChoices().find('.select2-result-label');
|
1473
|
-
|
1474
|
-
child = $(children[index]);
|
1475
|
-
|
1476
|
-
hb = child.offset().top + child.outerHeight(true);
|
1477
|
-
|
1478
|
-
// if this is the last child lets also make sure select2-more-results is visible
|
1479
|
-
if (index === children.length - 1) {
|
1480
|
-
more = results.find("li.select2-more-results");
|
1481
|
-
if (more.length > 0) {
|
1482
|
-
hb = more.offset().top + more.outerHeight(true);
|
1483
|
-
}
|
1484
|
-
}
|
1485
|
-
|
1486
|
-
rb = results.offset().top + results.outerHeight(true);
|
1487
|
-
if (hb > rb) {
|
1488
|
-
results.scrollTop(results.scrollTop() + (hb - rb));
|
1489
|
-
}
|
1490
|
-
y = child.offset().top - results.offset().top;
|
1491
|
-
|
1492
|
-
// make sure the top of the element is visible
|
1493
|
-
if (y < 0 && child.css('display') != 'none' ) {
|
1494
|
-
results.scrollTop(results.scrollTop() + y); // y is negative
|
1495
|
-
}
|
1496
|
-
},
|
1497
|
-
|
1498
|
-
// abstract
|
1499
|
-
findHighlightableChoices: function() {
|
1500
|
-
return this.results.find(".select2-result-selectable:not(.select2-disabled):not(.select2-selected)");
|
1501
|
-
},
|
1502
|
-
|
1503
|
-
// abstract
|
1504
|
-
moveHighlight: function (delta) {
|
1505
|
-
var choices = this.findHighlightableChoices(),
|
1506
|
-
index = this.highlight();
|
1507
|
-
|
1508
|
-
while (index > -1 && index < choices.length) {
|
1509
|
-
index += delta;
|
1510
|
-
var choice = $(choices[index]);
|
1511
|
-
if (choice.hasClass("select2-result-selectable") && !choice.hasClass("select2-disabled") && !choice.hasClass("select2-selected")) {
|
1512
|
-
this.highlight(index);
|
1513
|
-
break;
|
1514
|
-
}
|
1515
|
-
}
|
1516
|
-
},
|
1517
|
-
|
1518
|
-
// abstract
|
1519
|
-
highlight: function (index) {
|
1520
|
-
var choices = this.findHighlightableChoices(),
|
1521
|
-
choice,
|
1522
|
-
data;
|
1523
|
-
|
1524
|
-
if (arguments.length === 0) {
|
1525
|
-
return indexOf(choices.filter(".select2-highlighted")[0], choices.get());
|
1526
|
-
}
|
1527
|
-
|
1528
|
-
if (index >= choices.length) index = choices.length - 1;
|
1529
|
-
if (index < 0) index = 0;
|
1530
|
-
|
1531
|
-
this.removeHighlight();
|
1532
|
-
|
1533
|
-
choice = $(choices[index]);
|
1534
|
-
choice.addClass("select2-highlighted");
|
1535
|
-
|
1536
|
-
// ensure assistive technology can determine the active choice
|
1537
|
-
this.search.attr("aria-activedescendant", choice.find(".select2-result-label").attr("id"));
|
1538
|
-
|
1539
|
-
this.ensureHighlightVisible();
|
1540
|
-
|
1541
|
-
this.liveRegion.text(choice.text());
|
1542
|
-
|
1543
|
-
data = choice.data("select2-data");
|
1544
|
-
if (data) {
|
1545
|
-
this.opts.element.trigger({ type: "select2-highlight", val: this.id(data), choice: data });
|
1546
|
-
}
|
1547
|
-
},
|
1548
|
-
|
1549
|
-
removeHighlight: function() {
|
1550
|
-
this.results.find(".select2-highlighted").removeClass("select2-highlighted");
|
1551
|
-
},
|
1552
|
-
|
1553
|
-
touchMoved: function() {
|
1554
|
-
this._touchMoved = true;
|
1555
|
-
},
|
1556
|
-
|
1557
|
-
clearTouchMoved: function() {
|
1558
|
-
this._touchMoved = false;
|
1559
|
-
},
|
1560
|
-
|
1561
|
-
// abstract
|
1562
|
-
countSelectableResults: function() {
|
1563
|
-
return this.findHighlightableChoices().length;
|
1564
|
-
},
|
1565
|
-
|
1566
|
-
// abstract
|
1567
|
-
highlightUnderEvent: function (event) {
|
1568
|
-
var el = $(event.target).closest(".select2-result-selectable");
|
1569
|
-
if (el.length > 0 && !el.is(".select2-highlighted")) {
|
1570
|
-
var choices = this.findHighlightableChoices();
|
1571
|
-
this.highlight(choices.index(el));
|
1572
|
-
} else if (el.length == 0) {
|
1573
|
-
// if we are over an unselectable item remove all highlights
|
1574
|
-
this.removeHighlight();
|
1575
|
-
}
|
1576
|
-
},
|
1577
|
-
|
1578
|
-
// abstract
|
1579
|
-
loadMoreIfNeeded: function () {
|
1580
|
-
var results = this.results,
|
1581
|
-
more = results.find("li.select2-more-results"),
|
1582
|
-
below, // pixels the element is below the scroll fold, below==0 is when the element is starting to be visible
|
1583
|
-
page = this.resultsPage + 1,
|
1584
|
-
self=this,
|
1585
|
-
term=this.search.val(),
|
1586
|
-
context=this.context;
|
1587
|
-
|
1588
|
-
if (more.length === 0) return;
|
1589
|
-
below = more.offset().top - results.offset().top - results.height();
|
1590
|
-
|
1591
|
-
if (below <= this.opts.loadMorePadding) {
|
1592
|
-
more.addClass("select2-active");
|
1593
|
-
this.opts.query({
|
1594
|
-
element: this.opts.element,
|
1595
|
-
term: term,
|
1596
|
-
page: page,
|
1597
|
-
context: context,
|
1598
|
-
matcher: this.opts.matcher,
|
1599
|
-
callback: this.bind(function (data) {
|
1600
|
-
|
1601
|
-
// ignore a response if the select2 has been closed before it was received
|
1602
|
-
if (!self.opened()) return;
|
1603
|
-
|
1604
|
-
|
1605
|
-
self.opts.populateResults.call(this, results, data.results, {term: term, page: page, context:context});
|
1606
|
-
self.postprocessResults(data, false, false);
|
1607
|
-
|
1608
|
-
if (data.more===true) {
|
1609
|
-
more.detach().appendTo(results).text(evaluate(self.opts.formatLoadMore, page+1));
|
1610
|
-
window.setTimeout(function() { self.loadMoreIfNeeded(); }, 10);
|
1611
|
-
} else {
|
1612
|
-
more.remove();
|
1613
|
-
}
|
1614
|
-
self.positionDropdown();
|
1615
|
-
self.resultsPage = page;
|
1616
|
-
self.context = data.context;
|
1617
|
-
this.opts.element.trigger({ type: "select2-loaded", items: data });
|
1618
|
-
})});
|
1619
|
-
}
|
1620
|
-
},
|
1621
|
-
|
1622
|
-
/**
|
1623
|
-
* Default tokenizer function which does nothing
|
1624
|
-
*/
|
1625
|
-
tokenize: function() {
|
1626
|
-
|
1627
|
-
},
|
1628
|
-
|
1629
|
-
/**
|
1630
|
-
* @param initial whether or not this is the call to this method right after the dropdown has been opened
|
1631
|
-
*/
|
1632
|
-
// abstract
|
1633
|
-
updateResults: function (initial) {
|
1634
|
-
var search = this.search,
|
1635
|
-
results = this.results,
|
1636
|
-
opts = this.opts,
|
1637
|
-
data,
|
1638
|
-
self = this,
|
1639
|
-
input,
|
1640
|
-
term = search.val(),
|
1641
|
-
lastTerm = $.data(this.container, "select2-last-term"),
|
1642
|
-
// sequence number used to drop out-of-order responses
|
1643
|
-
queryNumber;
|
1644
|
-
|
1645
|
-
// prevent duplicate queries against the same term
|
1646
|
-
if (initial !== true && lastTerm && equal(term, lastTerm)) return;
|
1647
|
-
|
1648
|
-
$.data(this.container, "select2-last-term", term);
|
1649
|
-
|
1650
|
-
// if the search is currently hidden we do not alter the results
|
1651
|
-
if (initial !== true && (this.showSearchInput === false || !this.opened())) {
|
1652
|
-
return;
|
1653
|
-
}
|
1654
|
-
|
1655
|
-
function postRender() {
|
1656
|
-
search.removeClass("select2-active");
|
1657
|
-
self.positionDropdown();
|
1658
|
-
if (results.find('.select2-no-results,.select2-selection-limit,.select2-searching').length) {
|
1659
|
-
self.liveRegion.text(results.text());
|
1660
|
-
}
|
1661
|
-
else {
|
1662
|
-
self.liveRegion.text(self.opts.formatMatches(results.find('.select2-result-selectable').length));
|
1663
|
-
}
|
1664
|
-
}
|
1665
|
-
|
1666
|
-
function render(html) {
|
1667
|
-
results.html(html);
|
1668
|
-
postRender();
|
1669
|
-
}
|
1670
|
-
|
1671
|
-
queryNumber = ++this.queryCount;
|
1672
|
-
|
1673
|
-
var maxSelSize = this.getMaximumSelectionSize();
|
1674
|
-
if (maxSelSize >=1) {
|
1675
|
-
data = this.data();
|
1676
|
-
if ($.isArray(data) && data.length >= maxSelSize && checkFormatter(opts.formatSelectionTooBig, "formatSelectionTooBig")) {
|
1677
|
-
render("<li class='select2-selection-limit'>" + evaluate(opts.formatSelectionTooBig, maxSelSize) + "</li>");
|
1678
|
-
return;
|
1679
|
-
}
|
1680
|
-
}
|
1681
|
-
|
1682
|
-
if (search.val().length < opts.minimumInputLength) {
|
1683
|
-
if (checkFormatter(opts.formatInputTooShort, "formatInputTooShort")) {
|
1684
|
-
render("<li class='select2-no-results'>" + evaluate(opts.formatInputTooShort, search.val(), opts.minimumInputLength) + "</li>");
|
1685
|
-
} else {
|
1686
|
-
render("");
|
1687
|
-
}
|
1688
|
-
if (initial && this.showSearch) this.showSearch(true);
|
1689
|
-
return;
|
1690
|
-
}
|
1691
|
-
|
1692
|
-
if (opts.maximumInputLength && search.val().length > opts.maximumInputLength) {
|
1693
|
-
if (checkFormatter(opts.formatInputTooLong, "formatInputTooLong")) {
|
1694
|
-
render("<li class='select2-no-results'>" + evaluate(opts.formatInputTooLong, search.val(), opts.maximumInputLength) + "</li>");
|
1695
|
-
} else {
|
1696
|
-
render("");
|
1697
|
-
}
|
1698
|
-
return;
|
1699
|
-
}
|
1700
|
-
|
1701
|
-
if (opts.formatSearching && this.findHighlightableChoices().length === 0) {
|
1702
|
-
render("<li class='select2-searching'>" + evaluate(opts.formatSearching) + "</li>");
|
1703
|
-
}
|
1704
|
-
|
1705
|
-
search.addClass("select2-active");
|
1706
|
-
|
1707
|
-
this.removeHighlight();
|
1708
|
-
|
1709
|
-
// give the tokenizer a chance to pre-process the input
|
1710
|
-
input = this.tokenize();
|
1711
|
-
if (input != undefined && input != null) {
|
1712
|
-
search.val(input);
|
1713
|
-
}
|
1714
|
-
|
1715
|
-
this.resultsPage = 1;
|
1716
|
-
|
1717
|
-
opts.query({
|
1718
|
-
element: opts.element,
|
1719
|
-
term: search.val(),
|
1720
|
-
page: this.resultsPage,
|
1721
|
-
context: null,
|
1722
|
-
matcher: opts.matcher,
|
1723
|
-
callback: this.bind(function (data) {
|
1724
|
-
var def; // default choice
|
1725
|
-
|
1726
|
-
// ignore old responses
|
1727
|
-
if (queryNumber != this.queryCount) {
|
1728
|
-
return;
|
1729
|
-
}
|
1730
|
-
|
1731
|
-
// ignore a response if the select2 has been closed before it was received
|
1732
|
-
if (!this.opened()) {
|
1733
|
-
this.search.removeClass("select2-active");
|
1734
|
-
return;
|
1735
|
-
}
|
1736
|
-
|
1737
|
-
// save context, if any
|
1738
|
-
this.context = (data.context===undefined) ? null : data.context;
|
1739
|
-
// create a default choice and prepend it to the list
|
1740
|
-
if (this.opts.createSearchChoice && search.val() !== "") {
|
1741
|
-
def = this.opts.createSearchChoice.call(self, search.val(), data.results);
|
1742
|
-
if (def !== undefined && def !== null && self.id(def) !== undefined && self.id(def) !== null) {
|
1743
|
-
if ($(data.results).filter(
|
1744
|
-
function () {
|
1745
|
-
return equal(self.id(this), self.id(def));
|
1746
|
-
}).length === 0) {
|
1747
|
-
this.opts.createSearchChoicePosition(data.results, def);
|
1748
|
-
}
|
1749
|
-
}
|
1750
|
-
}
|
1751
|
-
|
1752
|
-
if (data.results.length === 0 && checkFormatter(opts.formatNoMatches, "formatNoMatches")) {
|
1753
|
-
render("<li class='select2-no-results'>" + evaluate(opts.formatNoMatches, search.val()) + "</li>");
|
1754
|
-
return;
|
1755
|
-
}
|
1756
|
-
|
1757
|
-
results.empty();
|
1758
|
-
self.opts.populateResults.call(this, results, data.results, {term: search.val(), page: this.resultsPage, context:null});
|
1759
|
-
|
1760
|
-
if (data.more === true && checkFormatter(opts.formatLoadMore, "formatLoadMore")) {
|
1761
|
-
results.append("<li class='select2-more-results'>" + self.opts.escapeMarkup(evaluate(opts.formatLoadMore, this.resultsPage)) + "</li>");
|
1762
|
-
window.setTimeout(function() { self.loadMoreIfNeeded(); }, 10);
|
1763
|
-
}
|
1764
|
-
|
1765
|
-
this.postprocessResults(data, initial);
|
1766
|
-
|
1767
|
-
postRender();
|
1768
|
-
|
1769
|
-
this.opts.element.trigger({ type: "select2-loaded", items: data });
|
1770
|
-
})});
|
1771
|
-
},
|
1772
|
-
|
1773
|
-
// abstract
|
1774
|
-
cancel: function () {
|
1775
|
-
this.close();
|
1776
|
-
},
|
1777
|
-
|
1778
|
-
// abstract
|
1779
|
-
blur: function () {
|
1780
|
-
// if selectOnBlur == true, select the currently highlighted option
|
1781
|
-
if (this.opts.selectOnBlur)
|
1782
|
-
this.selectHighlighted({noFocus: true});
|
1783
|
-
|
1784
|
-
this.close();
|
1785
|
-
this.container.removeClass("select2-container-active");
|
1786
|
-
// synonymous to .is(':focus'), which is available in jquery >= 1.6
|
1787
|
-
if (this.search[0] === document.activeElement) { this.search.blur(); }
|
1788
|
-
this.clearSearch();
|
1789
|
-
this.selection.find(".select2-search-choice-focus").removeClass("select2-search-choice-focus");
|
1790
|
-
},
|
1791
|
-
|
1792
|
-
// abstract
|
1793
|
-
focusSearch: function () {
|
1794
|
-
focus(this.search);
|
1795
|
-
},
|
1796
|
-
|
1797
|
-
// abstract
|
1798
|
-
selectHighlighted: function (options) {
|
1799
|
-
if (this._touchMoved) {
|
1800
|
-
this.clearTouchMoved();
|
1801
|
-
return;
|
1802
|
-
}
|
1803
|
-
var index=this.highlight(),
|
1804
|
-
highlighted=this.results.find(".select2-highlighted"),
|
1805
|
-
data = highlighted.closest('.select2-result').data("select2-data");
|
1806
|
-
|
1807
|
-
if (data) {
|
1808
|
-
this.highlight(index);
|
1809
|
-
this.onSelect(data, options);
|
1810
|
-
} else if (options && options.noFocus) {
|
1811
|
-
this.close();
|
1812
|
-
}
|
1813
|
-
},
|
1814
|
-
|
1815
|
-
// abstract
|
1816
|
-
getPlaceholder: function () {
|
1817
|
-
var placeholderOption;
|
1818
|
-
return this.opts.element.attr("placeholder") ||
|
1819
|
-
this.opts.element.attr("data-placeholder") || // jquery 1.4 compat
|
1820
|
-
this.opts.element.data("placeholder") ||
|
1821
|
-
this.opts.placeholder ||
|
1822
|
-
((placeholderOption = this.getPlaceholderOption()) !== undefined ? placeholderOption.text() : undefined);
|
1823
|
-
},
|
1824
|
-
|
1825
|
-
// abstract
|
1826
|
-
getPlaceholderOption: function() {
|
1827
|
-
if (this.select) {
|
1828
|
-
var firstOption = this.select.children('option').first();
|
1829
|
-
if (this.opts.placeholderOption !== undefined ) {
|
1830
|
-
//Determine the placeholder option based on the specified placeholderOption setting
|
1831
|
-
return (this.opts.placeholderOption === "first" && firstOption) ||
|
1832
|
-
(typeof this.opts.placeholderOption === "function" && this.opts.placeholderOption(this.select));
|
1833
|
-
} else if ($.trim(firstOption.text()) === "" && firstOption.val() === "") {
|
1834
|
-
//No explicit placeholder option specified, use the first if it's blank
|
1835
|
-
return firstOption;
|
1836
|
-
}
|
1837
|
-
}
|
1838
|
-
},
|
1839
|
-
|
1840
|
-
/**
|
1841
|
-
* Get the desired width for the container element. This is
|
1842
|
-
* derived first from option `width` passed to select2, then
|
1843
|
-
* the inline 'style' on the original element, and finally
|
1844
|
-
* falls back to the jQuery calculated element width.
|
1845
|
-
*/
|
1846
|
-
// abstract
|
1847
|
-
initContainerWidth: function () {
|
1848
|
-
function resolveContainerWidth() {
|
1849
|
-
var style, attrs, matches, i, l, attr;
|
1850
|
-
|
1851
|
-
if (this.opts.width === "off") {
|
1852
|
-
return null;
|
1853
|
-
} else if (this.opts.width === "element"){
|
1854
|
-
return this.opts.element.outerWidth(false) === 0 ? 'auto' : this.opts.element.outerWidth(false) + 'px';
|
1855
|
-
} else if (this.opts.width === "copy" || this.opts.width === "resolve") {
|
1856
|
-
// check if there is inline style on the element that contains width
|
1857
|
-
style = this.opts.element.attr('style');
|
1858
|
-
if (style !== undefined) {
|
1859
|
-
attrs = style.split(';');
|
1860
|
-
for (i = 0, l = attrs.length; i < l; i = i + 1) {
|
1861
|
-
attr = attrs[i].replace(/\s/g, '');
|
1862
|
-
matches = attr.match(/^width:(([-+]?([0-9]*\.)?[0-9]+)(px|em|ex|%|in|cm|mm|pt|pc))/i);
|
1863
|
-
if (matches !== null && matches.length >= 1)
|
1864
|
-
return matches[1];
|
1865
|
-
}
|
1866
|
-
}
|
1867
|
-
|
1868
|
-
if (this.opts.width === "resolve") {
|
1869
|
-
// next check if css('width') can resolve a width that is percent based, this is sometimes possible
|
1870
|
-
// when attached to input type=hidden or elements hidden via css
|
1871
|
-
style = this.opts.element.css('width');
|
1872
|
-
if (style.indexOf("%") > 0) return style;
|
1873
|
-
|
1874
|
-
// finally, fallback on the calculated width of the element
|
1875
|
-
return (this.opts.element.outerWidth(false) === 0 ? 'auto' : this.opts.element.outerWidth(false) + 'px');
|
1876
|
-
}
|
1877
|
-
|
1878
|
-
return null;
|
1879
|
-
} else if ($.isFunction(this.opts.width)) {
|
1880
|
-
return this.opts.width();
|
1881
|
-
} else {
|
1882
|
-
return this.opts.width;
|
1883
|
-
}
|
1884
|
-
};
|
1885
|
-
|
1886
|
-
var width = resolveContainerWidth.call(this);
|
1887
|
-
if (width !== null) {
|
1888
|
-
this.container.css("width", width);
|
1889
|
-
}
|
1890
|
-
}
|
1891
|
-
});
|
1892
|
-
|
1893
|
-
SingleSelect2 = clazz(AbstractSelect2, {
|
1894
|
-
|
1895
|
-
// single
|
1896
|
-
|
1897
|
-
createContainer: function () {
|
1898
|
-
var container = $(document.createElement("div")).attr({
|
1899
|
-
"class": "select2-container"
|
1900
|
-
}).html([
|
1901
|
-
"<a href='javascript:void(0)' class='select2-choice' tabindex='-1'>",
|
1902
|
-
" <span class='select2-chosen'> </span><abbr class='select2-search-choice-close'></abbr>",
|
1903
|
-
" <span class='select2-arrow' role='presentation'><b role='presentation'></b></span>",
|
1904
|
-
"</a>",
|
1905
|
-
"<label for='' class='select2-offscreen'></label>",
|
1906
|
-
"<input class='select2-focusser select2-offscreen' type='text' aria-haspopup='true' role='button' />",
|
1907
|
-
"<div class='select2-drop select2-display-none'>",
|
1908
|
-
" <div class='select2-search'>",
|
1909
|
-
" <label for='' class='select2-offscreen'></label>",
|
1910
|
-
" <input type='text' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' class='select2-input' role='combobox' aria-expanded='true'",
|
1911
|
-
" aria-autocomplete='list' />",
|
1912
|
-
" </div>",
|
1913
|
-
" <ul class='select2-results' role='listbox'>",
|
1914
|
-
" </ul>",
|
1915
|
-
"</div>"].join(""));
|
1916
|
-
return container;
|
1917
|
-
},
|
1918
|
-
|
1919
|
-
// single
|
1920
|
-
enableInterface: function() {
|
1921
|
-
if (this.parent.enableInterface.apply(this, arguments)) {
|
1922
|
-
this.focusser.prop("disabled", !this.isInterfaceEnabled());
|
1923
|
-
}
|
1924
|
-
},
|
1925
|
-
|
1926
|
-
// single
|
1927
|
-
opening: function () {
|
1928
|
-
var el, range, len;
|
1929
|
-
|
1930
|
-
if (this.opts.minimumResultsForSearch >= 0) {
|
1931
|
-
this.showSearch(true);
|
1932
|
-
}
|
1933
|
-
|
1934
|
-
this.parent.opening.apply(this, arguments);
|
1935
|
-
|
1936
|
-
if (this.showSearchInput !== false) {
|
1937
|
-
// IE appends focusser.val() at the end of field :/ so we manually insert it at the beginning using a range
|
1938
|
-
// all other browsers handle this just fine
|
1939
|
-
|
1940
|
-
this.search.val(this.focusser.val());
|
1941
|
-
}
|
1942
|
-
if (this.opts.shouldFocusInput(this)) {
|
1943
|
-
this.search.focus();
|
1944
|
-
// move the cursor to the end after focussing, otherwise it will be at the beginning and
|
1945
|
-
// new text will appear *before* focusser.val()
|
1946
|
-
el = this.search.get(0);
|
1947
|
-
if (el.createTextRange) {
|
1948
|
-
range = el.createTextRange();
|
1949
|
-
range.collapse(false);
|
1950
|
-
range.select();
|
1951
|
-
} else if (el.setSelectionRange) {
|
1952
|
-
len = this.search.val().length;
|
1953
|
-
el.setSelectionRange(len, len);
|
1954
|
-
}
|
1955
|
-
}
|
1956
|
-
|
1957
|
-
// initializes search's value with nextSearchTerm (if defined by user)
|
1958
|
-
// ignore nextSearchTerm if the dropdown is opened by the user pressing a letter
|
1959
|
-
if(this.search.val() === "") {
|
1960
|
-
if(this.nextSearchTerm != undefined){
|
1961
|
-
this.search.val(this.nextSearchTerm);
|
1962
|
-
this.search.select();
|
1963
|
-
}
|
1964
|
-
}
|
1965
|
-
|
1966
|
-
this.focusser.prop("disabled", true).val("");
|
1967
|
-
this.updateResults(true);
|
1968
|
-
this.opts.element.trigger($.Event("select2-open"));
|
1969
|
-
},
|
1970
|
-
|
1971
|
-
// single
|
1972
|
-
close: function () {
|
1973
|
-
if (!this.opened()) return;
|
1974
|
-
this.parent.close.apply(this, arguments);
|
1975
|
-
|
1976
|
-
this.focusser.prop("disabled", false);
|
1977
|
-
|
1978
|
-
if (this.opts.shouldFocusInput(this)) {
|
1979
|
-
this.focusser.focus();
|
1980
|
-
}
|
1981
|
-
},
|
1982
|
-
|
1983
|
-
// single
|
1984
|
-
focus: function () {
|
1985
|
-
if (this.opened()) {
|
1986
|
-
this.close();
|
1987
|
-
} else {
|
1988
|
-
this.focusser.prop("disabled", false);
|
1989
|
-
if (this.opts.shouldFocusInput(this)) {
|
1990
|
-
this.focusser.focus();
|
1991
|
-
}
|
1992
|
-
}
|
1993
|
-
},
|
1994
|
-
|
1995
|
-
// single
|
1996
|
-
isFocused: function () {
|
1997
|
-
return this.container.hasClass("select2-container-active");
|
1998
|
-
},
|
1999
|
-
|
2000
|
-
// single
|
2001
|
-
cancel: function () {
|
2002
|
-
this.parent.cancel.apply(this, arguments);
|
2003
|
-
this.focusser.prop("disabled", false);
|
2004
|
-
|
2005
|
-
if (this.opts.shouldFocusInput(this)) {
|
2006
|
-
this.focusser.focus();
|
2007
|
-
}
|
2008
|
-
},
|
2009
|
-
|
2010
|
-
// single
|
2011
|
-
destroy: function() {
|
2012
|
-
$("label[for='" + this.focusser.attr('id') + "']")
|
2013
|
-
.attr('for', this.opts.element.attr("id"));
|
2014
|
-
this.parent.destroy.apply(this, arguments);
|
2015
|
-
|
2016
|
-
cleanupJQueryElements.call(this,
|
2017
|
-
"selection",
|
2018
|
-
"focusser"
|
2019
|
-
);
|
2020
|
-
},
|
2021
|
-
|
2022
|
-
// single
|
2023
|
-
initContainer: function () {
|
2024
|
-
|
2025
|
-
var selection,
|
2026
|
-
container = this.container,
|
2027
|
-
dropdown = this.dropdown,
|
2028
|
-
idSuffix = nextUid(),
|
2029
|
-
elementLabel;
|
2030
|
-
|
2031
|
-
if (this.opts.minimumResultsForSearch < 0) {
|
2032
|
-
this.showSearch(false);
|
2033
|
-
} else {
|
2034
|
-
this.showSearch(true);
|
2035
|
-
}
|
2036
|
-
|
2037
|
-
this.selection = selection = container.find(".select2-choice");
|
2038
|
-
|
2039
|
-
this.focusser = container.find(".select2-focusser");
|
2040
|
-
|
2041
|
-
// add aria associations
|
2042
|
-
selection.find(".select2-chosen").attr("id", "select2-chosen-"+idSuffix);
|
2043
|
-
this.focusser.attr("aria-labelledby", "select2-chosen-"+idSuffix);
|
2044
|
-
this.results.attr("id", "select2-results-"+idSuffix);
|
2045
|
-
this.search.attr("aria-owns", "select2-results-"+idSuffix);
|
2046
|
-
|
2047
|
-
// rewrite labels from original element to focusser
|
2048
|
-
this.focusser.attr("id", "s2id_autogen"+idSuffix);
|
2049
|
-
|
2050
|
-
elementLabel = $("label[for='" + this.opts.element.attr("id") + "']");
|
2051
|
-
|
2052
|
-
this.focusser.prev()
|
2053
|
-
.text(elementLabel.text())
|
2054
|
-
.attr('for', this.focusser.attr('id'));
|
2055
|
-
|
2056
|
-
// Ensure the original element retains an accessible name
|
2057
|
-
var originalTitle = this.opts.element.attr("title");
|
2058
|
-
this.opts.element.attr("title", (originalTitle || elementLabel.text()));
|
2059
|
-
|
2060
|
-
this.focusser.attr("tabindex", this.elementTabIndex);
|
2061
|
-
|
2062
|
-
// write label for search field using the label from the focusser element
|
2063
|
-
this.search.attr("id", this.focusser.attr('id') + '_search');
|
2064
|
-
|
2065
|
-
this.search.prev()
|
2066
|
-
.text($("label[for='" + this.focusser.attr('id') + "']").text())
|
2067
|
-
.attr('for', this.search.attr('id'));
|
2068
|
-
|
2069
|
-
this.search.on("keydown", this.bind(function (e) {
|
2070
|
-
if (!this.isInterfaceEnabled()) return;
|
2071
|
-
|
2072
|
-
if (e.which === KEY.PAGE_UP || e.which === KEY.PAGE_DOWN) {
|
2073
|
-
// prevent the page from scrolling
|
2074
|
-
killEvent(e);
|
2075
|
-
return;
|
2076
|
-
}
|
2077
|
-
|
2078
|
-
switch (e.which) {
|
2079
|
-
case KEY.UP:
|
2080
|
-
case KEY.DOWN:
|
2081
|
-
this.moveHighlight((e.which === KEY.UP) ? -1 : 1);
|
2082
|
-
killEvent(e);
|
2083
|
-
return;
|
2084
|
-
case KEY.ENTER:
|
2085
|
-
this.selectHighlighted();
|
2086
|
-
killEvent(e);
|
2087
|
-
return;
|
2088
|
-
case KEY.TAB:
|
2089
|
-
this.selectHighlighted({noFocus: true});
|
2090
|
-
return;
|
2091
|
-
case KEY.ESC:
|
2092
|
-
this.cancel(e);
|
2093
|
-
killEvent(e);
|
2094
|
-
return;
|
2095
|
-
}
|
2096
|
-
}));
|
2097
|
-
|
2098
|
-
this.search.on("blur", this.bind(function(e) {
|
2099
|
-
// a workaround for chrome to keep the search field focussed when the scroll bar is used to scroll the dropdown.
|
2100
|
-
// without this the search field loses focus which is annoying
|
2101
|
-
if (document.activeElement === this.body.get(0)) {
|
2102
|
-
window.setTimeout(this.bind(function() {
|
2103
|
-
if (this.opened()) {
|
2104
|
-
this.search.focus();
|
2105
|
-
}
|
2106
|
-
}), 0);
|
2107
|
-
}
|
2108
|
-
}));
|
2109
|
-
|
2110
|
-
this.focusser.on("keydown", this.bind(function (e) {
|
2111
|
-
if (!this.isInterfaceEnabled()) return;
|
2112
|
-
|
2113
|
-
if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC) {
|
2114
|
-
return;
|
2115
|
-
}
|
2116
|
-
|
2117
|
-
if (this.opts.openOnEnter === false && e.which === KEY.ENTER) {
|
2118
|
-
killEvent(e);
|
2119
|
-
return;
|
2120
|
-
}
|
2121
|
-
|
2122
|
-
if (e.which == KEY.DOWN || e.which == KEY.UP
|
2123
|
-
|| (e.which == KEY.ENTER && this.opts.openOnEnter)) {
|
2124
|
-
|
2125
|
-
if (e.altKey || e.ctrlKey || e.shiftKey || e.metaKey) return;
|
2126
|
-
|
2127
|
-
this.open();
|
2128
|
-
killEvent(e);
|
2129
|
-
return;
|
2130
|
-
}
|
2131
|
-
|
2132
|
-
if (e.which == KEY.DELETE || e.which == KEY.BACKSPACE) {
|
2133
|
-
if (this.opts.allowClear) {
|
2134
|
-
this.clear();
|
2135
|
-
}
|
2136
|
-
killEvent(e);
|
2137
|
-
return;
|
2138
|
-
}
|
2139
|
-
}));
|
2140
|
-
|
2141
|
-
|
2142
|
-
installKeyUpChangeEvent(this.focusser);
|
2143
|
-
this.focusser.on("keyup-change input", this.bind(function(e) {
|
2144
|
-
if (this.opts.minimumResultsForSearch >= 0) {
|
2145
|
-
e.stopPropagation();
|
2146
|
-
if (this.opened()) return;
|
2147
|
-
this.open();
|
2148
|
-
}
|
2149
|
-
}));
|
2150
|
-
|
2151
|
-
selection.on("mousedown touchstart", "abbr", this.bind(function (e) {
|
2152
|
-
if (!this.isInterfaceEnabled()) return;
|
2153
|
-
this.clear();
|
2154
|
-
killEventImmediately(e);
|
2155
|
-
this.close();
|
2156
|
-
this.selection.focus();
|
2157
|
-
}));
|
2158
|
-
|
2159
|
-
selection.on("mousedown touchstart", this.bind(function (e) {
|
2160
|
-
// Prevent IE from generating a click event on the body
|
2161
|
-
reinsertElement(selection);
|
2162
|
-
|
2163
|
-
if (!this.container.hasClass("select2-container-active")) {
|
2164
|
-
this.opts.element.trigger($.Event("select2-focus"));
|
2165
|
-
}
|
2166
|
-
|
2167
|
-
if (this.opened()) {
|
2168
|
-
this.close();
|
2169
|
-
} else if (this.isInterfaceEnabled()) {
|
2170
|
-
this.open();
|
2171
|
-
}
|
2172
|
-
|
2173
|
-
killEvent(e);
|
2174
|
-
}));
|
2175
|
-
|
2176
|
-
dropdown.on("mousedown touchstart", this.bind(function() {
|
2177
|
-
if (this.opts.shouldFocusInput(this)) {
|
2178
|
-
this.search.focus();
|
2179
|
-
}
|
2180
|
-
}));
|
2181
|
-
|
2182
|
-
selection.on("focus", this.bind(function(e) {
|
2183
|
-
killEvent(e);
|
2184
|
-
}));
|
2185
|
-
|
2186
|
-
this.focusser.on("focus", this.bind(function(){
|
2187
|
-
if (!this.container.hasClass("select2-container-active")) {
|
2188
|
-
this.opts.element.trigger($.Event("select2-focus"));
|
2189
|
-
}
|
2190
|
-
this.container.addClass("select2-container-active");
|
2191
|
-
})).on("blur", this.bind(function() {
|
2192
|
-
if (!this.opened()) {
|
2193
|
-
this.container.removeClass("select2-container-active");
|
2194
|
-
this.opts.element.trigger($.Event("select2-blur"));
|
2195
|
-
}
|
2196
|
-
}));
|
2197
|
-
this.search.on("focus", this.bind(function(){
|
2198
|
-
if (!this.container.hasClass("select2-container-active")) {
|
2199
|
-
this.opts.element.trigger($.Event("select2-focus"));
|
2200
|
-
}
|
2201
|
-
this.container.addClass("select2-container-active");
|
2202
|
-
}));
|
2203
|
-
|
2204
|
-
this.initContainerWidth();
|
2205
|
-
this.opts.element.addClass("select2-offscreen");
|
2206
|
-
this.setPlaceholder();
|
2207
|
-
|
2208
|
-
},
|
2209
|
-
|
2210
|
-
// single
|
2211
|
-
clear: function(triggerChange) {
|
2212
|
-
var data=this.selection.data("select2-data");
|
2213
|
-
if (data) { // guard against queued quick consecutive clicks
|
2214
|
-
var evt = $.Event("select2-clearing");
|
2215
|
-
this.opts.element.trigger(evt);
|
2216
|
-
if (evt.isDefaultPrevented()) {
|
2217
|
-
return;
|
2218
|
-
}
|
2219
|
-
var placeholderOption = this.getPlaceholderOption();
|
2220
|
-
this.opts.element.val(placeholderOption ? placeholderOption.val() : "");
|
2221
|
-
this.selection.find(".select2-chosen").empty();
|
2222
|
-
this.selection.removeData("select2-data");
|
2223
|
-
this.setPlaceholder();
|
2224
|
-
|
2225
|
-
if (triggerChange !== false){
|
2226
|
-
this.opts.element.trigger({ type: "select2-removed", val: this.id(data), choice: data });
|
2227
|
-
this.triggerChange({removed:data});
|
2228
|
-
}
|
2229
|
-
}
|
2230
|
-
},
|
2231
|
-
|
2232
|
-
/**
|
2233
|
-
* Sets selection based on source element's value
|
2234
|
-
*/
|
2235
|
-
// single
|
2236
|
-
initSelection: function () {
|
2237
|
-
var selected;
|
2238
|
-
if (this.isPlaceholderOptionSelected()) {
|
2239
|
-
this.updateSelection(null);
|
2240
|
-
this.close();
|
2241
|
-
this.setPlaceholder();
|
2242
|
-
} else {
|
2243
|
-
var self = this;
|
2244
|
-
this.opts.initSelection.call(null, this.opts.element, function(selected){
|
2245
|
-
if (selected !== undefined && selected !== null) {
|
2246
|
-
self.updateSelection(selected);
|
2247
|
-
self.close();
|
2248
|
-
self.setPlaceholder();
|
2249
|
-
self.nextSearchTerm = self.opts.nextSearchTerm(selected, self.search.val());
|
2250
|
-
}
|
2251
|
-
});
|
2252
|
-
}
|
2253
|
-
},
|
2254
|
-
|
2255
|
-
isPlaceholderOptionSelected: function() {
|
2256
|
-
var placeholderOption;
|
2257
|
-
if (this.getPlaceholder() === undefined) return false; // no placeholder specified so no option should be considered
|
2258
|
-
return ((placeholderOption = this.getPlaceholderOption()) !== undefined && placeholderOption.prop("selected"))
|
2259
|
-
|| (this.opts.element.val() === "")
|
2260
|
-
|| (this.opts.element.val() === undefined)
|
2261
|
-
|| (this.opts.element.val() === null);
|
2262
|
-
},
|
2263
|
-
|
2264
|
-
// single
|
2265
|
-
prepareOpts: function () {
|
2266
|
-
var opts = this.parent.prepareOpts.apply(this, arguments),
|
2267
|
-
self=this;
|
2268
|
-
|
2269
|
-
if (opts.element.get(0).tagName.toLowerCase() === "select") {
|
2270
|
-
// install the selection initializer
|
2271
|
-
opts.initSelection = function (element, callback) {
|
2272
|
-
var selected = element.find("option").filter(function() { return this.selected && !this.disabled });
|
2273
|
-
// a single select box always has a value, no need to null check 'selected'
|
2274
|
-
callback(self.optionToData(selected));
|
2275
|
-
};
|
2276
|
-
} else if ("data" in opts) {
|
2277
|
-
// install default initSelection when applied to hidden input and data is local
|
2278
|
-
opts.initSelection = opts.initSelection || function (element, callback) {
|
2279
|
-
var id = element.val();
|
2280
|
-
//search in data by id, storing the actual matching item
|
2281
|
-
var match = null;
|
2282
|
-
opts.query({
|
2283
|
-
matcher: function(term, text, el){
|
2284
|
-
var is_match = equal(id, opts.id(el));
|
2285
|
-
if (is_match) {
|
2286
|
-
match = el;
|
2287
|
-
}
|
2288
|
-
return is_match;
|
2289
|
-
},
|
2290
|
-
callback: !$.isFunction(callback) ? $.noop : function() {
|
2291
|
-
callback(match);
|
2292
|
-
}
|
2293
|
-
});
|
2294
|
-
};
|
2295
|
-
}
|
2296
|
-
|
2297
|
-
return opts;
|
2298
|
-
},
|
2299
|
-
|
2300
|
-
// single
|
2301
|
-
getPlaceholder: function() {
|
2302
|
-
// if a placeholder is specified on a single select without a valid placeholder option ignore it
|
2303
|
-
if (this.select) {
|
2304
|
-
if (this.getPlaceholderOption() === undefined) {
|
2305
|
-
return undefined;
|
2306
|
-
}
|
2307
|
-
}
|
2308
|
-
|
2309
|
-
return this.parent.getPlaceholder.apply(this, arguments);
|
2310
|
-
},
|
2311
|
-
|
2312
|
-
// single
|
2313
|
-
setPlaceholder: function () {
|
2314
|
-
var placeholder = this.getPlaceholder();
|
2315
|
-
|
2316
|
-
if (this.isPlaceholderOptionSelected() && placeholder !== undefined) {
|
2317
|
-
|
2318
|
-
// check for a placeholder option if attached to a select
|
2319
|
-
if (this.select && this.getPlaceholderOption() === undefined) return;
|
2320
|
-
|
2321
|
-
this.selection.find(".select2-chosen").html(this.opts.escapeMarkup(placeholder));
|
2322
|
-
|
2323
|
-
this.selection.addClass("select2-default");
|
2324
|
-
|
2325
|
-
this.container.removeClass("select2-allowclear");
|
2326
|
-
}
|
2327
|
-
},
|
2328
|
-
|
2329
|
-
// single
|
2330
|
-
postprocessResults: function (data, initial, noHighlightUpdate) {
|
2331
|
-
var selected = 0, self = this, showSearchInput = true;
|
2332
|
-
|
2333
|
-
// find the selected element in the result list
|
2334
|
-
|
2335
|
-
this.findHighlightableChoices().each2(function (i, elm) {
|
2336
|
-
if (equal(self.id(elm.data("select2-data")), self.opts.element.val())) {
|
2337
|
-
selected = i;
|
2338
|
-
return false;
|
2339
|
-
}
|
2340
|
-
});
|
2341
|
-
|
2342
|
-
// and highlight it
|
2343
|
-
if (noHighlightUpdate !== false) {
|
2344
|
-
if (initial === true && selected >= 0) {
|
2345
|
-
this.highlight(selected);
|
2346
|
-
} else {
|
2347
|
-
this.highlight(0);
|
2348
|
-
}
|
2349
|
-
}
|
2350
|
-
|
2351
|
-
// hide the search box if this is the first we got the results and there are enough of them for search
|
2352
|
-
|
2353
|
-
if (initial === true) {
|
2354
|
-
var min = this.opts.minimumResultsForSearch;
|
2355
|
-
if (min >= 0) {
|
2356
|
-
this.showSearch(countResults(data.results) >= min);
|
2357
|
-
}
|
2358
|
-
}
|
2359
|
-
},
|
2360
|
-
|
2361
|
-
// single
|
2362
|
-
showSearch: function(showSearchInput) {
|
2363
|
-
if (this.showSearchInput === showSearchInput) return;
|
2364
|
-
|
2365
|
-
this.showSearchInput = showSearchInput;
|
2366
|
-
|
2367
|
-
this.dropdown.find(".select2-search").toggleClass("select2-search-hidden", !showSearchInput);
|
2368
|
-
this.dropdown.find(".select2-search").toggleClass("select2-offscreen", !showSearchInput);
|
2369
|
-
//add "select2-with-searchbox" to the container if search box is shown
|
2370
|
-
$(this.dropdown, this.container).toggleClass("select2-with-searchbox", showSearchInput);
|
2371
|
-
},
|
2372
|
-
|
2373
|
-
// single
|
2374
|
-
onSelect: function (data, options) {
|
2375
|
-
|
2376
|
-
if (!this.triggerSelect(data)) { return; }
|
2377
|
-
|
2378
|
-
var old = this.opts.element.val(),
|
2379
|
-
oldData = this.data();
|
2380
|
-
|
2381
|
-
this.opts.element.val(this.id(data));
|
2382
|
-
this.updateSelection(data);
|
2383
|
-
|
2384
|
-
this.opts.element.trigger({ type: "select2-selected", val: this.id(data), choice: data });
|
2385
|
-
|
2386
|
-
this.nextSearchTerm = this.opts.nextSearchTerm(data, this.search.val());
|
2387
|
-
this.close();
|
2388
|
-
|
2389
|
-
if ((!options || !options.noFocus) && this.opts.shouldFocusInput(this)) {
|
2390
|
-
this.focusser.focus();
|
2391
|
-
}
|
2392
|
-
|
2393
|
-
if (!equal(old, this.id(data))) {
|
2394
|
-
this.triggerChange({ added: data, removed: oldData });
|
2395
|
-
}
|
2396
|
-
},
|
2397
|
-
|
2398
|
-
// single
|
2399
|
-
updateSelection: function (data) {
|
2400
|
-
|
2401
|
-
var container=this.selection.find(".select2-chosen"), formatted, cssClass;
|
2402
|
-
|
2403
|
-
this.selection.data("select2-data", data);
|
2404
|
-
|
2405
|
-
container.empty();
|
2406
|
-
if (data !== null) {
|
2407
|
-
formatted=this.opts.formatSelection(data, container, this.opts.escapeMarkup);
|
2408
|
-
}
|
2409
|
-
if (formatted !== undefined) {
|
2410
|
-
container.append(formatted);
|
2411
|
-
}
|
2412
|
-
cssClass=this.opts.formatSelectionCssClass(data, container);
|
2413
|
-
if (cssClass !== undefined) {
|
2414
|
-
container.addClass(cssClass);
|
2415
|
-
}
|
2416
|
-
|
2417
|
-
this.selection.removeClass("select2-default");
|
2418
|
-
|
2419
|
-
if (this.opts.allowClear && this.getPlaceholder() !== undefined) {
|
2420
|
-
this.container.addClass("select2-allowclear");
|
2421
|
-
}
|
2422
|
-
},
|
2423
|
-
|
2424
|
-
// single
|
2425
|
-
val: function () {
|
2426
|
-
var val,
|
2427
|
-
triggerChange = false,
|
2428
|
-
data = null,
|
2429
|
-
self = this,
|
2430
|
-
oldData = this.data();
|
2431
|
-
|
2432
|
-
if (arguments.length === 0) {
|
2433
|
-
return this.opts.element.val();
|
2434
|
-
}
|
2435
|
-
|
2436
|
-
val = arguments[0];
|
2437
|
-
|
2438
|
-
if (arguments.length > 1) {
|
2439
|
-
triggerChange = arguments[1];
|
2440
|
-
}
|
2441
|
-
|
2442
|
-
if (this.select) {
|
2443
|
-
this.select
|
2444
|
-
.val(val)
|
2445
|
-
.find("option").filter(function() { return this.selected }).each2(function (i, elm) {
|
2446
|
-
data = self.optionToData(elm);
|
2447
|
-
return false;
|
2448
|
-
});
|
2449
|
-
this.updateSelection(data);
|
2450
|
-
this.setPlaceholder();
|
2451
|
-
if (triggerChange) {
|
2452
|
-
this.triggerChange({added: data, removed:oldData});
|
2453
|
-
}
|
2454
|
-
} else {
|
2455
|
-
// val is an id. !val is true for [undefined,null,'',0] - 0 is legal
|
2456
|
-
if (!val && val !== 0) {
|
2457
|
-
this.clear(triggerChange);
|
2458
|
-
return;
|
2459
|
-
}
|
2460
|
-
if (this.opts.initSelection === undefined) {
|
2461
|
-
throw new Error("cannot call val() if initSelection() is not defined");
|
2462
|
-
}
|
2463
|
-
this.opts.element.val(val);
|
2464
|
-
this.opts.initSelection(this.opts.element, function(data){
|
2465
|
-
self.opts.element.val(!data ? "" : self.id(data));
|
2466
|
-
self.updateSelection(data);
|
2467
|
-
self.setPlaceholder();
|
2468
|
-
if (triggerChange) {
|
2469
|
-
self.triggerChange({added: data, removed:oldData});
|
2470
|
-
}
|
2471
|
-
});
|
2472
|
-
}
|
2473
|
-
},
|
2474
|
-
|
2475
|
-
// single
|
2476
|
-
clearSearch: function () {
|
2477
|
-
this.search.val("");
|
2478
|
-
this.focusser.val("");
|
2479
|
-
},
|
2480
|
-
|
2481
|
-
// single
|
2482
|
-
data: function(value) {
|
2483
|
-
var data,
|
2484
|
-
triggerChange = false;
|
2485
|
-
|
2486
|
-
if (arguments.length === 0) {
|
2487
|
-
data = this.selection.data("select2-data");
|
2488
|
-
if (data == undefined) data = null;
|
2489
|
-
return data;
|
2490
|
-
} else {
|
2491
|
-
if (arguments.length > 1) {
|
2492
|
-
triggerChange = arguments[1];
|
2493
|
-
}
|
2494
|
-
if (!value) {
|
2495
|
-
this.clear(triggerChange);
|
2496
|
-
} else {
|
2497
|
-
data = this.data();
|
2498
|
-
this.opts.element.val(!value ? "" : this.id(value));
|
2499
|
-
this.updateSelection(value);
|
2500
|
-
if (triggerChange) {
|
2501
|
-
this.triggerChange({added: value, removed:data});
|
2502
|
-
}
|
2503
|
-
}
|
2504
|
-
}
|
2505
|
-
}
|
2506
|
-
});
|
2507
|
-
|
2508
|
-
MultiSelect2 = clazz(AbstractSelect2, {
|
2509
|
-
|
2510
|
-
// multi
|
2511
|
-
createContainer: function () {
|
2512
|
-
var container = $(document.createElement("div")).attr({
|
2513
|
-
"class": "select2-container select2-container-multi"
|
2514
|
-
}).html([
|
2515
|
-
"<ul class='select2-choices'>",
|
2516
|
-
" <li class='select2-search-field'>",
|
2517
|
-
" <label for='' class='select2-offscreen'></label>",
|
2518
|
-
" <input type='text' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' class='select2-input'>",
|
2519
|
-
" </li>",
|
2520
|
-
"</ul>",
|
2521
|
-
"<div class='select2-drop select2-drop-multi select2-display-none'>",
|
2522
|
-
" <ul class='select2-results'>",
|
2523
|
-
" </ul>",
|
2524
|
-
"</div>"].join(""));
|
2525
|
-
return container;
|
2526
|
-
},
|
2527
|
-
|
2528
|
-
// multi
|
2529
|
-
prepareOpts: function () {
|
2530
|
-
var opts = this.parent.prepareOpts.apply(this, arguments),
|
2531
|
-
self=this;
|
2532
|
-
|
2533
|
-
// TODO validate placeholder is a string if specified
|
2534
|
-
|
2535
|
-
if (opts.element.get(0).tagName.toLowerCase() === "select") {
|
2536
|
-
// install the selection initializer
|
2537
|
-
opts.initSelection = function (element, callback) {
|
2538
|
-
|
2539
|
-
var data = [];
|
2540
|
-
|
2541
|
-
element.find("option").filter(function() { return this.selected && !this.disabled }).each2(function (i, elm) {
|
2542
|
-
data.push(self.optionToData(elm));
|
2543
|
-
});
|
2544
|
-
callback(data);
|
2545
|
-
};
|
2546
|
-
} else if ("data" in opts) {
|
2547
|
-
// install default initSelection when applied to hidden input and data is local
|
2548
|
-
opts.initSelection = opts.initSelection || function (element, callback) {
|
2549
|
-
var ids = splitVal(element.val(), opts.separator);
|
2550
|
-
//search in data by array of ids, storing matching items in a list
|
2551
|
-
var matches = [];
|
2552
|
-
opts.query({
|
2553
|
-
matcher: function(term, text, el){
|
2554
|
-
var is_match = $.grep(ids, function(id) {
|
2555
|
-
return equal(id, opts.id(el));
|
2556
|
-
}).length;
|
2557
|
-
if (is_match) {
|
2558
|
-
matches.push(el);
|
2559
|
-
}
|
2560
|
-
return is_match;
|
2561
|
-
},
|
2562
|
-
callback: !$.isFunction(callback) ? $.noop : function() {
|
2563
|
-
// reorder matches based on the order they appear in the ids array because right now
|
2564
|
-
// they are in the order in which they appear in data array
|
2565
|
-
var ordered = [];
|
2566
|
-
for (var i = 0; i < ids.length; i++) {
|
2567
|
-
var id = ids[i];
|
2568
|
-
for (var j = 0; j < matches.length; j++) {
|
2569
|
-
var match = matches[j];
|
2570
|
-
if (equal(id, opts.id(match))) {
|
2571
|
-
ordered.push(match);
|
2572
|
-
matches.splice(j, 1);
|
2573
|
-
break;
|
2574
|
-
}
|
2575
|
-
}
|
2576
|
-
}
|
2577
|
-
callback(ordered);
|
2578
|
-
}
|
2579
|
-
});
|
2580
|
-
};
|
2581
|
-
}
|
2582
|
-
|
2583
|
-
return opts;
|
2584
|
-
},
|
2585
|
-
|
2586
|
-
// multi
|
2587
|
-
selectChoice: function (choice) {
|
2588
|
-
|
2589
|
-
var selected = this.container.find(".select2-search-choice-focus");
|
2590
|
-
if (selected.length && choice && choice[0] == selected[0]) {
|
2591
|
-
|
2592
|
-
} else {
|
2593
|
-
if (selected.length) {
|
2594
|
-
this.opts.element.trigger("choice-deselected", selected);
|
2595
|
-
}
|
2596
|
-
selected.removeClass("select2-search-choice-focus");
|
2597
|
-
if (choice && choice.length) {
|
2598
|
-
this.close();
|
2599
|
-
choice.addClass("select2-search-choice-focus");
|
2600
|
-
this.opts.element.trigger("choice-selected", choice);
|
2601
|
-
}
|
2602
|
-
}
|
2603
|
-
},
|
2604
|
-
|
2605
|
-
// multi
|
2606
|
-
destroy: function() {
|
2607
|
-
$("label[for='" + this.search.attr('id') + "']")
|
2608
|
-
.attr('for', this.opts.element.attr("id"));
|
2609
|
-
this.parent.destroy.apply(this, arguments);
|
2610
|
-
|
2611
|
-
cleanupJQueryElements.call(this,
|
2612
|
-
"searchContainer",
|
2613
|
-
"selection"
|
2614
|
-
);
|
2615
|
-
},
|
2616
|
-
|
2617
|
-
// multi
|
2618
|
-
initContainer: function () {
|
2619
|
-
|
2620
|
-
var selector = ".select2-choices", selection;
|
2621
|
-
|
2622
|
-
this.searchContainer = this.container.find(".select2-search-field");
|
2623
|
-
this.selection = selection = this.container.find(selector);
|
2624
|
-
|
2625
|
-
var _this = this;
|
2626
|
-
this.selection.on("click", ".select2-search-choice:not(.select2-locked)", function (e) {
|
2627
|
-
//killEvent(e);
|
2628
|
-
_this.search[0].focus();
|
2629
|
-
_this.selectChoice($(this));
|
2630
|
-
});
|
2631
|
-
|
2632
|
-
// rewrite labels from original element to focusser
|
2633
|
-
this.search.attr("id", "s2id_autogen"+nextUid());
|
2634
|
-
|
2635
|
-
this.search.prev()
|
2636
|
-
.text($("label[for='" + this.opts.element.attr("id") + "']").text())
|
2637
|
-
.attr('for', this.search.attr('id'));
|
2638
|
-
|
2639
|
-
this.search.on("input paste", this.bind(function() {
|
2640
|
-
if (!this.isInterfaceEnabled()) return;
|
2641
|
-
if (!this.opened()) {
|
2642
|
-
this.open();
|
2643
|
-
}
|
2644
|
-
}));
|
2645
|
-
|
2646
|
-
this.search.attr("tabindex", this.elementTabIndex);
|
2647
|
-
|
2648
|
-
this.keydowns = 0;
|
2649
|
-
this.search.on("keydown", this.bind(function (e) {
|
2650
|
-
if (!this.isInterfaceEnabled()) return;
|
2651
|
-
|
2652
|
-
++this.keydowns;
|
2653
|
-
var selected = selection.find(".select2-search-choice-focus");
|
2654
|
-
var prev = selected.prev(".select2-search-choice:not(.select2-locked)");
|
2655
|
-
var next = selected.next(".select2-search-choice:not(.select2-locked)");
|
2656
|
-
var pos = getCursorInfo(this.search);
|
2657
|
-
|
2658
|
-
if (selected.length &&
|
2659
|
-
(e.which == KEY.LEFT || e.which == KEY.RIGHT || e.which == KEY.BACKSPACE || e.which == KEY.DELETE || e.which == KEY.ENTER)) {
|
2660
|
-
var selectedChoice = selected;
|
2661
|
-
if (e.which == KEY.LEFT && prev.length) {
|
2662
|
-
selectedChoice = prev;
|
2663
|
-
}
|
2664
|
-
else if (e.which == KEY.RIGHT) {
|
2665
|
-
selectedChoice = next.length ? next : null;
|
2666
|
-
}
|
2667
|
-
else if (e.which === KEY.BACKSPACE) {
|
2668
|
-
if (this.unselect(selected.first())) {
|
2669
|
-
this.search.width(10);
|
2670
|
-
selectedChoice = prev.length ? prev : next;
|
2671
|
-
}
|
2672
|
-
} else if (e.which == KEY.DELETE) {
|
2673
|
-
if (this.unselect(selected.first())) {
|
2674
|
-
this.search.width(10);
|
2675
|
-
selectedChoice = next.length ? next : null;
|
2676
|
-
}
|
2677
|
-
} else if (e.which == KEY.ENTER) {
|
2678
|
-
selectedChoice = null;
|
2679
|
-
}
|
2680
|
-
|
2681
|
-
this.selectChoice(selectedChoice);
|
2682
|
-
killEvent(e);
|
2683
|
-
if (!selectedChoice || !selectedChoice.length) {
|
2684
|
-
this.open();
|
2685
|
-
}
|
2686
|
-
return;
|
2687
|
-
} else if (((e.which === KEY.BACKSPACE && this.keydowns == 1)
|
2688
|
-
|| e.which == KEY.LEFT) && (pos.offset == 0 && !pos.length)) {
|
2689
|
-
|
2690
|
-
this.selectChoice(selection.find(".select2-search-choice:not(.select2-locked)").last());
|
2691
|
-
killEvent(e);
|
2692
|
-
return;
|
2693
|
-
} else {
|
2694
|
-
this.selectChoice(null);
|
2695
|
-
}
|
2696
|
-
|
2697
|
-
if (this.opened()) {
|
2698
|
-
switch (e.which) {
|
2699
|
-
case KEY.UP:
|
2700
|
-
case KEY.DOWN:
|
2701
|
-
this.moveHighlight((e.which === KEY.UP) ? -1 : 1);
|
2702
|
-
killEvent(e);
|
2703
|
-
return;
|
2704
|
-
case KEY.ENTER:
|
2705
|
-
this.selectHighlighted();
|
2706
|
-
killEvent(e);
|
2707
|
-
return;
|
2708
|
-
case KEY.TAB:
|
2709
|
-
this.selectHighlighted({noFocus:true});
|
2710
|
-
this.close();
|
2711
|
-
return;
|
2712
|
-
case KEY.ESC:
|
2713
|
-
this.cancel(e);
|
2714
|
-
killEvent(e);
|
2715
|
-
return;
|
2716
|
-
}
|
2717
|
-
}
|
2718
|
-
|
2719
|
-
if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e)
|
2720
|
-
|| e.which === KEY.BACKSPACE || e.which === KEY.ESC) {
|
2721
|
-
return;
|
2722
|
-
}
|
2723
|
-
|
2724
|
-
if (e.which === KEY.ENTER) {
|
2725
|
-
if (this.opts.openOnEnter === false) {
|
2726
|
-
return;
|
2727
|
-
} else if (e.altKey || e.ctrlKey || e.shiftKey || e.metaKey) {
|
2728
|
-
return;
|
2729
|
-
}
|
2730
|
-
}
|
2731
|
-
|
2732
|
-
this.open();
|
2733
|
-
|
2734
|
-
if (e.which === KEY.PAGE_UP || e.which === KEY.PAGE_DOWN) {
|
2735
|
-
// prevent the page from scrolling
|
2736
|
-
killEvent(e);
|
2737
|
-
}
|
2738
|
-
|
2739
|
-
if (e.which === KEY.ENTER) {
|
2740
|
-
// prevent form from being submitted
|
2741
|
-
killEvent(e);
|
2742
|
-
}
|
2743
|
-
|
2744
|
-
}));
|
2745
|
-
|
2746
|
-
this.search.on("keyup", this.bind(function (e) {
|
2747
|
-
this.keydowns = 0;
|
2748
|
-
this.resizeSearch();
|
2749
|
-
})
|
2750
|
-
);
|
2751
|
-
|
2752
|
-
this.search.on("blur", this.bind(function(e) {
|
2753
|
-
this.container.removeClass("select2-container-active");
|
2754
|
-
this.search.removeClass("select2-focused");
|
2755
|
-
this.selectChoice(null);
|
2756
|
-
if (!this.opened()) this.clearSearch();
|
2757
|
-
e.stopImmediatePropagation();
|
2758
|
-
this.opts.element.trigger($.Event("select2-blur"));
|
2759
|
-
}));
|
2760
|
-
|
2761
|
-
this.container.on("click", selector, this.bind(function (e) {
|
2762
|
-
if (!this.isInterfaceEnabled()) return;
|
2763
|
-
if ($(e.target).closest(".select2-search-choice").length > 0) {
|
2764
|
-
// clicked inside a select2 search choice, do not open
|
2765
|
-
return;
|
2766
|
-
}
|
2767
|
-
this.selectChoice(null);
|
2768
|
-
this.clearPlaceholder();
|
2769
|
-
if (!this.container.hasClass("select2-container-active")) {
|
2770
|
-
this.opts.element.trigger($.Event("select2-focus"));
|
2771
|
-
}
|
2772
|
-
this.open();
|
2773
|
-
this.focusSearch();
|
2774
|
-
e.preventDefault();
|
2775
|
-
}));
|
2776
|
-
|
2777
|
-
this.container.on("focus", selector, this.bind(function () {
|
2778
|
-
if (!this.isInterfaceEnabled()) return;
|
2779
|
-
if (!this.container.hasClass("select2-container-active")) {
|
2780
|
-
this.opts.element.trigger($.Event("select2-focus"));
|
2781
|
-
}
|
2782
|
-
this.container.addClass("select2-container-active");
|
2783
|
-
this.dropdown.addClass("select2-drop-active");
|
2784
|
-
this.clearPlaceholder();
|
2785
|
-
}));
|
2786
|
-
|
2787
|
-
this.initContainerWidth();
|
2788
|
-
this.opts.element.addClass("select2-offscreen");
|
2789
|
-
|
2790
|
-
// set the placeholder if necessary
|
2791
|
-
this.clearSearch();
|
2792
|
-
},
|
2793
|
-
|
2794
|
-
// multi
|
2795
|
-
enableInterface: function() {
|
2796
|
-
if (this.parent.enableInterface.apply(this, arguments)) {
|
2797
|
-
this.search.prop("disabled", !this.isInterfaceEnabled());
|
2798
|
-
}
|
2799
|
-
},
|
2800
|
-
|
2801
|
-
// multi
|
2802
|
-
initSelection: function () {
|
2803
|
-
var data;
|
2804
|
-
if (this.opts.element.val() === "" && this.opts.element.text() === "") {
|
2805
|
-
this.updateSelection([]);
|
2806
|
-
this.close();
|
2807
|
-
// set the placeholder if necessary
|
2808
|
-
this.clearSearch();
|
2809
|
-
}
|
2810
|
-
if (this.select || this.opts.element.val() !== "") {
|
2811
|
-
var self = this;
|
2812
|
-
this.opts.initSelection.call(null, this.opts.element, function(data){
|
2813
|
-
if (data !== undefined && data !== null) {
|
2814
|
-
self.updateSelection(data);
|
2815
|
-
self.close();
|
2816
|
-
// set the placeholder if necessary
|
2817
|
-
self.clearSearch();
|
2818
|
-
}
|
2819
|
-
});
|
2820
|
-
}
|
2821
|
-
},
|
2822
|
-
|
2823
|
-
// multi
|
2824
|
-
clearSearch: function () {
|
2825
|
-
var placeholder = this.getPlaceholder(),
|
2826
|
-
maxWidth = this.getMaxSearchWidth();
|
2827
|
-
|
2828
|
-
if (placeholder !== undefined && this.getVal().length === 0 && this.search.hasClass("select2-focused") === false) {
|
2829
|
-
this.search.val(placeholder).addClass("select2-default");
|
2830
|
-
// stretch the search box to full width of the container so as much of the placeholder is visible as possible
|
2831
|
-
// we could call this.resizeSearch(), but we do not because that requires a sizer and we do not want to create one so early because of a firefox bug, see #944
|
2832
|
-
this.search.width(maxWidth > 0 ? maxWidth : this.container.css("width"));
|
2833
|
-
} else {
|
2834
|
-
this.search.val("").width(10);
|
2835
|
-
}
|
2836
|
-
},
|
2837
|
-
|
2838
|
-
// multi
|
2839
|
-
clearPlaceholder: function () {
|
2840
|
-
if (this.search.hasClass("select2-default")) {
|
2841
|
-
this.search.val("").removeClass("select2-default");
|
2842
|
-
}
|
2843
|
-
},
|
2844
|
-
|
2845
|
-
// multi
|
2846
|
-
opening: function () {
|
2847
|
-
this.clearPlaceholder(); // should be done before super so placeholder is not used to search
|
2848
|
-
this.resizeSearch();
|
2849
|
-
|
2850
|
-
this.parent.opening.apply(this, arguments);
|
2851
|
-
|
2852
|
-
this.focusSearch();
|
2853
|
-
|
2854
|
-
// initializes search's value with nextSearchTerm (if defined by user)
|
2855
|
-
// ignore nextSearchTerm if the dropdown is opened by the user pressing a letter
|
2856
|
-
if(this.search.val() === "") {
|
2857
|
-
if(this.nextSearchTerm != undefined){
|
2858
|
-
this.search.val(this.nextSearchTerm);
|
2859
|
-
this.search.select();
|
2860
|
-
}
|
2861
|
-
}
|
2862
|
-
|
2863
|
-
this.updateResults(true);
|
2864
|
-
if (this.opts.shouldFocusInput(this)) {
|
2865
|
-
this.search.focus();
|
2866
|
-
}
|
2867
|
-
this.opts.element.trigger($.Event("select2-open"));
|
2868
|
-
},
|
2869
|
-
|
2870
|
-
// multi
|
2871
|
-
close: function () {
|
2872
|
-
if (!this.opened()) return;
|
2873
|
-
this.parent.close.apply(this, arguments);
|
2874
|
-
},
|
2875
|
-
|
2876
|
-
// multi
|
2877
|
-
focus: function () {
|
2878
|
-
this.close();
|
2879
|
-
this.search.focus();
|
2880
|
-
},
|
2881
|
-
|
2882
|
-
// multi
|
2883
|
-
isFocused: function () {
|
2884
|
-
return this.search.hasClass("select2-focused");
|
2885
|
-
},
|
2886
|
-
|
2887
|
-
// multi
|
2888
|
-
updateSelection: function (data) {
|
2889
|
-
var ids = [], filtered = [], self = this;
|
2890
|
-
|
2891
|
-
// filter out duplicates
|
2892
|
-
$(data).each(function () {
|
2893
|
-
if (indexOf(self.id(this), ids) < 0) {
|
2894
|
-
ids.push(self.id(this));
|
2895
|
-
filtered.push(this);
|
2896
|
-
}
|
2897
|
-
});
|
2898
|
-
data = filtered;
|
2899
|
-
|
2900
|
-
this.selection.find(".select2-search-choice").remove();
|
2901
|
-
$(data).each(function () {
|
2902
|
-
self.addSelectedChoice(this);
|
2903
|
-
});
|
2904
|
-
self.postprocessResults();
|
2905
|
-
},
|
2906
|
-
|
2907
|
-
// multi
|
2908
|
-
tokenize: function() {
|
2909
|
-
var input = this.search.val();
|
2910
|
-
input = this.opts.tokenizer.call(this, input, this.data(), this.bind(this.onSelect), this.opts);
|
2911
|
-
if (input != null && input != undefined) {
|
2912
|
-
this.search.val(input);
|
2913
|
-
if (input.length > 0) {
|
2914
|
-
this.open();
|
2915
|
-
}
|
2916
|
-
}
|
2917
|
-
|
2918
|
-
},
|
2919
|
-
|
2920
|
-
// multi
|
2921
|
-
onSelect: function (data, options) {
|
2922
|
-
|
2923
|
-
if (!this.triggerSelect(data)) { return; }
|
2924
|
-
|
2925
|
-
this.addSelectedChoice(data);
|
2926
|
-
|
2927
|
-
this.opts.element.trigger({ type: "selected", val: this.id(data), choice: data });
|
2928
|
-
|
2929
|
-
// keep track of the search's value before it gets cleared
|
2930
|
-
this.nextSearchTerm = this.opts.nextSearchTerm(data, this.search.val());
|
2931
|
-
|
2932
|
-
this.clearSearch();
|
2933
|
-
this.updateResults();
|
2934
|
-
|
2935
|
-
if (this.select || !this.opts.closeOnSelect) this.postprocessResults(data, false, this.opts.closeOnSelect===true);
|
2936
|
-
|
2937
|
-
if (this.opts.closeOnSelect) {
|
2938
|
-
this.close();
|
2939
|
-
this.search.width(10);
|
2940
|
-
} else {
|
2941
|
-
if (this.countSelectableResults()>0) {
|
2942
|
-
this.search.width(10);
|
2943
|
-
this.resizeSearch();
|
2944
|
-
if (this.getMaximumSelectionSize() > 0 && this.val().length >= this.getMaximumSelectionSize()) {
|
2945
|
-
// if we reached max selection size repaint the results so choices
|
2946
|
-
// are replaced with the max selection reached message
|
2947
|
-
this.updateResults(true);
|
2948
|
-
} else {
|
2949
|
-
// initializes search's value with nextSearchTerm and update search result
|
2950
|
-
if(this.nextSearchTerm != undefined){
|
2951
|
-
this.search.val(this.nextSearchTerm);
|
2952
|
-
this.updateResults();
|
2953
|
-
this.search.select();
|
2954
|
-
}
|
2955
|
-
}
|
2956
|
-
this.positionDropdown();
|
2957
|
-
} else {
|
2958
|
-
// if nothing left to select close
|
2959
|
-
this.close();
|
2960
|
-
this.search.width(10);
|
2961
|
-
}
|
2962
|
-
}
|
2963
|
-
|
2964
|
-
// since its not possible to select an element that has already been
|
2965
|
-
// added we do not need to check if this is a new element before firing change
|
2966
|
-
this.triggerChange({ added: data });
|
2967
|
-
|
2968
|
-
if (!options || !options.noFocus)
|
2969
|
-
this.focusSearch();
|
2970
|
-
},
|
2971
|
-
|
2972
|
-
// multi
|
2973
|
-
cancel: function () {
|
2974
|
-
this.close();
|
2975
|
-
this.focusSearch();
|
2976
|
-
},
|
2977
|
-
|
2978
|
-
addSelectedChoice: function (data) {
|
2979
|
-
var enableChoice = !data.locked,
|
2980
|
-
enabledItem = $(
|
2981
|
-
"<li class='select2-search-choice'>" +
|
2982
|
-
" <div></div>" +
|
2983
|
-
" <a href='#' class='select2-search-choice-close' tabindex='-1'></a>" +
|
2984
|
-
"</li>"),
|
2985
|
-
disabledItem = $(
|
2986
|
-
"<li class='select2-search-choice select2-locked'>" +
|
2987
|
-
"<div></div>" +
|
2988
|
-
"</li>");
|
2989
|
-
var choice = enableChoice ? enabledItem : disabledItem,
|
2990
|
-
id = this.id(data),
|
2991
|
-
val = this.getVal(),
|
2992
|
-
formatted,
|
2993
|
-
cssClass;
|
2994
|
-
|
2995
|
-
formatted=this.opts.formatSelection(data, choice.find("div"), this.opts.escapeMarkup);
|
2996
|
-
if (formatted != undefined) {
|
2997
|
-
choice.find("div").replaceWith("<div>"+formatted+"</div>");
|
2998
|
-
}
|
2999
|
-
cssClass=this.opts.formatSelectionCssClass(data, choice.find("div"));
|
3000
|
-
if (cssClass != undefined) {
|
3001
|
-
choice.addClass(cssClass);
|
3002
|
-
}
|
3003
|
-
|
3004
|
-
if(enableChoice){
|
3005
|
-
choice.find(".select2-search-choice-close")
|
3006
|
-
.on("mousedown", killEvent)
|
3007
|
-
.on("click dblclick", this.bind(function (e) {
|
3008
|
-
if (!this.isInterfaceEnabled()) return;
|
3009
|
-
|
3010
|
-
this.unselect($(e.target));
|
3011
|
-
this.selection.find(".select2-search-choice-focus").removeClass("select2-search-choice-focus");
|
3012
|
-
killEvent(e);
|
3013
|
-
this.close();
|
3014
|
-
this.focusSearch();
|
3015
|
-
})).on("focus", this.bind(function () {
|
3016
|
-
if (!this.isInterfaceEnabled()) return;
|
3017
|
-
this.container.addClass("select2-container-active");
|
3018
|
-
this.dropdown.addClass("select2-drop-active");
|
3019
|
-
}));
|
3020
|
-
}
|
3021
|
-
|
3022
|
-
choice.data("select2-data", data);
|
3023
|
-
choice.insertBefore(this.searchContainer);
|
3024
|
-
|
3025
|
-
val.push(id);
|
3026
|
-
this.setVal(val);
|
3027
|
-
},
|
3028
|
-
|
3029
|
-
// multi
|
3030
|
-
unselect: function (selected) {
|
3031
|
-
var val = this.getVal(),
|
3032
|
-
data,
|
3033
|
-
index;
|
3034
|
-
selected = selected.closest(".select2-search-choice");
|
3035
|
-
|
3036
|
-
if (selected.length === 0) {
|
3037
|
-
throw "Invalid argument: " + selected + ". Must be .select2-search-choice";
|
3038
|
-
}
|
3039
|
-
|
3040
|
-
data = selected.data("select2-data");
|
3041
|
-
|
3042
|
-
if (!data) {
|
3043
|
-
// prevent a race condition when the 'x' is clicked really fast repeatedly the event can be queued
|
3044
|
-
// and invoked on an element already removed
|
3045
|
-
return;
|
3046
|
-
}
|
3047
|
-
|
3048
|
-
var evt = $.Event("select2-removing");
|
3049
|
-
evt.val = this.id(data);
|
3050
|
-
evt.choice = data;
|
3051
|
-
this.opts.element.trigger(evt);
|
3052
|
-
|
3053
|
-
if (evt.isDefaultPrevented()) {
|
3054
|
-
return false;
|
3055
|
-
}
|
3056
|
-
|
3057
|
-
while((index = indexOf(this.id(data), val)) >= 0) {
|
3058
|
-
val.splice(index, 1);
|
3059
|
-
this.setVal(val);
|
3060
|
-
if (this.select) this.postprocessResults();
|
3061
|
-
}
|
3062
|
-
|
3063
|
-
selected.remove();
|
3064
|
-
|
3065
|
-
this.opts.element.trigger({ type: "select2-removed", val: this.id(data), choice: data });
|
3066
|
-
this.triggerChange({ removed: data });
|
3067
|
-
|
3068
|
-
return true;
|
3069
|
-
},
|
3070
|
-
|
3071
|
-
// multi
|
3072
|
-
postprocessResults: function (data, initial, noHighlightUpdate) {
|
3073
|
-
var val = this.getVal(),
|
3074
|
-
choices = this.results.find(".select2-result"),
|
3075
|
-
compound = this.results.find(".select2-result-with-children"),
|
3076
|
-
self = this;
|
3077
|
-
|
3078
|
-
choices.each2(function (i, choice) {
|
3079
|
-
var id = self.id(choice.data("select2-data"));
|
3080
|
-
if (indexOf(id, val) >= 0) {
|
3081
|
-
choice.addClass("select2-selected");
|
3082
|
-
// mark all children of the selected parent as selected
|
3083
|
-
choice.find(".select2-result-selectable").addClass("select2-selected");
|
3084
|
-
}
|
3085
|
-
});
|
3086
|
-
|
3087
|
-
compound.each2(function(i, choice) {
|
3088
|
-
// hide an optgroup if it doesn't have any selectable children
|
3089
|
-
if (!choice.is('.select2-result-selectable')
|
3090
|
-
&& choice.find(".select2-result-selectable:not(.select2-selected)").length === 0) {
|
3091
|
-
choice.addClass("select2-selected");
|
3092
|
-
}
|
3093
|
-
});
|
3094
|
-
|
3095
|
-
if (this.highlight() == -1 && noHighlightUpdate !== false){
|
3096
|
-
self.highlight(0);
|
3097
|
-
}
|
3098
|
-
|
3099
|
-
//If all results are chosen render formatNoMatches
|
3100
|
-
if(!this.opts.createSearchChoice && !choices.filter('.select2-result:not(.select2-selected)').length > 0){
|
3101
|
-
if(!data || data && !data.more && this.results.find(".select2-no-results").length === 0) {
|
3102
|
-
if (checkFormatter(self.opts.formatNoMatches, "formatNoMatches")) {
|
3103
|
-
this.results.append("<li class='select2-no-results'>" + evaluate(self.opts.formatNoMatches, self.search.val()) + "</li>");
|
3104
|
-
}
|
3105
|
-
}
|
3106
|
-
}
|
3107
|
-
|
3108
|
-
},
|
3109
|
-
|
3110
|
-
// multi
|
3111
|
-
getMaxSearchWidth: function() {
|
3112
|
-
return this.selection.width() - getSideBorderPadding(this.search);
|
3113
|
-
},
|
3114
|
-
|
3115
|
-
// multi
|
3116
|
-
resizeSearch: function () {
|
3117
|
-
var minimumWidth, left, maxWidth, containerLeft, searchWidth,
|
3118
|
-
sideBorderPadding = getSideBorderPadding(this.search);
|
3119
|
-
|
3120
|
-
minimumWidth = measureTextWidth(this.search) + 10;
|
3121
|
-
|
3122
|
-
left = this.search.offset().left;
|
3123
|
-
|
3124
|
-
maxWidth = this.selection.width();
|
3125
|
-
containerLeft = this.selection.offset().left;
|
3126
|
-
|
3127
|
-
searchWidth = maxWidth - (left - containerLeft) - sideBorderPadding;
|
3128
|
-
|
3129
|
-
if (searchWidth < minimumWidth) {
|
3130
|
-
searchWidth = maxWidth - sideBorderPadding;
|
3131
|
-
}
|
3132
|
-
|
3133
|
-
if (searchWidth < 40) {
|
3134
|
-
searchWidth = maxWidth - sideBorderPadding;
|
3135
|
-
}
|
3136
|
-
|
3137
|
-
if (searchWidth <= 0) {
|
3138
|
-
searchWidth = minimumWidth;
|
3139
|
-
}
|
3140
|
-
|
3141
|
-
this.search.width(Math.floor(searchWidth));
|
3142
|
-
},
|
3143
|
-
|
3144
|
-
// multi
|
3145
|
-
getVal: function () {
|
3146
|
-
var val;
|
3147
|
-
if (this.select) {
|
3148
|
-
val = this.select.val();
|
3149
|
-
return val === null ? [] : val;
|
3150
|
-
} else {
|
3151
|
-
val = this.opts.element.val();
|
3152
|
-
return splitVal(val, this.opts.separator);
|
3153
|
-
}
|
3154
|
-
},
|
3155
|
-
|
3156
|
-
// multi
|
3157
|
-
setVal: function (val) {
|
3158
|
-
var unique;
|
3159
|
-
if (this.select) {
|
3160
|
-
this.select.val(val);
|
3161
|
-
} else {
|
3162
|
-
unique = [];
|
3163
|
-
// filter out duplicates
|
3164
|
-
$(val).each(function () {
|
3165
|
-
if (indexOf(this, unique) < 0) unique.push(this);
|
3166
|
-
});
|
3167
|
-
this.opts.element.val(unique.length === 0 ? "" : unique.join(this.opts.separator));
|
3168
|
-
}
|
3169
|
-
},
|
3170
|
-
|
3171
|
-
// multi
|
3172
|
-
buildChangeDetails: function (old, current) {
|
3173
|
-
var current = current.slice(0),
|
3174
|
-
old = old.slice(0);
|
3175
|
-
|
3176
|
-
// remove intersection from each array
|
3177
|
-
for (var i = 0; i < current.length; i++) {
|
3178
|
-
for (var j = 0; j < old.length; j++) {
|
3179
|
-
if (equal(this.opts.id(current[i]), this.opts.id(old[j]))) {
|
3180
|
-
current.splice(i, 1);
|
3181
|
-
if(i>0){
|
3182
|
-
i--;
|
3183
|
-
}
|
3184
|
-
old.splice(j, 1);
|
3185
|
-
j--;
|
3186
|
-
}
|
3187
|
-
}
|
3188
|
-
}
|
3189
|
-
|
3190
|
-
return {added: current, removed: old};
|
3191
|
-
},
|
3192
|
-
|
3193
|
-
|
3194
|
-
// multi
|
3195
|
-
val: function (val, triggerChange) {
|
3196
|
-
var oldData, self=this;
|
3197
|
-
|
3198
|
-
if (arguments.length === 0) {
|
3199
|
-
return this.getVal();
|
3200
|
-
}
|
3201
|
-
|
3202
|
-
oldData=this.data();
|
3203
|
-
if (!oldData.length) oldData=[];
|
3204
|
-
|
3205
|
-
// val is an id. !val is true for [undefined,null,'',0] - 0 is legal
|
3206
|
-
if (!val && val !== 0) {
|
3207
|
-
this.opts.element.val("");
|
3208
|
-
this.updateSelection([]);
|
3209
|
-
this.clearSearch();
|
3210
|
-
if (triggerChange) {
|
3211
|
-
this.triggerChange({added: this.data(), removed: oldData});
|
3212
|
-
}
|
3213
|
-
return;
|
3214
|
-
}
|
3215
|
-
|
3216
|
-
// val is a list of ids
|
3217
|
-
this.setVal(val);
|
3218
|
-
|
3219
|
-
if (this.select) {
|
3220
|
-
this.opts.initSelection(this.select, this.bind(this.updateSelection));
|
3221
|
-
if (triggerChange) {
|
3222
|
-
this.triggerChange(this.buildChangeDetails(oldData, this.data()));
|
3223
|
-
}
|
3224
|
-
} else {
|
3225
|
-
if (this.opts.initSelection === undefined) {
|
3226
|
-
throw new Error("val() cannot be called if initSelection() is not defined");
|
3227
|
-
}
|
3228
|
-
|
3229
|
-
this.opts.initSelection(this.opts.element, function(data){
|
3230
|
-
var ids=$.map(data, self.id);
|
3231
|
-
self.setVal(ids);
|
3232
|
-
self.updateSelection(data);
|
3233
|
-
self.clearSearch();
|
3234
|
-
if (triggerChange) {
|
3235
|
-
self.triggerChange(self.buildChangeDetails(oldData, self.data()));
|
3236
|
-
}
|
3237
|
-
});
|
3238
|
-
}
|
3239
|
-
this.clearSearch();
|
3240
|
-
},
|
3241
|
-
|
3242
|
-
// multi
|
3243
|
-
onSortStart: function() {
|
3244
|
-
if (this.select) {
|
3245
|
-
throw new Error("Sorting of elements is not supported when attached to <select>. Attach to <input type='hidden'/> instead.");
|
3246
|
-
}
|
3247
|
-
|
3248
|
-
// collapse search field into 0 width so its container can be collapsed as well
|
3249
|
-
this.search.width(0);
|
3250
|
-
// hide the container
|
3251
|
-
this.searchContainer.hide();
|
3252
|
-
},
|
3253
|
-
|
3254
|
-
// multi
|
3255
|
-
onSortEnd:function() {
|
3256
|
-
|
3257
|
-
var val=[], self=this;
|
3258
|
-
|
3259
|
-
// show search and move it to the end of the list
|
3260
|
-
this.searchContainer.show();
|
3261
|
-
// make sure the search container is the last item in the list
|
3262
|
-
this.searchContainer.appendTo(this.searchContainer.parent());
|
3263
|
-
// since we collapsed the width in dragStarted, we resize it here
|
3264
|
-
this.resizeSearch();
|
3265
|
-
|
3266
|
-
// update selection
|
3267
|
-
this.selection.find(".select2-search-choice").each(function() {
|
3268
|
-
val.push(self.opts.id($(this).data("select2-data")));
|
3269
|
-
});
|
3270
|
-
this.setVal(val);
|
3271
|
-
this.triggerChange();
|
3272
|
-
},
|
3273
|
-
|
3274
|
-
// multi
|
3275
|
-
data: function(values, triggerChange) {
|
3276
|
-
var self=this, ids, old;
|
3277
|
-
if (arguments.length === 0) {
|
3278
|
-
return this.selection
|
3279
|
-
.children(".select2-search-choice")
|
3280
|
-
.map(function() { return $(this).data("select2-data"); })
|
3281
|
-
.get();
|
3282
|
-
} else {
|
3283
|
-
old = this.data();
|
3284
|
-
if (!values) { values = []; }
|
3285
|
-
ids = $.map(values, function(e) { return self.opts.id(e); });
|
3286
|
-
this.setVal(ids);
|
3287
|
-
this.updateSelection(values);
|
3288
|
-
this.clearSearch();
|
3289
|
-
if (triggerChange) {
|
3290
|
-
this.triggerChange(this.buildChangeDetails(old, this.data()));
|
3291
|
-
}
|
3292
|
-
}
|
3293
|
-
}
|
3294
|
-
});
|
3295
|
-
|
3296
|
-
$.fn.select2 = function () {
|
3297
|
-
|
3298
|
-
var args = Array.prototype.slice.call(arguments, 0),
|
3299
|
-
opts,
|
3300
|
-
select2,
|
3301
|
-
method, value, multiple,
|
3302
|
-
allowedMethods = ["val", "destroy", "opened", "open", "close", "focus", "isFocused", "container", "dropdown", "onSortStart", "onSortEnd", "enable", "disable", "readonly", "positionDropdown", "data", "search"],
|
3303
|
-
valueMethods = ["opened", "isFocused", "container", "dropdown"],
|
3304
|
-
propertyMethods = ["val", "data"],
|
3305
|
-
methodsMap = { search: "externalSearch" };
|
3306
|
-
|
3307
|
-
this.each(function () {
|
3308
|
-
if (args.length === 0 || typeof(args[0]) === "object") {
|
3309
|
-
opts = args.length === 0 ? {} : $.extend({}, args[0]);
|
3310
|
-
opts.element = $(this);
|
3311
|
-
|
3312
|
-
if (opts.element.get(0).tagName.toLowerCase() === "select") {
|
3313
|
-
multiple = opts.element.prop("multiple");
|
3314
|
-
} else {
|
3315
|
-
multiple = opts.multiple || false;
|
3316
|
-
if ("tags" in opts) {opts.multiple = multiple = true;}
|
3317
|
-
}
|
3318
|
-
|
3319
|
-
select2 = multiple ? new window.Select2["class"].multi() : new window.Select2["class"].single();
|
3320
|
-
select2.init(opts);
|
3321
|
-
} else if (typeof(args[0]) === "string") {
|
3322
|
-
|
3323
|
-
if (indexOf(args[0], allowedMethods) < 0) {
|
3324
|
-
throw "Unknown method: " + args[0];
|
3325
|
-
}
|
3326
|
-
|
3327
|
-
value = undefined;
|
3328
|
-
select2 = $(this).data("select2");
|
3329
|
-
if (select2 === undefined) return;
|
3330
|
-
|
3331
|
-
method=args[0];
|
3332
|
-
|
3333
|
-
if (method === "container") {
|
3334
|
-
value = select2.container;
|
3335
|
-
} else if (method === "dropdown") {
|
3336
|
-
value = select2.dropdown;
|
3337
|
-
} else {
|
3338
|
-
if (methodsMap[method]) method = methodsMap[method];
|
3339
|
-
|
3340
|
-
value = select2[method].apply(select2, args.slice(1));
|
3341
|
-
}
|
3342
|
-
if (indexOf(args[0], valueMethods) >= 0
|
3343
|
-
|| (indexOf(args[0], propertyMethods) >= 0 && args.length == 1)) {
|
3344
|
-
return false; // abort the iteration, ready to return first matched value
|
3345
|
-
}
|
3346
|
-
} else {
|
3347
|
-
throw "Invalid arguments to select2 plugin: " + args;
|
3348
|
-
}
|
3349
|
-
});
|
3350
|
-
return (value === undefined) ? this : value;
|
3351
|
-
};
|
3352
|
-
|
3353
|
-
// plugin defaults, accessible to users
|
3354
|
-
$.fn.select2.defaults = {
|
3355
|
-
width: "copy",
|
3356
|
-
loadMorePadding: 0,
|
3357
|
-
closeOnSelect: true,
|
3358
|
-
openOnEnter: true,
|
3359
|
-
containerCss: {},
|
3360
|
-
dropdownCss: {},
|
3361
|
-
containerCssClass: "",
|
3362
|
-
dropdownCssClass: "",
|
3363
|
-
formatResult: function(result, container, query, escapeMarkup) {
|
3364
|
-
var markup=[];
|
3365
|
-
markMatch(result.text, query.term, markup, escapeMarkup);
|
3366
|
-
return markup.join("");
|
3367
|
-
},
|
3368
|
-
formatSelection: function (data, container, escapeMarkup) {
|
3369
|
-
return data ? escapeMarkup(data.text) : undefined;
|
3370
|
-
},
|
3371
|
-
sortResults: function (results, container, query) {
|
3372
|
-
return results;
|
3373
|
-
},
|
3374
|
-
formatResultCssClass: function(data) {return data.css;},
|
3375
|
-
formatSelectionCssClass: function(data, container) {return undefined;},
|
3376
|
-
formatMatches: function (matches) { return matches + " results are available, use up and down arrow keys to navigate."; },
|
3377
|
-
formatNoMatches: function () { return "No matches found"; },
|
3378
|
-
formatInputTooShort: function (input, min) { var n = min - input.length; return "Please enter " + n + " or more character" + (n == 1? "" : "s"); },
|
3379
|
-
formatInputTooLong: function (input, max) { var n = input.length - max; return "Please delete " + n + " character" + (n == 1? "" : "s"); },
|
3380
|
-
formatSelectionTooBig: function (limit) { return "You can only select " + limit + " item" + (limit == 1 ? "" : "s"); },
|
3381
|
-
formatLoadMore: function (pageNumber) { return "Loading more results…"; },
|
3382
|
-
formatSearching: function () { return "Searching…"; },
|
3383
|
-
minimumResultsForSearch: 0,
|
3384
|
-
minimumInputLength: 0,
|
3385
|
-
maximumInputLength: null,
|
3386
|
-
maximumSelectionSize: 0,
|
3387
|
-
id: function (e) { return e == undefined ? null : e.id; },
|
3388
|
-
matcher: function(term, text) {
|
3389
|
-
return stripDiacritics(''+text).toUpperCase().indexOf(stripDiacritics(''+term).toUpperCase()) >= 0;
|
3390
|
-
},
|
3391
|
-
separator: ",",
|
3392
|
-
tokenSeparators: [],
|
3393
|
-
tokenizer: defaultTokenizer,
|
3394
|
-
escapeMarkup: defaultEscapeMarkup,
|
3395
|
-
blurOnChange: false,
|
3396
|
-
selectOnBlur: false,
|
3397
|
-
adaptContainerCssClass: function(c) { return c; },
|
3398
|
-
adaptDropdownCssClass: function(c) { return null; },
|
3399
|
-
nextSearchTerm: function(selectedObject, currentSearchTerm) { return undefined; },
|
3400
|
-
searchInputPlaceholder: '',
|
3401
|
-
createSearchChoicePosition: 'top',
|
3402
|
-
shouldFocusInput: function (instance) {
|
3403
|
-
// Attempt to detect touch devices
|
3404
|
-
var supportsTouchEvents = (('ontouchstart' in window) ||
|
3405
|
-
(navigator.msMaxTouchPoints > 0));
|
3406
|
-
|
3407
|
-
// Only devices which support touch events should be special cased
|
3408
|
-
if (!supportsTouchEvents) {
|
3409
|
-
return true;
|
3410
|
-
}
|
3411
|
-
|
3412
|
-
// Never focus the input if search is disabled
|
3413
|
-
if (instance.opts.minimumResultsForSearch < 0) {
|
3414
|
-
return false;
|
3415
|
-
}
|
3416
|
-
|
3417
|
-
return true;
|
3418
|
-
}
|
3419
|
-
};
|
3420
|
-
|
3421
|
-
$.fn.select2.ajaxDefaults = {
|
3422
|
-
transport: $.ajax,
|
3423
|
-
params: {
|
3424
|
-
type: "GET",
|
3425
|
-
cache: false,
|
3426
|
-
dataType: "json"
|
3427
|
-
}
|
3428
|
-
};
|
3429
|
-
|
3430
|
-
// exports
|
3431
|
-
window.Select2 = {
|
3432
|
-
query: {
|
3433
|
-
ajax: ajax,
|
3434
|
-
local: local,
|
3435
|
-
tags: tags
|
3436
|
-
}, util: {
|
3437
|
-
debounce: debounce,
|
3438
|
-
markMatch: markMatch,
|
3439
|
-
escapeMarkup: defaultEscapeMarkup,
|
3440
|
-
stripDiacritics: stripDiacritics
|
3441
|
-
}, "class": {
|
3442
|
-
"abstract": AbstractSelect2,
|
3443
|
-
"single": SingleSelect2,
|
3444
|
-
"multi": MultiSelect2
|
3445
|
-
}
|
3446
|
-
};
|
3447
|
-
|
3448
|
-
}(jQuery));
|
1
|
+
/*! Select2 4.0.3 | https://github.com/select2/select2/blob/master/LICENSE.md */!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a("object"==typeof exports?require("jquery"):jQuery)}(function(a){var b=function(){if(a&&a.fn&&a.fn.select2&&a.fn.select2.amd)var b=a.fn.select2.amd;var b;return function(){if(!b||!b.requirejs){b?c=b:b={};var a,c,d;!function(b){function e(a,b){return u.call(a,b)}function f(a,b){var c,d,e,f,g,h,i,j,k,l,m,n=b&&b.split("/"),o=s.map,p=o&&o["*"]||{};if(a&&"."===a.charAt(0))if(b){for(a=a.split("/"),g=a.length-1,s.nodeIdCompat&&w.test(a[g])&&(a[g]=a[g].replace(w,"")),a=n.slice(0,n.length-1).concat(a),k=0;k<a.length;k+=1)if(m=a[k],"."===m)a.splice(k,1),k-=1;else if(".."===m){if(1===k&&(".."===a[2]||".."===a[0]))break;k>0&&(a.splice(k-1,2),k-=2)}a=a.join("/")}else 0===a.indexOf("./")&&(a=a.substring(2));if((n||p)&&o){for(c=a.split("/"),k=c.length;k>0;k-=1){if(d=c.slice(0,k).join("/"),n)for(l=n.length;l>0;l-=1)if(e=o[n.slice(0,l).join("/")],e&&(e=e[d])){f=e,h=k;break}if(f)break;!i&&p&&p[d]&&(i=p[d],j=k)}!f&&i&&(f=i,h=j),f&&(c.splice(0,h,f),a=c.join("/"))}return a}function g(a,c){return function(){var d=v.call(arguments,0);return"string"!=typeof d[0]&&1===d.length&&d.push(null),n.apply(b,d.concat([a,c]))}}function h(a){return function(b){return f(b,a)}}function i(a){return function(b){q[a]=b}}function j(a){if(e(r,a)){var c=r[a];delete r[a],t[a]=!0,m.apply(b,c)}if(!e(q,a)&&!e(t,a))throw new Error("No "+a);return q[a]}function k(a){var b,c=a?a.indexOf("!"):-1;return c>-1&&(b=a.substring(0,c),a=a.substring(c+1,a.length)),[b,a]}function l(a){return function(){return s&&s.config&&s.config[a]||{}}}var m,n,o,p,q={},r={},s={},t={},u=Object.prototype.hasOwnProperty,v=[].slice,w=/\.js$/;o=function(a,b){var c,d=k(a),e=d[0];return a=d[1],e&&(e=f(e,b),c=j(e)),e?a=c&&c.normalize?c.normalize(a,h(b)):f(a,b):(a=f(a,b),d=k(a),e=d[0],a=d[1],e&&(c=j(e))),{f:e?e+"!"+a:a,n:a,pr:e,p:c}},p={require:function(a){return g(a)},exports:function(a){var b=q[a];return"undefined"!=typeof b?b:q[a]={}},module:function(a){return{id:a,uri:"",exports:q[a],config:l(a)}}},m=function(a,c,d,f){var h,k,l,m,n,s,u=[],v=typeof d;if(f=f||a,"undefined"===v||"function"===v){for(c=!c.length&&d.length?["require","exports","module"]:c,n=0;n<c.length;n+=1)if(m=o(c[n],f),k=m.f,"require"===k)u[n]=p.require(a);else if("exports"===k)u[n]=p.exports(a),s=!0;else if("module"===k)h=u[n]=p.module(a);else if(e(q,k)||e(r,k)||e(t,k))u[n]=j(k);else{if(!m.p)throw new Error(a+" missing "+k);m.p.load(m.n,g(f,!0),i(k),{}),u[n]=q[k]}l=d?d.apply(q[a],u):void 0,a&&(h&&h.exports!==b&&h.exports!==q[a]?q[a]=h.exports:l===b&&s||(q[a]=l))}else a&&(q[a]=d)},a=c=n=function(a,c,d,e,f){if("string"==typeof a)return p[a]?p[a](c):j(o(a,c).f);if(!a.splice){if(s=a,s.deps&&n(s.deps,s.callback),!c)return;c.splice?(a=c,c=d,d=null):a=b}return c=c||function(){},"function"==typeof d&&(d=e,e=f),e?m(b,a,c,d):setTimeout(function(){m(b,a,c,d)},4),n},n.config=function(a){return n(a)},a._defined=q,d=function(a,b,c){if("string"!=typeof a)throw new Error("See almond README: incorrect module build, no module name");b.splice||(c=b,b=[]),e(q,a)||e(r,a)||(r[a]=[a,b,c])},d.amd={jQuery:!0}}(),b.requirejs=a,b.require=c,b.define=d}}(),b.define("almond",function(){}),b.define("jquery",[],function(){var b=a||$;return null==b&&console&&console.error&&console.error("Select2: An instance of jQuery or a jQuery-compatible library was not found. Make sure that you are including jQuery before Select2 on your web page."),b}),b.define("select2/utils",["jquery"],function(a){function b(a){var b=a.prototype,c=[];for(var d in b){var e=b[d];"function"==typeof e&&"constructor"!==d&&c.push(d)}return c}var c={};c.Extend=function(a,b){function c(){this.constructor=a}var d={}.hasOwnProperty;for(var e in b)d.call(b,e)&&(a[e]=b[e]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a},c.Decorate=function(a,c){function d(){var b=Array.prototype.unshift,d=c.prototype.constructor.length,e=a.prototype.constructor;d>0&&(b.call(arguments,a.prototype.constructor),e=c.prototype.constructor),e.apply(this,arguments)}function e(){this.constructor=d}var f=b(c),g=b(a);c.displayName=a.displayName,d.prototype=new e;for(var h=0;h<g.length;h++){var i=g[h];d.prototype[i]=a.prototype[i]}for(var j=(function(a){var b=function(){};a in d.prototype&&(b=d.prototype[a]);var e=c.prototype[a];return function(){var a=Array.prototype.unshift;return a.call(arguments,b),e.apply(this,arguments)}}),k=0;k<f.length;k++){var l=f[k];d.prototype[l]=j(l)}return d};var d=function(){this.listeners={}};return d.prototype.on=function(a,b){this.listeners=this.listeners||{},a in this.listeners?this.listeners[a].push(b):this.listeners[a]=[b]},d.prototype.trigger=function(a){var b=Array.prototype.slice,c=b.call(arguments,1);this.listeners=this.listeners||{},null==c&&(c=[]),0===c.length&&c.push({}),c[0]._type=a,a in this.listeners&&this.invoke(this.listeners[a],b.call(arguments,1)),"*"in this.listeners&&this.invoke(this.listeners["*"],arguments)},d.prototype.invoke=function(a,b){for(var c=0,d=a.length;d>c;c++)a[c].apply(this,b)},c.Observable=d,c.generateChars=function(a){for(var b="",c=0;a>c;c++){var d=Math.floor(36*Math.random());b+=d.toString(36)}return b},c.bind=function(a,b){return function(){a.apply(b,arguments)}},c._convertData=function(a){for(var b in a){var c=b.split("-"),d=a;if(1!==c.length){for(var e=0;e<c.length;e++){var f=c[e];f=f.substring(0,1).toLowerCase()+f.substring(1),f in d||(d[f]={}),e==c.length-1&&(d[f]=a[b]),d=d[f]}delete a[b]}}return a},c.hasScroll=function(b,c){var d=a(c),e=c.style.overflowX,f=c.style.overflowY;return e!==f||"hidden"!==f&&"visible"!==f?"scroll"===e||"scroll"===f?!0:d.innerHeight()<c.scrollHeight||d.innerWidth()<c.scrollWidth:!1},c.escapeMarkup=function(a){var b={"\\":"\","&":"&","<":"<",">":">",'"':""","'":"'","/":"/"};return"string"!=typeof a?a:String(a).replace(/[&<>"'\/\\]/g,function(a){return b[a]})},c.appendMany=function(b,c){if("1.7"===a.fn.jquery.substr(0,3)){var d=a();a.map(c,function(a){d=d.add(a)}),c=d}b.append(c)},c}),b.define("select2/results",["jquery","./utils"],function(a,b){function c(a,b,d){this.$element=a,this.data=d,this.options=b,c.__super__.constructor.call(this)}return b.Extend(c,b.Observable),c.prototype.render=function(){var b=a('<ul class="select2-results__options" role="tree"></ul>');return this.options.get("multiple")&&b.attr("aria-multiselectable","true"),this.$results=b,b},c.prototype.clear=function(){this.$results.empty()},c.prototype.displayMessage=function(b){var c=this.options.get("escapeMarkup");this.clear(),this.hideLoading();var d=a('<li role="treeitem" aria-live="assertive" class="select2-results__option"></li>'),e=this.options.get("translations").get(b.message);d.append(c(e(b.args))),d[0].className+=" select2-results__message",this.$results.append(d)},c.prototype.hideMessages=function(){this.$results.find(".select2-results__message").remove()},c.prototype.append=function(a){this.hideLoading();var b=[];if(null==a.results||0===a.results.length)return void(0===this.$results.children().length&&this.trigger("results:message",{message:"noResults"}));a.results=this.sort(a.results);for(var c=0;c<a.results.length;c++){var d=a.results[c],e=this.option(d);b.push(e)}this.$results.append(b)},c.prototype.position=function(a,b){var c=b.find(".select2-results");c.append(a)},c.prototype.sort=function(a){var b=this.options.get("sorter");return b(a)},c.prototype.highlightFirstItem=function(){var a=this.$results.find(".select2-results__option[aria-selected]"),b=a.filter("[aria-selected=true]");b.length>0?b.first().trigger("mouseenter"):a.first().trigger("mouseenter"),this.ensureHighlightVisible()},c.prototype.setClasses=function(){var b=this;this.data.current(function(c){var d=a.map(c,function(a){return a.id.toString()}),e=b.$results.find(".select2-results__option[aria-selected]");e.each(function(){var b=a(this),c=a.data(this,"data"),e=""+c.id;null!=c.element&&c.element.selected||null==c.element&&a.inArray(e,d)>-1?b.attr("aria-selected","true"):b.attr("aria-selected","false")})})},c.prototype.showLoading=function(a){this.hideLoading();var b=this.options.get("translations").get("searching"),c={disabled:!0,loading:!0,text:b(a)},d=this.option(c);d.className+=" loading-results",this.$results.prepend(d)},c.prototype.hideLoading=function(){this.$results.find(".loading-results").remove()},c.prototype.option=function(b){var c=document.createElement("li");c.className="select2-results__option";var d={role:"treeitem","aria-selected":"false"};b.disabled&&(delete d["aria-selected"],d["aria-disabled"]="true"),null==b.id&&delete d["aria-selected"],null!=b._resultId&&(c.id=b._resultId),b.title&&(c.title=b.title),b.children&&(d.role="group",d["aria-label"]=b.text,delete d["aria-selected"]);for(var e in d){var f=d[e];c.setAttribute(e,f)}if(b.children){var g=a(c),h=document.createElement("strong");h.className="select2-results__group";a(h);this.template(b,h);for(var i=[],j=0;j<b.children.length;j++){var k=b.children[j],l=this.option(k);i.push(l)}var m=a("<ul></ul>",{"class":"select2-results__options select2-results__options--nested"});m.append(i),g.append(h),g.append(m)}else this.template(b,c);return a.data(c,"data",b),c},c.prototype.bind=function(b,c){var d=this,e=b.id+"-results";this.$results.attr("id",e),b.on("results:all",function(a){d.clear(),d.append(a.data),b.isOpen()&&(d.setClasses(),d.highlightFirstItem())}),b.on("results:append",function(a){d.append(a.data),b.isOpen()&&d.setClasses()}),b.on("query",function(a){d.hideMessages(),d.showLoading(a)}),b.on("select",function(){b.isOpen()&&(d.setClasses(),d.highlightFirstItem())}),b.on("unselect",function(){b.isOpen()&&(d.setClasses(),d.highlightFirstItem())}),b.on("open",function(){d.$results.attr("aria-expanded","true"),d.$results.attr("aria-hidden","false"),d.setClasses(),d.ensureHighlightVisible()}),b.on("close",function(){d.$results.attr("aria-expanded","false"),d.$results.attr("aria-hidden","true"),d.$results.removeAttr("aria-activedescendant")}),b.on("results:toggle",function(){var a=d.getHighlightedResults();0!==a.length&&a.trigger("mouseup")}),b.on("results:select",function(){var a=d.getHighlightedResults();if(0!==a.length){var b=a.data("data");"true"==a.attr("aria-selected")?d.trigger("close",{}):d.trigger("select",{data:b})}}),b.on("results:previous",function(){var a=d.getHighlightedResults(),b=d.$results.find("[aria-selected]"),c=b.index(a);if(0!==c){var e=c-1;0===a.length&&(e=0);var f=b.eq(e);f.trigger("mouseenter");var g=d.$results.offset().top,h=f.offset().top,i=d.$results.scrollTop()+(h-g);0===e?d.$results.scrollTop(0):0>h-g&&d.$results.scrollTop(i)}}),b.on("results:next",function(){var a=d.getHighlightedResults(),b=d.$results.find("[aria-selected]"),c=b.index(a),e=c+1;if(!(e>=b.length)){var f=b.eq(e);f.trigger("mouseenter");var g=d.$results.offset().top+d.$results.outerHeight(!1),h=f.offset().top+f.outerHeight(!1),i=d.$results.scrollTop()+h-g;0===e?d.$results.scrollTop(0):h>g&&d.$results.scrollTop(i)}}),b.on("results:focus",function(a){a.element.addClass("select2-results__option--highlighted")}),b.on("results:message",function(a){d.displayMessage(a)}),a.fn.mousewheel&&this.$results.on("mousewheel",function(a){var b=d.$results.scrollTop(),c=d.$results.get(0).scrollHeight-b+a.deltaY,e=a.deltaY>0&&b-a.deltaY<=0,f=a.deltaY<0&&c<=d.$results.height();e?(d.$results.scrollTop(0),a.preventDefault(),a.stopPropagation()):f&&(d.$results.scrollTop(d.$results.get(0).scrollHeight-d.$results.height()),a.preventDefault(),a.stopPropagation())}),this.$results.on("mouseup",".select2-results__option[aria-selected]",function(b){var c=a(this),e=c.data("data");return"true"===c.attr("aria-selected")?void(d.options.get("multiple")?d.trigger("unselect",{originalEvent:b,data:e}):d.trigger("close",{})):void d.trigger("select",{originalEvent:b,data:e})}),this.$results.on("mouseenter",".select2-results__option[aria-selected]",function(b){var c=a(this).data("data");d.getHighlightedResults().removeClass("select2-results__option--highlighted"),d.trigger("results:focus",{data:c,element:a(this)})})},c.prototype.getHighlightedResults=function(){var a=this.$results.find(".select2-results__option--highlighted");return a},c.prototype.destroy=function(){this.$results.remove()},c.prototype.ensureHighlightVisible=function(){var a=this.getHighlightedResults();if(0!==a.length){var b=this.$results.find("[aria-selected]"),c=b.index(a),d=this.$results.offset().top,e=a.offset().top,f=this.$results.scrollTop()+(e-d),g=e-d;f-=2*a.outerHeight(!1),2>=c?this.$results.scrollTop(0):(g>this.$results.outerHeight()||0>g)&&this.$results.scrollTop(f)}},c.prototype.template=function(b,c){var d=this.options.get("templateResult"),e=this.options.get("escapeMarkup"),f=d(b,c);null==f?c.style.display="none":"string"==typeof f?c.innerHTML=e(f):a(c).append(f)},c}),b.define("select2/keys",[],function(){var a={BACKSPACE:8,TAB:9,ENTER:13,SHIFT:16,CTRL:17,ALT:18,ESC:27,SPACE:32,PAGE_UP:33,PAGE_DOWN:34,END:35,HOME:36,LEFT:37,UP:38,RIGHT:39,DOWN:40,DELETE:46};return a}),b.define("select2/selection/base",["jquery","../utils","../keys"],function(a,b,c){function d(a,b){this.$element=a,this.options=b,d.__super__.constructor.call(this)}return b.Extend(d,b.Observable),d.prototype.render=function(){var b=a('<span class="select2-selection" role="combobox" aria-haspopup="true" aria-expanded="false"></span>');return this._tabindex=0,null!=this.$element.data("old-tabindex")?this._tabindex=this.$element.data("old-tabindex"):null!=this.$element.attr("tabindex")&&(this._tabindex=this.$element.attr("tabindex")),b.attr("title",this.$element.attr("title")),b.attr("tabindex",this._tabindex),this.$selection=b,b},d.prototype.bind=function(a,b){var d=this,e=(a.id+"-container",a.id+"-results");this.container=a,this.$selection.on("focus",function(a){d.trigger("focus",a)}),this.$selection.on("blur",function(a){d._handleBlur(a)}),this.$selection.on("keydown",function(a){d.trigger("keypress",a),a.which===c.SPACE&&a.preventDefault()}),a.on("results:focus",function(a){d.$selection.attr("aria-activedescendant",a.data._resultId)}),a.on("selection:update",function(a){d.update(a.data)}),a.on("open",function(){d.$selection.attr("aria-expanded","true"),d.$selection.attr("aria-owns",e),d._attachCloseHandler(a)}),a.on("close",function(){d.$selection.attr("aria-expanded","false"),d.$selection.removeAttr("aria-activedescendant"),d.$selection.removeAttr("aria-owns"),d.$selection.focus(),d._detachCloseHandler(a)}),a.on("enable",function(){d.$selection.attr("tabindex",d._tabindex)}),a.on("disable",function(){d.$selection.attr("tabindex","-1")})},d.prototype._handleBlur=function(b){var c=this;window.setTimeout(function(){document.activeElement==c.$selection[0]||a.contains(c.$selection[0],document.activeElement)||c.trigger("blur",b)},1)},d.prototype._attachCloseHandler=function(b){a(document.body).on("mousedown.select2."+b.id,function(b){var c=a(b.target),d=c.closest(".select2"),e=a(".select2.select2-container--open");e.each(function(){var b=a(this);if(this!=d[0]){var c=b.data("element");c.select2("close")}})})},d.prototype._detachCloseHandler=function(b){a(document.body).off("mousedown.select2."+b.id)},d.prototype.position=function(a,b){var c=b.find(".selection");c.append(a)},d.prototype.destroy=function(){this._detachCloseHandler(this.container)},d.prototype.update=function(a){throw new Error("The `update` method must be defined in child classes.")},d}),b.define("select2/selection/single",["jquery","./base","../utils","../keys"],function(a,b,c,d){function e(){e.__super__.constructor.apply(this,arguments)}return c.Extend(e,b),e.prototype.render=function(){var a=e.__super__.render.call(this);return a.addClass("select2-selection--single"),a.html('<span class="select2-selection__rendered"></span><span class="select2-selection__arrow" role="presentation"><b role="presentation"></b></span>'),a},e.prototype.bind=function(a,b){var c=this;e.__super__.bind.apply(this,arguments);var d=a.id+"-container";this.$selection.find(".select2-selection__rendered").attr("id",d),this.$selection.attr("aria-labelledby",d),this.$selection.on("mousedown",function(a){1===a.which&&c.trigger("toggle",{originalEvent:a})}),this.$selection.on("focus",function(a){}),this.$selection.on("blur",function(a){}),a.on("focus",function(b){a.isOpen()||c.$selection.focus()}),a.on("selection:update",function(a){c.update(a.data)})},e.prototype.clear=function(){this.$selection.find(".select2-selection__rendered").empty()},e.prototype.display=function(a,b){var c=this.options.get("templateSelection"),d=this.options.get("escapeMarkup");return d(c(a,b))},e.prototype.selectionContainer=function(){return a("<span></span>")},e.prototype.update=function(a){if(0===a.length)return void this.clear();var b=a[0],c=this.$selection.find(".select2-selection__rendered"),d=this.display(b,c);c.empty().append(d),c.prop("title",b.title||b.text)},e}),b.define("select2/selection/multiple",["jquery","./base","../utils"],function(a,b,c){function d(a,b){d.__super__.constructor.apply(this,arguments)}return c.Extend(d,b),d.prototype.render=function(){var a=d.__super__.render.call(this);return a.addClass("select2-selection--multiple"),a.html('<ul class="select2-selection__rendered"></ul>'),a},d.prototype.bind=function(b,c){var e=this;d.__super__.bind.apply(this,arguments),this.$selection.on("click",function(a){e.trigger("toggle",{originalEvent:a})}),this.$selection.on("click",".select2-selection__choice__remove",function(b){if(!e.options.get("disabled")){var c=a(this),d=c.parent(),f=d.data("data");e.trigger("unselect",{originalEvent:b,data:f})}})},d.prototype.clear=function(){this.$selection.find(".select2-selection__rendered").empty()},d.prototype.display=function(a,b){var c=this.options.get("templateSelection"),d=this.options.get("escapeMarkup");return d(c(a,b))},d.prototype.selectionContainer=function(){var b=a('<li class="select2-selection__choice"><span class="select2-selection__choice__remove" role="presentation">×</span></li>');return b},d.prototype.update=function(a){if(this.clear(),0!==a.length){for(var b=[],d=0;d<a.length;d++){var e=a[d],f=this.selectionContainer(),g=this.display(e,f);f.append(g),f.prop("title",e.title||e.text),f.data("data",e),b.push(f)}var h=this.$selection.find(".select2-selection__rendered");c.appendMany(h,b)}},d}),b.define("select2/selection/placeholder",["../utils"],function(a){function b(a,b,c){this.placeholder=this.normalizePlaceholder(c.get("placeholder")),a.call(this,b,c)}return b.prototype.normalizePlaceholder=function(a,b){return"string"==typeof b&&(b={id:"",text:b}),b},b.prototype.createPlaceholder=function(a,b){var c=this.selectionContainer();return c.html(this.display(b)),c.addClass("select2-selection__placeholder").removeClass("select2-selection__choice"),c},b.prototype.update=function(a,b){var c=1==b.length&&b[0].id!=this.placeholder.id,d=b.length>1;if(d||c)return a.call(this,b);this.clear();var e=this.createPlaceholder(this.placeholder);this.$selection.find(".select2-selection__rendered").append(e)},b}),b.define("select2/selection/allowClear",["jquery","../keys"],function(a,b){function c(){}return c.prototype.bind=function(a,b,c){var d=this;a.call(this,b,c),null==this.placeholder&&this.options.get("debug")&&window.console&&console.error&&console.error("Select2: The `allowClear` option should be used in combination with the `placeholder` option."),this.$selection.on("mousedown",".select2-selection__clear",function(a){d._handleClear(a)}),b.on("keypress",function(a){d._handleKeyboardClear(a,b)})},c.prototype._handleClear=function(a,b){if(!this.options.get("disabled")){var c=this.$selection.find(".select2-selection__clear");if(0!==c.length){b.stopPropagation();for(var d=c.data("data"),e=0;e<d.length;e++){var f={data:d[e]};if(this.trigger("unselect",f),f.prevented)return}this.$element.val(this.placeholder.id).trigger("change"),this.trigger("toggle",{})}}},c.prototype._handleKeyboardClear=function(a,c,d){d.isOpen()||(c.which==b.DELETE||c.which==b.BACKSPACE)&&this._handleClear(c)},c.prototype.update=function(b,c){if(b.call(this,c),!(this.$selection.find(".select2-selection__placeholder").length>0||0===c.length)){var d=a('<span class="select2-selection__clear">×</span>');d.data("data",c),this.$selection.find(".select2-selection__rendered").prepend(d)}},c}),b.define("select2/selection/search",["jquery","../utils","../keys"],function(a,b,c){function d(a,b,c){a.call(this,b,c)}return d.prototype.render=function(b){var c=a('<li class="select2-search select2-search--inline"><input class="select2-search__field" type="search" tabindex="-1" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" role="textbox" aria-autocomplete="list" /></li>');this.$searchContainer=c,this.$search=c.find("input");var d=b.call(this);return this._transferTabIndex(),d},d.prototype.bind=function(a,b,d){var e=this;a.call(this,b,d),b.on("open",function(){e.$search.trigger("focus")}),b.on("close",function(){e.$search.val(""),e.$search.removeAttr("aria-activedescendant"),e.$search.trigger("focus")}),b.on("enable",function(){e.$search.prop("disabled",!1),e._transferTabIndex()}),b.on("disable",function(){e.$search.prop("disabled",!0)}),b.on("focus",function(a){e.$search.trigger("focus")}),b.on("results:focus",function(a){e.$search.attr("aria-activedescendant",a.id)}),this.$selection.on("focusin",".select2-search--inline",function(a){e.trigger("focus",a)}),this.$selection.on("focusout",".select2-search--inline",function(a){e._handleBlur(a)}),this.$selection.on("keydown",".select2-search--inline",function(a){a.stopPropagation(),e.trigger("keypress",a),e._keyUpPrevented=a.isDefaultPrevented();var b=a.which;if(b===c.BACKSPACE&&""===e.$search.val()){var d=e.$searchContainer.prev(".select2-selection__choice");if(d.length>0){var f=d.data("data");e.searchRemoveChoice(f),a.preventDefault()}}});var f=document.documentMode,g=f&&11>=f;this.$selection.on("input.searchcheck",".select2-search--inline",function(a){return g?void e.$selection.off("input.search input.searchcheck"):void e.$selection.off("keyup.search")}),this.$selection.on("keyup.search input.search",".select2-search--inline",function(a){if(g&&"input"===a.type)return void e.$selection.off("input.search input.searchcheck");var b=a.which;b!=c.SHIFT&&b!=c.CTRL&&b!=c.ALT&&b!=c.TAB&&e.handleSearch(a)})},d.prototype._transferTabIndex=function(a){this.$search.attr("tabindex",this.$selection.attr("tabindex")),this.$selection.attr("tabindex","-1")},d.prototype.createPlaceholder=function(a,b){this.$search.attr("placeholder",b.text)},d.prototype.update=function(a,b){var c=this.$search[0]==document.activeElement;this.$search.attr("placeholder",""),a.call(this,b),this.$selection.find(".select2-selection__rendered").append(this.$searchContainer),this.resizeSearch(),c&&this.$search.focus()},d.prototype.handleSearch=function(){if(this.resizeSearch(),!this._keyUpPrevented){var a=this.$search.val();this.trigger("query",{term:a})}this._keyUpPrevented=!1},d.prototype.searchRemoveChoice=function(a,b){this.trigger("unselect",{data:b}),this.$search.val(b.text),this.handleSearch()},d.prototype.resizeSearch=function(){this.$search.css("width","25px");var a="";if(""!==this.$search.attr("placeholder"))a=this.$selection.find(".select2-selection__rendered").innerWidth();else{var b=this.$search.val().length+1;a=.75*b+"em"}this.$search.css("width",a)},d}),b.define("select2/selection/eventRelay",["jquery"],function(a){function b(){}return b.prototype.bind=function(b,c,d){var e=this,f=["open","opening","close","closing","select","selecting","unselect","unselecting"],g=["opening","closing","selecting","unselecting"];b.call(this,c,d),c.on("*",function(b,c){if(-1!==a.inArray(b,f)){c=c||{};var d=a.Event("select2:"+b,{params:c});e.$element.trigger(d),-1!==a.inArray(b,g)&&(c.prevented=d.isDefaultPrevented())}})},b}),b.define("select2/translation",["jquery","require"],function(a,b){function c(a){this.dict=a||{}}return c.prototype.all=function(){return this.dict},c.prototype.get=function(a){return this.dict[a]},c.prototype.extend=function(b){this.dict=a.extend({},b.all(),this.dict)},c._cache={},c.loadPath=function(a){if(!(a in c._cache)){var d=b(a);c._cache[a]=d}return new c(c._cache[a])},c}),b.define("select2/diacritics",[],function(){var a={"Ⓐ":"A","A":"A","À":"A","Á":"A","Â":"A","Ầ":"A","Ấ":"A","Ẫ":"A","Ẩ":"A","Ã":"A","Ā":"A","Ă":"A","Ằ":"A","Ắ":"A","Ẵ":"A","Ẳ":"A","Ȧ":"A","Ǡ":"A","Ä":"A","Ǟ":"A","Ả":"A","Å":"A","Ǻ":"A","Ǎ":"A","Ȁ":"A","Ȃ":"A","Ạ":"A","Ậ":"A","Ặ":"A","Ḁ":"A","Ą":"A","Ⱥ":"A","Ɐ":"A","Ꜳ":"AA","Æ":"AE","Ǽ":"AE","Ǣ":"AE","Ꜵ":"AO","Ꜷ":"AU","Ꜹ":"AV","Ꜻ":"AV","Ꜽ":"AY","Ⓑ":"B","B":"B","Ḃ":"B","Ḅ":"B","Ḇ":"B","Ƀ":"B","Ƃ":"B","Ɓ":"B","Ⓒ":"C","C":"C","Ć":"C","Ĉ":"C","Ċ":"C","Č":"C","Ç":"C","Ḉ":"C","Ƈ":"C","Ȼ":"C","Ꜿ":"C","Ⓓ":"D","D":"D","Ḋ":"D","Ď":"D","Ḍ":"D","Ḑ":"D","Ḓ":"D","Ḏ":"D","Đ":"D","Ƌ":"D","Ɗ":"D","Ɖ":"D","Ꝺ":"D","DZ":"DZ","DŽ":"DZ","Dz":"Dz","Dž":"Dz","Ⓔ":"E","E":"E","È":"E","É":"E","Ê":"E","Ề":"E","Ế":"E","Ễ":"E","Ể":"E","Ẽ":"E","Ē":"E","Ḕ":"E","Ḗ":"E","Ĕ":"E","Ė":"E","Ë":"E","Ẻ":"E","Ě":"E","Ȅ":"E","Ȇ":"E","Ẹ":"E","Ệ":"E","Ȩ":"E","Ḝ":"E","Ę":"E","Ḙ":"E","Ḛ":"E","Ɛ":"E","Ǝ":"E","Ⓕ":"F","F":"F","Ḟ":"F","Ƒ":"F","Ꝼ":"F","Ⓖ":"G","G":"G","Ǵ":"G","Ĝ":"G","Ḡ":"G","Ğ":"G","Ġ":"G","Ǧ":"G","Ģ":"G","Ǥ":"G","Ɠ":"G","Ꞡ":"G","Ᵹ":"G","Ꝿ":"G","Ⓗ":"H","H":"H","Ĥ":"H","Ḣ":"H","Ḧ":"H","Ȟ":"H","Ḥ":"H","Ḩ":"H","Ḫ":"H","Ħ":"H","Ⱨ":"H","Ⱶ":"H","Ɥ":"H","Ⓘ":"I","I":"I","Ì":"I","Í":"I","Î":"I","Ĩ":"I","Ī":"I","Ĭ":"I","İ":"I","Ï":"I","Ḯ":"I","Ỉ":"I","Ǐ":"I","Ȉ":"I","Ȋ":"I","Ị":"I","Į":"I","Ḭ":"I","Ɨ":"I","Ⓙ":"J","J":"J","Ĵ":"J","Ɉ":"J","Ⓚ":"K","K":"K","Ḱ":"K","Ǩ":"K","Ḳ":"K","Ķ":"K","Ḵ":"K","Ƙ":"K","Ⱪ":"K","Ꝁ":"K","Ꝃ":"K","Ꝅ":"K","Ꞣ":"K","Ⓛ":"L","L":"L","Ŀ":"L","Ĺ":"L","Ľ":"L","Ḷ":"L","Ḹ":"L","Ļ":"L","Ḽ":"L","Ḻ":"L","Ł":"L","Ƚ":"L","Ɫ":"L","Ⱡ":"L","Ꝉ":"L","Ꝇ":"L","Ꞁ":"L","LJ":"LJ","Lj":"Lj","Ⓜ":"M","M":"M","Ḿ":"M","Ṁ":"M","Ṃ":"M","Ɱ":"M","Ɯ":"M","Ⓝ":"N","N":"N","Ǹ":"N","Ń":"N","Ñ":"N","Ṅ":"N","Ň":"N","Ṇ":"N","Ņ":"N","Ṋ":"N","Ṉ":"N","Ƞ":"N","Ɲ":"N","Ꞑ":"N","Ꞥ":"N","NJ":"NJ","Nj":"Nj","Ⓞ":"O","O":"O","Ò":"O","Ó":"O","Ô":"O","Ồ":"O","Ố":"O","Ỗ":"O","Ổ":"O","Õ":"O","Ṍ":"O","Ȭ":"O","Ṏ":"O","Ō":"O","Ṑ":"O","Ṓ":"O","Ŏ":"O","Ȯ":"O","Ȱ":"O","Ö":"O","Ȫ":"O","Ỏ":"O","Ő":"O","Ǒ":"O","Ȍ":"O","Ȏ":"O","Ơ":"O","Ờ":"O","Ớ":"O","Ỡ":"O","Ở":"O","Ợ":"O","Ọ":"O","Ộ":"O","Ǫ":"O","Ǭ":"O","Ø":"O","Ǿ":"O","Ɔ":"O","Ɵ":"O","Ꝋ":"O","Ꝍ":"O","Ƣ":"OI","Ꝏ":"OO","Ȣ":"OU","Ⓟ":"P","P":"P","Ṕ":"P","Ṗ":"P","Ƥ":"P","Ᵽ":"P","Ꝑ":"P","Ꝓ":"P","Ꝕ":"P","Ⓠ":"Q","Q":"Q","Ꝗ":"Q","Ꝙ":"Q","Ɋ":"Q","Ⓡ":"R","R":"R","Ŕ":"R","Ṙ":"R","Ř":"R","Ȑ":"R","Ȓ":"R","Ṛ":"R","Ṝ":"R","Ŗ":"R","Ṟ":"R","Ɍ":"R","Ɽ":"R","Ꝛ":"R","Ꞧ":"R","Ꞃ":"R","Ⓢ":"S","S":"S","ẞ":"S","Ś":"S","Ṥ":"S","Ŝ":"S","Ṡ":"S","Š":"S","Ṧ":"S","Ṣ":"S","Ṩ":"S","Ș":"S","Ş":"S","Ȿ":"S","Ꞩ":"S","Ꞅ":"S","Ⓣ":"T","T":"T","Ṫ":"T","Ť":"T","Ṭ":"T","Ț":"T","Ţ":"T","Ṱ":"T","Ṯ":"T","Ŧ":"T","Ƭ":"T","Ʈ":"T","Ⱦ":"T","Ꞇ":"T","Ꜩ":"TZ","Ⓤ":"U","U":"U","Ù":"U","Ú":"U","Û":"U","Ũ":"U","Ṹ":"U","Ū":"U","Ṻ":"U","Ŭ":"U","Ü":"U","Ǜ":"U","Ǘ":"U","Ǖ":"U","Ǚ":"U","Ủ":"U","Ů":"U","Ű":"U","Ǔ":"U","Ȕ":"U","Ȗ":"U","Ư":"U","Ừ":"U","Ứ":"U","Ữ":"U","Ử":"U","Ự":"U","Ụ":"U","Ṳ":"U","Ų":"U","Ṷ":"U","Ṵ":"U","Ʉ":"U","Ⓥ":"V","V":"V","Ṽ":"V","Ṿ":"V","Ʋ":"V","Ꝟ":"V","Ʌ":"V","Ꝡ":"VY","Ⓦ":"W","W":"W","Ẁ":"W","Ẃ":"W","Ŵ":"W","Ẇ":"W","Ẅ":"W","Ẉ":"W","Ⱳ":"W","Ⓧ":"X","X":"X","Ẋ":"X","Ẍ":"X","Ⓨ":"Y","Y":"Y","Ỳ":"Y","Ý":"Y","Ŷ":"Y","Ỹ":"Y","Ȳ":"Y","Ẏ":"Y","Ÿ":"Y","Ỷ":"Y","Ỵ":"Y","Ƴ":"Y","Ɏ":"Y","Ỿ":"Y","Ⓩ":"Z","Z":"Z","Ź":"Z","Ẑ":"Z","Ż":"Z","Ž":"Z","Ẓ":"Z","Ẕ":"Z","Ƶ":"Z","Ȥ":"Z","Ɀ":"Z","Ⱬ":"Z","Ꝣ":"Z","ⓐ":"a","a":"a","ẚ":"a","à":"a","á":"a","â":"a","ầ":"a","ấ":"a","ẫ":"a","ẩ":"a","ã":"a","ā":"a","ă":"a","ằ":"a","ắ":"a","ẵ":"a","ẳ":"a","ȧ":"a","ǡ":"a","ä":"a","ǟ":"a","ả":"a","å":"a","ǻ":"a","ǎ":"a","ȁ":"a","ȃ":"a","ạ":"a","ậ":"a","ặ":"a","ḁ":"a","ą":"a","ⱥ":"a","ɐ":"a","ꜳ":"aa","æ":"ae","ǽ":"ae","ǣ":"ae","ꜵ":"ao","ꜷ":"au","ꜹ":"av","ꜻ":"av","ꜽ":"ay","ⓑ":"b","b":"b","ḃ":"b","ḅ":"b","ḇ":"b","ƀ":"b","ƃ":"b","ɓ":"b","ⓒ":"c","c":"c","ć":"c","ĉ":"c","ċ":"c","č":"c","ç":"c","ḉ":"c","ƈ":"c","ȼ":"c","ꜿ":"c","ↄ":"c","ⓓ":"d","d":"d","ḋ":"d","ď":"d","ḍ":"d","ḑ":"d","ḓ":"d","ḏ":"d","đ":"d","ƌ":"d","ɖ":"d","ɗ":"d","ꝺ":"d","dz":"dz","dž":"dz","ⓔ":"e","e":"e","è":"e","é":"e","ê":"e","ề":"e","ế":"e","ễ":"e","ể":"e","ẽ":"e","ē":"e","ḕ":"e","ḗ":"e","ĕ":"e","ė":"e","ë":"e","ẻ":"e","ě":"e","ȅ":"e","ȇ":"e","ẹ":"e","ệ":"e","ȩ":"e","ḝ":"e","ę":"e","ḙ":"e","ḛ":"e","ɇ":"e","ɛ":"e","ǝ":"e","ⓕ":"f","f":"f","ḟ":"f","ƒ":"f","ꝼ":"f","ⓖ":"g","g":"g","ǵ":"g","ĝ":"g","ḡ":"g","ğ":"g","ġ":"g","ǧ":"g","ģ":"g","ǥ":"g","ɠ":"g","ꞡ":"g","ᵹ":"g","ꝿ":"g","ⓗ":"h","h":"h","ĥ":"h","ḣ":"h","ḧ":"h","ȟ":"h","ḥ":"h","ḩ":"h","ḫ":"h","ẖ":"h","ħ":"h","ⱨ":"h","ⱶ":"h","ɥ":"h","ƕ":"hv","ⓘ":"i","i":"i","ì":"i","í":"i","î":"i","ĩ":"i","ī":"i","ĭ":"i","ï":"i","ḯ":"i","ỉ":"i","ǐ":"i","ȉ":"i","ȋ":"i","ị":"i","į":"i","ḭ":"i","ɨ":"i","ı":"i","ⓙ":"j","j":"j","ĵ":"j","ǰ":"j","ɉ":"j","ⓚ":"k","k":"k","ḱ":"k","ǩ":"k","ḳ":"k","ķ":"k","ḵ":"k","ƙ":"k","ⱪ":"k","ꝁ":"k","ꝃ":"k","ꝅ":"k","ꞣ":"k","ⓛ":"l","l":"l","ŀ":"l","ĺ":"l","ľ":"l","ḷ":"l","ḹ":"l","ļ":"l","ḽ":"l","ḻ":"l","ſ":"l","ł":"l","ƚ":"l","ɫ":"l","ⱡ":"l","ꝉ":"l","ꞁ":"l","ꝇ":"l","lj":"lj","ⓜ":"m","m":"m","ḿ":"m","ṁ":"m","ṃ":"m","ɱ":"m","ɯ":"m","ⓝ":"n","n":"n","ǹ":"n","ń":"n","ñ":"n","ṅ":"n","ň":"n","ṇ":"n","ņ":"n","ṋ":"n","ṉ":"n","ƞ":"n","ɲ":"n","ʼn":"n","ꞑ":"n","ꞥ":"n","nj":"nj","ⓞ":"o","o":"o","ò":"o","ó":"o","ô":"o","ồ":"o","ố":"o","ỗ":"o","ổ":"o","õ":"o","ṍ":"o","ȭ":"o","ṏ":"o","ō":"o","ṑ":"o","ṓ":"o","ŏ":"o","ȯ":"o","ȱ":"o","ö":"o","ȫ":"o","ỏ":"o","ő":"o","ǒ":"o","ȍ":"o","ȏ":"o","ơ":"o","ờ":"o","ớ":"o","ỡ":"o","ở":"o","ợ":"o","ọ":"o","ộ":"o","ǫ":"o","ǭ":"o","ø":"o","ǿ":"o","ɔ":"o","ꝋ":"o","ꝍ":"o","ɵ":"o","ƣ":"oi","ȣ":"ou","ꝏ":"oo","ⓟ":"p","p":"p","ṕ":"p","ṗ":"p","ƥ":"p","ᵽ":"p","ꝑ":"p","ꝓ":"p","ꝕ":"p","ⓠ":"q","q":"q","ɋ":"q","ꝗ":"q","ꝙ":"q","ⓡ":"r","r":"r","ŕ":"r","ṙ":"r","ř":"r","ȑ":"r","ȓ":"r","ṛ":"r","ṝ":"r","ŗ":"r","ṟ":"r","ɍ":"r","ɽ":"r","ꝛ":"r","ꞧ":"r","ꞃ":"r","ⓢ":"s","s":"s","ß":"s","ś":"s","ṥ":"s","ŝ":"s","ṡ":"s","š":"s","ṧ":"s","ṣ":"s","ṩ":"s","ș":"s","ş":"s","ȿ":"s","ꞩ":"s","ꞅ":"s","ẛ":"s","ⓣ":"t","t":"t","ṫ":"t","ẗ":"t","ť":"t","ṭ":"t","ț":"t","ţ":"t","ṱ":"t","ṯ":"t","ŧ":"t","ƭ":"t","ʈ":"t","ⱦ":"t","ꞇ":"t","ꜩ":"tz","ⓤ":"u","u":"u","ù":"u","ú":"u","û":"u","ũ":"u","ṹ":"u","ū":"u","ṻ":"u","ŭ":"u","ü":"u","ǜ":"u","ǘ":"u","ǖ":"u","ǚ":"u","ủ":"u","ů":"u","ű":"u","ǔ":"u","ȕ":"u","ȗ":"u","ư":"u","ừ":"u","ứ":"u","ữ":"u","ử":"u","ự":"u","ụ":"u","ṳ":"u","ų":"u","ṷ":"u","ṵ":"u","ʉ":"u","ⓥ":"v","v":"v","ṽ":"v","ṿ":"v","ʋ":"v","ꝟ":"v","ʌ":"v","ꝡ":"vy","ⓦ":"w","w":"w","ẁ":"w","ẃ":"w","ŵ":"w","ẇ":"w","ẅ":"w","ẘ":"w","ẉ":"w","ⱳ":"w","ⓧ":"x","x":"x","ẋ":"x","ẍ":"x","ⓨ":"y","y":"y","ỳ":"y","ý":"y","ŷ":"y","ỹ":"y","ȳ":"y","ẏ":"y","ÿ":"y","ỷ":"y","ẙ":"y","ỵ":"y","ƴ":"y","ɏ":"y","ỿ":"y","ⓩ":"z","z":"z","ź":"z","ẑ":"z","ż":"z","ž":"z","ẓ":"z","ẕ":"z","ƶ":"z","ȥ":"z","ɀ":"z","ⱬ":"z","ꝣ":"z","Ά":"Α","Έ":"Ε","Ή":"Η","Ί":"Ι","Ϊ":"Ι","Ό":"Ο","Ύ":"Υ","Ϋ":"Υ","Ώ":"Ω","ά":"α","έ":"ε","ή":"η","ί":"ι","ϊ":"ι","ΐ":"ι","ό":"ο","ύ":"υ","ϋ":"υ","ΰ":"υ","ω":"ω","ς":"σ"};return a}),b.define("select2/data/base",["../utils"],function(a){function b(a,c){b.__super__.constructor.call(this)}return a.Extend(b,a.Observable),b.prototype.current=function(a){throw new Error("The `current` method must be defined in child classes.")},b.prototype.query=function(a,b){throw new Error("The `query` method must be defined in child classes.")},b.prototype.bind=function(a,b){},b.prototype.destroy=function(){},b.prototype.generateResultId=function(b,c){var d=b.id+"-result-";return d+=a.generateChars(4),d+=null!=c.id?"-"+c.id.toString():"-"+a.generateChars(4)},b}),b.define("select2/data/select",["./base","../utils","jquery"],function(a,b,c){function d(a,b){this.$element=a,this.options=b,d.__super__.constructor.call(this)}return b.Extend(d,a),d.prototype.current=function(a){var b=[],d=this;this.$element.find(":selected").each(function(){var a=c(this),e=d.item(a);b.push(e)}),a(b)},d.prototype.select=function(a){var b=this;if(a.selected=!0,c(a.element).is("option"))return a.element.selected=!0,void this.$element.trigger("change");
|
2
|
+
if(this.$element.prop("multiple"))this.current(function(d){var e=[];a=[a],a.push.apply(a,d);for(var f=0;f<a.length;f++){var g=a[f].id;-1===c.inArray(g,e)&&e.push(g)}b.$element.val(e),b.$element.trigger("change")});else{var d=a.id;this.$element.val(d),this.$element.trigger("change")}},d.prototype.unselect=function(a){var b=this;if(this.$element.prop("multiple"))return a.selected=!1,c(a.element).is("option")?(a.element.selected=!1,void this.$element.trigger("change")):void this.current(function(d){for(var e=[],f=0;f<d.length;f++){var g=d[f].id;g!==a.id&&-1===c.inArray(g,e)&&e.push(g)}b.$element.val(e),b.$element.trigger("change")})},d.prototype.bind=function(a,b){var c=this;this.container=a,a.on("select",function(a){c.select(a.data)}),a.on("unselect",function(a){c.unselect(a.data)})},d.prototype.destroy=function(){this.$element.find("*").each(function(){c.removeData(this,"data")})},d.prototype.query=function(a,b){var d=[],e=this,f=this.$element.children();f.each(function(){var b=c(this);if(b.is("option")||b.is("optgroup")){var f=e.item(b),g=e.matches(a,f);null!==g&&d.push(g)}}),b({results:d})},d.prototype.addOptions=function(a){b.appendMany(this.$element,a)},d.prototype.option=function(a){var b;a.children?(b=document.createElement("optgroup"),b.label=a.text):(b=document.createElement("option"),void 0!==b.textContent?b.textContent=a.text:b.innerText=a.text),a.id&&(b.value=a.id),a.disabled&&(b.disabled=!0),a.selected&&(b.selected=!0),a.title&&(b.title=a.title);var d=c(b),e=this._normalizeItem(a);return e.element=b,c.data(b,"data",e),d},d.prototype.item=function(a){var b={};if(b=c.data(a[0],"data"),null!=b)return b;if(a.is("option"))b={id:a.val(),text:a.text(),disabled:a.prop("disabled"),selected:a.prop("selected"),title:a.prop("title")};else if(a.is("optgroup")){b={text:a.prop("label"),children:[],title:a.prop("title")};for(var d=a.children("option"),e=[],f=0;f<d.length;f++){var g=c(d[f]),h=this.item(g);e.push(h)}b.children=e}return b=this._normalizeItem(b),b.element=a[0],c.data(a[0],"data",b),b},d.prototype._normalizeItem=function(a){c.isPlainObject(a)||(a={id:a,text:a}),a=c.extend({},{text:""},a);var b={selected:!1,disabled:!1};return null!=a.id&&(a.id=a.id.toString()),null!=a.text&&(a.text=a.text.toString()),null==a._resultId&&a.id&&null!=this.container&&(a._resultId=this.generateResultId(this.container,a)),c.extend({},b,a)},d.prototype.matches=function(a,b){var c=this.options.get("matcher");return c(a,b)},d}),b.define("select2/data/array",["./select","../utils","jquery"],function(a,b,c){function d(a,b){var c=b.get("data")||[];d.__super__.constructor.call(this,a,b),this.addOptions(this.convertToOptions(c))}return b.Extend(d,a),d.prototype.select=function(a){var b=this.$element.find("option").filter(function(b,c){return c.value==a.id.toString()});0===b.length&&(b=this.option(a),this.addOptions(b)),d.__super__.select.call(this,a)},d.prototype.convertToOptions=function(a){function d(a){return function(){return c(this).val()==a.id}}for(var e=this,f=this.$element.find("option"),g=f.map(function(){return e.item(c(this)).id}).get(),h=[],i=0;i<a.length;i++){var j=this._normalizeItem(a[i]);if(c.inArray(j.id,g)>=0){var k=f.filter(d(j)),l=this.item(k),m=c.extend(!0,{},j,l),n=this.option(m);k.replaceWith(n)}else{var o=this.option(j);if(j.children){var p=this.convertToOptions(j.children);b.appendMany(o,p)}h.push(o)}}return h},d}),b.define("select2/data/ajax",["./array","../utils","jquery"],function(a,b,c){function d(a,b){this.ajaxOptions=this._applyDefaults(b.get("ajax")),null!=this.ajaxOptions.processResults&&(this.processResults=this.ajaxOptions.processResults),d.__super__.constructor.call(this,a,b)}return b.Extend(d,a),d.prototype._applyDefaults=function(a){var b={data:function(a){return c.extend({},a,{q:a.term})},transport:function(a,b,d){var e=c.ajax(a);return e.then(b),e.fail(d),e}};return c.extend({},b,a,!0)},d.prototype.processResults=function(a){return a},d.prototype.query=function(a,b){function d(){var d=f.transport(f,function(d){var f=e.processResults(d,a);e.options.get("debug")&&window.console&&console.error&&(f&&f.results&&c.isArray(f.results)||console.error("Select2: The AJAX results did not return an array in the `results` key of the response.")),b(f)},function(){d.status&&"0"===d.status||e.trigger("results:message",{message:"errorLoading"})});e._request=d}var e=this;null!=this._request&&(c.isFunction(this._request.abort)&&this._request.abort(),this._request=null);var f=c.extend({type:"GET"},this.ajaxOptions);"function"==typeof f.url&&(f.url=f.url.call(this.$element,a)),"function"==typeof f.data&&(f.data=f.data.call(this.$element,a)),this.ajaxOptions.delay&&null!=a.term?(this._queryTimeout&&window.clearTimeout(this._queryTimeout),this._queryTimeout=window.setTimeout(d,this.ajaxOptions.delay)):d()},d}),b.define("select2/data/tags",["jquery"],function(a){function b(b,c,d){var e=d.get("tags"),f=d.get("createTag");void 0!==f&&(this.createTag=f);var g=d.get("insertTag");if(void 0!==g&&(this.insertTag=g),b.call(this,c,d),a.isArray(e))for(var h=0;h<e.length;h++){var i=e[h],j=this._normalizeItem(i),k=this.option(j);this.$element.append(k)}}return b.prototype.query=function(a,b,c){function d(a,f){for(var g=a.results,h=0;h<g.length;h++){var i=g[h],j=null!=i.children&&!d({results:i.children},!0),k=i.text===b.term;if(k||j)return f?!1:(a.data=g,void c(a))}if(f)return!0;var l=e.createTag(b);if(null!=l){var m=e.option(l);m.attr("data-select2-tag",!0),e.addOptions([m]),e.insertTag(g,l)}a.results=g,c(a)}var e=this;return this._removeOldTags(),null==b.term||null!=b.page?void a.call(this,b,c):void a.call(this,b,d)},b.prototype.createTag=function(b,c){var d=a.trim(c.term);return""===d?null:{id:d,text:d}},b.prototype.insertTag=function(a,b,c){b.unshift(c)},b.prototype._removeOldTags=function(b){var c=(this._lastTag,this.$element.find("option[data-select2-tag]"));c.each(function(){this.selected||a(this).remove()})},b}),b.define("select2/data/tokenizer",["jquery"],function(a){function b(a,b,c){var d=c.get("tokenizer");void 0!==d&&(this.tokenizer=d),a.call(this,b,c)}return b.prototype.bind=function(a,b,c){a.call(this,b,c),this.$search=b.dropdown.$search||b.selection.$search||c.find(".select2-search__field")},b.prototype.query=function(b,c,d){function e(b){var c=g._normalizeItem(b),d=g.$element.find("option").filter(function(){return a(this).val()===c.id});if(!d.length){var e=g.option(c);e.attr("data-select2-tag",!0),g._removeOldTags(),g.addOptions([e])}f(c)}function f(a){g.trigger("select",{data:a})}var g=this;c.term=c.term||"";var h=this.tokenizer(c,this.options,e);h.term!==c.term&&(this.$search.length&&(this.$search.val(h.term),this.$search.focus()),c.term=h.term),b.call(this,c,d)},b.prototype.tokenizer=function(b,c,d,e){for(var f=d.get("tokenSeparators")||[],g=c.term,h=0,i=this.createTag||function(a){return{id:a.term,text:a.term}};h<g.length;){var j=g[h];if(-1!==a.inArray(j,f)){var k=g.substr(0,h),l=a.extend({},c,{term:k}),m=i(l);null!=m?(e(m),g=g.substr(h+1)||"",h=0):h++}else h++}return{term:g}},b}),b.define("select2/data/minimumInputLength",[],function(){function a(a,b,c){this.minimumInputLength=c.get("minimumInputLength"),a.call(this,b,c)}return a.prototype.query=function(a,b,c){return b.term=b.term||"",b.term.length<this.minimumInputLength?void this.trigger("results:message",{message:"inputTooShort",args:{minimum:this.minimumInputLength,input:b.term,params:b}}):void a.call(this,b,c)},a}),b.define("select2/data/maximumInputLength",[],function(){function a(a,b,c){this.maximumInputLength=c.get("maximumInputLength"),a.call(this,b,c)}return a.prototype.query=function(a,b,c){return b.term=b.term||"",this.maximumInputLength>0&&b.term.length>this.maximumInputLength?void this.trigger("results:message",{message:"inputTooLong",args:{maximum:this.maximumInputLength,input:b.term,params:b}}):void a.call(this,b,c)},a}),b.define("select2/data/maximumSelectionLength",[],function(){function a(a,b,c){this.maximumSelectionLength=c.get("maximumSelectionLength"),a.call(this,b,c)}return a.prototype.query=function(a,b,c){var d=this;this.current(function(e){var f=null!=e?e.length:0;return d.maximumSelectionLength>0&&f>=d.maximumSelectionLength?void d.trigger("results:message",{message:"maximumSelected",args:{maximum:d.maximumSelectionLength}}):void a.call(d,b,c)})},a}),b.define("select2/dropdown",["jquery","./utils"],function(a,b){function c(a,b){this.$element=a,this.options=b,c.__super__.constructor.call(this)}return b.Extend(c,b.Observable),c.prototype.render=function(){var b=a('<span class="select2-dropdown"><span class="select2-results"></span></span>');return b.attr("dir",this.options.get("dir")),this.$dropdown=b,b},c.prototype.bind=function(){},c.prototype.position=function(a,b){},c.prototype.destroy=function(){this.$dropdown.remove()},c}),b.define("select2/dropdown/search",["jquery","../utils"],function(a,b){function c(){}return c.prototype.render=function(b){var c=b.call(this),d=a('<span class="select2-search select2-search--dropdown"><input class="select2-search__field" type="search" tabindex="-1" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" role="textbox" /></span>');return this.$searchContainer=d,this.$search=d.find("input"),c.prepend(d),c},c.prototype.bind=function(b,c,d){var e=this;b.call(this,c,d),this.$search.on("keydown",function(a){e.trigger("keypress",a),e._keyUpPrevented=a.isDefaultPrevented()}),this.$search.on("input",function(b){a(this).off("keyup")}),this.$search.on("keyup input",function(a){e.handleSearch(a)}),c.on("open",function(){e.$search.attr("tabindex",0),e.$search.focus(),window.setTimeout(function(){e.$search.focus()},0)}),c.on("close",function(){e.$search.attr("tabindex",-1),e.$search.val("")}),c.on("focus",function(){c.isOpen()&&e.$search.focus()}),c.on("results:all",function(a){if(null==a.query.term||""===a.query.term){var b=e.showSearch(a);b?e.$searchContainer.removeClass("select2-search--hide"):e.$searchContainer.addClass("select2-search--hide")}})},c.prototype.handleSearch=function(a){if(!this._keyUpPrevented){var b=this.$search.val();this.trigger("query",{term:b})}this._keyUpPrevented=!1},c.prototype.showSearch=function(a,b){return!0},c}),b.define("select2/dropdown/hidePlaceholder",[],function(){function a(a,b,c,d){this.placeholder=this.normalizePlaceholder(c.get("placeholder")),a.call(this,b,c,d)}return a.prototype.append=function(a,b){b.results=this.removePlaceholder(b.results),a.call(this,b)},a.prototype.normalizePlaceholder=function(a,b){return"string"==typeof b&&(b={id:"",text:b}),b},a.prototype.removePlaceholder=function(a,b){for(var c=b.slice(0),d=b.length-1;d>=0;d--){var e=b[d];this.placeholder.id===e.id&&c.splice(d,1)}return c},a}),b.define("select2/dropdown/infiniteScroll",["jquery"],function(a){function b(a,b,c,d){this.lastParams={},a.call(this,b,c,d),this.$loadingMore=this.createLoadingMore(),this.loading=!1}return b.prototype.append=function(a,b){this.$loadingMore.remove(),this.loading=!1,a.call(this,b),this.showLoadingMore(b)&&this.$results.append(this.$loadingMore)},b.prototype.bind=function(b,c,d){var e=this;b.call(this,c,d),c.on("query",function(a){e.lastParams=a,e.loading=!0}),c.on("query:append",function(a){e.lastParams=a,e.loading=!0}),this.$results.on("scroll",function(){var b=a.contains(document.documentElement,e.$loadingMore[0]);if(!e.loading&&b){var c=e.$results.offset().top+e.$results.outerHeight(!1),d=e.$loadingMore.offset().top+e.$loadingMore.outerHeight(!1);c+50>=d&&e.loadMore()}})},b.prototype.loadMore=function(){this.loading=!0;var b=a.extend({},{page:1},this.lastParams);b.page++,this.trigger("query:append",b)},b.prototype.showLoadingMore=function(a,b){return b.pagination&&b.pagination.more},b.prototype.createLoadingMore=function(){var b=a('<li class="select2-results__option select2-results__option--load-more"role="treeitem" aria-disabled="true"></li>'),c=this.options.get("translations").get("loadingMore");return b.html(c(this.lastParams)),b},b}),b.define("select2/dropdown/attachBody",["jquery","../utils"],function(a,b){function c(b,c,d){this.$dropdownParent=d.get("dropdownParent")||a(document.body),b.call(this,c,d)}return c.prototype.bind=function(a,b,c){var d=this,e=!1;a.call(this,b,c),b.on("open",function(){d._showDropdown(),d._attachPositioningHandler(b),e||(e=!0,b.on("results:all",function(){d._positionDropdown(),d._resizeDropdown()}),b.on("results:append",function(){d._positionDropdown(),d._resizeDropdown()}))}),b.on("close",function(){d._hideDropdown(),d._detachPositioningHandler(b)}),this.$dropdownContainer.on("mousedown",function(a){a.stopPropagation()})},c.prototype.destroy=function(a){a.call(this),this.$dropdownContainer.remove()},c.prototype.position=function(a,b,c){b.attr("class",c.attr("class")),b.removeClass("select2"),b.addClass("select2-container--open"),b.css({position:"absolute",top:-999999}),this.$container=c},c.prototype.render=function(b){var c=a("<span></span>"),d=b.call(this);return c.append(d),this.$dropdownContainer=c,c},c.prototype._hideDropdown=function(a){this.$dropdownContainer.detach()},c.prototype._attachPositioningHandler=function(c,d){var e=this,f="scroll.select2."+d.id,g="resize.select2."+d.id,h="orientationchange.select2."+d.id,i=this.$container.parents().filter(b.hasScroll);i.each(function(){a(this).data("select2-scroll-position",{x:a(this).scrollLeft(),y:a(this).scrollTop()})}),i.on(f,function(b){var c=a(this).data("select2-scroll-position");a(this).scrollTop(c.y)}),a(window).on(f+" "+g+" "+h,function(a){e._positionDropdown(),e._resizeDropdown()})},c.prototype._detachPositioningHandler=function(c,d){var e="scroll.select2."+d.id,f="resize.select2."+d.id,g="orientationchange.select2."+d.id,h=this.$container.parents().filter(b.hasScroll);h.off(e),a(window).off(e+" "+f+" "+g)},c.prototype._positionDropdown=function(){var b=a(window),c=this.$dropdown.hasClass("select2-dropdown--above"),d=this.$dropdown.hasClass("select2-dropdown--below"),e=null,f=this.$container.offset();f.bottom=f.top+this.$container.outerHeight(!1);var g={height:this.$container.outerHeight(!1)};g.top=f.top,g.bottom=f.top+g.height;var h={height:this.$dropdown.outerHeight(!1)},i={top:b.scrollTop(),bottom:b.scrollTop()+b.height()},j=i.top<f.top-h.height,k=i.bottom>f.bottom+h.height,l={left:f.left,top:g.bottom},m=this.$dropdownParent;"static"===m.css("position")&&(m=m.offsetParent());var n=m.offset();l.top-=n.top,l.left-=n.left,c||d||(e="below"),k||!j||c?!j&&k&&c&&(e="below"):e="above",("above"==e||c&&"below"!==e)&&(l.top=g.top-n.top-h.height),null!=e&&(this.$dropdown.removeClass("select2-dropdown--below select2-dropdown--above").addClass("select2-dropdown--"+e),this.$container.removeClass("select2-container--below select2-container--above").addClass("select2-container--"+e)),this.$dropdownContainer.css(l)},c.prototype._resizeDropdown=function(){var a={width:this.$container.outerWidth(!1)+"px"};this.options.get("dropdownAutoWidth")&&(a.minWidth=a.width,a.position="relative",a.width="auto"),this.$dropdown.css(a)},c.prototype._showDropdown=function(a){this.$dropdownContainer.appendTo(this.$dropdownParent),this._positionDropdown(),this._resizeDropdown()},c}),b.define("select2/dropdown/minimumResultsForSearch",[],function(){function a(b){for(var c=0,d=0;d<b.length;d++){var e=b[d];e.children?c+=a(e.children):c++}return c}function b(a,b,c,d){this.minimumResultsForSearch=c.get("minimumResultsForSearch"),this.minimumResultsForSearch<0&&(this.minimumResultsForSearch=1/0),a.call(this,b,c,d)}return b.prototype.showSearch=function(b,c){return a(c.data.results)<this.minimumResultsForSearch?!1:b.call(this,c)},b}),b.define("select2/dropdown/selectOnClose",[],function(){function a(){}return a.prototype.bind=function(a,b,c){var d=this;a.call(this,b,c),b.on("close",function(a){d._handleSelectOnClose(a)})},a.prototype._handleSelectOnClose=function(a,b){if(b&&null!=b.originalSelect2Event){var c=b.originalSelect2Event;if("select"===c._type||"unselect"===c._type)return}var d=this.getHighlightedResults();if(!(d.length<1)){var e=d.data("data");null!=e.element&&e.element.selected||null==e.element&&e.selected||this.trigger("select",{data:e})}},a}),b.define("select2/dropdown/closeOnSelect",[],function(){function a(){}return a.prototype.bind=function(a,b,c){var d=this;a.call(this,b,c),b.on("select",function(a){d._selectTriggered(a)}),b.on("unselect",function(a){d._selectTriggered(a)})},a.prototype._selectTriggered=function(a,b){var c=b.originalEvent;c&&c.ctrlKey||this.trigger("close",{originalEvent:c,originalSelect2Event:b})},a}),b.define("select2/i18n/en",[],function(){return{errorLoading:function(){return"The results could not be loaded."},inputTooLong:function(a){var b=a.input.length-a.maximum,c="Please delete "+b+" character";return 1!=b&&(c+="s"),c},inputTooShort:function(a){var b=a.minimum-a.input.length,c="Please enter "+b+" or more characters";return c},loadingMore:function(){return"Loading more results…"},maximumSelected:function(a){var b="You can only select "+a.maximum+" item";return 1!=a.maximum&&(b+="s"),b},noResults:function(){return"No results found"},searching:function(){return"Searching…"}}}),b.define("select2/defaults",["jquery","require","./results","./selection/single","./selection/multiple","./selection/placeholder","./selection/allowClear","./selection/search","./selection/eventRelay","./utils","./translation","./diacritics","./data/select","./data/array","./data/ajax","./data/tags","./data/tokenizer","./data/minimumInputLength","./data/maximumInputLength","./data/maximumSelectionLength","./dropdown","./dropdown/search","./dropdown/hidePlaceholder","./dropdown/infiniteScroll","./dropdown/attachBody","./dropdown/minimumResultsForSearch","./dropdown/selectOnClose","./dropdown/closeOnSelect","./i18n/en"],function(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C){function D(){this.reset()}D.prototype.apply=function(l){if(l=a.extend(!0,{},this.defaults,l),null==l.dataAdapter){if(null!=l.ajax?l.dataAdapter=o:null!=l.data?l.dataAdapter=n:l.dataAdapter=m,l.minimumInputLength>0&&(l.dataAdapter=j.Decorate(l.dataAdapter,r)),l.maximumInputLength>0&&(l.dataAdapter=j.Decorate(l.dataAdapter,s)),l.maximumSelectionLength>0&&(l.dataAdapter=j.Decorate(l.dataAdapter,t)),l.tags&&(l.dataAdapter=j.Decorate(l.dataAdapter,p)),(null!=l.tokenSeparators||null!=l.tokenizer)&&(l.dataAdapter=j.Decorate(l.dataAdapter,q)),null!=l.query){var C=b(l.amdBase+"compat/query");l.dataAdapter=j.Decorate(l.dataAdapter,C)}if(null!=l.initSelection){var D=b(l.amdBase+"compat/initSelection");l.dataAdapter=j.Decorate(l.dataAdapter,D)}}if(null==l.resultsAdapter&&(l.resultsAdapter=c,null!=l.ajax&&(l.resultsAdapter=j.Decorate(l.resultsAdapter,x)),null!=l.placeholder&&(l.resultsAdapter=j.Decorate(l.resultsAdapter,w)),l.selectOnClose&&(l.resultsAdapter=j.Decorate(l.resultsAdapter,A))),null==l.dropdownAdapter){if(l.multiple)l.dropdownAdapter=u;else{var E=j.Decorate(u,v);l.dropdownAdapter=E}if(0!==l.minimumResultsForSearch&&(l.dropdownAdapter=j.Decorate(l.dropdownAdapter,z)),l.closeOnSelect&&(l.dropdownAdapter=j.Decorate(l.dropdownAdapter,B)),null!=l.dropdownCssClass||null!=l.dropdownCss||null!=l.adaptDropdownCssClass){var F=b(l.amdBase+"compat/dropdownCss");l.dropdownAdapter=j.Decorate(l.dropdownAdapter,F)}l.dropdownAdapter=j.Decorate(l.dropdownAdapter,y)}if(null==l.selectionAdapter){if(l.multiple?l.selectionAdapter=e:l.selectionAdapter=d,null!=l.placeholder&&(l.selectionAdapter=j.Decorate(l.selectionAdapter,f)),l.allowClear&&(l.selectionAdapter=j.Decorate(l.selectionAdapter,g)),l.multiple&&(l.selectionAdapter=j.Decorate(l.selectionAdapter,h)),null!=l.containerCssClass||null!=l.containerCss||null!=l.adaptContainerCssClass){var G=b(l.amdBase+"compat/containerCss");l.selectionAdapter=j.Decorate(l.selectionAdapter,G)}l.selectionAdapter=j.Decorate(l.selectionAdapter,i)}if("string"==typeof l.language)if(l.language.indexOf("-")>0){var H=l.language.split("-"),I=H[0];l.language=[l.language,I]}else l.language=[l.language];if(a.isArray(l.language)){var J=new k;l.language.push("en");for(var K=l.language,L=0;L<K.length;L++){var M=K[L],N={};try{N=k.loadPath(M)}catch(O){try{M=this.defaults.amdLanguageBase+M,N=k.loadPath(M)}catch(P){l.debug&&window.console&&console.warn&&console.warn('Select2: The language file for "'+M+'" could not be automatically loaded. A fallback will be used instead.');continue}}J.extend(N)}l.translations=J}else{var Q=k.loadPath(this.defaults.amdLanguageBase+"en"),R=new k(l.language);R.extend(Q),l.translations=R}return l},D.prototype.reset=function(){function b(a){function b(a){return l[a]||a}return a.replace(/[^\u0000-\u007E]/g,b)}function c(d,e){if(""===a.trim(d.term))return e;if(e.children&&e.children.length>0){for(var f=a.extend(!0,{},e),g=e.children.length-1;g>=0;g--){var h=e.children[g],i=c(d,h);null==i&&f.children.splice(g,1)}return f.children.length>0?f:c(d,f)}var j=b(e.text).toUpperCase(),k=b(d.term).toUpperCase();return j.indexOf(k)>-1?e:null}this.defaults={amdBase:"./",amdLanguageBase:"./i18n/",closeOnSelect:!0,debug:!1,dropdownAutoWidth:!1,escapeMarkup:j.escapeMarkup,language:C,matcher:c,minimumInputLength:0,maximumInputLength:0,maximumSelectionLength:0,minimumResultsForSearch:0,selectOnClose:!1,sorter:function(a){return a},templateResult:function(a){return a.text},templateSelection:function(a){return a.text},theme:"default",width:"resolve"}},D.prototype.set=function(b,c){var d=a.camelCase(b),e={};e[d]=c;var f=j._convertData(e);a.extend(this.defaults,f)};var E=new D;return E}),b.define("select2/options",["require","jquery","./defaults","./utils"],function(a,b,c,d){function e(b,e){if(this.options=b,null!=e&&this.fromElement(e),this.options=c.apply(this.options),e&&e.is("input")){var f=a(this.get("amdBase")+"compat/inputData");this.options.dataAdapter=d.Decorate(this.options.dataAdapter,f)}}return e.prototype.fromElement=function(a){var c=["select2"];null==this.options.multiple&&(this.options.multiple=a.prop("multiple")),null==this.options.disabled&&(this.options.disabled=a.prop("disabled")),null==this.options.language&&(a.prop("lang")?this.options.language=a.prop("lang").toLowerCase():a.closest("[lang]").prop("lang")&&(this.options.language=a.closest("[lang]").prop("lang"))),null==this.options.dir&&(a.prop("dir")?this.options.dir=a.prop("dir"):a.closest("[dir]").prop("dir")?this.options.dir=a.closest("[dir]").prop("dir"):this.options.dir="ltr"),a.prop("disabled",this.options.disabled),a.prop("multiple",this.options.multiple),a.data("select2Tags")&&(this.options.debug&&window.console&&console.warn&&console.warn('Select2: The `data-select2-tags` attribute has been changed to use the `data-data` and `data-tags="true"` attributes and will be removed in future versions of Select2.'),a.data("data",a.data("select2Tags")),a.data("tags",!0)),a.data("ajaxUrl")&&(this.options.debug&&window.console&&console.warn&&console.warn("Select2: The `data-ajax-url` attribute has been changed to `data-ajax--url` and support for the old attribute will be removed in future versions of Select2."),a.attr("ajax--url",a.data("ajaxUrl")),a.data("ajax--url",a.data("ajaxUrl")));var e={};e=b.fn.jquery&&"1."==b.fn.jquery.substr(0,2)&&a[0].dataset?b.extend(!0,{},a[0].dataset,a.data()):a.data();var f=b.extend(!0,{},e);f=d._convertData(f);for(var g in f)b.inArray(g,c)>-1||(b.isPlainObject(this.options[g])?b.extend(this.options[g],f[g]):this.options[g]=f[g]);return this},e.prototype.get=function(a){return this.options[a]},e.prototype.set=function(a,b){this.options[a]=b},e}),b.define("select2/core",["jquery","./options","./utils","./keys"],function(a,b,c,d){var e=function(a,c){null!=a.data("select2")&&a.data("select2").destroy(),this.$element=a,this.id=this._generateId(a),c=c||{},this.options=new b(c,a),e.__super__.constructor.call(this);var d=a.attr("tabindex")||0;a.data("old-tabindex",d),a.attr("tabindex","-1");var f=this.options.get("dataAdapter");this.dataAdapter=new f(a,this.options);var g=this.render();this._placeContainer(g);var h=this.options.get("selectionAdapter");this.selection=new h(a,this.options),this.$selection=this.selection.render(),this.selection.position(this.$selection,g);var i=this.options.get("dropdownAdapter");this.dropdown=new i(a,this.options),this.$dropdown=this.dropdown.render(),this.dropdown.position(this.$dropdown,g);var j=this.options.get("resultsAdapter");this.results=new j(a,this.options,this.dataAdapter),this.$results=this.results.render(),this.results.position(this.$results,this.$dropdown);var k=this;this._bindAdapters(),this._registerDomEvents(),this._registerDataEvents(),this._registerSelectionEvents(),this._registerDropdownEvents(),this._registerResultsEvents(),this._registerEvents(),this.dataAdapter.current(function(a){k.trigger("selection:update",{data:a})}),a.addClass("select2-hidden-accessible"),a.attr("aria-hidden","true"),this._syncAttributes(),a.data("select2",this)};return c.Extend(e,c.Observable),e.prototype._generateId=function(a){var b="";return b=null!=a.attr("id")?a.attr("id"):null!=a.attr("name")?a.attr("name")+"-"+c.generateChars(2):c.generateChars(4),b=b.replace(/(:|\.|\[|\]|,)/g,""),b="select2-"+b},e.prototype._placeContainer=function(a){a.insertAfter(this.$element);var b=this._resolveWidth(this.$element,this.options.get("width"));null!=b&&a.css("width",b)},e.prototype._resolveWidth=function(a,b){var c=/^width:(([-+]?([0-9]*\.)?[0-9]+)(px|em|ex|%|in|cm|mm|pt|pc))/i;if("resolve"==b){var d=this._resolveWidth(a,"style");return null!=d?d:this._resolveWidth(a,"element")}if("element"==b){var e=a.outerWidth(!1);return 0>=e?"auto":e+"px"}if("style"==b){var f=a.attr("style");if("string"!=typeof f)return null;for(var g=f.split(";"),h=0,i=g.length;i>h;h+=1){var j=g[h].replace(/\s/g,""),k=j.match(c);if(null!==k&&k.length>=1)return k[1]}return null}return b},e.prototype._bindAdapters=function(){this.dataAdapter.bind(this,this.$container),this.selection.bind(this,this.$container),this.dropdown.bind(this,this.$container),this.results.bind(this,this.$container)},e.prototype._registerDomEvents=function(){var b=this;this.$element.on("change.select2",function(){b.dataAdapter.current(function(a){b.trigger("selection:update",{data:a})})}),this.$element.on("focus.select2",function(a){b.trigger("focus",a)}),this._syncA=c.bind(this._syncAttributes,this),this._syncS=c.bind(this._syncSubtree,this),this.$element[0].attachEvent&&this.$element[0].attachEvent("onpropertychange",this._syncA);var d=window.MutationObserver||window.WebKitMutationObserver||window.MozMutationObserver;null!=d?(this._observer=new d(function(c){a.each(c,b._syncA),a.each(c,b._syncS)}),this._observer.observe(this.$element[0],{attributes:!0,childList:!0,subtree:!1})):this.$element[0].addEventListener&&(this.$element[0].addEventListener("DOMAttrModified",b._syncA,!1),this.$element[0].addEventListener("DOMNodeInserted",b._syncS,!1),this.$element[0].addEventListener("DOMNodeRemoved",b._syncS,!1))},e.prototype._registerDataEvents=function(){var a=this;this.dataAdapter.on("*",function(b,c){a.trigger(b,c)})},e.prototype._registerSelectionEvents=function(){var b=this,c=["toggle","focus"];this.selection.on("toggle",function(){b.toggleDropdown()}),this.selection.on("focus",function(a){b.focus(a)}),this.selection.on("*",function(d,e){-1===a.inArray(d,c)&&b.trigger(d,e)})},e.prototype._registerDropdownEvents=function(){var a=this;this.dropdown.on("*",function(b,c){a.trigger(b,c)})},e.prototype._registerResultsEvents=function(){var a=this;this.results.on("*",function(b,c){a.trigger(b,c)})},e.prototype._registerEvents=function(){var a=this;this.on("open",function(){a.$container.addClass("select2-container--open")}),this.on("close",function(){a.$container.removeClass("select2-container--open")}),this.on("enable",function(){a.$container.removeClass("select2-container--disabled")}),this.on("disable",function(){a.$container.addClass("select2-container--disabled")}),this.on("blur",function(){a.$container.removeClass("select2-container--focus")}),this.on("query",function(b){a.isOpen()||a.trigger("open",{}),this.dataAdapter.query(b,function(c){a.trigger("results:all",{data:c,query:b})})}),this.on("query:append",function(b){this.dataAdapter.query(b,function(c){a.trigger("results:append",{data:c,query:b})})}),this.on("keypress",function(b){var c=b.which;a.isOpen()?c===d.ESC||c===d.TAB||c===d.UP&&b.altKey?(a.close(),b.preventDefault()):c===d.ENTER?(a.trigger("results:select",{}),b.preventDefault()):c===d.SPACE&&b.ctrlKey?(a.trigger("results:toggle",{}),b.preventDefault()):c===d.UP?(a.trigger("results:previous",{}),b.preventDefault()):c===d.DOWN&&(a.trigger("results:next",{}),b.preventDefault()):(c===d.ENTER||c===d.SPACE||c===d.DOWN&&b.altKey)&&(a.open(),b.preventDefault())})},e.prototype._syncAttributes=function(){this.options.set("disabled",this.$element.prop("disabled")),this.options.get("disabled")?(this.isOpen()&&this.close(),this.trigger("disable",{})):this.trigger("enable",{})},e.prototype._syncSubtree=function(a,b){var c=!1,d=this;if(!a||!a.target||"OPTION"===a.target.nodeName||"OPTGROUP"===a.target.nodeName){if(b)if(b.addedNodes&&b.addedNodes.length>0)for(var e=0;e<b.addedNodes.length;e++){var f=b.addedNodes[e];f.selected&&(c=!0)}else b.removedNodes&&b.removedNodes.length>0&&(c=!0);else c=!0;c&&this.dataAdapter.current(function(a){d.trigger("selection:update",{data:a})})}},e.prototype.trigger=function(a,b){var c=e.__super__.trigger,d={open:"opening",close:"closing",select:"selecting",unselect:"unselecting"};if(void 0===b&&(b={}),a in d){var f=d[a],g={prevented:!1,name:a,args:b};if(c.call(this,f,g),g.prevented)return void(b.prevented=!0)}c.call(this,a,b)},e.prototype.toggleDropdown=function(){this.options.get("disabled")||(this.isOpen()?this.close():this.open())},e.prototype.open=function(){this.isOpen()||this.trigger("query",{})},e.prototype.close=function(){this.isOpen()&&this.trigger("close",{})},e.prototype.isOpen=function(){return this.$container.hasClass("select2-container--open")},e.prototype.hasFocus=function(){return this.$container.hasClass("select2-container--focus")},e.prototype.focus=function(a){this.hasFocus()||(this.$container.addClass("select2-container--focus"),this.trigger("focus",{}))},e.prototype.enable=function(a){this.options.get("debug")&&window.console&&console.warn&&console.warn('Select2: The `select2("enable")` method has been deprecated and will be removed in later Select2 versions. Use $element.prop("disabled") instead.'),(null==a||0===a.length)&&(a=[!0]);var b=!a[0];this.$element.prop("disabled",b)},e.prototype.data=function(){this.options.get("debug")&&arguments.length>0&&window.console&&console.warn&&console.warn('Select2: Data can no longer be set using `select2("data")`. You should consider setting the value instead using `$element.val()`.');var a=[];return this.dataAdapter.current(function(b){a=b}),a},e.prototype.val=function(b){if(this.options.get("debug")&&window.console&&console.warn&&console.warn('Select2: The `select2("val")` method has been deprecated and will be removed in later Select2 versions. Use $element.val() instead.'),null==b||0===b.length)return this.$element.val();var c=b[0];a.isArray(c)&&(c=a.map(c,function(a){return a.toString()})),this.$element.val(c).trigger("change")},e.prototype.destroy=function(){this.$container.remove(),this.$element[0].detachEvent&&this.$element[0].detachEvent("onpropertychange",this._syncA),null!=this._observer?(this._observer.disconnect(),this._observer=null):this.$element[0].removeEventListener&&(this.$element[0].removeEventListener("DOMAttrModified",this._syncA,!1),this.$element[0].removeEventListener("DOMNodeInserted",this._syncS,!1),this.$element[0].removeEventListener("DOMNodeRemoved",this._syncS,!1)),this._syncA=null,this._syncS=null,this.$element.off(".select2"),this.$element.attr("tabindex",this.$element.data("old-tabindex")),this.$element.removeClass("select2-hidden-accessible"),this.$element.attr("aria-hidden","false"),this.$element.removeData("select2"),this.dataAdapter.destroy(),this.selection.destroy(),this.dropdown.destroy(),this.results.destroy(),this.dataAdapter=null,this.selection=null,this.dropdown=null,this.results=null;
|
3
|
+
},e.prototype.render=function(){var b=a('<span class="select2 select2-container"><span class="selection"></span><span class="dropdown-wrapper" aria-hidden="true"></span></span>');return b.attr("dir",this.options.get("dir")),this.$container=b,this.$container.addClass("select2-container--"+this.options.get("theme")),b.data("element",this.$element),b},e}),b.define("jquery-mousewheel",["jquery"],function(a){return a}),b.define("jquery.select2",["jquery","jquery-mousewheel","./select2/core","./select2/defaults"],function(a,b,c,d){if(null==a.fn.select2){var e=["open","close","destroy"];a.fn.select2=function(b){if(b=b||{},"object"==typeof b)return this.each(function(){var d=a.extend(!0,{},b);new c(a(this),d)}),this;if("string"==typeof b){var d,f=Array.prototype.slice.call(arguments,1);return this.each(function(){var c=a(this).data("select2");null==c&&window.console&&console.error&&console.error("The select2('"+b+"') method was called on an element that is not using Select2."),d=c[b].apply(c,f)}),a.inArray(b,e)>-1?this:d}throw new Error("Invalid arguments for Select2: "+b)}}return null==a.fn.select2.defaults&&(a.fn.select2.defaults=d),c}),{define:b.define,require:b.require}}(),c=b.require("jquery.select2");return a.fn.select2.amd=b,c});
|