From: Corey Snyder Date: Wed, 11 Jan 2017 16:03:45 +0000 (-0500) Subject: Add eventsHandler() X-Git-Tag: 6.3.1~25^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F9462%2Fhead;p=thirdparty%2Ffoundation%2Ffoundation-sites.git Add eventsHandler() slim down the code --- diff --git a/js/foundation.sticky.js b/js/foundation.sticky.js index e643ea112..ed3cc74b9 100644 --- a/js/foundation.sticky.js +++ b/js/foundation.sticky.js @@ -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.