diff --git a/waypoints.coffee b/waypoints.coffee index 26ecb3bc..14c03d60 100644 --- a/waypoints.coffee +++ b/waypoints.coffee @@ -167,7 +167,7 @@ https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt $.each @waypoints[aKey], (wKey, waypoint) -> if axis.oldScroll < waypoint.offset <= axis.newScroll triggered.push waypoint - else if axis.newScroll < waypoint.offset <= axis.oldScroll + else if axis.newScroll <= waypoint.offset < axis.oldScroll triggered.push waypoint triggered.sort (a, b) -> a.offset - b.offset triggered.reverse() unless isForward @@ -356,6 +356,7 @@ https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt trigger: (args) -> return unless @enabled if @callback? + args.push @ @callback.apply @element, args if @options.triggerOnce @destroy() diff --git a/waypoints.js b/waypoints.js index 22bb9e6b..12767cb1 100644 --- a/waypoints.js +++ b/waypoints.js @@ -1,4 +1,5 @@ -// Generated by CoffeeScript 1.6.2 +// Generated by CoffeeScript 1.6.1 + /* jQuery Waypoints - v2.0.2 Copyright (c) 2011-2013 Caleb Troughton @@ -21,7 +22,6 @@ https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt } })(this, function($, window) { var $w, Context, Waypoint, allWaypoints, contextCounter, contextKey, contexts, isTouch, jQMethods, methods, resizeEvent, scrollEvent, waypointCounter, waypointKey, wp, wps; - $w = $(window); isTouch = __indexOf.call(window, 'ontouchstart') >= 0; allWaypoints = { @@ -38,9 +38,9 @@ https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt wp = 'waypoint'; wps = 'waypoints'; Context = (function() { + function Context($element) { var _this = this; - this.$element = $element; this.element = $element[0]; this.didResize = false; @@ -58,7 +58,6 @@ https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt contexts[this.id] = this; $element.bind(scrollEvent, function() { var scrollHandler; - if (!(_this.didScroll || isTouch)) { _this.didScroll = true; scrollHandler = function() { @@ -70,7 +69,6 @@ https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt }); $element.bind(resizeEvent, function() { var resizeHandler; - if (!_this.didResize) { _this.didResize = true; resizeHandler = function() { @@ -85,7 +83,6 @@ https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt Context.prototype.doScroll = function() { var axes, _this = this; - axes = { horizontal: { newScroll: this.$element.scrollLeft(), @@ -105,16 +102,14 @@ https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt } $.each(axes, function(aKey, axis) { var direction, isForward, triggered; - triggered = []; isForward = axis.newScroll > axis.oldScroll; direction = isForward ? axis.forward : axis.backward; $.each(_this.waypoints[aKey], function(wKey, waypoint) { var _ref, _ref1; - if ((axis.oldScroll < (_ref = waypoint.offset) && _ref <= axis.newScroll)) { return triggered.push(waypoint); - } else if ((axis.newScroll < (_ref1 = waypoint.offset) && _ref1 <= axis.oldScroll)) { + } else if ((axis.newScroll <= (_ref1 = waypoint.offset) && _ref1 < axis.oldScroll)) { return triggered.push(waypoint); } }); @@ -139,7 +134,6 @@ https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt Context.prototype.refresh = function() { var axes, cOffset, isWin, _this = this; - isWin = $.isWindow(this.element); cOffset = this.$element.offset(); this.doScroll(); @@ -166,7 +160,6 @@ https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt return $.each(axes, function(aKey, axis) { return $.each(_this.waypoints[aKey], function(i, waypoint) { var adjustment, elementOffset, oldOffset, _ref, _ref1; - adjustment = waypoint.options.offset; oldOffset = waypoint.offset; elementOffset = $.isWindow(waypoint.element) ? 0 : waypoint.$element.offset()[axis.offsetProp]; @@ -204,14 +197,13 @@ https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt })(); Waypoint = (function() { + function Waypoint($element, context, options) { var idList, _ref; - options = $.extend({}, $.fn[wp].defaults, options); if (options.offset === 'bottom-in-view') { options.offset = function() { var contextHeight; - contextHeight = $[wps]('viewportHeight'); if (!$.isWindow(context.element)) { contextHeight = context.$element.height(); @@ -240,6 +232,7 @@ https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt return; } if (this.callback != null) { + args.push(this); this.callback.apply(this.element, args); } if (this.options.triggerOnce) { @@ -264,7 +257,6 @@ https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt Waypoint.getWaypointsByElement = function(element) { var all, ids; - ids = $(element).data(waypointKey); if (!ids) { return []; @@ -281,7 +273,6 @@ https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt methods = { init: function(f, options) { var _ref; - if (options == null) { options = {}; } @@ -290,7 +281,6 @@ https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt } this.each(function() { var $this, context, contextElement, _ref1; - $this = $(this); contextElement = (_ref1 = options.context) != null ? _ref1 : $.fn[wp].defaults.context; if (!$.isWindow(contextElement)) { @@ -331,7 +321,6 @@ https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt }, _traverse: function(axis, selector, push) { var stack, waypoints; - if (axis == null) { axis = 'vertical'; } @@ -342,7 +331,6 @@ https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt stack = []; this.each(function() { var index; - index = $.inArray(this, waypoints[axis]); return push(stack, index, waypoints[axis]); }); @@ -351,7 +339,6 @@ https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt _invoke: function($elements, method) { $elements.each(function() { var waypoints; - waypoints = Waypoint.getWaypointsByElement(this); return $.each(waypoints, function(i, waypoint) { waypoint[method](); @@ -363,7 +350,6 @@ https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt }; $.fn[wp] = function() { var args, method; - method = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; if (methods[method]) { return methods[method].apply(this, args); @@ -393,12 +379,10 @@ https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt }, viewportHeight: function() { var _ref; - return (_ref = window.innerHeight) != null ? _ref : $w.height(); }, aggregate: function(contextSelector) { var collection, waypoints, _ref; - collection = allWaypoints; if (contextSelector) { collection = (_ref = contexts[$(contextSelector).data(contextKey)]) != null ? _ref.waypoints : void 0; @@ -470,7 +454,6 @@ https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt }, _invoke: function(method) { var waypoints; - waypoints = $.extend({}, allWaypoints.vertical, allWaypoints.horizontal); return $.each(waypoints, function(key, waypoint) { waypoint[method](); @@ -479,7 +462,6 @@ https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt }, _filter: function(selector, axis, test) { var context, waypoints; - context = contexts[$(selector).data(contextKey)]; if (!context) { return []; @@ -500,7 +482,6 @@ https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt }; $[wps] = function() { var args, method; - method = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; if (jQMethods[method]) { return jQMethods[method].apply(null, args);