forked from rails/jquery-ujs
-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
Description
Event System
We are using native JavaScript event now, which brings some trouble when used together with jQuery, such as
// Add an event listener using jQuery
// before
$(form).bind('ajax:success', function(e, data, status, xhr) {
// code
})
// after
$(form).bind('ajax:success', function(e) {
var data = e.originalEvent.detail[0]
var status = e.originalEvent.detail[1]
var xhr = e.originalEvent.detail[2]
// code
})
// Manually trigger an event
// before
$(link).trigger('click')
// after
$(link)[0].click()
// before
$(form).trigger('submit')
// after, because el.submit() does't fire the submit event!
if ($(form)[0].dispatchEvent(new Event('submit', { bubbles: true, cancelable: true })) !== false) {
$(form)[0].submit()
}There are two helper functions in test/settings.js. However, I'm wondering whether it's acceptable to add these functions to jQuery globally when users import UJS in their projects, or expose them in different APIs.
Ajax (finished)
Old UJS will prefilter all jQuery ajax requests with CSRFProtection header. This behavior shouldn't change in new version.
Reactions are currently unavailable