50da44d7 by Michael Richards

Build 0.5.4.

1 parent edc9c231
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
2 "name": "rivets", 2 "name": "rivets",
3 "repo": "mikeric/rivets", 3 "repo": "mikeric/rivets",
4 "description": "Declarative data binding facility.", 4 "description": "Declarative data binding facility.",
5 "version": "0.5.3", 5 "version": "0.5.4",
6 "keywords": ["data binding", "templating"], 6 "keywords": ["data binding", "templating"],
7 "scripts": ["dist/rivets.js"], 7 "scripts": ["dist/rivets.js"],
8 "main": "dist/rivets.js", 8 "main": "dist/rivets.js",
......
1 // Rivets.js 1 // Rivets.js
2 // version: 0.5.3 2 // version: 0.5.4
3 // author: Michael Richards 3 // author: Michael Richards
4 // license: MIT 4 // license: MIT
5 (function() { 5 (function() {
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
32 this.publish = __bind(this.publish, this); 32 this.publish = __bind(this.publish, this);
33 this.sync = __bind(this.sync, this); 33 this.sync = __bind(this.sync, this);
34 this.set = __bind(this.set, this); 34 this.set = __bind(this.set, this);
35 this.eventHandler = __bind(this.eventHandler, this);
35 this.formattedValue = __bind(this.formattedValue, this); 36 this.formattedValue = __bind(this.formattedValue, this);
36 if (!(this.binder = this.view.binders[type])) { 37 if (!(this.binder = this.view.binders[type])) {
37 _ref = this.view.binders; 38 _ref = this.view.binders;
...@@ -54,7 +55,7 @@ ...@@ -54,7 +55,7 @@
54 }; 55 };
55 } 56 }
56 this.formatters = this.options.formatters || []; 57 this.formatters = this.options.formatters || [];
57 this.model = this.view.models[this.key]; 58 this.model = this.key ? this.view.models[this.key] : this.view.models;
58 } 59 }
59 60
60 Binding.prototype.formattedValue = function(value) { 61 Binding.prototype.formattedValue = function(value) {
...@@ -75,6 +76,15 @@ ...@@ -75,6 +76,15 @@
75 return value; 76 return value;
76 }; 77 };
77 78
79 Binding.prototype.eventHandler = function(fn) {
80 var binding, handler;
81
82 handler = (binding = this).view.config.handler;
83 return function(ev) {
84 return handler.call(fn, this, ev, binding);
85 };
86 };
87
78 Binding.prototype.set = function(value) { 88 Binding.prototype.set = function(value) {
79 var _ref; 89 var _ref;
80 90
...@@ -165,7 +175,7 @@ ...@@ -165,7 +175,7 @@
165 175
166 Binding.prototype.update = function() { 176 Binding.prototype.update = function() {
167 this.unbind(); 177 this.unbind();
168 this.model = this.view.models[this.key]; 178 this.model = this.key ? this.view.models[this.key] : this.view.models;
169 return this.bind(); 179 return this.bind();
170 }; 180 };
171 181
...@@ -302,7 +312,7 @@ ...@@ -302,7 +312,7 @@
302 splitPath.shift(); 312 splitPath.shift();
303 } 313 }
304 keypath = splitPath.join('.'); 314 keypath = splitPath.join('.');
305 if (_this.models[key] != null) { 315 if (!key || (_this.models[key] != null)) {
306 if (dependencies = context.shift()) { 316 if (dependencies = context.shift()) {
307 options.dependencies = dependencies.split(/\s+/); 317 options.dependencies = dependencies.split(/\s+/);
308 } 318 }
...@@ -425,40 +435,34 @@ ...@@ -425,40 +435,34 @@
425 })(); 435 })();
426 436
427 Rivets.Util = { 437 Rivets.Util = {
428 bindEvent: function(el, event, handler, view) { 438 bindEvent: function(el, event, handler) {
429 var fn;
430
431 fn = function(ev) {
432 return handler.call(this, ev, view);
433 };
434 if (window.jQuery != null) { 439 if (window.jQuery != null) {
435 el = jQuery(el); 440 el = jQuery(el);
436 if (el.on != null) { 441 if (el.on != null) {
437 el.on(event, fn); 442 return el.on(event, handler);
438 } else { 443 } else {
439 el.bind(event, fn); 444 return el.bind(event, handler);
440 } 445 }
441 } else if (window.addEventListener != null) { 446 } else if (window.addEventListener != null) {
442 el.addEventListener(event, fn, false); 447 return el.addEventListener(event, handler, false);
443 } else { 448 } else {
444 event = 'on' + event; 449 event = 'on' + event;
445 el.attachEvent(event, fn); 450 return el.attachEvent(event, handler);
446 } 451 }
447 return fn;
448 }, 452 },
449 unbindEvent: function(el, event, fn) { 453 unbindEvent: function(el, event, handler) {
450 if (window.jQuery != null) { 454 if (window.jQuery != null) {
451 el = jQuery(el); 455 el = jQuery(el);
452 if (el.off != null) { 456 if (el.off != null) {
453 return el.off(event, fn); 457 return el.off(event, handler);
454 } else { 458 } else {
455 return el.unbind(event, fn); 459 return el.unbind(event, handler);
456 } 460 }
457 } else if (window.removeEventListener) { 461 } else if (window.removeEventListener != null) {
458 return el.removeEventListener(event, fn, false); 462 return el.removeEventListener(event, handler, false);
459 } else { 463 } else {
460 event = 'on' + event; 464 event = 'on' + event;
461 return el.detachEvent(event, fn); 465 return el.detachEvent(event, handler);
462 } 466 }
463 }, 467 },
464 getInputValue: function(el) { 468 getInputValue: function(el) {
...@@ -503,10 +507,10 @@ ...@@ -503,10 +507,10 @@
503 checked: { 507 checked: {
504 publishes: true, 508 publishes: true,
505 bind: function(el) { 509 bind: function(el) {
506 return this.currentListener = Rivets.Util.bindEvent(el, 'change', this.publish); 510 return Rivets.Util.bindEvent(el, 'change', this.publish);
507 }, 511 },
508 unbind: function(el) { 512 unbind: function(el) {
509 return Rivets.Util.unbindEvent(el, 'change', this.currentListener); 513 return Rivets.Util.unbindEvent(el, 'change', this.publish);
510 }, 514 },
511 routine: function(el, value) { 515 routine: function(el, value) {
512 var _ref; 516 var _ref;
...@@ -521,10 +525,10 @@ ...@@ -521,10 +525,10 @@
521 unchecked: { 525 unchecked: {
522 publishes: true, 526 publishes: true,
523 bind: function(el) { 527 bind: function(el) {
524 return this.currentListener = Rivets.Util.bindEvent(el, 'change', this.publish); 528 return Rivets.Util.bindEvent(el, 'change', this.publish);
525 }, 529 },
526 unbind: function(el) { 530 unbind: function(el) {
527 return Rivets.Util.unbindEvent(el, 'change', this.currentListener); 531 return Rivets.Util.unbindEvent(el, 'change', this.publish);
528 }, 532 },
529 routine: function(el, value) { 533 routine: function(el, value) {
530 var _ref; 534 var _ref;
...@@ -548,10 +552,10 @@ ...@@ -548,10 +552,10 @@
548 value: { 552 value: {
549 publishes: true, 553 publishes: true,
550 bind: function(el) { 554 bind: function(el) {
551 return this.currentListener = Rivets.Util.bindEvent(el, 'change', this.publish); 555 return Rivets.Util.bindEvent(el, 'change', this.publish);
552 }, 556 },
553 unbind: function(el) { 557 unbind: function(el) {
554 return Rivets.Util.unbindEvent(el, 'change', this.currentListener); 558 return Rivets.Util.unbindEvent(el, 'change', this.publish);
555 }, 559 },
556 routine: function(el, value) { 560 routine: function(el, value) {
557 var o, _i, _len, _ref, _ref1, _ref2, _results; 561 var o, _i, _len, _ref, _ref1, _ref2, _results;
...@@ -586,11 +590,16 @@ ...@@ -586,11 +590,16 @@
586 }, 590 },
587 "on-*": { 591 "on-*": {
588 "function": true, 592 "function": true,
593 unbind: function(el) {
594 if (this.handler) {
595 return Rivets.Util.unbindEvent(el, this.args[0], this.handler);
596 }
597 },
589 routine: function(el, value) { 598 routine: function(el, value) {
590 if (this.currentListener) { 599 if (this.handler) {
591 Rivets.Util.unbindEvent(el, this.args[0], this.currentListener); 600 Rivets.Util.unbindEvent(el, this.args[0], this.handler);
592 } 601 }
593 return this.currentListener = Rivets.Util.bindEvent(el, this.args[0], value, this.view); 602 return Rivets.Util.bindEvent(el, this.args[0], this.handler = this.eventHandler(value));
594 } 603 }
595 }, 604 },
596 "each-*": { 605 "each-*": {
...@@ -598,12 +607,14 @@ ...@@ -598,12 +607,14 @@
598 bind: function(el) { 607 bind: function(el) {
599 var attr; 608 var attr;
600 609
610 if (this.marker == null) {
601 attr = ['data', this.view.config.prefix, this.type].join('-').replace('--', '-'); 611 attr = ['data', this.view.config.prefix, this.type].join('-').replace('--', '-');
602 this.marker = document.createComment(" rivets: " + this.type + " "); 612 this.marker = document.createComment(" rivets: " + this.type + " ");
603 this.iterated = []; 613 this.iterated = [];
604 el.removeAttribute(attr); 614 el.removeAttribute(attr);
605 el.parentNode.insertBefore(this.marker, el); 615 el.parentNode.insertBefore(this.marker, el);
606 return el.parentNode.removeChild(el); 616 return el.parentNode.removeChild(el);
617 }
607 }, 618 },
608 unbind: function(el) { 619 unbind: function(el) {
609 var view, _i, _len, _ref, _results; 620 var view, _i, _len, _ref, _results;
...@@ -656,7 +667,9 @@ ...@@ -656,7 +667,9 @@
656 } 667 }
657 options.config.preloadData = true; 668 options.config.preloadData = true;
658 template = el.cloneNode(true); 669 template = el.cloneNode(true);
659 this.iterated.push(rivets.bind(template, data, options)); 670 view = new Rivets.View(template, data, options);
671 view.bind();
672 this.iterated.push(view);
660 _results.push(this.marker.parentNode.insertBefore(template, previous.nextSibling)); 673 _results.push(this.marker.parentNode.insertBefore(template, previous.nextSibling));
661 } else if (this.iterated[index].models[modelName] !== model) { 674 } else if (this.iterated[index].models[modelName] !== model) {
662 _results.push(this.iterated[index].update(data)); 675 _results.push(this.iterated[index].update(data));
...@@ -685,7 +698,10 @@ ...@@ -685,7 +698,10 @@
685 }; 698 };
686 699
687 Rivets.config = { 700 Rivets.config = {
688 preloadData: true 701 preloadData: true,
702 handler: function(context, ev, binding) {
703 return this.call(context, ev, binding.view.models);
704 }
689 }; 705 };
690 706
691 Rivets.formatters = {}; 707 Rivets.formatters = {};
......
1 { 1 {
2 "name": "rivets", 2 "name": "rivets",
3 "description": "Declarative data binding facility.", 3 "description": "Declarative data binding facility.",
4 "version": "0.5.3", 4 "version": "0.5.4",
5 "author": "Michael Richards", 5 "author": "Michael Richards",
6 "url": "http://rivetsjs.com", 6 "url": "http://rivetsjs.com",
7 "main": "./dist/rivets.js", 7 "main": "./dist/rivets.js",
......
1 # Rivets.js 1 # Rivets.js
2 # ========= 2 # =========
3 3
4 # > version: 0.5.3 4 # > version: 0.5.4
5 # > author: Michael Richards 5 # > author: Michael Richards
6 # > license: MIT 6 # > license: MIT
7 # > 7 # >
......