fe9918e1 by Michael Richards

Refactor element parsing in the exposed bind function.

1 parent ee8c7f77
......@@ -77,36 +77,34 @@
rivets = {
bind: function(el, adapter, contexts) {
var nodes, _i, _ref, _results;
var attribute, context, keypath, node, path, type, _i, _len, _ref, _results;
if (contexts == null) {
contexts = {};
}
nodes = el.getElementsByTagName('*');
return (function() {
_results = [];
for (var _i = 0, _ref = nodes.length - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; 0 <= _ref ? _i++ : _i--){ _results.push(_i); }
return _results;
}).apply(this).forEach(function(n) {
var node, _i, _ref, _results;
node = nodes[n];
if (node.attributes.length > 0) {
return (function() {
_results = [];
for (var _i = 0, _ref = node.attributes.length - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; 0 <= _ref ? _i++ : _i--){ _results.push(_i); }
return _results;
}).apply(this).forEach(function(n) {
var attribute, context, keypath, path, type;
attribute = node.attributes[n];
_ref = el.getElementsByTagName('*');
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
node = _ref[_i];
_results.push((function() {
var _j, _len1, _ref1, _results1;
_ref1 = node.attributes;
_results1 = [];
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
attribute = _ref1[_j];
if (/^data-/.test(attribute.name)) {
type = attribute.name.replace('data-', '');
path = attribute.value.split('.');
context = path.shift();
keypath = path.join('.');
return registerBinding(node, adapter, type, contexts[context], keypath);
_results1.push(registerBinding(node, adapter, type, contexts[context], keypath));
} else {
_results1.push(void 0);
}
});
}
});
}
return _results1;
})());
}
return _results;
}
};
......
......@@ -53,21 +53,14 @@ bidirectionals = ['value', 'checked', 'unchecked', 'selected', 'unselected']
rivets =
bind: (el, adapter, contexts = {}) ->
nodes = el.getElementsByTagName '*'
[0..(nodes.length - 1)].forEach (n) ->
node = nodes[n]
if node.attributes.length > 0
[0..(node.attributes.length - 1)].forEach (n) ->
attribute = node.attributes[n]
if /^data-/.test attribute.name
type = attribute.name.replace 'data-', ''
path = attribute.value.split '.'
context = path.shift()
keypath = path.join '.'
registerBinding node, adapter, type, contexts[context], keypath
for node in el.getElementsByTagName '*'
for attribute in node.attributes
if /^data-/.test attribute.name
type = attribute.name.replace 'data-', ''
path = attribute.value.split '.'
context = path.shift()
keypath = path.join '.'
registerBinding node, adapter, type, contexts[context], keypath
if module?
module.exports = rivets
......