Revert back to only binding child elements.
Showing
3 changed files
with
40 additions
and
37 deletions
... | @@ -96,43 +96,51 @@ | ... | @@ -96,43 +96,51 @@ |
96 | }; | 96 | }; |
97 | 97 | ||
98 | View.prototype.build = function() { | 98 | View.prototype.build = function() { |
99 | var attribute, bindType, bindingRegExp, elements, eventRegExp, keypath, model, node, path, pipe, pipes, type, _i, _j, _len, _len1, _ref; | 99 | var attribute, bindType, bindingRegExp, eventRegExp, keypath, model, node, path, pipe, pipes, type, _i, _len, _ref, _results; |
100 | this.bindings = []; | 100 | this.bindings = []; |
101 | bindingRegExp = this.bindingRegExp(); | 101 | bindingRegExp = this.bindingRegExp(); |
102 | eventRegExp = /^on-/; | 102 | eventRegExp = /^on-/; |
103 | elements = [this.el]; | 103 | _ref = this.el.getElementsByTagName('*'); |
104 | elements.concat(Array.prototype.slice.call(this.el.getElementsByTagName('*'))); | 104 | _results = []; |
105 | for (_i = 0, _len = elements.length; _i < _len; _i++) { | 105 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { |
106 | node = elements[_i]; | 106 | node = _ref[_i]; |
107 | _ref = node.attributes; | 107 | _results.push((function() { |
108 | for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { | 108 | var _j, _len1, _ref1, _results1; |
109 | attribute = _ref[_j]; | 109 | _ref1 = node.attributes; |
110 | if (bindingRegExp.test(attribute.name)) { | 110 | _results1 = []; |
111 | bindType = "attribute"; | 111 | for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { |
112 | type = attribute.name.replace(bindingRegExp, ''); | 112 | attribute = _ref1[_j]; |
113 | pipes = (function() { | 113 | if (bindingRegExp.test(attribute.name)) { |
114 | var _k, _len2, _ref1, _results; | 114 | bindType = "attribute"; |
115 | _ref1 = attribute.value.split('|'); | 115 | type = attribute.name.replace(bindingRegExp, ''); |
116 | _results = []; | 116 | pipes = (function() { |
117 | for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) { | 117 | var _k, _len2, _ref2, _results2; |
118 | pipe = _ref1[_k]; | 118 | _ref2 = attribute.value.split('|'); |
119 | _results.push(pipe.trim()); | 119 | _results2 = []; |
120 | for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) { | ||
121 | pipe = _ref2[_k]; | ||
122 | _results2.push(pipe.trim()); | ||
123 | } | ||
124 | return _results2; | ||
125 | })(); | ||
126 | path = pipes.shift().split('.'); | ||
127 | model = this.models[path.shift()]; | ||
128 | keypath = path.join('.'); | ||
129 | if (eventRegExp.test(type)) { | ||
130 | type = type.replace(eventRegExp, ''); | ||
131 | bindType = "event"; | ||
132 | } else if (__indexOf.call(bidirectionals, type) >= 0) { | ||
133 | bindType = "bidirectional"; | ||
120 | } | 134 | } |
121 | return _results; | 135 | _results1.push(this.bindings.push(new Rivets.Binding(node, type, bindType, model, keypath, pipes))); |
122 | })(); | 136 | } else { |
123 | path = pipes.shift().split('.'); | 137 | _results1.push(void 0); |
124 | model = this.models[path.shift()]; | ||
125 | keypath = path.join('.'); | ||
126 | if (eventRegExp.test(type)) { | ||
127 | type = type.replace(eventRegExp, ''); | ||
128 | bindType = "event"; | ||
129 | } else if (__indexOf.call(bidirectionals, type) >= 0) { | ||
130 | bindType = "bidirectional"; | ||
131 | } | 138 | } |
132 | this.bindings.push(new Rivets.Binding(node, type, bindType, model, keypath, pipes)); | ||
133 | } | 139 | } |
134 | } | 140 | return _results1; |
141 | }).call(this)); | ||
135 | } | 142 | } |
143 | return _results; | ||
136 | }; | 144 | }; |
137 | 145 | ||
138 | View.prototype.bind = function() { | 146 | View.prototype.bind = function() { | ... | ... |
1 | (function(){var a,b,c,d,e,f,g,h,i=function(a,b){return function(){return a.apply(b,arguments)}},j=[].indexOf||function(a){for(var b=0,c=this.length;b<c;b++)if(b in this&&this[b]===a)return b;return-1};a={},String.prototype.trim||(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")}),a.Binding=function(){function c(c,d,f,g,h,j){this.el=c,this.type=d,this.bindType=f,this.model=g,this.keypath=h,this.formatters=j!=null?j:[],this.publish=i(this.publish,this),this.bind=i(this.bind,this),this.set=i(this.set,this),this.bindType==="event"?this.routine=e(this.type):this.routine=a.routines[this.type]||b(this.type)}return c.prototype.set=function(b){var c,d,e,f;f=this.formatters;for(d=0,e=f.length;d<e;d++)c=f[d],b=a.config.formatters[c](b);return this.bindType==="event"?(this.routine(this.el,b,this.currentListener),this.currentListener=b):this.routine(this.el,b)},c.prototype.bind=function(){a.config.adapter.subscribe(this.model,this.keypath,this.set),a.config.preloadData&&this.set(a.config.adapter.read(this.model,this.keypath));if(this.bindType==="bidirectional")return d(this.el,"change",this.publish)},c.prototype.publish=function(b){var c;return c=b.target||b.srcElement,a.config.adapter.publish(this.model,this.keypath,f(c))},c}(),a.View=function(){function b(a,b){this.el=a,this.models=b,this.bind=i(this.bind,this),this.build=i(this.build,this),this.bindingRegExp=i(this.bindingRegExp,this),this.el.jquery&&(this.el=this.el.get(0)),this.build()}return b.prototype.bindingRegExp=function(){var b;return b=a.config.prefix,b?new RegExp("^data-"+b+"-"):/^data-/},b.prototype.build=function(){var b,d,e,f,g,h,i,k,l,m,n,o,p,q,r,s,t;this.bindings=[],e=this.bindingRegExp(),g=/^on-/,f=[this.el],f.concat(Array.prototype.slice.call(this.el.getElementsByTagName("*")));for(p=0,r=f.length;p<r;p++){k=f[p],t=k.attributes;for(q=0,s=t.length;q<s;q++)b=t[q],e.test(b.name)&&(d="attribute",o=b.name.replace(e,""),n=function(){var a,c,d,e;d=b.value.split("|"),e=[];for(a=0,c=d.length;a<c;a++)m=d[a],e.push(m.trim());return e}(),l=n.shift().split("."),i=this.models[l.shift()],h=l.join("."),g.test(o)?(o=o.replace(g,""),d="event"):j.call(c,o)>=0&&(d="bidirectional"),this.bindings.push(new a.Binding(k,o,d,i,h,n)))}},b.prototype.bind=function(){var a,b,c,d,e;d=this.bindings,e=[];for(b=0,c=d.length;b<c;b++)a=d[b],e.push(a.bind());return e},b}(),d=function(a,b,c){return window.addEventListener?a.addEventListener(b,c):a.attachEvent(b,c)},h=function(a,b,c){return window.removeEventListener?a.removeEventListener(b,c):a.detachEvent(b,c)},f=function(a){switch(a.type){case"text":case"textarea":case"password":case"select-one":return a.value;case"checkbox":case"radio":return a.checked}},e=function(a){return function(b,c,e){c&&d(b,a,c);if(e)return h(b,a,e)}},b=function(a){return function(b,c){return c?b.setAttribute(a,c):b.removeAttribute(a)}},c=["value","checked","unchecked","selected","unselected"],a.routines={enabled:function(a,b){return a.disabled=!b},disabled:function(a,b){return a.disabled=!!b},checked:function(a,b){return a.checked=!!b},unchecked:function(a,b){return a.checked=!b},selected:function(a,b){return a.selected=!!b},unselected:function(a,b){return a.selected=!b},show:function(a,b){return a.style.display=b?"":"none"},hide:function(a,b){return a.style.display=b?"none":""},html:function(a,b){return a.innerHTML=b||""},value:function(a,b){return a.value=b},text:function(a,b){return a.innerText!=null?a.innerText=b||"":a.textContent=b||""}},a.config={preloadData:!0},g={configure:function(b){var c,d,e;b==null&&(b={}),e=[];for(c in b)d=b[c],e.push(a.config[c]=d);return e},register:function(b,c){return a.routines[b]=c},bind:function(b,c){var d;return c==null&&(c={}),d=new a.View(b,c),d.bind(),d}},typeof module!="undefined"&&module!==null?module.exports=g:this.rivets=g}).call(this); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | (function(){var a,b,c,d,e,f,g,h,i=function(a,b){return function(){return a.apply(b,arguments)}},j=[].indexOf||function(a){for(var b=0,c=this.length;b<c;b++)if(b in this&&this[b]===a)return b;return-1};a={},String.prototype.trim||(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")}),a.Binding=function(){function c(c,d,f,g,h,j){this.el=c,this.type=d,this.bindType=f,this.model=g,this.keypath=h,this.formatters=j!=null?j:[],this.publish=i(this.publish,this),this.bind=i(this.bind,this),this.set=i(this.set,this),this.bindType==="event"?this.routine=e(this.type):this.routine=a.routines[this.type]||b(this.type)}return c.prototype.set=function(b){var c,d,e,f;f=this.formatters;for(d=0,e=f.length;d<e;d++)c=f[d],b=a.config.formatters[c](b);return this.bindType==="event"?(this.routine(this.el,b,this.currentListener),this.currentListener=b):this.routine(this.el,b)},c.prototype.bind=function(){a.config.adapter.subscribe(this.model,this.keypath,this.set),a.config.preloadData&&this.set(a.config.adapter.read(this.model,this.keypath));if(this.bindType==="bidirectional")return d(this.el,"change",this.publish)},c.prototype.publish=function(b){var c;return c=b.target||b.srcElement,a.config.adapter.publish(this.model,this.keypath,f(c))},c}(),a.View=function(){function b(a,b){this.el=a,this.models=b,this.bind=i(this.bind,this),this.build=i(this.build,this),this.bindingRegExp=i(this.bindingRegExp,this),this.el.jquery&&(this.el=this.el.get(0)),this.build()}return b.prototype.bindingRegExp=function(){var b;return b=a.config.prefix,b?new RegExp("^data-"+b+"-"):/^data-/},b.prototype.build=function(){var b,d,e,f,g,h,i,k,l,m,n,o,p,q,r;this.bindings=[],e=this.bindingRegExp(),f=/^on-/,q=this.el.getElementsByTagName("*"),r=[];for(o=0,p=q.length;o<p;o++)i=q[o],r.push(function(){var o,p,q,r;q=i.attributes,r=[];for(o=0,p=q.length;o<p;o++)b=q[o],e.test(b.name)?(d="attribute",n=b.name.replace(e,""),m=function(){var a,c,d,e;d=b.value.split("|"),e=[];for(a=0,c=d.length;a<c;a++)l=d[a],e.push(l.trim());return e}(),k=m.shift().split("."),h=this.models[k.shift()],g=k.join("."),f.test(n)?(n=n.replace(f,""),d="event"):j.call(c,n)>=0&&(d="bidirectional"),r.push(this.bindings.push(new a.Binding(i,n,d,h,g,m)))):r.push(void 0);return r}.call(this));return r},b.prototype.bind=function(){var a,b,c,d,e;d=this.bindings,e=[];for(b=0,c=d.length;b<c;b++)a=d[b],e.push(a.bind());return e},b}(),d=function(a,b,c){return window.addEventListener?a.addEventListener(b,c):a.attachEvent(b,c)},h=function(a,b,c){return window.removeEventListener?a.removeEventListener(b,c):a.detachEvent(b,c)},f=function(a){switch(a.type){case"text":case"textarea":case"password":case"select-one":return a.value;case"checkbox":case"radio":return a.checked}},e=function(a){return function(b,c,e){c&&d(b,a,c);if(e)return h(b,a,e)}},b=function(a){return function(b,c){return c?b.setAttribute(a,c):b.removeAttribute(a)}},c=["value","checked","unchecked","selected","unselected"],a.routines={enabled:function(a,b){return a.disabled=!b},disabled:function(a,b){return a.disabled=!!b},checked:function(a,b){return a.checked=!!b},unchecked:function(a,b){return a.checked=!b},selected:function(a,b){return a.selected=!!b},unselected:function(a,b){return a.selected=!b},show:function(a,b){return a.style.display=b?"":"none"},hide:function(a,b){return a.style.display=b?"none":""},html:function(a,b){return a.innerHTML=b||""},value:function(a,b){return a.value=b},text:function(a,b){return a.innerText!=null?a.innerText=b||"":a.textContent=b||""}},a.config={preloadData:!0},g={configure:function(b){var c,d,e;b==null&&(b={}),e=[];for(c in b)d=b[c],e.push(a.config[c]=d);return e},register:function(b,c){return a.routines[b]=c},bind:function(b,c){var d;return c==null&&(c={}),d=new a.View(b,c),d.bind(),d}},typeof module!="undefined"&&module!==null?module.exports=g:this.rivets=g}).call(this); | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -67,9 +67,7 @@ class Rivets.View | ... | @@ -67,9 +67,7 @@ class Rivets.View |
67 | @bindings = [] | 67 | @bindings = [] |
68 | bindingRegExp = @bindingRegExp() | 68 | bindingRegExp = @bindingRegExp() |
69 | eventRegExp = /^on-/ | 69 | eventRegExp = /^on-/ |
70 | elements = [@el] | 70 | for node in @el.getElementsByTagName '*' |
71 | elements.concat Array::slice.call @el.getElementsByTagName '*' | ||
72 | for node in elements | ||
73 | for attribute in node.attributes | 71 | for attribute in node.attributes |
74 | if bindingRegExp.test attribute.name | 72 | if bindingRegExp.test attribute.name |
75 | bindType = "attribute" | 73 | bindType = "attribute" |
... | @@ -87,9 +85,6 @@ class Rivets.View | ... | @@ -87,9 +85,6 @@ class Rivets.View |
87 | 85 | ||
88 | @bindings.push new Rivets.Binding node, type, bindType, model, keypath, pipes | 86 | @bindings.push new Rivets.Binding node, type, bindType, model, keypath, pipes |
89 | 87 | ||
90 | # To avoid returning the result of the loop | ||
91 | return | ||
92 | |||
93 | # Binds all of the current bindings for this view. | 88 | # Binds all of the current bindings for this view. |
94 | bind: => | 89 | bind: => |
95 | binding.bind() for binding in @bindings | 90 | binding.bind() for binding in @bindings | ... | ... |
-
Please register or sign in to post a comment