joosy 1.2.0.alpha.41 → 1.2.0.alpha.51

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/Gruntfile.coffee +27 -7
  4. data/bin/joosy +1 -1
  5. data/bower.json +3 -2
  6. data/build/joosy/extensions/preloaders.js +189 -0
  7. data/build/joosy/extensions/resources-form.js +588 -0
  8. data/build/joosy/extensions/resources.js +673 -0
  9. data/build/joosy.js +2395 -0
  10. data/{src/joosy/generators → generators}/base.coffee +2 -2
  11. data/{src/joosy/generators → generators/command}/command.coffee +16 -3
  12. data/generators/command/help.coffee +38 -0
  13. data/{src/joosy/generators → generators}/layout.coffee +0 -0
  14. data/{src/joosy/generators → generators}/page.coffee +0 -0
  15. data/{src/joosy/generators → generators}/project/base.coffee +2 -4
  16. data/{src/joosy/generators → generators}/project/standalone.coffee +4 -3
  17. data/{src/joosy/generators → generators}/project.coffee +0 -0
  18. data/generators/templates/application/base/application.coffee +13 -0
  19. data/{templates → generators/templates}/application/base/helpers/application.coffee +0 -0
  20. data/{templates → generators/templates}/application/base/layouts/application.coffee +0 -0
  21. data/{templates → generators/templates}/application/base/pages/application.coffee +0 -0
  22. data/{templates → generators/templates}/application/base/pages/welcome/index.coffee +0 -0
  23. data/{templates → generators/templates}/application/base/routes.coffee +0 -0
  24. data/{templates → generators/templates}/application/base/templates/layouts/application.jst.hamlc +0 -0
  25. data/{templates → generators/templates}/application/base/templates/pages/welcome/index.jst.hamlc +0 -0
  26. data/{templates → generators/templates}/application/standalone/Gruntfile.coffee +1 -0
  27. data/{templates → generators/templates}/application/standalone/Procfile +0 -0
  28. data/{templates → generators/templates}/application/standalone/_gitignore +0 -0
  29. data/generators/templates/application/standalone/bower.json +17 -0
  30. data/{templates → generators/templates}/application/standalone/package.json +0 -0
  31. data/{templates → generators/templates}/application/standalone/source/haml/index.haml +0 -0
  32. data/{templates → generators/templates}/application/standalone/source/stylesheets/application.styl +0 -0
  33. data/{templates → generators/templates}/layout/basic.coffee +0 -0
  34. data/{templates → generators/templates}/layout/namespaced.coffee +0 -0
  35. data/{templates → generators/templates}/page/basic.coffee +0 -0
  36. data/{templates → generators/templates}/page/namespaced.coffee +0 -0
  37. data/{templates → generators/templates}/widget/basic.coffee +0 -0
  38. data/{templates → generators/templates}/widget/namespaced.coffee +0 -0
  39. data/{src/joosy/generators → generators}/widget.coffee +0 -0
  40. data/lib/joosy.rb +3 -3
  41. data/package.json +2 -3
  42. data/source/joosy/application.coffee +95 -0
  43. data/source/joosy/events/namespace.coffee +24 -0
  44. data/{src → source}/joosy/extensions/preloaders/caching.coffee +0 -0
  45. data/{src → source}/joosy/extensions/preloaders/index.coffee +0 -0
  46. data/{src → source}/joosy/extensions/preloaders/inline.coffee +0 -0
  47. data/{src → source}/joosy/extensions/resources/base.coffee +16 -8
  48. data/{src → source}/joosy/extensions/resources/collection.coffee +0 -0
  49. data/{src → source}/joosy/extensions/resources/index.coffee +0 -0
  50. data/{src → source}/joosy/extensions/resources/rest.coffee +0 -0
  51. data/{src → source}/joosy/extensions/resources/rest_collection.coffee +0 -0
  52. data/{src → source}/joosy/extensions/resources-form/form.coffee +18 -18
  53. data/{src → source}/joosy/extensions/resources-form/helpers/form.coffee +6 -6
  54. data/{src → source}/joosy/extensions/resources-form/index.coffee +0 -0
  55. data/source/joosy/helpers/routes.coffee +10 -0
  56. data/source/joosy/helpers/view.coffee +115 -0
  57. data/{src/joosy/core → source/joosy}/helpers/widgets.coffee +1 -1
  58. data/{src/joosy/core → source/joosy}/joosy.coffee +59 -19
  59. data/source/joosy/layout.coffee +73 -0
  60. data/{src/joosy/core → source/joosy}/module.coffee +7 -2
  61. data/{src/joosy/core/modules/container.coffee → source/joosy/modules/dom.coffee} +24 -17
  62. data/source/joosy/modules/events.coffee +156 -0
  63. data/source/joosy/modules/filters.coffee +67 -0
  64. data/{src/joosy/core → source/joosy}/modules/log.coffee +7 -3
  65. data/source/joosy/modules/page/scrolling.coffee +51 -0
  66. data/source/joosy/modules/page/title.coffee +18 -0
  67. data/{src/joosy/core → source/joosy}/modules/renderer.coffee +12 -13
  68. data/{src/joosy/core → source/joosy}/modules/time_manager.coffee +5 -1
  69. data/{src/joosy/core → source/joosy}/modules/widgets_manager.coffee +9 -5
  70. data/source/joosy/page.coffee +68 -0
  71. data/{src/joosy/core → source/joosy}/resources/watcher.coffee +5 -1
  72. data/source/joosy/router.coffee +305 -0
  73. data/{src/joosy/core → source/joosy}/templaters/jst.coffee +10 -7
  74. data/source/joosy/widget.coffee +385 -0
  75. data/source/joosy.coffee +1 -0
  76. data/{src/vendor → source}/metamorph.coffee +0 -0
  77. data/spec/helpers/matchers.coffee +8 -1
  78. data/spec/joosy/core/application_spec.coffee +121 -20
  79. data/spec/joosy/core/helpers/view_spec.coffee +3 -3
  80. data/spec/joosy/core/helpers/widgets_spec.coffee +3 -6
  81. data/spec/joosy/core/joosy_spec.coffee +0 -5
  82. data/spec/joosy/core/layout_spec.coffee +2 -28
  83. data/spec/joosy/core/modules/dom_spec.coffee +133 -0
  84. data/spec/joosy/core/modules/events_spec.coffee +16 -9
  85. data/spec/joosy/core/modules/filters_spec.coffee +232 -89
  86. data/spec/joosy/core/modules/log_spec.coffee +2 -2
  87. data/spec/joosy/core/modules/renderer_spec.coffee +8 -4
  88. data/spec/joosy/core/page_spec.coffee +2 -201
  89. data/spec/joosy/core/router_spec.coffee +295 -233
  90. data/spec/joosy/core/templaters/jst_spec.coffee +1 -1
  91. data/spec/joosy/core/widget_spec.coffee +373 -34
  92. data/spec/joosy/environments/amd_spec.coffee +38 -0
  93. data/spec/joosy/environments/global_spec.coffee +21 -0
  94. data/spec/joosy/extensions/form/form_spec.coffee +18 -18
  95. data/spec/joosy/extensions/form/helpers/forms_spec.coffee +1 -1
  96. data/spec/joosy/extensions/resources/base_spec.coffee +23 -11
  97. data/tasks/joosy.coffee +6 -9
  98. metadata +75 -69
  99. data/lib/extensions/preloaders.js +0 -193
  100. data/lib/extensions/resources-form.js +0 -592
  101. data/lib/extensions/resources.js +0 -675
  102. data/lib/joosy.js +0 -2199
  103. data/spec/joosy/core/modules/container_spec.coffee +0 -153
  104. data/spec/joosy/core/modules/widget_manager_spec.coffee +0 -96
  105. data/src/joosy/core/application.coffee +0 -59
  106. data/src/joosy/core/helpers/view.coffee +0 -52
  107. data/src/joosy/core/layout.coffee +0 -174
  108. data/src/joosy/core/modules/events.coffee +0 -188
  109. data/src/joosy/core/modules/filters.coffee +0 -42
  110. data/src/joosy/core/page.coffee +0 -383
  111. data/src/joosy/core/router.coffee +0 -313
  112. data/src/joosy/core/widget.coffee +0 -88
  113. data/src/joosy.coffee +0 -1
  114. data/templates/application/base/application.coffee +0 -9
  115. data/templates/application/standalone/bower.json +0 -7
