joosy 1.1.2 → 1.2.0.alpha.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -7
  3. data/Gemfile +1 -11
  4. data/Gruntfile.coffee +138 -0
  5. data/README.md +65 -24
  6. data/bin/joosy +21 -0
  7. data/bower.json +23 -0
  8. data/joosy.gemspec +6 -12
  9. data/lib/joosy.js +3754 -0
  10. data/lib/joosy.rb +8 -9
  11. data/package.json +37 -0
  12. data/spec/{javascripts/helpers/spec_helper.js.coffee → helpers/helper.coffee} +0 -0
  13. data/spec/{javascripts/joosy/core/application_spec.js.coffee → joosy/core/application_spec.coffee} +0 -0
  14. data/spec/{javascripts/joosy/core/form_spec.js.coffee → joosy/core/form_spec.coffee} +30 -30
  15. data/spec/{javascripts/joosy/core/helpers/forms_spec.js.coffee → joosy/core/helpers/forms_spec.coffee} +0 -0
  16. data/spec/{javascripts/joosy/core/helpers/view_spec.js.coffee → joosy/core/helpers/view_spec.coffee} +0 -0
  17. data/spec/{javascripts/joosy/core/helpers/widgets_spec.js.coffee → joosy/core/helpers/widgets_spec.coffee} +0 -0
  18. data/spec/{javascripts/joosy/core/joosy_spec.js.coffee → joosy/core/joosy_spec.coffee} +0 -0
  19. data/spec/{javascripts/joosy/core/layout_spec.js.coffee → joosy/core/layout_spec.coffee} +0 -0
  20. data/spec/{javascripts/joosy/core/modules/container_spec.js.coffee → joosy/core/modules/container_spec.coffee} +1 -1
  21. data/spec/{javascripts/joosy/core/modules/events_spec.js.coffee → joosy/core/modules/events_spec.coffee} +0 -0
  22. data/spec/{javascripts/joosy/core/modules/filters_spec.js.coffee → joosy/core/modules/filters_spec.coffee} +0 -0
  23. data/spec/{javascripts/joosy/core/modules/log_spec.js.coffee → joosy/core/modules/log_spec.coffee} +0 -0
  24. data/spec/{javascripts/joosy/core/modules/module_spec.js.coffee → joosy/core/modules/module_spec.coffee} +0 -0
  25. data/spec/{javascripts/joosy/core/modules/renderer_spec.js.coffee → joosy/core/modules/renderer_spec.coffee} +35 -0
  26. data/spec/{javascripts/joosy/core/modules/time_manager_spec.js.coffee → joosy/core/modules/time_manager_spec.coffee} +0 -0
  27. data/spec/{javascripts/joosy/core/modules/widget_manager_spec.js.coffee → joosy/core/modules/widget_manager_spec.coffee} +0 -0
  28. data/spec/{javascripts/joosy/core/page_spec.js.coffee → joosy/core/page_spec.coffee} +0 -0
  29. data/spec/{javascripts/joosy/core/resource/collection_spec.js.coffee → joosy/core/resource/collection_spec.coffee} +0 -0
  30. data/spec/{javascripts/joosy/core/resource/generic_spec.js.coffee → joosy/core/resource/generic_spec.coffee} +0 -0
  31. data/spec/{javascripts/joosy/core/resource/rest_collection_spec.js.coffee → joosy/core/resource/rest_collection_spec.coffee} +0 -0
  32. data/spec/{javascripts/joosy/core/resource/rest_spec.js.coffee → joosy/core/resource/rest_spec.coffee} +0 -8
  33. data/spec/{javascripts/joosy/core/router_spec.js.coffee → joosy/core/router_spec.coffee} +19 -22
  34. data/spec/{javascripts/joosy/core/templaters/rails_jst_spec.js.coffee → joosy/core/templaters/rails_jst_spec.coffee} +0 -0
  35. data/spec/{javascripts/joosy/core/widget_spec.js.coffee → joosy/core/widget_spec.coffee} +0 -0
  36. data/spec/{javascripts/joosy/preloaders/caching_spec.js.coffee → joosy/preloaders/caching_spec.coffee} +2 -2
  37. data/spec/{javascripts/joosy/preloaders/inline_spec.js.coffee → joosy/preloaders/inline_spec.coffee} +1 -1
  38. data/spec/support/test.js +1 -0
  39. data/{app/assets/javascripts/joosy/core/application.js.coffee → src/joosy/core/application.coffee} +0 -0
  40. data/{app/assets/javascripts/joosy/core/form.js.coffee → src/joosy/core/form.coffee} +5 -5
  41. data/{app/assets/javascripts/joosy/core/helpers/form.js.coffee → src/joosy/core/helpers/form.coffee} +0 -0
  42. data/{app/assets/javascripts/joosy/core/helpers/view.js.coffee → src/joosy/core/helpers/view.coffee} +0 -0
  43. data/{app/assets/javascripts/joosy/core/helpers/widgets.js.coffee → src/joosy/core/helpers/widgets.coffee} +0 -0
  44. data/{app/assets/javascripts/joosy/core/joosy.js.coffee → src/joosy/core/joosy.coffee} +1 -1
  45. data/{app/assets/javascripts/joosy/core/layout.js.coffee → src/joosy/core/layout.coffee} +0 -0
  46. data/{app/assets/javascripts/joosy/core/modules/container.js.coffee → src/joosy/core/modules/container.coffee} +1 -1
  47. data/{app/assets/javascripts/joosy/core/modules/events.js.coffee → src/joosy/core/modules/events.coffee} +4 -6
  48. data/{app/assets/javascripts/joosy/core/modules/filters.js.coffee → src/joosy/core/modules/filters.coffee} +0 -0
  49. data/{app/assets/javascripts/joosy/core/modules/log.js.coffee → src/joosy/core/modules/log.coffee} +0 -0
  50. data/{app/assets/javascripts/joosy/core/modules/module.js.coffee → src/joosy/core/modules/module.coffee} +0 -0
  51. data/{app/assets/javascripts/joosy/core/modules/renderer.js.coffee → src/joosy/core/modules/renderer.coffee} +1 -1
  52. data/{app/assets/javascripts/joosy/core/modules/time_manager.js.coffee → src/joosy/core/modules/time_manager.coffee} +0 -0
  53. data/{app/assets/javascripts/joosy/core/modules/widgets_manager.js.coffee → src/joosy/core/modules/widgets_manager.coffee} +0 -0
  54. data/{app/assets/javascripts/joosy/core/page.js.coffee → src/joosy/core/page.coffee} +0 -1
  55. data/{app/assets/javascripts/joosy/core/preloader.js.coffee → src/joosy/core/preloader.coffee} +0 -0
  56. data/{app/assets/javascripts/joosy/core/resource/collection.js.coffee → src/joosy/core/resource/collection.coffee} +0 -0
  57. data/{app/assets/javascripts/joosy/core/resource/generic.js.coffee → src/joosy/core/resource/generic.coffee} +5 -5
  58. data/{app/assets/javascripts/joosy/core/resource/rest.js.coffee → src/joosy/core/resource/rest.coffee} +5 -5
  59. data/{app/assets/javascripts/joosy/core/resource/rest_collection.js.coffee → src/joosy/core/resource/rest_collection.coffee} +0 -0
  60. data/src/joosy/core/resource/watcher.coffee +50 -0
  61. data/{app/assets/javascripts/joosy/core/router.js.coffee → src/joosy/core/router.coffee} +28 -30
  62. data/{app/assets/javascripts/joosy/core/templaters/rails_jst.js.coffee → src/joosy/core/templaters/rails_jst.coffee} +12 -2
  63. data/{app/assets/javascripts/joosy/core/widget.js.coffee → src/joosy/core/widget.coffee} +0 -0
  64. data/src/joosy/generators/command.coffee +49 -0
  65. data/src/joosy/generators/generator.coffee +93 -0
  66. data/src/joosy/generators/layout.coffee +20 -0
  67. data/src/joosy/generators/page.coffee +20 -0
  68. data/src/joosy/generators/project/base.coffee +28 -0
  69. data/src/joosy/generators/project/standalone.coffee +25 -0
  70. data/src/joosy/generators/project.coffee +16 -0
  71. data/src/joosy/generators/widget.coffee +20 -0
  72. data/{app/assets/javascripts/joosy/preloaders/caching.js.coffee → src/joosy/preloaders/caching.coffee} +0 -0
  73. data/{app/assets/javascripts/joosy/preloaders/inline.js.coffee → src/joosy/preloaders/inline.coffee} +0 -0
  74. data/src/joosy.coffee +2 -0
  75. data/src/vendor/metamorph.coffee +410 -0
  76. data/tasks/joosy.coffee +63 -0
  77. data/templates/application/base/application.coffee +11 -0
  78. data/{lib/rails/generators/joosy/templates/app/helpers/application.js.coffee → templates/application/base/helpers/application.coffee} +0 -0
  79. data/{lib/rails/generators/joosy/templates/app/layouts/application.js.coffee → templates/application/base/layouts/application.coffee} +0 -0
  80. data/{lib/rails/generators/joosy/templates/app/pages/application.js.coffee → templates/application/base/pages/application.coffee} +0 -0
  81. data/{lib/rails/generators/joosy/templates/app/pages/welcome/index.js.coffee → templates/application/base/pages/welcome/index.coffee} +3 -3
  82. data/templates/application/base/routes.coffee +3 -0
  83. data/{lib/rails/generators/joosy/templates/app → templates/application/base}/templates/layouts/application.jst.hamlc +0 -0
  84. data/{lib/rails/generators/joosy/templates/app → templates/application/base}/templates/pages/welcome/index.jst.hamlc +1 -2
  85. data/templates/application/standalone/.gitignore +5 -0
  86. data/templates/application/standalone/Gruntfile.coffee +40 -0
  87. data/templates/application/standalone/Procfile +1 -0
  88. data/templates/application/standalone/bower.json +7 -0
  89. data/templates/application/standalone/package.json +24 -0
  90. data/templates/application/standalone/source/index.haml +7 -0
  91. data/templates/application/standalone/stylesheets/application.styl +2 -0
  92. data/templates/layout/basic.coffee +2 -0
  93. data/templates/layout/namespaced.coffee +4 -0
  94. data/templates/page/basic.coffee +3 -0
  95. data/templates/page/namespaced.coffee +5 -0
  96. data/templates/widget/basic.coffee +2 -0
  97. data/templates/widget/namespaced.coffee +4 -0
  98. metadata +98 -179
  99. data/.codoopts +0 -5
  100. data/Gemfile.lock +0 -157
  101. data/Guardfile +0 -32
  102. data/LICENSE +0 -22
  103. data/MIT-LICENSE +0 -21
  104. data/Rakefile +0 -14
  105. data/app/assets/javascripts/joosy.js.coffee +0 -5
  106. data/app/helpers/joosy/sprockets_helper.rb +0 -41
  107. data/app/views/layouts/json_wrapper.json.erb +0 -1
  108. data/lib/joosy/rails/engine.rb +0 -24
  109. data/lib/joosy/version.rb +0 -3
  110. data/lib/rails/generators/joosy/application_generator.rb +0 -43
  111. data/lib/rails/generators/joosy/joosy_base.rb +0 -30
  112. data/lib/rails/generators/joosy/layout_generator.rb +0 -30
  113. data/lib/rails/generators/joosy/page_generator.rb +0 -42
  114. data/lib/rails/generators/joosy/preloader_generator.rb +0 -30
  115. data/lib/rails/generators/joosy/resource_generator.rb +0 -40
  116. data/lib/rails/generators/joosy/templates/app/layouts/template.js.coffee +0 -2
  117. data/lib/rails/generators/joosy/templates/app/pages/template.js.coffee +0 -5
  118. data/lib/rails/generators/joosy/templates/app/resources/template.js.coffee +0 -2
  119. data/lib/rails/generators/joosy/templates/app/resources/template_with_namespace.js.coffee +0 -4
  120. data/lib/rails/generators/joosy/templates/app/routes.js.coffee +0 -8
  121. data/lib/rails/generators/joosy/templates/app/widgets/template.js.coffee +0 -2
  122. data/lib/rails/generators/joosy/templates/app.js.coffee +0 -11
  123. data/lib/rails/generators/joosy/templates/app_controller.rb +0 -9
  124. data/lib/rails/generators/joosy/templates/app_preloader.js.coffee.erb +0 -13
  125. data/lib/rails/generators/joosy/templates/app_railties.js.coffee.erb +0 -11
  126. data/lib/rails/generators/joosy/templates/preload.html.erb +0 -26
  127. data/lib/rails/generators/joosy/templates/preload.html.haml +0 -19
  128. data/lib/rails/generators/joosy/templates/preload.html.slim +0 -19
  129. data/lib/rails/generators/joosy/widget_generator.rb +0 -30
  130. data/lib/rails/resources_with_joosy.rb +0 -11
  131. data/spec/javascripts/support/assets/coolface.jpg +0 -0
  132. data/spec/javascripts/support/assets/okay.jpg +0 -0
  133. data/spec/javascripts/support/assets/test.js +0 -1
  134. data/spec/javascripts/support/jasmine.yml +0 -74
  135. data/spec/javascripts/support/jasmine_config.rb +0 -23
  136. data/spec/javascripts/support/jasmine_runner.rb +0 -32
  137. data/spec/javascripts/support/sinon-1.3.1.js +0 -3469
  138. data/spec/javascripts/support/sinon-ie-1.3.1.js.skip +0 -82
  139. data/vendor/assets/javascripts/jquery.form.js +0 -1190
  140. data/vendor/assets/javascripts/jquery.hashchange.js +0 -390
  141. data/vendor/assets/javascripts/metamorph.js +0 -409
  142. data/vendor/assets/javascripts/sugar.js +0 -8637
