fe9918e1 by Michael Richards

Refactor element parsing in the exposed bind function.

1 parent ee8c7f77
...@@ -77,36 +77,34 @@ ...@@ -77,36 +77,34 @@
77 77
78 rivets = { 78 rivets = {
79 bind: function(el, adapter, contexts) { 79 bind: function(el, adapter, contexts) {
80 var nodes, _i, _ref, _results; 80 var attribute, context, keypath, node, path, type, _i, _len, _ref, _results;
81 if (contexts == null) { 81 if (contexts == null) {
82 contexts = {}; 82 contexts = {};
83 } 83 }
84 nodes = el.getElementsByTagName('*'); 84 _ref = el.getElementsByTagName('*');
85 return (function() {
86 _results = []; 85 _results = [];
87 for (var _i = 0, _ref = nodes.length - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; 0 <= _ref ? _i++ : _i--){ _results.push(_i); } 86 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
88 return _results; 87 node = _ref[_i];
89 }).apply(this).forEach(function(n) { 88 _results.push((function() {
90 var node, _i, _ref, _results; 89 var _j, _len1, _ref1, _results1;
91 node = nodes[n]; 90 _ref1 = node.attributes;
92 if (node.attributes.length > 0) { 91 _results1 = [];
93 return (function() { 92 for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
94 _results = []; 93 attribute = _ref1[_j];
95 for (var _i = 0, _ref = node.attributes.length - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; 0 <= _ref ? _i++ : _i--){ _results.push(_i); }
96 return _results;
97 }).apply(this).forEach(function(n) {
98 var attribute, context, keypath, path, type;
99 attribute = node.attributes[n];
100 if (/^data-/.test(attribute.name)) { 94 if (/^data-/.test(attribute.name)) {
101 type = attribute.name.replace('data-', ''); 95 type = attribute.name.replace('data-', '');
102 path = attribute.value.split('.'); 96 path = attribute.value.split('.');
103 context = path.shift(); 97 context = path.shift();
104 keypath = path.join('.'); 98 keypath = path.join('.');
105 return registerBinding(node, adapter, type, contexts[context], keypath); 99 _results1.push(registerBinding(node, adapter, type, contexts[context], keypath));
100 } else {
101 _results1.push(void 0);
106 } 102 }
107 });
108 } 103 }
109 }); 104 return _results1;
105 })());
106 }
107 return _results;
110 } 108 }
111 }; 109 };
112 110
......
...@@ -53,15 +53,8 @@ bidirectionals = ['value', 'checked', 'unchecked', 'selected', 'unselected'] ...@@ -53,15 +53,8 @@ bidirectionals = ['value', 'checked', 'unchecked', 'selected', 'unselected']
53 53
54 rivets = 54 rivets =
55 bind: (el, adapter, contexts = {}) -> 55 bind: (el, adapter, contexts = {}) ->
56 nodes = el.getElementsByTagName '*' 56 for node in el.getElementsByTagName '*'
57 57 for attribute in node.attributes
58 [0..(nodes.length - 1)].forEach (n) ->
59 node = nodes[n]
60
61 if node.attributes.length > 0
62 [0..(node.attributes.length - 1)].forEach (n) ->
63 attribute = node.attributes[n]
64
65 if /^data-/.test attribute.name 58 if /^data-/.test attribute.name
66 type = attribute.name.replace 'data-', '' 59 type = attribute.name.replace 'data-', ''
67 path = attribute.value.split '.' 60 path = attribute.value.split '.'
......