@@ -219,6 +219,22 @@ methods =
219219 enable : -> methods ._invoke this , ' enable'
220220 destroy : -> methods ._invoke this , ' destroy'
221221
222+ prev : (axis , selector ) ->
223+ methods ._traverse .call this , axis, selector, (stack , index , waypoints ) ->
224+ stack .push waypoints[index- 1 ] if index > 0
225+
226+ next : (axis , selector ) ->
227+ methods ._traverse .call this , axis, selector, (stack , index , waypoints ) ->
228+ stack .push waypoints[index+ 1 ] if index < waypoints .length - 1
229+
230+ _traverse : (axis = ' vertical' , selector = window , push ) ->
231+ waypoints = jQMethods .aggregate selector
232+ stack = []
233+ @ each ->
234+ index = $ .inArray this , waypoints[axis]
235+ push stack, index, waypoints[axis]
236+ @ pushStack stack
237+
222238 _invoke : ($elements , method ) ->
223239 $elements .each ->
224240 waypoints = Waypoint .getWaypointsByElement this
@@ -253,28 +269,21 @@ jQMethods =
253269 viewportHeight : ->
254270 window .innerHeight ? $w .height ()
255271
256- aggregate : ->
272+ aggregate : (contextSelector ) ->
273+ collection = allWaypoints
274+ if contextSelector
275+ collection = contexts[$ (contextSelector).data contextKey].waypoints
257276 waypoints =
258277 horizontal : []
259278 vertical : []
260279 $ .each waypoints, (axis , arr ) ->
261- $ .each allWaypoints [axis], (key , waypoint ) ->
280+ $ .each collection [axis], (key , waypoint ) ->
262281 arr .push waypoint
263282 arr .sort (a, b) -> a .offset - b .offset
264283 waypoints[axis] = $ .map arr, (waypoint ) -> waypoint .element
265284 waypoints[axis] = $ .unique waypoints[axis]
266285 waypoints
267286
268- _filter : (selector , axis , test ) ->
269- context = contexts[$ (selector).data contextKey]
270- console .log $ (selector).
271- return [] unless context
272- waypoints = []
273- $ .each context .waypoints [axis], (i , waypoint ) ->
274- waypoints .push waypoint if test context, waypoint
275- waypoints .sort (a, b) -> a .offset - b .offset
276- $ .map waypoints, (waypoint ) -> waypoint .element
277-
278287 above : (contextSelector = window ) ->
279288 jQMethods ._filter contextSelector, ' vertical' , (context , waypoint ) ->
280289 waypoint .offset < context .oldScroll .y
@@ -291,6 +300,15 @@ jQMethods =
291300 jQMethods ._filter contextSelector, ' horizontal' , (context , waypoint ) ->
292301 waypoint .offset >= context .oldScroll .x
293302
303+ _filter : (selector , axis , test ) ->
304+ context = contexts[$ (selector).data contextKey]
305+ return [] unless context
306+ waypoints = []
307+ $ .each context .waypoints [axis], (i , waypoint ) ->
308+ waypoints .push waypoint if test context, waypoint
309+ waypoints .sort (a, b) -> a .offset - b .offset
310+ $ .map waypoints, (waypoint ) -> waypoint .element
311+
294312
295313$[wps] = (method ) ->
296314 if jQMethods[method] then jQMethods[method]() else jQMethods .aggregate ()
0 commit comments