]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
split this._bindHandler for each event 8696/head
authorjk <j.koehler@modulingo.de>
Wed, 4 May 2016 20:11:23 +0000 (22:11 +0200)
committerjk <j.koehler@modulingo.de>
Wed, 4 May 2016 20:11:23 +0000 (22:11 +0200)
js/foundation.equalizer.js
test/visual/equalizer/equalizer-events.html

index 910099b1938c3d6759dfb91abd6e6ec701bf5a19..e28b203e5fa719118653afb8a6d5fb56370046aa 100644 (file)
@@ -38,7 +38,10 @@ class Equalizer {
     this.hasNested = this.$element.find('[data-equalizer]').length > 0;
     this.isNested = this.$element.parentsUntil(document.body, '[data-equalizer]').length > 0;
     this.isOn = false;
-    this._bindHandler = this._bindHandlers.bind(this);
+    this._bindHandler = {
+      onResizeMeBound: this._onResizeMe.bind(this),
+      onPostEqualizedBound: this._onPostEqualized.bind(this)
+    };
 
     var imgs = this.$element.find('img');
     var tooSmall;
@@ -63,15 +66,26 @@ class Equalizer {
    */
   _pauseEvents() {
     this.isOn = false;
-    this.$element.off('.zf.equalizer resizeme.zf.trigger',this._bindHandler);
+    this.$element.off({
+      '.zf.equalizer': this._bindHandler.onPostEqualizedBound,
+      'resizeme.zf.trigger': this._bindHandler.onResizeMeBound
+    });
   }
 
-  _bindHandlers(e) {
-    if (e.type === 'resizeme') {
-      this._reflow();
-    }else if (e.type === 'postequalized'){
-      if(e.target !== this.$element[0]){ this._reflow(); }
-    };
+  /**
+   * function to handle $elements resizeme.zf.trigger, with bound this on _bindHandler.onResizeMeBound
+   * @private
+   */
+  _onResizeMe(e) {
+    this._reflow();
+  }
+
+  /**
+   * function to handle $elements postequalized.zf.equalizer, with bound this on _bindHandler.onPostEqualizedBound
+   * @private
+   */
+  _onPostEqualized(e) {
+    if(e.target !== this.$element[0]){ this._reflow(); }
   }
 
   /**
@@ -82,9 +96,9 @@ class Equalizer {
     var _this = this;
     this._pauseEvents();
     if(this.hasNested){
-      this.$element.on('postequalized.zf.equalizer', this._bindHandler);
+      this.$element.on('postequalized.zf.equalizer', this._bindHandler.onPostEqualizedBound);
     }else{
-      this.$element.on('resizeme.zf.trigger', this._bindHandler);
+      this.$element.on('resizeme.zf.trigger', this._bindHandler.onResizeMeBound);
     }
     this.isOn = true;
   }
index 01e91932156766b94604d6fdf70eeee49fe5fe3b..48e22608059b156d555a77b82fb7bcb3d7ef8e96 100644 (file)
@@ -9,7 +9,7 @@
   </head>
   <body>
     <div class="row column">
-      <h4>I Fire preequalized and postequalized on medium-up</h4>
+      <h4>I Fire preequalized and postequalized on medium-up and also after _pauseEvents</h4>
     </div>
     <div class="row" data-equalizer data-equalize-on-stack="false" data-equalize-on="medium" id="equalizer1">
       <div class="small-12 medium-3 columns">