1
0
mirror of synced 2024-11-29 16:16:02 +03:00

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.
This commit is contained in:
Kevin Brown 2014-12-09 22:12:07 -05:00
parent f7d75b62fa
commit f6625d2347
10 changed files with 31 additions and 21 deletions

View File

@ -742,7 +742,7 @@ define('select2/selection/base',[
}; };
BaseSelection.prototype.destroy = function () { BaseSelection.prototype.destroy = function () {
this._detachCloseHandler(); this._detachCloseHandler(this.container);
}; };
BaseSelection.prototype.update = function (data) { BaseSelection.prototype.update = function (data) {
@ -2851,6 +2851,8 @@ define('select2/dropdown/attachBody',[
], function () { ], function () {
function AttachBody (decorated, $element, options) { function AttachBody (decorated, $element, options) {
this.$dropdownParent = options.get('dropdownParent') || document.body;
decorated.call(this, $element, options); decorated.call(this, $element, options);
} }
@ -2981,7 +2983,7 @@ define('select2/dropdown/attachBody',[
}; };
AttachBody.prototype._showDropdown = function (decorated) { AttachBody.prototype._showDropdown = function (decorated) {
this.$dropdownContainer.appendTo(document.body); this.$dropdownContainer.appendTo(this.$dropdownParent);
this._positionDropdown(); this._positionDropdown();
}; };
@ -3323,7 +3325,7 @@ define('select2/core',[
], function ($, Options, Utils, KEYS) { ], function ($, Options, Utils, KEYS) {
var Select2 = function ($element, options) { var Select2 = function ($element, options) {
if ($element.data('select2') != null) { if ($element.data('select2') != null) {
$element.select2('destroy'); $element.data('select2').destroy();
} }
this.$element = $element; this.$element = $element;

View File

@ -742,7 +742,7 @@ define('select2/selection/base',[
}; };
BaseSelection.prototype.destroy = function () { BaseSelection.prototype.destroy = function () {
this._detachCloseHandler(); this._detachCloseHandler(this.container);
}; };
BaseSelection.prototype.update = function (data) { BaseSelection.prototype.update = function (data) {
@ -2851,6 +2851,8 @@ define('select2/dropdown/attachBody',[
], function () { ], function () {
function AttachBody (decorated, $element, options) { function AttachBody (decorated, $element, options) {
this.$dropdownParent = options.get('dropdownParent') || document.body;
decorated.call(this, $element, options); decorated.call(this, $element, options);
} }
@ -2981,7 +2983,7 @@ define('select2/dropdown/attachBody',[
}; };
AttachBody.prototype._showDropdown = function (decorated) { AttachBody.prototype._showDropdown = function (decorated) {
this.$dropdownContainer.appendTo(document.body); this.$dropdownContainer.appendTo(this.$dropdownParent);
this._positionDropdown(); this._positionDropdown();
}; };
@ -3323,7 +3325,7 @@ define('select2/core',[
], function ($, Options, Utils, KEYS) { ], function ($, Options, Utils, KEYS) {
var Select2 = function ($element, options) { var Select2 = function ($element, options) {
if ($element.data('select2') != null) { if ($element.data('select2') != null) {
$element.select2('destroy'); $element.data('select2').destroy();
} }
this.$element = $element; this.$element = $element;

View File

@ -10277,7 +10277,7 @@ define('select2/selection/base',[
}; };
BaseSelection.prototype.destroy = function () { BaseSelection.prototype.destroy = function () {
this._detachCloseHandler(); this._detachCloseHandler(this.container);
}; };
BaseSelection.prototype.update = function (data) { BaseSelection.prototype.update = function (data) {
@ -12386,6 +12386,8 @@ define('select2/dropdown/attachBody',[
], function () { ], function () {
function AttachBody (decorated, $element, options) { function AttachBody (decorated, $element, options) {
this.$dropdownParent = options.get('dropdownParent') || document.body;
decorated.call(this, $element, options); decorated.call(this, $element, options);
} }
@ -12516,7 +12518,7 @@ define('select2/dropdown/attachBody',[
}; };
AttachBody.prototype._showDropdown = function (decorated) { AttachBody.prototype._showDropdown = function (decorated) {
this.$dropdownContainer.appendTo(document.body); this.$dropdownContainer.appendTo(this.$dropdownParent);
this._positionDropdown(); this._positionDropdown();
}; };
@ -12858,7 +12860,7 @@ define('select2/core',[
], function ($, Options, Utils, KEYS) { ], function ($, Options, Utils, KEYS) {
var Select2 = function ($element, options) { var Select2 = function ($element, options) {
if ($element.data('select2') != null) { if ($element.data('select2') != null) {
$element.select2('destroy'); $element.data('select2').destroy();
} }
this.$element = $element; this.$element = $element;

File diff suppressed because one or more lines are too long

8
dist/js/select2.js vendored
View File

@ -1170,7 +1170,7 @@ define('select2/selection/base',[
}; };
BaseSelection.prototype.destroy = function () { BaseSelection.prototype.destroy = function () {
this._detachCloseHandler(); this._detachCloseHandler(this.container);
}; };
BaseSelection.prototype.update = function (data) { BaseSelection.prototype.update = function (data) {
@ -3279,6 +3279,8 @@ define('select2/dropdown/attachBody',[
], function () { ], function () {
function AttachBody (decorated, $element, options) { function AttachBody (decorated, $element, options) {
this.$dropdownParent = options.get('dropdownParent') || document.body;
decorated.call(this, $element, options); decorated.call(this, $element, options);
} }
@ -3409,7 +3411,7 @@ define('select2/dropdown/attachBody',[
}; };
AttachBody.prototype._showDropdown = function (decorated) { AttachBody.prototype._showDropdown = function (decorated) {
this.$dropdownContainer.appendTo(document.body); this.$dropdownContainer.appendTo(this.$dropdownParent);
this._positionDropdown(); this._positionDropdown();
}; };
@ -3751,7 +3753,7 @@ define('select2/core',[
], function ($, Options, Utils, KEYS) { ], function ($, Options, Utils, KEYS) {
var Select2 = function ($element, options) { var Select2 = function ($element, options) {
if ($element.data('select2') != null) { if ($element.data('select2') != null) {
$element.select2('destroy'); $element.data('select2').destroy();
} }
this.$element = $element; this.$element = $element;

File diff suppressed because one or more lines are too long

View File

@ -467,7 +467,7 @@ ajax: {
<dd><code>dropdownParent</code></dd> <dd><code>dropdownParent</code></dd>
<dt>Value</dt> <dt>Value</dt>
<dd>jQuery element</dd> <dd>jQuery element or DOM node</dd>
<hr /> <hr />

View File

@ -6,7 +6,7 @@ define([
], function ($, Options, Utils, KEYS) { ], function ($, Options, Utils, KEYS) {
var Select2 = function ($element, options) { var Select2 = function ($element, options) {
if ($element.data('select2') != null) { if ($element.data('select2') != null) {
$element.select2('destroy'); $element.data('select2').destroy();
} }
this.$element = $element; this.$element = $element;

View File

@ -2,6 +2,8 @@ define([
], function () { ], function () {
function AttachBody (decorated, $element, options) { function AttachBody (decorated, $element, options) {
this.$dropdownParent = options.get('dropdownParent') || document.body;
decorated.call(this, $element, options); decorated.call(this, $element, options);
} }
@ -132,7 +134,7 @@ define([
}; };
AttachBody.prototype._showDropdown = function (decorated) { AttachBody.prototype._showDropdown = function (decorated) {
this.$dropdownContainer.appendTo(document.body); this.$dropdownContainer.appendTo(this.$dropdownParent);
this._positionDropdown(); this._positionDropdown();
}; };

View File

@ -98,7 +98,7 @@ define([
}; };
BaseSelection.prototype.destroy = function () { BaseSelection.prototype.destroy = function () {
this._detachCloseHandler(); this._detachCloseHandler(this.container);
}; };
BaseSelection.prototype.update = function (data) { BaseSelection.prototype.update = function (data) {