jquery-dirtyforms-rails 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5265103f5d9276efeff89168e6894497df260b6d
4
+ data.tar.gz: ec9a3d9dea88096e6ad9b3e4f36a64e028c3accc
5
+ SHA512:
6
+ metadata.gz: 568a72381051cc8dd182b112ba2b48d4e84a6d9c0f6dd9bcbfb301160703d44d07a02eaf5739056a96a98526a3e198d85b47ba53b07f06d06a5591b9ebdcde45
7
+ data.tar.gz: 08b4066398a36ea3bd8293130152860d01737f78c6e7fc53c0a8c8e10399ee71f149f32fad6917b4b3bcb319965deb9ea539cd304822f7a30e1479ba4466adca
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2015 Eric Guo
2
+ Copyright (C) 2011 by Mal Curtis
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in
12
+ all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ THE SOFTWARE.
@@ -0,0 +1,45 @@
1
+ jQuery-DirtyForms-Rails [![Gem Version][version-badge]][rubygems]
2
+ =======================
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ gem 'jquery-dirtyforms-rails'
9
+
10
+ And then execute:
11
+
12
+ $ bundle
13
+
14
+ ## Usage
15
+
16
+ app/assets/javascripts/application.js
17
+
18
+ ```javascript
19
+ //= require jquery.dirtyforms
20
+ //= require jquery.dirtyforms.dialogs.bootstrap
21
+
22
+ $(document).ready(function() {
23
+ $("form.sodirty").dirtyForms();
24
+ });
25
+ ```
26
+
27
+ At any erb/slim/haml view
28
+
29
+ ```erb
30
+ <%= form_for :person, html: { class: "sodirty" } do |f| %>
31
+ First name: <%= f.text_field :first_name %><br />
32
+ Last name : <%= f.text_field :last_name %><br />
33
+ Biography : <%= f.text_area :biography %><br />
34
+ Admin? : <%= f.check_box :admin %><br />
35
+ <%= f.submit %>
36
+ <% end %>
37
+ ```
38
+
39
+
40
+ ## More detail
41
+
42
+ See [official readme](https://github.com/snikch/jquery.dirtyforms#readme)
43
+
44
+ [version-badge]: https://badge.fury.io/rb/jquery-dirtyforms-rails.svg
45
+ [rubygems]: https://rubygems.org/gems/jquery-dirtyforms-rails
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
@@ -0,0 +1,10 @@
1
+ require 'jquery-dirtyforms-rails/version'
2
+
3
+ module Jquery
4
+ module Dirtyforms
5
+ module Rails
6
+ class Engine < ::Rails::Engine
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ module Jquery
2
+ module Dirtyforms
3
+ module Rails
4
+ VERSION = '2.0.0'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,97 @@
1
+ /*!
2
+ BlockUI dialog module (for jQuery Dirty Forms) | v | github.com/snikch/jquery.dirtyforms
3
+ (c) 2015-2016 Shad Storhaug
4
+ License MIT
5
+ */
6
+
7
+ (function($, window, document, undefined) {
8
+ // Can't use ECMAScript 5's strict mode because several apps
9
+ // including ASP.NET trace the stack via arguments.caller.callee
10
+ // and Firefox dies if you try to trace through "use strict" call chains.
11
+ // See jQuery issue (#13335)
12
+ // Support: Firefox 18+
13
+ //"use strict";
14
+
15
+ $.DirtyForms.dialog = {
16
+ // Custom properties and methods to allow overriding (may differ per dialog)
17
+ title: 'Are you sure you want to do that?',
18
+ class: 'dirty-dialog',
19
+ proceedButtonText: 'Leave This Page',
20
+ stayButtonText: 'Stay Here',
21
+ width: '400px',
22
+ padding: '10px',
23
+ color: '#000',
24
+ border: '3px solid #aaa',
25
+ backgroundColor: '#fff',
26
+ overlayOpacity: 0.5,
27
+
28
+ // Typical Dirty Forms Properties and Methods
29
+ open: function (choice, message) {
30
+ $.blockUI({
31
+ message: '<span class="' + this.class + '">' +
32
+ '<h3>' + this.title + '</h3>' +
33
+ '<p>' + message + '</p>' +
34
+ '<span>' +
35
+ '<button type="button" class="dirty-proceed">' + this.proceedButtonText + '</button> ' +
36
+ '<button type="button" class="dirty-stay">' + this.stayButtonText + '</button>' +
37
+ '</span>' +
38
+ '</span>',
39
+ css: {
40
+ width: this.width,
41
+ padding: this.padding,
42
+ color: this.color,
43
+ border: this.border,
44
+ backgroundColor: this.backgroundColor,
45
+ cursor: 'auto'
46
+ },
47
+ overlayCSS: {
48
+ cursor: 'auto',
49
+ opacity: this.overlayOpacity
50
+ }
51
+ });
52
+
53
+ // Bind Events
54
+ choice.bindEnterKey = true;
55
+ choice.proceedSelector = '.' + this.class + ' .dirty-proceed';
56
+ choice.staySelector = '.' + this.class + ' .dirty-stay,.blockOverlay';
57
+
58
+ // Support for Dirty Forms < 2.0
59
+ if (choice.isDF1) {
60
+ var close = function (decision) {
61
+ return function (e) {
62
+ if (e.type !== 'keydown' || (e.type === 'keydown' && (e.which == 27 || e.which == 13))) {
63
+ $.unblockUI();
64
+ decision(e);
65
+ return false;
66
+ }
67
+ };
68
+ };
69
+ var decidingCancel = $.DirtyForms.decidingCancel;
70
+ $(document).keydown(close(decidingCancel));
71
+ $(choice.staySelector).click(close(decidingCancel));
72
+ $(choice.proceedSelector).click(close($.DirtyForms.decidingContinue));
73
+ }
74
+ },
75
+ close: function () {
76
+ $.unblockUI();
77
+ },
78
+
79
+ // Support for Dirty Forms < 2.0
80
+ fire: function (message, title) {
81
+ this.title = title;
82
+ this.open({ isDF1: true }, message);
83
+ },
84
+
85
+ // Support for Dirty Forms < 1.2
86
+ bind: function () {
87
+ },
88
+ stash: function () {
89
+ return false;
90
+ },
91
+ refire: function () {
92
+ return false;
93
+ },
94
+ selector: 'no-op'
95
+ };
96
+
97
+ })(jQuery, window, document);
@@ -0,0 +1,110 @@
1
+ /*!
2
+ Bootstrap modal dialog (for jQuery Dirty Forms) | v | github.com/snikch/jquery.dirtyforms
3
+ (c) 2015-2016 Shad Storhaug
4
+ License MIT
5
+ */
6
+
7
+ (function($, window, document, undefined) {
8
+ // Can't use ECMAScript 5's strict mode because several apps
9
+ // including ASP.NET trace the stack via arguments.caller.callee
10
+ // and Firefox dies if you try to trace through "use strict" call chains.
11
+ // See jQuery issue (#13335)
12
+ // Support: Firefox 18+
13
+ //"use strict";
14
+
15
+ var exclamationGlyphicon = '<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> ';
16
+
17
+ $.DirtyForms.dialog = {
18
+ // Custom properties and methods to allow overriding (may differ per dialog)
19
+ title: exclamationGlyphicon + 'Are you sure you want to do that?',
20
+ proceedButtonClass: 'dirty-proceed',
21
+ proceedButtonText: 'Leave This Page',
22
+ stayButtonClass: 'dirty-stay',
23
+ stayButtonText: 'Stay Here',
24
+ dialogID: 'dirty-dialog',
25
+ titleID: 'dirty-title',
26
+ messageClass: 'dirty-message',
27
+ preMessageText: '',
28
+ postMessageText: '',
29
+ replaceText: true,
30
+
31
+ // Typical Dirty Forms Properties and Methods
32
+ open: function (choice, message) {
33
+ // Look for a pre-existing element with the dialogID.
34
+ var $dialog = $('#' + this.dialogID);
35
+
36
+ // If the user already added a dialog with this ID, skip doing it here
37
+ if ($dialog.length === 0) {
38
+ // NOTE: Buttons don't have the ignore class because Bootstrap 3 isn't compatible
39
+ // with old versions of jQuery that don't properly cancel the click events.
40
+ $dialog =
41
+ $('<div id="' + this.dialogID + '" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="' + this.titleID + '">' +
42
+ '<div class="modal-dialog" role="document">' +
43
+ '<div class="modal-content panel-danger">' +
44
+ '<div class="modal-header panel-heading">' +
45
+ '<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>' +
46
+ '<h3 class="modal-title" id="' + this.titleID + '"></h3>' +
47
+ '</div>' +
48
+ '<div class="modal-body panel-body ' + this.messageClass + '"></div>' +
49
+ '<div class="modal-footer panel-footer">' +
50
+ '<button type="button" class="' + this.proceedButtonClass + ' btn btn-danger" data-dismiss="modal"></button>' +
51
+ '<button type="button" class="' + this.stayButtonClass + ' btn btn-default" data-dismiss="modal"></button>' +
52
+ '</div>' +
53
+ '</div>' +
54
+ '</div>' +
55
+ '</div>');
56
+
57
+ // Append to the body so we can capture DOM events.
58
+ // Flag the dialog for later removal.
59
+ $('body').append($dialog)
60
+ .data('df-dialog-appended', true);
61
+ }
62
+
63
+ if (this.replaceText) {
64
+ // Replace the text in the dialog (whether it is external or not).
65
+ $dialog.find('#' + this.titleID).html(this.title);
66
+ $dialog.find('.' + this.messageClass).html(this.preMessageText + message + this.postMessageText);
67
+ $dialog.find('.' + this.proceedButtonClass).html(this.proceedButtonText);
68
+ $dialog.find('.' + this.stayButtonClass).html(this.stayButtonText);
69
+ }
70
+
71
+ // Bind the events
72
+ choice.bindEscKey = false;
73
+
74
+ var onContinueClick = function () {
75
+ choice.proceed = $.DirtyForms.choiceContinue = true;
76
+ };
77
+ var onHidden = function (e) {
78
+ var commit = choice.isDF1 ? $.DirtyForms.choiceCommit : choice.commit;
79
+ commit(e);
80
+ if ($('body').data('df-dialog-appended') === true) {
81
+ $dialog.remove();
82
+ }
83
+ };
84
+ // NOTE: Bootstrap 3 requires jQuery 1.9, so we can use on and off here.
85
+ $dialog.find('.' + this.proceedButtonClass).off('click', onContinueClick).on('click', onContinueClick);
86
+ $dialog.off('hidden.bs.modal', onHidden).on('hidden.bs.modal', onHidden);
87
+
88
+ // Show the dialog
89
+ $dialog.modal({ show: true });
90
+ },
91
+
92
+ // Support for Dirty Forms < 2.0
93
+ fire: function (message, title) {
94
+ this.title = exclamationGlyphicon + title;
95
+ this.open({ isDF1: true }, message);
96
+ },
97
+
98
+ // Support for Dirty Forms < 1.2
99
+ bind: function () {
100
+ },
101
+ stash: function () {
102
+ return false;
103
+ },
104
+ refire: function () {
105
+ return false;
106
+ },
107
+ selector: 'no-op',
108
+ };
109
+
110
+ })(jQuery, window, document);
@@ -0,0 +1,126 @@
1
+ /*!
2
+ Facebox dialog module (for jQuery Dirty Forms) | v | github.com/snikch/jquery.dirtyforms
3
+ (c) 2015-2016 Shad Storhaug
4
+ License MIT
5
+ */
6
+
7
+ (function($, window, document, undefined) {
8
+ // Can't use ECMAScript 5's strict mode because several apps
9
+ // including ASP.NET trace the stack via arguments.caller.callee
10
+ // and Firefox dies if you try to trace through "use strict" call chains.
11
+ // See jQuery issue (#13335)
12
+ // Support: Firefox 18+
13
+ //"use strict";
14
+
15
+ $.DirtyForms.dialog = {
16
+ // Custom properties and methods to allow overriding (may differ per dialog)
17
+ title: 'Are you sure you want to do that?',
18
+ proceedButtonClass: '',
19
+ proceedButtonText: 'Leave This Page',
20
+ stayButtonClass: '',
21
+ stayButtonText: 'Stay Here',
22
+
23
+ // Typical Dirty Forms Properties and Methods
24
+
25
+ // Selector for stashing the content of another dialog.
26
+ stashSelector: '#facebox .content',
27
+ open: function (choice, message, ignoreClass) {
28
+ var content =
29
+ '<h1>' + this.title + '</h1>' +
30
+ '<p>' + message + '</p>' +
31
+ '<p>' +
32
+ '<a href="#" class="dirty-proceed ' + ignoreClass + ' ' + this.proceedButtonClass + '">' + this.proceedButtonText + '</a>' +
33
+ '<a href="#" class="dirty-stay ' + ignoreClass + ' ' + this.stayButtonClass + '">' + this.stayButtonText + '</a>' +
34
+ '</p>';
35
+ $.facebox(content);
36
+
37
+ // Bind Events
38
+ choice.bindEnterKey = true;
39
+ choice.staySelector = '#facebox .dirty-stay, #facebox .close, #facebox_overlay';
40
+ choice.proceedSelector = '#facebox .dirty-proceed';
41
+
42
+ if (choice.isDF1) {
43
+ var close = function (decision) {
44
+ return function (e) {
45
+ if (e.type !== 'keydown' || (e.type === 'keydown' && (e.which == 27 || e.which == 13))) {
46
+ // Facebox hack: If we call close when returning from the stash, the
47
+ // stash dialog will close, so we guard against calling close in that case.
48
+ if (!$.DirtyForms.dialogStash) {
49
+ $(document).trigger('close.facebox');
50
+ }
51
+ decision(e);
52
+ }
53
+ };
54
+ };
55
+ var decidingCancel = $.DirtyForms.decidingCancel;
56
+ $(document).bind('keydown.facebox', close(decidingCancel));
57
+ $(choice.staySelector).click(close(decidingCancel));
58
+ $(choice.proceedSelector).click(close($.DirtyForms.decidingContinue));
59
+ }
60
+ },
61
+ close: function (continuing, unstashing) {
62
+ // Facebox hack: If we call close when returning from the stash, the
63
+ // stash dialog will close, so we guard against calling close in that case.
64
+ if (!unstashing) {
65
+ $(document).trigger('close.facebox');
66
+ }
67
+ },
68
+ stash: function () {
69
+ var isDF1 = typeof $.DirtyForms.isDeciding === 'function',
70
+ $fb = $('#facebox'),
71
+ $content = $fb.find('.content');
72
+
73
+ // Store the DOM state as actual HTML DOM values
74
+ $content.find('datalist,select,textarea,input').not('[type="button"],[type="submit"],[type="reset"],[type="image"]').each(function () {
75
+ storeFieldValue($(this));
76
+ });
77
+
78
+ return ($.trim($fb.html()) === '' || $fb.css('display') != 'block') ?
79
+ false :
80
+ isDF1 ?
81
+ $content.clone(true) :
82
+ $content.children().clone(true);
83
+ },
84
+ unstash: function (stash, ev) {
85
+ $.facebox(stash);
86
+ },
87
+
88
+ // Support for Dirty Forms < 2.0
89
+ fire: function (message, title) {
90
+ this.title = title;
91
+ this.open({ isDF1: true }, message, $.DirtyForms.ignoreClass);
92
+ },
93
+ selector: $.DirtyForms.dialog.stashSelector,
94
+
95
+ // Support for Dirty Forms < 1.2
96
+ bind: function () {
97
+ },
98
+ refire: function (content, ev) {
99
+ this.unstash(content, ev);
100
+ }
101
+ };
102
+
103
+ var storeFieldValue = function ($field) {
104
+ if ($field.is('select,datalist')) {
105
+ $field.find('option').each(function () {
106
+ var $option = $(this);
107
+ if ($option.is(':selected')) {
108
+ $option.attr('selected', 'selected');
109
+ } else {
110
+ $option.removeAttr('selected');
111
+ }
112
+ });
113
+ } else if ($field.is(":checkbox,:radio")) {
114
+ if ($field.is(':checked')) {
115
+ $field.attr('checked', 'checked');
116
+ } else {
117
+ $field.removeAttr('checked');
118
+ }
119
+ } else if ($field.is('textarea')) {
120
+ $field.text($field.val());
121
+ } else {
122
+ $field.attr('value', $field.val());
123
+ }
124
+ };
125
+
126
+ })(jQuery, window, document);
@@ -0,0 +1,96 @@
1
+ /*!
2
+ jQuery UI dialog module (for jQuery Dirty Forms) | v | github.com/snikch/jquery.dirtyforms
3
+ (c) 2015-2016 Shad Storhaug
4
+ License MIT
5
+ */
6
+
7
+ (function($, window, document, undefined) {
8
+ // Can't use ECMAScript 5's strict mode because several apps
9
+ // including ASP.NET trace the stack via arguments.caller.callee
10
+ // and Firefox dies if you try to trace through "use strict" call chains.
11
+ // See jQuery issue (#13335)
12
+ // Support: Firefox 18+
13
+ //"use strict";
14
+
15
+ // Create a local reference for simplicity
16
+ var $dialog = $('<div style="display:none;" />');
17
+ $('body').append($dialog);
18
+
19
+ $.DirtyForms.dialog = {
20
+ // Custom properties and methods to allow overriding (may differ per dialog)
21
+ title: 'Are you sure you want to do that?',
22
+ proceedButtonText: 'Leave This Page',
23
+ stayButtonText: 'Stay Here',
24
+ preMessageText: '<span class="ui-icon ui-icon-alert" style="float:left; margin:2px 7px 25px 0;"></span>',
25
+ postMessageText: '',
26
+ width: 430,
27
+
28
+ // Typical Dirty Forms Properties and Methods
29
+ open: function (choice, message) {
30
+ var commit = choice.isDF1 ? $.DirtyForms.choiceCommit : choice.commit;
31
+
32
+ $dialog.dialog({
33
+ open: function () {
34
+ // Set the focus on close button
35
+ $(this).parents('.ui-dialog').find('.ui-dialog-buttonpane button:eq(1)').focus();
36
+ },
37
+ close: commit,
38
+ title: this.title,
39
+ width: this.width,
40
+ modal: true,
41
+ buttons: [
42
+ {
43
+ text: this.proceedButtonText,
44
+ click: function () {
45
+ choice.proceed = $.DirtyForms.choiceContinue = true;
46
+ $(this).dialog('close');
47
+ }
48
+ },
49
+ {
50
+ text: this.stayButtonText,
51
+ click: function () {
52
+ $(this).dialog('close');
53
+ }
54
+ }
55
+ ]
56
+ });
57
+ $dialog.html(this.preMessageText + message + this.postMessageText);
58
+
59
+ // Support for Dirty Forms < 2.0
60
+ if (choice.isDF1) {
61
+ var onEscKey = function (e) {
62
+ if (e.which == 27) {
63
+ e.preventDefault();
64
+ $dialog.dialog('close');
65
+ return false;
66
+ }
67
+ };
68
+
69
+ // Trap the escape key and force a close. Cancel it so jQuery UI doesn't intercept it.
70
+ // This will fire the dialogclose event to commit the choice (which defaults to false).
71
+ $(document).unbind('keydown', onEscKey).keydown(onEscKey);
72
+ }
73
+ },
74
+ close: function () {
75
+ $dialog.dialog('close');
76
+ },
77
+
78
+ // Support for Dirty Forms < 2.0
79
+ fire: function (message, title) {
80
+ this.title = title;
81
+ this.open({ isDF1: true }, message);
82
+ },
83
+
84
+ // Support for Dirty Forms < 1.2
85
+ bind: function () {
86
+ },
87
+ stash: function () {
88
+ return false;
89
+ },
90
+ refire: function () {
91
+ return false;
92
+ },
93
+ selector: 'no-op'
94
+ };
95
+
96
+ })(jQuery, window, document);