keymaster-rails 1.0.2

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.
@@ -0,0 +1,17 @@
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
@@ -0,0 +1 @@
1
+ 1.9.3@keymaster-rails
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in keymaster-rails.gemspec
4
+ gemspec
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+ Copyright © 2012 Phil Cohen <github@phlippers.net>
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,87 @@
1
+ # keymaster-rails
2
+
3
+ [Keymaster](https://github.com/madrobby/keymaster), bundled for Rails 3.0 and up.
4
+
5
+
6
+ ## Rails 3.1+
7
+
8
+ For Rails 3.1 and greater, the files will be added to the asset pipeline and available for you to use.
9
+
10
+ To enable:
11
+
12
+ * Add the following line to the file `app/assets/javascripts/application.js` (or other [sprockets](https://github.com/sstephenson/sprockets) manifest):
13
+
14
+ ``` javascript
15
+ //= require keymaster
16
+ ```
17
+
18
+
19
+ ### Installation
20
+
21
+ * Add `keymaster-rails` to your Gemfile
22
+ * Run `bundle`
23
+
24
+ Enjoy!
25
+
26
+
27
+ ## Rails 3.0
28
+
29
+ This gem adds a single generator to Rails 3, `keymaster:install`. Running the generator will install the JavaScript file necessary to use Keymaster.
30
+
31
+ ### Installation
32
+
33
+ * Add `keymaster-rails` to your Gemfile
34
+ * Run `bundle`
35
+ * Invoke the generator: `rails generate keymaster:install`
36
+ * Add the following to your layout or view files:
37
+
38
+ ```erb
39
+ <%= javascript_include_tag "keymaster" %>
40
+ ```
41
+
42
+ You're done!
43
+
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create new Pull Request
52
+
53
+
54
+ ## License
55
+
56
+ **keymaster-rails**
57
+
58
+ * Freely distributable and licensed under the [MIT license](http://phlipper.mit-license.org/2012/license.html).
59
+ * Copyright (c) 2012 Phil Cohen (github@phlippers.net) [![endorse](http://api.coderwall.com/phlipper/endorsecount.png)](http://coderwall.com/phlipper)
60
+ * http://phlippers.net/
61
+
62
+ **Keymaster JS**
63
+
64
+ * Freely distributable and licensed under the MIT-style license.
65
+ * Copyright (c) 2011 Thomas Fuchs
66
+ * https://github.com/madrobby/keymaster
67
+
68
+ Copyright (c) 2011 Thomas Fuchs
69
+
70
+ Permission is hereby granted, free of charge, to any person obtaining
71
+ a copy of this software and associated documentation files (the
72
+ "Software"), to deal in the Software without restriction, including
73
+ without limitation the rights to use, copy, modify, merge, publish,
74
+ distribute, sublicense, and/or sell copies of the Software, and to
75
+ permit persons to whom the Software is furnished to do so, subject to
76
+ the following conditions:
77
+
78
+ The above copyright notice and this permission notice shall be
79
+ included in all copies or substantial portions of the Software.
80
+
81
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
82
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
83
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
84
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
85
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
86
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
87
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/keymaster/rails/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Phil Cohen"]
6
+ gem.email = ["github@phlippers.net"]
7
+ gem.description = %q{Keymaster.js, bundled for Rails 3.0 and up.}
8
+ gem.summary = %q{Keymaster.js, bundled for Rails 3.0 and up.}
9
+ gem.homepage = "https://github.com/phlipper/keymaster-rails"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "keymaster-rails"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Keymaster::Rails::VERSION
17
+
18
+ gem.add_dependency "railties", ">= 3.0.0"
19
+ gem.add_development_dependency "bundler", ">= 1.1.0"
20
+ gem.add_development_dependency "rake", "~> 0.9.2.2"
21
+ end
@@ -0,0 +1,35 @@
1
+ require "rails"
2
+
3
+ # Supply generator for Rails 3.0.x or if asset pipeline is not enabled
4
+ if ::Rails.version < "3.1" || !::Rails.application.config.assets.enabled
5
+ module Keymaster
6
+ module Generators
7
+ class InstallGenerator < ::Rails::Generators::Base
8
+ desc "This generator installs keymaster #{Keymaster::Rails::KEYMASTERJS_VERSION}"
9
+ source_root File.expand_path("../../../../../vendor/assets", __FILE__)
10
+
11
+ def copy_javascript
12
+ say_status("copying", "Keymaster JS", :green)
13
+ copy_file "javascripts/keymaster.js", "public/javascripts/keymaster.js"
14
+ end
15
+ end
16
+ end
17
+ end
18
+ else
19
+ module Keymaster
20
+ module Generators
21
+ class InstallGenerator < ::Rails::Generators::Base
22
+ desc "Just show instructions so people will know what to do when mistakenly using generator for Rails 3.1 apps"
23
+
24
+ def do_nothing
25
+ say_status("deprecated", "You are using Rails 3.1 with the asset pipeline enabled, so this generator is not needed.")
26
+ say_status("", "The necessary files are already in your asset pipeline.")
27
+ say_status("", "Just add `//= require keymaster` to your app/assets/javascripts/application.js")
28
+ say_status("", "If you upgraded your app from Rails 3.0 and still have keymaster.js in your public assets folders, be sure to remove them.")
29
+ say_status("", "If you do not want the asset pipeline enabled, you may turn it off in application.rb and re-run this generator.")
30
+ # ok, nothing
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1 @@
1
+ require "keymaster/rails"
@@ -0,0 +1,6 @@
1
+ module Keymaster
2
+ module Rails
3
+ require "keymaster/rails/engine"
4
+ require "keymaster/rails/version"
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ # Configure Rails 3.1 to have assets in the load path
2
+ module Keymaster
3
+ module Rails
4
+ class Engine < ::Rails::Engine
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ module Keymaster
2
+ module Rails
3
+ VERSION = "1.0.2"
4
+ KEYMASTERJS_VERSION = "1.0.2"
5
+ end
6
+ end
@@ -0,0 +1,184 @@
1
+ // keymaster.js
2
+ // (c) 2011 Thomas Fuchs
3
+ // keymaster.js may be freely distributed under the MIT license.
4
+
5
+ ;(function(global){
6
+ var k,
7
+ _handlers = {},
8
+ _mods = { 16: false, 18: false, 17: false, 91: false },
9
+ _scope = 'all',
10
+ // modifier keys
11
+ _MODIFIERS = {
12
+ '⇧': 16, shift: 16,
13
+ '⌥': 18, alt: 18, option: 18,
14
+ '⌃': 17, ctrl: 17, control: 17,
15
+ '⌘': 91, command: 91
16
+ },
17
+ // special keys
18
+ _MAP = {
19
+ backspace: 8, tab: 9, clear: 12,
20
+ enter: 13, 'return': 13,
21
+ esc: 27, escape: 27, space: 32,
22
+ left: 37, up: 38,
23
+ right: 39, down: 40,
24
+ del: 46, 'delete': 46,
25
+ home: 36, end: 35,
26
+ pageup: 33, pagedown: 34,
27
+ ',': 188, '.': 190, '/': 191,
28
+ '`': 192, '-': 189, '=': 187,
29
+ ';': 186, '\'': 222,
30
+ '[': 219, ']': 221, '\\': 220
31
+ };
32
+
33
+ for(k=1;k<20;k++) _MODIFIERS['f'+k] = 111+k;
34
+
35
+ // IE doesn't support Array#indexOf, so have a simple replacement
36
+ function index(array, item){
37
+ var i = array.length;
38
+ while(i--) if(array[i]===item) return i;
39
+ return -1;
40
+ }
41
+
42
+ // handle keydown event
43
+ function dispatch(event){
44
+ var key, handler, k, i, modifiersMatch;
45
+ key = event.keyCode;
46
+
47
+ // if a modifier key, set the key.<modifierkeyname> property to true and return
48
+ if(key == 93 || key == 224) key = 91; // right command on webkit, command on Gecko
49
+ if(key in _mods) {
50
+ _mods[key] = true;
51
+ // 'assignKey' from inside this closure is exported to window.key
52
+ for(k in _MODIFIERS) if(_MODIFIERS[k] == key) assignKey[k] = true;
53
+ return;
54
+ }
55
+
56
+ // see if we need to ignore the keypress (ftiler() can can be overridden)
57
+ // by default ignore key presses if a select, textarea, or input is focused
58
+ if(!assignKey.filter.call(this, event)) return;
59
+
60
+ // abort if no potentially matching shortcuts found
61
+ if (!(key in _handlers)) return;
62
+
63
+ // for each potential shortcut
64
+ for (i = 0; i < _handlers[key].length; i++) {
65
+ handler = _handlers[key][i];
66
+
67
+ // see if it's in the current scope
68
+ if(handler.scope == _scope || handler.scope == 'all'){
69
+ // check if modifiers match if any
70
+ modifiersMatch = handler.mods.length > 0;
71
+ for(k in _mods)
72
+ if((!_mods[k] && index(handler.mods, +k) > -1) ||
73
+ (_mods[k] && index(handler.mods, +k) == -1)) modifiersMatch = false;
74
+ // call the handler and stop the event if neccessary
75
+ if((handler.mods.length == 0 && !_mods[16] && !_mods[18] && !_mods[17] && !_mods[91]) || modifiersMatch){
76
+ if(handler.method(event, handler)===false){
77
+ if(event.preventDefault) event.preventDefault();
78
+ else event.returnValue = false;
79
+ if(event.stopPropagation) event.stopPropagation();
80
+ if(event.cancelBubble) event.cancelBubble = true;
81
+ }
82
+ }
83
+ }
84
+ }
85
+ };
86
+
87
+ // unset modifier keys on keyup
88
+ function clearModifier(event){
89
+ var key = event.keyCode, k;
90
+ if(key == 93 || key == 224) key = 91;
91
+ if(key in _mods) {
92
+ _mods[key] = false;
93
+ for(k in _MODIFIERS) if(_MODIFIERS[k] == key) assignKey[k] = false;
94
+ }
95
+ };
96
+
97
+ function resetModifiers() {
98
+ for(k in _mods) _mods[k] = false;
99
+ for(k in _MODIFIERS) assignKey[k] = false;
100
+ }
101
+
102
+ // parse and assign shortcut
103
+ function assignKey(key, scope, method){
104
+ var keys, mods, i, mi;
105
+ if (method === undefined) {
106
+ method = scope;
107
+ scope = 'all';
108
+ }
109
+ key = key.replace(/\s/g,'');
110
+ keys = key.split(',');
111
+
112
+ if((keys[keys.length-1])=='')
113
+ keys[keys.length-2] += ',';
114
+ // for each shortcut
115
+ for (i = 0; i < keys.length; i++) {
116
+ // set modifier keys if any
117
+ mods = [];
118
+ key = keys[i].split('+');
119
+ if(key.length > 1){
120
+ mods = key.slice(0,key.length-1);
121
+ for (mi = 0; mi < mods.length; mi++)
122
+ mods[mi] = _MODIFIERS[mods[mi]];
123
+ key = [key[key.length-1]];
124
+ }
125
+ // convert to keycode and...
126
+ key = key[0]
127
+ key = _MAP[key] || key.toUpperCase().charCodeAt(0);
128
+ // ...store handler
129
+ if (!(key in _handlers)) _handlers[key] = [];
130
+ _handlers[key].push({ shortcut: keys[i], scope: scope, method: method, key: keys[i], mods: mods });
131
+ }
132
+ };
133
+
134
+ function filter(event){
135
+ var tagName = (event.target || event.srcElement).tagName;
136
+ // ignore keypressed in any elements that support keyboard data input
137
+ return !(tagName == 'INPUT' || tagName == 'SELECT' || tagName == 'TEXTAREA');
138
+ }
139
+
140
+ // initialize key.<modifier> to false
141
+ for(k in _MODIFIERS) assignKey[k] = false;
142
+
143
+ // set current scope (default 'all')
144
+ function setScope(scope){ _scope = scope || 'all' };
145
+ function getScope(){ return _scope || 'all' };
146
+
147
+ // delete all handlers for a given scope
148
+ function deleteScope(scope){
149
+ var key, handlers, i;
150
+
151
+ for (key in _handlers) {
152
+ handlers = _handlers[key];
153
+ for (i = 0; i < handlers.length; ) {
154
+ if (handlers[i].scope === scope) handlers.splice(i, 1);
155
+ else i++;
156
+ }
157
+ }
158
+ };
159
+
160
+ // cross-browser events
161
+ function addEvent(object, event, method) {
162
+ if (object.addEventListener)
163
+ object.addEventListener(event, method, false);
164
+ else if(object.attachEvent)
165
+ object.attachEvent('on'+event, function(){ method(window.event) });
166
+ };
167
+
168
+ // set the handlers globally on document
169
+ addEvent(document, 'keydown', dispatch);
170
+ addEvent(document, 'keyup', clearModifier);
171
+
172
+ // reset modifiers to false whenever the window is (re)focused.
173
+ addEvent(window, 'focus', resetModifiers);
174
+
175
+ // set window.key and window.key.set/get/deleteScope, and the default filter
176
+ global.key = assignKey;
177
+ global.key.setScope = setScope;
178
+ global.key.getScope = getScope;
179
+ global.key.deleteScope = deleteScope;
180
+ global.key.filter = filter;
181
+
182
+ if(typeof module !== 'undefined') module.exports = key;
183
+
184
+ })(this);
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: keymaster-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Phil Cohen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: railties
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.0.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 1.1.0
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.1.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.9.2.2
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.2.2
62
+ description: Keymaster.js, bundled for Rails 3.0 and up.
63
+ email:
64
+ - github@phlippers.net
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - .ruby-version
71
+ - Gemfile
72
+ - LICENSE.txt
73
+ - README.md
74
+ - Rakefile
75
+ - keymaster-rails.gemspec
76
+ - lib/generators/keymaster/install/install_generator.rb
77
+ - lib/keymaster-rails.rb
78
+ - lib/keymaster/rails.rb
79
+ - lib/keymaster/rails/engine.rb
80
+ - lib/keymaster/rails/version.rb
81
+ - vendor/assets/javascripts/keymaster.js
82
+ homepage: https://github.com/phlipper/keymaster-rails
83
+ licenses: []
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ segments:
95
+ - 0
96
+ hash: 1931070553266355197
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ segments:
104
+ - 0
105
+ hash: 1931070553266355197
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 1.8.24
109
+ signing_key:
110
+ specification_version: 3
111
+ summary: Keymaster.js, bundled for Rails 3.0 and up.
112
+ test_files: []