Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happened to the triggerOnce option in Waypoints 3.0?

I recently upgraded jquery-waypoints from 2.x to 3.x in my project and found that a lot of my code broke. All references to $(this) within my handlers had to be changed to $(this.element) which, once I figured out was the cause of my troubles, was easy enough to fix.

I haven't been able to figure out what happened to the triggerOnce option which would prevent a waypoint from firing multiple times. Any idea why this was removed and how can I achieve the same functionality?

like image 533
Yaron Avatar asked Dec 23 '14 23:12

Yaron


Video Answer


2 Answers

I know an answer was already marked as correct, but I'd like to expand beyond a simple comment.

3.0, being a major version, made breaking changes. One of them was the removal of triggerOnce. It is noted in the changelog. It is also mentioned in the destroy docs where using destroy at the end of the handler is called out as an alternative to the old triggerOnce.

Previously, triggerOnce wasn't the exact same as calling destroy because all Waypoint methods were called on jQuery objects. The elements in those jQuery objects may have multiple waypoints attached to them, but there was no way to separate them once they were created. If you called destroy all waypoints on that element were destroyed. The triggerOnce option, however, worked on an individual waypoint basis behind the scenes. Now that 3.0 returns instances of the Waypoint class directly and this within the handler is a reference to the Waypoint instance instead of the element, there is no difference between triggerOnce and calling this.destroy() to end a handler. So the code was removed.

like image 61
imakewebthings Avatar answered Nov 01 '22 16:11

imakewebthings


I figured out a solution. Adding this.disable() to the end of my handler disables the waypoint after it's been fired, preventing it from being called again. I really think this should be documented.

like image 29
Yaron Avatar answered Nov 01 '22 15:11

Yaron