diff --git a/dist/js/select2.amd.full.js b/dist/js/select2.amd.full.js index 778a2d89..517d024c 100644 --- a/dist/js/select2.amd.full.js +++ b/dist/js/select2.amd.full.js @@ -136,17 +136,38 @@ define('select2/utils',[], function () { return Utils; }); +define('select2/data/base',[ + '../utils' +], function (Utils) { + function BaseAdapter ($element, options) { + BaseAdapter.__super__.constructor.call(this); + } + + Utils.Extend(BaseAdapter, Utils.Observable); + + BaseAdapter.prototype.current = function (callback) { + throw new Error("The `current` method must be defined in child classes."); + } + + BaseAdapter.prototype.query = function (params, callback) { + throw new Error("The `query` method must be defined in child classes."); + } + + return BaseAdapter; +}); + define('select2/data/select',[ + './base', '../utils', 'jquery' -], function (Utils, $) { +], function (BaseAdapter, Utils, $) { function SelectAdapter ($element, options) { this.$element = $element; SelectAdapter.__super__.constructor.call(this); } - Utils.Extend(SelectAdapter, Utils.Observable); + Utils.Extend(SelectAdapter, BaseAdapter); SelectAdapter.prototype.current = function (callback) { var data = []; diff --git a/dist/js/select2.amd.js b/dist/js/select2.amd.js index 778a2d89..517d024c 100644 --- a/dist/js/select2.amd.js +++ b/dist/js/select2.amd.js @@ -136,17 +136,38 @@ define('select2/utils',[], function () { return Utils; }); +define('select2/data/base',[ + '../utils' +], function (Utils) { + function BaseAdapter ($element, options) { + BaseAdapter.__super__.constructor.call(this); + } + + Utils.Extend(BaseAdapter, Utils.Observable); + + BaseAdapter.prototype.current = function (callback) { + throw new Error("The `current` method must be defined in child classes."); + } + + BaseAdapter.prototype.query = function (params, callback) { + throw new Error("The `query` method must be defined in child classes."); + } + + return BaseAdapter; +}); + define('select2/data/select',[ + './base', '../utils', 'jquery' -], function (Utils, $) { +], function (BaseAdapter, Utils, $) { function SelectAdapter ($element, options) { this.$element = $element; SelectAdapter.__super__.constructor.call(this); } - Utils.Extend(SelectAdapter, Utils.Observable); + Utils.Extend(SelectAdapter, BaseAdapter); SelectAdapter.prototype.current = function (callback) { var data = []; diff --git a/dist/js/select2.full.js b/dist/js/select2.full.js index 0565aa39..8ab296bc 100644 --- a/dist/js/select2.full.js +++ b/dist/js/select2.full.js @@ -9673,17 +9673,38 @@ define('select2/utils',[], function () { return Utils; }); +define('select2/data/base',[ + '../utils' +], function (Utils) { + function BaseAdapter ($element, options) { + BaseAdapter.__super__.constructor.call(this); + } + + Utils.Extend(BaseAdapter, Utils.Observable); + + BaseAdapter.prototype.current = function (callback) { + throw new Error("The `current` method must be defined in child classes."); + } + + BaseAdapter.prototype.query = function (params, callback) { + throw new Error("The `query` method must be defined in child classes."); + } + + return BaseAdapter; +}); + define('select2/data/select',[ + './base', '../utils', 'jquery' -], function (Utils, $) { +], function (BaseAdapter, Utils, $) { function SelectAdapter ($element, options) { this.$element = $element; SelectAdapter.__super__.constructor.call(this); } - Utils.Extend(SelectAdapter, Utils.Observable); + Utils.Extend(SelectAdapter, BaseAdapter); SelectAdapter.prototype.current = function (callback) { var data = []; diff --git a/dist/js/select2.js b/dist/js/select2.js index 0d8af4d3..7bff98ee 100644 --- a/dist/js/select2.js +++ b/dist/js/select2.js @@ -564,17 +564,38 @@ define('select2/utils',[], function () { return Utils; }); +define('select2/data/base',[ + '../utils' +], function (Utils) { + function BaseAdapter ($element, options) { + BaseAdapter.__super__.constructor.call(this); + } + + Utils.Extend(BaseAdapter, Utils.Observable); + + BaseAdapter.prototype.current = function (callback) { + throw new Error("The `current` method must be defined in child classes."); + } + + BaseAdapter.prototype.query = function (params, callback) { + throw new Error("The `query` method must be defined in child classes."); + } + + return BaseAdapter; +}); + define('select2/data/select',[ + './base', '../utils', 'jquery' -], function (Utils, $) { +], function (BaseAdapter, Utils, $) { function SelectAdapter ($element, options) { this.$element = $element; SelectAdapter.__super__.constructor.call(this); } - Utils.Extend(SelectAdapter, Utils.Observable); + Utils.Extend(SelectAdapter, BaseAdapter); SelectAdapter.prototype.current = function (callback) { var data = []; diff --git a/src/js/select2/data/base.js b/src/js/select2/data/base.js new file mode 100644 index 00000000..a64298bc --- /dev/null +++ b/src/js/select2/data/base.js @@ -0,0 +1,19 @@ +define([ + '../utils' +], function (Utils) { + function BaseAdapter ($element, options) { + BaseAdapter.__super__.constructor.call(this); + } + + Utils.Extend(BaseAdapter, Utils.Observable); + + BaseAdapter.prototype.current = function (callback) { + throw new Error("The `current` method must be defined in child classes."); + } + + BaseAdapter.prototype.query = function (params, callback) { + throw new Error("The `query` method must be defined in child classes."); + } + + return BaseAdapter; +}); diff --git a/src/js/select2/data/select.js b/src/js/select2/data/select.js index a89697f1..6772f536 100644 --- a/src/js/select2/data/select.js +++ b/src/js/select2/data/select.js @@ -1,14 +1,15 @@ define([ + './base', '../utils', 'jquery' -], function (Utils, $) { +], function (BaseAdapter, Utils, $) { function SelectAdapter ($element, options) { this.$element = $element; SelectAdapter.__super__.constructor.call(this); } - Utils.Extend(SelectAdapter, Utils.Observable); + Utils.Extend(SelectAdapter, BaseAdapter); SelectAdapter.prototype.current = function (callback) { var data = []; diff --git a/tests/data/base-tests.js b/tests/data/base-tests.js new file mode 100644 index 00000000..31d3cecd --- /dev/null +++ b/tests/data/base-tests.js @@ -0,0 +1,29 @@ +module("Data adapters - Base") + +var BaseData = require("select2/data/base"); +var $ = require("jquery"); +var Options = require("select2/options"); + +var options = new Options({}); + +test("current is required", function (assert) { + var data = new BaseData($("#qunit-fixture select"), options); + + assert.throws( + function () { + data.current(function () {}); + }, + "current has no default implementation" + ) +}); + +test("query is required", function (assert) { + var data = new BaseData($("#qunit-fixture select"), options); + + assert.throws( + function () { + data.query({}, function () {}); + }, + "query has no default implementation" + ); +}); diff --git a/tests/data/base.html b/tests/data/base.html new file mode 100644 index 00000000..17dcbbe3 --- /dev/null +++ b/tests/data/base.html @@ -0,0 +1,20 @@ + + + + + + + +
+
+ +
+ + + + + + + + +