jquery-are_you_sure 1.9.0
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 +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +2 -0
- data/app/assets/javascripts/jquery.are-you-sure.js +192 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/jquery-are_you_sure.gemspec +25 -0
- data/lib/jquery/are_you_sure.rb +7 -0
- data/lib/jquery/are_you_sure/engine.rb +6 -0
- data/lib/jquery/are_you_sure/version.rb +5 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8a0f355cc257ec4a08ba5a57f49eefef91b8fc46
|
4
|
+
data.tar.gz: 5d8a8d198605e68ccaf1f7e2425f8631372bf38c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3b50246c4bfa1fc9e92969293fee8dfd5dc5f7946519b88f3f2754f4aa10809d4db48d678e08074c422b5aa6df315585f6cbaea7d66c3f514ad399c568489f19
|
7
|
+
data.tar.gz: 1efbd2b1d4ee84d627572cac76b562208c065fa2087401ad6cacfb2b6714726b3055edf4e57bea12682b30ef5adeb3a5c09f86f345cfab73af232f77ece8bdd1
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Julian Popescu
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Jquery::AreYouSure
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/jquery/are_you_sure`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'jquery-are_you_sure'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install jquery-are_you_sure
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/jquery-are_you_sure.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,192 @@
|
|
1
|
+
/*!
|
2
|
+
* jQuery Plugin: Are-You-Sure (Dirty Form Detection)
|
3
|
+
* https://github.com/codedance/jquery.AreYouSure/
|
4
|
+
*
|
5
|
+
* Copyright (c) 2012-2014, Chris Dance and PaperCut Software http://www.papercut.com/
|
6
|
+
* Dual licensed under the MIT or GPL Version 2 licenses.
|
7
|
+
* http://jquery.org/license
|
8
|
+
*
|
9
|
+
* Author: chris.dance@papercut.com
|
10
|
+
* Version: 1.9.0
|
11
|
+
* Date: 13th August 2014
|
12
|
+
*/
|
13
|
+
(function($) {
|
14
|
+
|
15
|
+
$.fn.areYouSure = function(options) {
|
16
|
+
|
17
|
+
var settings = $.extend(
|
18
|
+
{
|
19
|
+
'message' : 'You have unsaved changes!',
|
20
|
+
'dirtyClass' : 'dirty',
|
21
|
+
'change' : null,
|
22
|
+
'silent' : false,
|
23
|
+
'addRemoveFieldsMarksDirty' : false,
|
24
|
+
'fieldEvents' : 'change keyup propertychange input',
|
25
|
+
'fieldSelector': ":input:not(input[type=submit]):not(input[type=button])"
|
26
|
+
}, options);
|
27
|
+
|
28
|
+
var getValue = function($field) {
|
29
|
+
if ($field.hasClass('ays-ignore')
|
30
|
+
|| $field.hasClass('aysIgnore')
|
31
|
+
|| $field.attr('data-ays-ignore')
|
32
|
+
|| $field.attr('name') === undefined) {
|
33
|
+
return null;
|
34
|
+
}
|
35
|
+
|
36
|
+
if ($field.is(':disabled')) {
|
37
|
+
return 'ays-disabled';
|
38
|
+
}
|
39
|
+
|
40
|
+
var val;
|
41
|
+
var type = $field.attr('type');
|
42
|
+
if ($field.is('select')) {
|
43
|
+
type = 'select';
|
44
|
+
}
|
45
|
+
|
46
|
+
switch (type) {
|
47
|
+
case 'checkbox':
|
48
|
+
case 'radio':
|
49
|
+
val = $field.is(':checked');
|
50
|
+
break;
|
51
|
+
case 'select':
|
52
|
+
val = '';
|
53
|
+
$field.find('option').each(function(o) {
|
54
|
+
var $option = $(this);
|
55
|
+
if ($option.is(':selected')) {
|
56
|
+
val += $option.val();
|
57
|
+
}
|
58
|
+
});
|
59
|
+
break;
|
60
|
+
default:
|
61
|
+
val = $field.val();
|
62
|
+
}
|
63
|
+
|
64
|
+
return val;
|
65
|
+
};
|
66
|
+
|
67
|
+
var storeOrigValue = function($field) {
|
68
|
+
$field.data('ays-orig', getValue($field));
|
69
|
+
};
|
70
|
+
|
71
|
+
var checkForm = function(evt) {
|
72
|
+
|
73
|
+
var isFieldDirty = function($field) {
|
74
|
+
var origValue = $field.data('ays-orig');
|
75
|
+
if (undefined === origValue) {
|
76
|
+
return false;
|
77
|
+
}
|
78
|
+
return (getValue($field) != origValue);
|
79
|
+
};
|
80
|
+
|
81
|
+
var $form = ($(this).is('form'))
|
82
|
+
? $(this)
|
83
|
+
: $(this).parents('form');
|
84
|
+
|
85
|
+
// Test on the target first as it's the most likely to be dirty
|
86
|
+
if (isFieldDirty($(evt.target))) {
|
87
|
+
setDirtyStatus($form, true);
|
88
|
+
return;
|
89
|
+
}
|
90
|
+
|
91
|
+
$fields = $form.find(settings.fieldSelector);
|
92
|
+
|
93
|
+
if (settings.addRemoveFieldsMarksDirty) {
|
94
|
+
// Check if field count has changed
|
95
|
+
var origCount = $form.data("ays-orig-field-count");
|
96
|
+
if (origCount != $fields.length) {
|
97
|
+
setDirtyStatus($form, true);
|
98
|
+
return;
|
99
|
+
}
|
100
|
+
}
|
101
|
+
|
102
|
+
// Brute force - check each field
|
103
|
+
var isDirty = false;
|
104
|
+
$fields.each(function() {
|
105
|
+
$field = $(this);
|
106
|
+
if (isFieldDirty($field)) {
|
107
|
+
isDirty = true;
|
108
|
+
return false; // break
|
109
|
+
}
|
110
|
+
});
|
111
|
+
|
112
|
+
setDirtyStatus($form, isDirty);
|
113
|
+
};
|
114
|
+
|
115
|
+
var initForm = function($form) {
|
116
|
+
var fields = $form.find(settings.fieldSelector);
|
117
|
+
$(fields).each(function() { storeOrigValue($(this)); });
|
118
|
+
$(fields).unbind(settings.fieldEvents, checkForm);
|
119
|
+
$(fields).bind(settings.fieldEvents, checkForm);
|
120
|
+
$form.data("ays-orig-field-count", $(fields).length);
|
121
|
+
setDirtyStatus($form, false);
|
122
|
+
};
|
123
|
+
|
124
|
+
var setDirtyStatus = function($form, isDirty) {
|
125
|
+
var changed = isDirty != $form.hasClass(settings.dirtyClass);
|
126
|
+
$form.toggleClass(settings.dirtyClass, isDirty);
|
127
|
+
|
128
|
+
// Fire change event if required
|
129
|
+
if (changed) {
|
130
|
+
if (settings.change) settings.change.call($form, $form);
|
131
|
+
|
132
|
+
if (isDirty) $form.trigger('dirty.areYouSure', [$form]);
|
133
|
+
if (!isDirty) $form.trigger('clean.areYouSure', [$form]);
|
134
|
+
$form.trigger('change.areYouSure', [$form]);
|
135
|
+
}
|
136
|
+
};
|
137
|
+
|
138
|
+
var rescan = function() {
|
139
|
+
var $form = $(this);
|
140
|
+
var fields = $form.find(settings.fieldSelector);
|
141
|
+
$(fields).each(function() {
|
142
|
+
var $field = $(this);
|
143
|
+
if (!$field.data('ays-orig')) {
|
144
|
+
storeOrigValue($field);
|
145
|
+
$field.bind(settings.fieldEvents, checkForm);
|
146
|
+
}
|
147
|
+
});
|
148
|
+
// Check for changes while we're here
|
149
|
+
$form.trigger('checkform.areYouSure');
|
150
|
+
};
|
151
|
+
|
152
|
+
var reinitialize = function() {
|
153
|
+
initForm($(this));
|
154
|
+
}
|
155
|
+
|
156
|
+
if (!settings.silent && !window.aysUnloadSet) {
|
157
|
+
window.aysUnloadSet = true;
|
158
|
+
$(window).bind('beforeunload', function() {
|
159
|
+
$dirtyForms = $("form").filter('.' + settings.dirtyClass);
|
160
|
+
if ($dirtyForms.length == 0) {
|
161
|
+
return;
|
162
|
+
}
|
163
|
+
// Prevent multiple prompts - seen on Chrome and IE
|
164
|
+
if (navigator.userAgent.toLowerCase().match(/msie|chrome/)) {
|
165
|
+
if (window.aysHasPrompted) {
|
166
|
+
return;
|
167
|
+
}
|
168
|
+
window.aysHasPrompted = true;
|
169
|
+
window.setTimeout(function() {window.aysHasPrompted = false;}, 900);
|
170
|
+
}
|
171
|
+
return settings.message;
|
172
|
+
});
|
173
|
+
}
|
174
|
+
|
175
|
+
return this.each(function(elem) {
|
176
|
+
if (!$(this).is('form')) {
|
177
|
+
return;
|
178
|
+
}
|
179
|
+
var $form = $(this);
|
180
|
+
|
181
|
+
$form.submit(function() {
|
182
|
+
$form.removeClass(settings.dirtyClass);
|
183
|
+
});
|
184
|
+
$form.bind('reset', function() { setDirtyStatus($form, false); });
|
185
|
+
// Add a custom events
|
186
|
+
$form.bind('rescan.areYouSure', rescan);
|
187
|
+
$form.bind('reinitialize.areYouSure', reinitialize);
|
188
|
+
$form.bind('checkform.areYouSure', checkForm);
|
189
|
+
initForm($form);
|
190
|
+
});
|
191
|
+
};
|
192
|
+
})(jQuery);
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "jquery/are_you_sure"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'jquery/are_you_sure/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "jquery-are_you_sure"
|
8
|
+
spec.version = Jquery::AreYouSure::VERSION
|
9
|
+
spec.authors = ["Julian Popescu"]
|
10
|
+
spec.email = ["jpopesculian@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "Rails asset for jquery.AreYouSure"
|
13
|
+
spec.homepage = "https://github.com/jpopesculian/jquery-are_you_sure"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jquery-are_you_sure
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.9.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Julian Popescu
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- jpopesculian@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- app/assets/javascripts/jquery.are-you-sure.js
|
54
|
+
- bin/console
|
55
|
+
- bin/setup
|
56
|
+
- jquery-are_you_sure.gemspec
|
57
|
+
- lib/jquery/are_you_sure.rb
|
58
|
+
- lib/jquery/are_you_sure/engine.rb
|
59
|
+
- lib/jquery/are_you_sure/version.rb
|
60
|
+
homepage: https://github.com/jpopesculian/jquery-are_you_sure
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.4.8
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: Rails asset for jquery.AreYouSure
|
84
|
+
test_files: []
|