Skip to content

Commit 2d109aa

Browse files
committed
First version
0 parents  commit 2d109aa

File tree

11 files changed

+184
-0
lines changed

11 files changed

+184
-0
lines changed

.gitignore

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
*.gem
2+
*.rbc
3+
.bundle
4+
.config
5+
.yardoc
6+
Gemfile.lock
7+
InstalledFiles
8+
_yardoc
9+
coverage
10+
doc/
11+
lib/bundler/man
12+
pkg
13+
rdoc
14+
spec/reports
15+
test/tmp
16+
test/version_tmp
17+
tmp

Gemfile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source 'https://rubygems.org'
2+
3+
# Specify your gem's dependencies in twitter-bootstrap-confirm.gemspec
4+
gemspec

LICENSE

+22
Original file line numberDiff line numberDiff line change
@@ -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.

README.md

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Twitter::Bootstrap::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-title (default: window.top.location.origin)
8+
* data-confirm-cancel (default: 'cancel')
9+
* data-confirm-proceed (default: 'ok')
10+
* data-confirm-proceed-class (default: 'brn-primary')
11+
12+
## Installation
13+
14+
Add this line to your application's Gemfile:
15+
16+
gem 'twitter-bootstrap-rails-confirm'
17+
18+
And then execute:
19+
20+
$ bundle
21+
22+
Or install it yourself as:
23+
24+
$ gem install twitter-bootstrap-rails-confirm
25+
26+
## Usage
27+
28+
There is nothing you need to do to get this working. A helper could be useful for handling large amount of destroy buttons:
29+
30+
def destroy_link_to(path, options)
31+
link_to t('.destroy'), path,
32+
:method => :delete,
33+
:class => "btn",
34+
:confirm => t('.destroy_confirm.body', :item => options[:item]),
35+
"data-confirm-title" => t('.destroy_confirm.title', :item => options[:item]),
36+
"data-confirm-cancel" => t('.destroy_confirm.cancel', :item => options[:item]),
37+
"data-confirm-proceed" => t('.destroy_confirm.proceed', :item => options[:item]),
38+
"data-confirm-proceed-class" => "btn-danger"
39+
end
40+
41+
## Contributing
42+
43+
1. Fork it
44+
2. Create your feature branch (`git checkout -b my-new-feature`)
45+
3. Commit your changes (`git commit -am 'Added some feature'`)
46+
4. Push to the branch (`git push origin my-new-feature`)
47+
5. Create new Pull Request

Rakefile

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env rake
2+
require "bundler/gem_tasks"
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require "twitter-bootstrap-rails-confirm/version"
2+
3+
module Twitter
4+
module Bootstrap
5+
module Rails
6+
module Confirm
7+
require 'twitter-bootstrap-rails-confirm/engine' if defined?(Rails)
8+
end
9+
end
10+
end
11+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require 'rails'
2+
3+
module Twitter
4+
module Bootstrap
5+
module Rails
6+
module Confirm
7+
class Engine < ::Rails::Engine
8+
end
9+
end
10+
end
11+
end
12+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module Twitter
2+
module Bootstrap
3+
module Rails
4+
module Confirm
5+
VERSION = "0.0.1"
6+
end
7+
end
8+
end
9+
end
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# -*- encoding: utf-8 -*-
2+
require File.expand_path('../lib/twitter-bootstrap-rails-confirm/version', __FILE__)
3+
4+
Gem::Specification.new do |gem|
5+
gem.authors = ["Rene van Lieshout"]
6+
gem.email = ["[email protected]"]
7+
gem.description = %q{Confirm dialogs using Twitter Bootstrap}
8+
gem.summary = %q{Applies a custom confirm dialog for elements with a data-confirm attribute.}
9+
gem.homepage = "http://www.bluerail.nl"
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 = "twitter-bootstrap-rails-confirm"
15+
gem.require_paths = ["lib", "vendor"]
16+
gem.version = Twitter::Bootstrap::Rails::Confirm::VERSION
17+
end

vendor/assets/javascripts/bla.js

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
$(window).load ->
2+
TwitterBootstrapConfirmBox = (message, element, callback) ->
3+
$(document.body).append($('
4+
<div class="modal hide" id="confirmation_dialog">
5+
<div class="modal-header"><button type="button" class="close" data-dismiss="modal">×</button><h3>...</h3></div>
6+
<div class="modal-body"></div>
7+
<div class="modal-footer"><a href="#" class="btn cancel" data-dismiss="modal">...</a><a href="#" class="btn proceed btn-primary">...</a></div>
8+
</div>
9+
'))
10+
11+
$("#confirmation_dialog .modal-body").html(message)
12+
$("#confirmation_dialog .modal-header h3").html(element.data("confirm-title") || window.top.location.origin)
13+
$("#confirmation_dialog .modal-footer .cancel").html(element.data("confirm-cancel") || "Cancel")
14+
$("#confirmation_dialog .modal-footer .proceed").html(element.data("confirm-proceed") || "Ok").attr("class", "btn proceed btn-primary").addClass(element.data("confirm-proceed-class"))
15+
$("#confirmation_dialog").modal "show"
16+
17+
$("#confirmation_dialog .proceed").click ->
18+
$("#confirmation_dialog").modal("hide").remove()
19+
callback()
20+
true
21+
22+
$("#confirmation_dialog .cancel").click ->
23+
$("#confirmation_dialog").modal("hide").remove()
24+
false
25+
26+
$.rails.allowAction = (element) ->
27+
message = element.data("confirm")
28+
answer = false
29+
return true unless message
30+
31+
if $.rails.fire(element, "confirm")
32+
TwitterBootstrapConfirmBox message, element, ->
33+
#callback = $.rails.fire(element, "confirm:complete", [answer])
34+
if $.rails.fire(element, "confirm:complete", [answer])
35+
allowAction = $.rails.allowAction
36+
37+
$.rails.allowAction = ->
38+
true
39+
element.trigger "click"
40+
41+
$.rails.allowAction = allowAction
42+
43+
false

0 commit comments

Comments
 (0)