Skip to content

Commit

Permalink
Compatibility fix for jquery_ujs in Rails (fixes #9).
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack Letourneau committed Jul 25, 2014
1 parent 85414f3 commit a8e7997
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 37 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# CHANGELOG

## 1.0.1 (2014-07-25)

* Fix compatibility issue with [jquery-ujs](https://github.com/rails/jquery-ujs)
(see [issue #9](https://github.com/agoragames/confirm-with-reveal/issues/9)).

## 1.0.0 (2014-03-28)

* Additional UI customization options; plugin-specific confirm/cancel events.

## 0.0.3 (2014-02-25)

* Fix semantic versioning tag snafu. No functional changes.
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "confirm-with-reveal",
"version": "1.0.0",
"version": "1.0.1",
"homepage": "https://github.com/agoragames/confirm-with-reveal",
"authors": [
"Jack Letourneau <jletourneau@agoragames.com>"
Expand Down
41 changes: 21 additions & 20 deletions build/confirm_with_reveal.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/confirm_with_reveal.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 25 additions & 15 deletions confirm_with_reveal.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,21 @@ $.fn.extend
ok_class: 'button alert'
cancel: 'Cancel'
cancel_class: 'button secondary'

settings = $.extend {}, defaults, options

do_confirm = ($el) ->

el_options = $el.data('confirm')
el_options ?= {}

# The confirmation is actually triggered again when hitting "OK"
# (or whatever) in the modal (since we clone the original link in),
# but since we strip off the 'confirm' data attribute, we can tell
# whether this is the first confirmation or a subsequent one.
return true if !el_options

if (typeof el_options == 'string') and (el_options.length > 0)
return fallback_confirm.call(window, el_options)
return ($.rails?.confirm || window.confirm).call(window, el_options)

option = (name) ->
el_options[name] || settings[name]
Expand Down Expand Up @@ -120,19 +126,23 @@ $.fn.extend

return false

confirm_handler = (e) ->
unless (do_confirm $(this))
e.preventDefault()
e.stopImmediatePropagation()
if $.rails

# We do NOT do the event binding if $.rails exists, because jquery_ujs
# has already done it for us

$.rails.allowAction = (link) -> do_confirm $(link)
return $(this)

fallback_confirm = if $.rails?.confirm then $.rails.confirm else window.confirm
else

if $.rails?.allowAction
$.rails.allowAction = (link) ->
do_confirm $(link)
handler = (e) ->
unless (do_confirm $(this))
e.preventDefault()
e.stopImmediatePropagation()

return @each () ->
$el = $(this)
$el.on 'click', 'a[data-confirm], :input[data-confirm]', confirm_handler
$el.on 'submit', 'form[data-confirm]', confirm_handler
$el
return @each () ->
$el = $(this)
$el.on 'click', 'a[data-confirm], :input[data-confirm]', handler
$el.on 'submit', 'form[data-confirm]', handler
$el

0 comments on commit a8e7997

Please sign in to comment.