diff --git a/dist/js/select2.amd.full.js b/dist/js/select2.amd.full.js index 18be66cc..8a9a6c2c 100644 --- a/dist/js/select2.amd.full.js +++ b/dist/js/select2.amd.full.js @@ -306,17 +306,46 @@ define('select2/results',[ return Results; }); -define('select2/selection/single',[ +define('select2/selection/base',[ '../utils' ], function (Utils) { - function SingleSelection ($element, options) { + function BaseSelection ($element, options) { this.$element = $element; this.options = options; - SingleSelection.__super__.constructor.call(this); + BaseSelection.__super__.constructor.call(this); } - Utils.Extend(SingleSelection, Utils.Observable); + Utils.Extend(BaseSelection, Utils.Observable); + + BaseSelection.prototype.render = function () { + throw new Error('The `render` method must be defined in child classes.'); + }; + + BaseSelection.prototype.bind = function (container, $container) { + var self = this; + + container.on('selection:update', function (params) { + self.update(params.data); + }); + }; + + BaseSelection.prototype.update = function (data) { + throw new Error('The `update` method must be defined in child classes.'); + }; + + return BaseSelection; +}); + +define('select2/selection/single',[ + './base', + '../utils' +], function (BaseSelection, Utils) { + function SingleSelection () { + SingleSelection.__super__.constructor.apply(this, arguments); + } + + Utils.Extend(SingleSelection, BaseSelection); SingleSelection.prototype.render = function () { var $selection = $( @@ -333,6 +362,8 @@ define('select2/selection/single',[ SingleSelection.prototype.bind = function (container, $container) { var self = this; + SingleSelection.__super__.bind.apply(this, arguments); + this.$selection.on('mousedown', function (evt) { // Only respond to left clicks if (evt.which !== 1) { @@ -378,8 +409,9 @@ define('select2/selection/single',[ }); define('select2/selection/multiple',[ + './base', '../utils' -], function (Utils) { +], function (BaseSelection, Utils) { function MultipleSelection ($element, options) { this.$element = $element; this.options = options; @@ -387,7 +419,7 @@ define('select2/selection/multiple',[ MultipleSelection.__super__.constructor.call(this); } - Utils.Extend(MultipleSelection, Utils.Observable); + Utils.Extend(MultipleSelection, BaseSelection); MultipleSelection.prototype.render = function () { var $selection = $( @@ -404,6 +436,8 @@ define('select2/selection/multiple',[ MultipleSelection.prototype.bind = function (container, $container) { var self = this; + MultipleSelection.__super__.bind.apply(this, arguments); + this.$selection.on('click', function (evt) { self.trigger('toggle', { originalEvent: evt @@ -421,10 +455,6 @@ define('select2/selection/multiple',[ data: data }); }); - - container.on('selection:update', function (params) { - self.update(params.data); - }); }; MultipleSelection.prototype.clear = function () { @@ -532,6 +562,10 @@ define('select2/data/base',[ throw new Error('The `query` method must be defined in child classes.'); }; + BaseAdapter.prototype.bind = function (container, $container) { + // Can be implemented in subclasses + }; + return BaseAdapter; }); diff --git a/dist/js/select2.amd.js b/dist/js/select2.amd.js index 18be66cc..8a9a6c2c 100644 --- a/dist/js/select2.amd.js +++ b/dist/js/select2.amd.js @@ -306,17 +306,46 @@ define('select2/results',[ return Results; }); -define('select2/selection/single',[ +define('select2/selection/base',[ '../utils' ], function (Utils) { - function SingleSelection ($element, options) { + function BaseSelection ($element, options) { this.$element = $element; this.options = options; - SingleSelection.__super__.constructor.call(this); + BaseSelection.__super__.constructor.call(this); } - Utils.Extend(SingleSelection, Utils.Observable); + Utils.Extend(BaseSelection, Utils.Observable); + + BaseSelection.prototype.render = function () { + throw new Error('The `render` method must be defined in child classes.'); + }; + + BaseSelection.prototype.bind = function (container, $container) { + var self = this; + + container.on('selection:update', function (params) { + self.update(params.data); + }); + }; + + BaseSelection.prototype.update = function (data) { + throw new Error('The `update` method must be defined in child classes.'); + }; + + return BaseSelection; +}); + +define('select2/selection/single',[ + './base', + '../utils' +], function (BaseSelection, Utils) { + function SingleSelection () { + SingleSelection.__super__.constructor.apply(this, arguments); + } + + Utils.Extend(SingleSelection, BaseSelection); SingleSelection.prototype.render = function () { var $selection = $( @@ -333,6 +362,8 @@ define('select2/selection/single',[ SingleSelection.prototype.bind = function (container, $container) { var self = this; + SingleSelection.__super__.bind.apply(this, arguments); + this.$selection.on('mousedown', function (evt) { // Only respond to left clicks if (evt.which !== 1) { @@ -378,8 +409,9 @@ define('select2/selection/single',[ }); define('select2/selection/multiple',[ + './base', '../utils' -], function (Utils) { +], function (BaseSelection, Utils) { function MultipleSelection ($element, options) { this.$element = $element; this.options = options; @@ -387,7 +419,7 @@ define('select2/selection/multiple',[ MultipleSelection.__super__.constructor.call(this); } - Utils.Extend(MultipleSelection, Utils.Observable); + Utils.Extend(MultipleSelection, BaseSelection); MultipleSelection.prototype.render = function () { var $selection = $( @@ -404,6 +436,8 @@ define('select2/selection/multiple',[ MultipleSelection.prototype.bind = function (container, $container) { var self = this; + MultipleSelection.__super__.bind.apply(this, arguments); + this.$selection.on('click', function (evt) { self.trigger('toggle', { originalEvent: evt @@ -421,10 +455,6 @@ define('select2/selection/multiple',[ data: data }); }); - - container.on('selection:update', function (params) { - self.update(params.data); - }); }; MultipleSelection.prototype.clear = function () { @@ -532,6 +562,10 @@ define('select2/data/base',[ throw new Error('The `query` method must be defined in child classes.'); }; + BaseAdapter.prototype.bind = function (container, $container) { + // Can be implemented in subclasses + }; + return BaseAdapter; }); diff --git a/dist/js/select2.full.js b/dist/js/select2.full.js index 68f1e70a..64e1c8e3 100644 --- a/dist/js/select2.full.js +++ b/dist/js/select2.full.js @@ -9844,17 +9844,46 @@ define('select2/results',[ return Results; }); -define('select2/selection/single',[ +define('select2/selection/base',[ '../utils' ], function (Utils) { - function SingleSelection ($element, options) { + function BaseSelection ($element, options) { this.$element = $element; this.options = options; - SingleSelection.__super__.constructor.call(this); + BaseSelection.__super__.constructor.call(this); } - Utils.Extend(SingleSelection, Utils.Observable); + Utils.Extend(BaseSelection, Utils.Observable); + + BaseSelection.prototype.render = function () { + throw new Error('The `render` method must be defined in child classes.'); + }; + + BaseSelection.prototype.bind = function (container, $container) { + var self = this; + + container.on('selection:update', function (params) { + self.update(params.data); + }); + }; + + BaseSelection.prototype.update = function (data) { + throw new Error('The `update` method must be defined in child classes.'); + }; + + return BaseSelection; +}); + +define('select2/selection/single',[ + './base', + '../utils' +], function (BaseSelection, Utils) { + function SingleSelection () { + SingleSelection.__super__.constructor.apply(this, arguments); + } + + Utils.Extend(SingleSelection, BaseSelection); SingleSelection.prototype.render = function () { var $selection = $( @@ -9871,6 +9900,8 @@ define('select2/selection/single',[ SingleSelection.prototype.bind = function (container, $container) { var self = this; + SingleSelection.__super__.bind.apply(this, arguments); + this.$selection.on('mousedown', function (evt) { // Only respond to left clicks if (evt.which !== 1) { @@ -9916,8 +9947,9 @@ define('select2/selection/single',[ }); define('select2/selection/multiple',[ + './base', '../utils' -], function (Utils) { +], function (BaseSelection, Utils) { function MultipleSelection ($element, options) { this.$element = $element; this.options = options; @@ -9925,7 +9957,7 @@ define('select2/selection/multiple',[ MultipleSelection.__super__.constructor.call(this); } - Utils.Extend(MultipleSelection, Utils.Observable); + Utils.Extend(MultipleSelection, BaseSelection); MultipleSelection.prototype.render = function () { var $selection = $( @@ -9942,6 +9974,8 @@ define('select2/selection/multiple',[ MultipleSelection.prototype.bind = function (container, $container) { var self = this; + MultipleSelection.__super__.bind.apply(this, arguments); + this.$selection.on('click', function (evt) { self.trigger('toggle', { originalEvent: evt @@ -9959,10 +9993,6 @@ define('select2/selection/multiple',[ data: data }); }); - - container.on('selection:update', function (params) { - self.update(params.data); - }); }; MultipleSelection.prototype.clear = function () { @@ -10070,6 +10100,10 @@ define('select2/data/base',[ throw new Error('The `query` method must be defined in child classes.'); }; + BaseAdapter.prototype.bind = function (container, $container) { + // Can be implemented in subclasses + }; + return BaseAdapter; }); diff --git a/dist/js/select2.full.min.js b/dist/js/select2.full.min.js index f068c138..127f5bdc 100644 --- a/dist/js/select2.full.min.js +++ b/dist/js/select2.full.min.js @@ -1,4 +1,4 @@ var requirejs,require,define;!function(a){function b(a,b){return r.call(a,b)}function c(a,b){var c,d,e,f,g,h,i,j,k,l,m,n=b&&b.split("/"),o=p.map,q=o&&o["*"]||{};if(a&&"."===a.charAt(0))if(b){for(n=n.slice(0,n.length-1),a=a.split("/"),g=a.length-1,p.nodeIdCompat&&t.test(a[g])&&(a[g]=a[g].replace(t,"")),a=n.concat(a),k=0;k0&&(a.splice(k-1,2),k-=2)}a=a.join("/")}else 0===a.indexOf("./")&&(a=a.substring(2));if((n||q)&&o){for(c=a.split("/"),k=c.length;k>0;k-=1){if(d=c.slice(0,k).join("/"),n)for(l=n.length;l>0;l-=1)if(e=o[n.slice(0,l).join("/")],e&&(e=e[d])){f=e,h=k;break}if(f)break;!i&&q&&q[d]&&(i=q[d],j=k)}!f&&i&&(f=i,h=j),f&&(c.splice(0,h,f),a=c.join("/"))}return a}function d(b,c){return function(){return k.apply(a,s.call(arguments,0).concat([b,c]))}}function e(a){return function(b){return c(b,a)}}function f(a){return function(b){n[a]=b}}function g(c){if(b(o,c)){var d=o[c];delete o[c],q[c]=!0,j.apply(a,d)}if(!b(n,c)&&!b(q,c))throw new Error("No "+c);return n[c]}function h(a){var b,c=a?a.indexOf("!"):-1;return c>-1&&(b=a.substring(0,c),a=a.substring(c+1,a.length)),[b,a]}function i(a){return function(){return p&&p.config&&p.config[a]||{}}}var j,k,l,m,n={},o={},p={},q={},r=Object.prototype.hasOwnProperty,s=[].slice,t=/\.js$/;l=function(a,b){var d,f=h(a),i=f[0];return a=f[1],i&&(i=c(i,b),d=g(i)),i?a=d&&d.normalize?d.normalize(a,e(b)):c(a,b):(a=c(a,b),f=h(a),i=f[0],a=f[1],i&&(d=g(i))),{f:i?i+"!"+a:a,n:a,pr:i,p:d}},m={require:function(a){return d(a)},exports:function(a){var b=n[a];return"undefined"!=typeof b?b:n[a]={}},module:function(a){return{id:a,uri:"",exports:n[a],config:i(a)}}},j=function(c,e,h,i){var j,k,p,r,s,t,u=[],v=typeof h;if(i=i||c,"undefined"===v||"function"===v){for(e=!e.length&&h.length?["require","exports","module"]:e,s=0;s0&&b-1 in a}function d(a,b,c){if(ab.isFunction(b))return ab.grep(a,function(a,d){return!!b.call(a,d,a)!==c});if(b.nodeType)return ab.grep(a,function(a){return a===b!==c});if("string"==typeof b){if(hb.test(b))return ab.filter(b,a,c);b=ab.filter(b,a)}return ab.grep(a,function(a){return U.call(b,a)>=0!==c})}function e(a,b){for(;(a=a[b])&&1!==a.nodeType;);return a}function f(a){var b=ob[a]={};return ab.each(a.match(nb)||[],function(a,c){b[c]=!0}),b}function g(){$.removeEventListener("DOMContentLoaded",g,!1),a.removeEventListener("load",g,!1),ab.ready()}function h(){Object.defineProperty(this.cache={},0,{get:function(){return{}}}),this.expando=ab.expando+Math.random()}function i(a,b,c){var d;if(void 0===c&&1===a.nodeType)if(d="data-"+b.replace(ub,"-$1").toLowerCase(),c=a.getAttribute(d),"string"==typeof c){try{c="true"===c?!0:"false"===c?!1:"null"===c?null:+c+""===c?+c:tb.test(c)?ab.parseJSON(c):c}catch(e){}sb.set(a,b,c)}else c=void 0;return c}function j(){return!0}function k(){return!1}function l(){try{return $.activeElement}catch(a){}}function m(a,b){return ab.nodeName(a,"table")&&ab.nodeName(11!==b.nodeType?b:b.firstChild,"tr")?a.getElementsByTagName("tbody")[0]||a.appendChild(a.ownerDocument.createElement("tbody")):a}function n(a){return a.type=(null!==a.getAttribute("type"))+"/"+a.type,a}function o(a){var b=Kb.exec(a.type);return b?a.type=b[1]:a.removeAttribute("type"),a}function p(a,b){for(var c=0,d=a.length;d>c;c++)rb.set(a[c],"globalEval",!b||rb.get(b[c],"globalEval"))}function q(a,b){var c,d,e,f,g,h,i,j;if(1===b.nodeType){if(rb.hasData(a)&&(f=rb.access(a),g=rb.set(b,f),j=f.events)){delete g.handle,g.events={};for(e in j)for(c=0,d=j[e].length;d>c;c++)ab.event.add(b,e,j[e][c])}sb.hasData(a)&&(h=sb.access(a),i=ab.extend({},h),sb.set(b,i))}}function r(a,b){var c=a.getElementsByTagName?a.getElementsByTagName(b||"*"):a.querySelectorAll?a.querySelectorAll(b||"*"):[];return void 0===b||b&&ab.nodeName(a,b)?ab.merge([a],c):c}function s(a,b){var c=b.nodeName.toLowerCase();"input"===c&&yb.test(a.type)?b.checked=a.checked:("input"===c||"textarea"===c)&&(b.defaultValue=a.defaultValue)}function t(b,c){var d=ab(c.createElement(b)).appendTo(c.body),e=a.getDefaultComputedStyle?a.getDefaultComputedStyle(d[0]).display:ab.css(d[0],"display");return d.detach(),e}function u(a){var b=$,c=Ob[a];return c||(c=t(a,b),"none"!==c&&c||(Nb=(Nb||ab("