diff options
author | Guillermo Iguaran <guilleiguaran@gmail.com> | 2016-11-25 10:27:07 -0500 |
---|---|---|
committer | Guillermo Iguaran <guilleiguaran@gmail.com> | 2016-11-26 01:23:07 -0500 |
commit | ad3a47759e67a411f3534309cdd704f12f6930a7 (patch) | |
tree | 1da091b1dbf782068bb3881ef44886dc779ea149 /actionview/app/assets/javascripts/utils/dom.coffee | |
parent | 0cafbd4e9e0a226c5ef32eebb826f3acb902b744 (diff) | |
download | rails-ad3a47759e67a411f3534309cdd704f12f6930a7.tar.gz rails-ad3a47759e67a411f3534309cdd704f12f6930a7.tar.bz2 rails-ad3a47759e67a411f3534309cdd704f12f6930a7.zip |
Add rails-ujs to Action View
Diffstat (limited to 'actionview/app/assets/javascripts/utils/dom.coffee')
-rw-r--r-- | actionview/app/assets/javascripts/utils/dom.coffee | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/actionview/app/assets/javascripts/utils/dom.coffee b/actionview/app/assets/javascripts/utils/dom.coffee new file mode 100644 index 0000000000..6bef618147 --- /dev/null +++ b/actionview/app/assets/javascripts/utils/dom.coffee @@ -0,0 +1,28 @@ +m = Element.prototype.matches or + Element.prototype.matchesSelector or + Element.prototype.mozMatchesSelector or + Element.prototype.msMatchesSelector or + Element.prototype.oMatchesSelector or + Element.prototype.webkitMatchesSelector + +Rails.matches = (element, selector) -> + if selector.exclude? + m.call(element, selector.selector) and not m.call(element, selector.exclude) + else + m.call(element, selector) + +# get and set data on a given element using "expando properties" +# See: https://developer.mozilla.org/en-US/docs/Glossary/Expando +expando = '_ujsData' + +Rails.getData = (element, key) -> + element[expando]?[key] + +Rails.setData = (element, key, value) -> + element[expando] ?= {} + element[expando][key] = value + +# a wrapper for document.querySelectorAll +# returns an Array +Rails.$ = (selector) -> + Array.prototype.slice.call(document.querySelectorAll(selector)) |