67c5564b by Michael Richards

Build 0.3.2.

1 parent 58598d14
1 # Rivets.js 1 # Rivets.js
2 2
3 Rivets.js is a declarative data binding facility that plays well with existing frameworks such as [Backbone.js](http://backbonejs.org), [Spine.js](http://spinejs.com) and [Stapes.js](http://hay.github.com/stapes/). It aims to be lightweight (1.9KB minified and gzipped), extensible, and configurable to work with any event-driven model. 3 Rivets.js is a declarative data binding facility that plays well with existing frameworks such as [Backbone.js](http://backbonejs.org), [Spine.js](http://spinejs.com) and [Stapes.js](http://hay.github.com/stapes/). It aims to be lightweight (2.3KB minified and gzipped), extensible, and configurable to work with any event-driven model.
4 4
5 --- 5 ---
6 6
......
1 // rivets.js 1 // rivets.js
2 // version: 0.3.1 2 // version: 0.3.2
3 // author: Michael Richards 3 // author: Michael Richards
4 // license: MIT 4 // license: MIT
5 (function() { 5 (function() {
6 var Rivets, attributeBinding, bindEvent, eventBinding, getInputValue, rivets, unbindEvent, 6 var Rivets, attributeBinding, bindEvent, eventBinding, getInputValue, iterationBinding, rivets, unbindEvent,
7 __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, 7 __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
8 __slice = [].slice, 8 __slice = [].slice,
9 __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; 9 __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
...@@ -34,11 +34,16 @@ ...@@ -34,11 +34,16 @@
34 34
35 this.formattedValue = __bind(this.formattedValue, this); 35 this.formattedValue = __bind(this.formattedValue, this);
36 36
37 if (this.options.special === "event") { 37 this.routine = (function() {
38 this.routine = eventBinding(this.type); 38 switch (this.options.special) {
39 } else { 39 case "event":
40 this.routine = Rivets.routines[this.type] || attributeBinding(this.type); 40 return eventBinding(this.type);
41 } 41 case "iteration":
42 return iterationBinding(this.type);
43 default:
44 return Rivets.routines[this.type] || attributeBinding(this.type);
45 }
46 }).call(this);
42 this.formatters = this.options.formatters || []; 47 this.formatters = this.options.formatters || [];
43 } 48 }
44 49
...@@ -61,9 +66,11 @@ ...@@ -61,9 +66,11 @@
61 if (this.options.special === "event") { 66 if (this.options.special === "event") {
62 this.routine(this.el, value, this.currentListener); 67 this.routine(this.el, value, this.currentListener);
63 return this.currentListener = value; 68 return this.currentListener = value;
69 } else if (this.options.special === "iteration") {
70 return this.routine(this.el, value, this);
64 } else { 71 } else {
65 if (value instanceof Function) { 72 if (value instanceof Function) {
66 value = value(); 73 value = value.call(this.model);
67 } 74 }
68 return this.routine(this.el, value); 75 return this.routine(this.el, value);
69 } 76 }
...@@ -104,17 +111,19 @@ ...@@ -104,17 +111,19 @@
104 111
105 Binding.prototype.unbind = function() { 112 Binding.prototype.unbind = function() {
106 var callback, keypath, _i, _len, _ref, _ref1, _ref2; 113 var callback, keypath, _i, _len, _ref, _ref1, _ref2;
107 Rivets.config.adapter.unsubscribe(this.model, this.keypath, this.set); 114 if (!this.options.bypass) {
108 if ((_ref = this.options.dependencies) != null ? _ref.length : void 0) { 115 Rivets.config.adapter.unsubscribe(this.model, this.keypath, this.set);
109 _ref1 = this.options.dependencies; 116 if ((_ref = this.options.dependencies) != null ? _ref.length : void 0) {
110 for (_i = 0, _len = _ref1.length; _i < _len; _i++) { 117 _ref1 = this.options.dependencies;
111 keypath = _ref1[_i]; 118 for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
112 callback = this.dependencyCallbacks[keypath]; 119 keypath = _ref1[_i];
113 Rivets.config.adapter.unsubscribe(this.model, keypath, callback); 120 callback = this.dependencyCallbacks[keypath];
121 Rivets.config.adapter.unsubscribe(this.model, keypath, callback);
122 }
123 }
124 if (_ref2 = this.type, __indexOf.call(this.bidirectionals, _ref2) >= 0) {
125 return this.el.removeEventListener('change', this.publish);
114 } 126 }
115 }
116 if (_ref2 = this.type, __indexOf.call(this.bidirectionals, _ref2) >= 0) {
117 return this.el.removeEventListener('change', this.publish);
118 } 127 }
119 }; 128 };
120 129
...@@ -152,59 +161,96 @@ ...@@ -152,59 +161,96 @@
152 }; 161 };
153 162
154 View.prototype.build = function() { 163 View.prototype.build = function() {
155 var bindingRegExp, el, eventRegExp, node, parseNode, _i, _len, _ref, _results, 164 var bindingRegExp, el, eventRegExp, iterationRegExp, iterator, node, parseNode, skipNodes, _i, _len, _ref, _results,
156 _this = this; 165 _this = this;
157 this.bindings = []; 166 this.bindings = [];
167 skipNodes = [];
168 iterator = null;
158 bindingRegExp = this.bindingRegExp(); 169 bindingRegExp = this.bindingRegExp();
159 eventRegExp = /^on-/; 170 eventRegExp = /^on-/;
171 iterationRegExp = /^each-/;
160 parseNode = function(node) { 172 parseNode = function(node) {
161 var attribute, context, ctx, dependencies, keypath, model, options, path, pipe, pipes, splitPath, type, _i, _len, _ref, _results; 173 var a, attribute, binding, context, ctx, dependencies, keypath, model, n, options, path, pipe, pipes, splitPath, type, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref, _ref1, _ref2, _results;
162 _ref = node.attributes; 174 if (__indexOf.call(skipNodes, node) < 0) {
163 _results = []; 175 _ref = node.attributes;
164 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 176 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
165 attribute = _ref[_i]; 177 attribute = _ref[_i];
166 if (bindingRegExp.test(attribute.name)) { 178 if (bindingRegExp.test(attribute.name)) {
167 options = {}; 179 type = attribute.name.replace(bindingRegExp, '');
168 type = attribute.name.replace(bindingRegExp, ''); 180 if (iterationRegExp.test(type)) {
169 pipes = (function() { 181 if (!_this.models[type.replace(iterationRegExp, '')]) {
170 var _j, _len1, _ref1, _results1; 182 _ref1 = node.getElementsByTagName('*');
171 _ref1 = attribute.value.split('|'); 183 for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
172 _results1 = []; 184 n = _ref1[_j];
173 for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { 185 skipNodes.push(n);
174 pipe = _ref1[_j]; 186 }
175 _results1.push(pipe.trim()); 187 iterator = [attribute];
188 }
176 } 189 }
177 return _results1; 190 }
178 })(); 191 }
179 context = (function() { 192 _ref2 = iterator || node.attributes;
180 var _j, _len1, _ref1, _results1; 193 _results = [];
181 _ref1 = pipes.shift().split('>'); 194 for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
182 _results1 = []; 195 attribute = _ref2[_k];
183 for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { 196 if (bindingRegExp.test(attribute.name)) {
184 ctx = _ref1[_j]; 197 options = {};
185 _results1.push(ctx.trim()); 198 type = attribute.name.replace(bindingRegExp, '');
199 pipes = (function() {
200 var _l, _len3, _ref3, _results1;
201 _ref3 = attribute.value.split('|');
202 _results1 = [];
203 for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) {
204 pipe = _ref3[_l];
205 _results1.push(pipe.trim());
206 }
207 return _results1;
208 })();
209 context = (function() {
210 var _l, _len3, _ref3, _results1;
211 _ref3 = pipes.shift().split('>');
212 _results1 = [];
213 for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) {
214 ctx = _ref3[_l];
215 _results1.push(ctx.trim());
216 }
217 return _results1;
218 })();
219 path = context.shift();
220 splitPath = path.split(/\.|:/);
221 options.formatters = pipes;
222 model = _this.models[splitPath.shift()];
223 options.bypass = path.indexOf(":") !== -1;
224 keypath = splitPath.join();
225 if (model) {
226 if (dependencies = context.shift()) {
227 options.dependencies = dependencies.split(/\s+/);
228 }
229 if (eventRegExp.test(type)) {
230 type = type.replace(eventRegExp, '');
231 options.special = "event";
232 }
233 if (iterationRegExp.test(type)) {
234 type = type.replace(iterationRegExp, '');
235 options.special = "iteration";
236 }
237 binding = new Rivets.Binding(node, type, model, keypath, options);
238 binding.view = _this;
239 _this.bindings.push(binding);
186 } 240 }
187 return _results1;
188 })();
189 path = context.shift();
190 splitPath = path.split(/\.|:/);
191 options.formatters = pipes;
192 model = _this.models[splitPath.shift()];
193 options.bypass = path.indexOf(":") !== -1;
194 keypath = splitPath.join();
195 if (dependencies = context.shift()) {
196 options.dependencies = dependencies.split(/\s+/);
197 } 241 }
198 if (eventRegExp.test(type)) { 242 if (iterator) {
199 type = type.replace(eventRegExp, ''); 243 for (_l = 0, _len3 = iterator.length; _l < _len3; _l++) {
200 options.special = "event"; 244 a = iterator[_l];
245 node.removeAttribute(a.name);
246 }
247 _results.push(iterator = null);
248 } else {
249 _results.push(void 0);
201 } 250 }
202 _results.push(_this.bindings.push(new Rivets.Binding(node, type, model, keypath, options)));
203 } else {
204 _results.push(void 0);
205 } 251 }
252 return _results;
206 } 253 }
207 return _results;
208 }; 254 };
209 _ref = this.els; 255 _ref = this.els;
210 _results = []; 256 _results = [];
...@@ -289,6 +335,44 @@ ...@@ -289,6 +335,44 @@
289 }; 335 };
290 }; 336 };
291 337
338 iterationBinding = function(name) {
339 return function(el, collection, binding) {
340 var data, item, itemEl, iteration, m, n, previous, _i, _j, _len, _len1, _ref, _ref1, _results;
341 if (binding.iterated != null) {
342 _ref = binding.iterated;
343 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
344 iteration = _ref[_i];
345 iteration.view.unbind();
346 iteration.el.parentNode.removeChild(iteration.el);
347 }
348 } else {
349 binding.marker = document.createComment(" rivets: each-" + name + " ");
350 el.parentNode.insertBefore(binding.marker, el);
351 el.parentNode.removeChild(el);
352 }
353 binding.iterated = [];
354 _results = [];
355 for (_j = 0, _len1 = collection.length; _j < _len1; _j++) {
356 item = collection[_j];
357 data = {};
358 _ref1 = binding.view.models;
359 for (n in _ref1) {
360 m = _ref1[n];
361 data[n] = m;
362 }
363 data[name] = item;
364 itemEl = el.cloneNode(true);
365 previous = binding.iterated[binding.iterated.length - 1] || binding.marker;
366 binding.marker.parentNode.insertBefore(itemEl, previous.nextSibling);
367 _results.push(binding.iterated.push({
368 el: itemEl,
369 view: rivets.bind(itemEl, data)
370 }));
371 }
372 return _results;
373 };
374 };
375
292 attributeBinding = function(attr) { 376 attributeBinding = function(attr) {
293 return function(el, value) { 377 return function(el, value) {
294 if (value) { 378 if (value) {
......
1 // rivets.js 1 // rivets.js
2 // version: 0.3.1 2 // version: 0.3.2
3 // author: Michael Richards 3 // author: Michael Richards
4 // license: MIT 4 // license: MIT
5 (function(){var a,b,c,d,e,f,g,h=function(a,b){return function(){return a.apply(b,arguments)}},i=[].slice,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 f(c,e,f,g,i){this.el=c,this.type=e,this.model=f,this.keypath=g,this.options=i!=null?i:{},this.unbind=h(this.unbind,this),this.publish=h(this.publish,this),this.bind=h(this.bind,this),this.set=h(this.set,this),this.formattedValue=h(this.formattedValue,this),this.options.special==="event"?this.routine=d(this.type):this.routine=a.routines[this.type]||b(this.type),this.formatters=this.options.formatters||[]}return f.prototype.bidirectionals=["value","checked","unchecked"],f.prototype.formattedValue=function(b){var c,d,e,f,g,h,j,k;h=this.formatters;for(f=0,g=h.length;f<g;f++)d=h[f],c=d.split(/\s+/),e=c.shift(),b=this.model[e]instanceof Function?(j=this.model)[e].apply(j,[b].concat(i.call(c))):a.formatters[e]?(k=a.formatters)[e].apply(k,[b].concat(i.call(c))):void 0;return b},f.prototype.set=function(a){return a=this.formattedValue(a),this.options.special==="event"?(this.routine(this.el,a,this.currentListener),this.currentListener=a):(a instanceof Function&&(a=a()),this.routine(this.el,a))},f.prototype.bind=function(){var b,d,e,f,g,h,i,k=this;this.options.bypass?this.set(this.model[this.keypath]):(a.config.adapter.subscribe(this.model,this.keypath,this.set),a.config.preloadData&&this.set(a.config.adapter.read(this.model,this.keypath)));if((g=this.options.dependencies)!=null?g.length:void 0){this.dependencyCallbacks={},h=this.options.dependencies;for(e=0,f=h.length;e<f;e++)d=h[e],b=this.dependencyCallbacks[d]=function(b){return k.set(k.options.bypass?k.model[k.keypath]:a.config.adapter.read(k.model,k.keypath))},a.config.adapter.subscribe(this.model,d,b)}if(i=this.type,j.call(this.bidirectionals,i)>=0)return c(this.el,"change",this.publish)},f.prototype.publish=function(b){var c;return c=b.target||b.srcElement,a.config.adapter.publish(this.model,this.keypath,e(c))},f.prototype.unbind=function(){var b,c,d,e,f,g,h;a.config.adapter.unsubscribe(this.model,this.keypath,this.set);if((f=this.options.dependencies)!=null?f.length:void 0){g=this.options.dependencies;for(d=0,e=g.length;d<e;d++)c=g[d],b=this.dependencyCallbacks[c],a.config.adapter.unsubscribe(this.model,c,b)}if(h=this.type,j.call(this.bidirectionals,h)>=0)return this.el.removeEventListener("change",this.publish)},f}(),a.View=function(){function b(a,b){this.els=a,this.models=b,this.unbind=h(this.unbind,this),this.bind=h(this.bind,this),this.build=h(this.build,this),this.bindingRegExp=h(this.bindingRegExp,this),this.els.jquery||this.els instanceof Array||(this.els=[this.els]),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,c,d,e,f,g,h,i,j,k=this;this.bindings=[],b=this.bindingRegExp(),d=/^on-/,f=function(c){var e,f,g,h,i,j,l,m,n,o,p,q,r,s,t,u;t=c.attributes,u=[];for(r=0,s=t.length;r<s;r++){e=t[r];if(b.test(e.name)){l={},q=e.name.replace(b,""),o=function(){var a,b,c,d;c=e.value.split("|"),d=[];for(a=0,b=c.length;a<b;a++)n=c[a],d.push(n.trim());return d}(),f=function(){var a,b,c,d;c=o.shift().split(">"),d=[];for(a=0,b=c.length;a<b;a++)g=c[a],d.push(g.trim());return d}(),m=f.shift(),p=m.split(/\.|:/),l.formatters=o,j=k.models[p.shift()],l.bypass=m.indexOf(":")!==-1,i=p.join();if(h=f.shift())l.dependencies=h.split(/\s+/);d.test(q)&&(q=q.replace(d,""),l.special="event"),u.push(k.bindings.push(new a.Binding(c,q,j,i,l)))}else u.push(void 0)}return u},i=this.els,j=[];for(g=0,h=i.length;g<h;g++)c=i[g],f(c),j.push(function(){var a,b,d,g;d=c.getElementsByTagName("*"),g=[];for(a=0,b=d.length;a<b;a++)e=d[a],g.push(f(e));return g}());return j},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.prototype.unbind=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.unbind());return e},b}(),c=function(a,b,c){return window.addEventListener?a.addEventListener(b,c,!1):(b="on"+b,a.attachEvent(b,c))},g=function(a,b,c){return window.removeEventListener?a.removeEventListener(b,c,!1):(b="on"+b,a.detachEvent(b,c))},e=function(a){switch(a.type){case"checkbox":return a.checked;default:return a.value}},d=function(a){return function(b,d,e){d&&c(b,a,d);if(e)return g(b,a,e)}},b=function(a){return function(b,c){return c?b.setAttribute(a,c):b.removeAttribute(a)}},a.routines={enabled:function(a,b){return a.disabled=!b},disabled:function(a,b){return a.disabled=!!b},checked:function(a,b){return a.type==="radio"?a.checked=a.value===b:a.checked=!!b},unchecked:function(a,b){return a.type==="radio"?a.checked=a.value!==b:a.checked=!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!=null?b:""},value:function(a,b){return a.value=b!=null?b:""},text:function(a,b){return a.innerText!=null?a.innerText=b!=null?b:"":a.textContent=b!=null?b:""}},a.config={preloadData:!0},a.formatters={},f={routines:a.routines,formatters:a.formatters,config:a.config,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},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=f:this.rivets=f}).call(this);
...\ No newline at end of file ...\ No newline at end of file
5 (function(){var a,b,c,d,e,f,g,h,i=function(a,b){return function(){return a.apply(b,arguments)}},j=[].slice,k=[].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 g(c,e,g,h,j){this.el=c,this.type=e,this.model=g,this.keypath=h,this.options=j!=null?j:{},this.unbind=i(this.unbind,this),this.publish=i(this.publish,this),this.bind=i(this.bind,this),this.set=i(this.set,this),this.formattedValue=i(this.formattedValue,this),this.routine=function(){switch(this.options.special){case"event":return d(this.type);case"iteration":return f(this.type);default:return a.routines[this.type]||b(this.type)}}.call(this),this.formatters=this.options.formatters||[]}return g.prototype.bidirectionals=["value","checked","unchecked"],g.prototype.formattedValue=function(b){var c,d,e,f,g,h,i,k;h=this.formatters;for(f=0,g=h.length;f<g;f++)d=h[f],c=d.split(/\s+/),e=c.shift(),b=this.model[e]instanceof Function?(i=this.model)[e].apply(i,[b].concat(j.call(c))):a.formatters[e]?(k=a.formatters)[e].apply(k,[b].concat(j.call(c))):void 0;return b},g.prototype.set=function(a){return a=this.formattedValue(a),this.options.special==="event"?(this.routine(this.el,a,this.currentListener),this.currentListener=a):this.options.special==="iteration"?this.routine(this.el,a,this):(a instanceof Function&&(a=a.call(this.model)),this.routine(this.el,a))},g.prototype.bind=function(){var b,d,e,f,g,h,i,j=this;this.options.bypass?this.set(this.model[this.keypath]):(a.config.adapter.subscribe(this.model,this.keypath,this.set),a.config.preloadData&&this.set(a.config.adapter.read(this.model,this.keypath)));if((g=this.options.dependencies)!=null?g.length:void 0){this.dependencyCallbacks={},h=this.options.dependencies;for(e=0,f=h.length;e<f;e++)d=h[e],b=this.dependencyCallbacks[d]=function(b){return j.set(j.options.bypass?j.model[j.keypath]:a.config.adapter.read(j.model,j.keypath))},a.config.adapter.subscribe(this.model,d,b)}if(i=this.type,k.call(this.bidirectionals,i)>=0)return c(this.el,"change",this.publish)},g.prototype.publish=function(b){var c;return c=b.target||b.srcElement,a.config.adapter.publish(this.model,this.keypath,e(c))},g.prototype.unbind=function(){var b,c,d,e,f,g,h;if(!this.options.bypass){a.config.adapter.unsubscribe(this.model,this.keypath,this.set);if((f=this.options.dependencies)!=null?f.length:void 0){g=this.options.dependencies;for(d=0,e=g.length;d<e;d++)c=g[d],b=this.dependencyCallbacks[c],a.config.adapter.unsubscribe(this.model,c,b)}if(h=this.type,k.call(this.bidirectionals,h)>=0)return this.el.removeEventListener("change",this.publish)}},g}(),a.View=function(){function b(a,b){this.els=a,this.models=b,this.unbind=i(this.unbind,this),this.bind=i(this.bind,this),this.build=i(this.build,this),this.bindingRegExp=i(this.bindingRegExp,this),this.els.jquery||this.els instanceof Array||(this.els=[this.els]),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,c,d,e,f,g,h,i,j,l,m,n,o=this;this.bindings=[],i=[],f=null,b=this.bindingRegExp(),d=/^on-/,e=/^each-/,h=function(c){var g,h,j,l,m,n,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J;if(k.call(i,c)<0){G=c.attributes;for(y=0,C=G.length;y<C;y++){h=G[y];if(b.test(h.name)){x=h.name.replace(b,"");if(e.test(x)&&!o.models[x.replace(e,"")]){H=c.getElementsByTagName("*");for(z=0,D=H.length;z<D;z++)r=H[z],i.push(r);f=[h]}}}I=f||c.attributes,J=[];for(A=0,E=I.length;A<E;A++){h=I[A];if(b.test(h.name)){s={},x=h.name.replace(b,""),v=function(){var a,b,c,d;c=h.value.split("|"),d=[];for(a=0,b=c.length;a<b;a++)u=c[a],d.push(u.trim());return d}(),l=function(){var a,b,c,d;c=v.shift().split(">"),d=[];for(a=0,b=c.length;a<b;a++)m=c[a],d.push(m.trim());return d}(),t=l.shift(),w=t.split(/\.|:/),s.formatters=v,q=o.models[w.shift()],s.bypass=t.indexOf(":")!==-1,p=w.join();if(q){if(n=l.shift())s.dependencies=n.split(/\s+/);d.test(x)&&(x=x.replace(d,""),s.special="event"),e.test(x)&&(x=x.replace(e,""),s.special="iteration"),j=new a.Binding(c,x,q,p,s),j.view=o,o.bindings.push(j)}}if(f){for(B=0,F=f.length;B<F;B++)g=f[B],c.removeAttribute(g.name);J.push(f=null)}else J.push(void 0)}return J}},m=this.els,n=[];for(j=0,l=m.length;j<l;j++)c=m[j],h(c),n.push(function(){var a,b,d,e;d=c.getElementsByTagName("*"),e=[];for(a=0,b=d.length;a<b;a++)g=d[a],e.push(h(g));return e}());return 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.prototype.unbind=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.unbind());return e},b}(),c=function(a,b,c){return window.addEventListener?a.addEventListener(b,c,!1):(b="on"+b,a.attachEvent(b,c))},h=function(a,b,c){return window.removeEventListener?a.removeEventListener(b,c,!1):(b="on"+b,a.detachEvent(b,c))},e=function(a){switch(a.type){case"checkbox":return a.checked;default:return a.value}},d=function(a){return function(b,d,e){d&&c(b,a,d);if(e)return h(b,a,e)}},f=function(a){return function(b,c,d){var e,f,h,i,j,k,l,m,n,o,p,q,r,s;if(d.iterated!=null){q=d.iterated;for(m=0,o=q.length;m<o;m++)i=q[m],i.view.unbind(),i.el.parentNode.removeChild(i.el)}else d.marker=document.createComment(" rivets: each-"+a+" "),b.parentNode.insertBefore(d.marker,b),b.parentNode.removeChild(b);d.iterated=[],s=[];for(n=0,p=c.length;n<p;n++){f=c[n],e={},r=d.view.models;for(k in r)j=r[k],e[k]=j;e[a]=f,h=b.cloneNode(!0),l=d.iterated[d.iterated.length-1]||d.marker,d.marker.parentNode.insertBefore(h,l.nextSibling),s.push(d.iterated.push({el:h,view:g.bind(h,e)}))}return s}},b=function(a){return function(b,c){return c?b.setAttribute(a,c):b.removeAttribute(a)}},a.routines={enabled:function(a,b){return a.disabled=!b},disabled:function(a,b){return a.disabled=!!b},checked:function(a,b){return a.type==="radio"?a.checked=a.value===b:a.checked=!!b},unchecked:function(a,b){return a.type==="radio"?a.checked=a.value!==b:a.checked=!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!=null?b:""},value:function(a,b){return a.value=b!=null?b:""},text:function(a,b){return a.innerText!=null?a.innerText=b!=null?b:"":a.textContent=b!=null?b:""}},a.config={preloadData:!0},a.formatters={},g={routines:a.routines,formatters:a.formatters,config:a.config,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},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 { 1 {
2 "name" : "rivets", 2 "name" : "rivets",
3 "description" : "Declarative data binding facility.", 3 "description" : "Declarative data binding facility.",
4 "version" : "0.3.1", 4 "version" : "0.3.2",
5 "author" : "Michael Richards", 5 "author" : "Michael Richards",
6 "url" : "http://rivetsjs.com", 6 "url" : "http://rivetsjs.com",
7 "main" : "./lib/rivets.js", 7 "main" : "./lib/rivets.js",
......
1 # rivets.js 1 # rivets.js
2 # version : 0.3.1 2 # version : 0.3.2
3 # author : Michael Richards 3 # author : Michael Richards
4 # license : MIT 4 # license : MIT
5 5
......