1
0
mirror of synced 2024-11-22 21:16:10 +03:00

Added decorator to remove the placeholder object

This will remove the placeholder object from the results list.
This commit is contained in:
Kevin Brown 2014-11-01 17:21:46 -04:00
parent 09a0bb89b8
commit e57e0b1870
8 changed files with 256 additions and 7 deletions

View File

@ -1395,6 +1395,49 @@ define('select2/dropdown/search',[
return Search;
});
define('select2/dropdown/hidePlaceholder',[
], function () {
function HidePlaceholder (decorated, $element, options, dataAdapter) {
this.placeholder = this.normalizePlaceholder(options.get('placeholder'));
decorated.call(this, $element, options, dataAdapter);
}
HidePlaceholder.prototype.append = function (decorated, data) {
data = this.removePlaceholder(data);
decorated.call(this, data);
};
HidePlaceholder.prototype.normalizePlaceholder = function (_, placeholder) {
if (typeof placeholder === 'string') {
placeholder = {
id: '',
text: placeholder
};
}
return placeholder;
};
HidePlaceholder.prototype.removePlaceholder = function (_, data) {
var modifiedData = data.slice(0);
for (var d = data.length - 1; d >= 0; d--) {
var item = data[d];
if (this.placeholder.id === item.id) {
modifiedData.splice(d, 1);
}
}
return modifiedData;
};
return HidePlaceholder;
});
define('select2/i18n/en',[],function () {
return {
noResults: function () {
@ -1421,13 +1464,15 @@ define('select2/defaults',[
'./dropdown',
'./dropdown/search',
'./dropdown/hidePlaceholder',
'./i18n/en'
], function ($, ResultsList,
SingleSelection, MultipleSelection, Placeholder,
Utils, Translation,
SelectData, ArrayData, AjaxData, Tags,
Dropdown, Search, EnglishTranslation) {
Dropdown, Search, HidePlaceholder,
EnglishTranslation) {
function Defaults () {
this.reset();
}
@ -1472,6 +1517,11 @@ define('select2/defaults',[
options.selectionAdapter,
Placeholder
);
options.resultsAdapter = Utils.Decorate(
options.resultsAdapter,
HidePlaceholder
);
}
}

View File

@ -1395,6 +1395,49 @@ define('select2/dropdown/search',[
return Search;
});
define('select2/dropdown/hidePlaceholder',[
], function () {
function HidePlaceholder (decorated, $element, options, dataAdapter) {
this.placeholder = this.normalizePlaceholder(options.get('placeholder'));
decorated.call(this, $element, options, dataAdapter);
}
HidePlaceholder.prototype.append = function (decorated, data) {
data = this.removePlaceholder(data);
decorated.call(this, data);
};
HidePlaceholder.prototype.normalizePlaceholder = function (_, placeholder) {
if (typeof placeholder === 'string') {
placeholder = {
id: '',
text: placeholder
};
}
return placeholder;
};
HidePlaceholder.prototype.removePlaceholder = function (_, data) {
var modifiedData = data.slice(0);
for (var d = data.length - 1; d >= 0; d--) {
var item = data[d];
if (this.placeholder.id === item.id) {
modifiedData.splice(d, 1);
}
}
return modifiedData;
};
return HidePlaceholder;
});
define('select2/i18n/en',[],function () {
return {
noResults: function () {
@ -1421,13 +1464,15 @@ define('select2/defaults',[
'./dropdown',
'./dropdown/search',
'./dropdown/hidePlaceholder',
'./i18n/en'
], function ($, ResultsList,
SingleSelection, MultipleSelection, Placeholder,
Utils, Translation,
SelectData, ArrayData, AjaxData, Tags,
Dropdown, Search, EnglishTranslation) {
Dropdown, Search, HidePlaceholder,
EnglishTranslation) {
function Defaults () {
this.reset();
}
@ -1472,6 +1517,11 @@ define('select2/defaults',[
options.selectionAdapter,
Placeholder
);
options.resultsAdapter = Utils.Decorate(
options.resultsAdapter,
HidePlaceholder
);
}
}

View File

@ -10930,6 +10930,49 @@ define('select2/dropdown/search',[
return Search;
});
define('select2/dropdown/hidePlaceholder',[
], function () {
function HidePlaceholder (decorated, $element, options, dataAdapter) {
this.placeholder = this.normalizePlaceholder(options.get('placeholder'));
decorated.call(this, $element, options, dataAdapter);
}
HidePlaceholder.prototype.append = function (decorated, data) {
data = this.removePlaceholder(data);
decorated.call(this, data);
};
HidePlaceholder.prototype.normalizePlaceholder = function (_, placeholder) {
if (typeof placeholder === 'string') {
placeholder = {
id: '',
text: placeholder
};
}
return placeholder;
};
HidePlaceholder.prototype.removePlaceholder = function (_, data) {
var modifiedData = data.slice(0);
for (var d = data.length - 1; d >= 0; d--) {
var item = data[d];
if (this.placeholder.id === item.id) {
modifiedData.splice(d, 1);
}
}
return modifiedData;
};
return HidePlaceholder;
});
define('select2/i18n/en',[],function () {
return {
noResults: function () {
@ -10956,13 +10999,15 @@ define('select2/defaults',[
'./dropdown',
'./dropdown/search',
'./dropdown/hidePlaceholder',
'./i18n/en'
], function ($, ResultsList,
SingleSelection, MultipleSelection, Placeholder,
Utils, Translation,
SelectData, ArrayData, AjaxData, Tags,
Dropdown, Search, EnglishTranslation) {
Dropdown, Search, HidePlaceholder,
EnglishTranslation) {
function Defaults () {
this.reset();
}
@ -11007,6 +11052,11 @@ define('select2/defaults',[
options.selectionAdapter,
Placeholder
);
options.resultsAdapter = Utils.Decorate(
options.resultsAdapter,
HidePlaceholder
);
}
}

File diff suppressed because one or more lines are too long

52
dist/js/select2.js vendored
View File

@ -1823,6 +1823,49 @@ define('select2/dropdown/search',[
return Search;
});
define('select2/dropdown/hidePlaceholder',[
], function () {
function HidePlaceholder (decorated, $element, options, dataAdapter) {
this.placeholder = this.normalizePlaceholder(options.get('placeholder'));
decorated.call(this, $element, options, dataAdapter);
}
HidePlaceholder.prototype.append = function (decorated, data) {
data = this.removePlaceholder(data);
decorated.call(this, data);
};
HidePlaceholder.prototype.normalizePlaceholder = function (_, placeholder) {
if (typeof placeholder === 'string') {
placeholder = {
id: '',
text: placeholder
};
}
return placeholder;
};
HidePlaceholder.prototype.removePlaceholder = function (_, data) {
var modifiedData = data.slice(0);
for (var d = data.length - 1; d >= 0; d--) {
var item = data[d];
if (this.placeholder.id === item.id) {
modifiedData.splice(d, 1);
}
}
return modifiedData;
};
return HidePlaceholder;
});
define('select2/i18n/en',[],function () {
return {
noResults: function () {
@ -1849,13 +1892,15 @@ define('select2/defaults',[
'./dropdown',
'./dropdown/search',
'./dropdown/hidePlaceholder',
'./i18n/en'
], function ($, ResultsList,
SingleSelection, MultipleSelection, Placeholder,
Utils, Translation,
SelectData, ArrayData, AjaxData, Tags,
Dropdown, Search, EnglishTranslation) {
Dropdown, Search, HidePlaceholder,
EnglishTranslation) {
function Defaults () {
this.reset();
}
@ -1900,6 +1945,11 @@ define('select2/defaults',[
options.selectionAdapter,
Placeholder
);
options.resultsAdapter = Utils.Decorate(
options.resultsAdapter,
HidePlaceholder
);
}
}

File diff suppressed because one or more lines are too long

View File

@ -16,13 +16,15 @@ define([
'./dropdown',
'./dropdown/search',
'./dropdown/hidePlaceholder',
'./i18n/en'
], function ($, ResultsList,
SingleSelection, MultipleSelection, Placeholder,
Utils, Translation,
SelectData, ArrayData, AjaxData, Tags,
Dropdown, Search, EnglishTranslation) {
Dropdown, Search, HidePlaceholder,
EnglishTranslation) {
function Defaults () {
this.reset();
}
@ -67,6 +69,11 @@ define([
options.selectionAdapter,
Placeholder
);
options.resultsAdapter = Utils.Decorate(
options.resultsAdapter,
HidePlaceholder
);
}
}

View File

@ -0,0 +1,42 @@
define([
], function () {
function HidePlaceholder (decorated, $element, options, dataAdapter) {
this.placeholder = this.normalizePlaceholder(options.get('placeholder'));
decorated.call(this, $element, options, dataAdapter);
}
HidePlaceholder.prototype.append = function (decorated, data) {
data = this.removePlaceholder(data);
decorated.call(this, data);
};
HidePlaceholder.prototype.normalizePlaceholder = function (_, placeholder) {
if (typeof placeholder === 'string') {
placeholder = {
id: '',
text: placeholder
};
}
return placeholder;
};
HidePlaceholder.prototype.removePlaceholder = function (_, data) {
var modifiedData = data.slice(0);
for (var d = data.length - 1; d >= 0; d--) {
var item = data[d];
if (this.placeholder.id === item.id) {
modifiedData.splice(d, 1);
}
}
return modifiedData;
};
return HidePlaceholder;
});