Skip to content

Commit 94b460f

Browse files
committed
Limit the explicit coupling between adapters
1 parent 0081716 commit 94b460f

11 files changed

Lines changed: 162 additions & 48 deletions

File tree

dist/js/select2.amd.full.js

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,18 @@ define('select2/data/select',[
192192
}
193193
}
194194

195+
SelectAdapter.prototype.bind = function (container, $container) {
196+
var self = this;
197+
198+
container.on("select", function (params) {
199+
var current = self.current(function (data) {
200+
//
201+
});
202+
203+
self.select(params.data);
204+
});
205+
}
206+
195207
SelectAdapter.prototype.query = function (params, callback) {
196208
var data = [];
197209
var self = this;
@@ -305,7 +317,7 @@ define('select2/results',[
305317
return $option;
306318
}
307319

308-
Results.prototype.bind = function ($container) {
320+
Results.prototype.bind = function (container, $container) {
309321
var self = this;
310322

311323
this.on("results:all", function (data) {
@@ -390,14 +402,18 @@ define('select2/selection/single',[
390402
return $selection;
391403
}
392404

393-
SingleSelection.prototype.bind = function ($container) {
405+
SingleSelection.prototype.bind = function (container, $container) {
394406
var self = this;
395407

396408
this.$selection.on('click', function (evt) {
397409
self.trigger("toggle", {
398410
originalEvent: evt
399411
});
400412
});
413+
414+
container.on("selection:update", function (params) {
415+
self.update(params.data);
416+
})
401417
}
402418

403419
SingleSelection.prototype.clear = function () {
@@ -448,14 +464,18 @@ define('select2/selection/multiple',[
448464
return $selection;
449465
}
450466

451-
MultipleSelection.prototype.bind = function ($container) {
467+
MultipleSelection.prototype.bind = function (container, $container) {
452468
var self = this;
453469

454470
this.$selection.on('click', function (evt) {
455471
self.trigger("toggle", {
456472
originalEvent: evt
457473
});
458474
});
475+
476+
container.on("selection:update", function (params) {
477+
self.update(params.data);
478+
});
459479
}
460480

461481
MultipleSelection.prototype.clear = function () {
@@ -573,12 +593,15 @@ define('select2/core',[
573593

574594
var self = this;
575595

576-
this.selection.bind($container);
577-
this.results.bind($container);
596+
this.data.bind(this, $container);
597+
this.selection.bind(this, $container);
598+
this.results.bind(this, $container);
578599

579600
this.$element.on("change", function () {
580601
self.data.current(function (data) {
581-
self.selection.update(data);
602+
self.trigger("selection:update", {
603+
data: data
604+
});
582605
});
583606
});
584607

@@ -587,7 +610,8 @@ define('select2/core',[
587610
});
588611

589612
this.results.on("selected", function (params) {
590-
self.data.select(params.data);
613+
self.trigger("select", params);
614+
591615
$container.removeClass("open");
592616
});
593617

dist/js/select2.amd.js

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,18 @@ define('select2/data/select',[
192192
}
193193
}
194194

195+
SelectAdapter.prototype.bind = function (container, $container) {
196+
var self = this;
197+
198+
container.on("select", function (params) {
199+
var current = self.current(function (data) {
200+
//
201+
});
202+
203+
self.select(params.data);
204+
});
205+
}
206+
195207
SelectAdapter.prototype.query = function (params, callback) {
196208
var data = [];
197209
var self = this;
@@ -305,7 +317,7 @@ define('select2/results',[
305317
return $option;
306318
}
307319

308-
Results.prototype.bind = function ($container) {
320+
Results.prototype.bind = function (container, $container) {
309321
var self = this;
310322

311323
this.on("results:all", function (data) {
@@ -390,14 +402,18 @@ define('select2/selection/single',[
390402
return $selection;
391403
}
392404

393-
SingleSelection.prototype.bind = function ($container) {
405+
SingleSelection.prototype.bind = function (container, $container) {
394406
var self = this;
395407

396408
this.$selection.on('click', function (evt) {
397409
self.trigger("toggle", {
398410
originalEvent: evt
399411
});
400412
});
413+
414+
container.on("selection:update", function (params) {
415+
self.update(params.data);
416+
})
401417
}
402418

403419
SingleSelection.prototype.clear = function () {
@@ -448,14 +464,18 @@ define('select2/selection/multiple',[
448464
return $selection;
449465
}
450466

451-
MultipleSelection.prototype.bind = function ($container) {
467+
MultipleSelection.prototype.bind = function (container, $container) {
452468
var self = this;
453469

454470
this.$selection.on('click', function (evt) {
455471
self.trigger("toggle", {
456472
originalEvent: evt
457473
});
458474
});
475+
476+
container.on("selection:update", function (params) {
477+
self.update(params.data);
478+
});
459479
}
460480

461481
MultipleSelection.prototype.clear = function () {
@@ -573,12 +593,15 @@ define('select2/core',[
573593

574594
var self = this;
575595

576-
this.selection.bind($container);
577-
this.results.bind($container);
596+
this.data.bind(this, $container);
597+
this.selection.bind(this, $container);
598+
this.results.bind(this, $container);
578599

579600
this.$element.on("change", function () {
580601
self.data.current(function (data) {
581-
self.selection.update(data);
602+
self.trigger("selection:update", {
603+
data: data
604+
});
582605
});
583606
});
584607

@@ -587,7 +610,8 @@ define('select2/core',[
587610
});
588611

589612
this.results.on("selected", function (params) {
590-
self.data.select(params.data);
613+
self.trigger("select", params);
614+
591615
$container.removeClass("open");
592616
});
593617

dist/js/select2.full.js

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9729,6 +9729,18 @@ define('select2/data/select',[
97299729
}
97309730
}
97319731

9732+
SelectAdapter.prototype.bind = function (container, $container) {
9733+
var self = this;
9734+
9735+
container.on("select", function (params) {
9736+
var current = self.current(function (data) {
9737+
//
9738+
});
9739+
9740+
self.select(params.data);
9741+
});
9742+
}
9743+
97329744
SelectAdapter.prototype.query = function (params, callback) {
97339745
var data = [];
97349746
var self = this;
@@ -9842,7 +9854,7 @@ define('select2/results',[
98429854
return $option;
98439855
}
98449856

9845-
Results.prototype.bind = function ($container) {
9857+
Results.prototype.bind = function (container, $container) {
98469858
var self = this;
98479859

98489860
this.on("results:all", function (data) {
@@ -9927,14 +9939,18 @@ define('select2/selection/single',[
99279939
return $selection;
99289940
}
99299941

9930-
SingleSelection.prototype.bind = function ($container) {
9942+
SingleSelection.prototype.bind = function (container, $container) {
99319943
var self = this;
99329944

99339945
this.$selection.on('click', function (evt) {
99349946
self.trigger("toggle", {
99359947
originalEvent: evt
99369948
});
99379949
});
9950+
9951+
container.on("selection:update", function (params) {
9952+
self.update(params.data);
9953+
})
99389954
}
99399955

99409956
SingleSelection.prototype.clear = function () {
@@ -9985,14 +10001,18 @@ define('select2/selection/multiple',[
998510001
return $selection;
998610002
}
998710003

9988-
MultipleSelection.prototype.bind = function ($container) {
10004+
MultipleSelection.prototype.bind = function (container, $container) {
998910005
var self = this;
999010006

999110007
this.$selection.on('click', function (evt) {
999210008
self.trigger("toggle", {
999310009
originalEvent: evt
999410010
});
999510011
});
10012+
10013+
container.on("selection:update", function (params) {
10014+
self.update(params.data);
10015+
});
999610016
}
999710017

999810018
MultipleSelection.prototype.clear = function () {
@@ -10110,12 +10130,15 @@ define('select2/core',[
1011010130

1011110131
var self = this;
1011210132

10113-
this.selection.bind($container);
10114-
this.results.bind($container);
10133+
this.data.bind(this, $container);
10134+
this.selection.bind(this, $container);
10135+
this.results.bind(this, $container);
1011510136

1011610137
this.$element.on("change", function () {
1011710138
self.data.current(function (data) {
10118-
self.selection.update(data);
10139+
self.trigger("selection:update", {
10140+
data: data
10141+
});
1011910142
});
1012010143
});
1012110144

@@ -10124,7 +10147,8 @@ define('select2/core',[
1012410147
});
1012510148

1012610149
this.results.on("selected", function (params) {
10127-
self.data.select(params.data);
10150+
self.trigger("select", params);
10151+
1012810152
$container.removeClass("open");
1012910153
});
1013010154

dist/js/select2.js

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,18 @@ define('select2/data/select',[
620620
}
621621
}
622622

623+
SelectAdapter.prototype.bind = function (container, $container) {
624+
var self = this;
625+
626+
container.on("select", function (params) {
627+
var current = self.current(function (data) {
628+
//
629+
});
630+
631+
self.select(params.data);
632+
});
633+
}
634+
623635
SelectAdapter.prototype.query = function (params, callback) {
624636
var data = [];
625637
var self = this;
@@ -733,7 +745,7 @@ define('select2/results',[
733745
return $option;
734746
}
735747

736-
Results.prototype.bind = function ($container) {
748+
Results.prototype.bind = function (container, $container) {
737749
var self = this;
738750

739751
this.on("results:all", function (data) {
@@ -818,14 +830,18 @@ define('select2/selection/single',[
818830
return $selection;
819831
}
820832

821-
SingleSelection.prototype.bind = function ($container) {
833+
SingleSelection.prototype.bind = function (container, $container) {
822834
var self = this;
823835

824836
this.$selection.on('click', function (evt) {
825837
self.trigger("toggle", {
826838
originalEvent: evt
827839
});
828840
});
841+
842+
container.on("selection:update", function (params) {
843+
self.update(params.data);
844+
})
829845
}
830846

831847
SingleSelection.prototype.clear = function () {
@@ -876,14 +892,18 @@ define('select2/selection/multiple',[
876892
return $selection;
877893
}
878894

879-
MultipleSelection.prototype.bind = function ($container) {
895+
MultipleSelection.prototype.bind = function (container, $container) {
880896
var self = this;
881897

882898
this.$selection.on('click', function (evt) {
883899
self.trigger("toggle", {
884900
originalEvent: evt
885901
});
886902
});
903+
904+
container.on("selection:update", function (params) {
905+
self.update(params.data);
906+
});
887907
}
888908

889909
MultipleSelection.prototype.clear = function () {
@@ -1001,12 +1021,15 @@ define('select2/core',[
10011021

10021022
var self = this;
10031023

1004-
this.selection.bind($container);
1005-
this.results.bind($container);
1024+
this.data.bind(this, $container);
1025+
this.selection.bind(this, $container);
1026+
this.results.bind(this, $container);
10061027

10071028
this.$element.on("change", function () {
10081029
self.data.current(function (data) {
1009-
self.selection.update(data);
1030+
self.trigger("selection:update", {
1031+
data: data
1032+
});
10101033
});
10111034
});
10121035

@@ -1015,7 +1038,8 @@ define('select2/core',[
10151038
});
10161039

10171040
this.results.on("selected", function (params) {
1018-
self.data.select(params.data);
1041+
self.trigger("select", params);
1042+
10191043
$container.removeClass("open");
10201044
});
10211045

0 commit comments

Comments
 (0)