modjs-architecture 0.3.3 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -3
- data/VERSION +1 -1
- data/lib/modjs-architecture.rb +1 -1
- data/modjs-architecture.gemspec +10 -32
- data/spec/templates_spec.rb +24 -12
- metadata +14 -36
- data/spec/tmp/application/myapp.js +0 -322
- data/spec/tmp/application/test.js +0 -1
- data/spec/tmp/application/test.module.js +0 -1
- data/spec/tmp/foo-elements.js +0 -11
- data/spec/tmp/foo.js +0 -9
- data/spec/tmp/foo_all.js +0 -13
- data/spec/tmp/foo_elements.js +0 -11
- data/spec/tmp/foo_model.js +0 -11
- data/spec/tmp/lib/mod.js +0 -320
- data/spec/tmp/modules/test.module.js +0 -1
- data/spec/tmp/myapp.architecture +0 -8
- data/spec/tmp/myapp.blueprint +0 -8
- data/spec/tmp/spec/application_spec.js +0 -23
- data/spec/tmp/spec/dom_spec.js +0 -49
- data/spec/tmp/spec/existence_spec.js +0 -143
- data/spec/tmp/spec/jasmine/MIT.LICENSE +0 -20
- data/spec/tmp/spec/jasmine/index.html +0 -50
- data/spec/tmp/spec/jasmine/jasmine-html.js +0 -190
- data/spec/tmp/spec/jasmine/jasmine.css +0 -166
- data/spec/tmp/spec/jasmine/jasmine.js +0 -2476
- data/spec/tmp/spec/jasmine/jasmine_favicon.png +0 -0
- data/spec/tmp/spec/module_spec.js +0 -76
data/Gemfile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.5
|
data/lib/modjs-architecture.rb
CHANGED
@@ -4,7 +4,7 @@ module ArchitectureJS
|
|
4
4
|
path ||= File.expand_path(Dir.getwd)
|
5
5
|
filename = filename.gsub(/\.js$/, '.module.js')
|
6
6
|
File.open("#{path}/#{filename}", "w+") { |f| f.write template }
|
7
|
-
puts ArchitectureJS::Notification.added "#{filename}
|
7
|
+
puts ArchitectureJS::Notification.added "#{filename} added" if File.exists?("#{path}/#{filename}")
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
data/modjs-architecture.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "modjs-architecture"
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Dayton Nolan"]
|
@@ -69,28 +69,6 @@ Gem::Specification.new do |s|
|
|
69
69
|
"spec/modjs-architecture_spec.rb",
|
70
70
|
"spec/spec_helper.rb",
|
71
71
|
"spec/templates_spec.rb",
|
72
|
-
"spec/tmp/application/myapp.js",
|
73
|
-
"spec/tmp/application/test.js",
|
74
|
-
"spec/tmp/application/test.module.js",
|
75
|
-
"spec/tmp/foo-elements.js",
|
76
|
-
"spec/tmp/foo.js",
|
77
|
-
"spec/tmp/foo_all.js",
|
78
|
-
"spec/tmp/foo_elements.js",
|
79
|
-
"spec/tmp/foo_model.js",
|
80
|
-
"spec/tmp/lib/mod.js",
|
81
|
-
"spec/tmp/modules/test.module.js",
|
82
|
-
"spec/tmp/myapp.architecture",
|
83
|
-
"spec/tmp/myapp.blueprint",
|
84
|
-
"spec/tmp/spec/application_spec.js",
|
85
|
-
"spec/tmp/spec/dom_spec.js",
|
86
|
-
"spec/tmp/spec/existence_spec.js",
|
87
|
-
"spec/tmp/spec/jasmine/MIT.LICENSE",
|
88
|
-
"spec/tmp/spec/jasmine/index.html",
|
89
|
-
"spec/tmp/spec/jasmine/jasmine-html.js",
|
90
|
-
"spec/tmp/spec/jasmine/jasmine.css",
|
91
|
-
"spec/tmp/spec/jasmine/jasmine.js",
|
92
|
-
"spec/tmp/spec/jasmine/jasmine_favicon.png",
|
93
|
-
"spec/tmp/spec/module_spec.js",
|
94
72
|
"templates/model.js",
|
95
73
|
"templates/module.js"
|
96
74
|
]
|
@@ -105,25 +83,25 @@ Gem::Specification.new do |s|
|
|
105
83
|
|
106
84
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
107
85
|
s.add_runtime_dependency(%q<architecture-js>, [">= 0"])
|
108
|
-
s.add_development_dependency(%q<rspec>, ["
|
109
|
-
s.add_development_dependency(%q<bundler>, ["
|
86
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
87
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
110
88
|
s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
|
111
|
-
s.add_development_dependency(%q<jasmine>, ["
|
89
|
+
s.add_development_dependency(%q<jasmine>, [">= 0"])
|
112
90
|
s.add_runtime_dependency(%q<architecture-js>, [">= 0"])
|
113
91
|
else
|
114
92
|
s.add_dependency(%q<architecture-js>, [">= 0"])
|
115
|
-
s.add_dependency(%q<rspec>, ["
|
116
|
-
s.add_dependency(%q<bundler>, ["
|
93
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
94
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
117
95
|
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
118
|
-
s.add_dependency(%q<jasmine>, ["
|
96
|
+
s.add_dependency(%q<jasmine>, [">= 0"])
|
119
97
|
s.add_dependency(%q<architecture-js>, [">= 0"])
|
120
98
|
end
|
121
99
|
else
|
122
100
|
s.add_dependency(%q<architecture-js>, [">= 0"])
|
123
|
-
s.add_dependency(%q<rspec>, ["
|
124
|
-
s.add_dependency(%q<bundler>, ["
|
101
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
102
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
125
103
|
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
126
|
-
s.add_dependency(%q<jasmine>, ["
|
104
|
+
s.add_dependency(%q<jasmine>, [">= 0"])
|
127
105
|
s.add_dependency(%q<architecture-js>, [">= 0"])
|
128
106
|
end
|
129
107
|
end
|
data/spec/templates_spec.rb
CHANGED
@@ -22,12 +22,12 @@ describe "ModJS templates" do
|
|
22
22
|
filename: 'foo',
|
23
23
|
options: {}
|
24
24
|
}
|
25
|
-
|
26
|
-
@project.generator.generate(config)
|
27
|
-
File.exists?("#{TMP_DIR}/foo.js").should be_true
|
25
|
+
|
26
|
+
suppress_output { @project.generator.generate(config) }
|
27
|
+
File.exists?("#{TMP_DIR}/foo.module.js").should be_true
|
28
28
|
"#{TMP_DIR}/foo.module.js".should be_same_file_as "#{FIXTURES}/foo.js"
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
it 'should render a module with elements' do
|
32
32
|
config = {
|
33
33
|
arguments: ['module', 'foo_elements', '-e'],
|
@@ -35,12 +35,12 @@ describe "ModJS templates" do
|
|
35
35
|
filename: 'foo_elements',
|
36
36
|
options: { e: true }
|
37
37
|
}
|
38
|
-
|
39
|
-
@project.generator.generate(config)
|
38
|
+
|
39
|
+
suppress_output { @project.generator.generate(config) }
|
40
40
|
File.exists?("#{TMP_DIR}/foo_elements.module.js").should be_true
|
41
41
|
"#{TMP_DIR}/foo_elements.module.js".should be_same_file_as "#{FIXTURES}/foo_elements.js"
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
it 'should render a module with a model' do
|
45
45
|
config = {
|
46
46
|
arguments: ['module', 'foo_model', '-m'],
|
@@ -48,12 +48,12 @@ describe "ModJS templates" do
|
|
48
48
|
filename: 'foo_model',
|
49
49
|
options: { m: true }
|
50
50
|
}
|
51
|
-
|
52
|
-
@project.generator.generate(config)
|
51
|
+
|
52
|
+
suppress_output { @project.generator.generate(config) }
|
53
53
|
File.exists?("#{TMP_DIR}/foo_model.module.js").should be_true
|
54
54
|
"#{TMP_DIR}/foo_model.module.js".should be_same_file_as "#{FIXTURES}/foo_model.js"
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
it 'should render a module with both a model and elements' do
|
58
58
|
config = {
|
59
59
|
arguments: ['module', 'foo_all', '-e', '-m'],
|
@@ -61,10 +61,22 @@ describe "ModJS templates" do
|
|
61
61
|
filename: 'foo_all',
|
62
62
|
options: { e: true, m: true }
|
63
63
|
}
|
64
|
-
|
65
|
-
@project.generator.generate(config)
|
64
|
+
|
65
|
+
suppress_output { @project.generator.generate(config) }
|
66
66
|
File.exists?("#{TMP_DIR}/foo_all.module.js").should be_true
|
67
67
|
"#{TMP_DIR}/foo_all.module.js".should be_same_file_as "#{FIXTURES}/foo_all.js"
|
68
68
|
end
|
69
69
|
|
70
|
+
it 'should render a module partial with the correct module name' do
|
71
|
+
config = {
|
72
|
+
arguments: ['module', '_foo'],
|
73
|
+
template: 'module',
|
74
|
+
filename: '_foo',
|
75
|
+
options: {}
|
76
|
+
}
|
77
|
+
|
78
|
+
suppress_output { @project.generator.generate(config) }
|
79
|
+
File.exists?("#{TMP_DIR}/_foo.module.js").should be_true
|
80
|
+
"#{TMP_DIR}/_foo.module.js".should be_same_file_as "#{FIXTURES}/foo.js"
|
81
|
+
end
|
70
82
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: modjs-architecture
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -32,33 +32,33 @@ dependencies:
|
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
|
-
- -
|
35
|
+
- - ! '>='
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
37
|
+
version: '0'
|
38
38
|
type: :development
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
|
-
- -
|
43
|
+
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
45
|
+
version: '0'
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: bundler
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
51
|
-
- -
|
51
|
+
- - ! '>='
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
53
|
+
version: '0'
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
none: false
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: '0'
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
63
|
name: jeweler
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,17 +80,17 @@ dependencies:
|
|
80
80
|
requirement: !ruby/object:Gem::Requirement
|
81
81
|
none: false
|
82
82
|
requirements:
|
83
|
-
- -
|
83
|
+
- - ! '>='
|
84
84
|
- !ruby/object:Gem::Version
|
85
|
-
version:
|
85
|
+
version: '0'
|
86
86
|
type: :development
|
87
87
|
prerelease: false
|
88
88
|
version_requirements: !ruby/object:Gem::Requirement
|
89
89
|
none: false
|
90
90
|
requirements:
|
91
|
-
- -
|
91
|
+
- - ! '>='
|
92
92
|
- !ruby/object:Gem::Version
|
93
|
-
version:
|
93
|
+
version: '0'
|
94
94
|
- !ruby/object:Gem::Dependency
|
95
95
|
name: architecture-js
|
96
96
|
requirement: !ruby/object:Gem::Requirement
|
@@ -169,28 +169,6 @@ files:
|
|
169
169
|
- spec/modjs-architecture_spec.rb
|
170
170
|
- spec/spec_helper.rb
|
171
171
|
- spec/templates_spec.rb
|
172
|
-
- spec/tmp/application/myapp.js
|
173
|
-
- spec/tmp/application/test.js
|
174
|
-
- spec/tmp/application/test.module.js
|
175
|
-
- spec/tmp/foo-elements.js
|
176
|
-
- spec/tmp/foo.js
|
177
|
-
- spec/tmp/foo_all.js
|
178
|
-
- spec/tmp/foo_elements.js
|
179
|
-
- spec/tmp/foo_model.js
|
180
|
-
- spec/tmp/lib/mod.js
|
181
|
-
- spec/tmp/modules/test.module.js
|
182
|
-
- spec/tmp/myapp.architecture
|
183
|
-
- spec/tmp/myapp.blueprint
|
184
|
-
- spec/tmp/spec/application_spec.js
|
185
|
-
- spec/tmp/spec/dom_spec.js
|
186
|
-
- spec/tmp/spec/existence_spec.js
|
187
|
-
- spec/tmp/spec/jasmine/MIT.LICENSE
|
188
|
-
- spec/tmp/spec/jasmine/index.html
|
189
|
-
- spec/tmp/spec/jasmine/jasmine-html.js
|
190
|
-
- spec/tmp/spec/jasmine/jasmine.css
|
191
|
-
- spec/tmp/spec/jasmine/jasmine.js
|
192
|
-
- spec/tmp/spec/jasmine/jasmine_favicon.png
|
193
|
-
- spec/tmp/spec/module_spec.js
|
194
172
|
- templates/model.js
|
195
173
|
- templates/module.js
|
196
174
|
homepage: http://github.com/daytonn/modjs-architecture
|
@@ -208,7 +186,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
208
186
|
version: '0'
|
209
187
|
segments:
|
210
188
|
- 0
|
211
|
-
hash: -
|
189
|
+
hash: -4571541150195370455
|
212
190
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
213
191
|
none: false
|
214
192
|
requirements:
|
@@ -1,322 +0,0 @@
|
|
1
|
-
is_defined = function(suspect) {
|
2
|
-
return typeof suspect == "undefined" ? false : true;
|
3
|
-
};
|
4
|
-
|
5
|
-
is_undefined = function(suspect) {
|
6
|
-
return typeof suspect == "undefined" ? true : false;
|
7
|
-
};
|
8
|
-
|
9
|
-
is_typeof = function(type, suspect) {
|
10
|
-
if (is_undefined(type)) {
|
11
|
-
throw new Error("is_typeof(Type, suspect): type is undefined");
|
12
|
-
}
|
13
|
-
|
14
|
-
if (is_undefined(suspect)) {
|
15
|
-
throw new Error("is_typeof(Type, suspect): suspect is undefined");
|
16
|
-
}
|
17
|
-
|
18
|
-
return suspect.constructor == type ? true : false;
|
19
|
-
};
|
20
|
-
|
21
|
-
is_numeric = function(suspect) {
|
22
|
-
if (isNaN(suspect)) {
|
23
|
-
return false;
|
24
|
-
}
|
25
|
-
return !isNaN(parseFloat(suspect)) && isFinite(suspect);
|
26
|
-
};
|
27
|
-
|
28
|
-
is_string = function(suspect) {
|
29
|
-
return is_typeof(String, suspect);
|
30
|
-
};
|
31
|
-
|
32
|
-
is_array = function(suspect) {
|
33
|
-
return is_typeof(Array, suspect);
|
34
|
-
};
|
35
|
-
|
36
|
-
is_number = function(suspect) {
|
37
|
-
return is_typeof(Number, suspect);
|
38
|
-
};
|
39
|
-
|
40
|
-
is_date = function(suspect) {
|
41
|
-
return is_typeof(Date, suspect);
|
42
|
-
};
|
43
|
-
|
44
|
-
is_bool = function(suspect) {
|
45
|
-
return is_typeof(Boolean, suspect);
|
46
|
-
};
|
47
|
-
|
48
|
-
is_regex = function(suspect) {
|
49
|
-
return is_typeof(RegExp, suspect);
|
50
|
-
};
|
51
|
-
|
52
|
-
is_empty = function(suspect) {
|
53
|
-
if (is_undefined(suspect)) {
|
54
|
-
return true;
|
55
|
-
}
|
56
|
-
|
57
|
-
return suspect.length === 0;
|
58
|
-
};
|
59
|
-
|
60
|
-
is_not_empty = function(suspect) {
|
61
|
-
return suspect.length >= 1;
|
62
|
-
};
|
63
|
-
if (!Element.prototype.addEventListener) {
|
64
|
-
var oListeners = {};
|
65
|
-
|
66
|
-
function runListeners(oEvent) {
|
67
|
-
if (!oEvent) {
|
68
|
-
oEvent = window.event;
|
69
|
-
}
|
70
|
-
|
71
|
-
for (var iLstId = 0, iElId = 0, oEvtListeners = oListeners[oEvent.type]; iElId < oEvtListeners.aEls.length; iElId++) {
|
72
|
-
if (oEvtListeners.aEls[iElId] === this) {
|
73
|
-
for (iLstId; iLstId < oEvtListeners.aEvts[iElId].length; iLstId++) {
|
74
|
-
oEvtListeners.aEvts[iElId][iLstId].call(this, oEvent);
|
75
|
-
}
|
76
|
-
|
77
|
-
break;
|
78
|
-
}
|
79
|
-
}
|
80
|
-
}
|
81
|
-
|
82
|
-
Element.prototype.addEventListener = function (sEventType, fListener) {
|
83
|
-
if (oListeners.hasOwnProperty(sEventType)) {
|
84
|
-
var oEvtListeners = oListeners[sEventType];
|
85
|
-
|
86
|
-
for (var nElIdx = -1, iElId = 0; iElId < oEvtListeners.aEls.length; iElId++) {
|
87
|
-
if (oEvtListeners.aEls[iElId] === this) {
|
88
|
-
nElIdx = iElId; break;
|
89
|
-
}
|
90
|
-
}
|
91
|
-
|
92
|
-
if (nElIdx === -1) {
|
93
|
-
oEvtListeners.aEls.push(this);
|
94
|
-
oEvtListeners.aEvts.push([fListener]);
|
95
|
-
this["on" + sEventType] = runListeners;
|
96
|
-
}
|
97
|
-
else {
|
98
|
-
var aElListeners = oEvtListeners.aEvts[nElIdx];
|
99
|
-
|
100
|
-
if (this["on" + sEventType] !== runListeners) {
|
101
|
-
aElListeners.splice(0);
|
102
|
-
this["on" + sEventType] = runListeners;
|
103
|
-
}
|
104
|
-
|
105
|
-
for (var iLstId = 0; iLstId < aElListeners.length; iLstId++) {
|
106
|
-
if (aElListeners[iLstId] === fListener) {
|
107
|
-
return;
|
108
|
-
}
|
109
|
-
}
|
110
|
-
|
111
|
-
aElListeners.push(fListener);
|
112
|
-
}
|
113
|
-
}
|
114
|
-
else {
|
115
|
-
oListeners[sEventType] = {
|
116
|
-
aEls: [this],
|
117
|
-
aEvts: [[fListener]]
|
118
|
-
};
|
119
|
-
|
120
|
-
this["on" + sEventType] = runListeners;
|
121
|
-
}
|
122
|
-
};
|
123
|
-
|
124
|
-
Element.prototype.removeEventListener = function (sEventType) {
|
125
|
-
if (!oListeners.hasOwnProperty(sEventType)) {
|
126
|
-
return;
|
127
|
-
}
|
128
|
-
|
129
|
-
var oEvtListeners = oListeners[sEventType];
|
130
|
-
|
131
|
-
for (var nElIdx = -1, iElId = 0; iElId < oEvtListeners.aEls.length; iElId++) {
|
132
|
-
if (oEvtListeners.aEls[iElId] === this) {
|
133
|
-
nElIdx = iElId;
|
134
|
-
break;
|
135
|
-
}
|
136
|
-
}
|
137
|
-
|
138
|
-
if (nElIdx === -1) {
|
139
|
-
return;
|
140
|
-
}
|
141
|
-
|
142
|
-
for (var iLstId = 0, aElListeners = oEvtListeners.aEvts[nElIdx]; iLstId < aElListeners.length; iLstId++) {
|
143
|
-
aElListeners.splice(iLstId, 1);
|
144
|
-
}
|
145
|
-
};
|
146
|
-
}
|
147
|
-
|
148
|
-
var Mod = {};
|
149
|
-
|
150
|
-
Mod.DOM = (function() {
|
151
|
-
|
152
|
-
var timer,
|
153
|
-
queue = [];
|
154
|
-
|
155
|
-
function DOM() {
|
156
|
-
this.cache = {};
|
157
|
-
this.is_ready = false;
|
158
|
-
}
|
159
|
-
|
160
|
-
DOM.prototype.add_event = function(element, type, fn, capture) {
|
161
|
-
if (is_undefined(capture)) {
|
162
|
-
capture = false;
|
163
|
-
}
|
164
|
-
|
165
|
-
if (is_string(element)) {
|
166
|
-
element = this.cache[element];
|
167
|
-
}
|
168
|
-
|
169
|
-
element.addEventListener(type, fn, capture);
|
170
|
-
};
|
171
|
-
|
172
|
-
DOM.prototype.remove_event = function(element, type, fn, capture) {
|
173
|
-
if (is_undefined(capture)) {
|
174
|
-
capture = false;
|
175
|
-
}
|
176
|
-
|
177
|
-
if (is_string(element)) {
|
178
|
-
element = this.cache[element];
|
179
|
-
}
|
180
|
-
|
181
|
-
element.removeEventListener(type, fn, capture);
|
182
|
-
};
|
183
|
-
|
184
|
-
DOM.prototype.call_when_ready = function(func) {
|
185
|
-
if (this.is_ready) {
|
186
|
-
return func();
|
187
|
-
}
|
188
|
-
|
189
|
-
if (timer) {
|
190
|
-
queue.push(func);
|
191
|
-
}
|
192
|
-
else {
|
193
|
-
this.add_event(window, 'load', this.execute_ready_queue);
|
194
|
-
queue.push(func);
|
195
|
-
timer = setInterval(this.execute_ready_queue, 13);
|
196
|
-
}
|
197
|
-
};
|
198
|
-
|
199
|
-
DOM.prototype.execute_ready_queue = function() {
|
200
|
-
if (this.is_ready) {
|
201
|
-
return false;
|
202
|
-
}
|
203
|
-
|
204
|
-
if (document && document.getElementsByTagName && document.getElementById && document.body) {
|
205
|
-
clearInterval(timer);
|
206
|
-
timer = null;
|
207
|
-
for(var i = 0, j = queue.length; i < j; i++) {
|
208
|
-
queue[i]();
|
209
|
-
}
|
210
|
-
|
211
|
-
queue = [];
|
212
|
-
this.is_ready = true;
|
213
|
-
}
|
214
|
-
};
|
215
|
-
|
216
|
-
DOM.prototype.add_elements = function(elements) {
|
217
|
-
for(var key in elements) {
|
218
|
-
if (elements.hasOwnProperty(key)) {
|
219
|
-
this.add_element(key, elements[key]);
|
220
|
-
}
|
221
|
-
}
|
222
|
-
};
|
223
|
-
|
224
|
-
DOM.prototype.add_element = function(key, element) {
|
225
|
-
this.cache[key] = element;
|
226
|
-
};
|
227
|
-
|
228
|
-
return DOM;
|
229
|
-
})();
|
230
|
-
Mod.Module = (function() {
|
231
|
-
|
232
|
-
function Module(name) {
|
233
|
-
if (is_undefined(name)) {
|
234
|
-
throw new Error("Mod.Module(name): name is undefined");
|
235
|
-
}
|
236
|
-
|
237
|
-
this.dom = new Mod.DOM;
|
238
|
-
this.data = {};
|
239
|
-
this.name = name;
|
240
|
-
}
|
241
|
-
|
242
|
-
Module.prototype.actions = function() {};
|
243
|
-
|
244
|
-
Module.prototype.run = function() {
|
245
|
-
var mod = this;
|
246
|
-
this.dom.call_when_ready(function() {
|
247
|
-
mod.execute();
|
248
|
-
});
|
249
|
-
};
|
250
|
-
|
251
|
-
Module.prototype.execute = function() {
|
252
|
-
this.actions();
|
253
|
-
};
|
254
|
-
|
255
|
-
Module.prototype.elements = function(elements) {
|
256
|
-
if (is_undefined(elements)) {
|
257
|
-
return this.dom.cache;
|
258
|
-
}
|
259
|
-
|
260
|
-
if (is_string(elements)) {
|
261
|
-
var name = elements;
|
262
|
-
return this.dom.cache[name];
|
263
|
-
}
|
264
|
-
else {
|
265
|
-
this.dom.add_elements(elements);
|
266
|
-
}
|
267
|
-
};
|
268
|
-
|
269
|
-
Module.prototype.set_data = function(key, value) {
|
270
|
-
if (is_undefined(key)) {
|
271
|
-
throw new Error(this.name + '.set_data(key, value): key is undefined');
|
272
|
-
}
|
273
|
-
|
274
|
-
if (is_typeof(String, key) && is_undefined(value)) {
|
275
|
-
throw new SyntaxError(this.name + 'Module.set_data(key, value): value is undefined');
|
276
|
-
}
|
277
|
-
|
278
|
-
if (is_typeof(String, key)) {
|
279
|
-
this.data[key] = value;
|
280
|
-
}
|
281
|
-
else if (is_typeof(Object, key)) {
|
282
|
-
var data = key;
|
283
|
-
for(var property in data) {
|
284
|
-
this.data[property] = data[property];
|
285
|
-
}
|
286
|
-
}
|
287
|
-
|
288
|
-
return this;
|
289
|
-
};
|
290
|
-
|
291
|
-
return Module;
|
292
|
-
})();
|
293
|
-
Mod.Application = (function() {
|
294
|
-
|
295
|
-
function Application(name) {
|
296
|
-
if (is_undefined(name)) {
|
297
|
-
throw new Error("new Mod.Application(name): name is undefined");
|
298
|
-
}
|
299
|
-
|
300
|
-
this.name = name
|
301
|
-
};
|
302
|
-
|
303
|
-
Application.prototype.add_module = function(name) {
|
304
|
-
if (is_undefined(name)) {
|
305
|
-
throw new Error("Mod.Application.add_module(name): name is undefined");
|
306
|
-
}
|
307
|
-
|
308
|
-
if (is_defined(this[name])) {
|
309
|
-
throw new Error("Mod.Application.add_module('" + name + "'): '" + name + "' already declared");
|
310
|
-
}
|
311
|
-
|
312
|
-
if (this.name === name) {
|
313
|
-
throw new Error("Mod.Application.add_module('" + name + "'): a module cannot have the same name as the application. It's bad idea. Do you really want to write " + name + "." + name + "? It's confusing.'");
|
314
|
-
}
|
315
|
-
|
316
|
-
return this[name] = new Mod.Module(name);
|
317
|
-
};
|
318
|
-
|
319
|
-
return Application;
|
320
|
-
})();
|
321
|
-
|
322
|
-
var myapp = new Mod.Application('myapp');
|