diff --git a/dist/js/select2.amd.full.js b/dist/js/select2.amd.full.js index e2738ebf..b10bcbca 100644 --- a/dist/js/select2.amd.full.js +++ b/dist/js/select2.amd.full.js @@ -192,6 +192,18 @@ define('select2/data/select',[ } } + SelectAdapter.prototype.bind = function (container, $container) { + var self = this; + + container.on("select", function (params) { + var current = self.current(function (data) { + // + }); + + self.select(params.data); + }); + } + SelectAdapter.prototype.query = function (params, callback) { var data = []; var self = this; @@ -305,7 +317,7 @@ define('select2/results',[ return $option; } - Results.prototype.bind = function ($container) { + Results.prototype.bind = function (container, $container) { var self = this; this.on("results:all", function (data) { @@ -390,7 +402,7 @@ define('select2/selection/single',[ return $selection; } - SingleSelection.prototype.bind = function ($container) { + SingleSelection.prototype.bind = function (container, $container) { var self = this; this.$selection.on('click', function (evt) { @@ -398,6 +410,10 @@ define('select2/selection/single',[ originalEvent: evt }); }); + + container.on("selection:update", function (params) { + self.update(params.data); + }) } SingleSelection.prototype.clear = function () { @@ -448,7 +464,7 @@ define('select2/selection/multiple',[ return $selection; } - MultipleSelection.prototype.bind = function ($container) { + MultipleSelection.prototype.bind = function (container, $container) { var self = this; this.$selection.on('click', function (evt) { @@ -456,6 +472,10 @@ define('select2/selection/multiple',[ originalEvent: evt }); }); + + container.on("selection:update", function (params) { + self.update(params.data); + }); } MultipleSelection.prototype.clear = function () { @@ -573,12 +593,15 @@ define('select2/core',[ var self = this; - this.selection.bind($container); - this.results.bind($container); + this.data.bind(this, $container); + this.selection.bind(this, $container); + this.results.bind(this, $container); this.$element.on("change", function () { self.data.current(function (data) { - self.selection.update(data); + self.trigger("selection:update", { + data: data + }); }); }); @@ -587,7 +610,8 @@ define('select2/core',[ }); this.results.on("selected", function (params) { - self.data.select(params.data); + self.trigger("select", params); + $container.removeClass("open"); }); diff --git a/dist/js/select2.amd.js b/dist/js/select2.amd.js index e2738ebf..b10bcbca 100644 --- a/dist/js/select2.amd.js +++ b/dist/js/select2.amd.js @@ -192,6 +192,18 @@ define('select2/data/select',[ } } + SelectAdapter.prototype.bind = function (container, $container) { + var self = this; + + container.on("select", function (params) { + var current = self.current(function (data) { + // + }); + + self.select(params.data); + }); + } + SelectAdapter.prototype.query = function (params, callback) { var data = []; var self = this; @@ -305,7 +317,7 @@ define('select2/results',[ return $option; } - Results.prototype.bind = function ($container) { + Results.prototype.bind = function (container, $container) { var self = this; this.on("results:all", function (data) { @@ -390,7 +402,7 @@ define('select2/selection/single',[ return $selection; } - SingleSelection.prototype.bind = function ($container) { + SingleSelection.prototype.bind = function (container, $container) { var self = this; this.$selection.on('click', function (evt) { @@ -398,6 +410,10 @@ define('select2/selection/single',[ originalEvent: evt }); }); + + container.on("selection:update", function (params) { + self.update(params.data); + }) } SingleSelection.prototype.clear = function () { @@ -448,7 +464,7 @@ define('select2/selection/multiple',[ return $selection; } - MultipleSelection.prototype.bind = function ($container) { + MultipleSelection.prototype.bind = function (container, $container) { var self = this; this.$selection.on('click', function (evt) { @@ -456,6 +472,10 @@ define('select2/selection/multiple',[ originalEvent: evt }); }); + + container.on("selection:update", function (params) { + self.update(params.data); + }); } MultipleSelection.prototype.clear = function () { @@ -573,12 +593,15 @@ define('select2/core',[ var self = this; - this.selection.bind($container); - this.results.bind($container); + this.data.bind(this, $container); + this.selection.bind(this, $container); + this.results.bind(this, $container); this.$element.on("change", function () { self.data.current(function (data) { - self.selection.update(data); + self.trigger("selection:update", { + data: data + }); }); }); @@ -587,7 +610,8 @@ define('select2/core',[ }); this.results.on("selected", function (params) { - self.data.select(params.data); + self.trigger("select", params); + $container.removeClass("open"); }); diff --git a/dist/js/select2.full.js b/dist/js/select2.full.js index f61d2daa..379515fe 100644 --- a/dist/js/select2.full.js +++ b/dist/js/select2.full.js @@ -9729,6 +9729,18 @@ define('select2/data/select',[ } } + SelectAdapter.prototype.bind = function (container, $container) { + var self = this; + + container.on("select", function (params) { + var current = self.current(function (data) { + // + }); + + self.select(params.data); + }); + } + SelectAdapter.prototype.query = function (params, callback) { var data = []; var self = this; @@ -9842,7 +9854,7 @@ define('select2/results',[ return $option; } - Results.prototype.bind = function ($container) { + Results.prototype.bind = function (container, $container) { var self = this; this.on("results:all", function (data) { @@ -9927,7 +9939,7 @@ define('select2/selection/single',[ return $selection; } - SingleSelection.prototype.bind = function ($container) { + SingleSelection.prototype.bind = function (container, $container) { var self = this; this.$selection.on('click', function (evt) { @@ -9935,6 +9947,10 @@ define('select2/selection/single',[ originalEvent: evt }); }); + + container.on("selection:update", function (params) { + self.update(params.data); + }) } SingleSelection.prototype.clear = function () { @@ -9985,7 +10001,7 @@ define('select2/selection/multiple',[ return $selection; } - MultipleSelection.prototype.bind = function ($container) { + MultipleSelection.prototype.bind = function (container, $container) { var self = this; this.$selection.on('click', function (evt) { @@ -9993,6 +10009,10 @@ define('select2/selection/multiple',[ originalEvent: evt }); }); + + container.on("selection:update", function (params) { + self.update(params.data); + }); } MultipleSelection.prototype.clear = function () { @@ -10110,12 +10130,15 @@ define('select2/core',[ var self = this; - this.selection.bind($container); - this.results.bind($container); + this.data.bind(this, $container); + this.selection.bind(this, $container); + this.results.bind(this, $container); this.$element.on("change", function () { self.data.current(function (data) { - self.selection.update(data); + self.trigger("selection:update", { + data: data + }); }); }); @@ -10124,7 +10147,8 @@ define('select2/core',[ }); this.results.on("selected", function (params) { - self.data.select(params.data); + self.trigger("select", params); + $container.removeClass("open"); }); diff --git a/dist/js/select2.js b/dist/js/select2.js index 125ee08a..95c3adfa 100644 --- a/dist/js/select2.js +++ b/dist/js/select2.js @@ -620,6 +620,18 @@ define('select2/data/select',[ } } + SelectAdapter.prototype.bind = function (container, $container) { + var self = this; + + container.on("select", function (params) { + var current = self.current(function (data) { + // + }); + + self.select(params.data); + }); + } + SelectAdapter.prototype.query = function (params, callback) { var data = []; var self = this; @@ -733,7 +745,7 @@ define('select2/results',[ return $option; } - Results.prototype.bind = function ($container) { + Results.prototype.bind = function (container, $container) { var self = this; this.on("results:all", function (data) { @@ -818,7 +830,7 @@ define('select2/selection/single',[ return $selection; } - SingleSelection.prototype.bind = function ($container) { + SingleSelection.prototype.bind = function (container, $container) { var self = this; this.$selection.on('click', function (evt) { @@ -826,6 +838,10 @@ define('select2/selection/single',[ originalEvent: evt }); }); + + container.on("selection:update", function (params) { + self.update(params.data); + }) } SingleSelection.prototype.clear = function () { @@ -876,7 +892,7 @@ define('select2/selection/multiple',[ return $selection; } - MultipleSelection.prototype.bind = function ($container) { + MultipleSelection.prototype.bind = function (container, $container) { var self = this; this.$selection.on('click', function (evt) { @@ -884,6 +900,10 @@ define('select2/selection/multiple',[ originalEvent: evt }); }); + + container.on("selection:update", function (params) { + self.update(params.data); + }); } MultipleSelection.prototype.clear = function () { @@ -1001,12 +1021,15 @@ define('select2/core',[ var self = this; - this.selection.bind($container); - this.results.bind($container); + this.data.bind(this, $container); + this.selection.bind(this, $container); + this.results.bind(this, $container); this.$element.on("change", function () { self.data.current(function (data) { - self.selection.update(data); + self.trigger("selection:update", { + data: data + }); }); }); @@ -1015,7 +1038,8 @@ define('select2/core',[ }); this.results.on("selected", function (params) { - self.data.select(params.data); + self.trigger("select", params); + $container.removeClass("open"); }); diff --git a/playground/basic/decorators.html b/playground/basic/decorators.html index 706b9b5f..8e6f3d24 100644 --- a/playground/basic/decorators.html +++ b/playground/basic/decorators.html @@ -171,10 +171,10 @@ require(["select2/core", "select2/utils", "select2/selection/single", return $selection; }; - ClearSelection.prototype.bind = function (decorated, $container) { + ClearSelection.prototype.bind = function (decorated, container, $container) { var self = this; - decorated.call(this, $container); + decorated.call(this, container, $container); this.$container = $container; diff --git a/src/js/select2/core.js b/src/js/select2/core.js index 5717c02c..792c086d 100644 --- a/src/js/select2/core.js +++ b/src/js/select2/core.js @@ -49,12 +49,15 @@ define([ var self = this; - this.selection.bind($container); - this.results.bind($container); + this.data.bind(this, $container); + this.selection.bind(this, $container); + this.results.bind(this, $container); this.$element.on("change", function () { self.data.current(function (data) { - self.selection.update(data); + self.trigger("selection:update", { + data: data + }); }); }); @@ -63,7 +66,8 @@ define([ }); this.results.on("selected", function (params) { - self.data.select(params.data); + self.trigger("select", params); + $container.removeClass("open"); }); diff --git a/src/js/select2/data/select.js b/src/js/select2/data/select.js index 804a65ee..5ee72bee 100644 --- a/src/js/select2/data/select.js +++ b/src/js/select2/data/select.js @@ -54,6 +54,18 @@ define([ } } + SelectAdapter.prototype.bind = function (container, $container) { + var self = this; + + container.on("select", function (params) { + var current = self.current(function (data) { + // + }); + + self.select(params.data); + }); + } + SelectAdapter.prototype.query = function (params, callback) { var data = []; var self = this; diff --git a/src/js/select2/results.js b/src/js/select2/results.js index 5532e410..1d274c03 100644 --- a/src/js/select2/results.js +++ b/src/js/select2/results.js @@ -70,7 +70,7 @@ define([ return $option; } - Results.prototype.bind = function ($container) { + Results.prototype.bind = function (container, $container) { var self = this; this.on("results:all", function (data) { diff --git a/src/js/select2/selection/multiple.js b/src/js/select2/selection/multiple.js index 5cf7f6f2..7b396f79 100644 --- a/src/js/select2/selection/multiple.js +++ b/src/js/select2/selection/multiple.js @@ -22,7 +22,7 @@ define([ return $selection; } - MultipleSelection.prototype.bind = function ($container) { + MultipleSelection.prototype.bind = function (container, $container) { var self = this; this.$selection.on('click', function (evt) { @@ -30,6 +30,10 @@ define([ originalEvent: evt }); }); + + container.on("selection:update", function (params) { + self.update(params.data); + }); } MultipleSelection.prototype.clear = function () { diff --git a/src/js/select2/selection/single.js b/src/js/select2/selection/single.js index fc8c7801..86a42184 100644 --- a/src/js/select2/selection/single.js +++ b/src/js/select2/selection/single.js @@ -22,7 +22,7 @@ define([ return $selection; } - SingleSelection.prototype.bind = function ($container) { + SingleSelection.prototype.bind = function (container, $container) { var self = this; this.$selection.on('click', function (evt) { @@ -30,6 +30,10 @@ define([ originalEvent: evt }); }); + + container.on("selection:update", function (params) { + self.update(params.data); + }) } SingleSelection.prototype.clear = function () { diff --git a/tests/utils/decorator-tests.js b/tests/utils/decorator-tests.js index 961cb85d..7bdcd783 100644 --- a/tests/utils/decorator-tests.js +++ b/tests/utils/decorator-tests.js @@ -2,7 +2,7 @@ module("Decorators") var Utils = require("select2/utils"); -test("overridden", function (assert) { +test("overridden - method", function (assert) { function BaseClass () {}; BaseClass.prototype.hello = function () { @@ -47,7 +47,7 @@ test("overridden - constructor", function (assert) { assert.ok(!inst.inherited); }); -test("not overridden", function (assert) { +test("not overridden - method", function (assert) { function BaseClass () {}; BaseClass.prototype.hello = function () { @@ -89,20 +89,14 @@ test("not overridden - constructor", function (assert) { assert.ok(inst.called); }); -test("inherited", function (assert) { - function BaseClass () { - this.inherited = true; - }; +test("inherited - method", function (assert) { + function BaseClass () { }; BaseClass.prototype.hello = function () { return "A"; } - function DecoratorClass (decorated) { - this.called = true; - - decorated.call(this); - }; + function DecoratorClass (decorated) { }; DecoratorClass.prototype.hello = function (decorated) { return "B" + decorated.call(this) + "C";