Browse Source

Added a base class for the selection container

Kevin Brown 10 năm trước cách đây
mục cha
commit
e601e33ff3

+ 44 - 10
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;
 });
 

+ 44 - 10
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;
 });
 

+ 44 - 10
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;
 });
 

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist/js/select2.full.min.js


+ 44 - 10
dist/js/select2.js

@@ -735,17 +735,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 = $(
@@ -762,6 +791,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) {
@@ -807,8 +838,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;
@@ -816,7 +848,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 = $(
@@ -833,6 +865,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
@@ -850,10 +884,6 @@ define('select2/selection/multiple',[
         data: data
       });
     });
-
-    container.on('selection:update', function (params) {
-      self.update(params.data);
-    });
   };
 
   MultipleSelection.prototype.clear = function () {
@@ -961,6 +991,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;
 });
 

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
dist/js/select2.min.js


+ 4 - 0
src/js/select2/data/base.js

@@ -15,5 +15,9 @@ define([
     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;
 });

+ 30 - 0
src/js/select2/selection/base.js

@@ -0,0 +1,30 @@
+define([
+  '../utils'
+], function (Utils) {
+  function BaseSelection ($element, options) {
+    this.$element = $element;
+    this.options = options;
+
+    BaseSelection.__super__.constructor.call(this);
+  }
+
+  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;
+});

+ 5 - 6
src/js/select2/selection/multiple.js

@@ -1,6 +1,7 @@
 define([
+  './base',
   '../utils'
-], function (Utils) {
+], function (BaseSelection, Utils) {
   function MultipleSelection ($element, options) {
     this.$element = $element;
     this.options = options;
@@ -8,7 +9,7 @@ define([
     MultipleSelection.__super__.constructor.call(this);
   }
 
-  Utils.Extend(MultipleSelection, Utils.Observable);
+  Utils.Extend(MultipleSelection, BaseSelection);
 
   MultipleSelection.prototype.render = function () {
     var $selection = $(
@@ -25,6 +26,8 @@ define([
   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
@@ -42,10 +45,6 @@ define([
         data: data
       });
     });
-
-    container.on('selection:update', function (params) {
-      self.update(params.data);
-    });
   };
 
   MultipleSelection.prototype.clear = function () {

+ 7 - 7
src/js/select2/selection/single.js

@@ -1,14 +1,12 @@
 define([
+  './base',
   '../utils'
-], function (Utils) {
-  function SingleSelection ($element, options) {
-    this.$element = $element;
-    this.options = options;
-
-    SingleSelection.__super__.constructor.call(this);
+], function (BaseSelection, Utils) {
+  function SingleSelection () {
+    SingleSelection.__super__.constructor.apply(this, arguments);
   }
 
-  Utils.Extend(SingleSelection, Utils.Observable);
+  Utils.Extend(SingleSelection, BaseSelection);
 
   SingleSelection.prototype.render = function () {
     var $selection = $(
@@ -25,6 +23,8 @@ define([
   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) {

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác