1
1
/*!
2
- * Select2 4.0.3
2
+ * Select2 4.0.4
3
3
* https://select2.github.io
4
4
*
5
5
* Released under the MIT license
9
9
if ( typeof define === 'function' && define . amd ) {
10
10
// AMD. Register as an anonymous module.
11
11
define ( [ 'jquery' ] , factory ) ;
12
- } else if ( typeof exports === 'object' ) {
12
+ } else if ( typeof module === 'object' && module . exports ) {
13
13
// Node/CommonJS
14
- factory ( require ( 'jquery' ) ) ;
14
+ module . exports = function ( root , jQuery ) {
15
+ if ( jQuery === undefined ) {
16
+ // require('jQuery') returns a factory that requires window to
17
+ // build a jQuery instance, we normalize how we use modules
18
+ // that require this pattern but the window provided is a noop
19
+ // if it's defined (how jquery works)
20
+ if ( typeof window !== 'undefined' ) {
21
+ jQuery = require ( 'jquery' ) ;
22
+ }
23
+ else {
24
+ jQuery = require ( 'jquery' ) ( root ) ;
25
+ }
26
+ }
27
+ factory ( jQuery ) ;
28
+ return jQuery ;
29
+ } ;
15
30
} else {
16
31
// Browser globals
17
32
factory ( jQuery ) ;
18
33
}
19
- } ( function ( jQuery ) {
34
+ } ( function ( jQuery ) {
20
35
// This is needed so we can catch the AMD loader configuration and use it
21
36
// The inner file should be wrapped (by `banner.start.js`) in a function that
22
37
// returns the AMD loader references.
23
- var S2 =
24
- ( function ( ) {
38
+ var S2 = ( function ( ) {
25
39
// Restore the Select2 AMD loader so it can be used
26
40
// Needed mostly in the language files, where the loader is not inserted
27
41
if ( jQuery && jQuery . fn && jQuery . fn . select2 && jQuery . fn . select2 . amd ) {
30
44
var S2 ; ( function ( ) { if ( ! S2 || ! S2 . requirejs ) {
31
45
if ( ! S2 ) { S2 = { } ; } else { require = S2 ; }
32
46
/**
33
- * @license almond 0.3.1 Copyright (c) 2011-2014, The Dojo Foundation All Rights Reserved.
34
- * Available via the MIT or new BSD license.
35
- * see: http://github.com/jrburke/almond for details
47
+ * @license almond 0.3.3 Copyright jQuery Foundation and other contributors.
48
+ * Released under MIT license, http://github.com/requirejs/almond/LICENSE
36
49
*/
37
50
//Going sloppy to avoid 'use strict' string cost, but strict practices should
38
51
//be followed.
39
- /*jslint sloppy: true */
40
52
/*global setTimeout: false */
41
53
42
54
var requirejs , require , define ;
@@ -64,60 +76,58 @@ var requirejs, require, define;
64
76
*/
65
77
function normalize ( name , baseName ) {
66
78
var nameParts , nameSegment , mapValue , foundMap , lastIndex ,
67
- foundI , foundStarMap , starI , i , j , part ,
79
+ foundI , foundStarMap , starI , i , j , part , normalizedBaseParts ,
68
80
baseParts = baseName && baseName . split ( "/" ) ,
69
81
map = config . map ,
70
82
starMap = ( map && map [ '*' ] ) || { } ;
71
83
72
84
//Adjust any relative paths.
73
- if ( name && name . charAt ( 0 ) === "." ) {
74
- //If have a base name, try to normalize against it,
75
- //otherwise, assume it is a top-level require that will
76
- //be relative to baseUrl in the end.
77
- if ( baseName ) {
78
- name = name . split ( '/' ) ;
79
- lastIndex = name . length - 1 ;
80
-
81
- // Node .js allowance:
82
- if ( config . nodeIdCompat && jsSuffixRegExp . test ( name [ lastIndex ] ) ) {
83
- name [ lastIndex ] = name [ lastIndex ] . replace ( jsSuffixRegExp , '' ) ;
84
- }
85
+ if ( name ) {
86
+ name = name . split ( '/' ) ;
87
+ lastIndex = name . length - 1 ;
88
+
89
+ // If wanting node ID compatibility, strip .js from end
90
+ // of IDs. Have to do this here, and not in nameToUrl
91
+ // because node allows either .js or non .js to map
92
+ // to same file.
93
+ if ( config . nodeIdCompat && jsSuffixRegExp . test ( name [ lastIndex ] ) ) {
94
+ name [ lastIndex ] = name [ lastIndex ] . replace ( jsSuffixRegExp , '' ) ;
95
+ }
85
96
86
- //Lop off the last part of baseParts, so that . matches the
87
- //"directory" and not name of the baseName's module. For instance,
88
- //baseName of "one/two/three", maps to "one/two/three.js", but we
89
- //want the directory, "one/two" for this normalization.
90
- name = baseParts . slice ( 0 , baseParts . length - 1 ) . concat ( name ) ;
91
-
92
- //start trimDots
93
- for ( i = 0 ; i < name . length ; i += 1 ) {
94
- part = name [ i ] ;
95
- if ( part === "." ) {
96
- name . splice ( i , 1 ) ;
97
- i -= 1 ;
98
- } else if ( part === ".." ) {
99
- if ( i === 1 && ( name [ 2 ] === '..' || name [ 0 ] === '..' ) ) {
100
- //End of the line. Keep at least one non-dot
101
- //path segment at the front so it can be mapped
102
- //correctly to disk. Otherwise, there is likely
103
- //no path mapping for a path starting with '..'.
104
- //This can still fail, but catches the most reasonable
105
- //uses of ..
106
- break ;
107
- } else if ( i > 0 ) {
108
- name . splice ( i - 1 , 2 ) ;
109
- i -= 2 ;
110
- }
97
+ // Starts with a '.' so need the baseName
98
+ if ( name [ 0 ] . charAt ( 0 ) === '.' && baseParts ) {
99
+ //Convert baseName to array, and lop off the last part,
100
+ //so that . matches that 'directory' and not name of the baseName's
101
+ //module. For instance, baseName of 'one/two/three', maps to
102
+ //'one/two/three.js', but we want the directory, 'one/two' for
103
+ //this normalization.
104
+ normalizedBaseParts = baseParts . slice ( 0 , baseParts . length - 1 ) ;
105
+ name = normalizedBaseParts . concat ( name ) ;
106
+ }
107
+
108
+ //start trimDots
109
+ for ( i = 0 ; i < name . length ; i ++ ) {
110
+ part = name [ i ] ;
111
+ if ( part === '.' ) {
112
+ name . splice ( i , 1 ) ;
113
+ i -= 1 ;
114
+ } else if ( part === '..' ) {
115
+ // If at the start, or previous value is still ..,
116
+ // keep them so that when converted to a path it may
117
+ // still work when converted to a path, even though
118
+ // as an ID it is less than ideal. In larger point
119
+ // releases, may be better to just kick out an error.
120
+ if ( i === 0 || ( i === 1 && name [ 2 ] === '..' ) || name [ i - 1 ] === '..' ) {
121
+ continue ;
122
+ } else if ( i > 0 ) {
123
+ name . splice ( i - 1 , 2 ) ;
124
+ i -= 2 ;
111
125
}
112
126
}
113
- //end trimDots
114
-
115
- name = name . join ( "/" ) ;
116
- } else if ( name . indexOf ( './' ) === 0 ) {
117
- // No baseName, so this is ID is resolved relative
118
- // to baseUrl, pull off the leading dot.
119
- name = name . substring ( 2 ) ;
120
127
}
128
+ //end trimDots
129
+
130
+ name = name . join ( '/' ) ;
121
131
}
122
132
123
133
//Apply map config if available.
@@ -230,32 +240,39 @@ var requirejs, require, define;
230
240
return [ prefix , name ] ;
231
241
}
232
242
243
+ //Creates a parts array for a relName where first part is plugin ID,
244
+ //second part is resource ID. Assumes relName has already been normalized.
245
+ function makeRelParts ( relName ) {
246
+ return relName ? splitPrefix ( relName ) : [ ] ;
247
+ }
248
+
233
249
/**
234
250
* Makes a name map, normalizing the name, and using a plugin
235
251
* for normalization if necessary. Grabs a ref to plugin
236
252
* too, as an optimization.
237
253
*/
238
- makeMap = function ( name , relName ) {
254
+ makeMap = function ( name , relParts ) {
239
255
var plugin ,
240
256
parts = splitPrefix ( name ) ,
241
- prefix = parts [ 0 ] ;
257
+ prefix = parts [ 0 ] ,
258
+ relResourceName = relParts [ 1 ] ;
242
259
243
260
name = parts [ 1 ] ;
244
261
245
262
if ( prefix ) {
246
- prefix = normalize ( prefix , relName ) ;
263
+ prefix = normalize ( prefix , relResourceName ) ;
247
264
plugin = callDep ( prefix ) ;
248
265
}
249
266
250
267
//Normalize according
251
268
if ( prefix ) {
252
269
if ( plugin && plugin . normalize ) {
253
- name = plugin . normalize ( name , makeNormalize ( relName ) ) ;
270
+ name = plugin . normalize ( name , makeNormalize ( relResourceName ) ) ;
254
271
} else {
255
- name = normalize ( name , relName ) ;
272
+ name = normalize ( name , relResourceName ) ;
256
273
}
257
274
} else {
258
- name = normalize ( name , relName ) ;
275
+ name = normalize ( name , relResourceName ) ;
259
276
parts = splitPrefix ( name ) ;
260
277
prefix = parts [ 0 ] ;
261
278
name = parts [ 1 ] ;
@@ -302,13 +319,14 @@ var requirejs, require, define;
302
319
} ;
303
320
304
321
main = function ( name , deps , callback , relName ) {
305
- var cjsModule , depName , ret , map , i ,
322
+ var cjsModule , depName , ret , map , i , relParts ,
306
323
args = [ ] ,
307
324
callbackType = typeof callback ,
308
325
usingExports ;
309
326
310
327
//Use name if no relName
311
328
relName = relName || name ;
329
+ relParts = makeRelParts ( relName ) ;
312
330
313
331
//Call the callback to define the module, if necessary.
314
332
if ( callbackType === 'undefined' || callbackType === 'function' ) {
@@ -317,7 +335,7 @@ var requirejs, require, define;
317
335
//Default to [require, exports, module] if no deps
318
336
deps = ! deps . length && callback . length ? [ 'require' , 'exports' , 'module' ] : deps ;
319
337
for ( i = 0 ; i < deps . length ; i += 1 ) {
320
- map = makeMap ( deps [ i ] , relName ) ;
338
+ map = makeMap ( deps [ i ] , relParts ) ;
321
339
depName = map . f ;
322
340
323
341
//Fast path CommonJS standard dependencies.
@@ -373,7 +391,7 @@ var requirejs, require, define;
373
391
//deps arg is the module name, and second arg (if passed)
374
392
//is just the relName.
375
393
//Normalize module name, if it contains . or ..
376
- return callDep ( makeMap ( deps , callback ) . f ) ;
394
+ return callDep ( makeMap ( deps , makeRelParts ( callback ) ) . f ) ;
377
395
} else if ( ! deps . splice ) {
378
396
//deps is a config object, not an array.
379
397
config = deps ;
@@ -3191,7 +3209,7 @@ S2.define('select2/data/select',[
3191
3209
}
3192
3210
}
3193
3211
3194
- if ( data . id ) {
3212
+ if ( data . id !== undefined ) {
3195
3213
option . value = data . id ;
3196
3214
}
3197
3215
@@ -3550,7 +3568,10 @@ S2.define('select2/data/tags',[
3550
3568
} , true )
3551
3569
) ;
3552
3570
3553
- var checkText = option . text === params . term ;
3571
+ var optionText = ( option . text || '' ) . toUpperCase ( ) ;
3572
+ var paramsTerm = ( params . term || '' ) . toUpperCase ( ) ;
3573
+
3574
+ var checkText = optionText === paramsTerm ;
3554
3575
3555
3576
if ( checkText || checkChildren ) {
3556
3577
if ( child ) {
@@ -3941,7 +3962,7 @@ S2.define('select2/dropdown/search',[
3941
3962
} ) ;
3942
3963
3943
3964
container . on ( 'focus' , function ( ) {
3944
- if ( container . isOpen ( ) ) {
3965
+ if ( ! container . isOpen ( ) ) {
3945
3966
self . $search . focus ( ) ;
3946
3967
}
3947
3968
} ) ;
0 commit comments