micro-rails 0.1.0.pre.alpha5 → 0.1.0.pre.alpha6
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 +4 -4
- data/Rakefile +1 -1
- data/lib/micro/rails/version.rb +1 -1
- data/vendor/assets/javascripts/micro.js +899 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52e327d8894efaf370b3924cc0ea95f13ec10759
|
4
|
+
data.tar.gz: 6bd0a32dcb304d9cd99dcbd743a130050d50b2e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a98d8367473837f8ae740075938529601a6aa1b963de02d3b4c7e7e1caf86eb68b592dee4fb846922356db3a752700a0c35b68f6fe361a88aed3ed79121834dd
|
7
|
+
data.tar.gz: 0573fb192c64c9a940c9aac95ce8269ddb0f36086f54ea449edb641e6ef9019bf3e80e5428f7475ae2ae73cc1a94c91309d95525136cbc826b1ee70f5ef0628c
|
data/Rakefile
CHANGED
@@ -3,5 +3,5 @@ require "bundler/gem_tasks"
|
|
3
3
|
desc 'Download micro.js in vendor/assets/javascripts'
|
4
4
|
task 'download' do
|
5
5
|
puts 'Downloading micro.js'
|
6
|
-
puts `curl -o vendor/assets/javascripts/micro.js https://raw.githubusercontent.com/jguyon/micro/v#{Micro::Rails::MICRO_VERSION}/
|
6
|
+
puts `curl -o vendor/assets/javascripts/micro.js https://raw.githubusercontent.com/jguyon/micro/v#{Micro::Rails::MICRO_VERSION}/dist/micro.js`
|
7
7
|
end
|
data/lib/micro/rails/version.rb
CHANGED
@@ -1 +1,899 @@
|
|
1
|
-
|
1
|
+
(function() {
|
2
|
+
var Component, Factory, Module, Namespace, Unit, delegatedMethods, factory, method, mu, splitOnce, _fn, _i, _len,
|
3
|
+
__hasProp = {}.hasOwnProperty,
|
4
|
+
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
5
|
+
__slice = [].slice;
|
6
|
+
|
7
|
+
splitOnce = function(string, char) {
|
8
|
+
var splits;
|
9
|
+
splits = string.split(char);
|
10
|
+
return [splits.shift(), splits.join(char)];
|
11
|
+
};
|
12
|
+
|
13
|
+
Factory = (function() {
|
14
|
+
function Factory() {
|
15
|
+
this.config = {
|
16
|
+
defaultNamespace: 'app',
|
17
|
+
dataPrefix: 'micro'
|
18
|
+
};
|
19
|
+
this._namespaces = {};
|
20
|
+
this._initialize = [];
|
21
|
+
this._destroy = [];
|
22
|
+
}
|
23
|
+
|
24
|
+
Factory.prototype.configure = function(config) {
|
25
|
+
return _.extend(this.config, config);
|
26
|
+
};
|
27
|
+
|
28
|
+
Factory.prototype.setup = function(setup) {
|
29
|
+
return setup.call({
|
30
|
+
initialize: (function(_this) {
|
31
|
+
return function(initialize) {
|
32
|
+
return _this._initialize.push(initialize);
|
33
|
+
};
|
34
|
+
})(this),
|
35
|
+
destroy: (function(_this) {
|
36
|
+
return function(destroy) {
|
37
|
+
return _this._destroy.unshift(destroy);
|
38
|
+
};
|
39
|
+
})(this),
|
40
|
+
component: (function(_this) {
|
41
|
+
return function(name, el, config) {
|
42
|
+
var Component;
|
43
|
+
if (!(_.isString(el) || _.isElement(el))) {
|
44
|
+
config = el;
|
45
|
+
el = null;
|
46
|
+
}
|
47
|
+
Component = _this.component(name);
|
48
|
+
el || (el = Component.config.defaultSelector);
|
49
|
+
if (!el) {
|
50
|
+
throw new Error('you must provide a selector or define' + ' defaultSelector in the component configuration');
|
51
|
+
}
|
52
|
+
_this._initialize.push(function() {
|
53
|
+
Component.initialize(this.filter(el), config);
|
54
|
+
return Component.initialize(this.find(el), config);
|
55
|
+
});
|
56
|
+
return _this._destroy.unshift(function() {
|
57
|
+
Component.destroy(this.filter(el));
|
58
|
+
return Component.destroy(this.find(el));
|
59
|
+
});
|
60
|
+
};
|
61
|
+
})(this)
|
62
|
+
});
|
63
|
+
};
|
64
|
+
|
65
|
+
Factory.prototype.initialize = function(el) {
|
66
|
+
var $el, initialize, _i, _len, _ref, _results;
|
67
|
+
$el = $(el);
|
68
|
+
_ref = this._initialize;
|
69
|
+
_results = [];
|
70
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
71
|
+
initialize = _ref[_i];
|
72
|
+
_results.push(initialize.call($el));
|
73
|
+
}
|
74
|
+
return _results;
|
75
|
+
};
|
76
|
+
|
77
|
+
Factory.prototype.destroy = function(el) {
|
78
|
+
var $el, destroy, _i, _len, _ref, _results;
|
79
|
+
$el = $(el);
|
80
|
+
_ref = this._destroy;
|
81
|
+
_results = [];
|
82
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
83
|
+
destroy = _ref[_i];
|
84
|
+
_results.push(destroy.call($el));
|
85
|
+
}
|
86
|
+
return _results;
|
87
|
+
};
|
88
|
+
|
89
|
+
Factory.prototype.clean = function() {
|
90
|
+
this._namespaces = {};
|
91
|
+
this._initialize = [];
|
92
|
+
return this._destroy = [];
|
93
|
+
};
|
94
|
+
|
95
|
+
Factory.prototype.namespace = function(label, doNotThrow) {
|
96
|
+
var namespace;
|
97
|
+
if (doNotThrow == null) {
|
98
|
+
doNotThrow = false;
|
99
|
+
}
|
100
|
+
if (!((namespace = this._namespaces[label]) || doNotThrow)) {
|
101
|
+
throw new Error("could not find namespace " + label);
|
102
|
+
}
|
103
|
+
return namespace;
|
104
|
+
};
|
105
|
+
|
106
|
+
Factory.prototype.component = function(name, doNotThrow) {
|
107
|
+
var label, namespace, _ref;
|
108
|
+
if (doNotThrow == null) {
|
109
|
+
doNotThrow = false;
|
110
|
+
}
|
111
|
+
_ref = this._splitUnitName(name), namespace = _ref[0], label = _ref[1];
|
112
|
+
return this.namespace(namespace, doNotThrow).component(label, doNotThrow);
|
113
|
+
};
|
114
|
+
|
115
|
+
Factory.prototype.module = function(name, doNotThrow) {
|
116
|
+
var label, namespace, _ref;
|
117
|
+
if (doNotThrow == null) {
|
118
|
+
doNotThrow = false;
|
119
|
+
}
|
120
|
+
_ref = this._splitUnitName(name), namespace = _ref[0], label = _ref[1];
|
121
|
+
return this.namespace(namespace, doNotThrow).module(label, doNotThrow);
|
122
|
+
};
|
123
|
+
|
124
|
+
Factory.prototype.createNamespace = function(label) {
|
125
|
+
if (this._namespaces[label]) {
|
126
|
+
throw new Error("namespace " + label + " already exists");
|
127
|
+
}
|
128
|
+
return this._namespaces[label] = new Namespace(this, label);
|
129
|
+
};
|
130
|
+
|
131
|
+
Factory.prototype.data = function(el, name, value) {
|
132
|
+
if (arguments.length < 3) {
|
133
|
+
return $(el).data(this._dataName(name));
|
134
|
+
} else {
|
135
|
+
return $(el).data(this._dataName(name), value);
|
136
|
+
}
|
137
|
+
};
|
138
|
+
|
139
|
+
Factory.prototype.removeData = function(el, name) {
|
140
|
+
return $(el).removeData(this._dataName(name));
|
141
|
+
};
|
142
|
+
|
143
|
+
Factory.prototype._splitUnitName = function(name) {
|
144
|
+
var label, namespace, _ref;
|
145
|
+
_ref = splitOnce(name, '.'), namespace = _ref[0], label = _ref[1];
|
146
|
+
if (!label) {
|
147
|
+
label = namespace;
|
148
|
+
namespace = this.config.defaultNamespace;
|
149
|
+
}
|
150
|
+
return [namespace, label];
|
151
|
+
};
|
152
|
+
|
153
|
+
Factory.prototype._dataName = function(name) {
|
154
|
+
return "" + this.config.dataPrefix + "-" + name;
|
155
|
+
};
|
156
|
+
|
157
|
+
return Factory;
|
158
|
+
|
159
|
+
})();
|
160
|
+
|
161
|
+
Namespace = (function() {
|
162
|
+
Namespace.labelFormat = /^[a-z][a-zA-Z0-9]*$/;
|
163
|
+
|
164
|
+
function Namespace(factory, label) {
|
165
|
+
this.factory = factory;
|
166
|
+
this.label = label;
|
167
|
+
if (!this.label.match(this.constructor.labelFormat)) {
|
168
|
+
throw new Error("" + this.label + " is not a valid namespace name");
|
169
|
+
}
|
170
|
+
this._components = {};
|
171
|
+
this._modules = {};
|
172
|
+
this.config = {};
|
173
|
+
}
|
174
|
+
|
175
|
+
Namespace.prototype.muObject = function() {
|
176
|
+
return {
|
177
|
+
configure: (function(_this) {
|
178
|
+
return function(config) {
|
179
|
+
_this.configure(config);
|
180
|
+
return _this.muObject();
|
181
|
+
};
|
182
|
+
})(this)
|
183
|
+
};
|
184
|
+
};
|
185
|
+
|
186
|
+
Namespace.prototype.configure = function(config) {
|
187
|
+
return _.extend(this.config, config);
|
188
|
+
};
|
189
|
+
|
190
|
+
Namespace.prototype.component = function(label, doNotThrow) {
|
191
|
+
var Component;
|
192
|
+
if (doNotThrow == null) {
|
193
|
+
doNotThrow = false;
|
194
|
+
}
|
195
|
+
if (!((Component = this._components[label]) || doNotThrow)) {
|
196
|
+
throw new Error("component " + label + " could not be found in namespace " + this.name);
|
197
|
+
}
|
198
|
+
return Component;
|
199
|
+
};
|
200
|
+
|
201
|
+
Namespace.prototype.module = function(label, doNotThrow) {
|
202
|
+
var Module;
|
203
|
+
if (doNotThrow == null) {
|
204
|
+
doNotThrow = false;
|
205
|
+
}
|
206
|
+
if (!((Module = this._modules[label]) || doNotThrow)) {
|
207
|
+
throw new Error("module " + label + " could not be found in namespace " + this.name);
|
208
|
+
}
|
209
|
+
return Module;
|
210
|
+
};
|
211
|
+
|
212
|
+
Namespace.prototype.addUnit = function(Unit) {
|
213
|
+
var prototype;
|
214
|
+
if (Unit.namespace !== this) {
|
215
|
+
throw new Error("Unit " + Unit.label + " does not belong to namespace " + this.name);
|
216
|
+
}
|
217
|
+
prototype = Unit.prototype;
|
218
|
+
if (prototype instanceof Component) {
|
219
|
+
return this._components[Unit.label] = Unit;
|
220
|
+
} else if (prototype instanceof Module) {
|
221
|
+
return this._modules[Unit.label] = Unit;
|
222
|
+
} else {
|
223
|
+
throw new Error('cannot add a unit that is not a child of Component or Module');
|
224
|
+
}
|
225
|
+
};
|
226
|
+
|
227
|
+
return Namespace;
|
228
|
+
|
229
|
+
})();
|
230
|
+
|
231
|
+
Unit = (function() {
|
232
|
+
Unit.namespace = null;
|
233
|
+
|
234
|
+
Unit.label = null;
|
235
|
+
|
236
|
+
Unit.labelFormat = /^[A-Z][A-Za-z0-9]*$/;
|
237
|
+
|
238
|
+
Unit.config = {};
|
239
|
+
|
240
|
+
Unit._initialize = [];
|
241
|
+
|
242
|
+
Unit._destroy = [];
|
243
|
+
|
244
|
+
Unit.extend = function(options) {
|
245
|
+
var Child, Parent;
|
246
|
+
if (!options.label.match(this.labelFormat)) {
|
247
|
+
throw new Error("" + options.label + " is not a valid name");
|
248
|
+
}
|
249
|
+
Parent = this;
|
250
|
+
Child = (function(_super) {
|
251
|
+
var destroy, initialize;
|
252
|
+
|
253
|
+
__extends(Child, _super);
|
254
|
+
|
255
|
+
function Child() {
|
256
|
+
return Child.__super__.constructor.apply(this, arguments);
|
257
|
+
}
|
258
|
+
|
259
|
+
Child.namespace = options.namespace;
|
260
|
+
|
261
|
+
Child.label = options.label;
|
262
|
+
|
263
|
+
Child.config = _.clone(Child.config);
|
264
|
+
|
265
|
+
if (options.config) {
|
266
|
+
_.extend(Child.config, options.config);
|
267
|
+
}
|
268
|
+
|
269
|
+
if (options.properties) {
|
270
|
+
if (initialize = options.properties._initialize) {
|
271
|
+
Child._initialize = Child._initialize.concat([initialize]);
|
272
|
+
delete options.properties._initialize;
|
273
|
+
}
|
274
|
+
if (destroy = options.properties._destroy) {
|
275
|
+
Child._destroy = [destroy].concat(Child._destroy);
|
276
|
+
delete options.properties._destroy;
|
277
|
+
}
|
278
|
+
_.extend(Child.prototype, options.properties);
|
279
|
+
}
|
280
|
+
|
281
|
+
return Child;
|
282
|
+
|
283
|
+
})(Parent);
|
284
|
+
return options.namespace.addUnit(Child);
|
285
|
+
};
|
286
|
+
|
287
|
+
Unit.configure = function(config) {
|
288
|
+
_.extend(this.config, config);
|
289
|
+
return this.muObject();
|
290
|
+
};
|
291
|
+
|
292
|
+
Unit.fullName = function() {
|
293
|
+
return "" + this.namespace.label + "-" + this.label;
|
294
|
+
};
|
295
|
+
|
296
|
+
function Unit(config) {
|
297
|
+
var initialize, method, name, _i, _len, _ref, _ref1;
|
298
|
+
this.config = config != null ? config : {};
|
299
|
+
if (this.constructor.__super__) {
|
300
|
+
this["super"] = {};
|
301
|
+
_ref = this.constructor.__super__;
|
302
|
+
for (name in _ref) {
|
303
|
+
method = _ref[name];
|
304
|
+
this["super"][name] = _.bind(method, this);
|
305
|
+
}
|
306
|
+
}
|
307
|
+
_.defaults(this.config, this.constructor.config, this.constructor.namespace.config);
|
308
|
+
_ref1 = this.constructor._initialize;
|
309
|
+
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
310
|
+
initialize = _ref1[_i];
|
311
|
+
initialize.call(this);
|
312
|
+
}
|
313
|
+
}
|
314
|
+
|
315
|
+
Unit.prototype.destroy = function() {
|
316
|
+
var destroy, _i, _len, _ref, _results;
|
317
|
+
_ref = this.constructor._destroy;
|
318
|
+
_results = [];
|
319
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
320
|
+
destroy = _ref[_i];
|
321
|
+
_results.push(destroy.call(this));
|
322
|
+
}
|
323
|
+
return _results;
|
324
|
+
};
|
325
|
+
|
326
|
+
return Unit;
|
327
|
+
|
328
|
+
})();
|
329
|
+
|
330
|
+
Component = (function(_super) {
|
331
|
+
__extends(Component, _super);
|
332
|
+
|
333
|
+
Component._modules = {};
|
334
|
+
|
335
|
+
Component.muObject = function(options) {
|
336
|
+
var prototype;
|
337
|
+
prototype = this.prototype;
|
338
|
+
if (prototype instanceof Component) {
|
339
|
+
return {
|
340
|
+
configure: (function(_this) {
|
341
|
+
return function(config) {
|
342
|
+
return _this.configure(config);
|
343
|
+
};
|
344
|
+
})(this),
|
345
|
+
initialize: (function(_this) {
|
346
|
+
return function(el, config) {
|
347
|
+
return _this.initialize(el, config);
|
348
|
+
};
|
349
|
+
})(this),
|
350
|
+
instance: (function(_this) {
|
351
|
+
return function(el) {
|
352
|
+
return _this.instance(el);
|
353
|
+
};
|
354
|
+
})(this),
|
355
|
+
destroy: (function(_this) {
|
356
|
+
return function(el) {
|
357
|
+
return _this.destroy(el);
|
358
|
+
};
|
359
|
+
})(this)
|
360
|
+
};
|
361
|
+
} else {
|
362
|
+
return {
|
363
|
+
extend: (function(_this) {
|
364
|
+
return function(name) {
|
365
|
+
options.extend = options.namespace.factory.component(name);
|
366
|
+
return _this.muObject(options);
|
367
|
+
};
|
368
|
+
})(this),
|
369
|
+
module: (function(_this) {
|
370
|
+
return function(name) {
|
371
|
+
var Module;
|
372
|
+
Module = options.namespace.factory.module(name);
|
373
|
+
if (options.modules) {
|
374
|
+
options.modules.push(Module);
|
375
|
+
} else {
|
376
|
+
options.modules = [Module];
|
377
|
+
}
|
378
|
+
return _this.muObject(options);
|
379
|
+
};
|
380
|
+
})(this),
|
381
|
+
configure: (function(_this) {
|
382
|
+
return function(config) {
|
383
|
+
if (options.config) {
|
384
|
+
_.extend(options.config, config);
|
385
|
+
} else {
|
386
|
+
options.config = config;
|
387
|
+
}
|
388
|
+
return _this.muObject(options);
|
389
|
+
};
|
390
|
+
})(this),
|
391
|
+
create: (function(_this) {
|
392
|
+
return function(properties) {
|
393
|
+
var Parent;
|
394
|
+
options.properties = properties;
|
395
|
+
Parent = options.extend || _this;
|
396
|
+
return Parent.extend(options);
|
397
|
+
};
|
398
|
+
})(this)
|
399
|
+
};
|
400
|
+
}
|
401
|
+
};
|
402
|
+
|
403
|
+
Component.extend = function(options) {
|
404
|
+
var Child, Module, _i, _len, _ref;
|
405
|
+
Child = Component.__super__.constructor.extend.call(this, options);
|
406
|
+
Child._modules = _.clone(Child._modules);
|
407
|
+
if (options.modules) {
|
408
|
+
_ref = options.modules;
|
409
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
410
|
+
Module = _ref[_i];
|
411
|
+
Child.include(Module);
|
412
|
+
}
|
413
|
+
}
|
414
|
+
return Child.muObject();
|
415
|
+
};
|
416
|
+
|
417
|
+
Component.include = function(Module) {
|
418
|
+
this._modules[Module.fullName()] = Module;
|
419
|
+
return Module.included(this);
|
420
|
+
};
|
421
|
+
|
422
|
+
Component.initialize = function(el, config) {
|
423
|
+
var instances;
|
424
|
+
instances = [];
|
425
|
+
$(el).each((function(_this) {
|
426
|
+
return function(i, el) {
|
427
|
+
return instances.push(new _this($(el), config));
|
428
|
+
};
|
429
|
+
})(this));
|
430
|
+
return this._methods(instances);
|
431
|
+
};
|
432
|
+
|
433
|
+
Component.instance = function(el) {
|
434
|
+
var instances;
|
435
|
+
instances = $(el).map((function(_this) {
|
436
|
+
return function(i, el) {
|
437
|
+
return _this._instance($(el));
|
438
|
+
};
|
439
|
+
})(this)).get();
|
440
|
+
return this._methods(instances);
|
441
|
+
};
|
442
|
+
|
443
|
+
Component.destroy = function(el, config) {
|
444
|
+
$(el).each((function(_this) {
|
445
|
+
return function(i, el) {
|
446
|
+
return _this._instance($(el)).destroy();
|
447
|
+
};
|
448
|
+
})(this));
|
449
|
+
return this.muObject();
|
450
|
+
};
|
451
|
+
|
452
|
+
Component._methods = function(instances) {
|
453
|
+
var methodNames, methods, name, prefix, _fn, _i, _len;
|
454
|
+
prefix = this.config.methodPrefix || 'mu';
|
455
|
+
methodNames = _.chain(this.prototype).functions().filter(function(name) {
|
456
|
+
return name.match(new RegExp("^" + prefix + "[A-Z]"));
|
457
|
+
}).value();
|
458
|
+
methods = {};
|
459
|
+
_fn = function(oldName) {
|
460
|
+
var newName;
|
461
|
+
newName = oldName[prefix.length].toLowerCase() + oldName.slice(prefix.length + 1);
|
462
|
+
return methods[newName] = function() {
|
463
|
+
var args, lastResult, results;
|
464
|
+
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
465
|
+
results = _.invoke.apply(_, [instances, oldName].concat(__slice.call(args)));
|
466
|
+
lastResult = _.last(results);
|
467
|
+
if (_.isNull(lastResult)) {
|
468
|
+
return methods;
|
469
|
+
} else {
|
470
|
+
return lastResult;
|
471
|
+
}
|
472
|
+
};
|
473
|
+
};
|
474
|
+
for (_i = 0, _len = methodNames.length; _i < _len; _i++) {
|
475
|
+
name = methodNames[_i];
|
476
|
+
_fn(name);
|
477
|
+
}
|
478
|
+
methods.destroy = (function(_this) {
|
479
|
+
return function() {
|
480
|
+
_.invoke(instances, 'destroy');
|
481
|
+
return _this.muObject();
|
482
|
+
};
|
483
|
+
})(this);
|
484
|
+
return methods;
|
485
|
+
};
|
486
|
+
|
487
|
+
Component._instance = function($el) {
|
488
|
+
var components, instance;
|
489
|
+
components = this.namespace.factory.data($el, 'components') || {};
|
490
|
+
if (!(instance = components[this.fullName()])) {
|
491
|
+
throw new Error('component is not initialized');
|
492
|
+
}
|
493
|
+
return instance;
|
494
|
+
};
|
495
|
+
|
496
|
+
function Component($el, config) {
|
497
|
+
var Module, components, factory, name, _ref;
|
498
|
+
this.$el = $el;
|
499
|
+
factory = this.constructor.namespace.factory;
|
500
|
+
components = factory.data(this.$el, 'components') || {};
|
501
|
+
if (components[this.constructor.fullName()]) {
|
502
|
+
throw new Error('component is already initialized');
|
503
|
+
}
|
504
|
+
components[this.constructor.fullName()] = this;
|
505
|
+
factory.data(this.$el, 'components', components);
|
506
|
+
this._uniqueId = _.uniqueId("component-");
|
507
|
+
this._listeners = $();
|
508
|
+
this._dataFull = $();
|
509
|
+
this._dataNames = [];
|
510
|
+
this._handlers = {};
|
511
|
+
Component.__super__.constructor.call(this, config);
|
512
|
+
this._moduleInstances = {};
|
513
|
+
_ref = this.constructor._modules;
|
514
|
+
for (name in _ref) {
|
515
|
+
Module = _ref[name];
|
516
|
+
this._moduleInstances[name] = new Module(this, this.config);
|
517
|
+
}
|
518
|
+
}
|
519
|
+
|
520
|
+
Component.prototype.destroy = function() {
|
521
|
+
var components, factory, instance, name, _i, _len, _ref, _ref1;
|
522
|
+
_ref = this._moduleInstances;
|
523
|
+
for (name in _ref) {
|
524
|
+
instance = _ref[name];
|
525
|
+
instance.destroy();
|
526
|
+
}
|
527
|
+
Component.__super__.destroy.apply(this, arguments);
|
528
|
+
factory = this.constructor.namespace.factory;
|
529
|
+
this._listeners.off("." + this._uniqueId);
|
530
|
+
_ref1 = this._dataNames;
|
531
|
+
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
532
|
+
name = _ref1[_i];
|
533
|
+
factory.removeData(this._dataFull, name);
|
534
|
+
}
|
535
|
+
components = factory.data(this.$el, 'components');
|
536
|
+
delete components[this.constructor.fullName()];
|
537
|
+
return factory.data(this.$el, 'components', components);
|
538
|
+
};
|
539
|
+
|
540
|
+
Component.prototype.$ = function(el) {
|
541
|
+
return this.$el.find(el);
|
542
|
+
};
|
543
|
+
|
544
|
+
Component.prototype.on = function($el, event, handler) {
|
545
|
+
var handlers, selector, type, _ref;
|
546
|
+
if (arguments.length < 2) {
|
547
|
+
handlers = $el;
|
548
|
+
for (event in handlers) {
|
549
|
+
handler = handlers[event];
|
550
|
+
this.on(event, handler);
|
551
|
+
}
|
552
|
+
return this;
|
553
|
+
} else if (arguments.length < 3) {
|
554
|
+
if (!(_.isString(event) || _.isFunction(event))) {
|
555
|
+
handlers = event;
|
556
|
+
for (event in handlers) {
|
557
|
+
handler = handlers[event];
|
558
|
+
this.on($el, event, handler);
|
559
|
+
}
|
560
|
+
return this;
|
561
|
+
} else {
|
562
|
+
handler = event;
|
563
|
+
event = $el;
|
564
|
+
$el = this.$el;
|
565
|
+
}
|
566
|
+
}
|
567
|
+
if (!($el instanceof $)) {
|
568
|
+
throw new Error('the element provided to on must be a jQuery object');
|
569
|
+
}
|
570
|
+
this._listeners = this._listeners.add($el);
|
571
|
+
_ref = splitOnce(event, ' '), type = _ref[0], selector = _ref[1];
|
572
|
+
type = "" + type + "." + this._uniqueId;
|
573
|
+
if (_.isString(handler)) {
|
574
|
+
handler = this._handler(handler);
|
575
|
+
}
|
576
|
+
if (selector) {
|
577
|
+
$el.on(type, selector, handler);
|
578
|
+
} else {
|
579
|
+
$el.on(type, handler);
|
580
|
+
}
|
581
|
+
return this;
|
582
|
+
};
|
583
|
+
|
584
|
+
Component.prototype.off = function($el, event, handler) {
|
585
|
+
var events, handlers, selector, type, _i, _j, _len, _len1, _ref;
|
586
|
+
if (arguments.length < 1) {
|
587
|
+
$el = this.$el;
|
588
|
+
} else if (arguments.length < 2) {
|
589
|
+
if (_.isArray($el)) {
|
590
|
+
events = $el;
|
591
|
+
for (_i = 0, _len = events.length; _i < _len; _i++) {
|
592
|
+
event = events[_i];
|
593
|
+
this.off(event);
|
594
|
+
}
|
595
|
+
return this;
|
596
|
+
} else if ($.isPlainObject($el)) {
|
597
|
+
handlers = $el;
|
598
|
+
for (event in handlers) {
|
599
|
+
handler = handlers[event];
|
600
|
+
this.off(event, handler);
|
601
|
+
}
|
602
|
+
return this;
|
603
|
+
} else if (_.isString($el)) {
|
604
|
+
event = $el;
|
605
|
+
$el = this.$el;
|
606
|
+
}
|
607
|
+
} else if (arguments.length < 3) {
|
608
|
+
if (_.isArray(event)) {
|
609
|
+
events = event;
|
610
|
+
for (_j = 0, _len1 = events.length; _j < _len1; _j++) {
|
611
|
+
event = events[_j];
|
612
|
+
this.off($el, event);
|
613
|
+
}
|
614
|
+
return this;
|
615
|
+
} else if (_.isObject(event)) {
|
616
|
+
handlers = event;
|
617
|
+
for (event in handlers) {
|
618
|
+
handler = handlers[event];
|
619
|
+
this.off($el, event, handler);
|
620
|
+
}
|
621
|
+
return this;
|
622
|
+
} else if (!($el instanceof $)) {
|
623
|
+
handler = event;
|
624
|
+
event = $el;
|
625
|
+
$el = this.$el;
|
626
|
+
}
|
627
|
+
}
|
628
|
+
if (!($el instanceof $)) {
|
629
|
+
throw new Error('the element provided to off must be a jQuery object');
|
630
|
+
}
|
631
|
+
if (_.isString(handler)) {
|
632
|
+
handler = this._handler(handler);
|
633
|
+
}
|
634
|
+
if (event) {
|
635
|
+
_ref = splitOnce(event, ' '), type = _ref[0], selector = _ref[1];
|
636
|
+
type = "" + type + "." + this._uniqueId;
|
637
|
+
if (selector) {
|
638
|
+
$el.off(type, selector, handler);
|
639
|
+
} else {
|
640
|
+
$el.off(type, handler);
|
641
|
+
}
|
642
|
+
} else {
|
643
|
+
$el.off("." + this._uniqueId);
|
644
|
+
}
|
645
|
+
return this;
|
646
|
+
};
|
647
|
+
|
648
|
+
Component.prototype.trigger = function() {
|
649
|
+
var componentLabel, event, namespaceLabel, params, type;
|
650
|
+
type = arguments[0], params = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
651
|
+
namespaceLabel = this.constructor.namespace.label.toLowerCase();
|
652
|
+
componentLabel = this.constructor.label.toLowerCase();
|
653
|
+
event = "" + namespaceLabel + ":" + componentLabel + ":" + type;
|
654
|
+
return this.$el.trigger(event, params);
|
655
|
+
};
|
656
|
+
|
657
|
+
Component.prototype.data = function($el, name, value) {
|
658
|
+
var factory;
|
659
|
+
if (arguments.length < 3 && _.isString($el)) {
|
660
|
+
value = name;
|
661
|
+
name = $el;
|
662
|
+
$el = this.$el;
|
663
|
+
}
|
664
|
+
if (!($el instanceof $)) {
|
665
|
+
throw new Error('given element to data must be a jQuery object');
|
666
|
+
}
|
667
|
+
factory = this.constructor.namespace.factory;
|
668
|
+
name = this._dataName(name);
|
669
|
+
if (_.isUndefined(value)) {
|
670
|
+
return factory.data($el, name);
|
671
|
+
} else {
|
672
|
+
factory.data($el, name, value);
|
673
|
+
this._dataFull = this._dataFull.add($el);
|
674
|
+
return this._dataNames.push(name);
|
675
|
+
}
|
676
|
+
};
|
677
|
+
|
678
|
+
Component.prototype.removeData = function($el, name) {
|
679
|
+
var factory;
|
680
|
+
if (arguments.length < 2) {
|
681
|
+
name = $el;
|
682
|
+
$el = this.$el;
|
683
|
+
}
|
684
|
+
if (!($el instanceof $)) {
|
685
|
+
throw new Error('given element to removeData must be a jQuery object');
|
686
|
+
}
|
687
|
+
factory = this.constructor.namespace.factory;
|
688
|
+
name = this._dataName(name);
|
689
|
+
return factory.removeData($el, name);
|
690
|
+
};
|
691
|
+
|
692
|
+
Component.prototype._handler = function(name) {
|
693
|
+
if (this._handlers[name]) {
|
694
|
+
return this._handlers[name];
|
695
|
+
} else {
|
696
|
+
return this._handlers[name] = (function(_this) {
|
697
|
+
return function() {
|
698
|
+
var args;
|
699
|
+
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
700
|
+
return _this[name].apply(_this, args);
|
701
|
+
};
|
702
|
+
})(this);
|
703
|
+
}
|
704
|
+
};
|
705
|
+
|
706
|
+
Component.prototype._dataName = function(name) {
|
707
|
+
return "" + this._uniqueId + "-" + name;
|
708
|
+
};
|
709
|
+
|
710
|
+
return Component;
|
711
|
+
|
712
|
+
})(Unit);
|
713
|
+
|
714
|
+
Module = (function(_super) {
|
715
|
+
var delegatedMethods, method, _fn, _i, _len;
|
716
|
+
|
717
|
+
__extends(Module, _super);
|
718
|
+
|
719
|
+
Module._extensions = {};
|
720
|
+
|
721
|
+
Module.muObject = function(options) {
|
722
|
+
var prototype;
|
723
|
+
prototype = this.prototype;
|
724
|
+
if (prototype instanceof Module) {
|
725
|
+
return {
|
726
|
+
configure: (function(_this) {
|
727
|
+
return function(config) {
|
728
|
+
return _this.configure(config);
|
729
|
+
};
|
730
|
+
})(this)
|
731
|
+
};
|
732
|
+
} else {
|
733
|
+
return {
|
734
|
+
configure: (function(_this) {
|
735
|
+
return function(config) {
|
736
|
+
options.config = config;
|
737
|
+
return _this.muObject(options);
|
738
|
+
};
|
739
|
+
})(this),
|
740
|
+
extend: (function(_this) {
|
741
|
+
return function(name) {
|
742
|
+
options.extend = factory.module(name);
|
743
|
+
return _this.muObject(options);
|
744
|
+
};
|
745
|
+
})(this),
|
746
|
+
extensions: (function(_this) {
|
747
|
+
return function(extensions) {
|
748
|
+
options.extensions = extensions;
|
749
|
+
return _this.muObject(options);
|
750
|
+
};
|
751
|
+
})(this),
|
752
|
+
create: (function(_this) {
|
753
|
+
return function(properties) {
|
754
|
+
var Parent;
|
755
|
+
options.properties = properties;
|
756
|
+
Parent = options.extend || _this;
|
757
|
+
return Parent.extend(options);
|
758
|
+
};
|
759
|
+
})(this)
|
760
|
+
};
|
761
|
+
}
|
762
|
+
};
|
763
|
+
|
764
|
+
Module.extend = function(options) {
|
765
|
+
var Child;
|
766
|
+
Child = Module.__super__.constructor.extend.call(this, options);
|
767
|
+
Child._extensions = _.clone(Child._extensions);
|
768
|
+
if (options.extensions) {
|
769
|
+
_.extend(Child._extensions, options.extensions);
|
770
|
+
}
|
771
|
+
return Child.muObject();
|
772
|
+
};
|
773
|
+
|
774
|
+
Module.included = function(Component) {
|
775
|
+
var extension, fullName, name, _ref, _results;
|
776
|
+
fullName = this.fullName();
|
777
|
+
_ref = this._extensions;
|
778
|
+
_results = [];
|
779
|
+
for (name in _ref) {
|
780
|
+
extension = _ref[name];
|
781
|
+
_results.push((function(extension) {
|
782
|
+
return Component.prototype[name] = function() {
|
783
|
+
var args, instance;
|
784
|
+
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
785
|
+
instance = this._moduleInstances[fullName];
|
786
|
+
return extension.apply(instance, args);
|
787
|
+
};
|
788
|
+
})(extension));
|
789
|
+
}
|
790
|
+
return _results;
|
791
|
+
};
|
792
|
+
|
793
|
+
function Module(component, config) {
|
794
|
+
this.component = component;
|
795
|
+
this.$el = this.component.$el;
|
796
|
+
Module.__super__.constructor.call(this, config);
|
797
|
+
}
|
798
|
+
|
799
|
+
delegatedMethods = ['$', 'on', 'off', 'trigger', 'data', 'removeData'];
|
800
|
+
|
801
|
+
_fn = function(name) {
|
802
|
+
return Module.prototype[name] = function() {
|
803
|
+
var args, _ref;
|
804
|
+
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
805
|
+
return (_ref = this.component)[name].apply(_ref, args);
|
806
|
+
};
|
807
|
+
};
|
808
|
+
for (_i = 0, _len = delegatedMethods.length; _i < _len; _i++) {
|
809
|
+
method = delegatedMethods[_i];
|
810
|
+
_fn(method);
|
811
|
+
}
|
812
|
+
|
813
|
+
return Module;
|
814
|
+
|
815
|
+
})(Unit);
|
816
|
+
|
817
|
+
factory = new Factory();
|
818
|
+
|
819
|
+
mu = function(objectName) {
|
820
|
+
var C, M, componentName, currentName, moduleName, names, namespace, namespaceName;
|
821
|
+
if (objectName == null) {
|
822
|
+
objectName = '';
|
823
|
+
}
|
824
|
+
names = objectName.split('.');
|
825
|
+
currentName = names.shift();
|
826
|
+
switch (currentName) {
|
827
|
+
case 'components':
|
828
|
+
case 'modules':
|
829
|
+
case '':
|
830
|
+
namespaceName = factory.config.defaultNamespace;
|
831
|
+
break;
|
832
|
+
default:
|
833
|
+
if (currentName.match(Unit.labelFormat)) {
|
834
|
+
namespaceName = factory.config.defaultNamespace;
|
835
|
+
} else {
|
836
|
+
namespaceName = currentName;
|
837
|
+
currentName = names.shift();
|
838
|
+
}
|
839
|
+
}
|
840
|
+
if (!(namespace = factory.namespace(namespaceName, true))) {
|
841
|
+
namespace = factory.createNamespace(namespaceName);
|
842
|
+
}
|
843
|
+
if (!currentName) {
|
844
|
+
return namespace.muObject();
|
845
|
+
}
|
846
|
+
switch (currentName) {
|
847
|
+
case 'components':
|
848
|
+
componentName = names.shift();
|
849
|
+
if (C = namespace.component(componentName, true)) {
|
850
|
+
return C.muObject();
|
851
|
+
} else {
|
852
|
+
return Component.muObject({
|
853
|
+
namespace: namespace,
|
854
|
+
label: componentName
|
855
|
+
});
|
856
|
+
}
|
857
|
+
break;
|
858
|
+
case 'modules':
|
859
|
+
moduleName = names.shift();
|
860
|
+
if (M = namespace.module(moduleName, true)) {
|
861
|
+
return M.muObject();
|
862
|
+
} else {
|
863
|
+
return Module.muObject({
|
864
|
+
namespace: namespace,
|
865
|
+
label: moduleName
|
866
|
+
});
|
867
|
+
}
|
868
|
+
break;
|
869
|
+
default:
|
870
|
+
if (C = namespace.component(currentName, true)) {
|
871
|
+
return C.muObject();
|
872
|
+
} else if (M = namespace.module(currentName, true)) {
|
873
|
+
return M.muObject();
|
874
|
+
} else {
|
875
|
+
return Component.muObject({
|
876
|
+
namespace: namespace,
|
877
|
+
label: currentName
|
878
|
+
});
|
879
|
+
}
|
880
|
+
}
|
881
|
+
};
|
882
|
+
|
883
|
+
delegatedMethods = ['configure', 'setup', 'initialize', 'destroy', 'clean'];
|
884
|
+
|
885
|
+
_fn = function(name) {
|
886
|
+
return mu[name] = function() {
|
887
|
+
var args;
|
888
|
+
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
889
|
+
return factory[name].apply(factory, args);
|
890
|
+
};
|
891
|
+
};
|
892
|
+
for (_i = 0, _len = delegatedMethods.length; _i < _len; _i++) {
|
893
|
+
method = delegatedMethods[_i];
|
894
|
+
_fn(method);
|
895
|
+
}
|
896
|
+
|
897
|
+
window.Micro = window.mu = mu;
|
898
|
+
|
899
|
+
}).call(this);
|