1
0
mirror of synced 2024-11-25 22:36:03 +03:00

Limit the explicit coupling between adapters

This commit is contained in:
Kevin Brown 2014-08-30 18:34:41 -04:00
parent 0081716841
commit 94b460f930
11 changed files with 162 additions and 48 deletions

View File

@ -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) { SelectAdapter.prototype.query = function (params, callback) {
var data = []; var data = [];
var self = this; var self = this;
@ -305,7 +317,7 @@ define('select2/results',[
return $option; return $option;
} }
Results.prototype.bind = function ($container) { Results.prototype.bind = function (container, $container) {
var self = this; var self = this;
this.on("results:all", function (data) { this.on("results:all", function (data) {
@ -390,7 +402,7 @@ define('select2/selection/single',[
return $selection; return $selection;
} }
SingleSelection.prototype.bind = function ($container) { SingleSelection.prototype.bind = function (container, $container) {
var self = this; var self = this;
this.$selection.on('click', function (evt) { this.$selection.on('click', function (evt) {
@ -398,6 +410,10 @@ define('select2/selection/single',[
originalEvent: evt originalEvent: evt
}); });
}); });
container.on("selection:update", function (params) {
self.update(params.data);
})
} }
SingleSelection.prototype.clear = function () { SingleSelection.prototype.clear = function () {
@ -448,7 +464,7 @@ define('select2/selection/multiple',[
return $selection; return $selection;
} }
MultipleSelection.prototype.bind = function ($container) { MultipleSelection.prototype.bind = function (container, $container) {
var self = this; var self = this;
this.$selection.on('click', function (evt) { this.$selection.on('click', function (evt) {
@ -456,6 +472,10 @@ define('select2/selection/multiple',[
originalEvent: evt originalEvent: evt
}); });
}); });
container.on("selection:update", function (params) {
self.update(params.data);
});
} }
MultipleSelection.prototype.clear = function () { MultipleSelection.prototype.clear = function () {
@ -573,12 +593,15 @@ define('select2/core',[
var self = this; var self = this;
this.selection.bind($container); this.data.bind(this, $container);
this.results.bind($container); this.selection.bind(this, $container);
this.results.bind(this, $container);
this.$element.on("change", function () { this.$element.on("change", function () {
self.data.current(function (data) { 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) { this.results.on("selected", function (params) {
self.data.select(params.data); self.trigger("select", params);
$container.removeClass("open"); $container.removeClass("open");
}); });

View File

@ -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) { SelectAdapter.prototype.query = function (params, callback) {
var data = []; var data = [];
var self = this; var self = this;
@ -305,7 +317,7 @@ define('select2/results',[
return $option; return $option;
} }
Results.prototype.bind = function ($container) { Results.prototype.bind = function (container, $container) {
var self = this; var self = this;
this.on("results:all", function (data) { this.on("results:all", function (data) {
@ -390,7 +402,7 @@ define('select2/selection/single',[
return $selection; return $selection;
} }
SingleSelection.prototype.bind = function ($container) { SingleSelection.prototype.bind = function (container, $container) {
var self = this; var self = this;
this.$selection.on('click', function (evt) { this.$selection.on('click', function (evt) {
@ -398,6 +410,10 @@ define('select2/selection/single',[
originalEvent: evt originalEvent: evt
}); });
}); });
container.on("selection:update", function (params) {
self.update(params.data);
})
} }
SingleSelection.prototype.clear = function () { SingleSelection.prototype.clear = function () {
@ -448,7 +464,7 @@ define('select2/selection/multiple',[
return $selection; return $selection;
} }
MultipleSelection.prototype.bind = function ($container) { MultipleSelection.prototype.bind = function (container, $container) {
var self = this; var self = this;
this.$selection.on('click', function (evt) { this.$selection.on('click', function (evt) {
@ -456,6 +472,10 @@ define('select2/selection/multiple',[
originalEvent: evt originalEvent: evt
}); });
}); });
container.on("selection:update", function (params) {
self.update(params.data);
});
} }
MultipleSelection.prototype.clear = function () { MultipleSelection.prototype.clear = function () {
@ -573,12 +593,15 @@ define('select2/core',[
var self = this; var self = this;
this.selection.bind($container); this.data.bind(this, $container);
this.results.bind($container); this.selection.bind(this, $container);
this.results.bind(this, $container);
this.$element.on("change", function () { this.$element.on("change", function () {
self.data.current(function (data) { 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) { this.results.on("selected", function (params) {
self.data.select(params.data); self.trigger("select", params);
$container.removeClass("open"); $container.removeClass("open");
}); });

View File

@ -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) { SelectAdapter.prototype.query = function (params, callback) {
var data = []; var data = [];
var self = this; var self = this;
@ -9842,7 +9854,7 @@ define('select2/results',[
return $option; return $option;
} }
Results.prototype.bind = function ($container) { Results.prototype.bind = function (container, $container) {
var self = this; var self = this;
this.on("results:all", function (data) { this.on("results:all", function (data) {
@ -9927,7 +9939,7 @@ define('select2/selection/single',[
return $selection; return $selection;
} }
SingleSelection.prototype.bind = function ($container) { SingleSelection.prototype.bind = function (container, $container) {
var self = this; var self = this;
this.$selection.on('click', function (evt) { this.$selection.on('click', function (evt) {
@ -9935,6 +9947,10 @@ define('select2/selection/single',[
originalEvent: evt originalEvent: evt
}); });
}); });
container.on("selection:update", function (params) {
self.update(params.data);
})
} }
SingleSelection.prototype.clear = function () { SingleSelection.prototype.clear = function () {
@ -9985,7 +10001,7 @@ define('select2/selection/multiple',[
return $selection; return $selection;
} }
MultipleSelection.prototype.bind = function ($container) { MultipleSelection.prototype.bind = function (container, $container) {
var self = this; var self = this;
this.$selection.on('click', function (evt) { this.$selection.on('click', function (evt) {
@ -9993,6 +10009,10 @@ define('select2/selection/multiple',[
originalEvent: evt originalEvent: evt
}); });
}); });
container.on("selection:update", function (params) {
self.update(params.data);
});
} }
MultipleSelection.prototype.clear = function () { MultipleSelection.prototype.clear = function () {
@ -10110,12 +10130,15 @@ define('select2/core',[
var self = this; var self = this;
this.selection.bind($container); this.data.bind(this, $container);
this.results.bind($container); this.selection.bind(this, $container);
this.results.bind(this, $container);
this.$element.on("change", function () { this.$element.on("change", function () {
self.data.current(function (data) { 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) { this.results.on("selected", function (params) {
self.data.select(params.data); self.trigger("select", params);
$container.removeClass("open"); $container.removeClass("open");
}); });

38
dist/js/select2.js vendored
View File

@ -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) { SelectAdapter.prototype.query = function (params, callback) {
var data = []; var data = [];
var self = this; var self = this;
@ -733,7 +745,7 @@ define('select2/results',[
return $option; return $option;
} }
Results.prototype.bind = function ($container) { Results.prototype.bind = function (container, $container) {
var self = this; var self = this;
this.on("results:all", function (data) { this.on("results:all", function (data) {
@ -818,7 +830,7 @@ define('select2/selection/single',[
return $selection; return $selection;
} }
SingleSelection.prototype.bind = function ($container) { SingleSelection.prototype.bind = function (container, $container) {
var self = this; var self = this;
this.$selection.on('click', function (evt) { this.$selection.on('click', function (evt) {
@ -826,6 +838,10 @@ define('select2/selection/single',[
originalEvent: evt originalEvent: evt
}); });
}); });
container.on("selection:update", function (params) {
self.update(params.data);
})
} }
SingleSelection.prototype.clear = function () { SingleSelection.prototype.clear = function () {
@ -876,7 +892,7 @@ define('select2/selection/multiple',[
return $selection; return $selection;
} }
MultipleSelection.prototype.bind = function ($container) { MultipleSelection.prototype.bind = function (container, $container) {
var self = this; var self = this;
this.$selection.on('click', function (evt) { this.$selection.on('click', function (evt) {
@ -884,6 +900,10 @@ define('select2/selection/multiple',[
originalEvent: evt originalEvent: evt
}); });
}); });
container.on("selection:update", function (params) {
self.update(params.data);
});
} }
MultipleSelection.prototype.clear = function () { MultipleSelection.prototype.clear = function () {
@ -1001,12 +1021,15 @@ define('select2/core',[
var self = this; var self = this;
this.selection.bind($container); this.data.bind(this, $container);
this.results.bind($container); this.selection.bind(this, $container);
this.results.bind(this, $container);
this.$element.on("change", function () { this.$element.on("change", function () {
self.data.current(function (data) { 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) { this.results.on("selected", function (params) {
self.data.select(params.data); self.trigger("select", params);
$container.removeClass("open"); $container.removeClass("open");
}); });

View File

@ -171,10 +171,10 @@ require(["select2/core", "select2/utils", "select2/selection/single",
return $selection; return $selection;
}; };
ClearSelection.prototype.bind = function (decorated, $container) { ClearSelection.prototype.bind = function (decorated, container, $container) {
var self = this; var self = this;
decorated.call(this, $container); decorated.call(this, container, $container);
this.$container = $container; this.$container = $container;

View File

@ -49,12 +49,15 @@ define([
var self = this; var self = this;
this.selection.bind($container); this.data.bind(this, $container);
this.results.bind($container); this.selection.bind(this, $container);
this.results.bind(this, $container);
this.$element.on("change", function () { this.$element.on("change", function () {
self.data.current(function (data) { 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) { this.results.on("selected", function (params) {
self.data.select(params.data); self.trigger("select", params);
$container.removeClass("open"); $container.removeClass("open");
}); });

View File

@ -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) { SelectAdapter.prototype.query = function (params, callback) {
var data = []; var data = [];
var self = this; var self = this;

View File

@ -70,7 +70,7 @@ define([
return $option; return $option;
} }
Results.prototype.bind = function ($container) { Results.prototype.bind = function (container, $container) {
var self = this; var self = this;
this.on("results:all", function (data) { this.on("results:all", function (data) {

View File

@ -22,7 +22,7 @@ define([
return $selection; return $selection;
} }
MultipleSelection.prototype.bind = function ($container) { MultipleSelection.prototype.bind = function (container, $container) {
var self = this; var self = this;
this.$selection.on('click', function (evt) { this.$selection.on('click', function (evt) {
@ -30,6 +30,10 @@ define([
originalEvent: evt originalEvent: evt
}); });
}); });
container.on("selection:update", function (params) {
self.update(params.data);
});
} }
MultipleSelection.prototype.clear = function () { MultipleSelection.prototype.clear = function () {

View File

@ -22,7 +22,7 @@ define([
return $selection; return $selection;
} }
SingleSelection.prototype.bind = function ($container) { SingleSelection.prototype.bind = function (container, $container) {
var self = this; var self = this;
this.$selection.on('click', function (evt) { this.$selection.on('click', function (evt) {
@ -30,6 +30,10 @@ define([
originalEvent: evt originalEvent: evt
}); });
}); });
container.on("selection:update", function (params) {
self.update(params.data);
})
} }
SingleSelection.prototype.clear = function () { SingleSelection.prototype.clear = function () {

View File

@ -2,7 +2,7 @@ module("Decorators")
var Utils = require("select2/utils"); var Utils = require("select2/utils");
test("overridden", function (assert) { test("overridden - method", function (assert) {
function BaseClass () {}; function BaseClass () {};
BaseClass.prototype.hello = function () { BaseClass.prototype.hello = function () {
@ -47,7 +47,7 @@ test("overridden - constructor", function (assert) {
assert.ok(!inst.inherited); assert.ok(!inst.inherited);
}); });
test("not overridden", function (assert) { test("not overridden - method", function (assert) {
function BaseClass () {}; function BaseClass () {};
BaseClass.prototype.hello = function () { BaseClass.prototype.hello = function () {
@ -89,20 +89,14 @@ test("not overridden - constructor", function (assert) {
assert.ok(inst.called); assert.ok(inst.called);
}); });
test("inherited", function (assert) { test("inherited - method", function (assert) {
function BaseClass () { function BaseClass () { };
this.inherited = true;
};
BaseClass.prototype.hello = function () { BaseClass.prototype.hello = function () {
return "A"; return "A";
} }
function DecoratorClass (decorated) { function DecoratorClass (decorated) { };
this.called = true;
decorated.call(this);
};
DecoratorClass.prototype.hello = function (decorated) { DecoratorClass.prototype.hello = function (decorated) {
return "B" + decorated.call(this) + "C"; return "B" + decorated.call(this) + "C";