|
@@ -9891,6 +9891,10 @@ define('select2/selection/single',[
|
|
return data.text;
|
|
return data.text;
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ SingleSelection.prototype.selectionContainer = function () {
|
|
|
|
+ return $('<span></span>');
|
|
|
|
+ };
|
|
|
|
+
|
|
SingleSelection.prototype.update = function (data) {
|
|
SingleSelection.prototype.update = function (data) {
|
|
if (data.length === 0) {
|
|
if (data.length === 0) {
|
|
this.clear();
|
|
this.clear();
|
|
@@ -9953,6 +9957,10 @@ define('select2/selection/multiple',[
|
|
return data.text;
|
|
return data.text;
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ MultipleSelection.prototype.selectionContainer = function () {
|
|
|
|
+ return $('<li class="choice"></li>');
|
|
|
|
+ };
|
|
|
|
+
|
|
MultipleSelection.prototype.update = function (data) {
|
|
MultipleSelection.prototype.update = function (data) {
|
|
this.clear();
|
|
this.clear();
|
|
|
|
|
|
@@ -9967,7 +9975,7 @@ define('select2/selection/multiple',[
|
|
|
|
|
|
var formatted = this.display(selection);
|
|
var formatted = this.display(selection);
|
|
|
|
|
|
- var $selection = $('<ul class="choice"></ul>');
|
|
|
|
|
|
+ var $selection = this.selectionContainer();
|
|
|
|
|
|
$selection.text(formatted);
|
|
$selection.text(formatted);
|
|
$selection.data('data', data);
|
|
$selection.data('data', data);
|
|
@@ -9981,6 +9989,49 @@ define('select2/selection/multiple',[
|
|
return MultipleSelection;
|
|
return MultipleSelection;
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+define('select2/selection/placeholder',[
|
|
|
|
+ '../utils'
|
|
|
|
+], function (Utils) {
|
|
|
|
+ function Placeholder (decorated, $element, options) {
|
|
|
|
+ this.placeholder = this.normalizePlaceholder(options.get('placeholder'));
|
|
|
|
+
|
|
|
|
+ decorated.call(this, $element, options);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Placeholder.prototype.normalizePlaceholder = function (_, placeholder) {
|
|
|
|
+ if (typeof placeholder === 'string') {
|
|
|
|
+ placeholder = {
|
|
|
|
+ id: '',
|
|
|
|
+ text: placeholder
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return placeholder;
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ Placeholder.prototype.update = function (decorated, data) {
|
|
|
|
+ var singlePlaceholder = (
|
|
|
|
+ data.length == 1 && data[0].id != this.placeholder.id
|
|
|
|
+ );
|
|
|
|
+ var multipleSelections = data.length > 1;
|
|
|
|
+
|
|
|
|
+ if (multipleSelections || singlePlaceholder) {
|
|
|
|
+ return decorated.call(this, data);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.clear();
|
|
|
|
+
|
|
|
|
+ var $placeholder = this.selectionContainer();
|
|
|
|
+
|
|
|
|
+ $placeholder.html(this.display(this.placeholder));
|
|
|
|
+ $placeholder.addClass('placeholder').removeClass('choice');
|
|
|
|
+
|
|
|
|
+ this.$selection.find('.rendered-selection').append($placeholder);
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ return Placeholder;
|
|
|
|
+});
|
|
|
|
+
|
|
define('select2/data/base',[
|
|
define('select2/data/base',[
|
|
'../utils'
|
|
'../utils'
|
|
], function (Utils) {
|
|
], function (Utils) {
|
|
@@ -10378,6 +10429,7 @@ define('select2/defaults',[
|
|
|
|
|
|
'./selection/single',
|
|
'./selection/single',
|
|
'./selection/multiple',
|
|
'./selection/multiple',
|
|
|
|
+ './selection/placeholder',
|
|
|
|
|
|
'./utils',
|
|
'./utils',
|
|
|
|
|
|
@@ -10387,7 +10439,9 @@ define('select2/defaults',[
|
|
|
|
|
|
'./dropdown',
|
|
'./dropdown',
|
|
'./dropdown/search'
|
|
'./dropdown/search'
|
|
-], function (ResultsList, SingleSelection, MultipleSelection, Utils,
|
|
|
|
|
|
+], function (ResultsList,
|
|
|
|
+ SingleSelection, MultipleSelection, Placeholder,
|
|
|
|
+ Utils,
|
|
SelectData, ArrayData, AjaxData,
|
|
SelectData, ArrayData, AjaxData,
|
|
Dropdown, Search) {
|
|
Dropdown, Search) {
|
|
function Defaults () {
|
|
function Defaults () {
|
|
@@ -10423,6 +10477,14 @@ define('select2/defaults',[
|
|
} else {
|
|
} else {
|
|
options.selectionAdapter = SingleSelection;
|
|
options.selectionAdapter = SingleSelection;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // Add the placeholder mixin if a placeholder was specified
|
|
|
|
+ if (options.placeholder != null) {
|
|
|
|
+ options.selectionAdapter = Utils.Decorate(
|
|
|
|
+ options.selectionAdapter,
|
|
|
|
+ Placeholder
|
|
|
|
+ );
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
return options;
|
|
return options;
|