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