ende 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/component.json +1 -1
  3. data/lib/assets/javascripts/aura/extensions/devise.js.coffee +7 -4
  4. data/lib/assets/javascripts/aura/extensions/routes.js.coffee +16 -8
  5. data/lib/assets/javascripts/aura/extensions/widget/lifecycleable.js.coffee +10 -5
  6. data/lib/assets/javascripts/widgets/authenticator/main.js.coffee +4 -8
  7. data/lib/assets/javascripts/widgets/authenticator/presenter.js.coffee +4 -4
  8. data/lib/assets/javascripts/widgets/authenticator/states/default.html +1 -1
  9. data/lib/assets/javascripts/widgets/tray/main.js.coffee +26 -0
  10. data/lib/ende/version.rb +1 -1
  11. data/lib/tasks/component.thor +1 -1
  12. data/vendor/assets/javascripts/ende/build.js +10008 -8202
  13. data/vendor/components/KapIT-observe-utils/component.json +16 -0
  14. data/vendor/components/KapIT-observe-utils/lib/observe-utils.js +780 -0
  15. data/vendor/components/chaijs-assertion-error/component.json +18 -0
  16. data/vendor/components/chaijs-assertion-error/index.js +110 -0
  17. data/vendor/components/chaijs-chai/component.json +47 -0
  18. data/vendor/components/chaijs-chai/index.js +1 -0
  19. data/vendor/components/chaijs-chai/lib/chai/assertion.js +130 -0
  20. data/vendor/components/chaijs-chai/lib/chai/core/assertions.js +1270 -0
  21. data/vendor/components/chaijs-chai/lib/chai/interface/assert.js +1080 -0
  22. data/vendor/components/chaijs-chai/lib/chai/interface/expect.js +12 -0
  23. data/vendor/components/chaijs-chai/lib/chai/interface/should.js +76 -0
  24. data/vendor/components/chaijs-chai/lib/chai/utils/addChainableMethod.js +94 -0
  25. data/vendor/components/chaijs-chai/lib/chai/utils/addMethod.js +37 -0
  26. data/vendor/components/chaijs-chai/lib/chai/utils/addProperty.js +40 -0
  27. data/vendor/components/chaijs-chai/lib/chai/utils/flag.js +32 -0
  28. data/vendor/components/chaijs-chai/lib/chai/utils/getActual.js +19 -0
  29. data/vendor/components/chaijs-chai/lib/chai/utils/getEnumerableProperties.js +25 -0
  30. data/vendor/components/chaijs-chai/lib/chai/utils/getMessage.js +49 -0
  31. data/vendor/components/chaijs-chai/lib/chai/utils/getName.js +20 -0
  32. data/vendor/components/chaijs-chai/lib/chai/utils/getPathValue.js +102 -0
  33. data/vendor/components/chaijs-chai/lib/chai/utils/getProperties.js +35 -0
  34. data/vendor/components/chaijs-chai/lib/chai/utils/index.js +108 -0
  35. data/vendor/components/chaijs-chai/lib/chai/utils/inspect.js +320 -0
  36. data/vendor/components/chaijs-chai/lib/chai/utils/objDisplay.js +48 -0
  37. data/vendor/components/chaijs-chai/lib/chai/utils/overwriteMethod.js +51 -0
  38. data/vendor/components/chaijs-chai/lib/chai/utils/overwriteProperty.js +54 -0
  39. data/vendor/components/chaijs-chai/lib/chai/utils/test.js +26 -0
  40. data/vendor/components/chaijs-chai/lib/chai/utils/transferFlags.js +44 -0
  41. data/vendor/components/chaijs-chai/lib/chai/utils/type.js +45 -0
  42. data/vendor/components/chaijs-chai/lib/chai.js +80 -0
  43. data/vendor/components/chaijs-deep-eql/component.json +18 -0
  44. data/vendor/components/chaijs-deep-eql/lib/eql.js +257 -0
  45. data/vendor/components/chaijs-type-detect/component.json +16 -0
  46. data/vendor/components/chaijs-type-detect/lib/type.js +142 -0
  47. data/vendor/components/component-bind/component.json +14 -0
  48. data/vendor/components/component-bind/index.js +24 -0
  49. data/vendor/components/component-delegate/component.json +19 -0
  50. data/vendor/components/component-delegate/index.js +42 -0
  51. data/vendor/components/component-event/component.json +13 -0
  52. data/vendor/components/component-event/index.js +40 -0
  53. data/vendor/components/component-jquery/component.json +14 -0
  54. data/vendor/components/component-jquery/index.js +9601 -0
  55. data/vendor/components/component-link-delegate/component.json +23 -0
  56. data/vendor/components/component-link-delegate/index.js +60 -0
  57. data/vendor/components/component-matches-selector/component.json +20 -0
  58. data/vendor/components/component-matches-selector/index.js +45 -0
  59. data/vendor/components/component-query/component.json +21 -0
  60. data/vendor/components/component-query/index.js +21 -0
  61. data/vendor/components/component-type/component.json +18 -0
  62. data/vendor/components/component-type/index.js +32 -0
  63. data/vendor/components/component-url/component.json +17 -0
  64. data/vendor/components/component-url/index.js +63 -0
  65. data/vendor/components/components-modernizr/component.json +18 -0
  66. data/vendor/components/components-modernizr/modernizr.js +1393 -0
  67. data/vendor/components/discore-closest/component.json +14 -0
  68. data/vendor/components/discore-closest/index.js +18 -0
  69. data/vendor/components/indefinido-advisable/component.json +21 -0
  70. data/vendor/components/indefinido-advisable/index.js +1 -0
  71. data/vendor/components/indefinido-advisable/lib/advisable.js +60 -0
  72. data/vendor/components/indefinido-indemma/component.json +40 -0
  73. data/vendor/components/indefinido-indemma/index.js +1 -0
  74. data/vendor/components/indefinido-indemma/lib/extensions/rivets.js +23 -0
  75. data/vendor/components/indefinido-indemma/lib/record/associable.js +217 -0
  76. data/vendor/components/indefinido-indemma/lib/record/maid.js +24 -0
  77. data/vendor/components/indefinido-indemma/lib/record/resource.js +104 -0
  78. data/vendor/components/indefinido-indemma/lib/record/rest.js +36 -0
  79. data/vendor/components/indefinido-indemma/lib/record/restfulable.js +326 -0
  80. data/vendor/components/indefinido-indemma/lib/record/scopable.js +279 -0
  81. data/vendor/components/indefinido-indemma/lib/record/translationable.js +19 -0
  82. data/vendor/components/indefinido-indemma/lib/record/validatable.js +216 -0
  83. data/vendor/components/indefinido-indemma/lib/record/validations/associated.js +30 -0
  84. data/vendor/components/indefinido-indemma/lib/record/validations/confirmation.js +19 -0
  85. data/vendor/components/indefinido-indemma/lib/record/validations/cpf.js +60 -0
  86. data/vendor/components/indefinido-indemma/lib/record/validations/presence.js +19 -0
  87. data/vendor/components/indefinido-indemma/lib/record/validations/remote.js +71 -0
  88. data/vendor/components/indefinido-indemma/lib/record.js +167 -0
  89. data/vendor/components/indefinido-indemma/vendor/sinon.js +4290 -0
  90. data/vendor/components/indefinido-indemma/vendor/stampit.js +392 -0
  91. data/vendor/components/indefinido-observable/component.json +25 -0
  92. data/vendor/components/indefinido-observable/components/cjohansen-sinon/sinon.js +4290 -0
  93. data/vendor/components/indefinido-observable/index.js +1 -0
  94. data/vendor/components/indefinido-observable/lib/adapters/rivets.js +26 -0
  95. data/vendor/components/indefinido-observable/lib/observable.js +320 -0
  96. data/vendor/components/indefinido-observable/vendor/shims/accessors-legacy.js +92 -0
  97. data/vendor/components/indefinido-observable/vendor/shims/accessors.js +173 -0
  98. data/vendor/components/indefinido-observable/vendor/shims/array.indexOf.js +8 -0
  99. data/vendor/components/indefinido-observable/vendor/shims/object.create.js +77 -0
  100. data/vendor/components/mikeric-rivets/component.json +15 -0
  101. data/vendor/components/mikeric-rivets/dist/rivets.js +1239 -0
  102. data/vendor/components/paulmillr-es6-shim/component.json +17 -0
  103. data/vendor/components/paulmillr-es6-shim/es6-shim.js +985 -0
  104. data/vendor/components/pluma-assimilate/component.json +25 -0
  105. data/vendor/components/pluma-assimilate/dist/assimilate.js +87 -0
  106. data/vendor/components/segmentio-extend/component.json +13 -0
  107. data/vendor/components/segmentio-extend/index.js +15 -0
  108. metadata +98 -2
