Skip to content

Commit e601e33

Browse files
committed
Added a base class for the selection container
1 parent a07fc21 commit e601e33

10 files changed

Lines changed: 225 additions & 56 deletions

File tree

dist/js/select2.amd.full.js

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -306,17 +306,46 @@ define('select2/results',[
306306
return Results;
307307
});
308308

309-
define('select2/selection/single',[
309+
define('select2/selection/base',[
310310
'../utils'
311311
], function (Utils) {
312-
function SingleSelection ($element, options) {
312+
function BaseSelection ($element, options) {
313313
this.$element = $element;
314314
this.options = options;
315315

316-
SingleSelection.__super__.constructor.call(this);
316+
BaseSelection.__super__.constructor.call(this);
317317
}
318318

319-
Utils.Extend(SingleSelection, Utils.Observable);
319+
Utils.Extend(BaseSelection, Utils.Observable);
320+
321+
BaseSelection.prototype.render = function () {
322+
throw new Error('The `render` method must be defined in child classes.');
323+
};
324+
325+
BaseSelection.prototype.bind = function (container, $container) {
326+
var self = this;
327+
328+
container.on('selection:update', function (params) {
329+
self.update(params.data);
330+
});
331+
};
332+
333+
BaseSelection.prototype.update = function (data) {
334+
throw new Error('The `update` method must be defined in child classes.');
335+
};
336+
337+
return BaseSelection;
338+
});
339+
340+
define('select2/selection/single',[
341+
'./base',
342+
'../utils'
343+
], function (BaseSelection, Utils) {
344+
function SingleSelection () {
345+
SingleSelection.__super__.constructor.apply(this, arguments);
346+
}
347+
348+
Utils.Extend(SingleSelection, BaseSelection);
320349

321350
SingleSelection.prototype.render = function () {
322351
var $selection = $(
@@ -333,6 +362,8 @@ define('select2/selection/single',[
333362
SingleSelection.prototype.bind = function (container, $container) {
334363
var self = this;
335364

365+
SingleSelection.__super__.bind.apply(this, arguments);
366+
336367
this.$selection.on('mousedown', function (evt) {
337368
// Only respond to left clicks
338369
if (evt.which !== 1) {
@@ -378,16 +409,17 @@ define('select2/selection/single',[
378409
});
379410

380411
define('select2/selection/multiple',[
412+
'./base',
381413
'../utils'
382-
], function (Utils) {
414+
], function (BaseSelection, Utils) {
383415
function MultipleSelection ($element, options) {
384416
this.$element = $element;
385417
this.options = options;
386418

387419
MultipleSelection.__super__.constructor.call(this);
388420
}
389421

390-
Utils.Extend(MultipleSelection, Utils.Observable);
422+
Utils.Extend(MultipleSelection, BaseSelection);
391423

392424
MultipleSelection.prototype.render = function () {
393425
var $selection = $(
@@ -404,6 +436,8 @@ define('select2/selection/multiple',[
404436
MultipleSelection.prototype.bind = function (container, $container) {
405437
var self = this;
406438

439+
MultipleSelection.__super__.bind.apply(this, arguments);
440+
407441
this.$selection.on('click', function (evt) {
408442
self.trigger('toggle', {
409443
originalEvent: evt
@@ -421,10 +455,6 @@ define('select2/selection/multiple',[
421455
data: data
422456
});
423457
});
424-
425-
container.on('selection:update', function (params) {
426-
self.update(params.data);
427-
});
428458
};
429459

430460
MultipleSelection.prototype.clear = function () {
@@ -532,6 +562,10 @@ define('select2/data/base',[
532562
throw new Error('The `query` method must be defined in child classes.');
533563
};
534564

565+
BaseAdapter.prototype.bind = function (container, $container) {
566+
// Can be implemented in subclasses
567+
};
568+
535569
return BaseAdapter;
536570
});
537571

dist/js/select2.amd.js

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -306,17 +306,46 @@ define('select2/results',[
306306
return Results;
307307
});
308308

309-
define('select2/selection/single',[
309+
define('select2/selection/base',[
310310
'../utils'
311311
], function (Utils) {
312-
function SingleSelection ($element, options) {
312+
function BaseSelection ($element, options) {
313313
this.$element = $element;
314314
this.options = options;
315315

316-
SingleSelection.__super__.constructor.call(this);
316+
BaseSelection.__super__.constructor.call(this);
317317
}
318318

319-
Utils.Extend(SingleSelection, Utils.Observable);
319+
Utils.Extend(BaseSelection, Utils.Observable);
320+
321+
BaseSelection.prototype.render = function () {
322+
throw new Error('The `render` method must be defined in child classes.');
323+
};
324+
325+
BaseSelection.prototype.bind = function (container, $container) {
326+
var self = this;
327+
328+
container.on('selection:update', function (params) {
329+
self.update(params.data);
330+
});
331+
};
332+
333+
BaseSelection.prototype.update = function (data) {
334+
throw new Error('The `update` method must be defined in child classes.');
335+
};
336+
337+
return BaseSelection;
338+
});
339+
340+
define('select2/selection/single',[
341+
'./base',
342+
'../utils'
343+
], function (BaseSelection, Utils) {
344+
function SingleSelection () {
345+
SingleSelection.__super__.constructor.apply(this, arguments);
346+
}
347+
348+
Utils.Extend(SingleSelection, BaseSelection);
320349

321350
SingleSelection.prototype.render = function () {
322351
var $selection = $(
@@ -333,6 +362,8 @@ define('select2/selection/single',[
333362
SingleSelection.prototype.bind = function (container, $container) {
334363
var self = this;
335364

365+
SingleSelection.__super__.bind.apply(this, arguments);
366+
336367
this.$selection.on('mousedown', function (evt) {
337368
// Only respond to left clicks
338369
if (evt.which !== 1) {
@@ -378,16 +409,17 @@ define('select2/selection/single',[
378409
});
379410

380411
define('select2/selection/multiple',[
412+
'./base',
381413
'../utils'
382-
], function (Utils) {
414+
], function (BaseSelection, Utils) {
383415
function MultipleSelection ($element, options) {
384416
this.$element = $element;
385417
this.options = options;
386418

387419
MultipleSelection.__super__.constructor.call(this);
388420
}
389421

390-
Utils.Extend(MultipleSelection, Utils.Observable);
422+
Utils.Extend(MultipleSelection, BaseSelection);
391423

392424
MultipleSelection.prototype.render = function () {
393425
var $selection = $(
@@ -404,6 +436,8 @@ define('select2/selection/multiple',[
404436
MultipleSelection.prototype.bind = function (container, $container) {
405437
var self = this;
406438

439+
MultipleSelection.__super__.bind.apply(this, arguments);
440+
407441
this.$selection.on('click', function (evt) {
408442
self.trigger('toggle', {
409443
originalEvent: evt
@@ -421,10 +455,6 @@ define('select2/selection/multiple',[
421455
data: data
422456
});
423457
});
424-
425-
container.on('selection:update', function (params) {
426-
self.update(params.data);
427-
});
428458
};
429459

430460
MultipleSelection.prototype.clear = function () {
@@ -532,6 +562,10 @@ define('select2/data/base',[
532562
throw new Error('The `query` method must be defined in child classes.');
533563
};
534564

565+
BaseAdapter.prototype.bind = function (container, $container) {
566+
// Can be implemented in subclasses
567+
};
568+
535569
return BaseAdapter;
536570
});
537571

dist/js/select2.full.js

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9844,17 +9844,46 @@ define('select2/results',[
98449844
return Results;
98459845
});
98469846

9847-
define('select2/selection/single',[
9847+
define('select2/selection/base',[
98489848
'../utils'
98499849
], function (Utils) {
9850-
function SingleSelection ($element, options) {
9850+
function BaseSelection ($element, options) {
98519851
this.$element = $element;
98529852
this.options = options;
98539853

9854-
SingleSelection.__super__.constructor.call(this);
9854+
BaseSelection.__super__.constructor.call(this);
98559855
}
98569856

9857-
Utils.Extend(SingleSelection, Utils.Observable);
9857+
Utils.Extend(BaseSelection, Utils.Observable);
9858+
9859+
BaseSelection.prototype.render = function () {
9860+
throw new Error('The `render` method must be defined in child classes.');
9861+
};
9862+
9863+
BaseSelection.prototype.bind = function (container, $container) {
9864+
var self = this;
9865+
9866+
container.on('selection:update', function (params) {
9867+
self.update(params.data);
9868+
});
9869+
};
9870+
9871+
BaseSelection.prototype.update = function (data) {
9872+
throw new Error('The `update` method must be defined in child classes.');
9873+
};
9874+
9875+
return BaseSelection;
9876+
});
9877+
9878+
define('select2/selection/single',[
9879+
'./base',
9880+
'../utils'
9881+
], function (BaseSelection, Utils) {
9882+
function SingleSelection () {
9883+
SingleSelection.__super__.constructor.apply(this, arguments);
9884+
}
9885+
9886+
Utils.Extend(SingleSelection, BaseSelection);
98589887

98599888
SingleSelection.prototype.render = function () {
98609889
var $selection = $(
@@ -9871,6 +9900,8 @@ define('select2/selection/single',[
98719900
SingleSelection.prototype.bind = function (container, $container) {
98729901
var self = this;
98739902

9903+
SingleSelection.__super__.bind.apply(this, arguments);
9904+
98749905
this.$selection.on('mousedown', function (evt) {
98759906
// Only respond to left clicks
98769907
if (evt.which !== 1) {
@@ -9916,16 +9947,17 @@ define('select2/selection/single',[
99169947
});
99179948

99189949
define('select2/selection/multiple',[
9950+
'./base',
99199951
'../utils'
9920-
], function (Utils) {
9952+
], function (BaseSelection, Utils) {
99219953
function MultipleSelection ($element, options) {
99229954
this.$element = $element;
99239955
this.options = options;
99249956

99259957
MultipleSelection.__super__.constructor.call(this);
99269958
}
99279959

9928-
Utils.Extend(MultipleSelection, Utils.Observable);
9960+
Utils.Extend(MultipleSelection, BaseSelection);
99299961

99309962
MultipleSelection.prototype.render = function () {
99319963
var $selection = $(
@@ -9942,6 +9974,8 @@ define('select2/selection/multiple',[
99429974
MultipleSelection.prototype.bind = function (container, $container) {
99439975
var self = this;
99449976

9977+
MultipleSelection.__super__.bind.apply(this, arguments);
9978+
99459979
this.$selection.on('click', function (evt) {
99469980
self.trigger('toggle', {
99479981
originalEvent: evt
@@ -9959,10 +9993,6 @@ define('select2/selection/multiple',[
99599993
data: data
99609994
});
99619995
});
9962-
9963-
container.on('selection:update', function (params) {
9964-
self.update(params.data);
9965-
});
99669996
};
99679997

99689998
MultipleSelection.prototype.clear = function () {
@@ -10070,6 +10100,10 @@ define('select2/data/base',[
1007010100
throw new Error('The `query` method must be defined in child classes.');
1007110101
};
1007210102

10103+
BaseAdapter.prototype.bind = function (container, $container) {
10104+
// Can be implemented in subclasses
10105+
};
10106+
1007310107
return BaseAdapter;
1007410108
});
1007510109

dist/js/select2.full.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)