Skip to content

Commit 86b4a5d

Browse files
committed
Added amdBase and amdLanguageBase options
This should allow those using their own build systems to automatically load in translations. In the future, the `amdBase` option may be used to optionally load some components of Select2. As Select2 cannot know what the base directory is, it currently has to load in all of the optional components in the default build. By allowing users to set their own base, it will allow us to know the base to load files from, which makes it easier to use the `require` function to optionally load them. This fixes select2#2899.
1 parent 584d3b4 commit 86b4a5d

8 files changed

Lines changed: 23 additions & 13 deletions

File tree

dist/js/select2.amd.full.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3570,7 +3570,7 @@ define('select2/defaults',[
35703570
language = Translation.loadPath(name);
35713571
} catch (e) {
35723572
// If we couldn't load it, check if it wasn't the full path
3573-
name = 'select2/i18n/' + name;
3573+
name = this.get('amdTranslationBase') + name;
35743574
language = Translation.loadPath(name);
35753575
}
35763576

@@ -3641,6 +3641,8 @@ define('select2/defaults',[
36413641
}
36423642

36433643
this.defaults = {
3644+
amdBase: 'select2/',
3645+
amdLanguageBase: 'select2/i18n/',
36443646
language: EnglishTranslation,
36453647
matcher: matcher,
36463648
minimumInputLength: 0,
@@ -4538,7 +4540,7 @@ define('select2/dropdown/attachContainer',[
45384540

45394541
define('jquery.select2',[
45404542
'jquery',
4541-
'select2/core'
4543+
'./select2/core'
45424544
], function ($, Select2) {
45434545
// Force jQuery.mousewheel to be loaded if it hasn't already
45444546
try {

dist/js/select2.amd.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3570,7 +3570,7 @@ define('select2/defaults',[
35703570
language = Translation.loadPath(name);
35713571
} catch (e) {
35723572
// If we couldn't load it, check if it wasn't the full path
3573-
name = 'select2/i18n/' + name;
3573+
name = this.get('amdTranslationBase') + name;
35743574
language = Translation.loadPath(name);
35753575
}
35763576

@@ -3641,6 +3641,8 @@ define('select2/defaults',[
36413641
}
36423642

36433643
this.defaults = {
3644+
amdBase: 'select2/',
3645+
amdLanguageBase: 'select2/i18n/',
36443646
language: EnglishTranslation,
36453647
matcher: matcher,
36463648
minimumInputLength: 0,
@@ -4254,7 +4256,7 @@ define('select2/core',[
42544256

42554257
define('jquery.select2',[
42564258
'jquery',
4257-
'select2/core'
4259+
'./select2/core'
42584260
], function ($, Select2) {
42594261
// Force jQuery.mousewheel to be loaded if it hasn't already
42604262
try {

dist/js/select2.full.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13105,7 +13105,7 @@ define('select2/defaults',[
1310513105
language = Translation.loadPath(name);
1310613106
} catch (e) {
1310713107
// If we couldn't load it, check if it wasn't the full path
13108-
name = 'select2/i18n/' + name;
13108+
name = this.get('amdTranslationBase') + name;
1310913109
language = Translation.loadPath(name);
1311013110
}
1311113111

@@ -13176,6 +13176,8 @@ define('select2/defaults',[
1317613176
}
1317713177

1317813178
this.defaults = {
13179+
amdBase: 'select2/',
13180+
amdLanguageBase: 'select2/i18n/',
1317913181
language: EnglishTranslation,
1318013182
matcher: matcher,
1318113183
minimumInputLength: 0,
@@ -14073,7 +14075,7 @@ define('select2/dropdown/attachContainer',[
1407314075

1407414076
define('jquery.select2',[
1407514077
'jquery',
14076-
'select2/core'
14078+
'./select2/core'
1407714079
], function ($, Select2) {
1407814080
// Force jQuery.mousewheel to be loaded if it hasn't already
1407914081
try {

dist/js/select2.full.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/select2.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3998,7 +3998,7 @@ define('select2/defaults',[
39983998
language = Translation.loadPath(name);
39993999
} catch (e) {
40004000
// If we couldn't load it, check if it wasn't the full path
4001-
name = 'select2/i18n/' + name;
4001+
name = this.get('amdTranslationBase') + name;
40024002
language = Translation.loadPath(name);
40034003
}
40044004

@@ -4069,6 +4069,8 @@ define('select2/defaults',[
40694069
}
40704070

40714071
this.defaults = {
4072+
amdBase: 'select2/',
4073+
amdLanguageBase: 'select2/i18n/',
40724074
language: EnglishTranslation,
40734075
matcher: matcher,
40744076
minimumInputLength: 0,
@@ -4682,7 +4684,7 @@ define('select2/core',[
46824684

46834685
define('jquery.select2',[
46844686
'jquery',
4685-
'select2/core'
4687+
'./select2/core'
46864688
], function ($, Select2) {
46874689
// Force jQuery.mousewheel to be loaded if it hasn't already
46884690
try {

dist/js/select2.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/js/jquery.select2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
define([
22
'jquery',
3-
'select2/core'
3+
'./select2/core'
44
], function ($, Select2) {
55
// Force jQuery.mousewheel to be loaded if it hasn't already
66
try {

src/js/select2/defaults.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ define([
187187
language = Translation.loadPath(name);
188188
} catch (e) {
189189
// If we couldn't load it, check if it wasn't the full path
190-
name = 'select2/i18n/' + name;
190+
name = this.get('amdTranslationBase') + name;
191191
language = Translation.loadPath(name);
192192
}
193193

@@ -258,6 +258,8 @@ define([
258258
}
259259

260260
this.defaults = {
261+
amdBase: 'select2/',
262+
amdLanguageBase: 'select2/i18n/',
261263
language: EnglishTranslation,
262264
matcher: matcher,
263265
minimumInputLength: 0,

0 commit comments

Comments
 (0)