autoexec_bat 0.0.2 → 0.1.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/README.md +7 -2
- data/Rakefile +5 -0
- data/autoexec_bat.js +18 -11
- data/lib/assets/javascripts/autoexec_bat.coffee +14 -9
- data/lib/autoexec_bat/version.rb +1 -1
- metadata +7 -9
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7f60fe570778c137a5bb9113e01a021045bb2030
|
4
|
+
data.tar.gz: 524273306bf383b9852747df6be337ea41138aa2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9dc3b94bd0b4f83be51aa53d2447f59225aa229d721b2d68f72a2068e74a3851b64ed14b5bd76614b4375e4c911d5381bbdaff79081a38c722171a5c607eeebc
|
7
|
+
data.tar.gz: 670464648abc419179aa3854cd98fd1f9843e15066beee0fcc44536649c98c5207ae7780b8d8422c2cb4d88e42975af1e739a66763a2dc8415db60840c6d1b32
|
data/README.md
CHANGED
@@ -63,6 +63,10 @@ Some examples:
|
|
63
63
|
# or
|
64
64
|
App.Products.Show.autoexec(productItem)
|
65
65
|
|
66
|
+
# If you want modules to be autoexec'd several times
|
67
|
+
App.Products.Show.autoexec
|
68
|
+
idempotent: false
|
69
|
+
|
66
70
|
Finally, just add the module name to a data-autoexec attribute:
|
67
71
|
|
68
72
|
<body data-autoexec="App.Products.Index">
|
@@ -90,8 +94,9 @@ Require your modules and activate autoexecution (with turbolinks - default in Ra
|
|
90
94
|
|
91
95
|
#= require autoexec_bat
|
92
96
|
#= require_tree ./folder-containing-your-modules
|
93
|
-
jQuery(document).bind 'ready page:
|
94
|
-
$('[data-autoexec]').autoexec
|
97
|
+
jQuery(document).bind 'ready page:load', ->
|
98
|
+
$('[data-autoexec]').autoexec
|
99
|
+
idempotent: false
|
95
100
|
|
96
101
|
For Rails 3:
|
97
102
|
|
data/Rakefile
CHANGED
data/autoexec_bat.js
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
// Generated by CoffeeScript 1.3.1
|
2
2
|
(function() {
|
3
|
+
// Generated by CoffeeScript 1.3.3
|
3
4
|
var $, AutoexecBat, root,
|
4
5
|
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
5
6
|
|
@@ -41,15 +42,17 @@
|
|
41
42
|
target.loaded = false;
|
42
43
|
target.autoexec = function() {};
|
43
44
|
target.dependencies = dependencies;
|
44
|
-
target.init = function() {
|
45
|
-
if (!this.loaded) {
|
45
|
+
target.init = function(options) {
|
46
|
+
if (!(options.idempotent && this.loaded)) {
|
46
47
|
require(dependencies);
|
47
48
|
if (typeof this.autoexec === 'function') {
|
48
|
-
this.autoexec();
|
49
|
+
this.autoexec(options.callee);
|
50
|
+
}
|
51
|
+
if (options.idempotent) {
|
52
|
+
this.autoexec = function() {
|
53
|
+
return AutoexecBat.log("Module already initialized");
|
54
|
+
};
|
49
55
|
}
|
50
|
-
this.autoexec = function() {
|
51
|
-
return AutoexecBat.log("Module already initialized");
|
52
|
-
};
|
53
56
|
return this.loaded = true;
|
54
57
|
}
|
55
58
|
};
|
@@ -96,17 +99,17 @@
|
|
96
99
|
}
|
97
100
|
return module;
|
98
101
|
},
|
99
|
-
initializeModule: function(nameOrModule) {
|
102
|
+
initializeModule: function(nameOrModule, options) {
|
100
103
|
var module;
|
101
104
|
module = typeof nameOrModule === "string" ? AutoexecBat.findModule(nameOrModule) : nameOrModule;
|
102
105
|
if (typeof module !== 'undefined' && typeof module.init !== 'undefined') {
|
103
|
-
return module.init();
|
106
|
+
return module.init(options);
|
104
107
|
}
|
105
108
|
},
|
106
|
-
run: function(name) {
|
109
|
+
run: function(name, options) {
|
107
110
|
var module;
|
108
111
|
module = AutoexecBat.findModule(name);
|
109
|
-
return AutoexecBat.initializeModule(module);
|
112
|
+
return AutoexecBat.initializeModule(module, options);
|
110
113
|
}
|
111
114
|
};
|
112
115
|
|
@@ -122,8 +125,12 @@
|
|
122
125
|
$ = jQuery;
|
123
126
|
$.fn.extend({
|
124
127
|
autoexec: function(options) {
|
128
|
+
options = $.extend({
|
129
|
+
callee: this,
|
130
|
+
idempotent: true
|
131
|
+
}, options);
|
125
132
|
return this.each(function() {
|
126
|
-
return AutoexecBat.run($(this).data('autoexec'));
|
133
|
+
return AutoexecBat.run($(this).data('autoexec'), options);
|
127
134
|
});
|
128
135
|
}
|
129
136
|
});
|
@@ -28,11 +28,12 @@ AutoexecBat =
|
|
28
28
|
target.loaded = false
|
29
29
|
target.autoexec = -> # make sure the autoexec function exists
|
30
30
|
target.dependencies = dependencies
|
31
|
-
target.init = (
|
32
|
-
unless @loaded
|
31
|
+
target.init = (options) ->
|
32
|
+
unless options.idempotent and @loaded
|
33
33
|
require dependencies
|
34
|
-
@autoexec(callee) if typeof @autoexec is 'function'
|
35
|
-
|
34
|
+
@autoexec(options.callee) if typeof @autoexec is 'function'
|
35
|
+
if options.idempotent
|
36
|
+
@autoexec = -> AutoexecBat.log "Module already initialized"
|
36
37
|
@loaded = true
|
37
38
|
|
38
39
|
block target, top
|
@@ -55,13 +56,13 @@ AutoexecBat =
|
|
55
56
|
module = module[item] unless typeof module[item] is 'undefined'
|
56
57
|
module
|
57
58
|
|
58
|
-
initializeModule: (nameOrModule,
|
59
|
+
initializeModule: (nameOrModule, options) ->
|
59
60
|
module = if typeof nameOrModule is "string" then AutoexecBat.findModule(nameOrModule) else nameOrModule
|
60
|
-
module.init(
|
61
|
+
module.init(options) if typeof module isnt 'undefined' and typeof module.init isnt 'undefined'
|
61
62
|
|
62
|
-
run: (name,
|
63
|
+
run: (name, options) ->
|
63
64
|
module = AutoexecBat.findModule name
|
64
|
-
AutoexecBat.initializeModule module,
|
65
|
+
AutoexecBat.initializeModule module, options
|
65
66
|
|
66
67
|
|
67
68
|
# Globals
|
@@ -75,4 +76,8 @@ unless typeof jQuery is 'undefined'
|
|
75
76
|
$ = jQuery
|
76
77
|
$.fn.extend
|
77
78
|
autoexec: (options) ->
|
78
|
-
|
79
|
+
options = $.extend
|
80
|
+
callee: @
|
81
|
+
idempotent: true
|
82
|
+
, options
|
83
|
+
return @each -> AutoexecBat.run $(@).data('autoexec'), options
|
data/lib/autoexec_bat/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: autoexec_bat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Gudleik Rasch
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-03-07 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: Autoexecution of javascript based on data attribute
|
15
14
|
email:
|
@@ -31,27 +30,26 @@ files:
|
|
31
30
|
- lib/autoexec_bat/version.rb
|
32
31
|
homepage: https://github.com/Skalar/autoexec_bat
|
33
32
|
licenses: []
|
33
|
+
metadata: {}
|
34
34
|
post_install_message:
|
35
35
|
rdoc_options: []
|
36
36
|
require_paths:
|
37
37
|
- lib
|
38
38
|
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
40
39
|
requirements:
|
41
|
-
- -
|
40
|
+
- - '>='
|
42
41
|
- !ruby/object:Gem::Version
|
43
42
|
version: '0'
|
44
43
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
-
none: false
|
46
44
|
requirements:
|
47
|
-
- -
|
45
|
+
- - '>='
|
48
46
|
- !ruby/object:Gem::Version
|
49
47
|
version: '0'
|
50
48
|
requirements: []
|
51
49
|
rubyforge_project:
|
52
|
-
rubygems_version:
|
50
|
+
rubygems_version: 2.0.0
|
53
51
|
signing_key:
|
54
|
-
specification_version:
|
52
|
+
specification_version: 4
|
55
53
|
summary: Autoexecution of javascript based on data attribute
|
56
54
|
test_files: []
|
57
55
|
has_rdoc:
|