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

Added a base class for the selection container

This commit is contained in:
Kevin Brown 2014-10-17 20:53:34 -04:00
parent a07fc21815
commit e601e33ff3
10 changed files with 225 additions and 56 deletions

View File

@ -306,17 +306,46 @@ define('select2/results',[
return Results;
});
define('select2/selection/single',[
define('select2/selection/base',[
'../utils'
], function (Utils) {
function SingleSelection ($element, options) {
function BaseSelection ($element, options) {
this.$element = $element;
this.options = options;
SingleSelection.__super__.constructor.call(this);
BaseSelection.__super__.constructor.call(this);
}
Utils.Extend(SingleSelection, Utils.Observable);
Utils.Extend(BaseSelection, Utils.Observable);
BaseSelection.prototype.render = function () {
throw new Error('The `render` method must be defined in child classes.');
};
BaseSelection.prototype.bind = function (container, $container) {
var self = this;
container.on('selection:update', function (params) {
self.update(params.data);
});
};
BaseSelection.prototype.update = function (data) {
throw new Error('The `update` method must be defined in child classes.');
};
return BaseSelection;
});
define('select2/selection/single',[
'./base',
'../utils'
], function (BaseSelection, Utils) {
function SingleSelection () {
SingleSelection.__super__.constructor.apply(this, arguments);
}
Utils.Extend(SingleSelection, BaseSelection);
SingleSelection.prototype.render = function () {
var $selection = $(
@ -333,6 +362,8 @@ define('select2/selection/single',[
SingleSelection.prototype.bind = function (container, $container) {
var self = this;
SingleSelection.__super__.bind.apply(this, arguments);
this.$selection.on('mousedown', function (evt) {
// Only respond to left clicks
if (evt.which !== 1) {
@ -378,8 +409,9 @@ define('select2/selection/single',[
});
define('select2/selection/multiple',[
'./base',
'../utils'
], function (Utils) {
], function (BaseSelection, Utils) {
function MultipleSelection ($element, options) {
this.$element = $element;
this.options = options;
@ -387,7 +419,7 @@ define('select2/selection/multiple',[
MultipleSelection.__super__.constructor.call(this);
}
Utils.Extend(MultipleSelection, Utils.Observable);
Utils.Extend(MultipleSelection, BaseSelection);
MultipleSelection.prototype.render = function () {
var $selection = $(
@ -404,6 +436,8 @@ define('select2/selection/multiple',[
MultipleSelection.prototype.bind = function (container, $container) {
var self = this;
MultipleSelection.__super__.bind.apply(this, arguments);
this.$selection.on('click', function (evt) {
self.trigger('toggle', {
originalEvent: evt
@ -421,10 +455,6 @@ define('select2/selection/multiple',[
data: data
});
});
container.on('selection:update', function (params) {
self.update(params.data);
});
};
MultipleSelection.prototype.clear = function () {
@ -532,6 +562,10 @@ define('select2/data/base',[
throw new Error('The `query` method must be defined in child classes.');
};
BaseAdapter.prototype.bind = function (container, $container) {
// Can be implemented in subclasses
};
return BaseAdapter;
});

View File

@ -306,17 +306,46 @@ define('select2/results',[
return Results;
});
define('select2/selection/single',[
define('select2/selection/base',[
'../utils'
], function (Utils) {
function SingleSelection ($element, options) {
function BaseSelection ($element, options) {
this.$element = $element;
this.options = options;
SingleSelection.__super__.constructor.call(this);
BaseSelection.__super__.constructor.call(this);
}
Utils.Extend(SingleSelection, Utils.Observable);
Utils.Extend(BaseSelection, Utils.Observable);
BaseSelection.prototype.render = function () {
throw new Error('The `render` method must be defined in child classes.');
};
BaseSelection.prototype.bind = function (container, $container) {
var self = this;
container.on('selection:update', function (params) {
self.update(params.data);
});
};
BaseSelection.prototype.update = function (data) {
throw new Error('The `update` method must be defined in child classes.');
};
return BaseSelection;
});
define('select2/selection/single',[
'./base',
'../utils'
], function (BaseSelection, Utils) {
function SingleSelection () {
SingleSelection.__super__.constructor.apply(this, arguments);
}
Utils.Extend(SingleSelection, BaseSelection);
SingleSelection.prototype.render = function () {
var $selection = $(
@ -333,6 +362,8 @@ define('select2/selection/single',[
SingleSelection.prototype.bind = function (container, $container) {
var self = this;
SingleSelection.__super__.bind.apply(this, arguments);
this.$selection.on('mousedown', function (evt) {
// Only respond to left clicks
if (evt.which !== 1) {
@ -378,8 +409,9 @@ define('select2/selection/single',[
});
define('select2/selection/multiple',[
'./base',
'../utils'
], function (Utils) {
], function (BaseSelection, Utils) {
function MultipleSelection ($element, options) {
this.$element = $element;
this.options = options;
@ -387,7 +419,7 @@ define('select2/selection/multiple',[
MultipleSelection.__super__.constructor.call(this);
}
Utils.Extend(MultipleSelection, Utils.Observable);
Utils.Extend(MultipleSelection, BaseSelection);
MultipleSelection.prototype.render = function () {
var $selection = $(
@ -404,6 +436,8 @@ define('select2/selection/multiple',[
MultipleSelection.prototype.bind = function (container, $container) {
var self = this;
MultipleSelection.__super__.bind.apply(this, arguments);
this.$selection.on('click', function (evt) {
self.trigger('toggle', {
originalEvent: evt
@ -421,10 +455,6 @@ define('select2/selection/multiple',[
data: data
});
});
container.on('selection:update', function (params) {
self.update(params.data);
});
};
MultipleSelection.prototype.clear = function () {
@ -532,6 +562,10 @@ define('select2/data/base',[
throw new Error('The `query` method must be defined in child classes.');
};
BaseAdapter.prototype.bind = function (container, $container) {
// Can be implemented in subclasses
};
return BaseAdapter;
});

View File

@ -9844,17 +9844,46 @@ define('select2/results',[
return Results;
});
define('select2/selection/single',[
define('select2/selection/base',[
'../utils'
], function (Utils) {
function SingleSelection ($element, options) {
function BaseSelection ($element, options) {
this.$element = $element;
this.options = options;
SingleSelection.__super__.constructor.call(this);
BaseSelection.__super__.constructor.call(this);
}
Utils.Extend(SingleSelection, Utils.Observable);
Utils.Extend(BaseSelection, Utils.Observable);
BaseSelection.prototype.render = function () {
throw new Error('The `render` method must be defined in child classes.');
};
BaseSelection.prototype.bind = function (container, $container) {
var self = this;
container.on('selection:update', function (params) {
self.update(params.data);
});
};
BaseSelection.prototype.update = function (data) {
throw new Error('The `update` method must be defined in child classes.');
};
return BaseSelection;
});
define('select2/selection/single',[
'./base',
'../utils'
], function (BaseSelection, Utils) {
function SingleSelection () {
SingleSelection.__super__.constructor.apply(this, arguments);
}
Utils.Extend(SingleSelection, BaseSelection);
SingleSelection.prototype.render = function () {
var $selection = $(
@ -9871,6 +9900,8 @@ define('select2/selection/single',[
SingleSelection.prototype.bind = function (container, $container) {
var self = this;
SingleSelection.__super__.bind.apply(this, arguments);
this.$selection.on('mousedown', function (evt) {
// Only respond to left clicks
if (evt.which !== 1) {
@ -9916,8 +9947,9 @@ define('select2/selection/single',[
});
define('select2/selection/multiple',[
'./base',
'../utils'
], function (Utils) {
], function (BaseSelection, Utils) {
function MultipleSelection ($element, options) {
this.$element = $element;
this.options = options;
@ -9925,7 +9957,7 @@ define('select2/selection/multiple',[
MultipleSelection.__super__.constructor.call(this);
}
Utils.Extend(MultipleSelection, Utils.Observable);
Utils.Extend(MultipleSelection, BaseSelection);
MultipleSelection.prototype.render = function () {
var $selection = $(
@ -9942,6 +9974,8 @@ define('select2/selection/multiple',[
MultipleSelection.prototype.bind = function (container, $container) {
var self = this;
MultipleSelection.__super__.bind.apply(this, arguments);
this.$selection.on('click', function (evt) {
self.trigger('toggle', {
originalEvent: evt
@ -9959,10 +9993,6 @@ define('select2/selection/multiple',[
data: data
});
});
container.on('selection:update', function (params) {
self.update(params.data);
});
};
MultipleSelection.prototype.clear = function () {
@ -10070,6 +10100,10 @@ define('select2/data/base',[
throw new Error('The `query` method must be defined in child classes.');
};
BaseAdapter.prototype.bind = function (container, $container) {
// Can be implemented in subclasses
};
return BaseAdapter;
});

File diff suppressed because one or more lines are too long

54
dist/js/select2.js vendored
View File

@ -735,17 +735,46 @@ define('select2/results',[
return Results;
});
define('select2/selection/single',[
define('select2/selection/base',[
'../utils'
], function (Utils) {
function SingleSelection ($element, options) {
function BaseSelection ($element, options) {
this.$element = $element;
this.options = options;
SingleSelection.__super__.constructor.call(this);
BaseSelection.__super__.constructor.call(this);
}
Utils.Extend(SingleSelection, Utils.Observable);
Utils.Extend(BaseSelection, Utils.Observable);
BaseSelection.prototype.render = function () {
throw new Error('The `render` method must be defined in child classes.');
};
BaseSelection.prototype.bind = function (container, $container) {
var self = this;
container.on('selection:update', function (params) {
self.update(params.data);
});
};
BaseSelection.prototype.update = function (data) {
throw new Error('The `update` method must be defined in child classes.');
};
return BaseSelection;
});
define('select2/selection/single',[
'./base',
'../utils'
], function (BaseSelection, Utils) {
function SingleSelection () {
SingleSelection.__super__.constructor.apply(this, arguments);
}
Utils.Extend(SingleSelection, BaseSelection);
SingleSelection.prototype.render = function () {
var $selection = $(
@ -762,6 +791,8 @@ define('select2/selection/single',[
SingleSelection.prototype.bind = function (container, $container) {
var self = this;
SingleSelection.__super__.bind.apply(this, arguments);
this.$selection.on('mousedown', function (evt) {
// Only respond to left clicks
if (evt.which !== 1) {
@ -807,8 +838,9 @@ define('select2/selection/single',[
});
define('select2/selection/multiple',[
'./base',
'../utils'
], function (Utils) {
], function (BaseSelection, Utils) {
function MultipleSelection ($element, options) {
this.$element = $element;
this.options = options;
@ -816,7 +848,7 @@ define('select2/selection/multiple',[
MultipleSelection.__super__.constructor.call(this);
}
Utils.Extend(MultipleSelection, Utils.Observable);
Utils.Extend(MultipleSelection, BaseSelection);
MultipleSelection.prototype.render = function () {
var $selection = $(
@ -833,6 +865,8 @@ define('select2/selection/multiple',[
MultipleSelection.prototype.bind = function (container, $container) {
var self = this;
MultipleSelection.__super__.bind.apply(this, arguments);
this.$selection.on('click', function (evt) {
self.trigger('toggle', {
originalEvent: evt
@ -850,10 +884,6 @@ define('select2/selection/multiple',[
data: data
});
});
container.on('selection:update', function (params) {
self.update(params.data);
});
};
MultipleSelection.prototype.clear = function () {
@ -961,6 +991,10 @@ define('select2/data/base',[
throw new Error('The `query` method must be defined in child classes.');
};
BaseAdapter.prototype.bind = function (container, $container) {
// Can be implemented in subclasses
};
return BaseAdapter;
});

File diff suppressed because one or more lines are too long

View File

@ -15,5 +15,9 @@ define([
throw new Error('The `query` method must be defined in child classes.');
};
BaseAdapter.prototype.bind = function (container, $container) {
// Can be implemented in subclasses
};
return BaseAdapter;
});

30
src/js/select2/selection/base.js vendored Normal file
View File

@ -0,0 +1,30 @@
define([
'../utils'
], function (Utils) {
function BaseSelection ($element, options) {
this.$element = $element;
this.options = options;
BaseSelection.__super__.constructor.call(this);
}
Utils.Extend(BaseSelection, Utils.Observable);
BaseSelection.prototype.render = function () {
throw new Error('The `render` method must be defined in child classes.');
};
BaseSelection.prototype.bind = function (container, $container) {
var self = this;
container.on('selection:update', function (params) {
self.update(params.data);
});
};
BaseSelection.prototype.update = function (data) {
throw new Error('The `update` method must be defined in child classes.');
};
return BaseSelection;
});

View File

@ -1,6 +1,7 @@
define([
'./base',
'../utils'
], function (Utils) {
], function (BaseSelection, Utils) {
function MultipleSelection ($element, options) {
this.$element = $element;
this.options = options;
@ -8,7 +9,7 @@ define([
MultipleSelection.__super__.constructor.call(this);
}
Utils.Extend(MultipleSelection, Utils.Observable);
Utils.Extend(MultipleSelection, BaseSelection);
MultipleSelection.prototype.render = function () {
var $selection = $(
@ -25,6 +26,8 @@ define([
MultipleSelection.prototype.bind = function (container, $container) {
var self = this;
MultipleSelection.__super__.bind.apply(this, arguments);
this.$selection.on('click', function (evt) {
self.trigger('toggle', {
originalEvent: evt
@ -42,10 +45,6 @@ define([
data: data
});
});
container.on('selection:update', function (params) {
self.update(params.data);
});
};
MultipleSelection.prototype.clear = function () {

View File

@ -1,14 +1,12 @@
define([
'./base',
'../utils'
], function (Utils) {
function SingleSelection ($element, options) {
this.$element = $element;
this.options = options;
SingleSelection.__super__.constructor.call(this);
], function (BaseSelection, Utils) {
function SingleSelection () {
SingleSelection.__super__.constructor.apply(this, arguments);
}
Utils.Extend(SingleSelection, Utils.Observable);
Utils.Extend(SingleSelection, BaseSelection);
SingleSelection.prototype.render = function () {
var $selection = $(
@ -25,6 +23,8 @@ define([
SingleSelection.prototype.bind = function (container, $container) {
var self = this;
SingleSelection.__super__.bind.apply(this, arguments);
this.$selection.on('mousedown', function (evt) {
// Only respond to left clicks
if (evt.which !== 1) {