Skip to content

Commit f6625d2

Browse files
committed
Added dropdownParent
`dropdownParent` controls the location of the dropdown when it is automatically added to the DOM. By default, this is the body element but it can be modified based on where the user needs it.
1 parent f7d75b6 commit f6625d2

10 files changed

Lines changed: 31 additions & 21 deletions

File tree

dist/js/select2.amd.full.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ define('select2/selection/base',[
742742
};
743743

744744
BaseSelection.prototype.destroy = function () {
745-
this._detachCloseHandler();
745+
this._detachCloseHandler(this.container);
746746
};
747747

748748
BaseSelection.prototype.update = function (data) {
@@ -2851,6 +2851,8 @@ define('select2/dropdown/attachBody',[
28512851

28522852
], function () {
28532853
function AttachBody (decorated, $element, options) {
2854+
this.$dropdownParent = options.get('dropdownParent') || document.body;
2855+
28542856
decorated.call(this, $element, options);
28552857
}
28562858

@@ -2981,7 +2983,7 @@ define('select2/dropdown/attachBody',[
29812983
};
29822984

29832985
AttachBody.prototype._showDropdown = function (decorated) {
2984-
this.$dropdownContainer.appendTo(document.body);
2986+
this.$dropdownContainer.appendTo(this.$dropdownParent);
29852987

29862988
this._positionDropdown();
29872989
};
@@ -3323,7 +3325,7 @@ define('select2/core',[
33233325
], function ($, Options, Utils, KEYS) {
33243326
var Select2 = function ($element, options) {
33253327
if ($element.data('select2') != null) {
3326-
$element.select2('destroy');
3328+
$element.data('select2').destroy();
33273329
}
33283330

33293331
this.$element = $element;

dist/js/select2.amd.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ define('select2/selection/base',[
742742
};
743743

744744
BaseSelection.prototype.destroy = function () {
745-
this._detachCloseHandler();
745+
this._detachCloseHandler(this.container);
746746
};
747747

748748
BaseSelection.prototype.update = function (data) {
@@ -2851,6 +2851,8 @@ define('select2/dropdown/attachBody',[
28512851

28522852
], function () {
28532853
function AttachBody (decorated, $element, options) {
2854+
this.$dropdownParent = options.get('dropdownParent') || document.body;
2855+
28542856
decorated.call(this, $element, options);
28552857
}
28562858

@@ -2981,7 +2983,7 @@ define('select2/dropdown/attachBody',[
29812983
};
29822984

29832985
AttachBody.prototype._showDropdown = function (decorated) {
2984-
this.$dropdownContainer.appendTo(document.body);
2986+
this.$dropdownContainer.appendTo(this.$dropdownParent);
29852987

29862988
this._positionDropdown();
29872989
};
@@ -3323,7 +3325,7 @@ define('select2/core',[
33233325
], function ($, Options, Utils, KEYS) {
33243326
var Select2 = function ($element, options) {
33253327
if ($element.data('select2') != null) {
3326-
$element.select2('destroy');
3328+
$element.data('select2').destroy();
33273329
}
33283330

33293331
this.$element = $element;

dist/js/select2.full.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10277,7 +10277,7 @@ define('select2/selection/base',[
1027710277
};
1027810278

1027910279
BaseSelection.prototype.destroy = function () {
10280-
this._detachCloseHandler();
10280+
this._detachCloseHandler(this.container);
1028110281
};
1028210282

1028310283
BaseSelection.prototype.update = function (data) {
@@ -12386,6 +12386,8 @@ define('select2/dropdown/attachBody',[
1238612386

1238712387
], function () {
1238812388
function AttachBody (decorated, $element, options) {
12389+
this.$dropdownParent = options.get('dropdownParent') || document.body;
12390+
1238912391
decorated.call(this, $element, options);
1239012392
}
1239112393

@@ -12516,7 +12518,7 @@ define('select2/dropdown/attachBody',[
1251612518
};
1251712519

1251812520
AttachBody.prototype._showDropdown = function (decorated) {
12519-
this.$dropdownContainer.appendTo(document.body);
12521+
this.$dropdownContainer.appendTo(this.$dropdownParent);
1252012522

1252112523
this._positionDropdown();
1252212524
};
@@ -12858,7 +12860,7 @@ define('select2/core',[
1285812860
], function ($, Options, Utils, KEYS) {
1285912861
var Select2 = function ($element, options) {
1286012862
if ($element.data('select2') != null) {
12861-
$element.select2('destroy');
12863+
$element.data('select2').destroy();
1286212864
}
1286312865

1286412866
this.$element = $element;

dist/js/select2.full.min.js

Lines changed: 3 additions & 3 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: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ define('select2/selection/base',[
11701170
};
11711171

11721172
BaseSelection.prototype.destroy = function () {
1173-
this._detachCloseHandler();
1173+
this._detachCloseHandler(this.container);
11741174
};
11751175

11761176
BaseSelection.prototype.update = function (data) {
@@ -3279,6 +3279,8 @@ define('select2/dropdown/attachBody',[
32793279

32803280
], function () {
32813281
function AttachBody (decorated, $element, options) {
3282+
this.$dropdownParent = options.get('dropdownParent') || document.body;
3283+
32823284
decorated.call(this, $element, options);
32833285
}
32843286

@@ -3409,7 +3411,7 @@ define('select2/dropdown/attachBody',[
34093411
};
34103412

34113413
AttachBody.prototype._showDropdown = function (decorated) {
3412-
this.$dropdownContainer.appendTo(document.body);
3414+
this.$dropdownContainer.appendTo(this.$dropdownParent);
34133415

34143416
this._positionDropdown();
34153417
};
@@ -3751,7 +3753,7 @@ define('select2/core',[
37513753
], function ($, Options, Utils, KEYS) {
37523754
var Select2 = function ($element, options) {
37533755
if ($element.data('select2') != null) {
3754-
$element.select2('destroy');
3756+
$element.data('select2').destroy();
37553757
}
37563758

37573759
this.$element = $element;

dist/js/select2.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.

docs/options.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ <h2 id="dropdownParent">
467467
<dd><code>dropdownParent</code></dd>
468468

469469
<dt>Value</dt>
470-
<dd>jQuery element</dd>
470+
<dd>jQuery element or DOM node</dd>
471471

472472
<hr />
473473

src/js/select2/core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ define([
66
], function ($, Options, Utils, KEYS) {
77
var Select2 = function ($element, options) {
88
if ($element.data('select2') != null) {
9-
$element.select2('destroy');
9+
$element.data('select2').destroy();
1010
}
1111

1212
this.$element = $element;

src/js/select2/dropdown/attachBody.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ define([
22

33
], function () {
44
function AttachBody (decorated, $element, options) {
5+
this.$dropdownParent = options.get('dropdownParent') || document.body;
6+
57
decorated.call(this, $element, options);
68
}
79

@@ -132,7 +134,7 @@ define([
132134
};
133135

134136
AttachBody.prototype._showDropdown = function (decorated) {
135-
this.$dropdownContainer.appendTo(document.body);
137+
this.$dropdownContainer.appendTo(this.$dropdownParent);
136138

137139
this._positionDropdown();
138140
};

src/js/select2/selection/base.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ define([
9898
};
9999

100100
BaseSelection.prototype.destroy = function () {
101-
this._detachCloseHandler();
101+
this._detachCloseHandler(this.container);
102102
};
103103

104104
BaseSelection.prototype.update = function (data) {

0 commit comments

Comments
 (0)