foundation-rails-confirm 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +6 -0
- data/LICENSE +22 -0
- data/README.md +71 -0
- data/Rakefile +2 -0
- data/foundation-rails-confirm.gemspec +17 -0
- data/lib/foundation-rails-confirm.rb +9 -0
- data/lib/foundation/rails/confirm/engine.rb +10 -0
- data/lib/foundation/rails/confirm/version.rb +7 -0
- data/vendor/assets/javascripts/foundation/rails/confirm.coffee +113 -0
- metadata +54 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d569775c136301b1b8c1152648c0b3d2fa64b66f
|
4
|
+
data.tar.gz: 3ce529c53c11f04bc6d4f7bfdd18fcf699fe5b4e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cb10813c51030c8478c248b7d0447ec7caf615fdd52908f5ddc62099a11e8354e94ae40b589c480eee5c6b708348272fced13f7f864a81a3c347c758cd00b87d
|
7
|
+
data.tar.gz: 63e6e64718cb82332725ca03a09bbacc61f6db78edda16c5ab6a2f8dfd580d1a7f8d6209a202f9c23a04308978c24e6addca64b2e8ac827dfa1edb4d19c28cf7
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Rene van Lieshout
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# Foundation::Rails::Confirm
|
2
|
+
|
3
|
+
This gem adds some javascript to change the default behaviour of data-confirm processing.
|
4
|
+
|
5
|
+
The normal confirm dialog shows a text with buttons 'ok' and 'cancel'. More information is needed here for a user to make the right decision. This gem therefore also adds:
|
6
|
+
|
7
|
+
* data-confirm-fade (default: false)
|
8
|
+
* data-confirm-title (default: window.top.location.origin)
|
9
|
+
* data-confirm-cancel (default: 'cancel')
|
10
|
+
* data-confirm-cancel-class (default: 'btn cancel')
|
11
|
+
* data-confirm-proceed (default: 'ok')
|
12
|
+
* data-confirm-proceed-class (default: 'btn-primary')
|
13
|
+
|
14
|
+
This behaviour is similar to that of a "regular" confirm box in ways that it uses the same title and button labels. Defaults can be changed in two ways:
|
15
|
+
|
16
|
+
Changing all default values:
|
17
|
+
|
18
|
+
$.fn.foundation_confirmbox.defaults = {
|
19
|
+
fade: false,
|
20
|
+
title: null, // if title equals null window.top.location.origin is used
|
21
|
+
cancel: "Cancel",
|
22
|
+
cancel_class: "btn cancel",
|
23
|
+
proceed: "OK",
|
24
|
+
proceed_class: "btn proceed btn-primary"
|
25
|
+
};
|
26
|
+
|
27
|
+
Only changing one default value:
|
28
|
+
|
29
|
+
$.fn.foundation_confirmbox.defaults.proceed_class = "btn proceed btn-success";
|
30
|
+
|
31
|
+
## Installation
|
32
|
+
|
33
|
+
Add this line to your application's Gemfile:
|
34
|
+
|
35
|
+
gem 'foundation-rails-confirm'
|
36
|
+
|
37
|
+
And then execute:
|
38
|
+
|
39
|
+
$ bundle
|
40
|
+
|
41
|
+
## Usage
|
42
|
+
|
43
|
+
Add it to your application.js, anywhere after you require jquery_ujs:
|
44
|
+
|
45
|
+
//= require foundation/rails/confirm
|
46
|
+
|
47
|
+
Next... nothing. There is nothing you need to do to get this working. A helper could be useful for handling large amount of destroy buttons:
|
48
|
+
|
49
|
+
def destroy_link_to(path, options)
|
50
|
+
link_to t('.destroy'), path,
|
51
|
+
"method" => :delete,
|
52
|
+
"class" => "btn",
|
53
|
+
"confirm" => t('.destroy_confirm.body', item: options[:item]),
|
54
|
+
"data-confirm-title" => t('.destroy_confirm.title', item: options[:item]),
|
55
|
+
"data-confirm-cancel" => t('.destroy_confirm.cancel', item: options[:item]),
|
56
|
+
"data-confirm-cancel-class" => "button secondary"),
|
57
|
+
"data-confirm-proceed" => t('.destroy_confirm.proceed', item: options[:item]),
|
58
|
+
"data-confirm-proceed-class" => "button "
|
59
|
+
end
|
60
|
+
|
61
|
+
## Contributing
|
62
|
+
|
63
|
+
1. Fork it
|
64
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
65
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
66
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
67
|
+
5. Create new Pull Request
|
68
|
+
|
69
|
+
## Thanks
|
70
|
+
|
71
|
+
This gem is based to amazing gem by Rene van Lieshout, [twitter-bootstrap-rails-confirm](https://github.com/bluerail/foundation-rails-confirm). All thanks goes to all conributors and authors of that gem.
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/foundation/rails/confirm/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Mikko Kokkonen"]
|
6
|
+
gem.email = ["mikko@mikian.com"]
|
7
|
+
gem.description = %q{Confirm dialogs using Zurb Foundation}
|
8
|
+
gem.summary = %q{Applies a custom confirm dialog for elements with a data-confirm attribute.}
|
9
|
+
gem.homepage = "https://github.com/mikian/foundation-rails-confirm"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "foundation-rails-confirm"
|
15
|
+
gem.require_paths = ["lib", "vendor"]
|
16
|
+
gem.version = Foundation::Rails::Confirm::VERSION
|
17
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
$.fn.foundation_confirmbox =
|
2
|
+
defaults:
|
3
|
+
title: null
|
4
|
+
proceed: "OK"
|
5
|
+
proceed_class: "button tiny right"
|
6
|
+
cancel: "Cancel"
|
7
|
+
cancel_class: "button secondary tiny"
|
8
|
+
fade: false
|
9
|
+
|
10
|
+
FoundationConfirmBox = (message, element, callback) ->
|
11
|
+
$dialog = $('
|
12
|
+
<div class="reveal-modal small" id="confirmation_dialog" data-reveal>
|
13
|
+
<h4 class="title"></h4>
|
14
|
+
<p class="body"></p>
|
15
|
+
<div class="footer"></div>
|
16
|
+
<a class="close-reveal-modal">×</a>
|
17
|
+
</div>
|
18
|
+
')
|
19
|
+
|
20
|
+
$dialog
|
21
|
+
.find(".title")
|
22
|
+
.html(element.data("confirm-title") || $.fn.foundation_confirmbox.defaults.title || window.top.location.origin)
|
23
|
+
.end()
|
24
|
+
|
25
|
+
.find(".body")
|
26
|
+
.html(message.replace(/\n/g, "<br />"))
|
27
|
+
.end()
|
28
|
+
|
29
|
+
.find(".footer")
|
30
|
+
.append(
|
31
|
+
$("<a />", {href: "#"})
|
32
|
+
.html(element.data("confirm-cancel") || $.fn.foundation_confirmbox.defaults.cancel)
|
33
|
+
.addClass($.fn.foundation_confirmbox.defaults.cancel_class)
|
34
|
+
.addClass(element.data("confirm-cancel-class"))
|
35
|
+
.click((event) ->
|
36
|
+
event.preventDefault()
|
37
|
+
$dialog.foundation('reveal', 'close').remove()
|
38
|
+
false
|
39
|
+
)
|
40
|
+
,
|
41
|
+
$("<a />", {href: "#"})
|
42
|
+
.html(element.data("confirm-proceed") || $.fn.foundation_confirmbox.defaults.proceed)
|
43
|
+
.addClass($.fn.foundation_confirmbox.defaults.proceed_class)
|
44
|
+
.addClass(element.data("confirm-proceed-class") || "btn-primary")
|
45
|
+
.click((event) ->
|
46
|
+
event.preventDefault()
|
47
|
+
$dialog.foundation('reveal', 'close')
|
48
|
+
callback()
|
49
|
+
)
|
50
|
+
)
|
51
|
+
.end()
|
52
|
+
.appendTo(document.body)
|
53
|
+
.foundation('reveal', 'open')
|
54
|
+
|
55
|
+
$.rails.allowAction = (element) ->
|
56
|
+
message = element.data("confirm")
|
57
|
+
answer = false
|
58
|
+
return true unless message
|
59
|
+
|
60
|
+
if $.rails.fire(element, "confirm")
|
61
|
+
FoundationConfirmBox message, element, ->
|
62
|
+
if $.rails.fire(element, "confirm:complete", [answer])
|
63
|
+
allowAction = $.rails.allowAction
|
64
|
+
|
65
|
+
$.rails.allowAction = ->
|
66
|
+
true
|
67
|
+
|
68
|
+
if element.get(0).click
|
69
|
+
element.get(0).click()
|
70
|
+
|
71
|
+
else if Event?
|
72
|
+
evt = new Event("click", {
|
73
|
+
bubbles: true,
|
74
|
+
cancelable: true,
|
75
|
+
view: window,
|
76
|
+
detail: 0,
|
77
|
+
screenX: 0,
|
78
|
+
screenY: 0,
|
79
|
+
clientX: 0,
|
80
|
+
clientY: 0,
|
81
|
+
ctrlKey: false,
|
82
|
+
altKey: false,
|
83
|
+
shiftKey: false,
|
84
|
+
metaKey: false,
|
85
|
+
button: 0,
|
86
|
+
relatedTarget: document.body.parentNode
|
87
|
+
})
|
88
|
+
element.get(0).dispatchEvent(evt)
|
89
|
+
|
90
|
+
else if $.isFunction(document.createEvent)
|
91
|
+
evt = document.createEvent "MouseEvents"
|
92
|
+
evt.initMouseEvent(
|
93
|
+
"click",
|
94
|
+
true, # e.bubbles,
|
95
|
+
true, # e.cancelable,
|
96
|
+
window, # e.view,
|
97
|
+
0, # e.detail,
|
98
|
+
0, # e.screenX,
|
99
|
+
0, # e.screenY,
|
100
|
+
0, # e.clientX,
|
101
|
+
0, # e.clientY,
|
102
|
+
false, # e.ctrlKey,
|
103
|
+
false, # e.altKey,
|
104
|
+
false, # e.shiftKey,
|
105
|
+
false, # e.metaKey,
|
106
|
+
0, # e.button,
|
107
|
+
document.body.parentNode # e.relatedTarget
|
108
|
+
)
|
109
|
+
element.get(0).dispatchEvent(evt)
|
110
|
+
|
111
|
+
$.rails.allowAction = allowAction
|
112
|
+
|
113
|
+
false
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: foundation-rails-confirm
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mikko Kokkonen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-04 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Confirm dialogs using Zurb Foundation
|
14
|
+
email:
|
15
|
+
- mikko@mikian.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- Gemfile
|
22
|
+
- LICENSE
|
23
|
+
- README.md
|
24
|
+
- Rakefile
|
25
|
+
- foundation-rails-confirm.gemspec
|
26
|
+
- lib/foundation-rails-confirm.rb
|
27
|
+
- lib/foundation/rails/confirm/engine.rb
|
28
|
+
- lib/foundation/rails/confirm/version.rb
|
29
|
+
- vendor/assets/javascripts/foundation/rails/confirm.coffee
|
30
|
+
homepage: https://github.com/mikian/foundation-rails-confirm
|
31
|
+
licenses: []
|
32
|
+
metadata: {}
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
- vendor
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirements: []
|
49
|
+
rubyforge_project:
|
50
|
+
rubygems_version: 2.2.0
|
51
|
+
signing_key:
|
52
|
+
specification_version: 4
|
53
|
+
summary: Applies a custom confirm dialog for elements with a data-confirm attribute.
|
54
|
+
test_files: []
|