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; 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 () { define('select2/i18n/en',[],function () {
return { return {
noResults: function () { noResults: function () {
@ -1421,13 +1464,15 @@ define('select2/defaults',[
'./dropdown', './dropdown',
'./dropdown/search', './dropdown/search',
'./dropdown/hidePlaceholder',
'./i18n/en' './i18n/en'
], function ($, ResultsList, ], function ($, ResultsList,
SingleSelection, MultipleSelection, Placeholder, SingleSelection, MultipleSelection, Placeholder,
Utils, Translation, Utils, Translation,
SelectData, ArrayData, AjaxData, Tags, SelectData, ArrayData, AjaxData, Tags,
Dropdown, Search, EnglishTranslation) { Dropdown, Search, HidePlaceholder,
EnglishTranslation) {
function Defaults () { function Defaults () {
this.reset(); this.reset();
} }
@ -1472,6 +1517,11 @@ define('select2/defaults',[
options.selectionAdapter, options.selectionAdapter,
Placeholder Placeholder
); );
options.resultsAdapter = Utils.Decorate(
options.resultsAdapter,
HidePlaceholder
);
} }
} }

View File

@ -1395,6 +1395,49 @@ define('select2/dropdown/search',[
return 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 () { define('select2/i18n/en',[],function () {
return { return {
noResults: function () { noResults: function () {
@ -1421,13 +1464,15 @@ define('select2/defaults',[
'./dropdown', './dropdown',
'./dropdown/search', './dropdown/search',
'./dropdown/hidePlaceholder',
'./i18n/en' './i18n/en'
], function ($, ResultsList, ], function ($, ResultsList,
SingleSelection, MultipleSelection, Placeholder, SingleSelection, MultipleSelection, Placeholder,
Utils, Translation, Utils, Translation,
SelectData, ArrayData, AjaxData, Tags, SelectData, ArrayData, AjaxData, Tags,
Dropdown, Search, EnglishTranslation) { Dropdown, Search, HidePlaceholder,
EnglishTranslation) {
function Defaults () { function Defaults () {
this.reset(); this.reset();
} }
@ -1472,6 +1517,11 @@ define('select2/defaults',[
options.selectionAdapter, options.selectionAdapter,
Placeholder Placeholder
); );
options.resultsAdapter = Utils.Decorate(
options.resultsAdapter,
HidePlaceholder
);
} }
} }

View File

@ -10930,6 +10930,49 @@ define('select2/dropdown/search',[
return 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 () { define('select2/i18n/en',[],function () {
return { return {
noResults: function () { noResults: function () {
@ -10956,13 +10999,15 @@ define('select2/defaults',[
'./dropdown', './dropdown',
'./dropdown/search', './dropdown/search',
'./dropdown/hidePlaceholder',
'./i18n/en' './i18n/en'
], function ($, ResultsList, ], function ($, ResultsList,
SingleSelection, MultipleSelection, Placeholder, SingleSelection, MultipleSelection, Placeholder,
Utils, Translation, Utils, Translation,
SelectData, ArrayData, AjaxData, Tags, SelectData, ArrayData, AjaxData, Tags,
Dropdown, Search, EnglishTranslation) { Dropdown, Search, HidePlaceholder,
EnglishTranslation) {
function Defaults () { function Defaults () {
this.reset(); this.reset();
} }
@ -11007,6 +11052,11 @@ define('select2/defaults',[
options.selectionAdapter, options.selectionAdapter,
Placeholder 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; 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 () { define('select2/i18n/en',[],function () {
return { return {
noResults: function () { noResults: function () {
@ -1849,13 +1892,15 @@ define('select2/defaults',[
'./dropdown', './dropdown',
'./dropdown/search', './dropdown/search',
'./dropdown/hidePlaceholder',
'./i18n/en' './i18n/en'
], function ($, ResultsList, ], function ($, ResultsList,
SingleSelection, MultipleSelection, Placeholder, SingleSelection, MultipleSelection, Placeholder,
Utils, Translation, Utils, Translation,
SelectData, ArrayData, AjaxData, Tags, SelectData, ArrayData, AjaxData, Tags,
Dropdown, Search, EnglishTranslation) { Dropdown, Search, HidePlaceholder,
EnglishTranslation) {
function Defaults () { function Defaults () {
this.reset(); this.reset();
} }
@ -1900,6 +1945,11 @@ define('select2/defaults',[
options.selectionAdapter, options.selectionAdapter,
Placeholder 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',
'./dropdown/search', './dropdown/search',
'./dropdown/hidePlaceholder',
'./i18n/en' './i18n/en'
], function ($, ResultsList, ], function ($, ResultsList,
SingleSelection, MultipleSelection, Placeholder, SingleSelection, MultipleSelection, Placeholder,
Utils, Translation, Utils, Translation,
SelectData, ArrayData, AjaxData, Tags, SelectData, ArrayData, AjaxData, Tags,
Dropdown, Search, EnglishTranslation) { Dropdown, Search, HidePlaceholder,
EnglishTranslation) {
function Defaults () { function Defaults () {
this.reset(); this.reset();
} }
@ -67,6 +69,11 @@ define([
options.selectionAdapter, options.selectionAdapter,
Placeholder 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;
});