Build 0.5.3.
Showing
5 changed files
with
42 additions
and
41 deletions
... | @@ -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.2", | 5 | "version": "0.5.3", |
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.2 | 2 | // version: 0.5.3 |
3 | // author: Michael Richards | 3 | // author: Michael Richards |
4 | // license: MIT | 4 | // license: MIT |
5 | (function() { | 5 | (function() { |
... | @@ -595,10 +595,17 @@ | ... | @@ -595,10 +595,17 @@ |
595 | }, | 595 | }, |
596 | "each-*": { | 596 | "each-*": { |
597 | block: true, | 597 | block: true, |
598 | bind: function(el, collection) { | 598 | bind: function(el) { |
599 | return el.removeAttribute(['data', this.view.config.prefix, this.type].join('-').replace('--', '-')); | 599 | var attr; |
600 | |||
601 | attr = ['data', this.view.config.prefix, this.type].join('-').replace('--', '-'); | ||
602 | this.marker = document.createComment(" rivets: " + this.type + " "); | ||
603 | this.iterated = []; | ||
604 | el.removeAttribute(attr); | ||
605 | el.parentNode.insertBefore(this.marker, el); | ||
606 | return el.parentNode.removeChild(el); | ||
600 | }, | 607 | }, |
601 | unbind: function(el, collection) { | 608 | unbind: function(el) { |
602 | var view, _i, _len, _ref, _results; | 609 | var view, _i, _len, _ref, _results; |
603 | 610 | ||
604 | if (this.iterated != null) { | 611 | if (this.iterated != null) { |
... | @@ -612,58 +619,52 @@ | ... | @@ -612,58 +619,52 @@ |
612 | } | 619 | } |
613 | }, | 620 | }, |
614 | routine: function(el, collection) { | 621 | routine: function(el, collection) { |
615 | var data, e, item, itemEl, k, m, n, options, previous, v, view, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _ref3, _ref4, _results; | 622 | var data, i, index, k, key, model, modelName, options, previous, template, v, view, _i, _j, _len, _len1, _ref, _ref1, _ref2, _results; |
616 | 623 | ||
617 | if (this.iterated != null) { | 624 | modelName = this.args[0]; |
618 | _ref = this.iterated; | 625 | collection = collection || []; |
626 | if (this.iterated.length > collection.length) { | ||
627 | _ref = Array(this.iterated.length - collection.length); | ||
619 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { | 628 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { |
620 | view = _ref[_i]; | 629 | i = _ref[_i]; |
630 | view = this.iterated.pop(); | ||
621 | view.unbind(); | 631 | view.unbind(); |
622 | _ref1 = view.els; | 632 | this.marker.parentNode.removeChild(view.els[0]); |
623 | for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { | ||
624 | e = _ref1[_j]; | ||
625 | e.parentNode.removeChild(e); | ||
626 | } | ||
627 | } | 633 | } |
628 | } else { | ||
629 | this.marker = document.createComment(" rivets: " + this.type + " "); | ||
630 | el.parentNode.insertBefore(this.marker, el); | ||
631 | el.parentNode.removeChild(el); | ||
632 | } | 634 | } |
633 | this.iterated = []; | ||
634 | if (collection) { | ||
635 | _results = []; | 635 | _results = []; |
636 | for (_k = 0, _len2 = collection.length; _k < _len2; _k++) { | 636 | for (index = _j = 0, _len1 = collection.length; _j < _len1; index = ++_j) { |
637 | item = collection[_k]; | 637 | model = collection[index]; |
638 | data = {}; | 638 | data = {}; |
639 | _ref2 = this.view.models; | 639 | data[modelName] = model; |
640 | for (n in _ref2) { | 640 | if (this.iterated[index] == null) { |
641 | m = _ref2[n]; | 641 | _ref1 = this.view.models; |
642 | data[n] = m; | 642 | for (key in _ref1) { |
643 | model = _ref1[key]; | ||
644 | data[key] = model; | ||
643 | } | 645 | } |
644 | data[this.args[0]] = item; | ||
645 | itemEl = el.cloneNode(true); | ||
646 | previous = this.iterated.length ? this.iterated[this.iterated.length - 1].els[0] : this.marker; | 646 | previous = this.iterated.length ? this.iterated[this.iterated.length - 1].els[0] : this.marker; |
647 | this.marker.parentNode.insertBefore(itemEl, (_ref3 = previous.nextSibling) != null ? _ref3 : null); | ||
648 | options = { | 647 | options = { |
649 | binders: this.view.options.binders, | 648 | binders: this.view.options.binders, |
650 | formatters: this.view.options.binders, | 649 | formatters: this.view.options.formatters, |
651 | config: {} | 650 | config: {} |
652 | }; | 651 | }; |
653 | if (this.view.options.config) { | 652 | _ref2 = this.view.options.config; |
654 | _ref4 = this.view.options.config; | 653 | for (k in _ref2) { |
655 | for (k in _ref4) { | 654 | v = _ref2[k]; |
656 | v = _ref4[k]; | ||
657 | options.config[k] = v; | 655 | options.config[k] = v; |
658 | } | 656 | } |
659 | } | ||
660 | options.config.preloadData = true; | 657 | options.config.preloadData = true; |
661 | view = new Rivets.View(itemEl, data, options); | 658 | template = el.cloneNode(true); |
662 | view.bind(); | 659 | this.iterated.push(rivets.bind(template, data, options)); |
663 | _results.push(this.iterated.push(view)); | 660 | _results.push(this.marker.parentNode.insertBefore(template, previous.nextSibling)); |
661 | } else if (this.iterated[index].models[modelName] !== model) { | ||
662 | _results.push(this.iterated[index].update(data)); | ||
663 | } else { | ||
664 | _results.push(void 0); | ||
664 | } | 665 | } |
665 | return _results; | ||
666 | } | 666 | } |
667 | return _results; | ||
667 | } | 668 | } |
668 | }, | 669 | }, |
669 | "class-*": function(el, value) { | 670 | "class-*": function(el, value) { | ... | ... |
This diff is collapsed.
Click to expand it.
1 | { | 1 | { |
2 | "name": "rivets", | 2 | "name": "rivets", |
3 | "description": "Declarative data binding facility.", | 3 | "description": "Declarative data binding facility.", |
4 | "version": "0.5.2", | 4 | "version": "0.5.3", |
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", | ... | ... |
-
Please register or sign in to post a comment