twitter-bootstrap-rails-confirm 1.0.6 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c8d3c67c7d3310a0c8a501c54dfa55df5ac0eed
4
- data.tar.gz: c1b607e10d288da91216f56ade8f1e742f12389a
3
+ metadata.gz: 5c6fc0126e16b808c7ee4fb81e5e5c589693a33c
4
+ data.tar.gz: 35b26a8694584f33e5c9d11be9d5fb12472a0cef
5
5
  SHA512:
6
- metadata.gz: 624ba343808e818ec3c9e5d04eab263015c49a2307740a4ef7dd6bb198442f9c208c574fcfb8f47dc4782eab01c41109821cafc9976e059f90e9cc81e0de266a
7
- data.tar.gz: 83b7c49d7032f0bdcd0017cb98781fb41171b7727a6b9b920ec41e8eed970b27bcf6f9b757995d30156ab7e341140c6f7eb79b1f8a441bd449a0b07542eaea23
6
+ metadata.gz: e81136caf2cc11ab8630b67fa600637ede0e87438bcf177ecaeb35b6a67d299bff42ad018e7a66eac1499fc964531e9f569cf96704db60866049bb0c8fb6deb7
7
+ data.tar.gz: 00efad5027fa893dc46f0e3099c518b9442615e01b3d5fbc94ec713bc64860e32757b58c29d12a4996797ef275185cf01a761684bacb2bf213aa1548e2af0849
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 Rene van Lieshout
1
+ Copyright (c) 2012 - 2018 Rene van Lieshout
2
2
 
3
3
  MIT License
4
4
 
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
19
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
20
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
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.
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # Twitter::Bootstrap::Rails::Confirm
2
2
 
3
- This gem adds some javascript to change the default behaviour of data-confirm processing for both Boostrap 2 and Bootstrap 3.
3
+ This gem adds some javascript to change the default behaviour of data-confirm processing for both Boostrap 2, 3 and 4.
4
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:
5
+ The normal confirm dialog shows a text with buttons 'ok' and 'cancel'. More information is needed here for a user to
6
+ make the right decision. This gem therefore also adds:
6
7
 
7
8
  * data-confirm-fade (default: false)
8
9
  * data-confirm-title (default: window.top.location.origin)
@@ -11,56 +12,76 @@ The normal confirm dialog shows a text with buttons 'ok' and 'cancel'. More info
11
12
  * data-confirm-proceed (default: 'ok')
12
13
  * data-confirm-proceed-class (default: 'btn-primary')
13
14
 
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
+ This behaviour is similar to that of a "regular" confirm box in ways that it uses the same title and button labels.
16
+ Defaults can be changed in two ways:
15
17
 
16
18
  Changing all default values:
17
19
 
18
- $.fn.twitter_bootstrap_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
- modal_class: ""
26
- };
20
+ ```javascript
21
+ $.fn.twitter_bootstrap_confirmbox.defaults = {
22
+ fade: false,
23
+ title: null, // if title equals null window.top.location.origin is used
24
+ cancel: "Cancel",
25
+ cancel_class: "btn cancel",
26
+ proceed: "OK",
27
+ proceed_class: "btn proceed btn-primary",
28
+ modal_class: ""
29
+ };
30
+ ```
27
31
 
28
32
  Only changing one default value:
29
33
 
30
- $.fn.twitter_bootstrap_confirmbox.defaults.proceed_class = "btn proceed btn-success";
34
+ ```javascript
35
+ $.fn.twitter_bootstrap_confirmbox.defaults.proceed_class = "btn proceed btn-success";
36
+ ```
31
37
 
32
38
  ## Installation
33
39
 
34
40
  Add this line to your application's Gemfile:
35
41
 
36
- gem 'twitter-bootstrap-rails-confirm'
42
+ ```ruby
43
+ gem 'twitter-bootstrap-rails-confirm'
44
+ ```
37
45
 
38
46
  And then execute:
39
47
 
40
- $ bundle
48
+ ```
49
+ $ bundle
50
+ ```
41
51
 
