onload_js-rails 1.1.0 → 1.2.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.
- data/.gitignore +8 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +14 -0
- data/LICENSE +20 -0
- data/README.markdown +97 -0
- data/Rakefile +42 -0
- data/app/assets/javascripts/onload.js +72 -0
- data/app/helpers/onload_helper.rb +10 -0
- data/coffee/onload.js.coffee +35 -0
- data/lib/onload_js-rails.rb +13 -0
- data/lib/onload_js.rb +2 -0
- data/lib/onload_js/engine.rb +8 -0
- data/lib/onload_js/version.rb +5 -0
- data/onload_js-rails.gemspec +19 -0
- data/test_application/.powder +1 -0
- data/test_application/Gemfile +12 -0
- data/test_application/Gemfile.lock +115 -0
- data/test_application/README.rdoc +261 -0
- data/test_application/Rakefile +7 -0
- data/test_application/app/assets/images/rails.png +0 -0
- data/test_application/app/assets/javascripts/application.js +16 -0
- data/test_application/app/assets/javascripts/users.js.coffee +20 -0
- data/test_application/app/assets/stylesheets/application.css +13 -0
- data/test_application/app/assets/stylesheets/users.css.scss +3 -0
- data/test_application/app/controllers/application_controller.rb +3 -0
- data/test_application/app/controllers/users_controller.rb +10 -0
- data/test_application/app/helpers/application_helper.rb +2 -0
- data/test_application/app/helpers/users_helper.rb +2 -0
- data/test_application/app/views/layouts/application.html.erb +15 -0
- data/test_application/app/views/users/edit.html.erb +2 -0
- data/test_application/app/views/users/index.html.erb +1 -0
- data/test_application/app/views/users/new.html.erb +2 -0
- data/test_application/config.ru +4 -0
- data/test_application/config/application.rb +68 -0
- data/test_application/config/boot.rb +6 -0
- data/test_application/config/environment.rb +5 -0
- data/test_application/config/environments/development.rb +31 -0
- data/test_application/config/environments/production.rb +64 -0
- data/test_application/config/environments/test.rb +35 -0
- data/test_application/config/initializers/backtrace_silencers.rb +7 -0
- data/test_application/config/initializers/inflections.rb +15 -0
- data/test_application/config/initializers/mime_types.rb +5 -0
- data/test_application/config/initializers/secret_token.rb +7 -0
- data/test_application/config/initializers/session_store.rb +8 -0
- data/test_application/config/initializers/wrap_parameters.rb +10 -0
- data/test_application/config/locales/en.yml +5 -0
- data/test_application/config/routes.rb +6 -0
- data/test_application/db/seeds.rb +7 -0
- data/test_application/doc/README_FOR_APP +2 -0
- data/test_application/public/404.html +26 -0
- data/test_application/public/422.html +26 -0
- data/test_application/public/500.html +25 -0
- data/test_application/public/favicon.ico +0 -0
- data/test_application/public/robots.txt +5 -0
- data/test_application/script/rails +6 -0
- metadata +59 -4
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2012 Alex McHale (alex@anticlever.com)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
OnLoad JavaScript for Rails
|
2
|
+
===========================
|
3
|
+
|
4
|
+
This Rails 3.1+ add-on lets you easily run a JavaScript function based on what
|
5
|
+
controller and action is being loaded.
|
6
|
+
|
7
|
+
Requirements
|
8
|
+
------------
|
9
|
+
|
10
|
+
* Rails 3 Project
|
11
|
+
* jQuery 1.8+
|
12
|
+
|
13
|
+
Installation
|
14
|
+
------------
|
15
|
+
|
16
|
+
Add the following to your Gemfile and run *bundle*.
|
17
|
+
|
18
|
+
gem 'onload_js-rails'
|
19
|
+
|
20
|
+
Use the *onload_tag* helper at the bottom of your body, below your *javascript_include_tag*.
|
21
|
+
|
22
|
+
<%= onload_tag %>
|
23
|
+
|
24
|
+
In your application.js headers, add the onload js below jquery but above your custom javascript files.
|
25
|
+
|
26
|
+
//= require onload
|
27
|
+
|
28
|
+
Finally, use the *runOnLoad* method in your JavaScript or Coffee-Script as described below.
|
29
|
+
|
30
|
+
Examples
|
31
|
+
--------
|
32
|
+
|
33
|
+
Let's say you want to bind a function to run only on the Users controller on
|
34
|
+
the new or edit actions.
|
35
|
+
|
36
|
+
runOnLoad("Users", ["new", "edit"], function () {
|
37
|
+
...
|
38
|
+
});
|
39
|
+
|
40
|
+
On only on Users#new.
|
41
|
+
|
42
|
+
runOnLoad("Users", "new", function () {
|
43
|
+
...
|
44
|
+
});
|
45
|
+
|
46
|
+
On any controller on the index action.
|
47
|
+
|
48
|
+
runOnLoad("*", "index", function () {
|
49
|
+
...
|
50
|
+
});
|
51
|
+
|
52
|
+
On any action on the Users controller.
|
53
|
+
|
54
|
+
runOnLoad("Users", "*", function () {
|
55
|
+
...
|
56
|
+
});
|
57
|
+
|
58
|
+
On either the Users or UserSessions controllers, on the new or edit actions.
|
59
|
+
|
60
|
+
runOnLoad(["Users", "UserSessions"], ["new", "edit"], function () {
|
61
|
+
...
|
62
|
+
});
|
63
|
+
|
64
|
+
Maintainer
|
65
|
+
----------
|
66
|
+
|
67
|
+
* [Alex McHale](http://github.com/alexmchale)
|
68
|
+
|
69
|
+
Contributing
|
70
|
+
------------
|
71
|
+
|
72
|
+
* If you'd like to contribute to this project, please fork it on GitHub and
|
73
|
+
send me a pull request.
|
74
|
+
|
75
|
+
License
|
76
|
+
-------
|
77
|
+
|
78
|
+
Copyright 2012 Alex McHale (alex@anticlever.com)
|
79
|
+
|
80
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
81
|
+
a copy of this software and associated documentation files (the
|
82
|
+
"Software"), to deal in the Software without restriction, including
|
83
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
84
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
85
|
+
permit persons to whom the Software is furnished to do so, subject to
|
86
|
+
the following conditions:
|
87
|
+
|
88
|
+
The above copyright notice and this permission notice shall be
|
89
|
+
included in all copies or substantial portions of the Software.
|
90
|
+
|
91
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
92
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
93
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
94
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
95
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
96
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
97
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rubygems'
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rake'
|
10
|
+
require 'rdoc/task'
|
11
|
+
|
12
|
+
require 'rake/testtask'
|
13
|
+
|
14
|
+
Rake::TestTask.new(:test) do |t|
|
15
|
+
t.libs << 'lib'
|
16
|
+
t.libs << 'test'
|
17
|
+
t.pattern = 'test/**/*_test.rb'
|
18
|
+
t.verbose = false
|
19
|
+
end
|
20
|
+
|
21
|
+
task :default => :test
|
22
|
+
|
23
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
24
|
+
rdoc.rdoc_dir = 'rdoc'
|
25
|
+
rdoc.title = 'OnloadJs'
|
26
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
27
|
+
rdoc.rdoc_files.include('README.rdoc')
|
28
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
29
|
+
end
|
30
|
+
|
31
|
+
task :default do
|
32
|
+
sh "/usr/local/bin/coffee -c -s < coffee/onload.js.coffee > app/assets/javascripts/onload.js"
|
33
|
+
sh "gem build onload_js-rails.gemspec"
|
34
|
+
sh "mkdir -p pkg"
|
35
|
+
cd "pkg"
|
36
|
+
sh "rm -f *"
|
37
|
+
sh "mv ../*.gem ."
|
38
|
+
end
|
39
|
+
|
40
|
+
task :push => :default do
|
41
|
+
sh "gem push *.gem"
|
42
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
(function() {
|
2
|
+
var callAction, callController, makeOnLoadArray, onloadCallbacks;
|
3
|
+
onloadCallbacks = {};
|
4
|
+
makeOnLoadArray = function(items) {
|
5
|
+
if (jQuery.isArray(items)) {
|
6
|
+
return items;
|
7
|
+
}
|
8
|
+
if (jQuery.type(items) === "string") {
|
9
|
+
return [items];
|
10
|
+
}
|
11
|
+
return ["*"];
|
12
|
+
};
|
13
|
+
callAction = function(controllerName, actionName) {
|
14
|
+
var actionList, controllerList, fn, _i, _len, _results;
|
15
|
+
controllerList = onloadCallbacks[controllerName];
|
16
|
+
if (controllerList) {
|
17
|
+
actionList = controllerList[actionName];
|
18
|
+
}
|
19
|
+
if (actionList) {
|
20
|
+
_results = [];
|
21
|
+
for (_i = 0, _len = actionList.length; _i < _len; _i++) {
|
22
|
+
fn = actionList[_i];
|
23
|
+
_results.push(fn());
|
24
|
+
}
|
25
|
+
return _results;
|
26
|
+
}
|
27
|
+
};
|
28
|
+
callController = function(controllerName, actionName) {
|
29
|
+
callAction(controllerName, actionName);
|
30
|
+
callAction("*", actionName);
|
31
|
+
callAction(controllerName, "*");
|
32
|
+
return callAction("*", "*");
|
33
|
+
};
|
34
|
+
window.runOnLoad = function(controllers, actions, fn) {
|
35
|
+
var a, c, _i, _len, _results;
|
36
|
+
if (jQuery.isFunction(actions) && !jQuery.isFunction(fn)) {
|
37
|
+
fn = actions;
|
38
|
+
actions = null;
|
39
|
+
}
|
40
|
+
controllers = makeOnLoadArray(controllers);
|
41
|
+
actions = makeOnLoadArray(actions);
|
42
|
+
_results = [];
|
43
|
+
for (_i = 0, _len = controllers.length; _i < _len; _i++) {
|
44
|
+
c = controllers[_i];
|
45
|
+
_results.push((function() {
|
46
|
+
var _base, _j, _len2, _ref, _ref2, _results2;
|
47
|
+
_results2 = [];
|
48
|
+
for (_j = 0, _len2 = actions.length; _j < _len2; _j++) {
|
49
|
+
a = actions[_j];
|
50
|
+
if ((_ref = onloadCallbacks[c]) == null) {
|
51
|
+
onloadCallbacks[c] = {};
|
52
|
+
}
|
53
|
+
if ((_ref2 = (_base = onloadCallbacks[c])[a]) == null) {
|
54
|
+
_base[a] = [];
|
55
|
+
}
|
56
|
+
_results2.push(onloadCallbacks[c][a].push(fn));
|
57
|
+
}
|
58
|
+
return _results2;
|
59
|
+
})());
|
60
|
+
}
|
61
|
+
return _results;
|
62
|
+
};
|
63
|
+
jQuery(function() {
|
64
|
+
var action, controller, dataElement, _ref, _ref2;
|
65
|
+
dataElement = $("#onload-js-data");
|
66
|
+
controller = (_ref = dataElement.data("controller")) != null ? _ref : "";
|
67
|
+
action = (_ref2 = dataElement.data("action")) != null ? _ref2 : "";
|
68
|
+
if (controller !== "" && action !== "") {
|
69
|
+
return callController(controller, action);
|
70
|
+
}
|
71
|
+
});
|
72
|
+
}).call(this);
|
@@ -0,0 +1,35 @@
|
|
1
|
+
onloadCallbacks = {}
|
2
|
+
|
3
|
+
makeOnLoadArray = (items) ->
|
4
|
+
return items if jQuery.isArray(items)
|
5
|
+
return [items] if jQuery.type(items) == "string"
|
6
|
+
return ["*"]
|
7
|
+
|
8
|
+
callAction = (controllerName, actionName) ->
|
9
|
+
controllerList = onloadCallbacks[controllerName]
|
10
|
+
actionList = controllerList[actionName] if controllerList
|
11
|
+
(fn() for fn in actionList) if actionList
|
12
|
+
|
13
|
+
callController = (controllerName, actionName) ->
|
14
|
+
callAction controllerName, actionName
|
15
|
+
callAction "*", actionName
|
16
|
+
callAction controllerName, "*"
|
17
|
+
callAction "*", "*"
|
18
|
+
|
19
|
+
window.runOnLoad = (controllers, actions, fn) ->
|
20
|
+
if jQuery.isFunction(actions) && !jQuery.isFunction(fn)
|
21
|
+
fn = actions
|
22
|
+
actions = null
|
23
|
+
controllers = makeOnLoadArray(controllers)
|
24
|
+
actions = makeOnLoadArray(actions)
|
25
|
+
for c in controllers
|
26
|
+
for a in actions
|
27
|
+
onloadCallbacks[c] ?= {}
|
28
|
+
onloadCallbacks[c][a] ?= []
|
29
|
+
onloadCallbacks[c][a].push fn
|
30
|
+
|
31
|
+
jQuery ->
|
32
|
+
dataElement = $("#onload-js-data")
|
33
|
+
controller = dataElement.data("controller") ? ""
|
34
|
+
action = dataElement.data("action") ? ""
|
35
|
+
callController(controller, action) if controller != "" && action != ""
|
data/lib/onload_js.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.expand_path("../lib/onload_js/version", __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "onload_js-rails"
|
5
|
+
s.version = OnloadJs::VERSION
|
6
|
+
s.platform = Gem::Platform::RUBY
|
7
|
+
s.authors = [ "Alex McHale" ]
|
8
|
+
s.email = [ "alex@anticlever.com" ]
|
9
|
+
s.homepage = "http://github.com/alexmchale/onload_js-rails"
|
10
|
+
s.description = "Lets you easily run JavaScript based on the current controller#action."
|
11
|
+
s.summary = "Lets you easily run JavaScript based on the current controller#action."
|
12
|
+
|
13
|
+
s.rubyforge_project = "onload_js-rails"
|
14
|
+
s.required_rubygems_version = "> 1.3.6"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
18
|
+
s.require_path = 'lib'
|
19
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
onload-js-test
|
@@ -0,0 +1,115 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
onload_js-rails (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
actionmailer (3.2.8)
|
10
|
+
actionpack (= 3.2.8)
|
11
|
+
mail (~> 2.4.4)
|
12
|
+
actionpack (3.2.8)
|
13
|
+
activemodel (= 3.2.8)
|
14
|
+
activesupport (= 3.2.8)
|
15
|
+
builder (~> 3.0.0)
|
16
|
+
erubis (~> 2.7.0)
|
17
|
+
journey (~> 1.0.4)
|
18
|
+
rack (~> 1.4.0)
|
19
|
+
rack-cache (~> 1.2)
|
20
|
+
rack-test (~> 0.6.1)
|
21
|
+
sprockets (~> 2.1.3)
|
22
|
+
activemodel (3.2.8)
|
23
|
+
activesupport (= 3.2.8)
|
24
|
+
builder (~> 3.0.0)
|
25
|
+
activerecord (3.2.8)
|
26
|
+
activemodel (= 3.2.8)
|
27
|
+
activesupport (= 3.2.8)
|
28
|
+
arel (~> 3.0.2)
|
29
|
+
tzinfo (~> 0.3.29)
|
30
|
+
activeresource (3.2.8)
|
31
|
+
activemodel (= 3.2.8)
|
32
|
+
activesupport (= 3.2.8)
|
33
|
+
activesupport (3.2.8)
|
34
|
+
i18n (~> 0.6)
|
35
|
+
multi_json (~> 1.0)
|
36
|
+
arel (3.0.2)
|
37
|
+
builder (3.0.4)
|
38
|
+
coffee-rails (3.2.2)
|
39
|
+
coffee-script (>= 2.2.0)
|
40
|
+
railties (~> 3.2.0)
|
41
|
+
coffee-script (2.2.0)
|
42
|
+
coffee-script-source
|
43
|
+
execjs
|
44
|
+
coffee-script-source (1.4.0)
|
45
|
+
erubis (2.7.0)
|
46
|
+
execjs (1.4.0)
|
47
|
+
multi_json (~> 1.0)
|
48
|
+
hike (1.2.1)
|
49
|
+
i18n (0.6.1)
|
50
|
+
journey (1.0.4)
|
51
|
+
jquery-rails (2.1.3)
|
52
|
+
railties (>= 3.1.0, < 5.0)
|
53
|
+
thor (~> 0.14)
|
54
|
+
json (1.7.5)
|
55
|
+
mail (2.4.4)
|
56
|
+
i18n (>= 0.4.0)
|
57
|
+
mime-types (~> 1.16)
|
58
|
+
treetop (~> 1.4.8)
|
59
|
+
mime-types (1.19)
|
60
|
+
multi_json (1.3.6)
|
61
|
+
polyglot (0.3.3)
|
62
|
+
rack (1.4.1)
|
63
|
+
rack-cache (1.2)
|
64
|
+
rack (>= 0.4)
|
65
|
+
rack-ssl (1.3.2)
|
66
|
+
rack
|
67
|
+
rack-test (0.6.2)
|
68
|
+
rack (>= 1.0)
|
69
|
+
rails (3.2.8)
|
70
|
+
actionmailer (= 3.2.8)
|
71
|
+
actionpack (= 3.2.8)
|
72
|
+
activerecord (= 3.2.8)
|
73
|
+
activeresource (= 3.2.8)
|
74
|
+
activesupport (= 3.2.8)
|
75
|
+
bundler (~> 1.0)
|
76
|
+
railties (= 3.2.8)
|
77
|
+
railties (3.2.8)
|
78
|
+
actionpack (= 3.2.8)
|
79
|
+
activesupport (= 3.2.8)
|
80
|
+
rack-ssl (~> 1.3.2)
|
81
|
+
rake (>= 0.8.7)
|
82
|
+
rdoc (~> 3.4)
|
83
|
+
thor (>= 0.14.6, < 2.0)
|
84
|
+
rake (0.9.2.2)
|
85
|
+
rdoc (3.12)
|
86
|
+
json (~> 1.4)
|
87
|
+
sass (3.2.1)
|
88
|
+
sass-rails (3.2.5)
|
89
|
+
railties (~> 3.2.0)
|
90
|
+
sass (>= 3.1.10)
|
91
|
+
tilt (~> 1.3)
|
92
|
+
sprockets (2.1.3)
|
93
|
+
hike (~> 1.2)
|
94
|
+
rack (~> 1.0)
|
95
|
+
tilt (~> 1.1, != 1.3.0)
|
96
|
+
thor (0.16.0)
|
97
|
+
tilt (1.3.3)
|
98
|
+
treetop (1.4.11)
|
99
|
+
polyglot
|
100
|
+
polyglot (>= 0.3.1)
|
101
|
+
tzinfo (0.3.34)
|
102
|
+
uglifier (1.3.0)
|
103
|
+
execjs (>= 0.3.0)
|
104
|
+
multi_json (~> 1.0, >= 1.0.2)
|
105
|
+
|
106
|
+
PLATFORMS
|
107
|
+
ruby
|
108
|
+
|
109
|
+
DEPENDENCIES
|
110
|
+
coffee-rails (~> 3.2.1)
|
111
|
+
jquery-rails
|
112
|
+
onload_js-rails!
|
113
|
+
rails (= 3.2.8)
|
114
|
+
sass-rails (~> 3.2.3)
|
115
|
+
uglifier (>= 1.0.3)
|