1
0
mirror of synced 2025-02-16 20:13:16 +03:00

Move positioning into the components

The main container should not need to position the individual
components. This makes it easier for components to override where
they should be placed, such as adding the dropdown outside of the
container.
This commit is contained in:
Kevin Brown 2014-11-25 14:19:07 -05:00
parent be3414f6fe
commit 31c09315c8
10 changed files with 109 additions and 130 deletions

View File

@ -230,6 +230,11 @@ define('select2/results',[
this.$results.append($options);
};
Results.prototype.position = function ($results, $container) {
var $resultsContainer = $container.find('.select2-results');
$resultsContainer.append($results);
};
Results.prototype.sort = function (data) {
return data;
};
@ -724,6 +729,11 @@ define('select2/selection/base',[
$(document.body).off('mousedown.select2.' + container.id);
};
BaseSelection.prototype.position = function ($selection, $container) {
var $selectionContainer = $container.find('.selection');
$selectionContainer.append($selection);
};
BaseSelection.prototype.destroy = function () {
// Unbind the dropdown click handler if it exists
$(document.body).off('.select2.' + this.container.id);
@ -2575,6 +2585,11 @@ define('select2/dropdown',[
return $dropdown;
};
Dropdown.prototype.position = function ($dropdown, $container) {
var $dropdownContainer = $container.find('.dropdown-wrapper');
$dropdownContainer.append($dropdown);
};
Dropdown.prototype.destroy = function () {
// Remove the dropdown from the DOM
this.$dropdown.remove();
@ -3135,24 +3150,22 @@ define('select2/core',[
var SelectionAdapter = this.options.get('selectionAdapter');
this.selection = new SelectionAdapter($element, this.options);
this.$selection = this.selection.render();
var $selection = this.selection.render();
this._placeSelection($selection);
this.selection.position(this.$selection, $container);
var DropdownAdapter = this.options.get('dropdownAdapter');
this.dropdown = new DropdownAdapter($element, this.options);
this.$dropdown = this.dropdown.render();
var $dropdown = this.dropdown.render();
this._placeDropdown($dropdown);
this.dropdown.position(this.$dropdown, $container);
var ResultsAdapter = this.options.get('resultsAdapter');
this.results = new ResultsAdapter($element, this.options, this.data);
var $results = this.results.render();
this.$results = this.results.render();
this._placeResults($results);
this.results.position(this.$results, $container);
// Bind events
@ -3213,23 +3226,6 @@ define('select2/core',[
$container.width(this.$element.outerWidth(false));
};
Select2.prototype._placeSelection = function ($selection) {
var $selectionContainer = this.$container.find('.selection');
$selectionContainer.append($selection);
};
Select2.prototype._placeDropdown = function ($dropdown) {
this.$dropdown = $dropdown;
var $dropdownContainer = this.$container.find('.dropdown-wrapper');
$dropdownContainer.append($dropdown);
};
Select2.prototype._placeResults = function ($results) {
var $resultsContainer = this.$dropdown.find('.select2-results');
$resultsContainer.append($results);
};
Select2.prototype._bindAdapters = function () {
this.data.bind(this, this.$container);
this.selection.bind(this, this.$container);

View File

@ -230,6 +230,11 @@ define('select2/results',[
this.$results.append($options);
};
Results.prototype.position = function ($results, $container) {
var $resultsContainer = $container.find('.select2-results');
$resultsContainer.append($results);
};
Results.prototype.sort = function (data) {
return data;
};
@ -724,6 +729,11 @@ define('select2/selection/base',[
$(document.body).off('mousedown.select2.' + container.id);
};
BaseSelection.prototype.position = function ($selection, $container) {
var $selectionContainer = $container.find('.selection');
$selectionContainer.append($selection);
};
BaseSelection.prototype.destroy = function () {
// Unbind the dropdown click handler if it exists
$(document.body).off('.select2.' + this.container.id);
@ -2575,6 +2585,11 @@ define('select2/dropdown',[
return $dropdown;
};
Dropdown.prototype.position = function ($dropdown, $container) {
var $dropdownContainer = $container.find('.dropdown-wrapper');
$dropdownContainer.append($dropdown);
};
Dropdown.prototype.destroy = function () {
// Remove the dropdown from the DOM
this.$dropdown.remove();
@ -3135,24 +3150,22 @@ define('select2/core',[
var SelectionAdapter = this.options.get('selectionAdapter');
this.selection = new SelectionAdapter($element, this.options);
this.$selection = this.selection.render();
var $selection = this.selection.render();
this._placeSelection($selection);
this.selection.position(this.$selection, $container);
var DropdownAdapter = this.options.get('dropdownAdapter');
this.dropdown = new DropdownAdapter($element, this.options);
this.$dropdown = this.dropdown.render();
var $dropdown = this.dropdown.render();
this._placeDropdown($dropdown);
this.dropdown.position(this.$dropdown, $container);
var ResultsAdapter = this.options.get('resultsAdapter');
this.results = new ResultsAdapter($element, this.options, this.data);
var $results = this.results.render();
this.$results = this.results.render();
this._placeResults($results);
this.results.position(this.$results, $container);
// Bind events
@ -3213,23 +3226,6 @@ define('select2/core',[
$container.width(this.$element.outerWidth(false));
};
Select2.prototype._placeSelection = function ($selection) {
var $selectionContainer = this.$container.find('.selection');
$selectionContainer.append($selection);
};
Select2.prototype._placeDropdown = function ($dropdown) {
this.$dropdown = $dropdown;
var $dropdownContainer = this.$container.find('.dropdown-wrapper');
$dropdownContainer.append($dropdown);
};
Select2.prototype._placeResults = function ($results) {
var $resultsContainer = this.$dropdown.find('.select2-results');
$resultsContainer.append($results);
};
Select2.prototype._bindAdapters = function () {
this.data.bind(this, this.$container);
this.selection.bind(this, this.$container);

View File

@ -9765,6 +9765,11 @@ define('select2/results',[
this.$results.append($options);
};
Results.prototype.position = function ($results, $container) {
var $resultsContainer = $container.find('.select2-results');
$resultsContainer.append($results);
};
Results.prototype.sort = function (data) {
return data;
};
@ -10259,6 +10264,11 @@ define('select2/selection/base',[
$(document.body).off('mousedown.select2.' + container.id);
};
BaseSelection.prototype.position = function ($selection, $container) {
var $selectionContainer = $container.find('.selection');
$selectionContainer.append($selection);
};
BaseSelection.prototype.destroy = function () {
// Unbind the dropdown click handler if it exists
$(document.body).off('.select2.' + this.container.id);
@ -12110,6 +12120,11 @@ define('select2/dropdown',[
return $dropdown;
};
Dropdown.prototype.position = function ($dropdown, $container) {
var $dropdownContainer = $container.find('.dropdown-wrapper');
$dropdownContainer.append($dropdown);
};
Dropdown.prototype.destroy = function () {
// Remove the dropdown from the DOM
this.$dropdown.remove();
@ -12670,24 +12685,22 @@ define('select2/core',[
var SelectionAdapter = this.options.get('selectionAdapter');
this.selection = new SelectionAdapter($element, this.options);
this.$selection = this.selection.render();
var $selection = this.selection.render();
this._placeSelection($selection);
this.selection.position(this.$selection, $container);
var DropdownAdapter = this.options.get('dropdownAdapter');
this.dropdown = new DropdownAdapter($element, this.options);
this.$dropdown = this.dropdown.render();
var $dropdown = this.dropdown.render();
this._placeDropdown($dropdown);
this.dropdown.position(this.$dropdown, $container);
var ResultsAdapter = this.options.get('resultsAdapter');
this.results = new ResultsAdapter($element, this.options, this.data);
var $results = this.results.render();
this.$results = this.results.render();
this._placeResults($results);
this.results.position(this.$results, $container);
// Bind events
@ -12748,23 +12761,6 @@ define('select2/core',[
$container.width(this.$element.outerWidth(false));
};
Select2.prototype._placeSelection = function ($selection) {
var $selectionContainer = this.$container.find('.selection');
$selectionContainer.append($selection);
};
Select2.prototype._placeDropdown = function ($dropdown) {
this.$dropdown = $dropdown;
var $dropdownContainer = this.$container.find('.dropdown-wrapper');
$dropdownContainer.append($dropdown);
};
Select2.prototype._placeResults = function ($results) {
var $resultsContainer = this.$dropdown.find('.select2-results');
$resultsContainer.append($results);
};
Select2.prototype._bindAdapters = function () {
this.data.bind(this, this.$container);
this.selection.bind(this, this.$container);

File diff suppressed because one or more lines are too long

46
dist/js/select2.js vendored
View File

@ -658,6 +658,11 @@ define('select2/results',[
this.$results.append($options);
};
Results.prototype.position = function ($results, $container) {
var $resultsContainer = $container.find('.select2-results');
$resultsContainer.append($results);
};
Results.prototype.sort = function (data) {
return data;
};
@ -1152,6 +1157,11 @@ define('select2/selection/base',[
$(document.body).off('mousedown.select2.' + container.id);
};
BaseSelection.prototype.position = function ($selection, $container) {
var $selectionContainer = $container.find('.selection');
$selectionContainer.append($selection);
};
BaseSelection.prototype.destroy = function () {
// Unbind the dropdown click handler if it exists
$(document.body).off('.select2.' + this.container.id);
@ -3003,6 +3013,11 @@ define('select2/dropdown',[
return $dropdown;
};
Dropdown.prototype.position = function ($dropdown, $container) {
var $dropdownContainer = $container.find('.dropdown-wrapper');
$dropdownContainer.append($dropdown);
};
Dropdown.prototype.destroy = function () {
// Remove the dropdown from the DOM
this.$dropdown.remove();
@ -3563,24 +3578,22 @@ define('select2/core',[
var SelectionAdapter = this.options.get('selectionAdapter');
this.selection = new SelectionAdapter($element, this.options);
this.$selection = this.selection.render();
var $selection = this.selection.render();
this._placeSelection($selection);
this.selection.position(this.$selection, $container);
var DropdownAdapter = this.options.get('dropdownAdapter');
this.dropdown = new DropdownAdapter($element, this.options);
this.$dropdown = this.dropdown.render();
var $dropdown = this.dropdown.render();
this._placeDropdown($dropdown);
this.dropdown.position(this.$dropdown, $container);
var ResultsAdapter = this.options.get('resultsAdapter');
this.results = new ResultsAdapter($element, this.options, this.data);
var $results = this.results.render();
this.$results = this.results.render();
this._placeResults($results);
this.results.position(this.$results, $container);
// Bind events
@ -3641,23 +3654,6 @@ define('select2/core',[
$container.width(this.$element.outerWidth(false));
};
Select2.prototype._placeSelection = function ($selection) {
var $selectionContainer = this.$container.find('.selection');
$selectionContainer.append($selection);
};
Select2.prototype._placeDropdown = function ($dropdown) {
this.$dropdown = $dropdown;
var $dropdownContainer = this.$container.find('.dropdown-wrapper');
$dropdownContainer.append($dropdown);
};
Select2.prototype._placeResults = function ($results) {
var $resultsContainer = this.$dropdown.find('.select2-results');
$resultsContainer.append($results);
};
Select2.prototype._bindAdapters = function () {
this.data.bind(this, this.$container);
this.selection.bind(this, this.$container);

File diff suppressed because one or more lines are too long

View File

@ -30,24 +30,21 @@ define([
var SelectionAdapter = this.options.get('selectionAdapter');
this.selection = new SelectionAdapter($element, this.options);
this.$selection = this.selection.render();
var $selection = this.selection.render();
this._placeSelection($selection);
this.selection.position(this.$selection, $container);
var DropdownAdapter = this.options.get('dropdownAdapter');
this.dropdown = new DropdownAdapter($element, this.options);
this.$dropdown = this.dropdown.render();
var $dropdown = this.dropdown.render();
this._placeDropdown($dropdown);
this.dropdown.position(this.$dropdown, $container);
var ResultsAdapter = this.options.get('resultsAdapter');
this.results = new ResultsAdapter($element, this.options, this.data);
this.$results = this.results.render();
var $results = this.results.render();
this._placeResults($results);
this.results.position(this.$results, $container);
// Bind events
@ -108,23 +105,6 @@ define([
$container.width(this.$element.outerWidth(false));
};
Select2.prototype._placeSelection = function ($selection) {
var $selectionContainer = this.$container.find('.selection');
$selectionContainer.append($selection);
};
Select2.prototype._placeDropdown = function ($dropdown) {
this.$dropdown = $dropdown;
var $dropdownContainer = this.$container.find('.dropdown-wrapper');
$dropdownContainer.append($dropdown);
};
Select2.prototype._placeResults = function ($results) {
var $resultsContainer = this.$dropdown.find('.select2-results');
$resultsContainer.append($results);
};
Select2.prototype._bindAdapters = function () {
this.data.bind(this, this.$container);
this.selection.bind(this, this.$container);

View File

@ -19,6 +19,11 @@ define([
return $dropdown;
};
Dropdown.prototype.position = function ($dropdown, $container) {
var $dropdownContainer = $container.find('.dropdown-wrapper');
$dropdownContainer.append($dropdown);
};
Dropdown.prototype.destroy = function () {
// Remove the dropdown from the DOM
this.$dropdown.remove();

View File

@ -72,6 +72,11 @@ define([
this.$results.append($options);
};
Results.prototype.position = function ($results, $container) {
var $resultsContainer = $container.find('.select2-results');
$resultsContainer.append($results);
};
Results.prototype.sort = function (data) {
return data;
};

View File

@ -85,6 +85,11 @@ define([
$(document.body).off('mousedown.select2.' + container.id);
};
BaseSelection.prototype.position = function ($selection, $container) {
var $selectionContainer = $container.find('.selection');
$selectionContainer.append($selection);
};
BaseSelection.prototype.destroy = function () {
// Unbind the dropdown click handler if it exists
$(document.body).off('.select2.' + this.container.id);