aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/app
diff options
context:
space:
mode:
authorMarc Rendl Ignacio <marcrendlignacio@gmail.com>2017-07-07 15:34:35 +0800
committerMarc Rendl Ignacio <marcrendlignacio@gmail.com>2017-07-07 15:34:35 +0800
commitff4b18358d06c6ce5f36bf171941b00ed321ab0c (patch)
tree1f793a233c0c03c687a6b5ba1bca83a1c40cad07 /actionview/app
parent990a4dbbca5b7a8cf3d01861cb66deae456d370e (diff)
downloadrails-ff4b18358d06c6ce5f36bf171941b00ed321ab0c.tar.gz
rails-ff4b18358d06c6ce5f36bf171941b00ed321ab0c.tar.bz2
rails-ff4b18358d06c6ce5f36bf171941b00ed321ab0c.zip
Adds descriptions to rails-ujs methods [ci skip]
Diffstat (limited to 'actionview/app')
-rw-r--r--actionview/app/assets/javascripts/rails-ujs/utils/dom.coffee7
-rw-r--r--actionview/app/assets/javascripts/rails-ujs/utils/event.coffee18
2 files changed, 25 insertions, 0 deletions
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