Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes .bind to .on #118

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Changes .bind to .on #118

wants to merge 1 commit into from

Conversation

wmill
Copy link

@wmill wmill commented Aug 30, 2013

.on will work on newly created elements, .bind will not.

This will fix some issues I had using jquery-ui-touch-punch with AngularJS.

Plus, "As of jQuery 1.7, the .on() method is the preferred method for attaching event handlers to a document."

.bind('touchstart', $.proxy(self, '_touchStart'))
.bind('touchmove', $.proxy(self, '_touchMove'))
.bind('touchend', $.proxy(self, '_touchEnd'));
.on('touchstart', $.proxy(self, '_touchStart'))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be modernized even more:

    self.element.on({
        'touchstart': $.proxy(self, '_touchStart'),
        'touchmove': $.proxy(self, '_touchMove'),
        'touchend': $.proxy(self, '_touchEnd')
    });

@benjamindeclercq
Copy link

And for removing the event handlers

self.element.off({
'touchstart': $.proxy(self, '_touchStart'),
'touchmove': $.proxy(self, '_touchMove'),
'touchend': $.proxy(self, '_touchEnd')
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants