From 19afeaf5804b3d6e0738d6a9506235ff50a0497b Mon Sep 17 00:00:00 2001 From: Vasin Dmitriy Date: Wed, 17 May 2017 22:19:52 +0300 Subject: Fix callback in rails ujs --- .../app/assets/javascripts/rails-ujs/features/remote.coffee | 2 +- actionview/app/assets/javascripts/rails-ujs/utils/ajax.coffee | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) (limited to 'actionview/app/assets/javascripts/rails-ujs') diff --git a/actionview/app/assets/javascripts/rails-ujs/features/remote.coffee b/actionview/app/assets/javascripts/rails-ujs/features/remote.coffee index 852587042c..b3448dabac 100644 --- a/actionview/app/assets/javascripts/rails-ujs/features/remote.coffee +++ b/actionview/app/assets/javascripts/rails-ujs/features/remote.coffee @@ -62,7 +62,7 @@ Rails.handleRemote = (e) -> fire(element, 'ajax:send', [xhr]) else fire(element, 'ajax:stopped') - xhr.abort() + return false success: (args...) -> fire(element, 'ajax:success', args) error: (args...) -> fire(element, 'ajax:error', args) complete: (args...) -> fire(element, 'ajax:complete', args) diff --git a/actionview/app/assets/javascripts/rails-ujs/utils/ajax.coffee b/actionview/app/assets/javascripts/rails-ujs/utils/ajax.coffee index a653d3af3d..4d7848e162 100644 --- a/actionview/app/assets/javascripts/rails-ujs/utils/ajax.coffee +++ b/actionview/app/assets/javascripts/rails-ujs/utils/ajax.coffee @@ -20,13 +20,12 @@ Rails.ajax = (options) -> else options.error?(response, xhr.statusText, xhr) options.complete?(xhr, xhr.statusText) - # Call beforeSend hook - options.beforeSend?(xhr, options) - # Send the request + + unless options.beforeSend?(xhr, options) + return false + if xhr.readyState is XMLHttpRequest.OPENED xhr.send(options.data) - else - fire(document, 'ajaxStop') # to be compatible with jQuery.ajax prepareOptions = (options) -> options.url = options.url or location.href -- cgit v1.2.3 From ff4b18358d06c6ce5f36bf171941b00ed321ab0c Mon Sep 17 00:00:00 2001 From: Marc Rendl Ignacio Date: Fri, 7 Jul 2017 15:34:35 +0800 Subject: Adds descriptions to rails-ujs methods [ci skip] --- .../app/assets/javascripts/rails-ujs/utils/dom.coffee | 7 +++++++ .../assets/javascripts/rails-ujs/utils/event.coffee | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) (limited to 'actionview/app/assets/javascripts/rails-ujs') diff --git a/actionview/app/assets/javascripts/rails-ujs/utils/dom.coffee b/actionview/app/assets/javascripts/rails-ujs/utils/dom.coffee index 6bef618147..3d3c5bb330 100644 --- a/actionview/app/assets/javascripts/rails-ujs/utils/dom.coffee +++ b/actionview/app/assets/javascripts/rails-ujs/utils/dom.coffee @@ -5,6 +5,13 @@ m = Element.prototype.matches or Element.prototype.oMatchesSelector or Element.prototype.webkitMatchesSelector +# Checks if the given native dom element matches the selector +# element:: +# native DOM element +# selector:: +# css selector string or +# a javascript object with `selector` and `exclude` properties +# Examples: "form", { selector: "form", exclude: "form[data-remote='true']"} Rails.matches = (element, selector) -> if selector.exclude? m.call(element, selector.selector) and not m.call(element, selector.exclude) diff --git a/actionview/app/assets/javascripts/rails-ujs/utils/event.coffee b/actionview/app/assets/javascripts/rails-ujs/utils/event.coffee index 8d3ff007ea..a2135c9851 100644 --- a/actionview/app/assets/javascripts/rails-ujs/utils/event.coffee +++ b/actionview/app/assets/javascripts/rails-ujs/utils/event.coffee @@ -14,6 +14,13 @@ if typeof CustomEvent isnt 'function' CustomEvent.prototype = window.Event.prototype # Triggers a custom event on an element and returns false if the event result is false +# obj:: +# a native DOM element +# name:: +# string that corrspends to the event you want to trigger +# e.g. 'click', 'submit' +# data:: +# data you want to pass when you dispatch an event fire = Rails.fire = (obj, name, data) -> event = new CustomEvent( name, @@ -31,6 +38,17 @@ Rails.stopEverything = (e) -> e.stopPropagation() e.stopImmediatePropagation() +# Delegates events +# to a specified parent `element`, which fires event `handler` +# for the specified `selector` when an event of `eventType` is triggered +# element:: +# parent element that will listen for events e.g. document +# selector:: +# css selector; or an object that has `selector` and `exclude` properties (see: Rails.matches) +# eventType:: +# string representing the event e.g. 'submit', 'click' +# handler:: +# the event handler to be called Rails.delegate = (element, selector, eventType, handler) -> element.addEventListener eventType, (e) -> target = e.target -- cgit v1.2.3 From a5d80d4a1c4a41ec92985e34cac23bac0509e7fb Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sun, 3 Sep 2017 16:49:38 +0900 Subject: Does not include disabled element in params In the case of remote, it should be the same behavior as submitting HTML form. Fixes #30444 --- actionview/app/assets/javascripts/rails-ujs/utils/form.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionview/app/assets/javascripts/rails-ujs') diff --git a/actionview/app/assets/javascripts/rails-ujs/utils/form.coffee b/actionview/app/assets/javascripts/rails-ujs/utils/form.coffee index 5fa337b518..736cab08db 100644 --- a/actionview/app/assets/javascripts/rails-ujs/utils/form.coffee +++ b/actionview/app/assets/javascripts/rails-ujs/utils/form.coffee @@ -10,7 +10,7 @@ Rails.serializeElement = (element, additionalParam) -> params = [] inputs.forEach (input) -> - return unless input.name + return if !input.name || input.disabled if matches(input, 'select') toArray(input.options).forEach (option) -> params.push(name: input.name, value: option.value) if option.selected -- cgit v1.2.3 From 8b22725c782a65b2222f7a9ffed6d241c599f2e6 Mon Sep 17 00:00:00 2001 From: ta1kt0me Date: Sat, 28 Oct 2017 11:51:21 +0900 Subject: Enable to call Rails.ajax without beforeSend --- actionview/app/assets/javascripts/rails-ujs/utils/ajax.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionview/app/assets/javascripts/rails-ujs') diff --git a/actionview/app/assets/javascripts/rails-ujs/utils/ajax.coffee b/actionview/app/assets/javascripts/rails-ujs/utils/ajax.coffee index 4d7848e162..cc0e037428 100644 --- a/actionview/app/assets/javascripts/rails-ujs/utils/ajax.coffee +++ b/actionview/app/assets/javascripts/rails-ujs/utils/ajax.coffee @@ -21,7 +21,7 @@ Rails.ajax = (options) -> options.error?(response, xhr.statusText, xhr) options.complete?(xhr, xhr.statusText) - unless options.beforeSend?(xhr, options) + if options.beforeSend? && !options.beforeSend(xhr, options) return false if xhr.readyState is XMLHttpRequest.OPENED -- cgit v1.2.3