1
0
mirror of synced 2024-11-26 06:46:04 +03:00

Header and footer decorators

Added examples of header and footer decorators.
This commit is contained in:
Kevin Brown 2014-08-30 17:46:34 -04:00
parent f82202036f
commit 0081716841
6 changed files with 35 additions and 8 deletions

View File

@ -507,7 +507,7 @@ define('select2/options',[
this.dataAdapter = SelectData;
this.resultsAdapter = ResultsList;
this.dropdownAdapter = Dropdown;
this.dropdownAdapter = options.dropdownAdapter || Dropdown;
this.selectionAdapter = options.selectionAdapter;
if (this.selectionAdapter == null) {

View File

@ -507,7 +507,7 @@ define('select2/options',[
this.dataAdapter = SelectData;
this.resultsAdapter = ResultsList;
this.dropdownAdapter = Dropdown;
this.dropdownAdapter = options.dropdownAdapter || Dropdown;
this.selectionAdapter = options.selectionAdapter;
if (this.selectionAdapter == null) {

View File

@ -10044,7 +10044,7 @@ define('select2/options',[
this.dataAdapter = SelectData;
this.resultsAdapter = ResultsList;
this.dropdownAdapter = Dropdown;
this.dropdownAdapter = options.dropdownAdapter || Dropdown;
this.selectionAdapter = options.selectionAdapter;
if (this.selectionAdapter == null) {

2
dist/js/select2.js vendored
View File

@ -935,7 +935,7 @@ define('select2/options',[
this.dataAdapter = SelectData;
this.resultsAdapter = ResultsList;
this.dropdownAdapter = Dropdown;
this.dropdownAdapter = options.dropdownAdapter || Dropdown;
this.selectionAdapter = options.selectionAdapter;
if (this.selectionAdapter == null) {

View File

@ -152,7 +152,8 @@
</style>
<script>
require(["select2/core", "select2/utils", "select2/selection"], function (Select2, Utils, Selection) {
require(["select2/core", "select2/utils", "select2/selection/single",
"select2/dropdown"], function (Select2, Utils, Selection, Dropdown) {
function ClearSelection () { }
ClearSelection.prototype.render = function (decorated) {
@ -203,10 +204,36 @@ require(["select2/core", "select2/utils", "select2/selection"], function (Select
}
};
var CustomSelection = Utils.Decorate(Selection, ClearSelection);
function DropdownFooter () { }
DropdownFooter.prototype.render = function (decorated) {
var $dropdown = decorated.call(this);
$dropdown.append('<div class="footer">My custom footer</div>');
return $dropdown;
}
function DropdownHeader () { }
DropdownHeader.prototype.render = function (decorated) {
var $dropdown = decorated.call(this);
$dropdown.prepend('<div class="header">Some custom header</div>');
return $dropdown;
}
var CustomSelection = Utils.Decorate(Selection, ClearSelection)
var CustomDropdown = Utils.Decorate(
Utils.Decorate(Dropdown, DropdownHeader),
DropdownFooter
);
var s2 = new Select2($("#source"), {
selectionAdapter: CustomSelection
selectionAdapter: CustomSelection,
dropdownAdapter: CustomDropdown
});
});
</script>

View File

@ -11,7 +11,7 @@ define([
this.dataAdapter = SelectData;
this.resultsAdapter = ResultsList;
this.dropdownAdapter = Dropdown;
this.dropdownAdapter = options.dropdownAdapter || Dropdown;
this.selectionAdapter = options.selectionAdapter;
if (this.selectionAdapter == null) {