@@ -0,0 +1,1239 @@
1
+ // Rivets.js
2
+ // version: 0.6.0
3
+ // author: Michael Richards
4
+ // license: MIT
5
+ (function() {
6
+ var KeypathObserver, Rivets,
7
+ __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
8
+ __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
9
+ __slice = [].slice,
10
+ __hasProp = {}.hasOwnProperty,
11
+ __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; };
12
+
13
+ Rivets = {
14
+ binders: {},
15
+ components: {},
16
+ formatters: {},
17
+ adapters: {},
18
+ config: {
19
+ prefix: 'rv',
20
+ templateDelimiters: ['{', '}'],
21
+ rootInterface: '.',
22
+ preloadData: true,
23
+ handler: function(context, ev, binding) {
24
+ return this.call(context, ev, binding.view.models);
25
+ }
26
+ }
27
+ };
28
+
29
+ Rivets.Util = {
30
+ bindEvent: function(el, event, handler) {
31
+ if (window.jQuery != null) {
32
+ el = jQuery(el);
33
+ if (el.on != null) {
34
+ return el.on(event, handler);
35
+ } else {
36
+ return el.bind(event, handler);
37
+ }
38
+ } else if (window.addEventListener != null) {
39
+ return el.addEventListener(event, handler, false);
40
+ } else {
41
+ event = 'on' + event;
42
+ return el.attachEvent(event, handler);
43
+ }
44
+ },
45
+ unbindEvent: function(el, event, handler) {
46
+ if (window.jQuery != null) {
47
+ el = jQuery(el);
48
+ if (el.off != null) {
49
+ return el.off(event, handler);
50
+ } else {
51
+ return el.unbind(event, handler);
52
+ }
53
+ } else if (window.removeEventListener != null) {
54
+ return el.removeEventListener(event, handler, false);
55
+ } else {
56
+ event = 'on' + event;
57
+ return el.detachEvent(event, handler);
58
+ }
59
+ },
60
+ getInputValue: function(el) {
61
+ var o, _i, _len, _results;
62
+ if (window.jQuery != null) {
63
+ el = jQuery(el);
64
+ switch (el[0].type) {
65
+ case 'checkbox':
66
+ return el.is(':checked');
67
+ default:
68
+ return el.val();
69
+ }
70
+ } else {
71
+ switch (el.type) {
72
+ case 'checkbox':
73
+ return el.checked;
74
+ case 'select-multiple':
75
+ _results = [];
76
+ for (_i = 0, _len = el.length; _i < _len; _i++) {
77
+ o = el[_i];
78
+ if (o.selected) {
79
+ _results.push(o.value);
80
+ }
81
+ }
82
+ return _results;
83
+ break;
84
+ default:
85
+ return el.value;
86
+ }
87
+ }
88
+ }
89
+ };
90
+
91
+ Rivets.View = (function() {
92
+ function View(els, models, options) {
93
+ var k, option, v, _base, _i, _len, _ref, _ref1, _ref2;
94
+ this.els = els;
95
+ this.models = models;
96
+ this.options = options != null ? options : {};
97
+ this.update = __bind(this.update, this);
98
+ this.publish = __bind(this.publish, this);
99
+ this.sync = __bind(this.sync, this);
100
+ this.unbind = __bind(this.unbind, this);
101
+ this.bind = __bind(this.bind, this);
102
+ this.select = __bind(this.select, this);
103
+ this.build = __bind(this.build, this);
104
+ this.componentRegExp = __bind(this.componentRegExp, this);
105
+ this.bindingRegExp = __bind(this.bindingRegExp, this);
106
+ if (!(this.els.jquery || this.els instanceof Array)) {
107
+ this.els = [this.els];
108
+ }
109
+ _ref = ['config', 'binders', 'formatters', 'adapters'];
110
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
111
+ option = _ref[_i];
112
+ this[option] = {};
113
+ if (this.options[option]) {
114
+ _ref1 = this.options[option];
115
+ for (k in _ref1) {
116
+ v = _ref1[k];
117
+ this[option][k] = v;
118
+ }
119
+ }
120
+ _ref2 = Rivets[option];
121
+ for (k in _ref2) {
122
+ v = _ref2[k];
123
+ if ((_base = this[option])[k] == null) {
124
+ _base[k] = v;
125
+ }
126
+ }
127
+ }
128
+ this.build();
129
+ }
130
+
131
+ View.prototype.bindingRegExp = function() {
132
+ return new RegExp("^" + this.config.prefix + "-");
133
+ };
134
+
135
+ View.prototype.componentRegExp = function() {
136
+ return new RegExp("^" + (this.config.prefix.toUpperCase()) + "-");
137
+ };
138
+
139
+ View.prototype.build = function() {
140
+ var bindingRegExp, buildBinding, componentRegExp, el, parse, skipNodes, _i, _len, _ref,
141
+ _this = this;
142
+ this.bindings = [];
143
+ skipNodes = [];
144
+ bindingRegExp = this.bindingRegExp();
145
+ componentRegExp = this.componentRegExp();
146
+ buildBinding = function(binding, node, type, declaration) {
147
+ var context, ctx, dependencies, keypath, options, pipe, pipes;
148
+ options = {};
149
+ pipes = (function() {
150
+ var _i, _len, _ref, _results;
151
+ _ref = declaration.split('|');
152
+ _results = [];
153
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
154
+ pipe = _ref[_i];
155
+ _results.push(pipe.trim());
156
+ }
157
+ return _results;
158
+ })();
159
+ context = (function() {
160
+ var _i, _len, _ref, _results;
161
+ _ref = pipes.shift().split('<');
162
+ _results = [];
163
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
164
+ ctx = _ref[_i];
165
+ _results.push(ctx.trim());
166
+ }
167
+ return _results;
168
+ })();
169
+ keypath = context.shift();
170
+ options.formatters = pipes;
171
+ if (dependencies = context.shift()) {
172
+ options.dependencies = dependencies.split(/\s+/);
173
+ }
174
+ return _this.bindings.push(new Rivets[binding](_this, node, type, keypath, options));
175
+ };
176
+ parse = function(node) {
177
+ var attribute, attributes, binder, childNode, delimiters, identifier, n, parser, regexp, restTokens, startToken, text, token, tokens, type, value, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref, _ref1, _ref2, _ref3, _ref4, _results;
178
+ if (__indexOf.call(skipNodes, node) < 0) {
179
+ if (node.nodeType === Node.TEXT_NODE) {
180
+ parser = Rivets.TextTemplateParser;
181
+ if (delimiters = _this.config.templateDelimiters) {
182
+ if ((tokens = parser.parse(node.data, delimiters)).length) {
183
+ if (!(tokens.length === 1 && tokens[0].type === parser.types.text)) {
184
+ startToken = tokens[0], restTokens = 2 <= tokens.length ? __slice.call(tokens, 1) : [];
185
+ node.data = startToken.value;
186
+ if (startToken.type === 0) {
187
+ node.data = startToken.value;
188
+ } else {
189
+ buildBinding('TextBinding', node, null, startToken.value);
190
+ }
191
+ for (_i = 0, _len = restTokens.length; _i < _len; _i++) {
192
+ token = restTokens[_i];
193
+ text = document.createTextNode(token.value);
194
+ node.parentNode.appendChild(text);
195
+ if (token.type === 1) {
196
+ buildBinding('TextBinding', text, null, token.value);
197
+ }
198
+ }
199
+ }
200
+ }
201
+ }
202
+ } else if (componentRegExp.test(node.tagName)) {
203
+ type = node.tagName.replace(componentRegExp, '').toLowerCase();
204
+ _this.bindings.push(new Rivets.ComponentBinding(_this, node, type));
205
+ } else if (node.attributes != null) {
206
+ _ref = node.attributes;
207
+ for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
208
+ attribute = _ref[_j];
209
+ if (bindingRegExp.test(attribute.name)) {
210
+ type = attribute.name.replace(bindingRegExp, '');
211
+ if (!(binder = _this.binders[type])) {
212
+ _ref1 = _this.binders;
213
+ for (identifier in _ref1) {
214
+ value = _ref1[identifier];
215
+ if (identifier !== '*' && identifier.indexOf('*') !== -1) {
216
+ regexp = new RegExp("^" + (identifier.replace('*', '.+')) + "$");
217
+ if (regexp.test(type)) {
218
+ binder = value;
219
+ }
220
+ }
221
+ }
222
+ }
223
+ binder || (binder = _this.binders['*']);
224
+ if (binder.block) {
225
+ _ref2 = node.childNodes;
226
+ for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
227
+ n = _ref2[_k];
228
+ skipNodes.push(n);
229
+ }
230
+ attributes = [attribute];
231
+ }
232
+ }
233
+ }
234
+ _ref3 = attributes || node.attributes;
235
+ for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) {
236
+ attribute = _ref3[_l];
237
+ if (bindingRegExp.test(attribute.name)) {
238
+ type = attribute.name.replace(bindingRegExp, '');
239
+ buildBinding('Binding', node, type, attribute.value);
240
+ }
241
+ }
242
+ }
243
+ _ref4 = node.childNodes;
244
+ _results = [];
245
+ for (_m = 0, _len4 = _ref4.length; _m < _len4; _m++) {
246
+ childNode = _ref4[_m];
247
+ _results.push(parse(childNode));
248
+ }
249
+ return _results;
250
+ }
251
+ };
252
+ _ref = this.els;
253
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
254
+ el = _ref[_i];
255
+ parse(el);
256
+ }
257
+ };
258
+
259
+ View.prototype.select = function(fn) {
260
+ var binding, _i, _len, _ref, _results;
261
+ _ref = this.bindings;
262
+ _results = [];
263
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
264
+ binding = _ref[_i];
265
+ if (fn(binding)) {
266
+ _results.push(binding);
267
+ }
268
+ }
269
+ return _results;
270
+ };
271
+
272
+ View.prototype.bind = function() {
273
+ var binding, _i, _len, _ref, _results;
274
+ _ref = this.bindings;
275
+ _results = [];
276
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
277
+ binding = _ref[_i];
278
+ _results.push(binding.bind());
279
+ }
280
+ return _results;
281
+ };
282
+
283
+ View.prototype.unbind = function() {
284
+ var binding, _i, _len, _ref, _results;
285
+ _ref = this.bindings;
286
+ _results = [];
287
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
288
+ binding = _ref[_i];
289
+ _results.push(binding.unbind());
290
+ }
291
+ return _results;
292
+ };
293
+
294
+ View.prototype.sync = function() {
295
+ var binding, _i, _len, _ref, _results;
296
+ _ref = this.bindings;
297
+ _results = [];
298
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
299
+ binding = _ref[_i];
300
+ _results.push(binding.sync());
301
+ }
302
+ return _results;
303
+ };
304
+
305
+ View.prototype.publish = function() {
306
+ var binding, _i, _len, _ref, _results;
307
+ _ref = this.select(function(b) {
308
+ return b.binder.publishes;
309
+ });
310
+ _results = [];
311
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
312
+ binding = _ref[_i];
313
+ _results.push(binding.publish());
314
+ }
315
+ return _results;
316
+ };
317
+
318
+ View.prototype.update = function(models) {
319
+ var binding, key, model, _i, _len, _ref, _results;
320
+ if (models == null) {
321
+ models = {};
322
+ }
323
+ for (key in models) {
324
+ model = models[key];
325
+ this.models[key] = model;
326
+ }
327
+ _ref = this.bindings;
328
+ _results = [];
329
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
330
+ binding = _ref[_i];
331
+ _results.push(binding.update(models));
332
+ }
333
+ return _results;
334
+ };
335
+
336
+ return View;
337
+
338
+ })();
339
+
340
+ Rivets.Binding = (function() {
341
+ function Binding(view, el, type, keypath, options) {
342
+ this.view = view;
343
+ this.el = el;
344
+ this.type = type;
345
+ this.keypath = keypath;
346
+ this.options = options != null ? options : {};
347
+ this.update = __bind(this.update, this);
348
+ this.unbind = __bind(this.unbind, this);
349
+ this.bind = __bind(this.bind, this);
350
+ this.publish = __bind(this.publish, this);
351
+ this.sync = __bind(this.sync, this);
352
+ this.set = __bind(this.set, this);
353
+ this.eventHandler = __bind(this.eventHandler, this);
354
+ this.formattedValue = __bind(this.formattedValue, this);
355
+ this.setObserver = __bind(this.setObserver, this);
356
+ this.setBinder = __bind(this.setBinder, this);
357
+ this.formatters = this.options.formatters || [];
358
+ this.dependencies = [];
359
+ this.setBinder();
360
+ this.setObserver();
361
+ }
362
+
363
+ Binding.prototype.setBinder = function() {
364
+ var identifier, regexp, value, _ref;
365
+ if (!(this.binder = this.view.binders[this.type])) {
366
+ _ref = this.view.binders;
367
+ for (identifier in _ref) {
368
+ value = _ref[identifier];
369
+ if (identifier !== '*' && identifier.indexOf('*') !== -1) {
370
+ regexp = new RegExp("^" + (identifier.replace('*', '.+')) + "$");
371
+ if (regexp.test(this.type)) {
372
+ this.binder = value;
373
+ this.args = new RegExp("^" + (identifier.replace('*', '(.+)')) + "$").exec(this.type);
374
+ this.args.shift();
375
+ }
376
+ }
377
+ }
378
+ }
379
+ this.binder || (this.binder = this.view.binders['*']);
380
+ if (this.binder instanceof Function) {
381
+ return this.binder = {
382
+ routine: this.binder
383
+ };
384
+ }
385
+ };
386
+
387
+ Binding.prototype.setObserver = function() {
388
+ var _this = this;
389
+ this.observer = new KeypathObserver(this.view, this.view.models, this.keypath, function(obs) {
390
+ if (_this.key) {
391
+ _this.unbind(true);
392
+ }
393
+ _this.model = obs.target;
394
+ if (_this.key) {
395
+ _this.bind(true);
396
+ }
397
+ return _this.sync();
398
+ });
399
+ this.key = this.observer.key;
400
+ return this.model = this.observer.target;
401
+ };
402
+
403
+ Binding.prototype.formattedValue = function(value) {
404
+ var args, formatter, id, _i, _len, _ref;
405
+ _ref = this.formatters;
406
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
407
+ formatter = _ref[_i];
408
+ args = formatter.split(/\s+/);
409
+ id = args.shift();
410
+ formatter = this.view.formatters[id];
411
+ if ((formatter != null ? formatter.read : void 0) instanceof Function) {
412
+ value = formatter.read.apply(formatter, [value].concat(__slice.call(args)));
413
+ } else if (formatter instanceof Function) {
414
+ value = formatter.apply(null, [value].concat(__slice.call(args)));
415
+ }
416
+ }
417
+ return value;
418
+ };
419
+
420
+ Binding.prototype.eventHandler = function(fn) {
421
+ var binding, handler;
422
+ handler = (binding = this).view.config.handler;
423
+ return function(ev) {
424
+ return handler.call(fn, this, ev, binding);
425
+ };
426
+ };
427
+
428
+ Binding.prototype.set = function(value) {
429
+ var _ref;
430
+ value = value instanceof Function && !this.binder["function"] ? this.formattedValue(value.call(this.model)) : this.formattedValue(value);
431
+ return (_ref = this.binder.routine) != null ? _ref.call(this, this.el, value) : void 0;
432
+ };
433
+
434
+ Binding.prototype.sync = function() {
435
+ return this.set(this.key ? this.view.adapters[this.key["interface"]].read(this.model, this.key.path) : this.model);
436
+ };
437
+
438
+ Binding.prototype.publish = function() {
439
+ var args, formatter, id, value, _i, _len, _ref, _ref1, _ref2;
440
+ value = Rivets.Util.getInputValue(this.el);
441
+ _ref = this.formatters.slice(0).reverse();
442
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
443
+ formatter = _ref[_i];
444
+ args = formatter.split(/\s+/);
445
+ id = args.shift();
446
+ if ((_ref1 = this.view.formatters[id]) != null ? _ref1.publish : void 0) {
447
+ value = (_ref2 = this.view.formatters[id]).publish.apply(_ref2, [value].concat(__slice.call(args)));
448
+ }
449
+ }
450
+ return this.view.adapters[this.key["interface"]].publish(this.model, this.key.path, value);
451
+ };
452
+
453
+ Binding.prototype.bind = function(silent) {
454
+ var dependency, key, observer, _i, _len, _ref, _ref1, _ref2, _results,
455
+ _this = this;
456
+ if (silent == null) {
457
+ silent = false;
458
+ }
459
+ if (!silent) {
460
+ if ((_ref = this.binder.bind) != null) {
461
+ _ref.call(this, this.el);
462
+ }
463
+ }
464
+ if (this.key) {
465
+ this.view.adapters[this.key["interface"]].subscribe(this.model, this.key.path, this.sync);
466
+ }
467
+ if (!silent ? this.view.config.preloadData : void 0) {
468
+ this.sync();
469
+ }
470
+ if ((_ref1 = this.options.dependencies) != null ? _ref1.length : void 0) {
471
+ _ref2 = this.options.dependencies;
472
+ _results = [];
473
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
474
+ dependency = _ref2[_i];
475
+ observer = new KeypathObserver(this.view, this.model, dependency, function(obs, prev) {
476
+ var key;
477
+ key = obs.key;
478
+ _this.view.adapters[key["interface"]].unsubscribe(prev, key.path, _this.sync);
479
+ _this.view.adapters[key["interface"]].subscribe(obs.target, key.path, _this.sync);
480
+ return _this.sync();
481
+ });
482
+ key = observer.key;
483
+ this.view.adapters[key["interface"]].subscribe(observer.target, key.path, this.sync);
484
+ _results.push(this.dependencies.push(observer));
485
+ }
486
+ return _results;
487
+ }
488
+ };
489
+
490
+ Binding.prototype.unbind = function(silent) {
491
+ var key, obs, _i, _len, _ref, _ref1;
492
+ if (silent == null) {
493
+ silent = false;
494
+ }
495
+ if (!silent) {
496
+ if ((_ref = this.binder.unbind) != null) {
497
+ _ref.call(this, this.el);
498
+ }
499
+ }
500
+ if (this.key) {
501
+ this.view.adapters[this.key["interface"]].unsubscribe(this.model, this.key.path, this.sync);
502
+ }
503
+ if (this.dependencies.length) {
504
+ _ref1 = this.dependencies;
505
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
506
+ obs = _ref1[_i];
507
+ key = obs.key;
508
+ this.view.adapters[key["interface"]].unsubscribe(obs.target, key.path, this.sync);
509
+ }
510
+ return this.dependencies = [];
511
+ }
512
+ };
513
+
514
+ Binding.prototype.update = function(models) {
515
+ var _ref;
516
+ if (models == null) {
517
+ models = {};
518
+ }
519
+ return (_ref = this.binder.update) != null ? _ref.call(this, models) : void 0;
520
+ };
521
+
522
+ return Binding;
523
+
524
+ })();
525
+
526
+ Rivets.ComponentBinding = (function(_super) {
527
+ __extends(ComponentBinding, _super);
528
+
529
+ function ComponentBinding(view, el, type) {
530
+ var attribute, _i, _len, _ref, _ref1;
531
+ this.view = view;
532
+ this.el = el;
533
+ this.type = type;
534
+ this.unbind = __bind(this.unbind, this);
535
+ this.bind = __bind(this.bind, this);
536
+ this.update = __bind(this.update, this);
537
+ this.locals = __bind(this.locals, this);
538
+ this.component = Rivets.components[this.type];
539
+ this.attributes = {};
540
+ this.inflections = {};
541
+ _ref = this.el.attributes || [];
542
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
543
+ attribute = _ref[_i];
544
+ if (_ref1 = attribute.name, __indexOf.call(this.component.attributes, _ref1) >= 0) {
545
+ this.attributes[attribute.name] = attribute.value;
546
+ } else {
547
+ this.inflections[attribute.name] = attribute.value;
548
+ }
549
+ }
550
+ }
551
+
552
+ ComponentBinding.prototype.sync = function() {};
553
+
554
+ ComponentBinding.prototype.locals = function(models) {
555
+ var inverse, key, model, path, result, _i, _len, _ref, _ref1;
556
+ if (models == null) {
557
+ models = this.view.models;
558
+ }
559
+ result = {};
560
+ _ref = this.inflections;
561
+ for (key in _ref) {
562
+ inverse = _ref[key];
563
+ _ref1 = inverse.split('.');
564
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
565
+ path = _ref1[_i];
566
+ result[key] = (result[key] || models)[path];
567
+ }
568
+ }
569
+ for (key in models) {
570
+ model = models[key];
571
+ if (result[key] == null) {
572
+ result[key] = model;
573
+ }
574
+ }
575
+ return result;
576
+ };
577
+
578
+ ComponentBinding.prototype.update = function(models) {
579
+ var _ref;
580
+ return (_ref = this.componentView) != null ? _ref.update(this.locals(models)) : void 0;
581
+ };
582
+
583
+ ComponentBinding.prototype.bind = function() {
584
+ var el, _ref;
585
+ if (this.componentView != null) {
586
+ return (_ref = this.componentView) != null ? _ref.bind() : void 0;
587
+ } else {
588
+ el = this.component.build.call(this.attributes);
589
+ (this.componentView = new Rivets.View(el, this.locals(), this.view.options)).bind();
590
+ return this.el.parentNode.replaceChild(el, this.el);
591
+ }
592
+ };
593
+
594
+ ComponentBinding.prototype.unbind = function() {
595
+ var _ref;
596
+ return (_ref = this.componentView) != null ? _ref.unbind() : void 0;
597
+ };
598
+
599
+ return ComponentBinding;
600
+
601
+ })(Rivets.Binding);
602
+
603
+ Rivets.TextBinding = (function(_super) {
604
+ __extends(TextBinding, _super);
605
+
606
+ function TextBinding(view, el, type, keypath, options) {
607
+ this.view = view;
608
+ this.el = el;
609
+ this.type = type;
610
+ this.keypath = keypath;
611
+ this.options = options != null ? options : {};
612
+ this.sync = __bind(this.sync, this);
613
+ this.formatters = this.options.formatters || [];
614
+ this.dependencies = [];
615
+ this.setObserver();
616
+ }
617
+
618
+ TextBinding.prototype.binder = {
619
+ routine: function(node, value) {
620
+ return node.data = value != null ? value : '';
621
+ }
622
+ };
623
+
624
+ TextBinding.prototype.sync = function() {
625
+ return TextBinding.__super__.sync.apply(this, arguments);
626
+ };
627
+
628
+ return TextBinding;
629
+
630
+ })(Rivets.Binding);
631
+
632
+ Rivets.KeypathParser = (function() {
633
+ function KeypathParser() {}
634
+
635
+ KeypathParser.parse = function(keypath, interfaces, root) {
636
+ var char, current, index, tokens;
637
+ tokens = [];
638
+ current = {
639
+ "interface": root,
640
+ path: ''
641
+ };
642
+ for (index in keypath) {
643
+ char = keypath[index];
644
+ if (__indexOf.call(interfaces, char) >= 0) {
645
+ tokens.push(current);
646
+ current = {
647
+ "interface": char,
648
+ path: ''
649
+ };
650
+ } else {
651
+ current.path += char;
652
+ }
653
+ }
654
+ tokens.push(current);
655
+ return tokens;
656
+ };
657
+
658
+ return KeypathParser;
659
+
660
+ })();
661
+
662
+ Rivets.TextTemplateParser = (function() {
663
+ function TextTemplateParser() {}
664
+
665
+ TextTemplateParser.types = {
666
+ text: 0,
667
+ binding: 1
668
+ };
669
+
670
+ TextTemplateParser.parse = function(template, delimiters) {
671
+ var index, lastIndex, lastToken, length, substring, tokens, value;
672
+ tokens = [];
673
+ length = template.length;
674
+ index = 0;
675
+ lastIndex = 0;
676
+ while (lastIndex < length) {
677
+ index = template.indexOf(delimiters[0], lastIndex);
678
+ if (index < 0) {
679
+ tokens.push({
680
+ type: this.types.text,
681
+ value: template.slice(lastIndex)
682
+ });
683
+ break;
684
+ } else {
685
+ if (index > 0 && lastIndex < index) {
686
+ tokens.push({
687
+ type: this.types.text,
688
+ value: template.slice(lastIndex, index)
689
+ });
690
+ }
691
+ lastIndex = index + 2;
692
+ index = template.indexOf(delimiters[1], lastIndex);
693
+ if (index < 0) {
694
+ substring = template.slice(lastIndex - 2);
695
+ lastToken = tokens[tokens.length - 1];
696
+ if ((lastToken != null ? lastToken.type : void 0) === this.types.text) {
697
+ lastToken.value += substring;
698
+ } else {
699
+ tokens.push({
700
+ type: this.types.text,
701
+ value: substring
702
+ });
703
+ }
704
+ break;
705
+ }
706
+ value = template.slice(lastIndex, index).trim();
707
+ tokens.push({
708
+ type: this.types.binding,
709
+ value: value
710
+ });
711
+ lastIndex = index + 2;
712
+ }
713
+ }
714
+ return tokens;
715
+ };
716
+
717
+ return TextTemplateParser;
718
+
719
+ })();
720
+
721
+ KeypathObserver = (function() {
722
+ function KeypathObserver(view, model, keypath, callback) {
723
+ this.view = view;
724
+ this.model = model;
725
+ this.keypath = keypath;
726
+ this.callback = callback;
727
+ this.realize = __bind(this.realize, this);
728
+ this.update = __bind(this.update, this);
729
+ this.parse = __bind(this.parse, this);
730
+ this.parse();
731
+ this.objectPath = [];
732
+ this.target = this.realize();
733
+ }
734
+
735
+ KeypathObserver.prototype.parse = function() {
736
+ var interfaces, k, path, root, v, _ref;
737
+ interfaces = (function() {
738
+ var _ref, _results;
739
+ _ref = this.view.adapters;
740
+ _results = [];
741
+ for (k in _ref) {
742
+ v = _ref[k];
743
+ _results.push(k);
744
+ }
745
+ return _results;
746
+ }).call(this);
747
+ if (_ref = this.keypath[0], __indexOf.call(interfaces, _ref) >= 0) {
748
+ root = this.keypath[0];
749
+ path = this.keypath.substr(1);
750
+ } else {
751
+ root = this.view.config.rootInterface;
752
+ path = this.keypath;
753
+ }
754
+ this.tokens = Rivets.KeypathParser.parse(path, interfaces, root);
755
+ return this.key = this.tokens.pop();
756
+ };
757
+
758
+ KeypathObserver.prototype.update = function() {
759
+ var next, prev;
760
+ if ((next = this.realize()) !== this.target) {
761
+ prev = this.target;
762
+ this.target = next;
763
+ return this.callback(this, prev);
764
+ }
765
+ };
766
+
767
+ KeypathObserver.prototype.realize = function() {
768
+ var current, index, prev, token, _i, _len, _ref;
769
+ current = this.model;
770
+ _ref = this.tokens;
771
+ for (index = _i = 0, _len = _ref.length; _i < _len; index = ++_i) {
772
+ token = _ref[index];
773
+ if (this.objectPath[index] != null) {
774
+ if (current !== (prev = this.objectPath[index])) {
775
+ this.view.adapters[token["interface"]].unsubscribe(prev, token.path, this.update);
776
+ this.view.adapters[token["interface"]].subscribe(current, token.path, this.update);
777
+ this.objectPath[index] = current;
778
+ }
779
+ } else {
780
+ this.view.adapters[token["interface"]].subscribe(current, token.path, this.update);
781
+ this.objectPath[index] = current;
782
+ }
783
+ current = this.view.adapters[token["interface"]].read(current, token.path);
784
+ }
785
+ return current;
786
+ };
787
+
788
+ return KeypathObserver;
789
+
790
+ })();
791
+
792
+ Rivets.binders.enabled = function(el, value) {
793
+ return el.disabled = !value;
794
+ };
795
+
796
+ Rivets.binders.disabled = function(el, value) {
797
+ return el.disabled = !!value;
798
+ };
799
+
800
+ Rivets.binders.checked = {
801
+ publishes: true,
802
+ bind: function(el) {
803
+ return Rivets.Util.bindEvent(el, 'change', this.publish);
804
+ },
805
+ unbind: function(el) {
806
+ return Rivets.Util.unbindEvent(el, 'change', this.publish);
807
+ },
808
+ routine: function(el, value) {
809
+ var _ref;
810
+ if (el.type === 'radio') {
811
+ return el.checked = ((_ref = el.value) != null ? _ref.toString() : void 0) === (value != null ? value.toString() : void 0);
812
+ } else {
813
+ return el.checked = !!value;
814
+ }
815
+ }
816
+ };
817
+
818
+ Rivets.binders.unchecked = {
819
+ publishes: true,
820
+ bind: function(el) {
821
+ return Rivets.Util.bindEvent(el, 'change', this.publish);
822
+ },
823
+ unbind: function(el) {
824
+ return Rivets.Util.unbindEvent(el, 'change', this.publish);
825
+ },
826
+ routine: function(el, value) {
827
+ var _ref;
828
+ if (el.type === 'radio') {
829
+ return el.checked = ((_ref = el.value) != null ? _ref.toString() : void 0) !== (value != null ? value.toString() : void 0);
830
+ } else {
831
+ return el.checked = !value;
832
+ }
833
+ }
834
+ };
835
+
836
+ Rivets.binders.show = function(el, value) {
837
+ return el.style.display = value ? '' : 'none';
838
+ };
839
+
840
+ Rivets.binders.hide = function(el, value) {
841
+ return el.style.display = value ? 'none' : '';
842
+ };
843
+
844
+ Rivets.binders.html = function(el, value) {
845
+ return el.innerHTML = value != null ? value : '';
846
+ };
847
+
848
+ Rivets.binders.value = {
849
+ publishes: true,
850
+ bind: function(el) {
851
+ return Rivets.Util.bindEvent(el, 'change', this.publish);
852
+ },
853
+ unbind: function(el) {
854
+ return Rivets.Util.unbindEvent(el, 'change', this.publish);
855
+ },
856
+ routine: function(el, value) {
857
+ var o, _i, _len, _ref, _ref1, _ref2, _results;
858
+ if (window.jQuery != null) {
859
+ el = jQuery(el);
860
+ if ((value != null ? value.toString() : void 0) !== ((_ref = el.val()) != null ? _ref.toString() : void 0)) {
861
+ return el.val(value != null ? value : '');
862
+ }
863
+ } else {
864
+ if (el.type === 'select-multiple') {
865
+ if (value != null) {
866
+ _results = [];
867
+ for (_i = 0, _len = el.length; _i < _len; _i++) {
868
+ o = el[_i];
869
+ _results.push(o.selected = (_ref1 = o.value, __indexOf.call(value, _ref1) >= 0));
870
+ }
871
+ return _results;
872
+ }
873
+ } else if ((value != null ? value.toString() : void 0) !== ((_ref2 = el.value) != null ? _ref2.toString() : void 0)) {
874
+ return el.value = value != null ? value : '';
875
+ }
876
+ }
877
+ }
878
+ };
879
+
880
+ Rivets.binders.text = function(el, value) {
881
+ if (el.innerText != null) {
882
+ return el.innerText = value != null ? value : '';
883
+ } else {
884
+ return el.textContent = value != null ? value : '';
885
+ }
886
+ };
887
+
888
+ Rivets.binders["if"] = {
889
+ block: true,
890
+ bind: function(el) {
891
+ var attr, declaration;
892
+ if (this.marker == null) {
893
+ attr = [this.view.config.prefix, this.type].join('-').replace('--', '-');
894
+ declaration = el.getAttribute(attr);
895
+ this.marker = document.createComment(" rivets: " + this.type + " " + declaration + " ");
896
+ el.removeAttribute(attr);
897
+ el.parentNode.insertBefore(this.marker, el);
898
+ return el.parentNode.removeChild(el);
899
+ }
900
+ },
901
+ unbind: function() {
902
+ var _ref;
903
+ return (_ref = this.nested) != null ? _ref.unbind() : void 0;
904
+ },
905
+ routine: function(el, value) {
906
+ var key, model, models, options, _ref;
907
+ if (!!value === (this.nested == null)) {
908
+ if (value) {
909
+ models = {};
910
+ _ref = this.view.models;
911
+ for (key in _ref) {
912
+ model = _ref[key];
913
+ models[key] = model;
914
+ }
915
+ options = {
916
+ binders: this.view.options.binders,
917
+ formatters: this.view.options.formatters,
918
+ adapters: this.view.options.adapters,
919
+ config: this.view.options.config
920
+ };
921
+ (this.nested = new Rivets.View(el, models, options)).bind();
922
+ return this.marker.parentNode.insertBefore(el, this.marker.nextSibling);
923
+ } else {
924
+ el.parentNode.removeChild(el);
925
+ this.nested.unbind();
926
+ return delete this.nested;
927
+ }
928
+ }
929
+ },
930
+ update: function(models) {
931
+ var _ref;
932
+ return (_ref = this.nested) != null ? _ref.update(models) : void 0;
933
+ }
934
+ };
935
+
936
+ Rivets.binders.unless = {
937
+ block: true,
938
+ bind: function(el) {
939
+ return Rivets.binders["if"].bind.call(this, el);
940
+ },
941
+ unbind: function() {
942
+ return Rivets.binders["if"].unbind.call(this);
943
+ },
944
+ routine: function(el, value) {
945
+ return Rivets.binders["if"].routine.call(this, el, !value);
946
+ },
947
+ update: function(models) {
948
+ return Rivets.binders["if"].update.call(this, models);
949
+ }
950
+ };
951
+
952
+ Rivets.binders['on-*'] = {
953
+ "function": true,
954
+ unbind: function(el) {
955
+ if (this.handler) {
956
+ return Rivets.Util.unbindEvent(el, this.args[0], this.handler);
957
+ }
958
+ },
959
+ routine: function(el, value) {
960
+ if (this.handler) {
961
+ Rivets.Util.unbindEvent(el, this.args[0], this.handler);
962
+ }
963
+ return Rivets.Util.bindEvent(el, this.args[0], this.handler = this.eventHandler(value));
964
+ }
965
+ };
966
+
967
+ Rivets.binders['each-*'] = {
968
+ block: true,
969
+ bind: function(el) {
970
+ var attr;
971
+ if (this.marker == null) {
972
+ attr = [this.view.config.prefix, this.type].join('-').replace('--', '-');
973
+ this.marker = document.createComment(" rivets: " + this.type + " ");
974
+ this.iterated = [];
975
+ el.removeAttribute(attr);
976
+ el.parentNode.insertBefore(this.marker, el);
977
+ return el.parentNode.removeChild(el);
978
+ }
979
+ },
980
+ unbind: function(el) {
981
+ var view, _i, _len, _ref, _results;
982
+ if (this.iterated != null) {
983
+ _ref = this.iterated;
984
+ _results = [];
985
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
986
+ view = _ref[_i];
987
+ _results.push(view.unbind());
988
+ }
989
+ return _results;
990
+ }
991
+ },
992
+ routine: function(el, collection) {
993
+ var binding, data, i, index, k, key, model, modelName, options, previous, template, v, view, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _ref3, _results;
994
+ modelName = this.args[0];
995
+ collection = collection || [];
996
+ if (this.iterated.length > collection.length) {
997
+ _ref = Array(this.iterated.length - collection.length);
998
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
999
+ i = _ref[_i];
1000
+ view = this.iterated.pop();
1001
+ view.unbind();
1002
+ this.marker.parentNode.removeChild(view.els[0]);
1003
+ }
1004
+ }
1005
+ for (index = _j = 0, _len1 = collection.length; _j < _len1; index = ++_j) {
1006
+ model = collection[index];
1007
+ data = {};
1008
+ data[modelName] = model;
1009
+ if (this.iterated[index] == null) {
1010
+ _ref1 = this.view.models;
1011
+ for (key in _ref1) {
1012
+ model = _ref1[key];
1013
+ if (data[key] == null) {
1014
+ data[key] = model;
1015
+ }
1016
+ }
1017
+ previous = this.iterated.length ? this.iterated[this.iterated.length - 1].els[0] : this.marker;
1018
+ options = {
1019
+ binders: this.view.options.binders,
1020
+ formatters: this.view.options.formatters,
1021
+ adapters: this.view.options.adapters,
1022
+ config: {}
1023
+ };
1024
+ _ref2 = this.view.options.config;
1025
+ for (k in _ref2) {
1026
+ v = _ref2[k];
1027
+ options.config[k] = v;
1028
+ }
1029
+ options.config.preloadData = true;
1030
+ template = el.cloneNode(true);
1031
+ view = new Rivets.View(template, data, options);
1032
+ view.bind();
1033
+ this.iterated.push(view);
1034
+ this.marker.parentNode.insertBefore(template, previous.nextSibling);
1035
+ } else if (this.iterated[index].models[modelName] !== model) {
1036
+ this.iterated[index].update(data);
1037
+ }
1038
+ }
1039
+ if (el.nodeName === 'OPTION') {
1040
+ _ref3 = this.view.bindings;
1041
+ _results = [];
1042
+ for (_k = 0, _len2 = _ref3.length; _k < _len2; _k++) {
1043
+ binding = _ref3[_k];
1044
+ if (binding.el === this.marker.parentNode && binding.type === 'value') {
1045
+ _results.push(binding.sync());
1046
+ } else {
1047
+ _results.push(void 0);
1048
+ }
1049
+ }
1050
+ return _results;
1051
+ }
1052
+ },
1053
+ update: function(models) {
1054
+ var data, key, model, view, _i, _len, _ref, _results;
1055
+ data = {};
1056
+ for (key in models) {
1057
+ model = models[key];
1058
+ if (key !== this.args[0]) {
1059
+ data[key] = model;
1060
+ }
1061
+ }
1062
+ _ref = this.iterated;
1063
+ _results = [];
1064
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1065
+ view = _ref[_i];
1066
+ _results.push(view.update(data));
1067
+ }
1068
+ return _results;
1069
+ }
1070
+ };
1071
+
1072
+ Rivets.binders['class-*'] = function(el, value) {
1073
+ var elClass;
1074
+ elClass = " " + el.className + " ";
1075
+ if (!value === (elClass.indexOf(" " + this.args[0] + " ") !== -1)) {
1076
+ return el.className = value ? "" + el.className + " " + this.args[0] : elClass.replace(" " + this.args[0] + " ", ' ').trim();
1077
+ }
1078
+ };
1079
+
1080
+ Rivets.binders['*'] = function(el, value) {
1081
+ if (value) {
1082
+ return el.setAttribute(this.type, value);
1083
+ } else {
1084
+ return el.removeAttribute(this.type);
1085
+ }
1086
+ };
1087
+
1088
+ Rivets.adapters['.'] = {
1089
+ id: '_rv',
1090
+ counter: 0,
1091
+ weakmap: {},
1092
+ weakReference: function(obj) {
1093
+ var id;
1094
+ if (obj[this.id] == null) {
1095
+ id = this.counter++;
1096
+ this.weakmap[id] = {
1097
+ callbacks: {}
1098
+ };
1099
+ Object.defineProperty(obj, this.id, {
1100
+ value: id
1101
+ });
1102
+ }
1103
+ return this.weakmap[obj[this.id]];
1104
+ },
1105
+ stubFunction: function(obj, fn) {
1106
+ var map, original, weakmap;
1107
+ original = obj[fn];
1108
+ map = this.weakReference(obj);
1109
+ weakmap = this.weakmap;
1110
+ return obj[fn] = function() {
1111
+ var callback, k, r, response, _i, _len, _ref, _ref1, _ref2, _ref3;
1112
+ response = original.apply(obj, arguments);
1113
+ _ref = map.pointers;
1114
+ for (r in _ref) {
1115
+ k = _ref[r];
1116
+ _ref3 = (_ref1 = (_ref2 = weakmap[r]) != null ? _ref2.callbacks[k] : void 0) != null ? _ref1 : [];
1117
+ for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
1118
+ callback = _ref3[_i];
1119
+ callback();
1120
+ }
1121
+ }
1122
+ return response;
1123
+ };
1124
+ },
1125
+ observeMutations: function(obj, ref, keypath) {
1126
+ var fn, functions, map, _base, _i, _len;
1127
+ if (Array.isArray(obj)) {
1128
+ map = this.weakReference(obj);
1129
+ if (map.pointers == null) {
1130
+ map.pointers = {};
1131
+ functions = ['push', 'pop', 'shift', 'unshift', 'sort', 'reverse', 'splice'];
1132
+ for (_i = 0, _len = functions.length; _i < _len; _i++) {
1133
+ fn = functions[_i];
1134
+ this.stubFunction(obj, fn);
1135
+ }
1136
+ }
1137
+ if ((_base = map.pointers)[ref] == null) {
1138
+ _base[ref] = [];
1139
+ }
1140
+ if (__indexOf.call(map.pointers[ref], keypath) < 0) {
1141
+ return map.pointers[ref].push(keypath);
1142
+ }
1143
+ }
1144
+ },
1145
+ unobserveMutations: function(obj, ref, keypath) {
1146
+ var keypaths, _ref;
1147
+ if (Array.isArray(obj && (obj[this.id] != null))) {
1148
+ if (keypaths = (_ref = this.weakReference(obj).pointers) != null ? _ref[ref] : void 0) {
1149
+ return keypaths.splice(keypaths.indexOf(keypath), 1);
1150
+ }
1151
+ }
1152
+ },
1153
+ subscribe: function(obj, keypath, callback) {
1154
+ var callbacks, value,
1155
+ _this = this;
1156
+ callbacks = this.weakReference(obj).callbacks;
1157
+ if (callbacks[keypath] == null) {
1158
+ callbacks[keypath] = [];
1159
+ value = obj[keypath];
1160
+ Object.defineProperty(obj, keypath, {
1161
+ get: function() {
1162
+ return value;
1163
+ },
1164
+ set: function(newValue) {
1165
+ var _i, _len, _ref;
1166
+ if (newValue !== value) {
1167
+ value = newValue;
1168
+ _ref = callbacks[keypath];
1169
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1170
+ callback = _ref[_i];
1171
+ callback();
1172
+ }
1173
+ return _this.observeMutations(newValue, obj[_this.id], keypath);
1174
+ }
1175
+ }
1176
+ });
1177
+ }
1178
+ if (__indexOf.call(callbacks[keypath], callback) < 0) {
1179
+ callbacks[keypath].push(callback);
1180
+ }
1181
+ return this.observeMutations(obj[keypath], obj[this.id], keypath);
1182
+ },
1183
+ unsubscribe: function(obj, keypath, callback) {
1184
+ var callbacks;
1185
+ callbacks = this.weakmap[obj[this.id]].callbacks[keypath];
1186
+ callbacks.splice(callbacks.indexOf(callback), 1);
1187
+ return this.unobserveMutations(obj[keypath], obj[this.id], keypath);
1188
+ },
1189
+ read: function(obj, keypath) {
1190
+ return obj[keypath];
1191
+ },
1192
+ publish: function(obj, keypath, value) {
1193
+ return obj[keypath] = value;
1194
+ }
1195
+ };
1196
+
1197
+ Rivets.factory = function(exports) {
1198
+ exports._ = Rivets;
1199
+ exports.binders = Rivets.binders;
1200
+ exports.components = Rivets.components;
1201
+ exports.formatters = Rivets.formatters;
1202
+ exports.adapters = Rivets.adapters;
1203
+ exports.config = Rivets.config;
1204
+ exports.configure = function(options) {
1205
+ var property, value;
1206
+ if (options == null) {
1207
+ options = {};
1208
+ }
1209
+ for (property in options) {
1210
+ value = options[property];
1211
+ Rivets.config[property] = value;
1212
+ }
1213
+ };
1214
+ return exports.bind = function(el, models, options) {
1215
+ var view;
1216
+ if (models == null) {
1217
+ models = {};
1218
+ }
1219
+ if (options == null) {
1220
+ options = {};
1221
+ }
1222
+ view = new Rivets.View(el, models, options);
1223
+ view.bind();
1224
+ return view;
1225
+ };
1226
+ };
1227
+
1228
+ if (typeof exports === 'object') {
1229
+ Rivets.factory(exports);
1230
+ } else if (typeof define === 'function' && define.amd) {
1231
+ define(['exports'], function(exports) {
1232
+ Rivets.factory(this.rivets = exports);
1233
+ return exports;
1234
+ });
1235
+ } else {
1236
+ Rivets.factory(this.rivets = {});
1237
+ }
1238
+
1239
+ }).call(this);