data/lib/joosy.js DELETED
@@ -1,2199 +0,0 @@
1
-
2
-
3
- /*** src/joosy/core/joosy ***/
4
-
5
- this.Joosy = {
6
- Modules: {},
7
- Resources: {},
8
- Templaters: {},
9
- namespace: function(name, generator) {
10
- var key, klass, part, space, _i, _len, _results;
11
- if (generator == null) {
12
- generator = false;
13
- }
14
- name = name.split('.');
15
- space = window;
16
- for (_i = 0, _len = name.length; _i < _len; _i++) {
17
- part = name[_i];
18
- if (part.length > 0) {
19
- space = space[part] != null ? space[part] : space[part] = {};
20
- }
21
- }
22
- if (generator) {
23
- generator = generator.apply(space);
24
- }
25
- _results = [];
26
- for (key in space) {
27
- klass = space[key];
28
- if (space.hasOwnProperty(key) && Joosy.Module.hasAncestor(klass, Joosy.Module)) {
29
- _results.push(klass.__namespace__ = name);
30
- } else {
31
- _results.push(void 0);
32
- }
33
- }
34
- return _results;
35
- },
36
- helpers: function(name, generator) {
37
- return Joosy.namespace("Joosy.Helpers." + name, generator);
38
- },
39
- synchronize: function() {
40
- var _ref;
41
- if (!Joosy.Modules.Events) {
42
- return console.error("Events module is required to use `Joosy.synchronize'!");
43
- } else {
44
- return (_ref = Joosy.Modules.Events).synchronize.apply(_ref, arguments);
45
- }
46
- },
47
- uid: function() {
48
- this.__uid || (this.__uid = 0);
49
- return "__joosy" + (this.__uid++);
50
- },
51
- uuid: function() {
52
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
53
- var r, v;
54
- r = Math.random() * 16 | 0;
55
- v = c === 'x' ? r : r & 3 | 8;
56
- return v.toString(16);
57
- }).toUpperCase();
58
- },
59
- buildUrl: function(url, params) {
60
- var hash, paramsString;
61
- paramsString = [];
62
- Object.each(params, function(key, value) {
63
- return paramsString.push("" + key + "=" + value);
64
- });
65
- hash = url.match(/(\#.*)?$/)[0];
66
- url = url.replace(/\#.*$/, '');
67
- if (!paramsString.isEmpty() && !url.has(/\?/)) {
68
- url = url + "?";
69
- }
70
- paramsString = paramsString.join('&');
71
- if (!paramsString.isBlank() && url.last() !== '?') {
72
- paramsString = '&' + paramsString;
73
- }
74
- return url + paramsString + hash;
75
- }
76
- };
77
-
78
-
79
- /*** src/joosy/core/module ***/
80
-
81
- this.Joosy.Module = (function() {
82
- function Module() {}
83
-
84
- Module.__namespace__ = [];
85
-
86
- Module.__className = function(klass) {
87
- if (!Object.isFunction(klass)) {
88
- klass = klass.constructor;
89
- }
90
- if (klass.name != null) {
91
- return klass.name;
92
- } else {
93
- return klass.toString().replace(/^function ([a-zA-Z]+)\([\s\S]+/, '$1');
94
- }
95
- };
96
-
97
- Module.hasAncestor = function(what, klass) {
98
- var _ref, _ref1;
99
- if (!((what != null) && (klass != null))) {
100
- return false;
101
- }
102
- _ref = [what.prototype, klass.prototype], what = _ref[0], klass = _ref[1];
103
- while (what) {
104
- if (what === klass) {
105
- return true;
106
- }
107
- what = (_ref1 = what.constructor) != null ? _ref1.__super__ : void 0;
108
- }
109
- return false;
110
- };
111
-
112
- Module.aliasMethodChain = function(method, feature, action) {
113
- var camelized, chained;
114
- camelized = feature.charAt(0).toUpperCase() + feature.slice(1);
115
- chained = "" + method + "Without" + camelized;
116
- if (!Object.isFunction(action)) {
117
- action = this.prototype[action];
118
- }
119
- this.prototype[chained] = this.prototype[method];
120
- return this.prototype[method] = action;
121
- };
122
-
123
- Module.aliasStaticMethodChain = function(method, feature, action) {
124
- var camelized, chained;
125
- camelized = feature.charAt(0).toUpperCase() + feature.slice(1);
126
- chained = "" + method + "Without" + camelized;
127
- this[chained] = this[method];
128
- return this[method] = action;
129
- };
130
-
131
- Module.merge = function(destination, source, unsafe) {
132
- var key, value;
133
- if (unsafe == null) {
134
- unsafe = true;
135
- }
136
- for (key in source) {
137
- value = source[key];
138
- if (source.hasOwnProperty(key)) {
139
- if (unsafe || !destination.hasOwnProperty(key)) {
140
- destination[key] = value;
141
- }
142
- }
143
- }
144
- return destination;
145
- };
146
-
147
- Module.include = function(object) {
148
- var key, value, _ref;
149
- if (!object) {
150
- throw new Error('include(object) requires obj');
151
- }
152
- for (key in object) {
153
- value = object[key];
154
- if (key !== 'included' && key !== 'extended') {
155
- this.prototype[key] = value;
156
- }
157
- }
158
- if ((_ref = object.included) != null) {
159
- _ref.apply(this);
160
- }
161
- return null;
162
- };
163
-
164
- Module.extend = function(object) {
165
- var _ref;
166
- if (!object) {
167
- throw new Error('extend(object) requires object');
168
- }
169
- this.merge(this, object);
170
- if ((_ref = object.extended) != null) {
171
- _ref.apply(this);
172
- }
173
- return null;
174
- };
175
-
176
- return Module;
177
-
178
- })();
179
-
180
-
181
- /*** src/joosy/core/application ***/
182
-
183
- Joosy.Application = {
184
- Pages: {},
185
- Layouts: {},
186
- Controls: {},
187
- loading: true,
188
- identity: true,
189
- debounceForms: false,
190
- config: {
191
- debug: false,
192
- router: {
193
- html5: false,
194
- base: '/'
195
- }
196
- },
197
- initialize: function(name, selector, options) {
198
- this.name = name;
199
- this.selector = selector;
200
- if (options == null) {
201
- options = {};
202
- }
203
- if (window.JoosyEnvironment != null) {
204
- this.mergeConfig(window.JoosyEnvironment);
205
- }
206
- this.mergeConfig(options);
207
- this.templater = new Joosy.Templaters.JST(this.name);
208
- return Joosy.Router.__setupRoutes();
209
- },
210
- content: function() {
211
- return $(this.selector);
212
- },
213
- setCurrentPage: function(page, params) {
214
- var attempt;
215
- attempt = new page(params, this.page);
216
- if (!attempt.halted) {
217
- return this.page = attempt;
218
- }
219
- },
220
- mergeConfig: function(options) {
221
- var key, value, _results;
222
- _results = [];
223
- for (key in options) {
224
- value = options[key];
225
- if (Object.isObject(this.config[key])) {
226
- _results.push(Object.merge(this.config[key], value));
227
- } else {
228
- _results.push(this.config[key] = value);
229
- }
230
- }
231
- return _results;
232
- }
233
- };
234
-
235
-
236
- /*** src/joosy/core/helpers/view ***/
237
-
238
- Joosy.helpers('Application', function() {
239
- this.tag = function(name, options, content) {
240
- var e, element, temp;
241
- if (options == null) {
242
- options = {};
243
- }
244
- if (content == null) {
245
- content = '';
246
- }
247
- if (Object.isFunction(content)) {
248
- content = content();
249
- }
250
- element = document.createElement(name);
251
- temp = document.createElement('div');
252
- Object.each(options, function(name, value) {
253
- return element.setAttribute(name, value);
254
- });
255
- try {
256
- element.innerHTML = content;
257
- } catch (_error) {
258
- e = _error;
259
- if (content) {
260
- throw e;
261
- }
262
- }
263
- temp.appendChild(element);
264
- return temp.innerHTML;
265
- };
266
- return this.renderWrapped = function(template, lambda) {
267
- return this.render(template, Joosy.Module.merge(this, {
268
- "yield": lambda()
269
- }));
270
- };
271
- });
272
-
273
-
274
- /*** src/joosy/core/helpers/widgets ***/
275
-
276
- Joosy.helpers('Application', function() {
277
- return this.widget = function(tag, options, widget) {
278
- var _this = this;
279
- if (widget == null) {
280
- widget = options;
281
- options = {};
282
- }
283
- options.id = Joosy.uid();
284
- this.__renderer.setTimeout(0, function() {
285
- return _this.__renderer.registerWidget($('#' + options.id), widget);
286
- });
287
- return this.tag(tag, options);
288
- };
289
- });
290
-
291
-
292
- /*** src/joosy/core/modules/log ***/
293
-
294
- var __slice = [].slice;
295
-
296
- Joosy.Modules.Log = {
297
- log: function() {
298
- var args;
299
- args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
300
- if (typeof console === "undefined" || console === null) {
301
- return;
302
- }
303
- if (console.log.apply != null) {
304
- args.unshift("Joosy>");
305
- return console.log.apply(console, args);
306
- } else {
307
- return console.log(args.first());
308
- }
309
- },
310
- debug: function() {
311
- var args;
312
- args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
313
- if (!Joosy.Application.config.debug) {
314
- return;
315
- }
316
- return this.log.apply(this, args);
317
- },
318
- debugAs: function() {
319
- var args, context, string;
320
- context = arguments[0], string = arguments[1], args = 3 <= arguments.length ? __slice.call(arguments, 2) : [];
321
- if (!Joosy.Application.config.debug) {
322
- return;
323
- }
324
- context = Joosy.Module.__className(context) || 'unknown context';
325
- return this.debug.apply(this, ["" + context + "> " + string].concat(__slice.call(args)));
326
- }
327
- };
328
-
329
-
330
- /*** src/joosy/core/modules/events ***/
331
-
332
- var __slice = [].slice;
333
-
334
- Joosy.Modules.Events = {
335
- wait: function(name, events, callback) {
336
- this.__oneShotEvents || (this.__oneShotEvents = {});
337
- if (Object.isFunction(events)) {
338
- callback = events;
339
- events = name;
340
- name = Object.keys(this.__oneShotEvents).length.toString();
341
- }
342
- this.__oneShotEvents[name] = [this.__splitEvents(events), callback];
343
- return name;
344
- },
345
- unwait: function(target) {
346
- return delete this.__oneShotEvents[target];
347
- },
348
- bind: function(name, events, callback) {
349
- this.__boundEvents || (this.__boundEvents = {});
350
- if (Object.isFunction(events)) {
351
- callback = events;
352
- events = name;
353
- name = Object.keys(this.__boundEvents).length.toString();
354
- }
355
- this.__boundEvents[name] = [this.__splitEvents(events), callback];
356
- return name;
357
- },
358
- unbind: function(target) {
359
- return delete this.__boundEvents[target];
360
- },
361
- trigger: function() {
362
- var callback, data, event, events, fire, name, _ref, _ref1, _ref2, _ref3, _results,
363
- _this = this;
364
- event = arguments[0], data = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
365
- Joosy.Modules.Log.debugAs(this, "Event " + event + " triggered");
366
- if (this.__oneShotEvents) {
367
- fire = [];
368
- _ref = this.__oneShotEvents;
369
- for (name in _ref) {
370
- _ref1 = _ref[name], events = _ref1[0], callback = _ref1[1];
371
- events.remove(event);
372
- if (events.length === 0) {
373
- fire.push(name);
374
- }
375
- }
376
- fire.each(function(name) {
377
- callback = _this.__oneShotEvents[name][1];
378
- delete _this.__oneShotEvents[name];
379
- return callback.apply(null, data);
380
- });
381
- }
382
- if (this.__boundEvents) {
383
- _ref2 = this.__boundEvents;
384
- _results = [];
385
- for (name in _ref2) {
386
- _ref3 = _ref2[name], events = _ref3[0], callback = _ref3[1];
387
- if (events.any(event)) {
388
- _results.push(callback.apply(null, data));
389
- } else {
390
- _results.push(void 0);
391
- }
392
- }
393
- return _results;
394
- }
395
- },
396
- synchronize: function(block) {
397
- var context,
398
- _this = this;
399
- context = new Joosy.Events.SynchronizationContext(this);
400
- block.call(this, context);
401
- if (context.expectations.length === 0) {
402
- return context.after.call(this);
403
- } else {
404
- this.wait(context.expectations, function() {
405
- return context.after.call(_this);
406
- });
407
- return context.actions.each(function(data) {
408
- return data[0].call(_this, function() {
409
- return _this.trigger(data[1]);
410
- });
411
- });
412
- }
413
- },
414
- __splitEvents: function(events) {
415
- if (Object.isString(events)) {
416
- if (events.isBlank()) {
417
- events = [];
418
- } else {
419
- events = events.trim().split(/\s+/);
420
- }
421
- }
422
- if (!(Object.isArray(events) && events.length > 0)) {
423
- throw new Error("" + (Joosy.Module.__className(this)) + "> bind invalid events: " + events);
424
- }
425
- return events;
426
- }
427
- };
428
-
429
- Joosy.namespace('Joosy.Events', function() {
430
- this.Namespace = (function() {
431
- function Namespace(parent) {
432
- this.parent = parent;
433
- this.bindings = [];
434
- }
435
-
436
- Namespace.prototype.bind = function() {
437
- var args, _ref;
438
- args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
439
- return this.bindings.push((_ref = this.parent).bind.apply(_ref, args));
440
- };
441
-
442
- Namespace.prototype.unbind = function() {
443
- var b, _i, _len, _ref;
444
- _ref = this.bindings;
445
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
446
- b = _ref[_i];
447
- this.parent.unbind(b);
448
- }
449
- return this.bindings = [];
450
- };
451
-
452
- return Namespace;
453
-
454
- })();
455
- return this.SynchronizationContext = (function() {
456
- SynchronizationContext.uid = 0;
457
-
458
- function SynchronizationContext(parent) {
459
- this.parent = parent;
460
- this.expectations = [];
461
- this.actions = [];
462
- }
463
-
464
- SynchronizationContext.prototype.uid = function() {
465
- return this.constructor.uid += 1;
466
- };
467
-
468
- SynchronizationContext.prototype["do"] = function(action) {
469
- var event;
470
- event = "synchro-" + (this.uid());
471
- this.expectations.push(event);
472
- return this.actions.push([action, event]);
473
- };
474
-
475
- SynchronizationContext.prototype.after = function(after) {
476
- this.after = after;
477
- };
478
-
479
- return SynchronizationContext;
480
-
481
- })();
482
- });
483
-
484
-
485
- /*** src/joosy/core/modules/container ***/
486
-
487
- Joosy.Modules.Container = {
488
- eventSplitter: /^(\S+)\s*(.*)$/,
489
- included: function() {
490
- this.mapElements = function(map) {
491
- if (!this.prototype.hasOwnProperty("__elements")) {
492
- this.prototype.__elements = Object.clone(this.__super__.__elements) || {};
493
- }
494
- return Object.merge(this.prototype.__elements, map);
495
- };
496
- return this.mapEvents = function(map) {
497
- if (!this.prototype.hasOwnProperty("__events")) {
498
- this.prototype.__events = Object.clone(this.__super__.__events) || {};
499
- }
500
- return Object.merge(this.prototype.__events, map);
501
- };
502
- },
503
- $: function(selector) {
504
- return $(selector, this.container);
505
- },
506
- swapContainer: function(container, data) {
507
- container.unbind().off();
508
- container.html(data);
509
- return container;
510
- },
511
- __extractSelector: function(selector) {
512
- var _this = this;
513
- selector = selector.replace(/(\$[A-z0-9\.\$]+)/g, function(path) {
514
- var keyword, part, target, _i, _len, _ref;
515
- path = path.split('.');
516
- keyword = path.pop();
517
- target = _this;
518
- for (_i = 0, _len = path.length; _i < _len; _i++) {
519
- part = path[_i];
520
- target = target != null ? target[part] : void 0;
521
- }
522
- return target != null ? (_ref = target[keyword]) != null ? _ref.selector : void 0 : void 0;
523
- });
524
- return selector.trim();
525
- },
526
- __assignElements: function(root, entries) {
527
- var key, value, _results;
528
- root || (root = this);
529
- entries || (entries = this.__elements);
530
- if (!entries) {
531
- return;
532
- }
533
- _results = [];
534
- for (key in entries) {
535
- value = entries[key];
536
- if (Object.isObject(value)) {
537
- _results.push(this.__assignElements(root['$' + key] = {}, value));
538
- } else {
539
- value = this.__extractSelector(value);
540
- root['$' + key] = this.__wrapElement(value);
541
- _results.push(root['$' + key].selector = value);
542
- }
543
- }
544
- return _results;
545
- },
546
- __wrapElement: function(value) {
547
- var _this = this;
548
- return function(filter) {
549
- if (!filter) {
550
- return _this.$(value);
551
- }
552
- return _this.$(value).filter(filter);
553
- };
554
- },
555
- __delegateEvents: function() {
556
- var events, module,
557
- _this = this;
558
- module = this;
559
- events = this.__events;
560
- if (!events) {
561
- return;
562
- }
563
- return Object.each(events, function(key, method) {
564
- var callback, eventName, match, selector;
565
- if (!Object.isFunction(method)) {
566
- method = _this[method];
567
- }
568
- callback = function(event) {
569
- return method.call(module, $(this), event);
570
- };
571
- match = key.match(_this.eventSplitter);
572
- eventName = match[1];
573
- selector = _this.__extractSelector(match[2]);
574
- if (selector === "") {
575
- _this.container.bind(eventName, callback);
576
- return Joosy.Modules.Log.debugAs(_this, "" + eventName + " binded on container");
577
- } else if (selector === void 0) {
578
- throw new Error("Unknown element " + match[2] + " in " + (Joosy.Module.__className(_this.constructor)) + " (maybe typo?)");
579
- } else {
580
- _this.container.on(eventName, selector, callback);
581
- return Joosy.Modules.Log.debugAs(_this, "" + eventName + " binded on " + selector);
582
- }
583
- });
584
- }
585
- };
586
-
587
-
588
- /*** src/joosy/core/templaters/jst ***/
589
-
590
- Joosy.Templaters.JST = (function() {
591
- function JST(applicationName) {
592
- if (Object.isString(applicationName) && applicationName.length > 0) {
593
- this.applicationName = applicationName;
594
- }
595
- }
596
-
597
- JST.prototype.buildView = function(name) {
598
- var haystack, path, template, _i, _len;
599
- template = false;
600
- if (this.applicationName) {
601
- haystack = ["" + this.applicationName + "/templates/" + name + "-" + (typeof I18n !== "undefined" && I18n !== null ? I18n.locale : void 0), "" + this.applicationName + "/templates/" + name];
602
- } else {
603
- haystack = ["templates/" + name + "-" + (typeof I18n !== "undefined" && I18n !== null ? I18n.locale : void 0), "templates/" + name];
604
- }
605
- for (_i = 0, _len = haystack.length; _i < _len; _i++) {
606
- path = haystack[_i];
607
- if (window.JST[path]) {
608
- return window.JST[path];
609
- }
610
- }
611
- throw new Error("Template '" + name + "' not found. Checked at: '" + (haystack.join(', ')) + "'");
612
- };
613
-
614
- JST.prototype.resolveTemplate = function(section, template, entity) {
615
- var path, _ref, _ref1;
616
- if (template.startsWith('/')) {
617
- return template.substr(1);
618
- }
619
- path = ((_ref = entity.constructor) != null ? (_ref1 = _ref.__namespace__) != null ? _ref1.map('underscore') : void 0 : void 0) || [];
620
- path.unshift(section);
621
- return "" + (path.join('/')) + "/" + template;
622
- };
623
-
624
- return JST;
625
-
626
- })();
627
-
628
-
629
- /*** src/vendor/metamorph ***/
630
-
631
- (function(window) {
632
- var K, Metamorph, afterFunc, appendToFunc, document, endTagFunc, findChildById, firstNodeFor, fixParentage, guid, htmlFunc, movesWhitespace, needsShy, outerHTMLFunc, prependFunc, rangeFor, realNode, removeFunc, setInnerHTML, startTagFunc, supportsRange, wrapMap;
633
- K = function() {};
634
- guid = 0;
635
- document = window.document;
636
- supportsRange = document && ("createRange" in document) && (typeof Range !== "undefined") && Range.prototype.createContextualFragment;
637
- needsShy = document && (function() {
638
- var testEl;
639
- testEl = document.createElement("div");
640
- testEl.innerHTML = "<div></div>";
641
- testEl.firstChild.innerHTML = "<script></script>";
642
- return testEl.firstChild.innerHTML === "";
643
- })();
644
- movesWhitespace = document && (function() {
645
- var testEl;
646
- testEl = document.createElement("div");
647
- testEl.innerHTML = "Test: <script type='text/x-placeholder'></script>Value";
648
- return testEl.childNodes[0].nodeValue === "Test:" && testEl.childNodes[2].nodeValue === " Value";
649
- })();
650
- Metamorph = function(html) {
651
- var myGuid, self;
652
- self = void 0;
653
- if (this instanceof Metamorph) {
654
- self = this;
655
- } else {
656
- self = new K();
657
- }
658
- self.innerHTML = html;
659
- myGuid = "metamorph-" + (guid++);
660
- self.start = myGuid + "-start";
661
- self.end = myGuid + "-end";
662
- return self;
663
- };
664
- K.prototype = Metamorph.prototype;
665
- rangeFor = void 0;
666
- htmlFunc = void 0;
667
- removeFunc = void 0;
668
- outerHTMLFunc = void 0;
669
- appendToFunc = void 0;
670
- afterFunc = void 0;
671
- prependFunc = void 0;
672
- startTagFunc = void 0;
673
- endTagFunc = void 0;
674
- outerHTMLFunc = function() {
675
- return this.startTag() + this.innerHTML + this.endTag();
676
- };
677
- startTagFunc = function() {
678
- return "<script id='" + this.start + "' type='text/x-placeholder'></script>";
679
- };
680
- endTagFunc = function() {
681
- return "<script id='" + this.end + "' type='text/x-placeholder'></script>";
682
- };
683
- if (supportsRange) {
684
- rangeFor = function(morph, outerToo) {
685
- var after, before, range;
686
- range = document.createRange();
687
- before = document.getElementById(morph.start);
688
- after = document.getElementById(morph.end);
689
- if (outerToo) {
690
- range.setStartBefore(before);
691
- range.setEndAfter(after);
692
- } else {
693
- range.setStartAfter(before);
694
- range.setEndBefore(after);
695
- }
696
- return range;
697
- };
698
- htmlFunc = function(html, outerToo) {
699
- var fragment, range;
700
- range = rangeFor(this, outerToo);
701
- range.deleteContents();
702
- fragment = range.createContextualFragment(html);
703
- return range.insertNode(fragment);
704
- };
705
- removeFunc = function() {
706
- var range;
707
- range = rangeFor(this, true);
708
- return range.deleteContents();
709
- };
710
- appendToFunc = function(node) {
711
- var frag, range;
712
- range = document.createRange();
713
- range.setStart(node);
714
- range.collapse(false);
715
- frag = range.createContextualFragment(this.outerHTML());
716
- return node.appendChild(frag);
717
- };
718
- afterFunc = function(html) {
719
- var after, fragment, range;
720
- range = document.createRange();
721
- after = document.getElementById(this.end);
722
- range.setStartAfter(after);
723
- range.setEndAfter(after);
724
- fragment = range.createContextualFragment(html);
725
- return range.insertNode(fragment);
726
- };
727
- prependFunc = function(html) {
728
- var fragment, range, start;
729
- range = document.createRange();
730
- start = document.getElementById(this.start);
731
- range.setStartAfter(start);
732
- range.setEndAfter(start);
733
- fragment = range.createContextualFragment(html);
734
- return range.insertNode(fragment);
735
- };
736
- } else {
737
- /*
738
- This code is mostly taken from jQuery, with one exception. In jQuery's case, we
739
- have some HTML and we need to figure out how to convert it into some nodes.
740
-
741
- In this case, jQuery needs to scan the HTML looking for an opening tag and use
742
- that as the key for the wrap map. In our case, we know the parent node, and
743
- can use its type as the key for the wrap map.
744
- */
745
-
746
- wrapMap = {
747
- select: [1, "<select multiple='multiple'>", "</select>"],
748
- fieldset: [1, "<fieldset>", "</fieldset>"],
749
- table: [1, "<table>", "</table>"],
750
- tbody: [2, "<table><tbody>", "</tbody></table>"],
751
- tr: [3, "<table><tbody><tr>", "</tr></tbody></table>"],
752
- colgroup: [2, "<table><tbody></tbody><colgroup>", "</colgroup></table>"],
753
- map: [1, "<map>", "</map>"],
754
- _default: [0, "", ""]
755
- };
756
- findChildById = function(element, id) {
757
- var found, idx, len, node;
758
- if (element.getAttribute("id") === id) {
759
- return element;
760
- }
761
- len = element.childNodes.length;
762
- idx = void 0;
763
- node = void 0;
764
- found = void 0;
765
- idx = 0;
766
- while (idx < len) {
767
- node = element.childNodes[idx];
768
- found = node.nodeType === 1 && findChildById(node, id);
769
- if (found) {
770
- return found;
771
- }
772
- idx++;
773
- }
774
- };
775
- setInnerHTML = function(element, html) {
776
- var idx, len, matches, node, script, _results;
777
- matches = [];
778
- if (movesWhitespace) {
779
- html = html.replace(/(\s+)(<script id='([^']+)')/g, function(match, spaces, tag, id) {
780
- matches.push([id, spaces]);
781
- return tag;
782
- });
783
- }
784
- element.innerHTML = html;
785
- if (matches.length > 0) {
786
- len = matches.length;
787
- idx = void 0;
788
- idx = 0;
789
- _results = [];
790
- while (idx < len) {
791
- script = findChildById(element, matches[idx][0]);
792
- node = document.createTextNode(matches[idx][1]);
793
- script.parentNode.insertBefore(node, script);
794
- _results.push(idx++);
795
- }
796
- return _results;
797
- }
798
- };
799
- /*
800
- Given a parent node and some HTML, generate a set of nodes. Return the first
801
- node, which will allow us to traverse the rest using nextSibling.
802
-
803
- We need to do this because innerHTML in IE does not really parse the nodes.
804
- */
805
-
806
- firstNodeFor = function(parentNode, html) {
807
- var arr, depth, element, end, i, shyElement, start;
808
- arr = wrapMap[parentNode.tagName.toLowerCase()] || wrapMap._default;
809
- depth = arr[0];
810
- start = arr[1];
811
- end = arr[2];
812
- if (needsShy) {
813
- html = "&shy;" + html;
814
- }
815
- element = document.createElement("div");
816
- setInnerHTML(element, start + html + end);
817
- i = 0;
818
- while (i <= depth) {
819
- element = element.firstChild;
820
- i++;
821
- }
822
- if (needsShy) {
823
- shyElement = element;
824
- while (shyElement.nodeType === 1 && !shyElement.nodeName) {
825
- shyElement = shyElement.firstChild;
826
- }
827
- if (shyElement.nodeType === 3 && shyElement.nodeValue.charAt(0) === "­") {
828
- shyElement.nodeValue = shyElement.nodeValue.slice(1);
829
- }
830
- }
831
- return element;
832
- };
833
- /*
834
- In some cases, Internet Explorer can create an anonymous node in
835
- the hierarchy with no tagName. You can create this scenario via:
836
-
837
- div = document.createElement("div");
838
- div.innerHTML = "<table>&shy<script></script><tr><td>hi</td></tr></table>";
839
- div.firstChild.firstChild.tagName //=> ""
840
-
841
- If our script markers are inside such a node, we need to find that
842
- node and use *it* as the marker.
843
- */
844
-
845
- realNode = function(start) {
846
- while (start.parentNode.tagName === "") {
847
- start = start.parentNode;
848
- }
849
- return start;
850
- };
851
- /*
852
- When automatically adding a tbody, Internet Explorer inserts the
853
- tbody immediately before the first <tr>. Other browsers create it
854
- before the first node, no matter what.
855
-
856
- This means the the following code:
857
-
858
- div = document.createElement("div");
859
- div.innerHTML = "<table><script id='first'></script><tr><td>hi</td></tr><script id='last'></script></table>
860
-
861
- Generates the following DOM in IE:
862
-
863
- + div
864
- + table
865
- - script id='first'
866
- + tbody
867
- + tr
868
- + td
869
- - "hi"
870
- - script id='last'
871
-
872
- Which means that the two script tags, even though they were
873
- inserted at the same point in the hierarchy in the original
874
- HTML, now have different parents.
875
-
876
- This code reparents the first script tag by making it the tbody's
877
- first child.
878
- */
879
-
880
- fixParentage = function(start, end) {
881
- if (start.parentNode !== end.parentNode) {
882
- return end.parentNode.insertBefore(start, end.parentNode.firstChild);
883
- }
884
- };
885
- htmlFunc = function(html, outerToo) {
886
- var end, last, nextSibling, node, parentNode, start, _results;
887
- start = realNode(document.getElementById(this.start));
888
- end = document.getElementById(this.end);
889
- parentNode = end.parentNode;
890
- node = void 0;
891
- nextSibling = void 0;
892
- last = void 0;
893
- fixParentage(start, end);
894
- node = start.nextSibling;
895
- while (node) {
896
- nextSibling = node.nextSibling;
897
- last = node === end;
898
- if (last) {
899
- if (outerToo) {
900
- end = node.nextSibling;
901
- } else {
902
- break;
903
- }
904
- }
905
- node.parentNode.removeChild(node);
906
- if (last) {
907
- break;
908
- }
909
- node = nextSibling;
910
- }
911
- node = firstNodeFor(start.parentNode, html);
912
- _results = [];
913
- while (node) {
914
- nextSibling = node.nextSibling;
915
- parentNode.insertBefore(node, end);
916
- _results.push(node = nextSibling);
917
- }
918
- return _results;
919
- };
920
- removeFunc = function() {
921
- var end, start;
922
- start = realNode(document.getElementById(this.start));
923
- end = document.getElementById(this.end);
924
- this.html("");
925
- start.parentNode.removeChild(start);
926
- return end.parentNode.removeChild(end);
927
- };
928
- appendToFunc = function(parentNode) {
929
- var nextSibling, node, _results;
930
- node = firstNodeFor(parentNode, this.outerHTML());
931
- nextSibling = void 0;
932
- _results = [];
933
- while (node) {
934
- nextSibling = node.nextSibling;
935
- parentNode.appendChild(node);
936
- _results.push(node = nextSibling);
937
- }
938
- return _results;
939
- };
940
- afterFunc = function(html) {
941
- var end, insertBefore, nextSibling, node, parentNode, _results;
942
- end = document.getElementById(this.end);
943
- insertBefore = end.nextSibling;
944
- parentNode = end.parentNode;
945
- nextSibling = void 0;
946
- node = void 0;
947
- node = firstNodeFor(parentNode, html);
948
- _results = [];
949
- while (node) {
950
- nextSibling = node.nextSibling;
951
- parentNode.insertBefore(node, insertBefore);
952
- _results.push(node = nextSibling);
953
- }
954
- return _results;
955
- };
956
- prependFunc = function(html) {
957
- var insertBefore, nextSibling, node, parentNode, start, _results;
958
- start = document.getElementById(this.start);
959
- parentNode = start.parentNode;
960
- nextSibling = void 0;
961
- node = void 0;
962
- node = firstNodeFor(parentNode, html);
963
- insertBefore = start.nextSibling;
964
- _results = [];
965
- while (node) {
966
- nextSibling = node.nextSibling;
967
- parentNode.insertBefore(node, insertBefore);
968
- _results.push(node = nextSibling);
969
- }
970
- return _results;
971
- };
972
- }
973
- Metamorph.prototype.html = function(html) {
974
- this.checkRemoved();
975
- if (html === undefined) {
976
- return this.innerHTML;
977
- }
978
- htmlFunc.call(this, html);
979
- return this.innerHTML = html;
980
- };
981
- Metamorph.prototype.replaceWith = function(html) {
982
- this.checkRemoved();
983
- return htmlFunc.call(this, html, true);
984
- };
985
- Metamorph.prototype.remove = removeFunc;
986
- Metamorph.prototype.outerHTML = outerHTMLFunc;
987
- Metamorph.prototype.appendTo = appendToFunc;
988
- Metamorph.prototype.after = afterFunc;
989
- Metamorph.prototype.prepend = prependFunc;
990
- Metamorph.prototype.startTag = startTagFunc;
991
- Metamorph.prototype.endTag = endTagFunc;
992
- Metamorph.prototype.isRemoved = function() {
993
- var after, before;
994
- before = document.getElementById(this.start);
995
- after = document.getElementById(this.end);
996
- return !before || !after;
997
- };
998
- Metamorph.prototype.checkRemoved = function() {
999
- if (this.isRemoved()) {
1000
- throw new Error("Cannot perform operations on a Metamorph that is not in the DOM.");
1001
- }
1002
- };
1003
- return window.Metamorph = Metamorph;
1004
- })(this);
1005
-
1006
-
1007
- /*** src/joosy/core/modules/renderer ***/
1008
-
1009
- var __slice = [].slice;
1010
-
1011
- Joosy.Modules.Renderer = {
1012
- __renderDefault: function() {
1013
- throw new Error("" + (Joosy.Module.__className(this.constructor)) + " does not have an attached template");
1014
- },
1015
- included: function() {
1016
- this.view = function(template, options) {
1017
- if (options == null) {
1018
- options = {};
1019
- }
1020
- return this.prototype.__renderDefault = function(locals) {
1021
- if (locals == null) {
1022
- locals = {};
1023
- }
1024
- if (options.dynamic) {
1025
- return this.renderDynamic(template, locals);
1026
- } else {
1027
- return this.render(template, locals);
1028
- }
1029
- };
1030
- };
1031
- return this.helper = function() {
1032
- var helpers, _ref;
1033
- helpers = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
1034
- if (!this.prototype.hasOwnProperty("__helpers")) {
1035
- this.prototype.__helpers = ((_ref = this.__super__.__helpers) != null ? _ref.clone() : void 0) || [];
1036
- }
1037
- this.prototype.__helpers = this.prototype.__helpers.add(helpers).unique();
1038
- return this.prototype.__helpers = this.prototype.__helpers.unique();
1039
- };
1040
- },
1041
- render: function(template, locals, parentStackPointer) {
1042
- if (locals == null) {
1043
- locals = {};
1044
- }
1045
- if (parentStackPointer == null) {
1046
- parentStackPointer = false;
1047
- }
1048
- return this.__render(false, template, locals, parentStackPointer);
1049
- },
1050
- renderDynamic: function(template, locals, parentStackPointer) {
1051
- if (locals == null) {
1052
- locals = {};
1053
- }
1054
- if (parentStackPointer == null) {
1055
- parentStackPointer = false;
1056
- }
1057
- return this.__render(true, template, locals, parentStackPointer);
1058
- },
1059
- __assignHelpers: function() {
1060
- var _this = this;
1061
- if (this.__helpers == null) {
1062
- return;
1063
- }
1064
- if (!this.hasOwnProperty("__helpers")) {
1065
- this.__helpers = this.__helpers.clone();
1066
- }
1067
- return this.__helpers.each(function(helper, i) {
1068
- if (!Object.isObject(helper)) {
1069
- if (_this[helper] == null) {
1070
- throw new Error("Cannot find method '" + helper + "' to use as helper");
1071
- }
1072
- _this.__helpers[i] = {};
1073
- return _this.__helpers[i][helper] = function() {
1074
- return _this[helper].apply(_this, arguments);
1075
- };
1076
- }
1077
- });
1078
- },
1079
- __instantiateHelpers: function() {
1080
- var helper, _i, _len, _ref;
1081
- if (!this.__helpersInstance) {
1082
- this.__assignHelpers();
1083
- this.__helpersInstance = Object.extended(Joosy.Helpers.Application);
1084
- this.__helpersInstance.__renderer = this;
1085
- if (this.__helpers) {
1086
- _ref = this.__helpers;
1087
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1088
- helper = _ref[_i];
1089
- Joosy.Module.merge(this.__helpersInstance, helper);
1090
- }
1091
- }
1092
- }
1093
- return this.__helpersInstance;
1094
- },
1095
- __instantiateRenderers: function(parentStackPointer) {
1096
- var _this = this;
1097
- return {
1098
- render: function(template, locals) {
1099
- if (locals == null) {
1100
- locals = {};
1101
- }
1102
- return _this.render(template, locals, parentStackPointer);
1103
- },
1104
- renderDynamic: function(template, locals) {
1105
- if (locals == null) {
1106
- locals = {};
1107
- }
1108
- return _this.renderDynamic(template, locals, parentStackPointer);
1109
- },
1110
- renderInline: function(locals, template) {
1111
- if (locals == null) {
1112
- locals = {};
1113
- }
1114
- return _this.renderDynamic(template, locals, parentStackPointer);
1115
- }
1116
- };
1117
- },
1118
- __render: function(dynamic, template, locals, parentStackPointer) {
1119
- var binding, context, key, morph, object, result, stack, update,
1120
- _this = this;
1121
- if (locals == null) {
1122
- locals = {};
1123
- }
1124
- if (parentStackPointer == null) {
1125
- parentStackPointer = false;
1126
- }
1127
- stack = this.__renderingStackChildFor(parentStackPointer);
1128
- stack.template = template;
1129
- stack.locals = locals;
1130
- if (Object.isString(template)) {
1131
- if (this.__renderSection != null) {
1132
- template = Joosy.Application.templater.resolveTemplate(this.__renderSection(), template, this);
1133
- }
1134
- template = Joosy.Application.templater.buildView(template);
1135
- } else if (!Object.isFunction(template)) {
1136
- throw new Error("" + (Joosy.Module.__className(this)) + "> template (maybe @view) does not look like a string or lambda");
1137
- }
1138
- if (!Object.isObject(locals) && Object.extended().constructor !== locals.constructor) {
1139
- throw new Error("" + (Joosy.Module.__className(this)) + "> locals (maybe @data?) is not a hash");
1140
- }
1141
- context = function() {
1142
- var data;
1143
- data = {};
1144
- Joosy.Module.merge(data, stack.locals);
1145
- Joosy.Module.merge(data, _this.__instantiateHelpers(), false);
1146
- Joosy.Module.merge(data, _this.__instantiateRenderers(stack));
1147
- return data;
1148
- };
1149
- result = function() {
1150
- return template(context());
1151
- };
1152
- if (dynamic) {
1153
- morph = Metamorph(result());
1154
- update = function() {
1155
- var binding, child, object, _i, _j, _len, _len1, _ref, _ref1, _ref2, _results;
1156
- if (morph.isRemoved()) {
1157
- _ref = morph.__bindings;
1158
- _results = [];
1159
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1160
- _ref1 = _ref[_i], object = _ref1[0], binding = _ref1[1];
1161
- _results.push(object.unbind(binding));
1162
- }
1163
- return _results;
1164
- } else {
1165
- _ref2 = stack.children;
1166
- for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
1167
- child = _ref2[_j];
1168
- _this.__removeMetamorphs(child);
1169
- }
1170
- stack.children = [];
1171
- return morph.html(result());
1172
- }
1173
- };
1174
- update = update.debounce(0);
1175
- for (key in locals) {
1176
- object = locals[key];
1177
- if (locals.hasOwnProperty(key)) {
1178
- if (((object != null ? object.bind : void 0) != null) && ((object != null ? object.unbind : void 0) != null)) {
1179
- binding = [object, object.bind('changed', update)];
1180
- stack.metamorphBindings.push(binding);
1181
- }
1182
- }
1183
- }
1184
- morph.__bindings = stack.metamorphBindings;
1185
- return morph.outerHTML();
1186
- } else {
1187
- return result();
1188
- }
1189
- },
1190
- __renderingStackElement: function(parent) {
1191
- if (parent == null) {
1192
- parent = null;
1193
- }
1194
- return {
1195
- metamorphBindings: [],
1196
- locals: null,
1197
- template: null,
1198
- children: [],
1199
- parent: parent
1200
- };
1201
- },
1202
- __renderingStackChildFor: function(parentPointer) {
1203
- var element;
1204
- if (!this.__renderingStack) {
1205
- this.__renderingStack = [];
1206
- }
1207
- if (!parentPointer) {
1208
- element = this.__renderingStackElement();
1209
- this.__renderingStack.push(element);
1210
- return element;
1211
- } else {
1212
- element = this.__renderingStackElement(parentPointer);
1213
- parentPointer.children.push(element);
1214
- return element;
1215
- }
1216
- },
1217
- __removeMetamorphs: function(stackPointer) {
1218
- var remove, _ref,
1219
- _this = this;
1220
- if (stackPointer == null) {
1221
- stackPointer = false;
1222
- }
1223
- remove = function(stackPointer) {
1224
- var callback, child, object, _i, _j, _len, _len1, _ref, _ref1, _ref2;
1225
- if (stackPointer != null ? stackPointer.children : void 0) {
1226
- _ref = stackPointer.children;
1227
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1228
- child = _ref[_i];
1229
- _this.__removeMetamorphs(child);
1230
- }
1231
- }
1232
- if (stackPointer != null ? stackPointer.metamorphBindings : void 0) {
1233
- _ref1 = stackPointer.metamorphBindings;
1234
- for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
1235
- _ref2 = _ref1[_j], object = _ref2[0], callback = _ref2[1];
1236
- object.unbind(callback);
1237
- }
1238
- return stackPointer.metamorphBindings = [];
1239
- }
1240
- };
1241
- if (!stackPointer) {
1242
- return (_ref = this.__renderingStack) != null ? _ref.each(function(stackPointer) {
1243
- return remove(stackPointer);
1244
- }) : void 0;
1245
- } else {
1246
- return remove(stackPointer);
1247
- }
1248
- }
1249
- };
1250
-
1251
-
1252
- /*** src/joosy/core/modules/time_manager ***/
1253
-
1254
- Joosy.Modules.TimeManager = {
1255
- setTimeout: function(timeout, action) {
1256
- var timer,
1257
- _this = this;
1258
- this.__timeouts || (this.__timeouts = []);
1259
- timer = window.setTimeout((function() {
1260
- return action();
1261
- }), timeout);
1262
- this.__timeouts.push(timer);
1263
- return timer;
1264
- },
1265
- setInterval: function(delay, action) {
1266
- var timer,
1267
- _this = this;
1268
- this.__intervals || (this.__intervals = []);
1269
- timer = window.setInterval((function() {
1270
- return action();
1271
- }), delay);
1272
- this.__intervals.push(timer);
1273
- return timer;
1274
- },
1275
- __clearTime: function() {
1276
- var entry, _i, _j, _len, _len1, _ref, _ref1, _results;
1277
- if (this.__intervals) {
1278
- _ref = this.__intervals;
1279
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1280
- entry = _ref[_i];
1281
- window.clearInterval(entry);
1282
- }
1283
- }
1284
- if (this.__timeouts) {
1285
- _ref1 = this.__timeouts;
1286
- _results = [];
1287
- for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
1288
- entry = _ref1[_j];
1289
- _results.push(window.clearTimeout(entry));
1290
- }
1291
- return _results;
1292
- }
1293
- }
1294
- };
1295
-
1296
-
1297
- /*** src/joosy/core/modules/widgets_manager ***/
1298
-
1299
- Joosy.Modules.WidgetsManager = {
1300
- included: function() {
1301
- return this.mapWidgets = function(map) {
1302
- if (!this.prototype.hasOwnProperty("__widgets")) {
1303
- this.prototype.__widgets = Object.clone(this.__super__.__widgets) || {};
1304
- }
1305
- return Object.merge(this.prototype.__widgets, map);
1306
- };
1307
- },
1308
- registerWidget: function(container, widget) {
1309
- if (Joosy.Module.hasAncestor(widget, Joosy.Widget)) {
1310
- widget = new widget();
1311
- }
1312
- if (Object.isFunction(widget)) {
1313
- widget = widget();
1314
- }
1315
- this.__activeWidgets || (this.__activeWidgets = []);
1316
- this.__activeWidgets.push(widget.__load(this, $(container)));
1317
- return widget;
1318
- },
1319
- unregisterWidget: function(widget) {
1320
- widget.__unload();
1321
- return this.__activeWidgets.splice(this.__activeWidgets.indexOf(widget), 1);
1322
- },
1323
- __setupWidgets: function() {
1324
- var registered,
1325
- _this = this;
1326
- if (!this.__widgets) {
1327
- return;
1328
- }
1329
- registered = Object.extended();
1330
- Object.each(this.__widgets, function(selector, widget) {
1331
- var activeSelector;
1332
- if (selector === '$container') {
1333
- activeSelector = _this.container;
1334
- } else {
1335
- if (_this.__extractSelector != null) {
1336
- selector = _this.__extractSelector(selector);
1337
- }
1338
- activeSelector = $(selector, _this.container);
1339
- }
1340
- registered[selector] = Object.extended();
1341
- return activeSelector.each(function(index, elem) {
1342
- var instance, _base, _name;
1343
- if (Joosy.Module.hasAncestor(widget, Joosy.Widget)) {
1344
- instance = new widget;
1345
- } else {
1346
- instance = widget.call(_this, index);
1347
- }
1348
- if (Joosy.Application.config.debug) {
1349
- (_base = registered[selector])[_name = Joosy.Module.__className(instance)] || (_base[_name] = 0);
1350
- registered[selector][Joosy.Module.__className(instance)] += 1;
1351
- }
1352
- return _this.registerWidget($(elem), instance);
1353
- });
1354
- });
1355
- this.__widgets = {};
1356
- if (Joosy.Application.config.debug) {
1357
- return registered.each(function(selector, value) {
1358
- return value.each(function(widget, count) {
1359
- return Joosy.Modules.Log.debugAs(_this, "Widget " + widget + " registered at '" + selector + "'. Elements: " + count);
1360
- });
1361
- });
1362
- }
1363
- },
1364
- __unloadWidgets: function() {
1365
- var widget, _i, _len, _ref, _results;
1366
- if (this.__activeWidgets) {
1367
- _ref = this.__activeWidgets;
1368
- _results = [];
1369
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1370
- widget = _ref[_i];
1371
- _results.push(widget.__unload());
1372
- }
1373
- return _results;
1374
- }
1375
- }
1376
- };
1377
-
1378
-
1379
- /*** src/joosy/core/modules/filters ***/
1380
-
1381
- var _this = this,
1382
- __slice = [].slice;
1383
-
1384
- Joosy.Modules.Filters = {
1385
- included: function() {
1386
- var _this = this;
1387
- return ['beforeLoad', 'afterLoad', 'afterUnload'].each(function(filter) {
1388
- return _this[filter] = function(callback) {
1389
- if (!this.prototype.hasOwnProperty("__" + filter + "s")) {
1390
- this.prototype["__" + filter + "s"] = [].concat(this.__super__["__" + filter + "s"] || []);
1391
- }
1392
- return this.prototype["__" + filter + "s"].push(callback);
1393
- };
1394
- });
1395
- }
1396
- };
1397
-
1398
- ['beforeLoad', 'afterLoad', 'afterUnload'].each(function(filter) {
1399
- var camelized;
1400
- camelized = filter.charAt(0).toUpperCase() + filter.slice(1);
1401
- return Joosy.Modules.Filters["__run" + camelized + "s"] = function() {
1402
- var opts,
1403
- _this = this;
1404
- opts = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
1405
- if (!this["__" + filter + "s"]) {
1406
- return true;
1407
- }
1408
- return this["__" + filter + "s"].reduce(function(flag, func) {
1409
- if (!Object.isFunction(func)) {
1410
- func = _this[func];
1411
- }
1412
- return flag && func.apply(_this, opts) !== false;
1413
- }, true);
1414
- };
1415
- });
1416
-
1417
-
1418
- /*** src/joosy/core/layout ***/
1419
-
1420
- var __hasProp = {}.hasOwnProperty,
1421
- __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; },
1422
- __slice = [].slice;
1423
-
1424
- Joosy.Layout = (function(_super) {
1425
- __extends(Layout, _super);
1426
-
1427
- Layout.include(Joosy.Modules.Log);
1428
-
1429
- Layout.include(Joosy.Modules.Events);
1430
-
1431
- Layout.include(Joosy.Modules.Container);
1432
-
1433
- Layout.include(Joosy.Modules.Renderer);
1434
-
1435
- Layout.include(Joosy.Modules.TimeManager);
1436
-
1437
- Layout.include(Joosy.Modules.WidgetsManager);
1438
-
1439
- Layout.include(Joosy.Modules.Filters);
1440
-
1441
- Layout.view('default');
1442
-
1443
- Layout.helper('page');
1444
-
1445
- Layout.beforePaint = function(callback) {
1446
- return this.prototype.__beforePaint = callback;
1447
- };
1448
-
1449
- Layout.paint = function(callback) {
1450
- return this.prototype.__paint = callback;
1451
- };
1452
-
1453
- Layout.erase = function(callback) {
1454
- return this.prototype.__erase = callback;
1455
- };
1456
-
1457
- Layout.fetch = function(callback) {
1458
- return this.prototype.__fetch = function(complete) {
1459
- var _this = this;
1460
- this.data = {};
1461
- return callback.call(this, function() {
1462
- _this.dataFetched = true;
1463
- return complete();
1464
- });
1465
- };
1466
- };
1467
-
1468
- Layout.prototype.data = false;
1469
-
1470
- Layout.prototype.dataFetched = false;
1471
-
1472
- function Layout(params) {
1473
- this.params = params;
1474
- this.uid = Joosy.uid();
1475
- }
1476
-
1477
- Layout.prototype.navigate = function() {
1478
- var args, _ref;
1479
- args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
1480
- return (_ref = Joosy.Router).navigate.apply(_ref, args);
1481
- };
1482
-
1483
- Layout.prototype.__renderSection = function() {
1484
- return 'layouts';
1485
- };
1486
-
1487
- Layout.prototype.__load = function(container) {
1488
- this.container = container;
1489
- this.__assignElements();
1490
- this.__delegateEvents();
1491
- this.__setupWidgets();
1492
- return this.__runAfterLoads();
1493
- };
1494
-
1495
- Layout.prototype.__unload = function() {
1496
- this.__clearTime();
1497
- this.__unloadWidgets();
1498
- this.__removeMetamorphs();
1499
- return this.__runAfterUnloads();
1500
- };
1501
-
1502
- Layout.prototype.page = function(tag, options) {
1503
- if (options == null) {
1504
- options = {};
1505
- }
1506
- options.id = this.uid;
1507
- return Joosy.Helpers.Application.tag(tag, options);
1508
- };
1509
-
1510
- Layout.prototype.content = function() {
1511
- return $("#" + this.uid);
1512
- };
1513
-
1514
- return Layout;
1515
-
1516
- })(Joosy.Module);
1517
-
1518
-
1519
- /*** src/joosy/core/page ***/
1520
-
1521
- var __hasProp = {}.hasOwnProperty,
1522
- __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; },
1523
- __slice = [].slice;
1524
-
1525
- Joosy.Page = (function(_super) {
1526
- __extends(Page, _super);
1527
-
1528
- Page.include(Joosy.Modules.Log);
1529
-
1530
- Page.include(Joosy.Modules.Events);
1531
-
1532
- Page.include(Joosy.Modules.Container);
1533
-
1534
- Page.include(Joosy.Modules.Renderer);
1535
-
1536
- Page.include(Joosy.Modules.TimeManager);
1537
-
1538
- Page.include(Joosy.Modules.WidgetsManager);
1539
-
1540
- Page.include(Joosy.Modules.Filters);
1541
-
1542
- Page.prototype.halted = false;
1543
-
1544
- Page.prototype.layout = false;
1545
-
1546
- Page.prototype.previous = false;
1547
-
1548
- Page.prototype.params = false;
1549
-
1550
- Page.prototype.data = false;
1551
-
1552
- Page.prototype.dataFetched = false;
1553
-
1554
- Page.layout = function(layoutClass) {
1555
- return this.prototype.__layoutClass = layoutClass;
1556
- };
1557
-
1558
- Page.beforePaint = function(callback) {
1559
- return this.prototype.__beforePaint = callback;
1560
- };
1561
-
1562
- Page.paint = function(callback) {
1563
- return this.prototype.__paint = callback;
1564
- };
1565
-
1566
- Page.afterPaint = function(callback) {
1567
- return this.prototype.__afterPaint = callback;
1568
- };
1569
-
1570
- Page.erase = function(callback) {
1571
- return this.prototype.__erase = callback;
1572
- };
1573
-
1574
- Page.fetch = function(callback) {
1575
- return this.prototype.__fetch = function(complete) {
1576
- var _this = this;
1577
- this.data = {};
1578
- return callback.call(this, function() {
1579
- _this.dataFetched = true;
1580
- return complete();
1581
- });
1582
- };
1583
- };
1584
-
1585
- Page.fetchSynchronized = function(callback) {
1586
- return this.prototype.__fetch = function(complete) {
1587
- return this.synchronize(function(context) {
1588
- context.after(function() {
1589
- return complete();
1590
- });
1591
- return callback.call(this, context);
1592
- });
1593
- };
1594
- };
1595
-
1596
- Page.scroll = function(element, options) {
1597
- if (options == null) {
1598
- options = {};
1599
- }
1600
- this.prototype.__scrollElement = element;
1601
- this.prototype.__scrollSpeed = options.speed || 500;
1602
- return this.prototype.__scrollMargin = options.margin || 0;
1603
- };
1604
-
1605
- Page.prototype.__performScrolling = function() {
1606
- var scroll, _ref,
1607
- _this = this;
1608
- scroll = ((_ref = $(this.__extractSelector(this.__scrollElement)).offset()) != null ? _ref.top : void 0) + this.__scrollMargin;
1609
- Joosy.Modules.Log.debugAs(this, "Scrolling to " + (this.__extractSelector(this.__scrollElement)));
1610
- return $('html, body').animate({
1611
- scrollTop: scroll
1612
- }, this.__scrollSpeed, function() {
1613
- if (_this.__scrollSpeed !== 0) {
1614
- return _this.__releaseHeight();
1615
- }
1616
- });
1617
- };
1618
-
1619
- Page.title = function(title, separator) {
1620
- if (separator == null) {
1621
- separator = ' / ';
1622
- }
1623
- this.afterLoad(function() {
1624
- var titleStr;
1625
- titleStr = Object.isFunction(title) ? title.apply(this) : title;
1626
- if (Object.isArray(titleStr)) {
1627
- titleStr = titleStr.join(separator);
1628
- }
1629
- this.__previousTitle = document.title;
1630
- return document.title = titleStr;
1631
- });
1632
- return this.afterUnload(function() {
1633
- return document.title = this.__previousTitle;
1634
- });
1635
- };
1636
-
1637
- function Page(params, previous) {
1638
- var _ref, _ref1, _ref2;
1639
- this.params = params;
1640
- this.previous = previous;
1641
- this.__layoutClass || (this.__layoutClass = ApplicationLayout);
1642
- if (!(this.halted = !this.__runBeforeLoads(this.params, this.previous))) {
1643
- Joosy.Application.loading = true;
1644
- if ((((_ref = this.previous) != null ? (_ref1 = _ref.layout) != null ? _ref1.uid : void 0 : void 0) == null) || ((_ref2 = this.previous) != null ? _ref2.__layoutClass : void 0) !== this.__layoutClass) {
1645
- this.__bootstrapLayout();
1646
- } else {
1647
- this.__bootstrap();
1648
- }
1649
- }
1650
- }
1651
-
1652
- Page.prototype.navigate = function() {
1653
- var args, _ref;
1654
- args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
1655
- return (_ref = Joosy.Router).navigate.apply(_ref, args);
1656
- };
1657
-
1658
- Page.prototype.__renderSection = function() {
1659
- return 'pages';
1660
- };
1661
-
1662
- Page.prototype.__fixHeight = function() {
1663
- return $('html').css('min-height', $(document).height());
1664
- };
1665
-
1666
- Page.prototype.__releaseHeight = function() {
1667
- return $('html').css('min-height', '');
1668
- };
1669
-
1670
- Page.prototype.__load = function() {
1671
- this.__assignElements();
1672
- this.__delegateEvents();
1673
- this.__setupWidgets();
1674
- this.__runAfterLoads(this.params, this.previous);
1675
- if (this.__scrollElement) {
1676
- this.__performScrolling();
1677
- }
1678
- Joosy.Application.loading = false;
1679
- Joosy.Router.trigger('loaded', this);
1680
- this.trigger('loaded');
1681
- return Joosy.Modules.Log.debugAs(this, "Page loaded");
1682
- };
1683
-
1684
- Page.prototype.__unload = function() {
1685
- this.__clearTime();
1686
- this.__unloadWidgets();
1687
- this.__removeMetamorphs();
1688
- this.__runAfterUnloads(this.params, this.previous);
1689
- return delete this.previous;
1690
- };
1691
-
1692
- Page.prototype.__callSyncedThrough = function(entity, receiver, params, callback) {
1693
- if ((entity != null ? entity[receiver] : void 0) != null) {
1694
- return entity[receiver].apply(entity, params.clone().add(callback));
1695
- } else {
1696
- return callback();
1697
- }
1698
- };
1699
-
1700
- Page.prototype.__bootstrap = function() {
1701
- var callbacksParams,
1702
- _this = this;
1703
- Joosy.Modules.Log.debugAs(this, "Boostraping page");
1704
- this.layout = this.previous.layout;
1705
- callbacksParams = [this.layout.content()];
1706
- if (this.__scrollElement && this.__scrollSpeed !== 0) {
1707
- this.__fixHeight();
1708
- }
1709
- this.wait("stageClear dataReceived", function() {
1710
- var _ref;
1711
- if ((_ref = _this.previous) != null) {
1712
- if (typeof _ref.__afterPaint === "function") {
1713
- _ref.__afterPaint(callbacksParams);
1714
- }
1715
- }
1716
- return _this.__callSyncedThrough(_this, '__paint', callbacksParams, function() {
1717
- _this.swapContainer(_this.layout.content(), _this.__renderDefault(_this.data || {}));
1718
- _this.container = _this.layout.content();
1719
- return _this.__load();
1720
- });
1721
- });
1722
- this.__callSyncedThrough(this.previous, '__erase', callbacksParams, function() {
1723
- var _ref;
1724
- if ((_ref = _this.previous) != null) {
1725
- _ref.__unload();
1726
- }
1727
- return _this.__callSyncedThrough(_this, '__beforePaint', callbacksParams, function() {
1728
- return _this.trigger('stageClear');
1729
- });
1730
- });
1731
- return this.__callSyncedThrough(this, '__fetch', [], function() {
1732
- Joosy.Modules.Log.debugAs(_this, "Fetch complete");
1733
- return _this.trigger('dataReceived');
1734
- });
1735
- };
1736
-
1737
- Page.prototype.__bootstrapLayout = function() {
1738
- var callbacksParams, _ref,
1739
- _this = this;
1740
- Joosy.Modules.Log.debugAs(this, "Boostraping page with layout");
1741
- this.layout = new this.__layoutClass(this.params);
1742
- callbacksParams = [Joosy.Application.content(), this];
1743
- if (this.__scrollElement && this.__scrollSpeed !== 0) {
1744
- this.__fixHeight();
1745
- }
1746
- this.wait("stageClear dataReceived", function() {
1747
- return _this.__callSyncedThrough(_this.layout, '__paint', callbacksParams, function() {
1748
- _this.swapContainer(Joosy.Application.content(), _this.layout.__renderDefault(_this.layout.data || {}));
1749
- _this.swapContainer(_this.layout.content(), _this.__renderDefault(_this.data || {}));
1750
- _this.container = _this.layout.content();
1751
- _this.layout.__load(Joosy.Application.content());
1752
- return _this.__load();
1753
- });
1754
- });
1755
- this.__callSyncedThrough((_ref = this.previous) != null ? _ref.layout : void 0, '__erase', callbacksParams, function() {
1756
- var _ref1, _ref2, _ref3;
1757
- if ((_ref1 = _this.previous) != null) {
1758
- if ((_ref2 = _ref1.layout) != null) {
1759
- if (typeof _ref2.__unload === "function") {
1760
- _ref2.__unload();
1761
- }
1762
- }
1763
- }
1764
- if ((_ref3 = _this.previous) != null) {
1765
- _ref3.__unload();
1766
- }
1767
- return _this.__callSyncedThrough(_this.layout, '__beforePaint', callbacksParams, function() {
1768
- return _this.trigger('stageClear');
1769
- });
1770
- });
1771
- return this.__callSyncedThrough(this.layout, '__fetch', [], function() {
1772
- return _this.__callSyncedThrough(_this, '__fetch', [], function() {
1773
- Joosy.Modules.Log.debugAs(_this, "Fetch complete");
1774
- return _this.trigger('dataReceived');
1775
- });
1776
- });
1777
- };
1778
-
1779
- return Page;
1780
-
1781
- })(Joosy.Module);
1782
-
1783
-
1784
- /*** src/joosy/core/resources/watcher ***/
1785
-
1786
- var __hasProp = {}.hasOwnProperty,
1787
- __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; };
1788
-
1789
- Joosy.Resources.Watcher = (function(_super) {
1790
- __extends(Watcher, _super);
1791
-
1792
- Watcher.include(Joosy.Modules.Events);
1793
-
1794
- Watcher.cache = function(cacheKey) {
1795
- return this.prototype.__cacheKey = cacheKey;
1796
- };
1797
-
1798
- Watcher.fetcher = function(fetcher) {
1799
- return this.prototype.__fetcher = fetcher;
1800
- };
1801
-
1802
- Watcher.beforeLoad = function(action) {
1803
- if (!this.prototype.hasOwnProperty('__beforeLoads')) {
1804
- this.prototype.__beforeLoads = [].concat(this.__super__.__beforeLoads || []);
1805
- }
1806
- return this.prototype.__beforeLoads.push(action);
1807
- };
1808
-
1809
- function Watcher(cacheKey, fetcher) {
1810
- if (cacheKey == null) {
1811
- cacheKey = false;
1812
- }
1813
- if (fetcher == null) {
1814
- fetcher = false;
1815
- }
1816
- if (Object.isFunction(cacheKey)) {
1817
- fetcher = cacheKey;
1818
- cacheKey = void 0;
1819
- }
1820
- if (fetcher) {
1821
- this.__fetcher = fetcher;
1822
- }
1823
- if (cacheKey) {
1824
- this.__cacheKey = cacheKey;
1825
- }
1826
- }
1827
-
1828
- Watcher.prototype.load = function(callback) {
1829
- var _this = this;
1830
- if (this.__cacheKey && localStorage[this.__cacheKey]) {
1831
- this.data = this.prepare(JSON.parse(localStorage[this.__cacheKey]));
1832
- this.trigger('changed');
1833
- this.refresh();
1834
- return typeof callback === "function" ? callback(this) : void 0;
1835
- } else {
1836
- return this.__fetcher(function(result) {
1837
- if (_this.__cacheKey) {
1838
- localStorage[_this.__cacheKey] = JSON.stringify(result);
1839
- }
1840
- _this.data = _this.prepare(result);
1841
- _this.trigger('changed');
1842
- return typeof callback === "function" ? callback(_this) : void 0;
1843
- });
1844
- }
1845
- };
1846
-
1847
- Watcher.prototype.clone = function() {
1848
- var copy;
1849
- copy = new this.constructor(this.__cacheKey, this.__fetcher);
1850
- copy.data = Object.clone(this.data, true);
1851
- copy.trigger('changed');
1852
- return copy;
1853
- };
1854
-
1855
- Watcher.prototype.refresh = function(callback) {
1856
- var _this = this;
1857
- return this.__fetcher(function(result) {
1858
- if (_this.__cacheKey) {
1859
- localStorage[_this.__cacheKey] = JSON.stringify(result);
1860
- }
1861
- _this.data = _this.prepare(result);
1862
- _this.trigger('changed');
1863
- return typeof callback === "function" ? callback(_this) : void 0;
1864
- });
1865
- };
1866
-
1867
- Watcher.prototype.prepare = function(data) {
1868
- var bl, _i, _len, _ref;
1869
- if (this.__beforeLoads != null) {
1870
- _ref = this.__beforeLoads;
1871
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1872
- bl = _ref[_i];
1873
- data = bl.call(this, data);
1874
- }
1875
- }
1876
- return data;
1877
- };
1878
-
1879
- return Watcher;
1880
-
1881
- })(Joosy.Module);
1882
-
1883
-
1884
- /*** src/joosy/core/router ***/
1885
-
1886
- Joosy.Router = {
1887
- rawRoutes: Object.extended(),
1888
- routes: Object.extended(),
1889
- restrictPattern: false,
1890
- __namespace: "",
1891
- __asNamespace: "",
1892
- prefix: '',
1893
- restrict: function(restrictPattern) {
1894
- this.restrictPattern = restrictPattern;
1895
- },
1896
- reset: function() {
1897
- this.rawRoutes = Object.extended();
1898
- this.routes = Object.extended();
1899
- this.__namespace = "";
1900
- return this.__asNamespace = "";
1901
- },
1902
- draw: function(block) {
1903
- if (Object.isFunction(block)) {
1904
- return block.call(this);
1905
- }
1906
- },
1907
- map: function(routes) {
1908
- return Joosy.Module.merge(this.rawRoutes, routes);
1909
- },
1910
- navigate: function(to, options) {
1911
- var path,
1912
- _this = this;
1913
- if (options == null) {
1914
- options = {};
1915
- }
1916
- path = to;
1917
- if (path[0] === '#') {
1918
- path = path.substr(1);
1919
- }
1920
- if (!path.startsWith(this.prefix)) {
1921
- path = this.prefix + path;
1922
- }
1923
- if (options.respond !== false) {
1924
- return location.hash = path;
1925
- } else {
1926
- if (!history.pushState) {
1927
- this.__ignoreRequest = to;
1928
- location.hash = path;
1929
- return setTimeout((function() {
1930
- return _this.__ignoreRequest = false;
1931
- }), 0);
1932
- } else {
1933
- return history[options.replaceState ? 'replaceState' : 'pushState']({}, '', '#' + path);
1934
- }
1935
- }
1936
- },
1937
- match: function(route, options) {
1938
- var as, map, routeName;
1939
- if (options == null) {
1940
- options = {};
1941
- }
1942
- if (this.__asNamespace) {
1943
- as = this.__asNamespace + options["as"].capitalize();
1944
- } else {
1945
- as = options["as"];
1946
- }
1947
- routeName = this.__namespace + route;
1948
- map = {};
1949
- map[route] = options["to"];
1950
- Joosy.Module.merge(this.rawRoutes, map);
1951
- return this.__injectReverseUrl(as, routeName);
1952
- },
1953
- root: function(options) {
1954
- var as;
1955
- if (options == null) {
1956
- options = {};
1957
- }
1958
- as = options["as"] || "root";
1959
- return this.match("/", {
1960
- to: options["to"],
1961
- as: as
1962
- });
1963
- },
1964
- notFound: function(options) {
1965
- if (options == null) {
1966
- options = {};
1967
- }
1968
- return this.match(404, {
1969
- to: options["to"]
1970
- });
1971
- },
1972
- namespace: function(name, options, block) {
1973
- var newScope;
1974
- if (options == null) {
1975
- options = {};
1976
- }
1977
- if (Object.isFunction(options)) {
1978
- block = options;
1979
- options = {};
1980
- }
1981
- newScope = $.extend({}, this);
1982
- newScope.rawRoutes = {};
1983
- newScope.__namespace += name;
1984
- if (options["as"]) {
1985
- newScope.__asNamespace += "" + options["as"];
1986
- }
1987
- if (Object.isFunction(block)) {
1988
- block.call(newScope);
1989
- }
1990
- return this.rawRoutes[name] = newScope.rawRoutes;
1991
- },
1992
- __setupRoutes: function() {
1993
- var _this = this;
1994
- $(window).on('hashchange', function() {
1995
- if (!(_this.__ignoreRequest && location.hash.match(_this.__ignoreRequest))) {
1996
- return _this.__respondRoute(location.hash);
1997
- }
1998
- });
1999
- this.__prepareRoutes(this.rawRoutes);
2000
- return this.__respondRoute(location.hash);
2001
- },
2002
- __prepareRoutes: function(routes, namespace) {
2003
- var _this = this;
2004
- if (namespace == null) {
2005
- namespace = '';
2006
- }
2007
- if (!namespace && routes[404]) {
2008
- this.wildcardAction = routes[404];
2009
- delete routes[404];
2010
- }
2011
- return Object.each(routes, function(path, response) {
2012
- path = (namespace + path).replace(/\/{2,}/, '/');
2013
- if (response && (Object.isFunction(response) || (response.prototype != null))) {
2014
- return Joosy.Module.merge(_this.routes, _this.__prepareRoute(path, response));
2015
- } else {
2016
- return _this.__prepareRoutes(response, path);
2017
- }
2018
- });
2019
- },
2020
- __prepareRoute: function(path, response) {
2021
- var matchPath, result;
2022
- matchPath = path.replace(/\/:([^\/]+)/g, '/([^/]+)').replace(/^\/?/, '^/?').replace(/\/?$/, '/?$');
2023
- result = Object.extended();
2024
- result[matchPath] = {
2025
- capture: (path.match(/\/:[^\/]+/g) || []).map(function(str) {
2026
- return str.substr(2);
2027
- }),
2028
- action: response
2029
- };
2030
- return result;
2031
- },
2032
- __respondRoute: function(hash) {
2033
- var found, fullPath, params, path, queryArray, regex, route, urlParams, vals, _ref;
2034
- Joosy.Modules.Log.debug("Router> Answering '" + hash + "'");
2035
- fullPath = hash.replace(RegExp("^\\#(" + this.prefix + ")?"), '');
2036
- if (this.restrictPattern && fullPath.match(this.restrictPattern) === null) {
2037
- this.trigger('restricted', fullPath);
2038
- return;
2039
- } else {
2040
- this.trigger('responded', fullPath);
2041
- }
2042
- this.currentPath = fullPath;
2043
- found = false;
2044
- queryArray = fullPath.split('&');
2045
- path = queryArray.shift();
2046
- urlParams = this.__paramsFromQueryArray(queryArray);
2047
- _ref = this.routes;
2048
- for (regex in _ref) {
2049
- route = _ref[regex];
2050
- if (this.routes.hasOwnProperty(regex)) {
2051
- if (vals = path.match(new RegExp(regex))) {
2052
- params = this.__paramsFromRouteMatch(vals, route).merge(urlParams);
2053
- if (Joosy.Module.hasAncestor(route.action, Joosy.Page)) {
2054
- Joosy.Application.setCurrentPage(route.action, params);
2055
- } else {
2056
- route.action.call(this, params);
2057
- }
2058
- found = true;
2059
- break;
2060
- }
2061
- }
2062
- }
2063
- if (!found && (this.wildcardAction != null)) {
2064
- if (Joosy.Module.hasAncestor(this.wildcardAction, Joosy.Page)) {
2065
- return Joosy.Application.setCurrentPage(this.wildcardAction, urlParams);
2066
- } else {
2067
- return this.wildcardAction(path, urlParams);
2068
- }
2069
- }
2070
- },
2071
- __paramsFromRouteMatch: function(vals, route) {
2072
- var param, params, _i, _len, _ref;
2073
- params = Object.extended();
2074
- vals.shift();
2075
- _ref = route.capture;
2076
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
2077
- param = _ref[_i];
2078
- params[param] = vals.shift();
2079
- }
2080
- return params;
2081
- },
2082
- __paramsFromQueryArray: function(queryArray) {
2083
- var params;
2084
- params = Object.extended();
2085
- if (queryArray) {
2086
- $.each(queryArray, function() {
2087
- var pair;
2088
- if (!this.isBlank()) {
2089
- pair = this.split('=');
2090
- return params[pair[0]] = pair[1];
2091
- }
2092
- });
2093
- }
2094
- return params;
2095
- },
2096
- __injectReverseUrl: function(as, route) {
2097
- var fnc,
2098
- _this = this;
2099
- if (as === void 0) {
2100
- return;
2101
- }
2102
- fnc = function(options) {
2103
- var url;
2104
- url = route;
2105
- (route.match(/\/:[^\/]+/g) || []).each(function(str) {
2106
- return url = url.replace(str.substr(1), options[str.substr(2)]);
2107
- });
2108
- return "#" + _this.prefix + url;
2109
- };
2110
- Joosy.Helpers.Application["" + as + "Path"] = function(options) {
2111
- return fnc(options);
2112
- };
2113
- return Joosy.Helpers.Application["" + as + "Url"] = function(options) {
2114
- var url;
2115
- url = 'http://' + window.location.host + window.location.pathname;
2116
- return "" + url + (fnc(options));
2117
- };
2118
- }
2119
- };
2120
-
2121
- Joosy.Module.merge(Joosy.Router, Joosy.Modules.Events);
2122
-
2123
-
2124
- /*** src/joosy/core/widget ***/
2125
-
2126
- var _ref,
2127
- __hasProp = {}.hasOwnProperty,
2128
- __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; },
2129
- __slice = [].slice;
2130
-
2131
- Joosy.Widget = (function(_super) {
2132
- __extends(Widget, _super);
2133
-
2134
- function Widget() {
2135
- _ref = Widget.__super__.constructor.apply(this, arguments);
2136
- return _ref;
2137
- }
2138
-
2139
- Widget.include(Joosy.Modules.Log);
2140
-
2141
- Widget.include(Joosy.Modules.Events);
2142
-
2143
- Widget.include(Joosy.Modules.Container);
2144
-
2145
- Widget.include(Joosy.Modules.Renderer);
2146
-
2147
- Widget.include(Joosy.Modules.Filters);
2148
-
2149
- Widget.include(Joosy.Modules.TimeManager);
2150
-
2151
- Widget.include(Joosy.Modules.WidgetsManager);
2152
-
2153
- Widget.prototype.__renderDefault = false;
2154
-
2155
- Widget.prototype.data = false;
2156
-
2157
- Widget.prototype.navigate = function() {
2158
- var args, _ref1;
2159
- args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
2160
- return (_ref1 = Joosy.Router).navigate.apply(_ref1, args);
2161
- };
2162
-
2163
- Widget.prototype.__renderSection = function() {
2164
- return 'widgets';
2165
- };
2166
-
2167
- Widget.prototype.__load = function(parent, container, render) {
2168
- this.parent = parent;
2169
- this.container = container;
2170
- if (render == null) {
2171
- render = true;
2172
- }
2173
- this.__runBeforeLoads();
2174
- if (render && this.__renderDefault) {
2175
- this.swapContainer(this.container, this.__renderDefault(this.data || {}));
2176
- }
2177
- this.__assignElements();
2178
- this.__delegateEvents();
2179
- this.__setupWidgets();
2180
- this.__runAfterLoads();
2181
- return this;
2182
- };
2183
-
2184
- Widget.prototype.__unload = function() {
2185
- this.__clearTime();
2186
- this.__unloadWidgets();
2187
- this.__removeMetamorphs();
2188
- return this.__runAfterUnloads();
2189
- };
2190
-
2191
- return Widget;
2192
-
2193
- })(Joosy.Module);
2194
-
2195
-
2196
- /*** src/joosy ***/
2197
-
2198
-
2199
- ;