42
- Note: [jQuery-Rails should be > 2.2.1](https://github.com/bluerail/twitter-bootstrap-rails-confirm/issues/27). The exact required version has not yet been determined.
52
+ Note: [jQuery-Rails should be > 2.2.1](https://github.com/bluerail/twitter-bootstrap-rails-confirm/issues/27). The exact
53
+ required version has not yet been determined.
43
54
 
44
55
  ## Usage
45
56
 
46
57
  Add it to your application.js, anywhere after you require jquery_ujs:
47
58
 
48
- //= require twitter/bootstrap/rails/confirm
49
-
50
- 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:
51
-
52
- def destroy_link_to(path, options)
53
- link_to t('.destroy'), path,
54
- :method => :delete,
55
- :class => "btn",
56
- :confirm => t('.destroy_confirm.body', :item => options[:item]),
57
- "data-confirm-fade" => true,
58
- "data-confirm-title" => t('.destroy_confirm.title', :item => options[:item]),
59
- "data-confirm-cancel" => t('.destroy_confirm.cancel', :item => options[:item]),
60
- "data-confirm-cancel-class" => "btn-cancel"),
61
- "data-confirm-proceed" => t('.destroy_confirm.proceed', :item => options[:item]),
62
- "data-confirm-proceed-class" => "btn-danger"
63
- end
59
+ ```coffeescript
60
+ //= require twitter/bootstrap/rails/confirm
61
+ ```
62
+
63
+ Next... nothing. There is nothing you need to do to get this working. A helper could be useful for handling large amount
64
+ of destroy buttons:
65
+
66
+ ```ruby
67
+ def destroy_link_to(path, options)
68
+ link_to t('.destroy'), path,
69
+ :method => :delete,
70
+ :class => 'btn',
71
+ :confirm => t('.destroy_confirm.body', :item => options[:item]),
72
+ 'data-confirm-fade' => true,
73
+ 'data-confirm-title' => t('.destroy_confirm.title', :item => options[:item]),
74
+ 'data-confirm-cancel' => t('.destroy_confirm.cancel', :item => options[:item]),
75
+ 'data-confirm-cancel-class' => 'btn-default'),
76
+ 'data-confirm-proceed' => t('.destroy_confirm.proceed', :item => options[:item]),
77
+ 'data-confirm-proceed-class' => 'btn-danger'
78
+ end
79
+ ```
80
+
81
+ ## Testing
82
+
83
+ See [Twitter Bootstrap Rails Confirm Test](https://github.com/bluerail/twitter-bootstrap-rails-confirm-test) for a
84
+ simple app that loads Bootstrap and this gem.
64
85
 
65
86
  ## Contributing
66
87
 
@@ -72,6 +93,22 @@ Next... nothing. There is nothing you need to do to get this working. A helper c
72
93
 
73
94
  ## Changelog
74
95
 
96
+ ### 2.0.2 (January 18, 2022)
97
+
98
+ * BREAKING: Resolved possible XSS by using .text() over .html()
99
+
100
+ ### 2.0.1 (January 14, 2018)
101
+
102
+ * [(eirvandelden)](https://github.com/eirvandelden) [Bootstrap 4 version is stored in Tooltip.VERSION](https://github.com/bluerail/twitter-bootstrap-rails-confirm/pull/38)
103
+
104
+ ### 2.0.0 (April 26, 2018)
105
+
106
+ * [(mftaff)](https://github.com/mftaff) [Convert CoffeeScript to JavaScript](https://github.com/bluerail/twitter-bootstrap-rails-confirm/pull/37)
107
+
108
+ ### 1.0.7 (November 24, 2017)
109
+
110
+ * [(thiesp)](https://github.com/thiesp) [Adding template and setting default cancel class to btn-secondary for bootstrap 4](https://github.com/bluerail/twitter-bootstrap-rails-confirm/pull/35)
111
+
75
112
  ### 1.0.6 (June 9, 2016)
76
113
 
77
114
  * [(rvanlieshout)](https://github.com/rvanlieshout) [Added proper events for Bootstrap 3](https://github.com/bluerail/twitter-bootstrap-rails-confirm/issues/28)
@@ -2,7 +2,7 @@ module Twitter
2
2
  module Bootstrap
3
3
  module Rails
4
4
  module Confirm
5
- VERSION = "1.0.6"
5
+ VERSION = "2.0.2"
6
6
  end
7
7
  end
8
8
  end
@@ -0,0 +1,127 @@
1
+ (function() {
2
+ var TwitterBootstrapConfirmBox;
3
+
4
+ $.fn.twitter_bootstrap_confirmbox = {
5
+ defaults: {
6
+ title: null,
7
+ proceed: "OK",
8
+ proceed_class: "btn proceed",
9
+ cancel: "Cancel",
10
+ cancel_class: "btn cancel",
11
+ fade: false,
12
+ modal_class: ""
13
+ }
14
+ };
15
+
16
+ TwitterBootstrapConfirmBox = function(message, element, callback) {
17
+ var $dialog, bootstrap_version;
18
+ if (typeof $().emulateTransitionEnd === 'function') {
19
+ if ($.fn.tooltip.Constructor === undefined) {
20
+ bootstrap_version = Tooltip.VERSION[0]
21
+ } else {
22
+ bootstrap_version = $.fn.tooltip.Constructor.VERSION[0]
23
+ }
24
+ } else {
25
+ bootstrap_version = 2
26
+ }
27
+
28
+ switch (bootstrap_version) {
29
+ case 2:
30
+ $dialog = $('<div class="modal hide" id="confirmation_dialog"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h3 class="modal-title">...</h3> </div> <div class="modal-body"></div> <div class="modal-footer"></div> </div>');
31
+ break;
32
+ case 3:
33
+ $dialog = $('<div class="modal" id="confirmation_dialog" role="dialog"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h4 class="modal-title">...</h4> </div> <div class="modal-body"></div> <div class="modal-footer"></div> </div> </div> </div>');
34
+ break;
35
+ default:
36
+ $dialog = $('<div class="modal" id="confirmation_dialog" role="dialog"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h4 class="modal-title">...</h4> <button type="button" class="close" data-dismiss="modal">×</button> </div> <div class="modal-body"></div> <div class="modal-footer"></div> </div> </div> </div>');
37
+ }
38
+
39
+ $dialog.addClass(element.data("confirm-modal-class") || $.fn.twitter_bootstrap_confirmbox.defaults.modal_class);
40
+
41
+ if (element.data("confirm-fade") || $.fn.twitter_bootstrap_confirmbox.defaults.fade) {
42
+ $dialog.addClass("fade");
43
+ }
44
+
45
+ $dialog.find(".modal-header .modal-title").text(element.data("confirm-title") || $.fn.twitter_bootstrap_confirmbox.defaults.title || window.top.location.origin);
46
+
47
+ var dialog_body = $dialog.find(".modal-body");
48
+ var paragraphs = message.toString().split(/\n/);
49
+ dialog_body.html('');
50
+ for (var paragraph_index in paragraphs) {
51
+ $("<p></p>").appendTo(dialog_body).text(paragraphs[paragraph_index]);
52
+ }
53
+
54
+ var cancel_buton = $("<a />", { href: "#", "data-dismiss": "modal" });
55
+ cancel_buton.text(element.data("confirm-cancel") || $.fn.twitter_bootstrap_confirmbox.defaults.cancel);
56
+ cancel_buton.addClass($.fn.twitter_bootstrap_confirmbox.defaults.cancel_class);
57
+ cancel_buton.addClass(element.data("confirm-cancel-class") || (bootstrap_version === 4 ? "btn-secondary" : void 0) || "btn-default");
58
+ cancel_buton.click(function(event) {
59
+ event.preventDefault();
60
+ return $dialog.modal("hide");
61
+ });
62
+ $dialog.find(".modal-footer").append(cancel_buton);
63
+
64
+ var confirm_button = $("<a />", { href: "#" });
65
+ confirm_button.text(element.data("confirm-proceed") || $.fn.twitter_bootstrap_confirmbox.defaults.proceed);
66
+ confirm_button.addClass($.fn.twitter_bootstrap_confirmbox.defaults.proceed_class);
67
+ confirm_button.addClass(element.data("confirm-proceed-class") || "btn-primary");
68
+ confirm_button.click(function(event) {
69
+ event.preventDefault();
70
+ $dialog.modal("hide");
71
+ return callback();
72
+ });
73
+ $dialog.find(".modal-footer").append(confirm_button);
74
+
75
+ $dialog.on('keypress', function(e) {
76
+ if (e.keyCode === 13) { return $('.modal-footer a:last').trigger('click'); }
77
+ }).on("hidden hidden.bs.modal", function() {
78
+ return $(this).remove();
79
+ });
80
+
81
+ $dialog.modal("show").appendTo(document.body);
82
+ };
83
+
84
+ if (typeof $().modal === 'function') {
85
+ $.rails.allowAction = function(element) {
86
+ $(element).blur();
87
+
88
+ var message = element.data("confirm");
89
+ var answer = false;
90
+
91
+ if (!message) {
92
+ return true;
93
+ }
94
+
95
+ if ($.rails.fire(element, "confirm")) {
96
+ TwitterBootstrapConfirmBox(message, element, function() {
97
+ if ($.rails.fire(element, "confirm:complete", [answer])) {
98
+ var allowAction = $.rails.allowAction;
99
+
100
+ $.rails.allowAction = function() {
101
+ return true;
102
+ };
103
+
104
+ if (element.get(0).click) {
105
+ element.get(0).click();
106
+ } else if (typeof Event !== "undefined" && Event !== null) {
107
+ var evt = new Event("click", { bubbles: true, cancelable: true, view: window, detail: 0, screenX: 0,
108
+ screenY: 0, clientX: 0, clientY: 0, ctrlKey: false, altKey: false,
109
+ shiftKey: false, metaKey: false, button: 0,
110
+ relatedTarget: document.body.parentNode });
111
+
112
+ element.get(0).dispatchEvent(evt);
113
+ } else if ($.isFunction(document.createEvent)) {
114
+ var evt = document.createEvent("MouseEvents");
115
+ evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, document.body.parentNode);
116
+
117
+ element.get(0).dispatchEvent(evt);
118
+ }
119
+
120
+ return $.rails.allowAction = allowAction;
121
+ }
122
+ });
123
+ }
124
+ return false;
125
+ };
126
+ }
127
+ }).call(this);
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twitter-bootstrap-rails-confirm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rene van Lieshout
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-09 00:00:00.000000000 Z
11
+ date: 2022-01-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Confirm dialogs using Twitter Bootstrap
14
14
  email:
@@ -26,7 +26,7 @@ files:
26
26
  - lib/twitter-bootstrap-rails-confirm/engine.rb
27
27
  - lib/twitter-bootstrap-rails-confirm/version.rb
28
28
  - twitter-bootstrap-rails-confirm.gemspec
29
- - vendor/assets/javascripts/twitter/bootstrap/rails/confirm.coffee
29
+ - vendor/assets/javascripts/twitter/bootstrap/rails/confirm.js
30
30
  homepage: https://github.com/bluerail/twitter-bootstrap-rails-confirm
31
31
  licenses: []
32
32
  metadata: {}
@@ -1,149 +0,0 @@
1
- $.fn.twitter_bootstrap_confirmbox =
2
- defaults:
3
- title: null
4
- proceed: "OK"
5
- proceed_class: "btn proceed"
6
- cancel: "Cancel"
7
- cancel_class: "btn cancel"
8
- fade: false
9
- modal_class: ""
10
-
11
- TwitterBootstrapConfirmBox = (message, element, callback) ->
12
- bootstrap_version = if (typeof $().emulateTransitionEnd == 'function') then 3 else 2
13
-
14
- if bootstrap_version == 2
15
- $dialog = $('
16
- <div class="modal hide" id="confirmation_dialog">
17
- <div class="modal-header">
18
- <button type="button" class="close" data-dismiss="modal">×</button>
19
- <h3 class="modal-title">...</h3>
20
- </div>
21
- <div class="modal-body"></div>
22
- <div class="modal-footer"></div>
23
- </div>
24
- ')
25
- else
26
- $dialog = $('
27
- <div class="modal" id="confirmation_dialog" role="dialog">
28
- <div class="modal-dialog">
29
- <div class="modal-content">
30
- <div class="modal-header">
31
- <button type="button" class="close" data-dismiss="modal">×</button>
32
- <h4 class="modal-title">...</h4>
33
- </div>
34
- <div class="modal-body"></div>
35
- <div class="modal-footer"></div>
36
- </div>
37
- </div>
38
- </div>
39
- ')
40
-
41
- $dialog.addClass(element.data("confirm-modal-class") || $.fn.twitter_bootstrap_confirmbox.defaults.modal_class)
42
-
43
- $dialog.addClass("fade") if element.data("confirm-fade") || $.fn.twitter_bootstrap_confirmbox.defaults.fade
44
-
45
- $dialog
46
- .find(".modal-header")
47
- .find(".modal-title")
48
- .html(element.data("confirm-title") || $.fn.twitter_bootstrap_confirmbox.defaults.title || window.top.location.origin)
49
- .end()
50
- .end()
51
-
52
- .find(".modal-body")
53
- .html(message.toString().replace(/\n/g, "<br />"))
54
- .end()
55
-
56
- .find(".modal-footer")
57
- .append(
58
- $("<a />", {href: "#", "data-dismiss": "modal"})
59
- .html(element.data("confirm-cancel") || $.fn.twitter_bootstrap_confirmbox.defaults.cancel)
60
- .addClass($.fn.twitter_bootstrap_confirmbox.defaults.cancel_class)
61
- .addClass(element.data("confirm-cancel-class") || "btn-default")
62
- .click((event) ->
63
- event.preventDefault()
64
- $dialog.modal("hide")
65
- )
66
- ,
67
- $("<a />", {href: "#"})
68
- .html(element.data("confirm-proceed") || $.fn.twitter_bootstrap_confirmbox.defaults.proceed)
69
- .addClass($.fn.twitter_bootstrap_confirmbox.defaults.proceed_class)
70
- .addClass(element.data("confirm-proceed-class") || "btn-primary")
71
- .click((event) ->
72
- event.preventDefault()
73
- $dialog.modal("hide")
74
- callback()
75
- )
76
- )
77
- .end()
78
-
79
- .on('keypress', (e) ->
80
- $('.modal-footer a:last').trigger('click') if e.keyCode == 13 # Enter Key Code
81
- )
82
-
83
- .on("hidden hidden.bs.modal", -> $(this).remove())
84
-
85
- .modal("show")
86
-
87
- .appendTo(document.body)
88
-
89
- if (typeof $().modal == 'function') # test if bootstrap is loaded
90
- $.rails.allowAction = (element) ->
91
- $(element).blur();
92
- message = element.data("confirm")
93
- answer = false
94
- return true unless message
95
-
96
- if $.rails.fire(element, "confirm")
97
- TwitterBootstrapConfirmBox message, element, ->
98
- if $.rails.fire(element, "confirm:complete", [answer])
99
- allowAction = $.rails.allowAction
100
-
101
- $.rails.allowAction = ->
102
- true
103
-
104
- if element.get(0).click
105
- element.get(0).click()
106
-
107
- else if Event?
108
- evt = new Event("click", {
109
- bubbles: true,
110
- cancelable: true,
111
- view: window,
112
- detail: 0,
113
- screenX: 0,
114
- screenY: 0,
115
- clientX: 0,
116
- clientY: 0,
117
- ctrlKey: false,
118
- altKey: false,
119
- shiftKey: false,
120
- metaKey: false,
121
- button: 0,
122
- relatedTarget: document.body.parentNode
123
- })
124
- element.get(0).dispatchEvent(evt)
125
-
126
- else if $.isFunction(document.createEvent)
127
- evt = document.createEvent "MouseEvents"
128
- evt.initMouseEvent(
129
- "click",
130
- true, # e.bubbles,
131
- true, # e.cancelable,
132
- window, # e.view,
133
- 0, # e.detail,
134
- 0, # e.screenX,
135
- 0, # e.screenY,
136
- 0, # e.clientX,
137
- 0, # e.clientY,
138
- false, # e.ctrlKey,
139
- false, # e.altKey,
140
- false, # e.shiftKey,
141
- false, # e.metaKey,
142
- 0, # e.button,
143
- document.body.parentNode # e.relatedTarget
144
- )
145
- element.get(0).dispatchEvent(evt)
146
-
147
- $.rails.allowAction = allowAction
148
-
149
- false