]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
Add eventsHandler() 9462/head
authorCorey Snyder <corey@tangerineindustries.com>
Wed, 11 Jan 2017 16:03:45 +0000 (11:03 -0500)
committerGitHub <noreply@github.com>
Wed, 11 Jan 2017 16:03:45 +0000 (11:03 -0500)
slim down the code

js/foundation.sticky.js

index e643ea112f3a36be4c22022cb90703b12058e724..ed3cc74b940b29a112e1c933d7e01fc4721f6ea1 100644 (file)
@@ -129,44 +129,38 @@ class Sticky {
 
     this.$element.off('resizeme.zf.trigger')
                  .on('resizeme.zf.trigger', function(e, el) {
-                     _this._setSizes(function() {
-                       _this._calc(false);
-                       if (_this.canStick) {
-                         if (!_this.isOn) {
-                           _this._events(id);
-                         }
-                       } else if (_this.isOn) {
-                         _this._pauseListeners(scrollListener);
-                       }
-                     });
+                    _this._eventsHandler(id);
     });
        
        this.$element.on('mutateme.zf.trigger', function (e, el) {
-               _this._setSizes(function () {
-                       _this._calc(false);
-                       if (_this.canStick) {
-                         if (!_this.isOn) {
-                               _this._events(id);
-                         }
-                       } else if (_this.isOn) {
-                         _this._pauseListeners(scrollListener);
-                       }
-         });
+               _this._eventsHandler(id);
        });
        
        this.$anchor.on('mutateme.zf.trigger', function (e, el) {
-               _this._setSizes(function () {
-                       _this._calc(false);
-                       if (_this.canStick) {
-                         if (!_this.isOn) {
-                               _this._events(id);
-                         }
-                       } else if (_this.isOn) {
-                         _this._pauseListeners(scrollListener);
-                       }
-               });
+               _this._eventsHandler(id);
        });
   }
+  
+  /**
+   * Handler for events.
+   * @private
+   * @param {String} id - psuedo-random id for unique scroll event listener.
+   */
+  _eventsHandler(id) {
+          var _this = this,
+        scrollListener = this.scrollListener = `scroll.zf.${id}`;
+               
+          _this._setSizes(function() {
+          _this._calc(false);
+          if (_this.canStick) {
+                if (!_this.isOn) {
+                  _this._events(id);
+                }
+          } else if (_this.isOn) {
+                _this._pauseListeners(scrollListener);
+          }
+        });
+  }
 
   /**
    * Removes event handlers for scroll and change events on anchor.