onestep 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,21 @@
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
18
+
19
+ # Vim Files
20
+ *.swp
21
+ *.swo
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in onestep.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 David Tuite
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.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # Onestep
2
+
3
+ Prevent users sending duplicate requests by rapidly clicking links and buttons.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'onestep'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install onestep
18
+
19
+ Once you've installed the gem, require it's JavaScript assets:
20
+
21
+ // app/assets/javascripts/application.js
22
+ //= require onestep/onestep
23
+
24
+ ## Usage
25
+
26
+ TODO: Write usage instructions here
27
+
28
+ ## TODO:
29
+
30
+ 1. Write a Heroku hosted Sinatra application which demos the functionality.
31
+ 2. Link to the application from this Readme.
32
+ 3. Make sure that the gem works with <button> tags.
33
+ 4. Consider initializing the jQuery so that it works automatically. Then add
34
+ a class the users can attach to optout.
35
+ 5. Specify that the assets must be required after jQuery. I might be able to
36
+ add jquery_ujs as a dependancy?
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,4 @@
1
+ module Onestep
2
+ class Engine < Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module Onestep
2
+ VERSION = "0.0.1"
3
+ end
data/lib/onestep.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "onestep/version"
2
+ require "onestep/engine"
3
+
4
+ module Onestep
5
+ # Your code goes here...
6
+ end
data/onestep.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'onestep/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "onestep"
8
+ gem.version = Onestep::VERSION
9
+ gem.authors = ["David Tuite"]
10
+ gem.email = ["dtuite@gmail.com"]
11
+ gem.description = %q{Prevent users sending duplicate requests by rapidly clicking links and buttons.}
12
+ gem.summary = %q{Onestep is a drop in JS modification which prevents users from submitting forms with idential information multiple times. Onestep disables the submission button until the first request has returned before re-enabling the submit button. THe same behavior is also applied to remote buttons and links.}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
@@ -0,0 +1,55 @@
1
+ (function(exports) {
2
+ var disabler = {
3
+ // Disable an <a/> tag.
4
+ disableLink: function(e) {
5
+ return this.each(function() {
6
+ return $(this).addClass('disabled').on('click', false);
7
+ });
8
+ },
9
+ // Disable a <form/> tag to prevent submission.
10
+ disableForm: function(e) {
11
+ return this.each(function() {
12
+ return $(this).find('input[type="submit"]').attr('disabled', 'disabled').addClass('disabled');
13
+ });
14
+ },
15
+ // Re-enable an <a/> tag.
16
+ enableLink: function() {
17
+ return this.each(function() {
18
+ return $(this).removeClass('disabled').off('click', false);
19
+ });
20
+ },
21
+ // Re-enable a <form/> tag.
22
+ enableForm: function(e, xhr, textStatus) {
23
+ return this.each(function() {
24
+ return $(this).find('input[type="submit"]').removeAttr('disabled').removeClass('disabled');
25
+ });
26
+ }
27
+ };
28
+
29
+ jQuery.fn.onestep = function() {
30
+ return this.each(function() {
31
+ var $this,
32
+ _this = this;
33
+ $this = $(this);
34
+ if ($this.is('a')) {
35
+ $this.on('ajax:complete', function() {
36
+ return disabler.enableLink.apply($this);
37
+ });
38
+ if ($this.hasClass('disabled')) {
39
+ return disabler.disableLink.apply($this);
40
+ } else {
41
+ return $this.on('ajax:beforeSend', function() {
42
+ return disabler.disableLink.apply($this);
43
+ });
44
+ }
45
+ } else if ($this.is('form')) {
46
+ $this.on('ajax:complete', function() {
47
+ return disabler.enableForm.apply($this);
48
+ });
49
+ return $this.submit(function() {
50
+ return disabler.disableForm.apply($this);
51
+ });
52
+ }
53
+ });
54
+ };
55
+ })(window);
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: onestep
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - David Tuite
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-16 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Prevent users sending duplicate requests by rapidly clicking links and
15
+ buttons.
16
+ email:
17
+ - dtuite@gmail.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - Gemfile
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - lib/onestep.rb
28
+ - lib/onestep/engine.rb
29
+ - lib/onestep/version.rb
30
+ - onestep.gemspec
31
+ - vendor/assets/javascripts/onestep/onestep.js
32
+ homepage: ''
33
+ licenses: []
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubyforge_project:
52
+ rubygems_version: 1.8.25
53
+ signing_key:
54
+ specification_version: 3
55
+ summary: Onestep is a drop in JS modification which prevents users from submitting
56
+ forms with idential information multiple times. Onestep disables the submission
57
+ button until the first request has returned before re-enabling the submit button.
58
+ THe same behavior is also applied to remote buttons and links.
59
+ test_files: []