Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails 6 and Foundation 6 #28

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## 1.1.0 (2021-04-05)

for usage with Rails6 and Foundation 6
* use $.rails.confirm to comply to Rails 6
* use Foundation 6 for reveal / close

## 1.0.2 (2015-01-08)

* Ensure that bare `data-confirm` attribute without value launches Foundation
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ For maximum **“are you really, really sure”** protection, the user can optio

Requires [jQuery](http://jquery.com/), as well as ZURB’s [Reveal](http://foundation.zurb.com/docs/components/reveal.html) plugin.

Integrates with the Rails [jQuery UJS adapter](https://github.com/indirect/jquery-rails) if the latter has been included, by overwriting `$.rails.allowAction`. Simple use of `confirm: "Are you sure?"` in the `link_to` helper will use the standard `window.confirm()` prompt; see CoffeeScript source for full usage details.
Integrates with the Rails [jQuery UJS adapter](https://github.com/indirect/jquery-rails) if the latter has been included, by overwriting `$.rails.confirm`. Simple use of `confirm: "Are you sure?"` in the `link_to` helper will use the standard `window.confirm()` prompt; see CoffeeScript source for full usage details.

For Rails < 6 use version 1.0.x that overwrites `$.rails.allowAction`.

## Example

Expand Down
7 changes: 4 additions & 3 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "confirm-with-reveal",
"version": "1.0.2",
"version": "1.1.0",
"homepage": "https://github.com/agoragames/confirm-with-reveal",
"authors": [
"Jack Letourneau <[email protected]>"
"Jack Letourneau <[email protected]>",
"Martin Meier <[email protected]>"
],
"description": "Confirm UI actions with ZURB Foundation Reveal modals.",
"description": "Confirm UI actions with Foundation Reveal modals.",
"main": "build/confirm_with_reveal.js",
"keywords": [
"zurb",
Expand Down
21 changes: 12 additions & 9 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.

18 changes: 11 additions & 7 deletions confirm_with_reveal.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Examples using Rails’ link_to helper
# use with Foundation 6 and Rails 6
#
# Basic usage:
# = link_to 'Delete', foo_path(foo), method: :delete, data: { confirm: true }
Expand All @@ -15,7 +16,8 @@
# Fall back to window.confirm() when confirm is a plain string:
# = link_to 'Delete', foo_path(foo), method: :delete, confirm: 'Are you sure?'

$ = this.jQuery
if !$
$ = this.jQuery

$.fn.extend
confirmWithReveal: (options = {}) ->
Expand All @@ -36,6 +38,8 @@ $.fn.extend

settings = $.extend {}, defaults, options

nativeConfirm = $.rails?.confirm

do_confirm = ($el) ->

el_options = $el.data('confirm')
Expand All @@ -47,14 +51,14 @@ $.fn.extend
return true unless $el.attr('data-confirm')?

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

option = (name) ->
el_options[name] || settings[name]

# TODO: allow caller to pass in a template (DOM element to clone?)
modal = $("""
<div data-reveal class='reveal-modal #{option 'modal_class'}'>
<div data-reveal class='reveal #{option 'modal_class'}'>
<h2 data-confirm-title class='#{option 'title_class'}'></h2>
<p data-confirm-body class='#{option 'body_class'}'></p>
<div data-confirm-footer class='#{option 'footer_class'}'>
Expand Down Expand Up @@ -89,7 +93,7 @@ $.fn.extend
.find('[data-confirm-cancel]')
.html(option 'cancel')
.on 'click', (e) ->
modal.foundation('reveal', 'close')
modal.foundation('close')
$el.trigger('cancel.reveal', e)
modal
.find('[data-confirm-footer]')
Expand Down Expand Up @@ -120,8 +124,8 @@ $.fn.extend
modal
.appendTo($('body'))
.foundation()
.foundation('reveal', 'open')
.on 'closed.fndtn.reveal', (e) ->
.foundation('open')
.on 'closed.zf.reveal', (e) ->
modal.remove()

return false
Expand All @@ -131,7 +135,7 @@ $.fn.extend
# 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)
$.rails.confirm = (message, element) -> do_confirm $(element)
return $(this)

else
Expand Down