modjs-architecture 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/.travis.yml +2 -0
  2. data/Gemfile +9 -3
  3. data/Gemfile.lock +49 -13
  4. data/{README.rdoc → README.md} +6 -4
  5. data/Rakefile +25 -4
  6. data/VERSION +1 -1
  7. data/lib/modjs-architecture.rb +122 -0
  8. data/lib/modjs-architecture/core/application.js +29 -0
  9. data/lib/modjs-architecture/core/dom.js +84 -0
  10. data/lib/modjs-architecture/core/module.js +65 -0
  11. data/lib/modjs-architecture/extensions/events.js +84 -0
  12. data/lib/modjs-architecture/helpers/existence.js +62 -0
  13. data/lib/modjs-architecture/jasmine/MIT.LICENSE +20 -0
  14. data/lib/modjs-architecture/jasmine/index.html +50 -0
  15. data/lib/modjs-architecture/jasmine/jasmine-html.js +190 -0
  16. data/lib/modjs-architecture/jasmine/jasmine.css +166 -0
  17. data/lib/modjs-architecture/jasmine/jasmine.js +2476 -0
  18. data/lib/modjs-architecture/jasmine/jasmine_favicon.png +0 -0
  19. data/lib/modjs-architecture/lib/mod.js +320 -0
  20. data/lib/modjs-architecture/modjs.architecture +6 -0
  21. data/lib/modjs-architecture/src/mod.js +9 -0
  22. data/modjs-architecture.gemspec +92 -0
  23. data/spec/fixtures/myapp.architecture +8 -0
  24. data/spec/fixtures/myapp.js +322 -0
  25. data/spec/fixtures/test.js +1 -0
  26. data/spec/fixtures/test.module.js +1 -0
  27. data/spec/fixtures/update.architecture +8 -0
  28. data/spec/fixtures/update.js +329 -0
  29. data/spec/javascripts/application_spec.js +23 -0
  30. data/spec/javascripts/dom_spec.js +49 -0
  31. data/spec/javascripts/existence_spec.js +143 -0
  32. data/spec/javascripts/module_spec.js +76 -0
  33. data/spec/javascripts/support/jasmine.css +229 -0
  34. data/spec/javascripts/support/jasmine.yml +73 -0
  35. data/spec/javascripts/support/jasmine_config.rb +23 -0
  36. data/spec/javascripts/support/jasmine_runner.rb +32 -0
  37. data/spec/modjs-architecture_spec.rb +97 -4
  38. data/spec/spec_helper.rb +39 -8
  39. metadata +61 -22
@@ -0,0 +1,320 @@
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
+ })();
@@ -0,0 +1,6 @@
1
+ framework: none
2
+ src_dir: src
3
+ build_dir: lib
4
+ asset_root: ../
5
+ output: expanded
6
+ name: mod
@@ -0,0 +1,9 @@
1
+ //= require "../helpers/existence"
2
+ //= require "../extensions/events"
3
+
4
+ // Mod namespace object
5
+ var Mod = {};
6
+
7
+ //= require "../core/dom"
8
+ //= require "../core/module"
9
+ //= require "../core/application"
@@ -0,0 +1,92 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "modjs-architecture"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Dayton Nolan"]
12
+ s.date = "2012-02-04"
13
+ s.description = "Mod.js is a modular javascript library that provides a base application strucure to build large javascript applications. Mod.js is designed to work with architecture.js."
14
+ s.email = "daytonn@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ ".travis.yml",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.md",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "lib/modjs-architecture.rb",
30
+ "lib/modjs-architecture/core/application.js",
31
+ "lib/modjs-architecture/core/dom.js",
32
+ "lib/modjs-architecture/core/module.js",
33
+ "lib/modjs-architecture/extensions/events.js",
34
+ "lib/modjs-architecture/helpers/existence.js",
35
+ "lib/modjs-architecture/jasmine/MIT.LICENSE",
36
+ "lib/modjs-architecture/jasmine/index.html",
37
+ "lib/modjs-architecture/jasmine/jasmine-html.js",
38
+ "lib/modjs-architecture/jasmine/jasmine.css",
39
+ "lib/modjs-architecture/jasmine/jasmine.js",
40
+ "lib/modjs-architecture/jasmine/jasmine_favicon.png",
41
+ "lib/modjs-architecture/lib/mod.js",
42
+ "lib/modjs-architecture/modjs.architecture",
43
+ "lib/modjs-architecture/src/mod.js",
44
+ "modjs-architecture.gemspec",
45
+ "spec/fixtures/myapp.architecture",
46
+ "spec/fixtures/myapp.js",
47
+ "spec/fixtures/test.js",
48
+ "spec/fixtures/test.module.js",
49
+ "spec/fixtures/update.architecture",
50
+ "spec/fixtures/update.js",
51
+ "spec/javascripts/application_spec.js",
52
+ "spec/javascripts/dom_spec.js",
53
+ "spec/javascripts/existence_spec.js",
54
+ "spec/javascripts/module_spec.js",
55
+ "spec/javascripts/support/jasmine.css",
56
+ "spec/javascripts/support/jasmine.yml",
57
+ "spec/javascripts/support/jasmine_config.rb",
58
+ "spec/javascripts/support/jasmine_runner.rb",
59
+ "spec/modjs-architecture_spec.rb",
60
+ "spec/spec_helper.rb"
61
+ ]
62
+ s.homepage = "http://github.com/daytonn/modjs-architecture"
63
+ s.licenses = ["MIT"]
64
+ s.require_paths = ["lib"]
65
+ s.rubygems_version = "1.8.10"
66
+ s.summary = "Mod.js is an a la carte javascript framework"
67
+
68
+ if s.respond_to? :specification_version then
69
+ s.specification_version = 3
70
+
71
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
72
+ s.add_runtime_dependency(%q<architecture-js>, ["~> 0.1.11"])
73
+ s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
74
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
75
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
76
+ s.add_development_dependency(%q<jasmine>, ["~> 1.1.2"])
77
+ else
78
+ s.add_dependency(%q<architecture-js>, ["~> 0.1.11"])
79
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
80
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
81
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
82
+ s.add_dependency(%q<jasmine>, ["~> 1.1.2"])
83
+ end
84
+ else
85
+ s.add_dependency(%q<architecture-js>, ["~> 0.1.11"])
86
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
87
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
88
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
89
+ s.add_dependency(%q<jasmine>, ["~> 1.1.2"])
90
+ end
91
+ end
92
+
@@ -0,0 +1,8 @@
1
+ framework: modjs
2
+ src_dir: modules
3
+ build_dir: application
4
+ asset_root: ../
5
+ output: compressed
6
+ dependencies: []
7
+ autoload: []
8
+ name: myapp
@@ -0,0 +1,322 @@
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');