-
Notifications
You must be signed in to change notification settings - Fork 508
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
Namespace #29
Comments
FYI There is another discussion on namespacing here http://github.com/rails/jquery-ujs/issues/#issue/9 |
Can you rebase your code against master? I would like this patch to be applied to master. |
Closing this ticket since a new pull request has been made. http://github.com/rails/jquery-ujs/issues#issue/37 |
I rebased the code against master, but git had some conflicts. I didn't want to muddy up the git history with extra merge commits for this simple change, so I just re-did the changes against a fresh pull from master, on a new branch. See the new pull-request here: http://github.com/rails/jquery-ujs/pull/37 If you'd prefer, I can push the changes to this branch, with the extra merge commits, just the same. |
Hi, I'm not sure if I'm doing the right thing, but I have $('a').die('rails'); in my application.js and my links with a "data-confirm" attribute are still calling the functions bound in rails.js. Also if I trie $('a').die('rails') from the console I still get the problem. Any thoughts? |
Hi capitaomorte, unfortunately what you're trying to do won't yet work. For an explanation why it won't work, please see the section "The problem with die" in the following article: The short answer is that the selector string in .die() must exactly match the selector string used in .live(). The rails.js binds to $('a[data-remote],input[data-remote]'), so you would need to kill it with: $('a[data-remote],input[data-remote]').die(); I've actually rewritten the .die() method in jQuery to work the way you're trying above (because it should work that way), and the fix may likely be included in jQuery 1.5. See discussion in the jQuery core developers forum: |
I added a "rails" namespace to all of the live click and submit bindings, making them .live('click.rails') and .live('submit.rails'), so that you can easily unbind all of the live events created specifically by Rails.
This is handy for instances where you may want to disable the Rails data-remote goodness without needing to exclude the rails.js file from that page (which may be combined and minified with all your other js files), by simply calling $(selector).die('rails').
For example, I may want to add my own .live('click') bindings on a given page, and then want to turn off the Rails bindings so that they don't also get called.
Perhaps this circumstance is rare, but namespacing the events is cleaner, more maintainable, adds basically no extra code, and is completely backwards compatible with everything people are already doing.
For more information about jQuery namespacing, see http://docs.jquery.com/Namespaced_Events
The text was updated successfully, but these errors were encountered: