g_form_submit_protector 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/History.txt +19 -0
- data/README.rdoc +93 -0
- data/Rakefile +66 -0
- data/VERSION +1 -0
- data/g_form_submit_protector.gemspec +73 -0
- data/lib/g_form_submit_protector/view_helpers.rb +16 -0
- data/lib/g_form_submit_protector.rb +12 -0
- data/lib/generators/form_submit_protector_assets/form_submit_protector_assets_generator.rb +14 -0
- data/lib/generators/form_submit_protector_assets/templates/guilded.form_submit_protector.js +24 -0
- data/lib/generators/form_submit_protector_assets/templates/guilded.form_submit_protector.min.js +4 -0
- data/lib/generators/form_submit_protector_assets/templates/jquery-disable_on_submit-1.0.js +45 -0
- data/lib/generators/form_submit_protector_assets/templates/jquery-disable_on_submit-1.0.min.js +7 -0
- data/rails_generators/form_submit_protector_assets/form_submit_protector_assets_generator.rb +15 -0
- data/rails_generators/form_submit_protector_assets/templates/guilded.form_submit_protector.js +24 -0
- data/rails_generators/form_submit_protector_assets/templates/guilded.form_submit_protector.min.js +4 -0
- data/rails_generators/form_submit_protector_assets/templates/jquery-disable_on_submit-1.0.js +45 -0
- data/rails_generators/form_submit_protector_assets/templates/jquery-disable_on_submit-1.0.min.js +7 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/spec/g_form_submit_protector_spec.rb +2 -0
- data/spec/generators/form_submit_protector_assets_generator_spec.rb +28 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +10 -0
- data/tasks/rspec.rake +21 -0
- metadata +114 -0
data/.gitignore
ADDED
data/History.txt
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
== 1.0.3 2010-06-08
|
2
|
+
|
3
|
+
* Converted to a Jeweler project.
|
4
|
+
* Made compatible with Rails 3.
|
5
|
+
|
6
|
+
|
7
|
+
== 1.0.2 2009-08-13
|
8
|
+
|
9
|
+
* Changed :form_class option to be :selector so that any jquery selector can be used, including multiple selectors
|
10
|
+
* Added :all shortcut for the selector option which extrapolates out to 'form', :selector => :all = :selector => 'form'
|
11
|
+
|
12
|
+
== 1.0.1 2009-03-21
|
13
|
+
|
14
|
+
* Fixed bug with not including view_helpers file
|
15
|
+
|
16
|
+
|
17
|
+
== 1.0.0 2009-03-17
|
18
|
+
|
19
|
+
* Initial release
|
data/README.rdoc
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
= g_form_submit_protector
|
2
|
+
|
3
|
+
http://github.com/midas/g_form_submit_protector/tree/master
|
4
|
+
|
5
|
+
|
6
|
+
== DESCRIPTION:
|
7
|
+
|
8
|
+
A Rails Guilded (http://github.com/midas/guilded/tree/master) component that will disable form elements once the
|
9
|
+
submit button has been used.
|
10
|
+
|
11
|
+
|
12
|
+
== FEATURES:
|
13
|
+
|
14
|
+
* Disables the form submission button once the form is submitted
|
15
|
+
* Can implement callback to determine if the disabling should occur (this will help integrate with other form plugins, etc)
|
16
|
+
|
17
|
+
|
18
|
+
== COMPATABILITY
|
19
|
+
|
20
|
+
* Ruby 1.9
|
21
|
+
* Ruby 1.8
|
22
|
+
* Rails 3
|
23
|
+
* Rails 2
|
24
|
+
|
25
|
+
|
26
|
+
== INSTALL:
|
27
|
+
|
28
|
+
gem install g_form_submit_protector
|
29
|
+
|
30
|
+
|
31
|
+
== INSTALL FOR RAILS
|
32
|
+
|
33
|
+
Configure the Gem for use:
|
34
|
+
|
35
|
+
gem 'g_form_submit_protector' # Rails 3
|
36
|
+
config.gem 'g_form_submit_protector' # Rails 2
|
37
|
+
|
38
|
+
Install the Gem:
|
39
|
+
|
40
|
+
bundle install # Rails 3
|
41
|
+
rake gems:install # Rails 2
|
42
|
+
|
43
|
+
Generate:
|
44
|
+
|
45
|
+
rails generate form_submit_protector # Rails 3
|
46
|
+
script/generate form_submit_protector # Rails 2
|
47
|
+
|
48
|
+
|
49
|
+
== USAGE:
|
50
|
+
|
51
|
+
To protect all forms:
|
52
|
+
|
53
|
+
<% g_form_submit_protector :selector => :all %>
|
54
|
+
|
55
|
+
To protect a specific form use any selector that jQuery supports:
|
56
|
+
|
57
|
+
<% g_form_submit_protector :selector => '.protectedForm' %>
|
58
|
+
|
59
|
+
You can even use multiple selectors:
|
60
|
+
|
61
|
+
<% g_form_submit_protector :selector => '.protectedForm,#anotherform' %>
|
62
|
+
|
63
|
+
|
64
|
+
== REQUIREMENTS:
|
65
|
+
|
66
|
+
* Rails >= 2.2.0
|
67
|
+
* Guilded >= 1.0.0 (http://github.com/midas/guilded/tree/master)
|
68
|
+
|
69
|
+
|
70
|
+
== LICENSE:
|
71
|
+
|
72
|
+
(The MIT License)
|
73
|
+
|
74
|
+
Copyright (c) 2009 C. Jason Harrelson (midas)
|
75
|
+
|
76
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
77
|
+
a copy of this software and associated documentation files (the
|
78
|
+
'Software'), to deal in the Software without restriction, including
|
79
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
80
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
81
|
+
permit persons to whom the Software is furnished to do so, subject to
|
82
|
+
the following conditions:
|
83
|
+
|
84
|
+
The above copyright notice and this permission notice shall be
|
85
|
+
included in all copies or substantial portions of the Software.
|
86
|
+
|
87
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
88
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
89
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
90
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
91
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
92
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
93
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "g_form_submit_protector"
|
8
|
+
gem.summary = %Q{A Rails Guilded component that will disable form elements once the submit button has been used.}
|
9
|
+
gem.description = %Q{A Rails Guilded component that will disable form elements once the submit button has been used.}
|
10
|
+
gem.email = "jason@lookforwardenterprises.com"
|
11
|
+
gem.homepage = "http://github.com/midas/g_form_submit_protector"
|
12
|
+
gem.authors = ["C. Jason Harrelson (midas)"]
|
13
|
+
gem.add_dependency "rails", ">= 2.3"
|
14
|
+
gem.add_dependency "guilded", ">= 1.0"
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'spec/rake/spectask'
|
22
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
23
|
+
spec.libs << 'lib' << 'spec'
|
24
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
25
|
+
end
|
26
|
+
|
27
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
28
|
+
spec.libs << 'lib' << 'spec'
|
29
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
30
|
+
spec.rcov = true
|
31
|
+
end
|
32
|
+
|
33
|
+
task :spec => :check_dependencies
|
34
|
+
|
35
|
+
task :default => :spec
|
36
|
+
|
37
|
+
begin
|
38
|
+
require 'rcov/rcovtask'
|
39
|
+
Rcov::RcovTask.new do |test|
|
40
|
+
test.libs << 'test'
|
41
|
+
test.pattern = 'test/**/*_test.rb'
|
42
|
+
test.verbose = true
|
43
|
+
end
|
44
|
+
rescue LoadError
|
45
|
+
task :rcov do
|
46
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
task :test => :check_dependencies
|
51
|
+
|
52
|
+
task :default => :test
|
53
|
+
|
54
|
+
require 'rake/rdoctask'
|
55
|
+
Rake::RDocTask.new do |rdoc|
|
56
|
+
if File.exist?('VERSION')
|
57
|
+
version = File.read('VERSION')
|
58
|
+
else
|
59
|
+
version = ""
|
60
|
+
end
|
61
|
+
|
62
|
+
rdoc.rdoc_dir = 'rdoc'
|
63
|
+
rdoc.title = "tester #{version}"
|
64
|
+
rdoc.rdoc_files.include('README*')
|
65
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
66
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.3
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{g_form_submit_protector}
|
8
|
+
s.version = "1.0.3"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["C. Jason Harrelson (midas)"]
|
12
|
+
s.date = %q{2010-06-08}
|
13
|
+
s.description = %q{A Rails Guilded component that will disable form elements once the submit button has been used.}
|
14
|
+
s.email = %q{jason@lookforwardenterprises.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".gitignore",
|
20
|
+
"History.txt",
|
21
|
+
"README.rdoc",
|
22
|
+
"Rakefile",
|
23
|
+
"VERSION",
|
24
|
+
"g_form_submit_protector.gemspec",
|
25
|
+
"lib/g_form_submit_protector.rb",
|
26
|
+
"lib/g_form_submit_protector/view_helpers.rb",
|
27
|
+
"lib/generators/form_submit_protector_assets/form_submit_protector_assets_generator.rb",
|
28
|
+
"lib/generators/form_submit_protector_assets/templates/guilded.form_submit_protector.js",
|
29
|
+
"lib/generators/form_submit_protector_assets/templates/guilded.form_submit_protector.min.js",
|
30
|
+
"lib/generators/form_submit_protector_assets/templates/jquery-disable_on_submit-1.0.js",
|
31
|
+
"lib/generators/form_submit_protector_assets/templates/jquery-disable_on_submit-1.0.min.js",
|
32
|
+
"rails_generators/form_submit_protector_assets/form_submit_protector_assets_generator.rb",
|
33
|
+
"rails_generators/form_submit_protector_assets/templates/guilded.form_submit_protector.js",
|
34
|
+
"rails_generators/form_submit_protector_assets/templates/guilded.form_submit_protector.min.js",
|
35
|
+
"rails_generators/form_submit_protector_assets/templates/jquery-disable_on_submit-1.0.js",
|
36
|
+
"rails_generators/form_submit_protector_assets/templates/jquery-disable_on_submit-1.0.min.js",
|
37
|
+
"script/console",
|
38
|
+
"script/destroy",
|
39
|
+
"script/generate",
|
40
|
+
"spec/g_form_submit_protector_spec.rb",
|
41
|
+
"spec/generators/form_submit_protector_assets_generator_spec.rb",
|
42
|
+
"spec/spec.opts",
|
43
|
+
"spec/spec_helper.rb",
|
44
|
+
"tasks/rspec.rake"
|
45
|
+
]
|
46
|
+
s.homepage = %q{http://github.com/midas/g_form_submit_protector}
|
47
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
48
|
+
s.require_paths = ["lib"]
|
49
|
+
s.rubygems_version = %q{1.3.6}
|
50
|
+
s.summary = %q{A Rails Guilded component that will disable form elements once the submit button has been used.}
|
51
|
+
s.test_files = [
|
52
|
+
"spec/g_form_submit_protector_spec.rb",
|
53
|
+
"spec/generators/form_submit_protector_assets_generator_spec.rb",
|
54
|
+
"spec/spec_helper.rb"
|
55
|
+
]
|
56
|
+
|
57
|
+
if s.respond_to? :specification_version then
|
58
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
59
|
+
s.specification_version = 3
|
60
|
+
|
61
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
62
|
+
s.add_runtime_dependency(%q<rails>, [">= 2.3"])
|
63
|
+
s.add_runtime_dependency(%q<guilded>, [">= 1.0"])
|
64
|
+
else
|
65
|
+
s.add_dependency(%q<rails>, [">= 2.3"])
|
66
|
+
s.add_dependency(%q<guilded>, [">= 1.0"])
|
67
|
+
end
|
68
|
+
else
|
69
|
+
s.add_dependency(%q<rails>, [">= 2.3"])
|
70
|
+
s.add_dependency(%q<guilded>, [">= 1.0"])
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module GFormSubmitProtector
|
2
|
+
module ViewHelpers
|
3
|
+
|
4
|
+
def g_form_submit_protector( *args )
|
5
|
+
return if Guilded::Guilder.instance.include_component?( :form_submit_protector ) # We only need one field highligher per page
|
6
|
+
options = args.extract_options!
|
7
|
+
throw Guilded::Exception::GuildedException.new( ":selector is a required option" ) unless options.has_key?( :selector )
|
8
|
+
options[:selector] = 'form' if options[:selector] == :all
|
9
|
+
options.merge! :id => "form-submit-protector"
|
10
|
+
options.merge! :exclude_css => true
|
11
|
+
Guilded::Guilder.instance.add( :form_submit_protector, options, [ 'jquery/jquery-disable_on_submit-1.0.min.js' ] )
|
12
|
+
''
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
require 'g_form_submit_protector/view_helpers'
|
5
|
+
|
6
|
+
module GFormSubmitProtector
|
7
|
+
VERSION = '1.0.3'
|
8
|
+
end
|
9
|
+
|
10
|
+
if defined?( ActionView::Base )
|
11
|
+
ActionView::Base.send( :include, GFormSubmitProtector::ViewHelpers ) unless ActionView::Base.include?( GFormSubmitProtector::ViewHelpers )
|
12
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
class FormSubmitProtectorAssetsGenerator < Rails::Generators::Base
|
4
|
+
def self.source_root
|
5
|
+
File.join( File.dirname(__FILE__), 'templates' )
|
6
|
+
end
|
7
|
+
|
8
|
+
def install_already_grid_assets
|
9
|
+
copy_file "guilded.form_submit_protector.js", "public/javascripts/guilded.form_submit_protector.js"
|
10
|
+
copy_file "guilded.form_submit_protector.min.js", "public/javascripts/guilded.form_submit_protector.min.js"
|
11
|
+
copy_file "jquery-disable_on_submit-1.0.js", "public/javascripts/jquery/jquery-disable_on_submit-1.0.js"
|
12
|
+
copy_file "jquery-disable_on_submit-1.0.min.js", "public/javascripts/jquery/jquery-disable_on_submit-1.0.min.js"
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
/* Guilded Form Submit Protector 1.0.0
|
2
|
+
* Copyright (c) 2009 C. Jason Harrelson (midas)
|
3
|
+
* Guilded Form Submit Protector is licensed under the terms of the MIT License */
|
4
|
+
|
5
|
+
g.formSubmitProtectorInit = function( options )
|
6
|
+
{
|
7
|
+
if( !options )
|
8
|
+
options = {};
|
9
|
+
|
10
|
+
if( g.beforeFormSubmitProtectorInit )
|
11
|
+
{
|
12
|
+
g.beforeFormSubmitProtectorInit( options );
|
13
|
+
}
|
14
|
+
|
15
|
+
if( g.doFormSubmitProtector )
|
16
|
+
options['should_inactivate'] = g.doFormSubmitProtector;
|
17
|
+
|
18
|
+
$j( options.selector ).disableOnSubmit( options );
|
19
|
+
|
20
|
+
if( g.afterFormSubmitProtectorInit )
|
21
|
+
{
|
22
|
+
g.afterFormSubmitProtectorInit( options );
|
23
|
+
}
|
24
|
+
};
|
data/lib/generators/form_submit_protector_assets/templates/guilded.form_submit_protector.min.js
ADDED
@@ -0,0 +1,4 @@
|
|
1
|
+
/* Guilded Form Submit Protector 1.0.0
|
2
|
+
* Copyright (c) 2009 C. Jason Harrelson (midas)
|
3
|
+
* Guilded Form Submit Protector is licensed under the terms of the MIT License */
|
4
|
+
g.formSubmitProtectorInit=function(options){if(!options)options={};if(g.beforeFormSubmitProtectorInit){g.beforeFormSubmitProtectorInit(options)}if(g.doFormSubmitProtector)options['should_inactivate']=g.doFormSubmitProtector; $jc(options.form_class).disableOnSubmit(options);if(g.afterFormSubmitProtectorInit){g.afterFormSubmitProtectorInit(options)}};
|
@@ -0,0 +1,45 @@
|
|
1
|
+
/*
|
2
|
+
* jQuery Disable On Submit Plugin
|
3
|
+
* http://www.evanbot.com/article/jquery-disable-on-submit-plugin/13
|
4
|
+
*
|
5
|
+
* Copyright (c) 2009 Evan Byrne (http://www.evanbot.com)
|
6
|
+
*/
|
7
|
+
(function($){
|
8
|
+
|
9
|
+
jQuery.fn.disableOnSubmit = function( /* Object literal */ options )
|
10
|
+
{
|
11
|
+
opts = jQuery.extend( jQuery.fn.disableOnSubmit.defaults, options );
|
12
|
+
|
13
|
+
if(opts.disable_list == null)
|
14
|
+
{
|
15
|
+
$list = 'input[type=submit],input[type=button],input[type=reset],button';
|
16
|
+
}
|
17
|
+
else
|
18
|
+
{
|
19
|
+
$list = opts.disable_list;
|
20
|
+
}
|
21
|
+
|
22
|
+
// Makes sure button is enabled at start
|
23
|
+
jQuery(this).find($list).removeAttr('disabled');
|
24
|
+
|
25
|
+
jQuery(this).submit(inactivateForm);
|
26
|
+
return this;
|
27
|
+
};
|
28
|
+
|
29
|
+
/* *************** public *************** */
|
30
|
+
|
31
|
+
jQuery.fn.disableOnSubmit.defaults =
|
32
|
+
{
|
33
|
+
disable_list: 'input[type=submit],input[type=button],input[type=reset],button', /* selector list of elements to disable */
|
34
|
+
should_inactivate: function(){ return true; } /* a callback function that returns true or false deciding if the form should be inactivated */
|
35
|
+
};
|
36
|
+
|
37
|
+
/* *************** private *************** */
|
38
|
+
|
39
|
+
inactivateForm = function( /* jquery Event */ e )
|
40
|
+
{
|
41
|
+
if( opts.should_inactivate() )
|
42
|
+
jQuery(this).find($list).attr('disabled','disabled');
|
43
|
+
};
|
44
|
+
|
45
|
+
})(jQuery);
|
data/lib/generators/form_submit_protector_assets/templates/jquery-disable_on_submit-1.0.min.js
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
/*
|
2
|
+
* jQuery Disable On Submit Plugin
|
3
|
+
* http://www.evanbot.com/article/jquery-disable-on-submit-plugin/13
|
4
|
+
*
|
5
|
+
* Copyright (c) 2009 Evan Byrne (http://www.evanbot.com)
|
6
|
+
*/
|
7
|
+
(function($){jQuery.fn.disableOnSubmit=function(options){opts = jQuery.extend( jQuery.fn.disableOnSubmit.defaults, options );if(opts.disable_list==null){$list='input[type=submit],input[type=button],input[type=reset],button';}else{$list=opts.disable_list;}jQuery(this).find($list).removeAttr('disabled');jQuery(this).submit(inactivateForm);return this;};jQuery.fn.disableOnSubmit.defaults={disable_list:'input[type=submit],input[type=button],input[type=reset],button',should_inactivate:function(){return true;}};inactivateForm=function(e){if(opts.should_inactivate())jQuery(this).find($list).attr('disabled','disabled');};})(jQuery);
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class FormSubmitProtectorAssetsGenerator < Rails::Generator::Base
|
2
|
+
def initialize(runtime_args, runtime_options = {})
|
3
|
+
super
|
4
|
+
end
|
5
|
+
|
6
|
+
def manifest
|
7
|
+
record do |m|
|
8
|
+
m.file "guilded.form_submit_protector.js", "public/javascripts/guilded.form_submit_protector.js"
|
9
|
+
m.file "guilded.form_submit_protector.min.js", "public/javascripts/guilded.form_submit_protector.min.js"
|
10
|
+
m.directory "public/javascripts/jquery"
|
11
|
+
m.file "jquery-disable_on_submit-1.0.js", "public/javascripts/jquery/jquery-disable_on_submit-1.0.js"
|
12
|
+
m.file "jquery-disable_on_submit-1.0.min.js", "public/javascripts/jquery/jquery-disable_on_submit-1.0.min.js"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
/* Guilded Form Submit Protector 1.0.0
|
2
|
+
* Copyright (c) 2009 C. Jason Harrelson (midas)
|
3
|
+
* Guilded Form Submit Protector is licensed under the terms of the MIT License */
|
4
|
+
|
5
|
+
g.formSubmitProtectorInit = function( options )
|
6
|
+
{
|
7
|
+
if( !options )
|
8
|
+
options = {};
|
9
|
+
|
10
|
+
if( g.beforeFormSubmitProtectorInit )
|
11
|
+
{
|
12
|
+
g.beforeFormSubmitProtectorInit( options );
|
13
|
+
}
|
14
|
+
|
15
|
+
if( g.doFormSubmitProtector )
|
16
|
+
options['should_inactivate'] = g.doFormSubmitProtector;
|
17
|
+
|
18
|
+
$j( options.selector ).disableOnSubmit( options );
|
19
|
+
|
20
|
+
if( g.afterFormSubmitProtectorInit )
|
21
|
+
{
|
22
|
+
g.afterFormSubmitProtectorInit( options );
|
23
|
+
}
|
24
|
+
};
|
data/rails_generators/form_submit_protector_assets/templates/guilded.form_submit_protector.min.js
ADDED
@@ -0,0 +1,4 @@
|
|
1
|
+
/* Guilded Form Submit Protector 1.0.0
|
2
|
+
* Copyright (c) 2009 C. Jason Harrelson (midas)
|
3
|
+
* Guilded Form Submit Protector is licensed under the terms of the MIT License */
|
4
|
+
g.formSubmitProtectorInit=function(options){if(!options)options={};if(g.beforeFormSubmitProtectorInit){g.beforeFormSubmitProtectorInit(options)}if(g.doFormSubmitProtector)options['should_inactivate']=g.doFormSubmitProtector; $jc(options.form_class).disableOnSubmit(options);if(g.afterFormSubmitProtectorInit){g.afterFormSubmitProtectorInit(options)}};
|
@@ -0,0 +1,45 @@
|
|
1
|
+
/*
|
2
|
+
* jQuery Disable On Submit Plugin
|
3
|
+
* http://www.evanbot.com/article/jquery-disable-on-submit-plugin/13
|
4
|
+
*
|
5
|
+
* Copyright (c) 2009 Evan Byrne (http://www.evanbot.com)
|
6
|
+
*/
|
7
|
+
(function($){
|
8
|
+
|
9
|
+
jQuery.fn.disableOnSubmit = function( /* Object literal */ options )
|
10
|
+
{
|
11
|
+
opts = jQuery.extend( jQuery.fn.disableOnSubmit.defaults, options );
|
12
|
+
|
13
|
+
if(opts.disable_list == null)
|
14
|
+
{
|
15
|
+
$list = 'input[type=submit],input[type=button],input[type=reset],button';
|
16
|
+
}
|
17
|
+
else
|
18
|
+
{
|
19
|
+
$list = opts.disable_list;
|
20
|
+
}
|
21
|
+
|
22
|
+
// Makes sure button is enabled at start
|
23
|
+
jQuery(this).find($list).removeAttr('disabled');
|
24
|
+
|
25
|
+
jQuery(this).submit(inactivateForm);
|
26
|
+
return this;
|
27
|
+
};
|
28
|
+
|
29
|
+
/* *************** public *************** */
|
30
|
+
|
31
|
+
jQuery.fn.disableOnSubmit.defaults =
|
32
|
+
{
|
33
|
+
disable_list: 'input[type=submit],input[type=button],input[type=reset],button', /* selector list of elements to disable */
|
34
|
+
should_inactivate: function(){ return true; } /* a callback function that returns true or false deciding if the form should be inactivated */
|
35
|
+
};
|
36
|
+
|
37
|
+
/* *************** private *************** */
|
38
|
+
|
39
|
+
inactivateForm = function( /* jquery Event */ e )
|
40
|
+
{
|
41
|
+
if( opts.should_inactivate() )
|
42
|
+
jQuery(this).find($list).attr('disabled','disabled');
|
43
|
+
};
|
44
|
+
|
45
|
+
})(jQuery);
|
data/rails_generators/form_submit_protector_assets/templates/jquery-disable_on_submit-1.0.min.js
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
/*
|
2
|
+
* jQuery Disable On Submit Plugin
|
3
|
+
* http://www.evanbot.com/article/jquery-disable-on-submit-plugin/13
|
4
|
+
*
|
5
|
+
* Copyright (c) 2009 Evan Byrne (http://www.evanbot.com)
|
6
|
+
*/
|
7
|
+
(function($){jQuery.fn.disableOnSubmit=function(options){opts = jQuery.extend( jQuery.fn.disableOnSubmit.defaults, options );if(opts.disable_list==null){$list='input[type=submit],input[type=button],input[type=reset],button';}else{$list=opts.disable_list;}jQuery(this).find($list).removeAttr('disabled');jQuery(this).submit(inactivateForm);return this;};jQuery.fn.disableOnSubmit.defaults={disable_list:'input[type=submit],input[type=button],input[type=reset],button',should_inactivate:function(){return true;}};inactivateForm=function(e){if(opts.should_inactivate())jQuery(this).find($list).attr('disabled','disabled');};})(jQuery);
|
data/script/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# File: script/console
|
3
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
+
|
5
|
+
libs = " -r irb/completion"
|
6
|
+
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
+
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/g_form_submit_protector.rb'}"
|
9
|
+
puts "Loading g_form_submit_protector gem"
|
10
|
+
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'generators/form_submit_protector_assets/form_submit_protector_assets_generator'
|
3
|
+
|
4
|
+
describe FormSubmitProtectorAssetsGenerator do
|
5
|
+
before :each do
|
6
|
+
@destination = File.join 'tmp', 'test_app'
|
7
|
+
@source = FormSubmitProtectorAssetsGenerator.source_root
|
8
|
+
FormSubmitProtectorAssetsGenerator.start '', :destination_root => @destination
|
9
|
+
end
|
10
|
+
|
11
|
+
after :each do
|
12
|
+
FileUtils.rm_rf @destination
|
13
|
+
end
|
14
|
+
|
15
|
+
{"guilded.form_submit_protector.js" => "public/javascripts/guilded.form_submit_protector.js",
|
16
|
+
"guilded.form_submit_protector.min.js" => "public/javascripts/guilded.form_submit_protector.min.js",
|
17
|
+
"jquery-disable_on_submit-1.0.js" => "public/javascripts/jquery/jquery-disable_on_submit-1.0.js",
|
18
|
+
"jquery-disable_on_submit-1.0.min.js" => "public/javascripts/jquery/jquery-disable_on_submit-1.0.min.js"}.each do |file, path|
|
19
|
+
|
20
|
+
it "should copy '#{file}' to '#{path}'" do
|
21
|
+
File.exists?( File.join( @destination, path ) ).should be_true
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should agree that the contents of '#{file}' are identical to '#{path}'" do
|
25
|
+
File.read( File.join( @source, file ) ).should eql File.read( File.join( @destination, path ) )
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/spec/spec_helper.rb
ADDED
data/tasks/rspec.rake
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
begin
|
2
|
+
require 'spec'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems'
|
5
|
+
require 'spec'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'spec/rake/spectask'
|
9
|
+
rescue LoadError
|
10
|
+
puts <<-EOS
|
11
|
+
To use rspec for testing you must install rspec gem:
|
12
|
+
gem install rspec
|
13
|
+
EOS
|
14
|
+
exit(0)
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Run the specs under spec/models"
|
18
|
+
Spec::Rake::SpecTask.new do |t|
|
19
|
+
t.spec_opts = ['--options', "spec/spec.opts"]
|
20
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: g_form_submit_protector
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 0
|
8
|
+
- 3
|
9
|
+
version: 1.0.3
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- C. Jason Harrelson (midas)
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-06-08 00:00:00 -05:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rails
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 2
|
29
|
+
- 3
|
30
|
+
version: "2.3"
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: guilded
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
segments:
|
41
|
+
- 1
|
42
|
+
- 0
|
43
|
+
version: "1.0"
|
44
|
+
type: :runtime
|
45
|
+
version_requirements: *id002
|
46
|
+
description: A Rails Guilded component that will disable form elements once the submit button has been used.
|
47
|
+
email: jason@lookforwardenterprises.com
|
48
|
+
executables: []
|
49
|
+
|
50
|
+
extensions: []
|
51
|
+
|
52
|
+
extra_rdoc_files:
|
53
|
+
- README.rdoc
|
54
|
+
files:
|
55
|
+
- .gitignore
|
56
|
+
- History.txt
|
57
|
+
- README.rdoc
|
58
|
+
- Rakefile
|
59
|
+
- VERSION
|
60
|
+
- g_form_submit_protector.gemspec
|
61
|
+
- lib/g_form_submit_protector.rb
|
62
|
+
- lib/g_form_submit_protector/view_helpers.rb
|
63
|
+
- lib/generators/form_submit_protector_assets/form_submit_protector_assets_generator.rb
|
64
|
+
- lib/generators/form_submit_protector_assets/templates/guilded.form_submit_protector.js
|
65
|
+
- lib/generators/form_submit_protector_assets/templates/guilded.form_submit_protector.min.js
|
66
|
+
- lib/generators/form_submit_protector_assets/templates/jquery-disable_on_submit-1.0.js
|
67
|
+
- lib/generators/form_submit_protector_assets/templates/jquery-disable_on_submit-1.0.min.js
|
68
|
+
- rails_generators/form_submit_protector_assets/form_submit_protector_assets_generator.rb
|
69
|
+
- rails_generators/form_submit_protector_assets/templates/guilded.form_submit_protector.js
|
70
|
+
- rails_generators/form_submit_protector_assets/templates/guilded.form_submit_protector.min.js
|
71
|
+
- rails_generators/form_submit_protector_assets/templates/jquery-disable_on_submit-1.0.js
|
72
|
+
- rails_generators/form_submit_protector_assets/templates/jquery-disable_on_submit-1.0.min.js
|
73
|
+
- script/console
|
74
|
+
- script/destroy
|
75
|
+
- script/generate
|
76
|
+
- spec/g_form_submit_protector_spec.rb
|
77
|
+
- spec/generators/form_submit_protector_assets_generator_spec.rb
|
78
|
+
- spec/spec.opts
|
79
|
+
- spec/spec_helper.rb
|
80
|
+
- tasks/rspec.rake
|
81
|
+
has_rdoc: true
|
82
|
+
homepage: http://github.com/midas/g_form_submit_protector
|
83
|
+
licenses: []
|
84
|
+
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options:
|
87
|
+
- --charset=UTF-8
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
version: "0"
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
segments:
|
102
|
+
- 0
|
103
|
+
version: "0"
|
104
|
+
requirements: []
|
105
|
+
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 1.3.6
|
108
|
+
signing_key:
|
109
|
+
specification_version: 3
|
110
|
+
summary: A Rails Guilded component that will disable form elements once the submit button has been used.
|
111
|
+
test_files:
|
112
|
+
- spec/g_form_submit_protector_spec.rb
|
113
|
+
- spec/generators/form_submit_protector_assets_generator_spec.rb
|
114
|
+
- spec/spec_helper.rb
|