data/lib/joosy.js ADDED
@@ -0,0 +1,3754 @@
1
+
2
+
3
+ /*** src/joosy/core/joosy ***/
4
+
5
+ var __hasProp = {}.hasOwnProperty,
6
+ __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; };
7
+
8
+ this.Joosy = {
9
+ Modules: {},
10
+ Resource: {},
11
+ Templaters: {},
12
+ namespace: function(name, generator) {
13
+ var key, klass, part, space, _i, _len, _results;
14
+ if (generator == null) {
15
+ generator = false;
16
+ }
17
+ name = name.split('.');
18
+ space = window;
19
+ for (_i = 0, _len = name.length; _i < _len; _i++) {
20
+ part = name[_i];
21
+ if (part.length > 0) {
22
+ space = space[part] != null ? space[part] : space[part] = {};
23
+ }
24
+ }
25
+ if (generator) {
26
+ generator = generator.apply(space);
27
+ }
28
+ _results = [];
29
+ for (key in space) {
30
+ klass = space[key];
31
+ if (space.hasOwnProperty(key) && Joosy.Module.hasAncestor(klass, Joosy.Module)) {
32
+ _results.push(klass.__namespace__ = name);
33
+ } else {
34
+ _results.push(void 0);
35
+ }
36
+ }
37
+ return _results;
38
+ },
39
+ helpers: function(name, generator) {
40
+ return Joosy.namespace("Joosy.Helpers." + name, generator);
41
+ },
42
+ test: function() {
43
+ var text;
44
+ text = "Hi :). I'm Joosy. And everything is just fine!";
45
+ if (console) {
46
+ return console.log(text);
47
+ } else {
48
+ return alert(text);
49
+ }
50
+ },
51
+ synchronize: function() {
52
+ var _ref;
53
+ return (_ref = Joosy.Modules.Events).synchronize.apply(_ref, arguments);
54
+ },
55
+ uuid: function() {
56
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
57
+ var r, v;
58
+ r = Math.random() * 16 | 0;
59
+ v = c === 'x' ? r : r & 3 | 8;
60
+ return v.toString(16);
61
+ }).toUpperCase();
62
+ },
63
+ preloadImages: function(images, callback) {
64
+ var checker, p, result, ticks, _i, _len;
65
+ if (!Object.isArray(images)) {
66
+ images = [images];
67
+ }
68
+ if (images.length === 0) {
69
+ callback();
70
+ }
71
+ ticks = images.length;
72
+ result = [];
73
+ checker = function() {
74
+ if ((ticks -= 1) === 0) {
75
+ return typeof callback === "function" ? callback() : void 0;
76
+ }
77
+ };
78
+ for (_i = 0, _len = images.length; _i < _len; _i++) {
79
+ p = images[_i];
80
+ result.push($('<img/>').load(checker).error(checker).attr('src', p));
81
+ }
82
+ return result;
83
+ },
84
+ buildUrl: function(url, params) {
85
+ var hash, paramsString;
86
+ paramsString = [];
87
+ Object.each(params, function(key, value) {
88
+ return paramsString.push("" + key + "=" + value);
89
+ });
90
+ hash = url.match(/(\#.*)?$/)[0];
91
+ url = url.replace(/\#.*$/, '');
92
+ if (!paramsString.isEmpty() && !url.has(/\?/)) {
93
+ url = url + "?";
94
+ }
95
+ paramsString = paramsString.join('&');
96
+ if (!paramsString.isBlank() && url.last() !== '?') {
97
+ paramsString = '&' + paramsString;
98
+ }
99
+ return url + paramsString + hash;
100
+ },
101
+ defineResources: function(resources) {
102
+ return Object.extended(resources).each(function(namespace, resources) {
103
+ if (namespace.isBlank()) {
104
+ return Object.extended(resources).each(function(resource, path) {
105
+ return Joosy.defineResource(resource, path);
106
+ });
107
+ } else {
108
+ return Joosy.namespace(namespace, function() {
109
+ var _this = this;
110
+ return Object.extended(resources).each(function(resource, path) {
111
+ return Joosy.defineResource(resource, path, _this);
112
+ });
113
+ });
114
+ }
115
+ });
116
+ },
117
+ defineResource: function(resource, path, space) {
118
+ var className, collectionName, _ref, _ref1;
119
+ if (space == null) {
120
+ space = window;
121
+ }
122
+ className = resource.camelize();
123
+ collectionName = "" + (resource.pluralize().camelize()) + "Collection";
124
+ if (!space[className]) {
125
+ Joosy.Modules.Log.debugAs(space, "Define " + className);
126
+ space[className] = (function(_super) {
127
+ __extends(_Class, _super);
128
+
129
+ function _Class() {
130
+ _ref = _Class.__super__.constructor.apply(this, arguments);
131
+ return _ref;
132
+ }
133
+
134
+ _Class.entity(resource);
135
+
136
+ _Class.source(path);
137
+
138
+ _Class.prototype.__collection = function() {
139
+ return space[collectionName];
140
+ };
141
+
142
+ return _Class;
143
+
144
+ })(Joosy.Resource.REST);
145
+ }
146
+ if (!space[collectionName]) {
147
+ Joosy.Modules.Log.debugAs(space, "Define " + collectionName);
148
+ return space[collectionName] = (function(_super) {
149
+ __extends(_Class, _super);
150
+
151
+ function _Class() {
152
+ _ref1 = _Class.__super__.constructor.apply(this, arguments);
153
+ return _ref1;
154
+ }
155
+
156
+ _Class.model(space[className]);
157
+
158
+ return _Class;
159
+
160
+ })(Joosy.Resource.RESTCollection);
161
+ }
162
+ }
163
+ };
164
+
165
+
166
+ /*** src/joosy/core/application ***/
167
+
168
+ Joosy.Application = {
169
+ Pages: {},
170
+ Layouts: {},
171
+ Controls: {},
172
+ loading: true,
173
+ identity: true,
174
+ debug: false,
175
+ debounceForms: false,
176
+ initialize: function(name, selector, options) {
177
+ var key, value;
178
+ this.name = name;
179
+ this.selector = selector;
180
+ if (options == null) {
181
+ options = {};
182
+ }
183
+ for (key in options) {
184
+ value = options[key];
185
+ this[key] = value;
186
+ }
187
+ this.templater = new Joosy.Templaters.RailsJST(this.name);
188
+ Joosy.Router.__setupRoutes();
189
+ this.sandboxSelector = Joosy.uuid();
190
+ this.content().after("<div id='" + this.sandboxSelector + "' style='display:none'></div>");
191
+ return this.sandboxSelector = '#' + this.sandboxSelector;
192
+ },
193
+ content: function() {
194
+ return $(this.selector);
195
+ },
196
+ sandbox: function() {
197
+ return $(this.sandboxSelector);
198
+ },
199
+ setCurrentPage: function(page, params) {
200
+ var attempt;
201
+ attempt = new page(params, this.page);
202
+ if (!attempt.halted) {
203
+ return this.page = attempt;
204
+ }
205
+ }
206
+ };
207
+
208
+
209
+ /*** src/joosy/core/modules/module ***/
210
+
211
+ Joosy.Module = (function() {
212
+ function Module() {}
213
+
214
+ Module.__namespace__ = [];
215
+
216
+ Module.__className = function(klass) {
217
+ if (!Object.isFunction(klass)) {
218
+ klass = klass.constructor;
219
+ }
220
+ if (klass.name != null) {
221
+ return klass.name;
222
+ } else {
223
+ return klass.toString().replace(/^function ([a-zA-Z]+)\([\s\S]+/, '$1');
224
+ }
225
+ };
226
+
227
+ Module.hasAncestor = function(what, klass) {
228
+ var _ref, _ref1;
229
+ if (!((what != null) && (klass != null))) {
230
+ return false;
231
+ }
232
+ _ref = [what.prototype, klass.prototype], what = _ref[0], klass = _ref[1];
233
+ while (what) {
234
+ if (what === klass) {
235
+ return true;
236
+ }
237
+ what = (_ref1 = what.constructor) != null ? _ref1.__super__ : void 0;
238
+ }
239
+ return false;
240
+ };
241
+
242
+ Module.alias = function(method, feature, action) {
243
+ var chained;
244
+ chained = "" + method + "Without" + (feature.camelize());
245
+ this.prototype[chained] = this.prototype[method];
246
+ return this.prototype[method] = action;
247
+ };
248
+
249
+ Module.aliasStatic = function(method, feature, action) {
250
+ var chained;
251
+ chained = "" + method + "Without" + (feature.camelize());
252
+ this[chained] = this[method];
253
+ return this[method] = action;
254
+ };
255
+
256
+ Module.merge = function(destination, source, unsafe) {
257
+ var key, value;
258
+ if (unsafe == null) {
259
+ unsafe = true;
260
+ }
261
+ for (key in source) {
262
+ value = source[key];
263
+ if (source.hasOwnProperty(key)) {
264
+ if (unsafe || !destination.hasOwnProperty(key)) {
265
+ destination[key] = value;
266
+ }
267
+ }
268
+ }
269
+ return destination;
270
+ };
271
+
272
+ Module.include = function(object) {
273
+ var key, value, _ref;
274
+ if (!object) {
275
+ throw new Error('include(object) requires obj');
276
+ }
277
+ for (key in object) {
278
+ value = object[key];
279
+ if (key !== 'included' && key !== 'extended') {
280
+ this.prototype[key] = value;
281
+ }
282
+ }
283
+ if ((_ref = object.included) != null) {
284
+ _ref.apply(this);
285
+ }
286
+ return null;
287
+ };
288
+
289
+ Module.extend = function(object) {
290
+ var _ref;
291
+ if (!object) {
292
+ throw new Error('extend(object) requires object');
293
+ }
294
+ this.merge(this, object);
295
+ if ((_ref = object.extended) != null) {
296
+ _ref.apply(this);
297
+ }
298
+ return null;
299
+ };
300
+
301
+ return Module;
302
+
303
+ })();
304
+
305
+
306
+ /*** src/joosy/core/modules/log ***/
307
+
308
+ var __slice = [].slice;
309
+
310
+ Joosy.Modules.Log = {
311
+ log: function() {
312
+ var args;
313
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
314
+ if (typeof console === "undefined" || console === null) {
315
+ return;
316
+ }
317
+ if (console.log.apply != null) {
318
+ args.unshift("Joosy>");
319
+ return console.log.apply(console, args);
320
+ } else {
321
+ return console.log(args.first());
322
+ }
323
+ },
324
+ debug: function() {
325
+ var args;
326
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
327
+ if (!Joosy.Application.debug) {
328
+ return;
329
+ }
330
+ return this.log.apply(this, args);
331
+ },
332
+ debugAs: function() {
333
+ var args, context, string;
334
+ context = arguments[0], string = arguments[1], args = 3 <= arguments.length ? __slice.call(arguments, 2) : [];
335
+ if (!Joosy.Application.debug) {
336
+ return;
337
+ }
338
+ context = Joosy.Module.__className(context) || 'unknown context';
339
+ return this.debug.apply(this, ["" + context + "> " + string].concat(__slice.call(args)));
340
+ }
341
+ };
342
+
343
+
344
+ /*** src/joosy/core/modules/events ***/
345
+
346
+ var __slice = [].slice;
347
+
348
+ Joosy.Modules.Events = {
349
+ wait: function(name, events, callback) {
350
+ this.__oneShotEvents || (this.__oneShotEvents = Object.extended());
351
+ if (Object.isFunction(events)) {
352
+ callback = events;
353
+ events = name;
354
+ name = this.__oneShotEvents.keys().length.toString();
355
+ }
356
+ events = this.__splitEvents(events);
357
+ this.__validateEvents(events);
358
+ this.__oneShotEvents[name] = [events, callback];
359
+ return name;
360
+ },
361
+ bind: function(name, events, callback) {
362
+ this.__boundEvents || (this.__boundEvents = Object.extended());
363
+ if (Object.isFunction(events)) {
364
+ callback = events;
365
+ events = name;
366
+ name = this.__boundEvents.keys().length.toString();
367
+ }
368
+ events = this.__splitEvents(events);
369
+ this.__validateEvents(events);
370
+ this.__boundEvents[name] = [events, callback];
371
+ return name;
372
+ },
373
+ unbind: function(target) {
374
+ var callback, events, name, needle, _ref, _ref1;
375
+ needle = void 0;
376
+ _ref = this.__boundEvents;
377
+ for (name in _ref) {
378
+ _ref1 = _ref[name], events = _ref1[0], callback = _ref1[1];
379
+ if ((Object.isFunction(target) && callback === target) || name === target) {
380
+ needle = name;
381
+ break;
382
+ }
383
+ }
384
+ if (needle != null) {
385
+ return delete this.__boundEvents[needle];
386
+ }
387
+ },
388
+ trigger: function() {
389
+ var callback, data, event, events, fire, name, _ref, _ref1, _ref2, _ref3, _results,
390
+ _this = this;
391
+ event = arguments[0], data = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
392
+ Joosy.Modules.Log.debugAs(this, "Event " + event + " triggered");
393
+ if (this.__oneShotEvents) {
394
+ fire = [];
395
+ _ref = this.__oneShotEvents;
396
+ for (name in _ref) {
397
+ _ref1 = _ref[name], events = _ref1[0], callback = _ref1[1];
398
+ events.remove(event);
399
+ if (events.length === 0) {
400
+ fire.push(name);
401
+ }
402
+ }
403
+ fire.each(function(name) {
404
+ callback = _this.__oneShotEvents[name][1];
405
+ delete _this.__oneShotEvents[name];
406
+ return callback.apply(null, data);
407
+ });
408
+ }
409
+ if (this.__boundEvents) {
410
+ _ref2 = this.__boundEvents;
411
+ _results = [];
412
+ for (name in _ref2) {
413
+ _ref3 = _ref2[name], events = _ref3[0], callback = _ref3[1];
414
+ if (events.any(event)) {
415
+ _results.push(callback.apply(null, data));
416
+ } else {
417
+ _results.push(void 0);
418
+ }
419
+ }
420
+ return _results;
421
+ }
422
+ },
423
+ synchronize: function(block) {
424
+ var context,
425
+ _this = this;
426
+ context = new Joosy.Events.SynchronizationContext(this);
427
+ block.call(this, context);
428
+ if (context.expectations.length === 0) {
429
+ return context.after.call(this);
430
+ } else {
431
+ this.wait(context.expectations, function() {
432
+ return context.after.call(_this);
433
+ });
434
+ return context.actions.each(function(data) {
435
+ return data[0].call(_this, function() {
436
+ return _this.trigger(data[1]);
437
+ });
438
+ });
439
+ }
440
+ },
441
+ __splitEvents: function(events) {
442
+ if (Object.isString(events)) {
443
+ if (events.isBlank()) {
444
+ return [];
445
+ } else {
446
+ return events.trim().split(/\s+/);
447
+ }
448
+ } else {
449
+ return events;
450
+ }
451
+ },
452
+ __validateEvents: function(events) {
453
+ if (!(Object.isArray(events) && events.length > 0)) {
454
+ throw new Error("" + (Joosy.Module.__className(this)) + "> bind invalid events: " + events);
455
+ }
456
+ }
457
+ };
458
+
459
+ Joosy.Events = {};
460
+
461
+ Joosy.Events.Namespace = (function() {
462
+ function Namespace(parent) {
463
+ this.parent = parent;
464
+ this.bindings = [];
465
+ }
466
+
467
+ Namespace.prototype.bind = function() {
468
+ var args, _ref;
469
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
470
+ return this.bindings.push((_ref = this.parent).bind.apply(_ref, args));
471
+ };
472
+
473
+ Namespace.prototype.unbind = function() {
474
+ var b, _i, _len, _ref;
475
+ _ref = this.bindings;
476
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
477
+ b = _ref[_i];
478
+ this.parent.unbind(b);
479
+ }
480
+ return this.bindings = [];
481
+ };
482
+
483
+ return Namespace;
484
+
485
+ })();
486
+
487
+ Joosy.Events.SynchronizationContext = (function() {
488
+ SynchronizationContext.uid = 0;
489
+
490
+ function SynchronizationContext(parent) {
491
+ this.parent = parent;
492
+ this.expectations = [];
493
+ this.actions = [];
494
+ }
495
+
496
+ SynchronizationContext.prototype.uid = function() {
497
+ return this.constructor.uid += 1;
498
+ };
499
+
500
+ SynchronizationContext.prototype["do"] = function(action) {
501
+ var event;
502
+ event = "synchro-" + (this.uid());
503
+ this.expectations.push(event);
504
+ return this.actions.push([action, event]);
505
+ };
506
+
507
+ SynchronizationContext.prototype.after = function(after) {
508
+ this.after = after;
509
+ };
510
+
511
+ return SynchronizationContext;
512
+
513
+ })();
514
+
515
+
516
+ /*** src/joosy/core/modules/container ***/
517
+
518
+ Joosy.Modules.Container = {
519
+ events: false,
520
+ elements: false,
521
+ eventSplitter: /^(\S+)\s*(.*)$/,
522
+ onRefresh: function(callback) {
523
+ if (!this.hasOwnProperty("__onRefreshes")) {
524
+ this.__onRefreshes = [];
525
+ }
526
+ return this.__onRefreshes.push(callback);
527
+ },
528
+ $: function(selector) {
529
+ return $(selector, this.container);
530
+ },
531
+ refreshElements: function() {
532
+ var _this = this;
533
+ this.__collectElements().each(function(key, value) {
534
+ return _this['$' + key] = _this.$(value);
535
+ });
536
+ if (this.hasOwnProperty("__onRefreshes")) {
537
+ this.__onRefreshes.each(function(callback) {
538
+ return callback.apply(_this);
539
+ });
540
+ return this.__onRefreshes = [];
541
+ }
542
+ },
543
+ reloadContainer: function(htmlCallback) {
544
+ if (typeof this.__removeMetamorphs === "function") {
545
+ this.__removeMetamorphs();
546
+ }
547
+ this.container.html(htmlCallback());
548
+ return this.refreshElements();
549
+ },
550
+ swapContainer: function(container, data) {
551
+ container.unbind().off();
552
+ container.html(data);
553
+ return container;
554
+ },
555
+ __collectElements: function() {
556
+ var elements, klass;
557
+ elements = Object.extended(this.elements || {});
558
+ klass = this;
559
+ while (klass = klass.constructor.__super__) {
560
+ Joosy.Module.merge(elements, klass.elements, false);
561
+ }
562
+ return elements;
563
+ },
564
+ __collectEvents: function() {
565
+ var events, klass;
566
+ events = Object.extended(this.events || {});
567
+ klass = this;
568
+ while (klass = klass.constructor.__super__) {
569
+ Joosy.Module.merge(events, klass.events, false);
570
+ }
571
+ return events;
572
+ },
573
+ __extractSelector: function(selector) {
574
+ var r;
575
+ if (r = selector.match(/\$([A-z]+)/)) {
576
+ selector = this.__collectElements()[r[1]];
577
+ }
578
+ return selector;
579
+ },
580
+ __delegateEvents: function() {
581
+ var events, module,
582
+ _this = this;
583
+ module = this;
584
+ events = this.__collectEvents();
585
+ return events.each(function(key, method) {
586
+ var callback, eventName, match, selector;
587
+ if (!Object.isFunction(method)) {
588
+ method = _this[method];
589
+ }
590
+ callback = function(event) {
591
+ return method.call(module, this, event);
592
+ };
593
+ match = key.match(_this.eventSplitter);
594
+ eventName = match[1];
595
+ selector = _this.__extractSelector(match[2]);
596
+ if (selector === "") {
597
+ _this.container.bind(eventName, callback);
598
+ return Joosy.Modules.Log.debugAs(_this, "" + eventName + " binded on container");
599
+ } else if (selector === void 0) {
600
+ throw new Error("Unknown element " + match[2] + " in " + (Joosy.Module.__className(_this.constructor)) + " (maybe typo?)");
601
+ } else {
602
+ _this.container.on(eventName, selector, callback);
603
+ return Joosy.Modules.Log.debugAs(_this, "" + eventName + " binded on " + selector);
604
+ }
605
+ });
606
+ }
607
+ };
608
+
609
+
610
+ /*** src/joosy/core/form ***/
611
+
612
+ var __hasProp = {}.hasOwnProperty,
613
+ __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; };
614
+
615
+ Joosy.Form = (function(_super) {
616
+ __extends(Form, _super);
617
+
618
+ Form.include(Joosy.Modules.Container);
619
+
620
+ Form.include(Joosy.Modules.Log);
621
+
622
+ Form.include(Joosy.Modules.Events);
623
+
624
+ Form.prototype.invalidationClass = 'field_with_errors';
625
+
626
+ Form.prototype.substitutions = {};
627
+
628
+ Form.prototype.elements = {
629
+ 'fields': 'input,select,textarea'
630
+ };
631
+
632
+ Form.submit = function(form, options) {
633
+ if (options == null) {
634
+ options = {};
635
+ }
636
+ form = new this(form, options);
637
+ form.container.submit();
638
+ form.unbind();
639
+ return null;
640
+ };
641
+
642
+ Form.attach = function() {
643
+ return (function(func, args, ctor) {
644
+ ctor.prototype = func.prototype;
645
+ var child = new ctor, result = func.apply(child, args);
646
+ return Object(result) === result ? result : child;
647
+ })(Joosy.Form, arguments, function(){});
648
+ };
649
+
650
+ function Form(form, options) {
651
+ var method, _ref,
652
+ _this = this;
653
+ if (options == null) {
654
+ options = {};
655
+ }
656
+ if (Object.isFunction(options)) {
657
+ this.success = options;
658
+ } else {
659
+ Object.each(options, function(key, value) {
660
+ return _this[key] = value;
661
+ });
662
+ }
663
+ this.container = $(form);
664
+ if (this.container.length === 0) {
665
+ return;
666
+ }
667
+ this.refreshElements();
668
+ this.__delegateEvents();
669
+ method = (_ref = this.container.get(0).getAttribute('method')) != null ? _ref.toLowerCase() : void 0;
670
+ if (method && !['get', 'post'].any(method)) {
671
+ this.__markMethod(method);
672
+ this.container.attr('method', 'POST');
673
+ }
674
+ this.container.ajaxForm({
675
+ dataType: 'json',
676
+ beforeSend: function() {
677
+ if (_this.__debounce.apply(_this, arguments)) {
678
+ return false;
679
+ }
680
+ _this.__before.apply(_this, arguments);
681
+ _this.__pending_request = true;
682
+ _this.debugAs(_this, 'beforeSend: pending_request = true');
683
+ return true;
684
+ },
685
+ success: function() {
686
+ _this.__pending_request = false;
687
+ _this.debugAs(_this, 'success: pending_request = false');
688
+ return _this.__success.apply(_this, arguments);
689
+ },
690
+ error: function() {
691
+ _this.__pending_request = false;
692
+ _this.debugAs(_this, 'error: pending_request = false');
693
+ return _this.__error.apply(_this, arguments);
694
+ },
695
+ xhr: function() {
696
+ var xhr;
697
+ xhr = $.ajaxSettings.xhr();
698
+ if ((xhr.upload != null) && _this.progress) {
699
+ xhr.upload.onprogress = function(event) {
700
+ if (event.lengthComputable) {
701
+ return _this.progress((event.position / event.total * 100).round(2));
702
+ }
703
+ };
704
+ }
705
+ return xhr;
706
+ }
707
+ });
708
+ if (this.resource != null) {
709
+ this.fill(this.resource, options);
710
+ delete this.resource;
711
+ }
712
+ if (this.action != null) {
713
+ this.container.attr('action', this.action);
714
+ this.container.attr('method', 'POST');
715
+ }
716
+ if (this.method != null) {
717
+ this.__markMethod(this.method);
718
+ }
719
+ }
720
+
721
+ Form.prototype.unbind = function() {
722
+ return this.container.unbind('submit').find('input:submit,input:image,button:submit').unbind('click');
723
+ };
724
+
725
+ Form.prototype.fill = function(resource, options) {
726
+ var data, filler, url,
727
+ _this = this;
728
+ if (Object.isFunction(resource.build)) {
729
+ resource = resource.build();
730
+ }
731
+ this.__resource = resource;
732
+ if ((options != null ? options.decorator : void 0) != null) {
733
+ data = options.decorator(resource.data);
734
+ } else {
735
+ data = resource.data;
736
+ }
737
+ filler = function(data, scope) {
738
+ if (data.__joosy_form_filler_lock) {
739
+ return;
740
+ }
741
+ data.__joosy_form_filler_lock = true;
742
+ Object.each(data, function(property, val) {
743
+ var entity, i, input, key, _i, _len, _ref, _results;
744
+ key = _this.concatFieldName(scope, property);
745
+ input = _this.$fields.filter("[name='" + key + "']:not(:file),[name='" + (key.underscore()) + "']:not(:file),[name='" + (key.camelize(false)) + "']:not(:file)");
746
+ if (input.length > 0) {
747
+ if (input.is(':checkbox')) {
748
+ if (val) {
749
+ input.attr('checked', 'checked');
750
+ } else {
751
+ input.removeAttr('checked');
752
+ }
753
+ } else if (input.is(':radio')) {
754
+ input.filter("[value='" + val + "']").attr('checked', 'checked');
755
+ } else {
756
+ input.val(val);
757
+ }
758
+ }
759
+ if (val instanceof Joosy.Resource.RESTCollection) {
760
+ _ref = val.data;
761
+ _results = [];
762
+ for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
763
+ entity = _ref[i];
764
+ _results.push(filler(entity.data, _this.concatFieldName(scope, "[" + property + "_attributes][" + i + "]")));
765
+ }
766
+ return _results;
767
+ } else if (val instanceof Joosy.Resource.REST) {
768
+ return filler(val.data, _this.concatFieldName(scope, "[" + property + "_attributes][0]"));
769
+ } else if (Object.isObject(val) || Object.isArray(val)) {
770
+ return filler(val, key);
771
+ } else {
772
+
773
+ }
774
+ });
775
+ return delete data.__joosy_form_filler_lock;
776
+ };
777
+ filler(data, resource.__entityName || options.resourceName);
778
+ $('input[name=_method]', this.container).remove();
779
+ if (resource.id()) {
780
+ this.__markMethod((options != null ? options.method : void 0) || 'PUT');
781
+ }
782
+ url = (options != null ? options.action : void 0) || (resource.id() != null ? resource.memberPath() : resource.collectionPath());
783
+ this.container.attr('action', url);
784
+ return this.container.attr('method', 'POST');
785
+ };
786
+
787
+ Form.prototype.submit = function() {
788
+ return this.container.submit();
789
+ };
790
+
791
+ Form.prototype.serialize = function(skipMethod) {
792
+ var data;
793
+ if (skipMethod == null) {
794
+ skipMethod = true;
795
+ }
796
+ data = this.container.serialize();
797
+ if (skipMethod) {
798
+ data = data.replace(/\&?\_method\=put/i, '');
799
+ }
800
+ return data;
801
+ };
802
+
803
+ Form.prototype.__success = function(response, status, xhr) {
804
+ var _ref;
805
+ if (xhr) {
806
+ return typeof this.success === "function" ? this.success(response) : void 0;
807
+ } else if ((200 <= (_ref = response.status) && _ref < 300)) {
808
+ return this.success(response.json);
809
+ } else {
810
+ return this.__error(response.json);
811
+ }
812
+ };
813
+
814
+ Form.prototype.__before = function(xhr, settings) {
815
+ if ((this.before == null) || this.before.apply(this, arguments) === true) {
816
+ return this.$fields.removeClass(this.invalidationClass);
817
+ }
818
+ };
819
+
820
+ Form.prototype.__error = function(data) {
821
+ var error, errors,
822
+ _this = this;
823
+ errors = (function() {
824
+ if (data.responseText) {
825
+ try {
826
+ return data = jQuery.parseJSON(data.responseText);
827
+ } catch (_error) {
828
+ error = _error;
829
+ return {};
830
+ }
831
+ } else {
832
+ return data;
833
+ }
834
+ })();
835
+ if ((this.error == null) || this.error(errors) === true) {
836
+ errors = this.__stringifyErrors(errors);
837
+ Object.each(errors, function(field, notifications) {
838
+ var input;
839
+ input = _this.findField(field).addClass(_this.invalidationClass);
840
+ return typeof _this.notification === "function" ? _this.notification(input, notifications) : void 0;
841
+ });
842
+ return errors;
843
+ }
844
+ return false;
845
+ };
846
+
847
+ Form.prototype.__debounce = function(xhr) {
848
+ this.debugAs(this, "debounce: pending_request == " + this.__pending_request);
849
+ if (this.__pending_request && this.debounce !== false) {
850
+ if (this.debounce || Joosy.Application.debounceForms) {
851
+ xhr.abort();
852
+ this.debugAs(this, "debounce: xhr aborted");
853
+ return true;
854
+ }
855
+ }
856
+ return false;
857
+ };
858
+
859
+ Form.prototype.findField = function(field) {
860
+ return this.$fields.filter("[name='" + field + "']");
861
+ };
862
+
863
+ Form.prototype.__markMethod = function(method) {
864
+ if (method == null) {
865
+ method = 'PUT';
866
+ }
867
+ method = $('<input/>', {
868
+ type: 'hidden',
869
+ name: '_method',
870
+ value: method
871
+ });
872
+ return this.container.append(method);
873
+ };
874
+
875
+ Form.prototype.__stringifyErrors = function(errors) {
876
+ var result,
877
+ _this = this;
878
+ result = {};
879
+ Object.each(errors, function(field, notifications) {
880
+ var f, name, splited, _i, _len;
881
+ if (_this.substitutions[field] != null) {
882
+ field = _this.substitutions[field];
883
+ }
884
+ if (Object.isObject(notifications) || _this.isArrayOfObjects(notifications)) {
885
+ return Object.each(_this.__foldInlineEntities(notifications), function(key, value) {
886
+ return result[field + key] = value;
887
+ });
888
+ } else {
889
+ if (field.indexOf(".") !== -1) {
890
+ splited = field.split('.');
891
+ field = splited.shift();
892
+ if (_this.resourceName || _this.__resource) {
893
+ name = _this.resourceName || _this.__resource.__entityName;
894
+ field = name + ("[" + field + "]");
895
+ }
896
+ for (_i = 0, _len = splited.length; _i < _len; _i++) {
897
+ f = splited[_i];
898
+ field += "[" + f + "]";
899
+ }
900
+ } else if (_this.resourceName || _this.__resource) {
901
+ name = _this.resourceName || _this.__resource.__entityName;
902
+ field = name + ("[" + field + "]");
903
+ }
904
+ return result[field] = notifications;
905
+ }
906
+ });
907
+ return result;
908
+ };
909
+
910
+ Form.prototype.__foldInlineEntities = function(hash, scope, result) {
911
+ var _this = this;
912
+ if (scope == null) {
913
+ scope = "";
914
+ }
915
+ if (result == null) {
916
+ result = {};
917
+ }
918
+ Object.each(hash, function(key, value) {
919
+ if (Object.isObject(value) || _this.isArrayOfObjects(value)) {
920
+ return _this.__foldInlineEntities(value, "" + scope + "[" + key + "]", result);
921
+ } else {
922
+ return result["" + scope + "[" + key + "]"] = value;
923
+ }
924
+ });
925
+ return result;
926
+ };
927
+
928
+ Form.prototype.concatFieldName = function(wrapper, name) {
929
+ var items;
930
+ items = this.splitFieldName(wrapper).concat(this.splitFieldName(name));
931
+ return "" + items[0] + "[" + (items.slice(1).join('][')) + "]";
932
+ };
933
+
934
+ Form.prototype.splitFieldName = function(name) {
935
+ var first, items;
936
+ items = name.split('][');
937
+ first = items[0].split('[');
938
+ if (first.length === 2) {
939
+ if (first[0].isBlank()) {
940
+ items.splice(0, 1, first[1]);
941
+ } else {
942
+ items.splice(0, 1, first[0], first[1]);
943
+ }
944
+ items[items.length - 1] = items[items.length - 1].split(']')[0];
945
+ }
946
+ return items;
947
+ };
948
+
949
+ Form.prototype.isArrayOfObjects = function(array) {
950
+ return Object.isArray(array) && array.every(function(elem) {
951
+ return Object.isObject(elem);
952
+ });
953
+ };
954
+
955
+ return Form;
956
+
957
+ })(Joosy.Module);
958
+
959
+
960
+ /*** src/joosy/core/helpers/form ***/
961
+
962
+ Joosy.helpers('Application', function() {
963
+ var Form, description, input,
964
+ _this = this;
965
+ description = function(resource, method, extendIds, idSuffix) {
966
+ var id;
967
+ if (Joosy.Module.hasAncestor(resource.constructor, Joosy.Resource.Generic)) {
968
+ id = resource.id();
969
+ resource = resource.__entityName;
970
+ }
971
+ return {
972
+ name: resource + ("" + (method.match(/^\[.*\]$/) ? method : "[" + method + "]")),
973
+ id: resource + (id && extendIds ? '_' + id : '') + ("_" + (method.parameterize().underscore())) + (idSuffix ? '_' + idSuffix : '')
974
+ };
975
+ };
976
+ input = function(type, resource, method, options) {
977
+ var d;
978
+ if (options == null) {
979
+ options = {};
980
+ }
981
+ d = description(resource, method, options.extendIds, options.idSuffix);
982
+ delete options.extendIds;
983
+ delete options.idSuffix;
984
+ return _this.tag('input', Joosy.Module.merge({
985
+ type: type,
986
+ name: d.name,
987
+ id: d.id
988
+ }, options));
989
+ };
990
+ Form = (function() {
991
+ function Form(context, resource, options) {
992
+ this.context = context;
993
+ this.resource = resource;
994
+ this.options = options;
995
+ }
996
+
997
+ Form.prototype.label = function(method, options, content) {
998
+ if (options == null) {
999
+ options = {};
1000
+ }
1001
+ if (content == null) {
1002
+ content = '';
1003
+ }
1004
+ if (!Object.isObject(options)) {
1005
+ content = options;
1006
+ options = {};
1007
+ }
1008
+ return this.context.label(this.resource, method, Joosy.Module.merge({
1009
+ extendIds: this.options.extendIds
1010
+ }, options), content);
1011
+ };
1012
+
1013
+ Form.prototype.radioButton = function(method, tagValue, options) {
1014
+ if (options == null) {
1015
+ options = {};
1016
+ }
1017
+ return this.context.radioButton(this.resource, method, tagValue, Joosy.Module.merge({
1018
+ extendIds: this.options.extendIds
1019
+ }, options));
1020
+ };
1021
+
1022
+ Form.prototype.textArea = function(method, options) {
1023
+ if (options == null) {
1024
+ options = {};
1025
+ }
1026
+ return this.context.textArea(this.resource, method, Joosy.Module.merge({
1027
+ extendIds: this.options.extendIds
1028
+ }, options));
1029
+ };
1030
+
1031
+ Form.prototype.checkBox = function(method, options, checkedValue, uncheckedValue) {
1032
+ if (options == null) {
1033
+ options = {};
1034
+ }
1035
+ if (checkedValue == null) {
1036
+ checkedValue = 1;
1037
+ }
1038
+ if (uncheckedValue == null) {
1039
+ uncheckedValue = 0;
1040
+ }
1041
+ return this.context.checkBox(this.resource, method, Joosy.Module.merge({
1042
+ extendIds: this.options.extendIds
1043
+ }, options), checkedValue, uncheckedValue);
1044
+ };
1045
+
1046
+ Form.prototype.select = function(method, options, htmlOptions) {
1047
+ if (options == null) {
1048
+ options = {};
1049
+ }
1050
+ if (htmlOptions == null) {
1051
+ htmlOptions = {};
1052
+ }
1053
+ return this.context.select(this.resource, method, options, Joosy.Module.merge({
1054
+ extendIds: this.options.extendIds
1055
+ }, htmlOptions));
1056
+ };
1057
+
1058
+ return Form;
1059
+
1060
+ })();
1061
+ ['text', 'file', 'hidden', 'password'].each(function(type) {
1062
+ return Form.prototype[type + 'Field'] = function(method, options) {
1063
+ if (options == null) {
1064
+ options = {};
1065
+ }
1066
+ return this.context[type + 'Field'](this.resource, method, Joosy.Module.merge({
1067
+ extendIds: this.options.extendIds
1068
+ }, options));
1069
+ };
1070
+ });
1071
+ this.formFor = function(resource, options, block) {
1072
+ var form, uuid;
1073
+ if (options == null) {
1074
+ options = {};
1075
+ }
1076
+ if (Object.isFunction(options)) {
1077
+ block = options;
1078
+ options = {};
1079
+ }
1080
+ uuid = Joosy.uuid();
1081
+ form = this.tag('form', Joosy.Module.merge(options.html || {}, {
1082
+ id: uuid
1083
+ }), block != null ? block.call(this, new Form(this, resource, options)) : void 0);
1084
+ if (typeof this.onRefresh === "function") {
1085
+ this.onRefresh(function() {
1086
+ return Joosy.Form.attach('#' + uuid, Joosy.Module.merge(options, {
1087
+ resource: resource
1088
+ }));
1089
+ });
1090
+ }
1091
+ return form;
1092
+ };
1093
+ this.label = function(resource, method, options, content) {
1094
+ var d;
1095
+ if (options == null) {
1096
+ options = {};
1097
+ }
1098
+ if (content == null) {
1099
+ content = '';
1100
+ }
1101
+ if (!Object.isObject(options)) {
1102
+ content = options;
1103
+ options = {};
1104
+ }
1105
+ d = description(resource, method, options.extendIds);
1106
+ delete options.extendIds;
1107
+ return this.tag('label', Joosy.Module.merge(options, {
1108
+ "for": d.id
1109
+ }), content);
1110
+ };
1111
+ ['text', 'file', 'hidden', 'password'].each(function(type) {
1112
+ return _this[type + 'Field'] = function(resource, method, options) {
1113
+ if (options == null) {
1114
+ options = {};
1115
+ }
1116
+ return input(type, resource, method, options);
1117
+ };
1118
+ });
1119
+ this.radioButton = function(resource, method, tagValue, options) {
1120
+ if (options == null) {
1121
+ options = {};
1122
+ }
1123
+ return input('radio', resource, method, Joosy.Module.merge({
1124
+ value: tagValue,
1125
+ idSuffix: tagValue
1126
+ }, options));
1127
+ };
1128
+ this.checkBox = function(resource, method, options, checkedValue, uncheckedValue) {
1129
+ var box, spy;
1130
+ if (options == null) {
1131
+ options = {};
1132
+ }
1133
+ if (checkedValue == null) {
1134
+ checkedValue = 1;
1135
+ }
1136
+ if (uncheckedValue == null) {
1137
+ uncheckedValue = 0;
1138
+ }
1139
+ spy = this.tag('input', Joosy.Module.merge({
1140
+ name: description(resource, method).name,
1141
+ value: uncheckedValue,
1142
+ type: 'hidden'
1143
+ }));
1144
+ box = input('checkbox', resource, method, Joosy.Module.merge({
1145
+ value: checkedValue
1146
+ }, options));
1147
+ return spy + box;
1148
+ };
1149
+ this.select = function(resource, method, options, htmlOptions) {
1150
+ var extendIds, key, opts, val,
1151
+ _this = this;
1152
+ if (Object.isObject(options)) {
1153
+ opts = [];
1154
+ for (key in options) {
1155
+ val = options[key];
1156
+ opts.push([val, key]);
1157
+ }
1158
+ } else {
1159
+ opts = options;
1160
+ }
1161
+ if (htmlOptions.includeBlank) {
1162
+ delete htmlOptions.includeBlank;
1163
+ opts.unshift(['', '']);
1164
+ }
1165
+ opts = opts.reduce(function(str, vals) {
1166
+ var params;
1167
+ params = Object.isArray(vals) ? [
1168
+ 'option', {
1169
+ value: vals[1]
1170
+ }, vals[0]
1171
+ ] : ['option', {}, vals];
1172
+ if (htmlOptions.value === (Object.isArray(vals) ? vals[1] : vals)) {
1173
+ params[1].selected = 'selected';
1174
+ }
1175
+ return str += _this.tag.apply(_this, params);
1176
+ }, '');
1177
+ extendIds = htmlOptions.extendIds;
1178
+ delete htmlOptions.value;
1179
+ delete htmlOptions.extendIds;
1180
+ return this.tag('select', Joosy.Module.merge(description(resource, method, extendIds), htmlOptions), opts);
1181
+ };
1182
+ return this.textArea = function(resource, method, options) {
1183
+ var extendIds, value;
1184
+ if (options == null) {
1185
+ options = {};
1186
+ }
1187
+ value = options.value;
1188
+ extendIds = options.extendIds;
1189
+ delete options.value;
1190
+ delete options.extendIds;
1191
+ return this.tag('textarea', Joosy.Module.merge(description(resource, method, extendIds), options), value);
1192
+ };
1193
+ });
1194
+
1195
+
1196
+ /*** src/joosy/core/helpers/view ***/
1197
+
1198
+ Joosy.helpers('Application', function() {
1199
+ this.tag = function(name, options, content) {
1200
+ var e, element, temp;
1201
+ if (options == null) {
1202
+ options = {};
1203
+ }
1204
+ if (content == null) {
1205
+ content = '';
1206
+ }
1207
+ if (Object.isFunction(content)) {
1208
+ content = content();
1209
+ }
1210
+ element = document.createElement(name);
1211
+ temp = document.createElement('div');
1212
+ Object.each(options, function(name, value) {
1213
+ return element.setAttribute(name, value);
1214
+ });
1215
+ try {
1216
+ element.innerHTML = content;
1217
+ } catch (_error) {
1218
+ e = _error;
1219
+ if (content) {
1220
+ throw e;
1221
+ }
1222
+ }
1223
+ temp.appendChild(element);
1224
+ return temp.innerHTML;
1225
+ };
1226
+ this.nl2br = function(text) {
1227
+ return text.toString().replace(/\n/g, '<br/>');
1228
+ };
1229
+ return this.renderWrapped = function(template, lambda) {
1230
+ return this.render(template, Joosy.Module.merge(this, {
1231
+ "yield": lambda()
1232
+ }));
1233
+ };
1234
+ });
1235
+
1236
+
1237
+ /*** src/joosy/core/helpers/widgets ***/
1238
+
1239
+ Joosy.helpers('Application', function() {
1240
+ return this.widget = function(element, widget) {
1241
+ var params, parts, uuid;
1242
+ uuid = Joosy.uuid();
1243
+ params = {
1244
+ id: uuid
1245
+ };
1246
+ parts = element.split('.');
1247
+ if (parts[1]) {
1248
+ params["class"] = parts.from(1).join(' ');
1249
+ }
1250
+ element = this.tag(parts[0], params);
1251
+ this.onRefresh(function() {
1252
+ return this.registerWidget('#' + uuid, widget);
1253
+ });
1254
+ return element;
1255
+ };
1256
+ });
1257
+
1258
+
1259
+ /*** src/joosy/core/templaters/rails_jst ***/
1260
+
1261
+ Joosy.Templaters.RailsJST = (function() {
1262
+ function RailsJST(applicationName) {
1263
+ this.applicationName = applicationName;
1264
+ }
1265
+
1266
+ RailsJST.prototype.buildView = function(name) {
1267
+ var haystack, template;
1268
+ template = false;
1269
+ haystack = ["" + this.applicationName + "/templates/" + name + "-" + (typeof I18n !== "undefined" && I18n !== null ? I18n.locale : void 0), "" + this.applicationName + "/templates/" + name, "templates/" + name + "-" + (typeof I18n !== "undefined" && I18n !== null ? I18n.locale : void 0), "templates/" + name];
1270
+ haystack.each(function(path) {
1271
+ var location;
1272
+ if (JST[path]) {
1273
+ location = path;
1274
+ return template = JST[path];
1275
+ }
1276
+ });
1277
+ if (!template) {
1278
+ throw new Error("Template '" + name + "' not found. Checked at: " + location);
1279
+ }
1280
+ return template;
1281
+ };
1282
+
1283
+ RailsJST.prototype.resolveTemplate = function(section, template, entity) {
1284
+ var path, _ref, _ref1;
1285
+ if (template.startsWith('/')) {
1286
+ return template.substr(1);
1287
+ }
1288
+ path = ((_ref = entity.constructor) != null ? (_ref1 = _ref.__namespace__) != null ? _ref1.map('underscore') : void 0 : void 0) || [];
1289
+ path.unshift(section);
1290
+ return "" + (path.join('/')) + "/" + template;
1291
+ };
1292
+
1293
+ return RailsJST;
1294
+
1295
+ })();
1296
+
1297
+
1298
+ /*** src/vendor/metamorph ***/
1299
+
1300
+ (function(window) {
1301
+ var K, Metamorph, afterFunc, appendToFunc, document, endTagFunc, findChildById, firstNodeFor, fixParentage, guid, htmlFunc, movesWhitespace, needsShy, outerHTMLFunc, prependFunc, rangeFor, realNode, removeFunc, setInnerHTML, startTagFunc, supportsRange, wrapMap;
1302
+ K = function() {};
1303
+ guid = 0;
1304
+ document = window.document;
1305
+ supportsRange = document && ("createRange" in document) && (typeof Range !== "undefined") && Range.prototype.createContextualFragment;
1306
+ needsShy = document && (function() {
1307
+ var testEl;
1308
+ testEl = document.createElement("div");
1309
+ testEl.innerHTML = "<div></div>";
1310
+ testEl.firstChild.innerHTML = "<script></script>";
1311
+ return testEl.firstChild.innerHTML === "";
1312
+ })();
1313
+ movesWhitespace = document && (function() {
1314
+ var testEl;
1315
+ testEl = document.createElement("div");
1316
+ testEl.innerHTML = "Test: <script type='text/x-placeholder'></script>Value";
1317
+ return testEl.childNodes[0].nodeValue === "Test:" && testEl.childNodes[2].nodeValue === " Value";
1318
+ })();
1319
+ Metamorph = function(html) {
1320
+ var myGuid, self;
1321
+ self = void 0;
1322
+ if (this instanceof Metamorph) {
1323
+ self = this;
1324
+ } else {
1325
+ self = new K();
1326
+ }
1327
+ self.innerHTML = html;
1328
+ myGuid = "metamorph-" + (guid++);
1329
+ self.start = myGuid + "-start";
1330
+ self.end = myGuid + "-end";
1331
+ return self;
1332
+ };
1333
+ K.prototype = Metamorph.prototype;
1334
+ rangeFor = void 0;
1335
+ htmlFunc = void 0;
1336
+ removeFunc = void 0;
1337
+ outerHTMLFunc = void 0;
1338
+ appendToFunc = void 0;
1339
+ afterFunc = void 0;
1340
+ prependFunc = void 0;
1341
+ startTagFunc = void 0;
1342
+ endTagFunc = void 0;
1343
+ outerHTMLFunc = function() {
1344
+ return this.startTag() + this.innerHTML + this.endTag();
1345
+ };
1346
+ startTagFunc = function() {
1347
+ return "<script id='" + this.start + "' type='text/x-placeholder'></script>";
1348
+ };
1349
+ endTagFunc = function() {
1350
+ return "<script id='" + this.end + "' type='text/x-placeholder'></script>";
1351
+ };
1352
+ if (supportsRange) {
1353
+ rangeFor = function(morph, outerToo) {
1354
+ var after, before, range;
1355
+ range = document.createRange();
1356
+ before = document.getElementById(morph.start);
1357
+ after = document.getElementById(morph.end);
1358
+ if (outerToo) {
1359
+ range.setStartBefore(before);
1360
+ range.setEndAfter(after);
1361
+ } else {
1362
+ range.setStartAfter(before);
1363
+ range.setEndBefore(after);
1364
+ }
1365
+ return range;
1366
+ };
1367
+ htmlFunc = function(html, outerToo) {
1368
+ var fragment, range;
1369
+ range = rangeFor(this, outerToo);
1370
+ range.deleteContents();
1371
+ fragment = range.createContextualFragment(html);
1372
+ return range.insertNode(fragment);
1373
+ };
1374
+ removeFunc = function() {
1375
+ var range;
1376
+ range = rangeFor(this, true);
1377
+ return range.deleteContents();
1378
+ };
1379
+ appendToFunc = function(node) {
1380
+ var frag, range;
1381
+ range = document.createRange();
1382
+ range.setStart(node);
1383
+ range.collapse(false);
1384
+ frag = range.createContextualFragment(this.outerHTML());
1385
+ return node.appendChild(frag);
1386
+ };
1387
+ afterFunc = function(html) {
1388
+ var after, fragment, range;
1389
+ range = document.createRange();
1390
+ after = document.getElementById(this.end);
1391
+ range.setStartAfter(after);
1392
+ range.setEndAfter(after);
1393
+ fragment = range.createContextualFragment(html);
1394
+ return range.insertNode(fragment);
1395
+ };
1396
+ prependFunc = function(html) {
1397
+ var fragment, range, start;
1398
+ range = document.createRange();
1399
+ start = document.getElementById(this.start);
1400
+ range.setStartAfter(start);
1401
+ range.setEndAfter(start);
1402
+ fragment = range.createContextualFragment(html);
1403
+ return range.insertNode(fragment);
1404
+ };
1405
+ } else {
1406
+ /*
1407
+ This code is mostly taken from jQuery, with one exception. In jQuery's case, we
1408
+ have some HTML and we need to figure out how to convert it into some nodes.
1409
+
1410
+ In this case, jQuery needs to scan the HTML looking for an opening tag and use
1411
+ that as the key for the wrap map. In our case, we know the parent node, and
1412
+ can use its type as the key for the wrap map.
1413
+ */
1414
+
1415
+ wrapMap = {
1416
+ select: [1, "<select multiple='multiple'>", "</select>"],
1417
+ fieldset: [1, "<fieldset>", "</fieldset>"],
1418
+ table: [1, "<table>", "</table>"],
1419
+ tbody: [2, "<table><tbody>", "</tbody></table>"],
1420
+ tr: [3, "<table><tbody><tr>", "</tr></tbody></table>"],
1421
+ colgroup: [2, "<table><tbody></tbody><colgroup>", "</colgroup></table>"],
1422
+ map: [1, "<map>", "</map>"],
1423
+ _default: [0, "", ""]
1424
+ };
1425
+ findChildById = function(element, id) {
1426
+ var found, idx, len, node;
1427
+ if (element.getAttribute("id") === id) {
1428
+ return element;
1429
+ }
1430
+ len = element.childNodes.length;
1431
+ idx = void 0;
1432
+ node = void 0;
1433
+ found = void 0;
1434
+ idx = 0;
1435
+ while (idx < len) {
1436
+ node = element.childNodes[idx];
1437
+ found = node.nodeType === 1 && findChildById(node, id);
1438
+ if (found) {
1439
+ return found;
1440
+ }
1441
+ idx++;
1442
+ }
1443
+ };
1444
+ setInnerHTML = function(element, html) {
1445
+ var idx, len, matches, node, script, _results;
1446
+ matches = [];
1447
+ if (movesWhitespace) {
1448
+ html = html.replace(/(\s+)(<script id='([^']+)')/g, function(match, spaces, tag, id) {
1449
+ matches.push([id, spaces]);
1450
+ return tag;
1451
+ });
1452
+ }
1453
+ element.innerHTML = html;
1454
+ if (matches.length > 0) {
1455
+ len = matches.length;
1456
+ idx = void 0;
1457
+ idx = 0;
1458
+ _results = [];
1459
+ while (idx < len) {
1460
+ script = findChildById(element, matches[idx][0]);
1461
+ node = document.createTextNode(matches[idx][1]);
1462
+ script.parentNode.insertBefore(node, script);
1463
+ _results.push(idx++);
1464
+ }
1465
+ return _results;
1466
+ }
1467
+ };
1468
+ /*
1469
+ Given a parent node and some HTML, generate a set of nodes. Return the first
1470
+ node, which will allow us to traverse the rest using nextSibling.
1471
+
1472
+ We need to do this because innerHTML in IE does not really parse the nodes.
1473
+ */
1474
+
1475
+ firstNodeFor = function(parentNode, html) {
1476
+ var arr, depth, element, end, i, shyElement, start;
1477
+ arr = wrapMap[parentNode.tagName.toLowerCase()] || wrapMap._default;
1478
+ depth = arr[0];
1479
+ start = arr[1];
1480
+ end = arr[2];
1481
+ if (needsShy) {
1482
+ html = "&shy;" + html;
1483
+ }
1484
+ element = document.createElement("div");
1485
+ setInnerHTML(element, start + html + end);
1486
+ i = 0;
1487
+ while (i <= depth) {
1488
+ element = element.firstChild;
1489
+ i++;
1490
+ }
1491
+ if (needsShy) {
1492
+ shyElement = element;
1493
+ while (shyElement.nodeType === 1 && !shyElement.nodeName) {
1494
+ shyElement = shyElement.firstChild;
1495
+ }
1496
+ if (shyElement.nodeType === 3 && shyElement.nodeValue.charAt(0) === "­") {
1497
+ shyElement.nodeValue = shyElement.nodeValue.slice(1);
1498
+ }
1499
+ }
1500
+ return element;
1501
+ };
1502
+ /*
1503
+ In some cases, Internet Explorer can create an anonymous node in
1504
+ the hierarchy with no tagName. You can create this scenario via:
1505
+
1506
+ div = document.createElement("div");
1507
+ div.innerHTML = "<table>&shy<script></script><tr><td>hi</td></tr></table>";
1508
+ div.firstChild.firstChild.tagName //=> ""
1509
+
1510
+ If our script markers are inside such a node, we need to find that
1511
+ node and use *it* as the marker.
1512
+ */
1513
+
1514
+ realNode = function(start) {
1515
+ while (start.parentNode.tagName === "") {
1516
+ start = start.parentNode;
1517
+ }
1518
+ return start;
1519
+ };
1520
+ /*
1521
+ When automatically adding a tbody, Internet Explorer inserts the
1522
+ tbody immediately before the first <tr>. Other browsers create it
1523
+ before the first node, no matter what.
1524
+
1525
+ This means the the following code:
1526
+
1527
+ div = document.createElement("div");
1528
+ div.innerHTML = "<table><script id='first'></script><tr><td>hi</td></tr><script id='last'></script></table>
1529
+
1530
+ Generates the following DOM in IE:
1531
+
1532
+ + div
1533
+ + table
1534
+ - script id='first'
1535
+ + tbody
1536
+ + tr
1537
+ + td
1538
+ - "hi"
1539
+ - script id='last'
1540
+
1541
+ Which means that the two script tags, even though they were
1542
+ inserted at the same point in the hierarchy in the original
1543
+ HTML, now have different parents.
1544
+
1545
+ This code reparents the first script tag by making it the tbody's
1546
+ first child.
1547
+ */
1548
+
1549
+ fixParentage = function(start, end) {
1550
+ if (start.parentNode !== end.parentNode) {
1551
+ return end.parentNode.insertBefore(start, end.parentNode.firstChild);
1552
+ }
1553
+ };
1554
+ htmlFunc = function(html, outerToo) {
1555
+ var end, last, nextSibling, node, parentNode, start, _results;
1556
+ start = realNode(document.getElementById(this.start));
1557
+ end = document.getElementById(this.end);
1558
+ parentNode = end.parentNode;
1559
+ node = void 0;
1560
+ nextSibling = void 0;
1561
+ last = void 0;
1562
+ fixParentage(start, end);
1563
+ node = start.nextSibling;
1564
+ while (node) {
1565
+ nextSibling = node.nextSibling;
1566
+ last = node === end;
1567
+ if (last) {
1568
+ if (outerToo) {
1569
+ end = node.nextSibling;
1570
+ } else {
1571
+ break;
1572
+ }
1573
+ }
1574
+ node.parentNode.removeChild(node);
1575
+ if (last) {
1576
+ break;
1577
+ }
1578
+ node = nextSibling;
1579
+ }
1580
+ node = firstNodeFor(start.parentNode, html);
1581
+ _results = [];
1582
+ while (node) {
1583
+ nextSibling = node.nextSibling;
1584
+ parentNode.insertBefore(node, end);
1585
+ _results.push(node = nextSibling);
1586
+ }
1587
+ return _results;
1588
+ };
1589
+ removeFunc = function() {
1590
+ var end, start;
1591
+ start = realNode(document.getElementById(this.start));
1592
+ end = document.getElementById(this.end);
1593
+ this.html("");
1594
+ start.parentNode.removeChild(start);
1595
+ return end.parentNode.removeChild(end);
1596
+ };
1597
+ appendToFunc = function(parentNode) {
1598
+ var nextSibling, node, _results;
1599
+ node = firstNodeFor(parentNode, this.outerHTML());
1600
+ nextSibling = void 0;
1601
+ _results = [];
1602
+ while (node) {
1603
+ nextSibling = node.nextSibling;
1604
+ parentNode.appendChild(node);
1605
+ _results.push(node = nextSibling);
1606
+ }
1607
+ return _results;
1608
+ };
1609
+ afterFunc = function(html) {
1610
+ var end, insertBefore, nextSibling, node, parentNode, _results;
1611
+ end = document.getElementById(this.end);
1612
+ insertBefore = end.nextSibling;
1613
+ parentNode = end.parentNode;
1614
+ nextSibling = void 0;
1615
+ node = void 0;
1616
+ node = firstNodeFor(parentNode, html);
1617
+ _results = [];
1618
+ while (node) {
1619
+ nextSibling = node.nextSibling;
1620
+ parentNode.insertBefore(node, insertBefore);
1621
+ _results.push(node = nextSibling);
1622
+ }
1623
+ return _results;
1624
+ };
1625
+ prependFunc = function(html) {
1626
+ var insertBefore, nextSibling, node, parentNode, start, _results;
1627
+ start = document.getElementById(this.start);
1628
+ parentNode = start.parentNode;
1629
+ nextSibling = void 0;
1630
+ node = void 0;
1631
+ node = firstNodeFor(parentNode, html);
1632
+ insertBefore = start.nextSibling;
1633
+ _results = [];
1634
+ while (node) {
1635
+ nextSibling = node.nextSibling;
1636
+ parentNode.insertBefore(node, insertBefore);
1637
+ _results.push(node = nextSibling);
1638
+ }
1639
+ return _results;
1640
+ };
1641
+ }
1642
+ Metamorph.prototype.html = function(html) {
1643
+ this.checkRemoved();
1644
+ if (html === undefined) {
1645
+ return this.innerHTML;
1646
+ }
1647
+ htmlFunc.call(this, html);
1648
+ return this.innerHTML = html;
1649
+ };
1650
+ Metamorph.prototype.replaceWith = function(html) {
1651
+ this.checkRemoved();
1652
+ return htmlFunc.call(this, html, true);
1653
+ };
1654
+ Metamorph.prototype.remove = removeFunc;
1655
+ Metamorph.prototype.outerHTML = outerHTMLFunc;
1656
+ Metamorph.prototype.appendTo = appendToFunc;
1657
+ Metamorph.prototype.after = afterFunc;
1658
+ Metamorph.prototype.prepend = prependFunc;
1659
+ Metamorph.prototype.startTag = startTagFunc;
1660
+ Metamorph.prototype.endTag = endTagFunc;
1661
+ Metamorph.prototype.isRemoved = function() {
1662
+ var after, before;
1663
+ before = document.getElementById(this.start);
1664
+ after = document.getElementById(this.end);
1665
+ return !before || !after;
1666
+ };
1667
+ Metamorph.prototype.checkRemoved = function() {
1668
+ if (this.isRemoved()) {
1669
+ throw new Error("Cannot perform operations on a Metamorph that is not in the DOM.");
1670
+ }
1671
+ };
1672
+ return window.Metamorph = Metamorph;
1673
+ })(this);
1674
+
1675
+
1676
+ /*** src/joosy/core/modules/renderer ***/
1677
+
1678
+ var __slice = [].slice;
1679
+
1680
+ Joosy.Modules.Renderer = {
1681
+ __renderer: function() {
1682
+ throw new Error("" + (Joosy.Module.__className(this.constructor)) + " does not have an attached template");
1683
+ },
1684
+ __helpers: null,
1685
+ included: function() {
1686
+ this.view = function(template, options) {
1687
+ if (options == null) {
1688
+ options = {};
1689
+ }
1690
+ if (Object.isFunction(template)) {
1691
+ return this.prototype.__renderer = template;
1692
+ } else {
1693
+ return this.prototype.__renderer = function(locals) {
1694
+ if (locals == null) {
1695
+ locals = {};
1696
+ }
1697
+ if (options.dynamic) {
1698
+ return this.renderDynamic(template, locals);
1699
+ } else {
1700
+ return this.render(template, locals);
1701
+ }
1702
+ };
1703
+ }
1704
+ };
1705
+ return this.helpers = function() {
1706
+ var helpers, _base,
1707
+ _this = this;
1708
+ helpers = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
1709
+ (_base = this.prototype).__helpers || (_base.__helpers = []);
1710
+ helpers.map(function(helper) {
1711
+ var module;
1712
+ module = Joosy.Helpers[helper];
1713
+ if (!module) {
1714
+ throw new Error("Cannot find helper module " + helper);
1715
+ }
1716
+ return _this.prototype.__helpers.push(module);
1717
+ });
1718
+ return this.prototype.__helpers = this.prototype.__helpers.unique();
1719
+ };
1720
+ },
1721
+ __instantiateHelpers: function() {
1722
+ var helper, _i, _len, _ref,
1723
+ _this = this;
1724
+ if (!this.__helpersInstance) {
1725
+ this.__helpersInstance = Object.extended(Joosy.Helpers.Application);
1726
+ if (this.onRefresh) {
1727
+ this.__helpersInstance.onRefresh = function(callback) {
1728
+ return _this.onRefresh(callback);
1729
+ };
1730
+ }
1731
+ if (this.__helpers) {
1732
+ _ref = this.__helpers;
1733
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1734
+ helper = _ref[_i];
1735
+ Joosy.Module.merge(this.__helpersInstance, helper);
1736
+ }
1737
+ }
1738
+ }
1739
+ return this.__helpersInstance;
1740
+ },
1741
+ __proxifyHelpers: function(locals) {
1742
+ if (locals.hasOwnProperty('__proto__')) {
1743
+ locals.__proto__ = this.__instantiateHelpers();
1744
+ return locals;
1745
+ } else {
1746
+ if (!this.__helpersProxyInstance) {
1747
+ this.__helpersProxyInstance = function(locals) {
1748
+ return Joosy.Module.merge(this, locals);
1749
+ };
1750
+ this.__helpersProxyInstance.prototype = this.__instantiateHelpers();
1751
+ }
1752
+ return new this.__helpersProxyInstance(locals);
1753
+ }
1754
+ },
1755
+ render: function(template, locals, parentStackPointer) {
1756
+ if (locals == null) {
1757
+ locals = {};
1758
+ }
1759
+ if (parentStackPointer == null) {
1760
+ parentStackPointer = false;
1761
+ }
1762
+ return this.__render(false, template, locals, parentStackPointer);
1763
+ },
1764
+ renderDynamic: function(template, locals, parentStackPointer) {
1765
+ if (locals == null) {
1766
+ locals = {};
1767
+ }
1768
+ if (parentStackPointer == null) {
1769
+ parentStackPointer = false;
1770
+ }
1771
+ return this.__render(true, template, locals, parentStackPointer);
1772
+ },
1773
+ __render: function(dynamic, template, locals, parentStackPointer) {
1774
+ var assignContext, binding, context, isCollection, isResource, key, morph, object, renderers, resource, result, stack, update, _i, _len, _ref,
1775
+ _this = this;
1776
+ if (locals == null) {
1777
+ locals = {};
1778
+ }
1779
+ if (parentStackPointer == null) {
1780
+ parentStackPointer = false;
1781
+ }
1782
+ stack = this.__renderingStackChildFor(parentStackPointer);
1783
+ stack.template = template;
1784
+ stack.locals = locals;
1785
+ assignContext = false;
1786
+ isResource = Joosy.Module.hasAncestor(locals.constructor, Joosy.Resource.Generic);
1787
+ isCollection = Joosy.Module.hasAncestor(locals.constructor, Joosy.Resource.Collection);
1788
+ if (Object.isString(template)) {
1789
+ if (this.__renderSection != null) {
1790
+ template = Joosy.Application.templater.resolveTemplate(this.__renderSection(), template, this);
1791
+ }
1792
+ template = Joosy.Application.templater.buildView(template);
1793
+ } else if (Object.isFunction(template)) {
1794
+ assignContext = true;
1795
+ } else if (!Object.isFunction(template)) {
1796
+ throw new Error("" + (Joosy.Module.__className(this)) + "> template (maybe @view) does not look like a string or lambda");
1797
+ }
1798
+ if (!Object.isObject(locals) && Object.extended().constructor !== locals.constructor && !isResource && !isCollection) {
1799
+ throw new Error("" + (Joosy.Module.__className(this)) + "> locals (maybe @data?) not in: dumb hash, Resource, Collection");
1800
+ }
1801
+ renderers = {
1802
+ render: function(template, locals) {
1803
+ if (locals == null) {
1804
+ locals = {};
1805
+ }
1806
+ return _this.render(template, locals, stack);
1807
+ },
1808
+ renderDynamic: function(template, locals) {
1809
+ if (locals == null) {
1810
+ locals = {};
1811
+ }
1812
+ return _this.renderDynamic(template, locals, stack);
1813
+ },
1814
+ renderInline: function(locals, template) {
1815
+ if (locals == null) {
1816
+ locals = {};
1817
+ }
1818
+ return _this.renderDynamic(template, locals, stack);
1819
+ }
1820
+ };
1821
+ context = function() {
1822
+ var data;
1823
+ data = {};
1824
+ if (isResource) {
1825
+ Joosy.Module.merge(data, stack.locals.data);
1826
+ } else {
1827
+ Joosy.Module.merge(data, stack.locals);
1828
+ }
1829
+ Joosy.Module.merge(data, _this.__instantiateHelpers(), false);
1830
+ Joosy.Module.merge(data, renderers);
1831
+ return data;
1832
+ };
1833
+ result = function() {
1834
+ if (assignContext) {
1835
+ return template.call(context());
1836
+ } else {
1837
+ return template(context());
1838
+ }
1839
+ };
1840
+ if (dynamic) {
1841
+ morph = Metamorph(result());
1842
+ update = function() {
1843
+ var callback, child, object, _i, _j, _len, _len1, _ref, _ref1, _ref2, _results;
1844
+ if (morph.isRemoved()) {
1845
+ _ref = morph.__bindings;
1846
+ _results = [];
1847
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1848
+ _ref1 = _ref[_i], object = _ref1[0], callback = _ref1[1];
1849
+ _results.push(object.unbind(callback));
1850
+ }
1851
+ return _results;
1852
+ } else {
1853
+ _ref2 = stack.children;
1854
+ for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
1855
+ child = _ref2[_j];
1856
+ _this.__removeMetamorphs(child);
1857
+ }
1858
+ stack.children = [];
1859
+ morph.html(result());
1860
+ return typeof _this.refreshElements === "function" ? _this.refreshElements() : void 0;
1861
+ }
1862
+ };
1863
+ update = update.debounce(0);
1864
+ morph.__bindings = [];
1865
+ if (isCollection) {
1866
+ _ref = locals.data;
1867
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1868
+ resource = _ref[_i];
1869
+ binding = [resource, update];
1870
+ resource.bind('changed', update);
1871
+ stack.metamorphBindings.push(binding);
1872
+ morph.__bindings.push(binding);
1873
+ }
1874
+ }
1875
+ if (isResource || isCollection) {
1876
+ binding = [locals, update];
1877
+ locals.bind('changed', update);
1878
+ stack.metamorphBindings.push(binding);
1879
+ morph.__bindings.push(binding);
1880
+ } else {
1881
+ for (key in locals) {
1882
+ object = locals[key];
1883
+ if (locals.hasOwnProperty(key)) {
1884
+ if (((object != null ? object.bind : void 0) != null) && ((object != null ? object.unbind : void 0) != null)) {
1885
+ binding = [object, update];
1886
+ object.bind('changed', update);
1887
+ stack.metamorphBindings.push(binding);
1888
+ morph.__bindings.push(binding);
1889
+ }
1890
+ }
1891
+ }
1892
+ }
1893
+ return morph.outerHTML();
1894
+ } else {
1895
+ return result();
1896
+ }
1897
+ },
1898
+ __renderingStackElement: function(parent) {
1899
+ if (parent == null) {
1900
+ parent = null;
1901
+ }
1902
+ return {
1903
+ metamorphBindings: [],
1904
+ locals: null,
1905
+ template: null,
1906
+ children: [],
1907
+ parent: parent
1908
+ };
1909
+ },
1910
+ __renderingStackChildFor: function(parentPointer) {
1911
+ var element;
1912
+ if (!this.__renderingStack) {
1913
+ this.__renderingStack = [];
1914
+ }
1915
+ if (!parentPointer) {
1916
+ element = this.__renderingStackElement();
1917
+ this.__renderingStack.push(element);
1918
+ return element;
1919
+ } else {
1920
+ element = this.__renderingStackElement(parentPointer);
1921
+ parentPointer.children.push(element);
1922
+ return element;
1923
+ }
1924
+ },
1925
+ __removeMetamorphs: function(stackPointer) {
1926
+ var remove, _ref,
1927
+ _this = this;
1928
+ if (stackPointer == null) {
1929
+ stackPointer = false;
1930
+ }
1931
+ remove = function(stackPointer) {
1932
+ var callback, child, object, _i, _j, _len, _len1, _ref, _ref1, _ref2;
1933
+ if (stackPointer != null ? stackPointer.children : void 0) {
1934
+ _ref = stackPointer.children;
1935
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1936
+ child = _ref[_i];
1937
+ _this.__removeMetamorphs(child);
1938
+ }
1939
+ }
1940
+ if (stackPointer != null ? stackPointer.metamorphBindings : void 0) {
1941
+ _ref1 = stackPointer.metamorphBindings;
1942
+ for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
1943
+ _ref2 = _ref1[_j], object = _ref2[0], callback = _ref2[1];
1944
+ object.unbind(callback);
1945
+ }
1946
+ return stackPointer.metamorphBindings = [];
1947
+ }
1948
+ };
1949
+ if (!stackPointer) {
1950
+ return (_ref = this.__renderingStack) != null ? _ref.each(function(stackPointer) {
1951
+ return remove(stackPointer);
1952
+ }) : void 0;
1953
+ } else {
1954
+ return remove(stackPointer);
1955
+ }
1956
+ }
1957
+ };
1958
+
1959
+
1960
+ /*** src/joosy/core/modules/time_manager ***/
1961
+
1962
+ Joosy.Modules.TimeManager = {
1963
+ setTimeout: function(timeout, action) {
1964
+ var timer,
1965
+ _this = this;
1966
+ this.__timeouts || (this.__timeouts = []);
1967
+ timer = window.setTimeout((function() {
1968
+ return action();
1969
+ }), timeout);
1970
+ this.__timeouts.push(timer);
1971
+ return timer;
1972
+ },
1973
+ setInterval: function(delay, action) {
1974
+ var timer,
1975
+ _this = this;
1976
+ this.__intervals || (this.__intervals = []);
1977
+ timer = window.setInterval((function() {
1978
+ return action();
1979
+ }), delay);
1980
+ this.__intervals.push(timer);
1981
+ return timer;
1982
+ },
1983
+ __clearTime: function() {
1984
+ var entry, _i, _j, _len, _len1, _ref, _ref1, _results;
1985
+ if (this.__intervals) {
1986
+ _ref = this.__intervals;
1987
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1988
+ entry = _ref[_i];
1989
+ window.clearInterval(entry);
1990
+ }
1991
+ }
1992
+ if (this.__timeouts) {
1993
+ _ref1 = this.__timeouts;
1994
+ _results = [];
1995
+ for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
1996
+ entry = _ref1[_j];
1997
+ _results.push(window.clearTimeout(entry));
1998
+ }
1999
+ return _results;
2000
+ }
2001
+ }
2002
+ };
2003
+
2004
+
2005
+ /*** src/joosy/core/modules/widgets_manager ***/
2006
+
2007
+ Joosy.Modules.WidgetsManager = {
2008
+ registerWidget: function(container, widget) {
2009
+ if (Joosy.Module.hasAncestor(widget, Joosy.Widget)) {
2010
+ widget = new widget();
2011
+ }
2012
+ if (Object.isFunction(widget)) {
2013
+ widget = widget();
2014
+ }
2015
+ this.__activeWidgets || (this.__activeWidgets = []);
2016
+ this.__activeWidgets.push(widget.__load(this, $(container)));
2017
+ return widget;
2018
+ },
2019
+ unregisterWidget: function(widget) {
2020
+ widget.__unload();
2021
+ return this.__activeWidgets.splice(this.__activeWidgets.indexOf(widget), 1);
2022
+ },
2023
+ __collectWidgets: function() {
2024
+ var klass, widgets;
2025
+ widgets = Object.extended(this.widgets || {});
2026
+ klass = this;
2027
+ while (klass = klass.constructor.__super__) {
2028
+ Joosy.Module.merge(widgets, klass.widgets, false);
2029
+ }
2030
+ return widgets;
2031
+ },
2032
+ __setupWidgets: function() {
2033
+ var registered, widgets,
2034
+ _this = this;
2035
+ widgets = this.__collectWidgets();
2036
+ registered = Object.extended();
2037
+ widgets.each(function(selector, widget) {
2038
+ var activeSelector, r;
2039
+ if (selector === '$container') {
2040
+ activeSelector = _this.container;
2041
+ } else {
2042
+ if (r = selector.match(/\$([A-z_]+)/)) {
2043
+ selector = _this.elements[r[1]];
2044
+ }
2045
+ activeSelector = $(selector, _this.container);
2046
+ }
2047
+ registered[selector] = Object.extended();
2048
+ return activeSelector.each(function(index, elem) {
2049
+ var instance, _base, _name;
2050
+ if (Joosy.Module.hasAncestor(widget, Joosy.Widget)) {
2051
+ instance = new widget;
2052
+ } else {
2053
+ instance = widget.call(_this, index);
2054
+ }
2055
+ (_base = registered[selector])[_name = Joosy.Module.__className(instance)] || (_base[_name] = 0);
2056
+ registered[selector][Joosy.Module.__className(instance)] += 1;
2057
+ return _this.registerWidget($(elem), instance);
2058
+ });
2059
+ });
2060
+ return registered.each(function(selector, value) {
2061
+ return value.each(function(widget, count) {
2062
+ return Joosy.Modules.Log.debugAs(_this, "Widget " + widget + " registered at '" + selector + "'. Elements: " + count);
2063
+ });
2064
+ });
2065
+ },
2066
+ __unloadWidgets: function() {
2067
+ var widget, _i, _len, _ref, _results;
2068
+ if (this.__activeWidgets) {
2069
+ _ref = this.__activeWidgets;
2070
+ _results = [];
2071
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
2072
+ widget = _ref[_i];
2073
+ _results.push(widget.__unload());
2074
+ }
2075
+ return _results;
2076
+ }
2077
+ }
2078
+ };
2079
+
2080
+
2081
+ /*** src/joosy/core/modules/filters ***/
2082
+
2083
+ var _this = this,
2084
+ __slice = [].slice;
2085
+
2086
+ Joosy.Modules.Filters = {
2087
+ included: function() {
2088
+ var _this = this;
2089
+ return ['beforeLoad', 'afterLoad', 'afterUnload'].each(function(filter) {
2090
+ return _this[filter] = function(callback) {
2091
+ if (!this.prototype.hasOwnProperty("__" + filter + "s")) {
2092
+ this.prototype["__" + filter + "s"] = [].concat(this.__super__["__" + filter + "s"] || []);
2093
+ }
2094
+ return this.prototype["__" + filter + "s"].push(callback);
2095
+ };
2096
+ });
2097
+ }
2098
+ };
2099
+
2100
+ ['beforeLoad', 'afterLoad', 'afterUnload'].each(function(filter) {
2101
+ return Joosy.Modules.Filters["__run" + (filter.camelize(true)) + "s"] = function() {
2102
+ var opts,
2103
+ _this = this;
2104
+ opts = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
2105
+ if (!this["__" + filter + "s"]) {
2106
+ return true;
2107
+ }
2108
+ return this["__" + filter + "s"].reduce(function(flag, func) {
2109
+ if (!Object.isFunction(func)) {
2110
+ func = _this[func];
2111
+ }
2112
+ return flag && func.apply(_this, opts) !== false;
2113
+ }, true);
2114
+ };
2115
+ });
2116
+
2117
+
2118
+ /*** src/joosy/core/layout ***/
2119
+
2120
+ var __hasProp = {}.hasOwnProperty,
2121
+ __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; },
2122
+ __slice = [].slice;
2123
+
2124
+ Joosy.Layout = (function(_super) {
2125
+ __extends(Layout, _super);
2126
+
2127
+ Layout.include(Joosy.Modules.Log);
2128
+
2129
+ Layout.include(Joosy.Modules.Events);
2130
+
2131
+ Layout.include(Joosy.Modules.Container);
2132
+
2133
+ Layout.include(Joosy.Modules.Renderer);
2134
+
2135
+ Layout.include(Joosy.Modules.TimeManager);
2136
+
2137
+ Layout.include(Joosy.Modules.WidgetsManager);
2138
+
2139
+ Layout.include(Joosy.Modules.Filters);
2140
+
2141
+ Layout.view('default');
2142
+
2143
+ Layout.beforePaint = function(callback) {
2144
+ return this.prototype.__beforePaint = callback;
2145
+ };
2146
+
2147
+ Layout.paint = function(callback) {
2148
+ return this.prototype.__paint = callback;
2149
+ };
2150
+
2151
+ Layout.erase = function(callback) {
2152
+ return this.prototype.__erase = callback;
2153
+ };
2154
+
2155
+ Layout.fetch = function(callback) {
2156
+ return this.prototype.__fetch = function(complete) {
2157
+ var _this = this;
2158
+ this.data = {};
2159
+ return callback.call(this, function() {
2160
+ _this.dataFetched = true;
2161
+ return complete();
2162
+ });
2163
+ };
2164
+ };
2165
+
2166
+ Layout.prototype.data = false;
2167
+
2168
+ Layout.prototype.dataFetched = false;
2169
+
2170
+ function Layout(params) {
2171
+ this.params = params;
2172
+ }
2173
+
2174
+ Layout.prototype.navigate = function() {
2175
+ var args, _ref;
2176
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
2177
+ return (_ref = Joosy.Router).navigate.apply(_ref, args);
2178
+ };
2179
+
2180
+ Layout.prototype.__renderSection = function() {
2181
+ return 'layouts';
2182
+ };
2183
+
2184
+ Layout.prototype.__load = function(container) {
2185
+ this.container = container;
2186
+ this.refreshElements();
2187
+ this.__delegateEvents();
2188
+ this.__setupWidgets();
2189
+ return this.__runAfterLoads();
2190
+ };
2191
+
2192
+ Layout.prototype.__unload = function() {
2193
+ this.__clearTime();
2194
+ this.__unloadWidgets();
2195
+ this.__removeMetamorphs();
2196
+ return this.__runAfterUnloads();
2197
+ };
2198
+
2199
+ Layout.prototype["yield"] = function() {
2200
+ return this.uuid = Joosy.uuid();
2201
+ };
2202
+
2203
+ Layout.prototype.content = function() {
2204
+ return $("#" + this.uuid);
2205
+ };
2206
+
2207
+ return Layout;
2208
+
2209
+ })(Joosy.Module);
2210
+
2211
+
2212
+ /*** src/joosy/core/page ***/
2213
+
2214
+ var __hasProp = {}.hasOwnProperty,
2215
+ __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; },
2216
+ __slice = [].slice;
2217
+
2218
+ Joosy.Page = (function(_super) {
2219
+ __extends(Page, _super);
2220
+
2221
+ Page.include(Joosy.Modules.Log);
2222
+
2223
+ Page.include(Joosy.Modules.Events);
2224
+
2225
+ Page.include(Joosy.Modules.Container);
2226
+
2227
+ Page.include(Joosy.Modules.Renderer);
2228
+
2229
+ Page.include(Joosy.Modules.TimeManager);
2230
+
2231
+ Page.include(Joosy.Modules.WidgetsManager);
2232
+
2233
+ Page.include(Joosy.Modules.Filters);
2234
+
2235
+ Page.prototype.halted = false;
2236
+
2237
+ Page.prototype.layout = false;
2238
+
2239
+ Page.prototype.previous = false;
2240
+
2241
+ Page.prototype.params = false;
2242
+
2243
+ Page.prototype.data = false;
2244
+
2245
+ Page.prototype.dataFetched = false;
2246
+
2247
+ Page.layout = function(layoutClass) {
2248
+ return this.prototype.__layoutClass = layoutClass;
2249
+ };
2250
+
2251
+ Page.beforePaint = function(callback) {
2252
+ return this.prototype.__beforePaint = callback;
2253
+ };
2254
+
2255
+ Page.paint = function(callback) {
2256
+ return this.prototype.__paint = callback;
2257
+ };
2258
+
2259
+ Page.afterPaint = function(callback) {
2260
+ return this.prototype.__afterPaint = callback;
2261
+ };
2262
+
2263
+ Page.erase = function(callback) {
2264
+ return this.prototype.__erase = callback;
2265
+ };
2266
+
2267
+ Page.fetch = function(callback) {
2268
+ return this.prototype.__fetch = function(complete) {
2269
+ var _this = this;
2270
+ this.data = {};
2271
+ return callback.call(this, function() {
2272
+ _this.dataFetched = true;
2273
+ return complete();
2274
+ });
2275
+ };
2276
+ };
2277
+
2278
+ Page.fetchSynchronized = function(callback) {
2279
+ return this.prototype.__fetch = function(complete) {
2280
+ return this.synchronize(function(context) {
2281
+ context.after(function() {
2282
+ return complete();
2283
+ });
2284
+ return callback.call(this, context);
2285
+ });
2286
+ };
2287
+ };
2288
+
2289
+ Page.scroll = function(element, options) {
2290
+ if (options == null) {
2291
+ options = {};
2292
+ }
2293
+ this.prototype.__scrollElement = element;
2294
+ this.prototype.__scrollSpeed = options.speed || 500;
2295
+ return this.prototype.__scrollMargin = options.margin || 0;
2296
+ };
2297
+
2298
+ Page.prototype.__performScrolling = function() {
2299
+ var scroll, _ref,
2300
+ _this = this;
2301
+ scroll = ((_ref = $(this.__extractSelector(this.__scrollElement)).offset()) != null ? _ref.top : void 0) + this.__scrollMargin;
2302
+ Joosy.Modules.Log.debugAs(this, "Scrolling to " + (this.__extractSelector(this.__scrollElement)));
2303
+ return $('html, body').animate({
2304
+ scrollTop: scroll
2305
+ }, this.__scrollSpeed, function() {
2306
+ if (_this.__scrollSpeed !== 0) {
2307
+ return _this.__releaseHeight();
2308
+ }
2309
+ });
2310
+ };
2311
+
2312
+ Page.title = function(title, separator) {
2313
+ if (separator == null) {
2314
+ separator = ' / ';
2315
+ }
2316
+ this.afterLoad(function() {
2317
+ var titleStr;
2318
+ titleStr = Object.isFunction(title) ? title.apply(this) : title;
2319
+ if (Object.isArray(titleStr)) {
2320
+ titleStr = titleStr.join(separator);
2321
+ }
2322
+ this.__previousTitle = document.title;
2323
+ return document.title = titleStr;
2324
+ });
2325
+ return this.afterUnload(function() {
2326
+ return document.title = this.__previousTitle;
2327
+ });
2328
+ };
2329
+
2330
+ function Page(params, previous) {
2331
+ var _ref, _ref1, _ref2;
2332
+ this.params = params;
2333
+ this.previous = previous;
2334
+ this.__layoutClass || (this.__layoutClass = ApplicationLayout);
2335
+ if (!(this.halted = !this.__runBeforeLoads(this.params, this.previous))) {
2336
+ Joosy.Application.loading = true;
2337
+ if ((((_ref = this.previous) != null ? (_ref1 = _ref.layout) != null ? _ref1.uuid : void 0 : void 0) == null) || ((_ref2 = this.previous) != null ? _ref2.__layoutClass : void 0) !== this.__layoutClass) {
2338
+ this.__bootstrapLayout();
2339
+ } else {
2340
+ this.__bootstrap();
2341
+ }
2342
+ }
2343
+ }
2344
+
2345
+ Page.prototype.navigate = function() {
2346
+ var args, _ref;
2347
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
2348
+ return (_ref = Joosy.Router).navigate.apply(_ref, args);
2349
+ };
2350
+
2351
+ Page.prototype.__renderSection = function() {
2352
+ return 'pages';
2353
+ };
2354
+
2355
+ Page.prototype.__fixHeight = function() {
2356
+ return $('html').css('min-height', $(document).height());
2357
+ };
2358
+
2359
+ Page.prototype.__releaseHeight = function() {
2360
+ return $('html').css('min-height', '');
2361
+ };
2362
+
2363
+ Page.prototype.__load = function() {
2364
+ this.refreshElements();
2365
+ this.__delegateEvents();
2366
+ this.__setupWidgets();
2367
+ this.__runAfterLoads(this.params, this.previous);
2368
+ if (this.__scrollElement) {
2369
+ this.__performScrolling();
2370
+ }
2371
+ Joosy.Application.loading = false;
2372
+ Joosy.Router.trigger('loaded', this);
2373
+ this.trigger('loaded');
2374
+ return Joosy.Modules.Log.debugAs(this, "Page loaded");
2375
+ };
2376
+
2377
+ Page.prototype.__unload = function() {
2378
+ this.__clearTime();
2379
+ this.__unloadWidgets();
2380
+ this.__removeMetamorphs();
2381
+ this.__runAfterUnloads(this.params, this.previous);
2382
+ return delete this.previous;
2383
+ };
2384
+
2385
+ Page.prototype.__callSyncedThrough = function(entity, receiver, params, callback) {
2386
+ if ((entity != null ? entity[receiver] : void 0) != null) {
2387
+ return entity[receiver].apply(entity, params.clone().add(callback));
2388
+ } else {
2389
+ return callback();
2390
+ }
2391
+ };
2392
+
2393
+ Page.prototype.__bootstrap = function() {
2394
+ var callbacksParams,
2395
+ _this = this;
2396
+ Joosy.Modules.Log.debugAs(this, "Boostraping page");
2397
+ this.layout = this.previous.layout;
2398
+ callbacksParams = [this.layout.content()];
2399
+ if (this.__scrollElement && this.__scrollSpeed !== 0) {
2400
+ this.__fixHeight();
2401
+ }
2402
+ this.wait("stageClear dataReceived", function() {
2403
+ var _ref;
2404
+ if ((_ref = _this.previous) != null) {
2405
+ if (typeof _ref.__afterPaint === "function") {
2406
+ _ref.__afterPaint(callbacksParams);
2407
+ }
2408
+ }
2409
+ return _this.__callSyncedThrough(_this, '__paint', callbacksParams, function() {
2410
+ _this.swapContainer(_this.layout.content(), _this.__renderer(_this.data || {}));
2411
+ _this.container = _this.layout.content();
2412
+ _this.__load();
2413
+ return _this.layout.content();
2414
+ });
2415
+ });
2416
+ this.__callSyncedThrough(this.previous, '__erase', callbacksParams, function() {
2417
+ var _ref;
2418
+ if ((_ref = _this.previous) != null) {
2419
+ _ref.__unload();
2420
+ }
2421
+ return _this.__callSyncedThrough(_this, '__beforePaint', callbacksParams, function() {
2422
+ return _this.trigger('stageClear');
2423
+ });
2424
+ });
2425
+ return this.__callSyncedThrough(this, '__fetch', [], function() {
2426
+ Joosy.Modules.Log.debugAs(_this, "Fetch complete");
2427
+ return _this.trigger('dataReceived');
2428
+ });
2429
+ };
2430
+
2431
+ Page.prototype.__bootstrapLayout = function() {
2432
+ var callbacksParams, _ref,
2433
+ _this = this;
2434
+ Joosy.Modules.Log.debugAs(this, "Boostraping page with layout");
2435
+ this.layout = new this.__layoutClass(this.params);
2436
+ callbacksParams = [Joosy.Application.content(), this];
2437
+ if (this.__scrollElement && this.__scrollSpeed !== 0) {
2438
+ this.__fixHeight();
2439
+ }
2440
+ this.wait("stageClear dataReceived", function() {
2441
+ return _this.__callSyncedThrough(_this.layout, '__paint', callbacksParams, function() {
2442
+ var data;
2443
+ data = Joosy.Module.merge({}, _this.layout.data || {});
2444
+ data = Joosy.Module.merge(data, {
2445
+ "yield": function() {
2446
+ return _this.layout["yield"]();
2447
+ }
2448
+ });
2449
+ _this.swapContainer(Joosy.Application.content(), _this.layout.__renderer(data));
2450
+ _this.swapContainer(_this.layout.content(), _this.__renderer(_this.data || {}));
2451
+ _this.container = _this.layout.content();
2452
+ _this.layout.__load(Joosy.Application.content());
2453
+ _this.__load();
2454
+ return Joosy.Application.content();
2455
+ });
2456
+ });
2457
+ this.__callSyncedThrough((_ref = this.previous) != null ? _ref.layout : void 0, '__erase', callbacksParams, function() {
2458
+ var _ref1, _ref2, _ref3;
2459
+ if ((_ref1 = _this.previous) != null) {
2460
+ if ((_ref2 = _ref1.layout) != null) {
2461
+ if (typeof _ref2.__unload === "function") {
2462
+ _ref2.__unload();
2463
+ }
2464
+ }
2465
+ }
2466
+ if ((_ref3 = _this.previous) != null) {
2467
+ _ref3.__unload();
2468
+ }
2469
+ return _this.__callSyncedThrough(_this.layout, '__beforePaint', callbacksParams, function() {
2470
+ return _this.trigger('stageClear');
2471
+ });
2472
+ });
2473
+ return this.__callSyncedThrough(this.layout, '__fetch', [], function() {
2474
+ return _this.__callSyncedThrough(_this, '__fetch', [], function() {
2475
+ Joosy.Modules.Log.debugAs(_this, "Fetch complete");
2476
+ return _this.trigger('dataReceived');
2477
+ });
2478
+ });
2479
+ };
2480
+
2481
+ return Page;
2482
+
2483
+ })(Joosy.Module);
2484
+
2485
+
2486
+ /*** src/joosy/core/preloader ***/
2487
+
2488
+ this.Preloader = {
2489
+ load: function(libraries, options) {
2490
+ var key, val, _ref;
2491
+ for (key in options) {
2492
+ val = options[key];
2493
+ this[key] = val;
2494
+ }
2495
+ return (_ref = this.complete) != null ? _ref.call(window) : void 0;
2496
+ }
2497
+ };
2498
+
2499
+
2500
+ /*** src/joosy/core/resource/collection ***/
2501
+
2502
+ var __hasProp = {}.hasOwnProperty,
2503
+ __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; },
2504
+ __slice = [].slice;
2505
+
2506
+ Joosy.Resource.Collection = (function(_super) {
2507
+ __extends(Collection, _super);
2508
+
2509
+ Collection.include(Joosy.Modules.Events);
2510
+
2511
+ Collection.beforeLoad = function(action) {
2512
+ return this.prototype.__beforeLoad = action;
2513
+ };
2514
+
2515
+ Collection.model = function(model) {
2516
+ return this.prototype.model = model;
2517
+ };
2518
+
2519
+ function Collection(model, findOptions) {
2520
+ if (model == null) {
2521
+ model = false;
2522
+ }
2523
+ this.findOptions = findOptions;
2524
+ if (model) {
2525
+ this.model = model;
2526
+ }
2527
+ this.data = [];
2528
+ if (!this.model) {
2529
+ throw new Error("" + (Joosy.Module.__className(this)) + "> model can't be empty");
2530
+ }
2531
+ }
2532
+
2533
+ Collection.prototype.load = function(entities, notify) {
2534
+ if (notify == null) {
2535
+ notify = true;
2536
+ }
2537
+ if (this.__beforeLoad != null) {
2538
+ entities = this.__beforeLoad(entities);
2539
+ }
2540
+ this.data = this.modelize(entities);
2541
+ if (notify) {
2542
+ this.trigger('changed');
2543
+ }
2544
+ return this;
2545
+ };
2546
+
2547
+ Collection.prototype.modelize = function(collection) {
2548
+ var root,
2549
+ _this = this;
2550
+ root = this.model.prototype.__entityName.pluralize();
2551
+ if (!(collection instanceof Array)) {
2552
+ collection = collection != null ? collection[root.camelize(false)] : void 0;
2553
+ if (!(collection instanceof Array)) {
2554
+ throw new Error("Can not read incoming JSON");
2555
+ }
2556
+ }
2557
+ return collection.map(function(x) {
2558
+ return _this.model.build(x);
2559
+ });
2560
+ };
2561
+
2562
+ Collection.prototype.each = function(callback) {
2563
+ return this.data.each(callback);
2564
+ };
2565
+
2566
+ Collection.prototype.size = function() {
2567
+ return this.data.length;
2568
+ };
2569
+
2570
+ Collection.prototype.find = function(description) {
2571
+ return this.data.find(description);
2572
+ };
2573
+
2574
+ Collection.prototype.sortBy = function() {
2575
+ var params, _ref;
2576
+ params = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
2577
+ return (_ref = this.data).sortBy.apply(_ref, params);
2578
+ };
2579
+
2580
+ Collection.prototype.findById = function(id) {
2581
+ return this.data.find(function(x) {
2582
+ return x.id().toString() === id.toString();
2583
+ });
2584
+ };
2585
+
2586
+ Collection.prototype.at = function(i) {
2587
+ return this.data[i];
2588
+ };
2589
+
2590
+ Collection.prototype.remove = function(target, notify) {
2591
+ var index, result;
2592
+ if (notify == null) {
2593
+ notify = true;
2594
+ }
2595
+ if (Object.isNumber(target)) {
2596
+ index = target;
2597
+ } else {
2598
+ index = this.data.indexOf(target);
2599
+ }
2600
+ if (index >= 0) {
2601
+ result = this.data.splice(index, 1)[0];
2602
+ if (notify) {
2603
+ this.trigger('changed');
2604
+ }
2605
+ }
2606
+ return result;
2607
+ };
2608
+
2609
+ Collection.prototype.add = function(element, index, notify) {
2610
+ if (index == null) {
2611
+ index = false;
2612
+ }
2613
+ if (notify == null) {
2614
+ notify = true;
2615
+ }
2616
+ if (typeof index === 'number') {
2617
+ this.data.splice(index, 0, element);
2618
+ } else {
2619
+ this.data.push(element);
2620
+ }
2621
+ if (notify) {
2622
+ this.trigger('changed');
2623
+ }
2624
+ return element;
2625
+ };
2626
+
2627
+ return Collection;
2628
+
2629
+ })(Joosy.Module);
2630
+
2631
+
2632
+ /*** src/joosy/core/resource/generic ***/
2633
+
2634
+ var __hasProp = {}.hasOwnProperty,
2635
+ __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; };
2636
+
2637
+ Joosy.Resource.Generic = (function(_super) {
2638
+ __extends(Generic, _super);
2639
+
2640
+ Generic.include(Joosy.Modules.Log);
2641
+
2642
+ Generic.include(Joosy.Modules.Events);
2643
+
2644
+ Generic.prototype.__primaryKey = 'id';
2645
+
2646
+ Generic.prototype.__source = false;
2647
+
2648
+ Generic.resetIdentity = function() {
2649
+ return Joosy.Resource.Generic.identity = {};
2650
+ };
2651
+
2652
+ Generic.beforeLoad = function(action) {
2653
+ if (!this.prototype.hasOwnProperty('__beforeLoads')) {
2654
+ this.prototype.__beforeLoads = [].concat(this.__super__.__beforeLoads || []);
2655
+ }
2656
+ return this.prototype.__beforeLoads.push(action);
2657
+ };
2658
+
2659
+ Generic.primaryKey = function(primaryKey) {
2660
+ return this.prototype.__primaryKey = primaryKey;
2661
+ };
2662
+
2663
+ Generic.source = function(location) {
2664
+ return this.__source = location;
2665
+ };
2666
+
2667
+ Generic.at = function(entity) {
2668
+ var Clone, _ref;
2669
+ Clone = (function(_super1) {
2670
+ __extends(Clone, _super1);
2671
+
2672
+ function Clone() {
2673
+ _ref = Clone.__super__.constructor.apply(this, arguments);
2674
+ return _ref;
2675
+ }
2676
+
2677
+ return Clone;
2678
+
2679
+ })(this);
2680
+ if (entity instanceof Joosy.Resource.Generic) {
2681
+ Clone.__source = entity.memberPath();
2682
+ if (this.prototype.__entityName) {
2683
+ Clone.__source += '/' + this.prototype.__entityName.pluralize();
2684
+ }
2685
+ } else {
2686
+ Clone.__source = entity;
2687
+ }
2688
+ return Clone;
2689
+ };
2690
+
2691
+ Generic.entity = function(name) {
2692
+ return this.prototype.__entityName = name;
2693
+ };
2694
+
2695
+ Generic.collection = function(klass) {
2696
+ return this.prototype.__collection = function() {
2697
+ return klass;
2698
+ };
2699
+ };
2700
+
2701
+ Generic.prototype.__collection = function() {
2702
+ var named;
2703
+ named = this.__entityName.camelize().pluralize() + 'Collection';
2704
+ if (window[named]) {
2705
+ return window[named];
2706
+ } else {
2707
+ return Joosy.Resource.Collection;
2708
+ }
2709
+ };
2710
+
2711
+ Generic.map = function(name, klass) {
2712
+ if (klass == null) {
2713
+ klass = false;
2714
+ }
2715
+ if (!klass) {
2716
+ klass = window[name.singularize().camelize()];
2717
+ }
2718
+ if (!klass) {
2719
+ throw new Error("" + (Joosy.Module.__className(this)) + "> class can not be detected for '" + name + "' mapping");
2720
+ }
2721
+ return this.beforeLoad(function(data) {
2722
+ if (!Joosy.Module.hasAncestor(klass, Joosy.Resource.Generic)) {
2723
+ klass = klass();
2724
+ }
2725
+ return this.__map(data, name, klass);
2726
+ });
2727
+ };
2728
+
2729
+ Generic.build = function(data) {
2730
+ var id, key, klass, shim, value, _base, _base1, _ref;
2731
+ if (data == null) {
2732
+ data = {};
2733
+ }
2734
+ klass = this.prototype.__entityName;
2735
+ (_base = Joosy.Resource.Generic).identity || (_base.identity = {});
2736
+ (_base1 = Joosy.Resource.Generic.identity)[klass] || (_base1[klass] = {});
2737
+ shim = function() {
2738
+ return shim.__call.apply(shim, arguments);
2739
+ };
2740
+ if (shim.__proto__) {
2741
+ shim.__proto__ = this.prototype;
2742
+ } else {
2743
+ _ref = this.prototype;
2744
+ for (key in _ref) {
2745
+ value = _ref[key];
2746
+ shim[key] = value;
2747
+ }
2748
+ }
2749
+ shim.constructor = this;
2750
+ if (Object.isNumber(data) || Object.isString(data)) {
2751
+ id = data;
2752
+ data = {};
2753
+ data[shim.__primaryKey] = id;
2754
+ }
2755
+ if (Joosy.Application.identity) {
2756
+ id = data[shim.__primaryKey];
2757
+ if ((id != null) && Joosy.Resource.Generic.identity[klass][id]) {
2758
+ shim = Joosy.Resource.Generic.identity[klass][id];
2759
+ shim.load(data);
2760
+ } else {
2761
+ Joosy.Resource.Generic.identity[klass][id] = shim;
2762
+ this.apply(shim, [data]);
2763
+ }
2764
+ } else {
2765
+ this.apply(shim, [data]);
2766
+ }
2767
+ return shim;
2768
+ };
2769
+
2770
+ function Generic(data) {
2771
+ if (data == null) {
2772
+ data = {};
2773
+ }
2774
+ this.__fillData(data, false);
2775
+ }
2776
+
2777
+ Generic.prototype.id = function() {
2778
+ return this.data[this.__primaryKey];
2779
+ };
2780
+
2781
+ Generic.prototype.knownAttributes = function() {
2782
+ return this.data.keys();
2783
+ };
2784
+
2785
+ Generic.prototype.load = function(data) {
2786
+ this.__fillData(data);
2787
+ return this;
2788
+ };
2789
+
2790
+ Generic.prototype.__get = function(path) {
2791
+ var target;
2792
+ target = this.__callTarget(path);
2793
+ if (target[0] instanceof Joosy.Resource.Generic) {
2794
+ return target[0](target[1]);
2795
+ } else {
2796
+ return target[0][target[1]];
2797
+ }
2798
+ };
2799
+
2800
+ Generic.prototype.__set = function(path, value) {
2801
+ var target;
2802
+ target = this.__callTarget(path);
2803
+ if (target[0] instanceof Joosy.Resource.Generic) {
2804
+ target[0](target[1], value);
2805
+ } else {
2806
+ target[0][target[1]] = value;
2807
+ }
2808
+ this.trigger('changed');
2809
+ return null;
2810
+ };
2811
+
2812
+ Generic.prototype.__callTarget = function(path) {
2813
+ var keyword, part, target, _i, _len;
2814
+ if (path.has(/\./) && (this.data[path] == null)) {
2815
+ path = path.split('.');
2816
+ keyword = path.pop();
2817
+ target = this.data;
2818
+ for (_i = 0, _len = path.length; _i < _len; _i++) {
2819
+ part = path[_i];
2820
+ target[part] || (target[part] = {});
2821
+ if (target instanceof Joosy.Resource.Generic) {
2822
+ target = target(part);
2823
+ } else {
2824
+ target = target[part];
2825
+ }
2826
+ }
2827
+ return [target, keyword];
2828
+ } else {
2829
+ return [this.data, path];
2830
+ }
2831
+ };
2832
+
2833
+ Generic.prototype.__call = function(path, value) {
2834
+ if (arguments.length > 1) {
2835
+ return this.__set(path, value);
2836
+ } else {
2837
+ return this.__get(path);
2838
+ }
2839
+ };
2840
+
2841
+ Generic.prototype.__fillData = function(data, notify) {
2842
+ if (notify == null) {
2843
+ notify = true;
2844
+ }
2845
+ this.raw = data;
2846
+ if (!this.hasOwnProperty('data')) {
2847
+ this.data = {};
2848
+ }
2849
+ Joosy.Module.merge(this.data, this.__prepareData(data));
2850
+ if (notify) {
2851
+ this.trigger('changed');
2852
+ }
2853
+ return null;
2854
+ };
2855
+
2856
+ Generic.prototype.__prepareData = function(data) {
2857
+ var bl, name, _i, _len, _ref;
2858
+ if (Object.isObject(data) && Object.keys(data).length === 1 && this.__entityName) {
2859
+ name = this.__entityName.camelize(false);
2860
+ if (data[name]) {
2861
+ data = data[name];
2862
+ }
2863
+ }
2864
+ if (this.__beforeLoads != null) {
2865
+ _ref = this.__beforeLoads;
2866
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
2867
+ bl = _ref[_i];
2868
+ data = bl.call(this, data);
2869
+ }
2870
+ }
2871
+ return data;
2872
+ };
2873
+
2874
+ Generic.prototype.__map = function(data, name, klass) {
2875
+ var entry;
2876
+ if (Object.isArray(data[name])) {
2877
+ entry = new (klass.prototype.__collection())(klass);
2878
+ entry.load(data[name]);
2879
+ data[name] = entry;
2880
+ } else if (Object.isObject(data[name])) {
2881
+ data[name] = klass.build(data[name]);
2882
+ }
2883
+ return data;
2884
+ };
2885
+
2886
+ return Generic;
2887
+
2888
+ })(Joosy.Module);
2889
+
2890
+
2891
+ /*** src/joosy/core/resource/rest ***/
2892
+
2893
+ var _ref,
2894
+ __hasProp = {}.hasOwnProperty,
2895
+ __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; };
2896
+
2897
+ Joosy.Resource.REST = (function(_super) {
2898
+ __extends(REST, _super);
2899
+
2900
+ function REST() {
2901
+ _ref = REST.__super__.constructor.apply(this, arguments);
2902
+ return _ref;
2903
+ }
2904
+
2905
+ REST.prototype.__collection = function() {
2906
+ var named;
2907
+ named = this.__entityName.camelize().pluralize() + 'Collection';
2908
+ if (window[named]) {
2909
+ return window[named];
2910
+ } else {
2911
+ return Joosy.Resource.RESTCollection;
2912
+ }
2913
+ };
2914
+
2915
+ REST.__parentsPath = function(parents) {
2916
+ return parents.reduce(function(path, parent) {
2917
+ return path += Joosy.Module.hasAncestor(parent.constructor, Joosy.Resource.REST) ? parent.memberPath() : parent;
2918
+ }, '');
2919
+ };
2920
+
2921
+ REST.basePath = function(options) {
2922
+ var path;
2923
+ if (options == null) {
2924
+ options = {};
2925
+ }
2926
+ if ((this.__source != null) && (options.parent == null)) {
2927
+ path = this.__source;
2928
+ } else {
2929
+ path = '/';
2930
+ if (this.__namespace__.length > 0) {
2931
+ path += this.__namespace__.map(function(s) {
2932
+ return s.toLowerCase();
2933
+ }).join('/') + '/';
2934
+ }
2935
+ path += this.prototype.__entityName.pluralize();
2936
+ }
2937
+ if (options.parent != null) {
2938
+ path = this.__parentsPath(Object.isArray(options.parent) ? options.parent : [options.parent]) + path;
2939
+ }
2940
+ return path;
2941
+ };
2942
+
2943
+ REST.prototype.basePath = function(options) {
2944
+ if (options == null) {
2945
+ options = {};
2946
+ }
2947
+ return this.constructor.basePath(options);
2948
+ };
2949
+
2950
+ REST.memberPath = function(id, options) {
2951
+ var path;
2952
+ if (options == null) {
2953
+ options = {};
2954
+ }
2955
+ path = this.basePath(options) + ("/" + id);
2956
+ if (options.from != null) {
2957
+ path += "/" + options.from;
2958
+ }
2959
+ return path;
2960
+ };
2961
+
2962
+ REST.prototype.memberPath = function(options) {
2963
+ if (options == null) {
2964
+ options = {};
2965
+ }
2966
+ return this.constructor.memberPath(this.id(), options);
2967
+ };
2968
+
2969
+ REST.collectionPath = function(options) {
2970
+ var path;
2971
+ if (options == null) {
2972
+ options = {};
2973
+ }
2974
+ path = this.basePath(options);
2975
+ if (options.from != null) {
2976
+ path += "/" + options.from;
2977
+ }
2978
+ return path;
2979
+ };
2980
+
2981
+ REST.prototype.collectionPath = function(options) {
2982
+ if (options == null) {
2983
+ options = {};
2984
+ }
2985
+ return this.constructor.collectionPath(options);
2986
+ };
2987
+
2988
+ REST.get = function(options, callback) {
2989
+ if (Object.isFunction(options)) {
2990
+ callback = options;
2991
+ options = {};
2992
+ }
2993
+ return this.__query(this.collectionPath(options), 'GET', options.params, callback);
2994
+ };
2995
+
2996
+ REST.post = function(options, callback) {
2997
+ if (Object.isFunction(options)) {
2998
+ callback = options;
2999
+ options = {};
3000
+ }
3001
+ return this.__query(this.collectionPath(options), 'POST', options.params, callback);
3002
+ };
3003
+
3004
+ REST.put = function(options, callback) {
3005
+ if (Object.isFunction(options)) {
3006
+ callback = options;
3007
+ options = {};
3008
+ }
3009
+ return this.__query(this.collectionPath(options), 'PUT', options.params, callback);
3010
+ };
3011
+
3012
+ REST["delete"] = function(options, callback) {
3013
+ if (Object.isFunction(options)) {
3014
+ callback = options;
3015
+ options = {};
3016
+ }
3017
+ return this.__query(this.collectionPath(options), 'DELETE', options.params, callback);
3018
+ };
3019
+
3020
+ REST.prototype.get = function(options, callback) {
3021
+ if (Object.isFunction(options)) {
3022
+ callback = options;
3023
+ options = {};
3024
+ }
3025
+ return this.constructor.__query(this.memberPath(options), 'GET', options.params, callback);
3026
+ };
3027
+
3028
+ REST.prototype.post = function(options, callback) {
3029
+ if (Object.isFunction(options)) {
3030
+ callback = options;
3031
+ options = {};
3032
+ }
3033
+ return this.constructor.__query(this.memberPath(options), 'POST', options.params, callback);
3034
+ };
3035
+
3036
+ REST.prototype.put = function(options, callback) {
3037
+ if (Object.isFunction(options)) {
3038
+ callback = options;
3039
+ options = {};
3040
+ }
3041
+ return this.constructor.__query(this.memberPath(options), 'PUT', options.params, callback);
3042
+ };
3043
+
3044
+ REST.prototype["delete"] = function(options, callback) {
3045
+ if (Object.isFunction(options)) {
3046
+ callback = options;
3047
+ options = {};
3048
+ }
3049
+ return this.constructor.__query(this.memberPath(options), 'DELETE', options.params, callback);
3050
+ };
3051
+
3052
+ REST.find = function(where, options, callback) {
3053
+ var result,
3054
+ _this = this;
3055
+ if (options == null) {
3056
+ options = {};
3057
+ }
3058
+ if (callback == null) {
3059
+ callback = false;
3060
+ }
3061
+ if (Object.isFunction(options)) {
3062
+ callback = options;
3063
+ options = {};
3064
+ }
3065
+ if (where === 'all') {
3066
+ result = new (this.prototype.__collection())(this, options);
3067
+ this.__query(this.collectionPath(options), 'GET', options.params, function(data) {
3068
+ result.load(data);
3069
+ return typeof callback === "function" ? callback(result, data) : void 0;
3070
+ });
3071
+ } else {
3072
+ result = this.build(where);
3073
+ this.__query(this.memberPath(where, options), 'GET', options.params, function(data) {
3074
+ result.load(data);
3075
+ return typeof callback === "function" ? callback(result, data) : void 0;
3076
+ });
3077
+ }
3078
+ return result;
3079
+ };
3080
+
3081
+ REST.__query = function(path, method, params, callback) {
3082
+ var options;
3083
+ options = {
3084
+ data: params,
3085
+ type: method,
3086
+ cache: false,
3087
+ dataType: 'json'
3088
+ };
3089
+ if (Object.isFunction(callback)) {
3090
+ options.success = callback;
3091
+ } else {
3092
+ Joosy.Module.merge(options, callback);
3093
+ }
3094
+ return $.ajax(path, options);
3095
+ };
3096
+
3097
+ REST.prototype.reload = function(options, callback) {
3098
+ var _this = this;
3099
+ if (options == null) {
3100
+ options = {};
3101
+ }
3102
+ if (callback == null) {
3103
+ callback = false;
3104
+ }
3105
+ if (Object.isFunction(options)) {
3106
+ callback = options;
3107
+ options = {};
3108
+ }
3109
+ return this.constructor.__query(this.memberPath(options), 'GET', options.params, function(data) {
3110
+ _this.load(data);
3111
+ return typeof callback === "function" ? callback(_this) : void 0;
3112
+ });
3113
+ };
3114
+
3115
+ return REST;
3116
+
3117
+ })(Joosy.Resource.Generic);
3118
+
3119
+
3120
+ /*** src/joosy/core/resource/rest_collection ***/
3121
+
3122
+ var _ref,
3123
+ __hasProp = {}.hasOwnProperty,
3124
+ __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; };
3125
+
3126
+ Joosy.Resource.RESTCollection = (function(_super) {
3127
+ __extends(RESTCollection, _super);
3128
+
3129
+ function RESTCollection() {
3130
+ _ref = RESTCollection.__super__.constructor.apply(this, arguments);
3131
+ return _ref;
3132
+ }
3133
+
3134
+ RESTCollection.include(Joosy.Modules.Log);
3135
+
3136
+ RESTCollection.include(Joosy.Modules.Events);
3137
+
3138
+ RESTCollection.prototype.reload = function(options, callback) {
3139
+ var _this = this;
3140
+ if (options == null) {
3141
+ options = {};
3142
+ }
3143
+ if (callback == null) {
3144
+ callback = false;
3145
+ }
3146
+ if (Object.isFunction(options)) {
3147
+ callback = options;
3148
+ options = {};
3149
+ }
3150
+ return this.model.__query(this.model.collectionPath(options), 'GET', options.params, function(data) {
3151
+ _this.load(data);
3152
+ return typeof callback === "function" ? callback(data) : void 0;
3153
+ });
3154
+ };
3155
+
3156
+ return RESTCollection;
3157
+
3158
+ })(Joosy.Resource.Collection);
3159
+
3160
+
3161
+ /*** src/joosy/core/resource/watcher ***/
3162
+
3163
+ var __hasProp = {}.hasOwnProperty,
3164
+ __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; };
3165
+
3166
+ Joosy.Resource.Watcher = (function(_super) {
3167
+ __extends(Watcher, _super);
3168
+
3169
+ Watcher.include(Joosy.Modules.Events);
3170
+
3171
+ Watcher.cache = function(cacheKey) {
3172
+ return this.prototype.__cacheKey = cacheKey;
3173
+ };
3174
+
3175
+ Watcher.fetcher = function(fetcher) {
3176
+ return this.prototype.__fetcher = fetcher;
3177
+ };
3178
+
3179
+ Watcher.beforeLoad = function(action) {
3180
+ if (!this.prototype.hasOwnProperty('__beforeLoads')) {
3181
+ this.prototype.__beforeLoads = [].concat(this.__super__.__beforeLoads || []);
3182
+ }
3183
+ return this.prototype.__beforeLoads.push(action);
3184
+ };
3185
+
3186
+ function Watcher(cacheKey, fetcher) {
3187
+ if (cacheKey == null) {
3188
+ cacheKey = false;
3189
+ }
3190
+ if (fetcher == null) {
3191
+ fetcher = false;
3192
+ }
3193
+ if (Object.isFunction(cacheKey)) {
3194
+ fetcher = cacheKey;
3195
+ cacheKey = void 0;
3196
+ }
3197
+ if (fetcher) {
3198
+ this.__fetcher = fetcher;
3199
+ }
3200
+ if (cacheKey) {
3201
+ this.__cacheKey = cacheKey;
3202
+ }
3203
+ }
3204
+
3205
+ Watcher.prototype.load = function(callback) {
3206
+ var _this = this;
3207
+ if (this.__cacheKey && localStorage[this.__cacheKey]) {
3208
+ this.data = this.prepare(JSON.parse(localStorage[this.__cacheKey]));
3209
+ this.trigger('changed');
3210
+ this.refresh();
3211
+ return typeof callback === "function" ? callback(this) : void 0;
3212
+ } else {
3213
+ return this.__fetcher(function(result) {
3214
+ if (_this.__cacheKey) {
3215
+ localStorage[_this.__cacheKey] = JSON.stringify(result);
3216
+ }
3217
+ _this.data = _this.prepare(result);
3218
+ _this.trigger('changed');
3219
+ return typeof callback === "function" ? callback(_this) : void 0;
3220
+ });
3221
+ }
3222
+ };
3223
+
3224
+ Watcher.prototype.clone = function() {
3225
+ var copy;
3226
+ copy = new this.constructor(this.__cacheKey, this.__fetcher);
3227
+ copy.data = Object.clone(this.data, true);
3228
+ copy.trigger('changed');
3229
+ return copy;
3230
+ };
3231
+
3232
+ Watcher.prototype.refresh = function(callback) {
3233
+ var _this = this;
3234
+ return this.__fetcher(function(result) {
3235
+ if (_this.__cacheKey) {
3236
+ localStorage[_this.__cacheKey] = JSON.stringify(result);
3237
+ }
3238
+ _this.data = _this.prepare(result);
3239
+ _this.trigger('changed');
3240
+ return typeof callback === "function" ? callback(_this) : void 0;
3241
+ });
3242
+ };
3243
+
3244
+ Watcher.prototype.prepare = function(data) {
3245
+ var bl, _i, _len, _ref;
3246
+ if (this.__beforeLoads != null) {
3247
+ _ref = this.__beforeLoads;
3248
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
3249
+ bl = _ref[_i];
3250
+ data = bl.call(this, data);
3251
+ }
3252
+ }
3253
+ return data;
3254
+ };
3255
+
3256
+ return Watcher;
3257
+
3258
+ })(Joosy.Module);
3259
+
3260
+
3261
+ /*** src/joosy/core/router ***/
3262
+
3263
+ Joosy.Router = {
3264
+ rawRoutes: Object.extended(),
3265
+ routes: Object.extended(),
3266
+ restrictPattern: false,
3267
+ __namespace: "",
3268
+ __asNamespace: "",
3269
+ restrict: function(restrictPattern) {
3270
+ this.restrictPattern = restrictPattern;
3271
+ },
3272
+ reset: function() {
3273
+ this.rawRoutes = Object.extended();
3274
+ this.routes = Object.extended();
3275
+ this.__namespace = "";
3276
+ return this.__asNamespace = "";
3277
+ },
3278
+ draw: function(block) {
3279
+ if (Object.isFunction(block)) {
3280
+ return block.call(this);
3281
+ }
3282
+ },
3283
+ map: function(routes) {
3284
+ return Joosy.Module.merge(this.rawRoutes, routes);
3285
+ },
3286
+ navigate: function(to, options) {
3287
+ var path,
3288
+ _this = this;
3289
+ if (options == null) {
3290
+ options = {};
3291
+ }
3292
+ path = to.replace(/^\#?\!?/, '!');
3293
+ if (options.respond !== false) {
3294
+ return location.hash = path;
3295
+ } else {
3296
+ if (!history.pushState) {
3297
+ this.__ignoreRequest = to;
3298
+ location.hash = path;
3299
+ return setTimeout(function() {
3300
+ return _this.__ignoreRequest = false;
3301
+ }, 2);
3302
+ } else {
3303
+ return history[options.replaceState ? 'replaceState' : 'pushState']({}, '', '#' + path);
3304
+ }
3305
+ }
3306
+ },
3307
+ match: function(route, options) {
3308
+ var as, map, routeName;
3309
+ if (options == null) {
3310
+ options = {};
3311
+ }
3312
+ if (this.__asNamespace) {
3313
+ as = this.__asNamespace + options["as"].capitalize();
3314
+ } else {
3315
+ as = options["as"];
3316
+ }
3317
+ routeName = this.__namespace + route;
3318
+ map = {};
3319
+ map[route] = options["to"];
3320
+ Joosy.Module.merge(this.rawRoutes, map);
3321
+ return this.__injectReverseUrl(as, routeName);
3322
+ },
3323
+ root: function(options) {
3324
+ var as;
3325
+ if (options == null) {
3326
+ options = {};
3327
+ }
3328
+ as = options["as"] || "root";
3329
+ return this.match("/", {
3330
+ to: options["to"],
3331
+ as: as
3332
+ });
3333
+ },
3334
+ notFound: function(options) {
3335
+ if (options == null) {
3336
+ options = {};
3337
+ }
3338
+ return this.match(404, {
3339
+ to: options["to"]
3340
+ });
3341
+ },
3342
+ namespace: function(name, options, block) {
3343
+ var newScope;
3344
+ if (options == null) {
3345
+ options = {};
3346
+ }
3347
+ if (Object.isFunction(options)) {
3348
+ block = options;
3349
+ options = {};
3350
+ }
3351
+ newScope = $.extend({}, this);
3352
+ newScope.rawRoutes = {};
3353
+ newScope.__namespace += name;
3354
+ if (options["as"]) {
3355
+ newScope.__asNamespace += "" + options["as"];
3356
+ }
3357
+ if (Object.isFunction(block)) {
3358
+ block.call(newScope);
3359
+ }
3360
+ return this.rawRoutes[name] = newScope.rawRoutes;
3361
+ },
3362
+ __setupRoutes: function() {
3363
+ var _this = this;
3364
+ $(window).on('hashchange', function() {
3365
+ if (!(_this.__ignoreRequest && location.hash.match(_this.__ignoreRequest))) {
3366
+ return _this.__respondRoute(location.hash);
3367
+ }
3368
+ });
3369
+ this.__prepareRoutes(this.rawRoutes);
3370
+ return this.__respondRoute(location.hash);
3371
+ },
3372
+ __prepareRoutes: function(routes, namespace) {
3373
+ var _this = this;
3374
+ if (namespace == null) {
3375
+ namespace = '';
3376
+ }
3377
+ if (!namespace && routes[404]) {
3378
+ this.wildcardAction = routes[404];
3379
+ delete routes[404];
3380
+ }
3381
+ return Object.each(routes, function(path, response) {
3382
+ path = (namespace + path).replace(/\/{2,}/, '/');
3383
+ if (response && (Object.isFunction(response) || (response.prototype != null))) {
3384
+ return Joosy.Module.merge(_this.routes, _this.__prepareRoute(path, response));
3385
+ } else {
3386
+ return _this.__prepareRoutes(response, path);
3387
+ }
3388
+ });
3389
+ },
3390
+ __prepareRoute: function(path, response) {
3391
+ var matchPath, result;
3392
+ matchPath = path.replace(/\/:([^\/]+)/g, '/([^/]+)').replace(/^\/?/, '^/?').replace(/\/?$/, '/?$');
3393
+ result = Object.extended();
3394
+ result[matchPath] = {
3395
+ capture: (path.match(/\/:[^\/]+/g) || []).map(function(str) {
3396
+ return str.substr(2);
3397
+ }),
3398
+ action: response
3399
+ };
3400
+ return result;
3401
+ },
3402
+ __respondRoute: function(hash) {
3403
+ var found, fullPath, params, path, queryArray, regex, route, urlParams, vals, _ref;
3404
+ Joosy.Modules.Log.debug("Router> Answering '" + hash + "'");
3405
+ fullPath = hash.replace(/^#!?/, '');
3406
+ if (this.restrictPattern && fullPath.match(this.restrictPattern) === null) {
3407
+ this.trigger('restricted', fullPath);
3408
+ return;
3409
+ } else {
3410
+ this.trigger('responded', fullPath);
3411
+ }
3412
+ this.currentPath = fullPath;
3413
+ found = false;
3414
+ queryArray = fullPath.split('&');
3415
+ path = queryArray.shift();
3416
+ urlParams = this.__paramsFromQueryArray(queryArray);
3417
+ _ref = this.routes;
3418
+ for (regex in _ref) {
3419
+ route = _ref[regex];
3420
+ if (this.routes.hasOwnProperty(regex)) {
3421
+ if (vals = path.match(new RegExp(regex))) {
3422
+ params = this.__paramsFromRouteMatch(vals, route).merge(urlParams);
3423
+ if (Joosy.Module.hasAncestor(route.action, Joosy.Page)) {
3424
+ Joosy.Application.setCurrentPage(route.action, params);
3425
+ } else {
3426
+ route.action.call(this, params);
3427
+ }
3428
+ found = true;
3429
+ break;
3430
+ }
3431
+ }
3432
+ }
3433
+ if (!found && (this.wildcardAction != null)) {
3434
+ if (Joosy.Module.hasAncestor(this.wildcardAction, Joosy.Page)) {
3435
+ return Joosy.Application.setCurrentPage(this.wildcardAction, urlParams);
3436
+ } else {
3437
+ return this.wildcardAction(path, urlParams);
3438
+ }
3439
+ }
3440
+ },
3441
+ __paramsFromRouteMatch: function(vals, route) {
3442
+ var param, params, _i, _len, _ref;
3443
+ params = Object.extended();
3444
+ vals.shift();
3445
+ _ref = route.capture;
3446
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
3447
+ param = _ref[_i];
3448
+ params[param] = vals.shift();
3449
+ }
3450
+ return params;
3451
+ },
3452
+ __paramsFromQueryArray: function(queryArray) {
3453
+ var params;
3454
+ params = Object.extended();
3455
+ if (queryArray) {
3456
+ $.each(queryArray, function() {
3457
+ var pair;
3458
+ if (!this.isBlank()) {
3459
+ pair = this.split('=');
3460
+ return params[pair[0]] = pair[1];
3461
+ }
3462
+ });
3463
+ }
3464
+ return params;
3465
+ },
3466
+ __injectReverseUrl: function(as, route) {
3467
+ var fnc;
3468
+ if (as === void 0) {
3469
+ return;
3470
+ }
3471
+ fnc = function(options) {
3472
+ var url;
3473
+ url = route;
3474
+ (route.match(/\/:[^\/]+/g) || []).each(function(str) {
3475
+ return url = url.replace(str.substr(1), options[str.substr(2)]);
3476
+ });
3477
+ return "#!" + url;
3478
+ };
3479
+ Joosy.Helpers.Application["" + as + "Path"] = function(options) {
3480
+ return fnc(options);
3481
+ };
3482
+ return Joosy.Helpers.Application["" + as + "Url"] = function(options) {
3483
+ var url;
3484
+ url = 'http://' + window.location.host + window.location.pathname;
3485
+ return "" + url + (fnc(options));
3486
+ };
3487
+ }
3488
+ };
3489
+
3490
+ Joosy.Module.merge(Joosy.Router, Joosy.Modules.Events);
3491
+
3492
+
3493
+ /*** src/joosy/core/widget ***/
3494
+
3495
+ var _ref,
3496
+ __hasProp = {}.hasOwnProperty,
3497
+ __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; },
3498
+ __slice = [].slice;
3499
+
3500
+ Joosy.Widget = (function(_super) {
3501
+ __extends(Widget, _super);
3502
+
3503
+ function Widget() {
3504
+ _ref = Widget.__super__.constructor.apply(this, arguments);
3505
+ return _ref;
3506
+ }
3507
+
3508
+ Widget.include(Joosy.Modules.Log);
3509
+
3510
+ Widget.include(Joosy.Modules.Events);
3511
+
3512
+ Widget.include(Joosy.Modules.Container);
3513
+
3514
+ Widget.include(Joosy.Modules.Renderer);
3515
+
3516
+ Widget.include(Joosy.Modules.Filters);
3517
+
3518
+ Widget.include(Joosy.Modules.TimeManager);
3519
+
3520
+ Widget.include(Joosy.Modules.WidgetsManager);
3521
+
3522
+ Widget.prototype.__renderer = false;
3523
+
3524
+ Widget.prototype.data = false;
3525
+
3526
+ Widget.prototype.navigate = function() {
3527
+ var args, _ref1;
3528
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
3529
+ return (_ref1 = Joosy.Router).navigate.apply(_ref1, args);
3530
+ };
3531
+
3532
+ Widget.prototype.__renderSection = function() {
3533
+ return 'widgets';
3534
+ };
3535
+
3536
+ Widget.prototype.__load = function(parent, container, render) {
3537
+ this.parent = parent;
3538
+ this.container = container;
3539
+ if (render == null) {
3540
+ render = true;
3541
+ }
3542
+ if (render && this.__renderer) {
3543
+ this.swapContainer(this.container, this.__renderer(this.data || {}));
3544
+ }
3545
+ this.refreshElements();
3546
+ this.__delegateEvents();
3547
+ this.__setupWidgets();
3548
+ this.__runAfterLoads();
3549
+ return this;
3550
+ };
3551
+
3552
+ Widget.prototype.__unload = function() {
3553
+ this.__clearTime();
3554
+ this.__unloadWidgets();
3555
+ this.__removeMetamorphs();
3556
+ return this.__runAfterUnloads();
3557
+ };
3558
+
3559
+ return Widget;
3560
+
3561
+ })(Joosy.Module);
3562
+
3563
+
3564
+ /*** src/joosy/preloaders/caching ***/
3565
+
3566
+ this.CachingPreloader = {
3567
+ force: false,
3568
+ prefix: "cache:",
3569
+ counter: 0,
3570
+ load: function(libraries, options) {
3571
+ var i, key, lib, val, _i, _len, _ref, _ref1;
3572
+ if (options == null) {
3573
+ options = {};
3574
+ }
3575
+ for (key in options) {
3576
+ val = options[key];
3577
+ this[key] = val;
3578
+ }
3579
+ this.libraries = libraries.slice();
3580
+ _ref = this.libraries;
3581
+ for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
3582
+ lib = _ref[i];
3583
+ this.libraries[i] = this.prefix + lib[0];
3584
+ }
3585
+ if (!this.force && this.check()) {
3586
+ return this.restore();
3587
+ } else {
3588
+ if ((_ref1 = this.start) != null) {
3589
+ _ref1.call(window);
3590
+ }
3591
+ this.clean();
3592
+ return this.download(libraries);
3593
+ }
3594
+ },
3595
+ check: function() {
3596
+ var flag, i, name, _i, _len, _ref;
3597
+ flag = true;
3598
+ _ref = this.libraries;
3599
+ for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
3600
+ name = _ref[i];
3601
+ flag && (flag = window.localStorage.getItem(name) != null);
3602
+ }
3603
+ return flag;
3604
+ },
3605
+ escapeStr: function(str) {
3606
+ return str.replace(new RegExp("\u0001", 'g'), "\\u0001").replace(new RegExp("\u000B", 'g'), "\\u000B");
3607
+ },
3608
+ restore: function() {
3609
+ var i, name, _i, _len, _ref, _ref1;
3610
+ _ref = this.libraries;
3611
+ for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
3612
+ name = _ref[i];
3613
+ window.evalGlobaly(window.localStorage.getItem(name));
3614
+ }
3615
+ return (_ref1 = this.complete) != null ? _ref1.call(window, true) : void 0;
3616
+ },
3617
+ download: function(libraries) {
3618
+ var lib, size, url, _ref,
3619
+ _this = this;
3620
+ if (libraries.length > 0) {
3621
+ this.counter += 1;
3622
+ lib = libraries.shift();
3623
+ url = lib[0];
3624
+ size = lib[1];
3625
+ return this.ajax(url, size, function(xhr) {
3626
+ var code;
3627
+ code = xhr.responseText;
3628
+ if (window.navigator.appName === "Microsoft Internet Explorer") {
3629
+ code = _this.escapeStr(code);
3630
+ }
3631
+ window.localStorage.setItem(_this.prefix + url, code);
3632
+ window.evalGlobaly(xhr.responseText);
3633
+ return _this.download(libraries);
3634
+ });
3635
+ } else {
3636
+ return (_ref = this.complete) != null ? _ref.call(window) : void 0;
3637
+ }
3638
+ },
3639
+ ajax: function(url, size, callback) {
3640
+ var poller, x,
3641
+ _this = this;
3642
+ if (window.XMLHttpRequest) {
3643
+ x = new XMLHttpRequest;
3644
+ } else {
3645
+ x = new ActiveXObject('Microsoft.XMLHTTP');
3646
+ }
3647
+ x.open('GET', url, 1);
3648
+ x.onreadystatechange = function() {
3649
+ if (x.readyState > 3) {
3650
+ clearInterval(_this.interval);
3651
+ return typeof callback === "function" ? callback(x) : void 0;
3652
+ }
3653
+ };
3654
+ if (this.progress) {
3655
+ poller = function() {
3656
+ var e;
3657
+ try {
3658
+ return _this.progress.call(window, Math.round((x.responseText.length / size) * (_this.counter / _this.libraries.length) * 100));
3659
+ } catch (_error) {
3660
+ e = _error;
3661
+ }
3662
+ };
3663
+ this.interval = setInterval(poller, 100);
3664
+ }
3665
+ return x.send();
3666
+ },
3667
+ clean: function() {
3668
+ var find, i, key, _results;
3669
+ i = 0;
3670
+ find = function(arr, obj) {
3671
+ var x, _i, _len;
3672
+ for (_i = 0, _len = arr.length; _i < _len; _i++) {
3673
+ x = arr[_i];
3674
+ if (obj === x) {
3675
+ return i;
3676
+ }
3677
+ }
3678
+ return -1;
3679
+ };
3680
+ _results = [];
3681
+ while (i < window.localStorage.length && (key = window.localStorage.key(i))) {
3682
+ if (key.indexOf(this.prefix) === 0 && find(this.libraries, key) < 0) {
3683
+ _results.push(window.localStorage.removeItem(key));
3684
+ } else {
3685
+ _results.push(i += 1);
3686
+ }
3687
+ }
3688
+ return _results;
3689
+ }
3690
+ };
3691
+
3692
+ window.evalGlobaly = function(src) {
3693
+ if (src.length === 0) {
3694
+ return;
3695
+ }
3696
+ if (window.execScript) {
3697
+ return window.execScript(src);
3698
+ } else {
3699
+ return window["eval"](src);
3700
+ }
3701
+ };
3702
+
3703
+ this.Preloader = this.CachingPreloader;
3704
+
3705
+
3706
+ /*** src/joosy/preloaders/inline ***/
3707
+
3708
+ this.InlinePreloader = {
3709
+ load: function(libraries, options) {
3710
+ var key, val,
3711
+ _this = this;
3712
+ for (key in options) {
3713
+ val = options[key];
3714
+ this[key] = val;
3715
+ }
3716
+ if (typeof this.start === "function") {
3717
+ this.start();
3718
+ }
3719
+ if (libraries.length > 0) {
3720
+ return this.receive(libraries.shift()[0], function() {
3721
+ return _this.load(libraries);
3722
+ });
3723
+ } else {
3724
+ return typeof this.complete === "function" ? this.complete() : void 0;
3725
+ }
3726
+ },
3727
+ receive: function(url, callback) {
3728
+ var done, head, proceed, script;
3729
+ head = document.getElementsByTagName("head")[0];
3730
+ script = document.createElement("script");
3731
+ script.src = url;
3732
+ done = false;
3733
+ proceed = function() {
3734
+ if (!done && ((this.readyState == null) || this.readyState === "loaded" || this.readyState === "complete")) {
3735
+ done = true;
3736
+ if (typeof callback === "function") {
3737
+ callback();
3738
+ }
3739
+ return script.onload = script.onreadystatechange = null;
3740
+ }
3741
+ };
3742
+ script.onload = script.onreadystatechange = proceed;
3743
+ head.appendChild(script);
3744
+ return void 0;
3745
+ }
3746
+ };
3747
+
3748
+ this.Preloader = this.InlinePreloader;
3749
+
3750
+
3751
+ /*** src/joosy ***/
3752
+
3753
+
3754
+ ;