rivets-rails 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/build/update.sh +1 -1
- data/dist/rivets.custom.binders.js +4 -0
- data/dist/rivets.custom.formatters.js +9 -0
- data/dist/rivets.general_custom.js +13 -0
- data/dist/rivets.general_custom.js.min.js +1 -1
- data/dist/rivets.js +57 -72
- data/dist/rivets.min.js +2 -2
- data/lib/rivets-rails/version.rb +1 -1
- data/src/rivets.custom.binders.coffee +9 -1
- data/src/rivets.custom.formatters.coffee +19 -1
- data/src/rivets.custom.general_adapter.coffee +1 -0
- data/vendor/assets/javascripts/rivets.custom.binders.js +4 -0
- data/vendor/assets/javascripts/rivets.custom.formatters.js +9 -0
- data/vendor/assets/javascripts/rivets.general_custom.js +13 -0
- data/vendor/assets/javascripts/rivets.general_custom.js.min.js +1 -1
- data/vendor/assets/javascripts/rivets.js +57 -72
- data/vendor/assets/javascripts/rivets.min.js +2 -2
- metadata +2 -2
data/dist/rivets.min.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
// Rivets.js
|
2
|
-
// version: 0.5.
|
2
|
+
// version: 0.5.12
|
3
3
|
// author: Michael Richards
|
4
4
|
// license: MIT
|
5
|
-
(function(){var t,i=function(t,i){return function(){return t.apply(i,arguments)}},e=[].slice,n={}.hasOwnProperty,s=function(t,i){function e(){this.constructor=t}for(var s in i)n.call(i,s)&&(t[s]=i[s]);return e.prototype=i.prototype,t.prototype=new e,t.__super__=i.prototype,t},r=[].indexOf||function(t){for(var i=0,e=this.length;e>i;i++)if(i in this&&this[i]===t)return i;return-1};t={},String.prototype.trim||(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")}),t.Binding=function(){function n(e,n,s,r,o,h){var l,u,a,d;if(this.view=e,this.el=n,this.type=s,this.key=r,this.keypath=o,this.options=null!=h?h:{},this.update=i(this.update,this),this.unbind=i(this.unbind,this),this.bind=i(this.bind,this),this.publish=i(this.publish,this),this.sync=i(this.sync,this),this.set=i(this.set,this),this.eventHandler=i(this.eventHandler,this),this.formattedValue=i(this.formattedValue,this),!(this.binder=t.internalBinders[this.type]||this.view.binders[s])){d=this.view.binders;for(l in d)a=d[l],"*"!==l&&-1!==l.indexOf("*")&&(u=RegExp("^"+l.replace("*",".+")+"$"),u.test(s)&&(this.binder=a,this.args=RegExp("^"+l.replace("*","(.+)")+"$").exec(s),this.args.shift()))}this.binder||(this.binder=this.view.binders["*"]),this.binder instanceof Function&&(this.binder={routine:this.binder}),this.formatters=this.options.formatters||[],this.model=this.key?this.view.models[this.key]:this.view.models}return n.prototype.formattedValue=function(t){var i,n,s,r,o,h;for(h=this.formatters,r=0,o=h.length;o>r;r++)n=h[r],i=n.split(/\s+/),s=i.shift(),n=this.model[s]instanceof Function?this.model[s]:this.view.formatters[s],(null!=n?n.read:void 0)instanceof Function?t=n.read.apply(n,[t].concat(e.call(i))):n instanceof Function&&(t=n.apply(null,[t].concat(e.call(i))));return t},n.prototype.eventHandler=function(t){var i,e;return e=(i=this).view.config.handler,function(n){return e.call(t,this,n,i)}},n.prototype.set=function(t){var i;return t=t instanceof Function&&!this.binder["function"]?this.formattedValue(t.call(this.model)):this.formattedValue(t),null!=(i=this.binder.routine)?i.call(this,this.el,t):void 0},n.prototype.sync=function(){return this.set(this.options.bypass?this.model[this.keypath]:this.view.config.adapter.read(this.model,this.keypath))},n.prototype.publish=function(){var i,n,s,r,o,h,l,u,a;for(r=t.Util.getInputValue(this.el),l=this.formatters.slice(0).reverse(),o=0,h=l.length;h>o;o++)n=l[o],i=n.split(/\s+/),s=i.shift(),(null!=(u=this.view.formatters[s])?u.publish:void 0)&&(r=(a=this.view.formatters[s]).publish.apply(a,[r].concat(e.call(i))));return this.view.config.adapter.publish(this.model,this.keypath,r)},n.prototype.bind=function(){var t,i,e,n,s,r,o,h,l;if(null!=(r=this.binder.bind)&&r.call(this,this.el),this.options.bypass?this.sync():(this.view.config.adapter.subscribe(this.model,this.keypath,this.sync),this.view.config.preloadData&&this.sync()),null!=(o=this.options.dependencies)?o.length:void 0){for(h=this.options.dependencies,l=[],n=0,s=h.length;s>n;n++)t=h[n],/^\./.test(t)?(e=this.model,i=t.substr(1)):(t=t.split("."),e=this.view.models[t.shift()],i=t.join(".")),l.push(this.view.config.adapter.subscribe(e,i,this.sync));return l}},n.prototype.unbind=function(){var t,i,e,n,s,r,o,h,l;if(null!=(r=this.binder.unbind)&&r.call(this,this.el),this.options.bypass||this.view.config.adapter.unsubscribe(this.model,this.keypath,this.sync),null!=(o=this.options.dependencies)?o.length:void 0){for(h=this.options.dependencies,l=[],n=0,s=h.length;s>n;n++)t=h[n],/^\./.test(t)?(e=this.model,i=t.substr(1)):(t=t.split("."),e=this.view.models[t.shift()],i=t.join(".")),l.push(this.view.config.adapter.unsubscribe(e,i,this.sync));return l}},n.prototype.update=function(t){var i;return null==t&&(t={}),this.key?t[this.key]&&(this.options.bypass||this.view.config.adapter.unsubscribe(this.model,this.keypath,this.sync),this.model=t[this.key],this.options.bypass?this.sync():(this.view.config.adapter.subscribe(this.model,this.keypath,this.sync),this.view.config.preloadData&&this.sync())):this.sync(),null!=(i=this.binder.update)?i.call(this,t):void 0},n}(),t.ComponentBinding=function(e){function n(e,n,s){var o,h,l,u,a;for(this.view=e,this.el=n,this.type=s,this.unbind=i(this.unbind,this),this.bind=i(this.bind,this),this.update=i(this.update,this),this.locals=i(this.locals,this),this.component=t.components[this.type],this.attributes={},this.inflections={},u=this.el.attributes||[],h=0,l=u.length;l>h;h++)o=u[h],a=o.name,r.call(this.component.attributes,a)>=0?this.attributes[o.name]=o.value:this.inflections[o.name]=o.value}return s(n,e),n.prototype.sync=function(){},n.prototype.locals=function(t){var i,e,n,s,r,o;null==t&&(t=this.view.models),s={},r=this.inflections;for(e in r)i=r[e],s[e]=t[i];for(e in t)n=t[e],null==(o=s[e])&&(s[e]=n);return s},n.prototype.update=function(t){var i;return null!=(i=this.componentView)?i.update(this.locals(t)):void 0},n.prototype.bind=function(){var i,e;return null!=this.componentView?null!=(e=this.componentView)?e.bind():void 0:(i=this.component.build.call(this.attributes),(this.componentView=new t.View(i,this.locals(),this.view.options)).bind(),this.el.parentNode.replaceChild(i,this.el))},n.prototype.unbind=function(){var t;return null!=(t=this.componentView)?t.unbind():void 0},n}(t.Binding),t.View=function(){function n(e,n,s){var r,o,h,l,u,a,d,p,c,f;for(this.els=e,this.models=n,this.options=null!=s?s:{},this.update=i(this.update,this),this.publish=i(this.publish,this),this.sync=i(this.sync,this),this.unbind=i(this.unbind,this),this.bind=i(this.bind,this),this.select=i(this.select,this),this.build=i(this.build,this),this.componentRegExp=i(this.componentRegExp,this),this.bindingRegExp=i(this.bindingRegExp,this),this.els.jquery||this.els instanceof Array||(this.els=[this.els]),d=["config","binders","formatters"],u=0,a=d.length;a>u;u++){if(o=d[u],this[o]={},this.options[o]){p=this.options[o];for(r in p)h=p[r],this[o][r]=h}c=t[o];for(r in c)h=c[r],null==(f=(l=this[o])[r])&&(l[r]=h)}this.build()}return n.prototype.bindingRegExp=function(){var t;return t=this.config.prefix,t?RegExp("^data-"+t+"-"):/^data-/},n.prototype.componentRegExp=function(){var t,i;return RegExp("^"+(null!=(t=null!=(i=this.config.prefix)?i.toUpperCase():void 0)?t:"RV")+"-")},n.prototype.build=function(){var i,n,s,o,h,l,u,a,d,p=this;for(this.bindings=[],l=[],i=this.bindingRegExp(),s=this.componentRegExp(),n=function(i,e,n){var s,r,o,h,l,u,a,d,c,f;return u={},c=function(){var t,i,e,s;for(e=n.split("|"),s=[],t=0,i=e.length;i>t;t++)d=e[t],s.push(d.trim());return s}(),s=function(){var t,i,e,n;for(e=c.shift().split("<"),n=[],t=0,i=e.length;i>t;t++)r=e[t],n.push(r.trim());return n}(),a=s.shift(),f=a.split(/\.|:/),u.formatters=c,u.bypass=-1!==a.indexOf(":"),f[0]?h=f.shift():(h=null,f.shift()),l=f.join("."),(o=s.shift())&&(u.dependencies=o.split(/\s+/)),p.bindings.push(new t.Binding(p,i,e,h,l,u))},h=function(o){var u,a,d,c,f,b,v,g,y,m,w,x,k,E,N,V,j,R,C,U,B,T,O,Q,A,D,L,_,F,H,S,$;if(0>r.call(l,o)){if(o.nodeType===Node.TEXT_NODE){if(g=t.TextTemplateParser,(f=p.config.templateDelimiters)&&(E=g.parse(o.data,f)).length&&(1!==E.length||E[0].type!==g.types.text)){switch(w=E[0],m=E.length>=2?e.call(E,1):[],o.data=w.value,w.type){case 0:o.data=w.value;break;case 1:n(o,"textNode",w.value)}for(j=0,B=m.length;B>j;j++)k=m[j],o.parentNode.appendChild(x=document.createTextNode(k.value)),1===k.type&&n(x,"textNode",k.value)}}else if(s.test(o.tagName))N=o.tagName.replace(s,"").toLowerCase(),p.bindings.push(new t.ComponentBinding(p,o,N));else if(null!=o.attributes){for(L=o.attributes,R=0,T=L.length;T>R;R++)if(u=L[R],i.test(u.name)){if(N=u.name.replace(i,""),!(d=p.binders[N])){_=p.binders;for(b in _)V=_[b],"*"!==b&&-1!==b.indexOf("*")&&(y=RegExp("^"+b.replace("*",".+")+"$"),y.test(N)&&(d=V))}if(d||(d=p.binders["*"]),d.block){for(F=o.childNodes,C=0,O=F.length;O>C;C++)v=F[C],l.push(v);a=[u]}}for(H=a||o.attributes,U=0,Q=H.length;Q>U;U++)u=H[U],i.test(u.name)&&(N=u.name.replace(i,""),n(o,N,u.value))}for(S=o.childNodes,$=[],D=0,A=S.length;A>D;D++)c=S[D],$.push(h(c));return $}},d=this.els,u=0,a=d.length;a>u;u++)o=d[u],h(o)},n.prototype.select=function(t){var i,e,n,s,r;for(s=this.bindings,r=[],e=0,n=s.length;n>e;e++)i=s[e],t(i)&&r.push(i);return r},n.prototype.bind=function(){var t,i,e,n,s;for(n=this.bindings,s=[],i=0,e=n.length;e>i;i++)t=n[i],s.push(t.bind());return s},n.prototype.unbind=function(){var t,i,e,n,s;for(n=this.bindings,s=[],i=0,e=n.length;e>i;i++)t=n[i],s.push(t.unbind());return s},n.prototype.sync=function(){var t,i,e,n,s;for(n=this.bindings,s=[],i=0,e=n.length;e>i;i++)t=n[i],s.push(t.sync());return s},n.prototype.publish=function(){var t,i,e,n,s;for(n=this.select(function(t){return t.binder.publishes}),s=[],i=0,e=n.length;e>i;i++)t=n[i],s.push(t.publish());return s},n.prototype.update=function(t){var i,e,n,s,r,o,h;null==t&&(t={});for(e in t)n=t[e],this.models[e]=n;for(o=this.bindings,h=[],s=0,r=o.length;r>s;s++)i=o[s],h.push(i.update(t));return h},n}(),t.TextTemplateParser=function(){function t(){}return t.types={text:0,binding:1},t.parse=function(t,i){var e,n,s,r,o,h,l;for(h=[],r=t.length,e=0,n=0;r>n;){if(e=t.indexOf(i[0],n),0>e){h.push({type:this.types.text,value:t.slice(n)});break}if(e>0&&e>n&&h.push({type:this.types.text,value:t.slice(n,e)}),n=e+2,e=t.indexOf(i[1],n),0>e){o=t.slice(n-2),s=h[h.length-1],(null!=s?s.type:void 0)===this.types.text?s.value+=o:h.push({type:this.types.text,value:o});break}l=t.slice(n,e).trim(),h.push({type:this.types.binding,value:l}),n=e+2}return h},t}(),t.Util={bindEvent:function(t,i,e){return null!=window.jQuery?(t=jQuery(t),null!=t.on?t.on(i,e):t.bind(i,e)):null!=window.addEventListener?t.addEventListener(i,e,!1):(i="on"+i,t.attachEvent(i,e))},unbindEvent:function(t,i,e){return null!=window.jQuery?(t=jQuery(t),null!=t.off?t.off(i,e):t.unbind(i,e)):null!=window.removeEventListener?t.removeEventListener(i,e,!1):(i="on"+i,t.detachEvent(i,e))},getInputValue:function(t){var i,e,n,s;if(null!=window.jQuery)switch(t=jQuery(t),t[0].type){case"checkbox":return t.is(":checked");default:return t.val()}else switch(t.type){case"checkbox":return t.checked;case"select-multiple":for(s=[],e=0,n=t.length;n>e;e++)i=t[e],i.selected&&s.push(i.value);return s;default:return t.value}}},t.binders={enabled:function(t,i){return t.disabled=!i},disabled:function(t,i){return t.disabled=!!i},checked:{publishes:!0,bind:function(i){return t.Util.bindEvent(i,"change",this.publish)},unbind:function(i){return t.Util.unbindEvent(i,"change",this.publish)},routine:function(t,i){var e;return t.checked="radio"===t.type?(null!=(e=t.value)?""+e:void 0)===(null!=i?""+i:void 0):!!i}},unchecked:{publishes:!0,bind:function(i){return t.Util.bindEvent(i,"change",this.publish)},unbind:function(i){return t.Util.unbindEvent(i,"change",this.publish)},routine:function(t,i){var e;return t.checked="radio"===t.type?(null!=(e=t.value)?""+e:void 0)!==(null!=i?""+i:void 0):!i}},show:function(t,i){return t.style.display=i?"":"none"},hide:function(t,i){return t.style.display=i?"none":""},html:function(t,i){return t.innerHTML=null!=i?i:""},value:{publishes:!0,bind:function(i){return t.Util.bindEvent(i,"change",this.publish)},unbind:function(i){return t.Util.unbindEvent(i,"change",this.publish)},routine:function(t,i){var e,n,s,o,h,l,u;if(null!=window.jQuery){if(t=jQuery(t),(null!=i?""+i:void 0)!==(null!=(o=t.val())?""+o:void 0))return t.val(null!=i?i:"")}else if("select-multiple"===t.type){if(null!=i){for(u=[],n=0,s=t.length;s>n;n++)e=t[n],u.push(e.selected=(h=e.value,r.call(i,h)>=0));return u}}else if((null!=i?""+i:void 0)!==(null!=(l=t.value)?""+l:void 0))return t.value=null!=i?i:""}},text:function(t,i){return null!=t.innerText?t.innerText=null!=i?i:"":t.textContent=null!=i?i:""},"if":{block:!0,bind:function(t){var i,e;return null==this.marker?(i=["data",this.view.config.prefix,this.type].join("-").replace("--","-"),e=t.getAttribute(i),this.marker=document.createComment(" rivets: "+this.type+" "+e+" "),t.removeAttribute(i),t.parentNode.insertBefore(this.marker,t),t.parentNode.removeChild(t)):void 0},unbind:function(){var t;return null!=(t=this.nested)?t.unbind():void 0},routine:function(i,e){var n,s,r,o,h;if(!!e==(null==this.nested)){if(e){r={},h=this.view.models;for(n in h)s=h[n],r[n]=s;return o={binders:this.view.options.binders,formatters:this.view.options.formatters,config:this.view.options.config},(this.nested=new t.View(i,r,o)).bind(),this.marker.parentNode.insertBefore(i,this.marker.nextSibling)}return i.parentNode.removeChild(i),this.nested.unbind(),delete this.nested}},update:function(t){return this.nested.update(t)}},unless:{block:!0,bind:function(i){return t.binders["if"].bind.call(this,i)},unbind:function(){return t.binders["if"].unbind.call(this)},routine:function(i,e){return t.binders["if"].routine.call(this,i,!e)},update:function(i){return t.binders["if"].update.call(this,i)}},"on-*":{"function":!0,unbind:function(i){return this.handler?t.Util.unbindEvent(i,this.args[0],this.handler):void 0},routine:function(i,e){return this.handler&&t.Util.unbindEvent(i,this.args[0],this.handler),t.Util.bindEvent(i,this.args[0],this.handler=this.eventHandler(e))}},"each-*":{block:!0,bind:function(t){var i;return null==this.marker?(i=["data",this.view.config.prefix,this.type].join("-").replace("--","-"),this.marker=document.createComment(" rivets: "+this.type+" "),this.iterated=[],t.removeAttribute(i),t.parentNode.insertBefore(this.marker,t),t.parentNode.removeChild(t)):void 0},unbind:function(){var t,i,e,n,s;if(null!=this.iterated){for(n=this.iterated,s=[],i=0,e=n.length;e>i;i++)t=n[i],s.push(t.unbind());return s}},routine:function(i,e){var n,s,r,o,h,l,u,a,d,p,c,f,b,v,g,y,m,w,x,k,E;if(u=this.args[0],e=e||[],this.iterated.length>e.length)for(m=Array(this.iterated.length-e.length),b=0,g=m.length;g>b;b++)s=m[b],f=this.iterated.pop(),f.unbind(),this.marker.parentNode.removeChild(f.els[0]);for(E=[],r=v=0,y=e.length;y>v;r=++v)if(l=e[r],n={},n[u]=l,null==this.iterated[r]){w=this.view.models;for(h in w)l=w[h],null==(x=n[h])&&(n[h]=l);d=this.iterated.length?this.iterated[this.iterated.length-1].els[0]:this.marker,a={binders:this.view.options.binders,formatters:this.view.options.formatters,config:{}},k=this.view.options.config;for(o in k)c=k[o],a.config[o]=c;a.config.preloadData=!0,p=i.cloneNode(!0),f=new t.View(p,n,a),f.bind(),this.iterated.push(f),E.push(this.marker.parentNode.insertBefore(p,d.nextSibling))}else this.iterated[r].models[u]!==l?E.push(this.iterated[r].update(n)):E.push(void 0);return E},update:function(t){var i,e,n,s,r,o,h,l;i={};for(e in t)n=t[e],e!==this.args[0]&&(i[e]=n);for(h=this.iterated,l=[],r=0,o=h.length;o>r;r++)s=h[r],l.push(s.update(i));return l}},"class-*":function(t,i){var e;return e=" "+t.className+" ",!i==(-1!==e.indexOf(" "+this.args[0]+" "))?t.className=i?""+t.className+" "+this.args[0]:e.replace(" "+this.args[0]+" "," ").trim():void 0},"*":function(t,i){return i?t.setAttribute(this.type,i):t.removeAttribute(this.type)}},t.internalBinders={textNode:function(t,i){return t.data=null!=i?i:""}},t.components={},t.config={preloadData:!0,handler:function(t,i,e){return this.call(t,i,e.view.models)}},t.formatters={},t.factory=function(i){return i._=t,i.binders=t.binders,i.components=t.components,i.formatters=t.formatters,i.config=t.config,i.configure=function(i){var e,n;null==i&&(i={});for(e in i)n=i[e],t.config[e]=n},i.bind=function(i,e,n){var s;return null==e&&(e={}),null==n&&(n={}),s=new t.View(i,e,n),s.bind(),s}},"object"==typeof exports?t.factory(exports):"function"==typeof define&&define.amd?define(["exports"],function(i){return t.factory(this.rivets=i),i}):t.factory(this.rivets={})}).call(this);
|
5
|
+
!function(){var a,b=function(a,b){return function(){return a.apply(b,arguments)}},c=[].slice,d={}.hasOwnProperty,e=function(a,b){function c(){this.constructor=a}for(var e in b)d.call(b,e)&&(a[e]=b[e]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a},f=[].indexOf||function(a){for(var b=0,c=this.length;c>b;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 d(a,c,d,e,f,g){var h,i,j,k;if(this.view=a,this.el=c,this.type=d,this.key=e,this.keypath=f,this.options=null!=g?g:{},this.update=b(this.update,this),this.unbind=b(this.unbind,this),this.bind=b(this.bind,this),this.publish=b(this.publish,this),this.sync=b(this.sync,this),this.set=b(this.set,this),this.eventHandler=b(this.eventHandler,this),this.formattedValue=b(this.formattedValue,this),!(this.binder=this.view.binders[d])){k=this.view.binders;for(h in k)j=k[h],"*"!==h&&-1!==h.indexOf("*")&&(i=new RegExp("^"+h.replace("*",".+")+"$"),i.test(d)&&(this.binder=j,this.args=new RegExp("^"+h.replace("*","(.+)")+"$").exec(d),this.args.shift()))}this.binder||(this.binder=this.view.binders["*"]),this.binder instanceof Function&&(this.binder={routine:this.binder}),this.formatters=this.options.formatters||[],this.model=this.key?this.view.models[this.key]:this.view.models}return d.prototype.formattedValue=function(a){var b,d,e,f,g,h;for(h=this.formatters,f=0,g=h.length;g>f;f++)d=h[f],b=d.split(/\s+/),e=b.shift(),d=this.model[e]instanceof Function?this.model[e]:this.view.formatters[e],(null!=d?d.read:void 0)instanceof Function?a=d.read.apply(d,[a].concat(c.call(b))):d instanceof Function&&(a=d.apply(null,[a].concat(c.call(b))));return a},d.prototype.eventHandler=function(a){var b,c;return c=(b=this).view.config.handler,function(d){return c.call(a,this,d,b)}},d.prototype.set=function(a){var b;return a=a instanceof Function&&!this.binder["function"]?this.formattedValue(a.call(this.model)):this.formattedValue(a),null!=(b=this.binder.routine)?b.call(this,this.el,a):void 0},d.prototype.sync=function(){return this.set(this.options.bypass?this.model[this.keypath]:this.view.config.adapter.read(this.model,this.keypath))},d.prototype.publish=function(){var b,d,e,f,g,h,i,j,k;for(f=a.Util.getInputValue(this.el),i=this.formatters.slice(0).reverse(),g=0,h=i.length;h>g;g++)d=i[g],b=d.split(/\s+/),e=b.shift(),(null!=(j=this.view.formatters[e])?j.publish:void 0)&&(f=(k=this.view.formatters[e]).publish.apply(k,[f].concat(c.call(b))));return this.view.config.adapter.publish(this.model,this.keypath,f)},d.prototype.bind=function(){var a,b,c,d,e,f,g,h,i;if(null!=(f=this.binder.bind)&&f.call(this,this.el),this.options.bypass?this.sync():(this.view.config.adapter.subscribe(this.model,this.keypath,this.sync),this.view.config.preloadData&&this.sync()),null!=(g=this.options.dependencies)?g.length:void 0){for(h=this.options.dependencies,i=[],d=0,e=h.length;e>d;d++)a=h[d],/^\./.test(a)?(c=this.model,b=a.substr(1)):(a=a.split("."),c=this.view.models[a.shift()],b=a.join(".")),i.push(this.view.config.adapter.subscribe(c,b,this.sync));return i}},d.prototype.unbind=function(){var a,b,c,d,e,f,g,h,i;if(null!=(f=this.binder.unbind)&&f.call(this,this.el),this.options.bypass||this.view.config.adapter.unsubscribe(this.model,this.keypath,this.sync),null!=(g=this.options.dependencies)?g.length:void 0){for(h=this.options.dependencies,i=[],d=0,e=h.length;e>d;d++)a=h[d],/^\./.test(a)?(c=this.model,b=a.substr(1)):(a=a.split("."),c=this.view.models[a.shift()],b=a.join(".")),i.push(this.view.config.adapter.unsubscribe(c,b,this.sync));return i}},d.prototype.update=function(a){var b;return null==a&&(a={}),this.key?a[this.key]&&(this.options.bypass||this.view.config.adapter.unsubscribe(this.model,this.keypath,this.sync),this.model=a[this.key],this.options.bypass?this.sync():(this.view.config.adapter.subscribe(this.model,this.keypath,this.sync),this.view.config.preloadData&&this.sync())):this.sync(),null!=(b=this.binder.update)?b.call(this,a):void 0},d}(),a.ComponentBinding=function(c){function d(c,d,e){var g,h,i,j,k;for(this.view=c,this.el=d,this.type=e,this.unbind=b(this.unbind,this),this.bind=b(this.bind,this),this.update=b(this.update,this),this.locals=b(this.locals,this),this.component=a.components[this.type],this.attributes={},this.inflections={},j=this.el.attributes||[],h=0,i=j.length;i>h;h++)g=j[h],k=g.name,f.call(this.component.attributes,k)>=0?this.attributes[g.name]=g.value:this.inflections[g.name]=g.value}return e(d,c),d.prototype.sync=function(){},d.prototype.locals=function(a){var b,c,d,e,f,g,h,i,j;null==a&&(a=this.view.models),f={},i=this.inflections;for(c in i)for(b=i[c],j=b.split("."),g=0,h=j.length;h>g;g++)e=j[g],f[c]=(f[c]||a)[e];for(c in a)d=a[c],null==f[c]&&(f[c]=d);return f},d.prototype.update=function(a){var b;return null!=(b=this.componentView)?b.update(this.locals(a)):void 0},d.prototype.bind=function(){var b,c;return null!=this.componentView?null!=(c=this.componentView)?c.bind():void 0:(b=this.component.build.call(this.attributes),(this.componentView=new a.View(b,this.locals(),this.view.options)).bind(),this.el.parentNode.replaceChild(b,this.el))},d.prototype.unbind=function(){var a;return null!=(a=this.componentView)?a.unbind():void 0},d}(a.Binding),a.TextBinding=function(a){function c(a,c,d,e,f,g){this.view=a,this.el=c,this.type=d,this.key=e,this.keypath=f,this.options=null!=g?g:{},this.sync=b(this.sync,this),this.formatters=this.options.formatters||[],this.model=this.key?this.view.models[this.key]:this.view.models}return e(c,a),c.prototype.binder={routine:function(a,b){return a.data=null!=b?b:""}},c.prototype.sync=function(){return c.__super__.sync.apply(this,arguments)},c}(a.Binding),a.View=function(){function d(c,d,e){var f,g,h,i,j,k,l,m,n;for(this.els=c,this.models=d,this.options=null!=e?e:{},this.update=b(this.update,this),this.publish=b(this.publish,this),this.sync=b(this.sync,this),this.unbind=b(this.unbind,this),this.bind=b(this.bind,this),this.select=b(this.select,this),this.build=b(this.build,this),this.componentRegExp=b(this.componentRegExp,this),this.bindingRegExp=b(this.bindingRegExp,this),this.els.jquery||this.els instanceof Array||(this.els=[this.els]),l=["config","binders","formatters"],j=0,k=l.length;k>j;j++){if(g=l[j],this[g]={},this.options[g]){m=this.options[g];for(f in m)h=m[f],this[g][f]=h}n=a[g];for(f in n)h=n[f],null==(i=this[g])[f]&&(i[f]=h)}this.build()}return d.prototype.bindingRegExp=function(){var a;return a=this.config.prefix,a?new RegExp("^data-"+a+"-"):/^data-/},d.prototype.componentRegExp=function(){var a,b;return new RegExp("^"+(null!=(a=null!=(b=this.config.prefix)?b.toUpperCase():void 0)?a:"RV")+"-")},d.prototype.build=function(){var b,d,e,g,h,i,j,k,l,m=this;for(this.bindings=[],i=[],b=this.bindingRegExp(),e=this.componentRegExp(),d=function(b,c,d,e){var f,g,h,i,j,k,l,n,o,p;return k={},o=function(){var a,b,c,d;for(c=e.split("|"),d=[],a=0,b=c.length;b>a;a++)n=c[a],d.push(n.trim());return d}(),f=function(){var a,b,c,d;for(c=o.shift().split("<"),d=[],a=0,b=c.length;b>a;a++)g=c[a],d.push(g.trim());return d}(),l=f.shift(),p=l.split(/\.|:/),k.formatters=o,k.bypass=-1!==l.indexOf(":"),p[0]?i=p.shift():(i=null,p.shift()),j=p.join("."),(h=f.shift())&&(k.dependencies=h.split(/\s+/)),m.bindings.push(new a[b](m,c,d,i,j,k))},h=function(g){var j,k,l,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P;if(f.call(i,g)<0){if(g.nodeType===Node.TEXT_NODE){if(r=a.TextTemplateParser,(o=m.config.templateDelimiters)&&(x=r.parse(g.data,o)).length&&(1!==x.length||x[0].type!==r.types.text))for(u=x[0],t=2<=x.length?c.call(x,1):[],g.data=u.value,0===u.type?g.data=u.value:d("TextBinding",g,null,u.value),A=0,E=t.length;E>A;A++)w=t[A],v=document.createTextNode(w.value),g.parentNode.appendChild(v),1===w.type&&d("TextBinding",v,null,w.value)}else if(e.test(g.tagName))y=g.tagName.replace(e,"").toLowerCase(),m.bindings.push(new a.ComponentBinding(m,g,y));else if(null!=g.attributes){for(K=g.attributes,B=0,F=K.length;F>B;B++)if(j=K[B],b.test(j.name)){if(y=j.name.replace(b,""),!(l=m.binders[y])){L=m.binders;for(p in L)z=L[p],"*"!==p&&-1!==p.indexOf("*")&&(s=new RegExp("^"+p.replace("*",".+")+"$"),s.test(y)&&(l=z))}if(l||(l=m.binders["*"]),l.block){for(M=g.childNodes,C=0,G=M.length;G>C;C++)q=M[C],i.push(q);k=[j]}}for(N=k||g.attributes,D=0,H=N.length;H>D;D++)j=N[D],b.test(j.name)&&(y=j.name.replace(b,""),d("Binding",g,y,j.value))}for(O=g.childNodes,P=[],J=0,I=O.length;I>J;J++)n=O[J],P.push(h(n));return P}},l=this.els,j=0,k=l.length;k>j;j++)g=l[j],h(g)},d.prototype.select=function(a){var b,c,d,e,f;for(e=this.bindings,f=[],c=0,d=e.length;d>c;c++)b=e[c],a(b)&&f.push(b);return f},d.prototype.bind=function(){var a,b,c,d,e;for(d=this.bindings,e=[],b=0,c=d.length;c>b;b++)a=d[b],e.push(a.bind());return e},d.prototype.unbind=function(){var a,b,c,d,e;for(d=this.bindings,e=[],b=0,c=d.length;c>b;b++)a=d[b],e.push(a.unbind());return e},d.prototype.sync=function(){var a,b,c,d,e;for(d=this.bindings,e=[],b=0,c=d.length;c>b;b++)a=d[b],e.push(a.sync());return e},d.prototype.publish=function(){var a,b,c,d,e;for(d=this.select(function(a){return a.binder.publishes}),e=[],b=0,c=d.length;c>b;b++)a=d[b],e.push(a.publish());return e},d.prototype.update=function(a){var b,c,d,e,f,g,h;null==a&&(a={});for(c in a)d=a[c],this.models[c]=d;for(g=this.bindings,h=[],e=0,f=g.length;f>e;e++)b=g[e],h.push(b.update(a));return h},d}(),a.TextTemplateParser=function(){function a(){}return a.types={text:0,binding:1},a.parse=function(a,b){var c,d,e,f,g,h,i;for(h=[],f=a.length,c=0,d=0;f>d;){if(c=a.indexOf(b[0],d),0>c){h.push({type:this.types.text,value:a.slice(d)});break}if(c>0&&c>d&&h.push({type:this.types.text,value:a.slice(d,c)}),d=c+2,c=a.indexOf(b[1],d),0>c){g=a.slice(d-2),e=h[h.length-1],(null!=e?e.type:void 0)===this.types.text?e.value+=g:h.push({type:this.types.text,value:g});break}i=a.slice(d,c).trim(),h.push({type:this.types.binding,value:i}),d=c+2}return h},a}(),a.Util={bindEvent:function(a,b,c){return null!=window.jQuery?(a=jQuery(a),null!=a.on?a.on(b,c):a.bind(b,c)):null!=window.addEventListener?a.addEventListener(b,c,!1):(b="on"+b,a.attachEvent(b,c))},unbindEvent:function(a,b,c){return null!=window.jQuery?(a=jQuery(a),null!=a.off?a.off(b,c):a.unbind(b,c)):null!=window.removeEventListener?a.removeEventListener(b,c,!1):(b="on"+b,a.detachEvent(b,c))},getInputValue:function(a){var b,c,d,e;if(null!=window.jQuery)switch(a=jQuery(a),a[0].type){case"checkbox":return a.is(":checked");default:return a.val()}else switch(a.type){case"checkbox":return a.checked;case"select-multiple":for(e=[],c=0,d=a.length;d>c;c++)b=a[c],b.selected&&e.push(b.value);return e;default:return a.value}}},a.binders={enabled:function(a,b){return a.disabled=!b},disabled:function(a,b){return a.disabled=!!b},checked:{publishes:!0,bind:function(b){return a.Util.bindEvent(b,"change",this.publish)},unbind:function(b){return a.Util.unbindEvent(b,"change",this.publish)},routine:function(a,b){var c;return a.checked="radio"===a.type?(null!=(c=a.value)?c.toString():void 0)===(null!=b?b.toString():void 0):!!b}},unchecked:{publishes:!0,bind:function(b){return a.Util.bindEvent(b,"change",this.publish)},unbind:function(b){return a.Util.unbindEvent(b,"change",this.publish)},routine:function(a,b){var c;return a.checked="radio"===a.type?(null!=(c=a.value)?c.toString():void 0)!==(null!=b?b.toString():void 0):!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=null!=b?b:""},value:{publishes:!0,bind:function(b){return a.Util.bindEvent(b,"change",this.publish)},unbind:function(b){return a.Util.unbindEvent(b,"change",this.publish)},routine:function(a,b){var c,d,e,g,h,i,j;if(null!=window.jQuery){if(a=jQuery(a),(null!=b?b.toString():void 0)!==(null!=(g=a.val())?g.toString():void 0))return a.val(null!=b?b:"")}else if("select-multiple"===a.type){if(null!=b){for(j=[],d=0,e=a.length;e>d;d++)c=a[d],j.push(c.selected=(h=c.value,f.call(b,h)>=0));return j}}else if((null!=b?b.toString():void 0)!==(null!=(i=a.value)?i.toString():void 0))return a.value=null!=b?b:""}},text:function(a,b){return null!=a.innerText?a.innerText=null!=b?b:"":a.textContent=null!=b?b:""},"if":{block:!0,bind:function(a){var b,c;return null==this.marker?(b=["data",this.view.config.prefix,this.type].join("-").replace("--","-"),c=a.getAttribute(b),this.marker=document.createComment(" rivets: "+this.type+" "+c+" "),a.removeAttribute(b),a.parentNode.insertBefore(this.marker,a),a.parentNode.removeChild(a)):void 0},unbind:function(){var a;return null!=(a=this.nested)?a.unbind():void 0},routine:function(b,c){var d,e,f,g,h;if(!!c==(null==this.nested)){if(c){f={},h=this.view.models;for(d in h)e=h[d],f[d]=e;return g={binders:this.view.options.binders,formatters:this.view.options.formatters,config:this.view.options.config},(this.nested=new a.View(b,f,g)).bind(),this.marker.parentNode.insertBefore(b,this.marker.nextSibling)}return b.parentNode.removeChild(b),this.nested.unbind(),delete this.nested}},update:function(a){var b;return null!=(b=this.nested)?b.update(a):void 0}},unless:{block:!0,bind:function(b){return a.binders["if"].bind.call(this,b)},unbind:function(){return a.binders["if"].unbind.call(this)},routine:function(b,c){return a.binders["if"].routine.call(this,b,!c)},update:function(b){return a.binders["if"].update.call(this,b)}},"on-*":{"function":!0,unbind:function(b){return this.handler?a.Util.unbindEvent(b,this.args[0],this.handler):void 0},routine:function(b,c){return this.handler&&a.Util.unbindEvent(b,this.args[0],this.handler),a.Util.bindEvent(b,this.args[0],this.handler=this.eventHandler(c))}},"each-*":{block:!0,bind:function(a){var b;return null==this.marker?(b=["data",this.view.config.prefix,this.type].join("-").replace("--","-"),this.marker=document.createComment(" rivets: "+this.type+" "),this.iterated=[],a.removeAttribute(b),a.parentNode.insertBefore(this.marker,a),a.parentNode.removeChild(a)):void 0},unbind:function(){var a,b,c,d,e;if(null!=this.iterated){for(d=this.iterated,e=[],b=0,c=d.length;c>b;b++)a=d[b],e.push(a.unbind());return e}},routine:function(b,c){var d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w;if(j=this.args[0],c=c||[],this.iterated.length>c.length)for(t=Array(this.iterated.length-c.length),p=0,r=t.length;r>p;p++)e=t[p],o=this.iterated.pop(),o.unbind(),this.marker.parentNode.removeChild(o.els[0]);for(w=[],f=q=0,s=c.length;s>q;f=++q)if(i=c[f],d={},d[j]=i,null==this.iterated[f]){u=this.view.models;for(h in u)i=u[h],null==d[h]&&(d[h]=i);l=this.iterated.length?this.iterated[this.iterated.length-1].els[0]:this.marker,k={binders:this.view.options.binders,formatters:this.view.options.formatters,config:{}},v=this.view.options.config;for(g in v)n=v[g],k.config[g]=n;k.config.preloadData=!0,m=b.cloneNode(!0),o=new a.View(m,d,k),o.bind(),this.iterated.push(o),w.push(this.marker.parentNode.insertBefore(m,l.nextSibling))}else this.iterated[f].models[j]!==i?w.push(this.iterated[f].update(d)):w.push(void 0);return w},update:function(a){var b,c,d,e,f,g,h,i;b={};for(c in a)d=a[c],c!==this.args[0]&&(b[c]=d);for(h=this.iterated,i=[],f=0,g=h.length;g>f;f++)e=h[f],i.push(e.update(b));return i}},"class-*":function(a,b){var c;return c=" "+a.className+" ",!b==(-1!==c.indexOf(" "+this.args[0]+" "))?a.className=b?""+a.className+" "+this.args[0]:c.replace(" "+this.args[0]+" "," ").trim():void 0},"*":function(a,b){return b?a.setAttribute(this.type,b):a.removeAttribute(this.type)}},a.components={},a.config={preloadData:!0,handler:function(a,b,c){return this.call(a,b,c.view.models)}},a.formatters={},a.factory=function(b){return b._=a,b.binders=a.binders,b.components=a.components,b.formatters=a.formatters,b.config=a.config,b.configure=function(b){var c,d;null==b&&(b={});for(c in b)d=b[c],a.config[c]=d},b.bind=function(b,c,d){var e;return null==c&&(c={}),null==d&&(d={}),e=new a.View(b,c,d),e.bind(),e}},"object"==typeof exports?a.factory(exports):"function"==typeof define&&define.amd?define(["exports"],function(b){return a.factory(this.rivets=b),b}):a.factory(this.rivets={})}.call(this);
|
data/lib/rivets-rails/version.rb
CHANGED
@@ -2,7 +2,7 @@ rivets = @rivets
|
|
2
2
|
|
3
3
|
#
|
4
4
|
# Support of Contenteditable
|
5
|
-
# http://jsfiddle.net/3yLQY/4/
|
5
|
+
# from http://jsfiddle.net/3yLQY/4/
|
6
6
|
#
|
7
7
|
rivets.binders.content =
|
8
8
|
routine: rivets.binders.text
|
@@ -15,3 +15,11 @@ rivets.binders.content =
|
|
15
15
|
|
16
16
|
unbind: (el) ->
|
17
17
|
el.removeEventListener "input", @callback, false
|
18
|
+
|
19
|
+
#
|
20
|
+
# from http://rivetsjs.com/
|
21
|
+
#
|
22
|
+
rivets.binders.color = (el, value) ->
|
23
|
+
el.style.color = value
|
24
|
+
|
25
|
+
# <span data-color="model.color">COLOR</span>
|
@@ -1,7 +1,7 @@
|
|
1
1
|
rivets = @rivets
|
2
2
|
|
3
3
|
#
|
4
|
-
# https://github.com/mikeric/rivets/wiki/Example-formatters
|
4
|
+
# from https://github.com/mikeric/rivets/wiki/Example-formatters
|
5
5
|
#
|
6
6
|
rivets.formatters.shortdate = (value) ->
|
7
7
|
moment(value).format "YYYY-MM-DD"
|
@@ -59,5 +59,23 @@ rivets.formatters.preventDefault = (value) ->
|
|
59
59
|
|
60
60
|
|
61
61
|
|
62
|
+
#
|
63
|
+
# custom
|
64
|
+
#
|
62
65
|
rivets.formatters.length = (value) ->
|
63
66
|
value.length
|
67
|
+
|
68
|
+
# data-length="model.foo | length"
|
69
|
+
|
70
|
+
|
71
|
+
#
|
72
|
+
# from http://rivetsjs.com/
|
73
|
+
#
|
74
|
+
rivets.formatters.mask = (value, left, right, mask) ->
|
75
|
+
formatted = value.substring(0, left)
|
76
|
+
formatted + mask
|
77
|
+
formatted += value.substring(value.length - right)
|
78
|
+
formatted
|
79
|
+
|
80
|
+
# <span data-text="billing.cardNumber | mask 4 4 ********"></span>
|
81
|
+
|
@@ -51,4 +51,13 @@
|
|
51
51
|
return value.length;
|
52
52
|
};
|
53
53
|
|
54
|
+
rivets.formatters.mask = function(value, left, right, mask) {
|
55
|
+
var formatted;
|
56
|
+
|
57
|
+
formatted = value.substring(0, left);
|
58
|
+
formatted + mask;
|
59
|
+
formatted += value.substring(value.length - right);
|
60
|
+
return formatted;
|
61
|
+
};
|
62
|
+
|
54
63
|
}).call(this);
|
@@ -34,6 +34,10 @@
|
|
34
34
|
}
|
35
35
|
};
|
36
36
|
|
37
|
+
rivets.binders.color = function(el, value) {
|
38
|
+
return el.style.color = value;
|
39
|
+
};
|
40
|
+
|
37
41
|
}).call(this);
|
38
42
|
|
39
43
|
(function() {
|
@@ -89,6 +93,15 @@
|
|
89
93
|
return value.length;
|
90
94
|
};
|
91
95
|
|
96
|
+
rivets.formatters.mask = function(value, left, right, mask) {
|
97
|
+
var formatted;
|
98
|
+
|
99
|
+
formatted = value.substring(0, left);
|
100
|
+
formatted + mask;
|
101
|
+
formatted += value.substring(value.length - right);
|
102
|
+
return formatted;
|
103
|
+
};
|
104
|
+
|
92
105
|
}).call(this);
|
93
106
|
|
94
107
|
(function() {
|
@@ -2,4 +2,4 @@
|
|
2
2
|
// version: 0.1.1
|
3
3
|
// author: vkill
|
4
4
|
// license: MIT
|
5
|
-
!function(){var a;a=this.rivets,a.configure({prefix:"bind"})}.call(this),function(){var a;a=this.rivets,a.binders.content={routine:a.binders.text,bind:function(b){var c;return c=this,this.callback=function(){return a.config.adapter.publish(c.model,c.keypath,b.textContent)},b.addEventListener("input",this.callback,!1)},unbind:function(a){return a.removeEventListener("input",this.callback,!1)}}}.call(this),function(){var a;a=this.rivets,a.formatters.shortdate=function(a){return moment(a).format("YYYY-MM-DD")},a.formatters.number=function(a){return+a},a.formatters.string=function(a){return String(a)},a.formatters.negate=function(a){return!a},a.formatters.eq=function(a,b){return a===b},a.formatters.not_eq=function(a,b){return a!==b},a.formatters.gt=function(a,b){return a>b},a.formatters.lt=function(a,b){return b>a},a.formatters.blank=function(a){return null==a||""===a},a.formatters.preventDefault=function(a){return function(b){return b.preventDefault(),a.call(this,b),!1}},a.formatters.length=function(a){return a.length}}.call(this),function(){var a;a=this.rivets,a.configure({adapter:{subscribe:function(a,b,c){return null!=a.on?a.on("change:"+b,c):void 0},unsubscribe:function(a,b,c){return null!=a.off?a.off("change:"+b,c):void 0},read:function(a,b){return a[b]},publish:function(a,b,c){return a[b]=c}}})}.call(this);
|
5
|
+
!function(){var a;a=this.rivets,a.configure({prefix:"bind"})}.call(this),function(){var a;a=this.rivets,a.binders.content={routine:a.binders.text,bind:function(b){var c;return c=this,this.callback=function(){return a.config.adapter.publish(c.model,c.keypath,b.textContent)},b.addEventListener("input",this.callback,!1)},unbind:function(a){return a.removeEventListener("input",this.callback,!1)}},a.binders.color=function(a,b){return a.style.color=b}}.call(this),function(){var a;a=this.rivets,a.formatters.shortdate=function(a){return moment(a).format("YYYY-MM-DD")},a.formatters.number=function(a){return+a},a.formatters.string=function(a){return String(a)},a.formatters.negate=function(a){return!a},a.formatters.eq=function(a,b){return a===b},a.formatters.not_eq=function(a,b){return a!==b},a.formatters.gt=function(a,b){return a>b},a.formatters.lt=function(a,b){return b>a},a.formatters.blank=function(a){return null==a||""===a},a.formatters.preventDefault=function(a){return function(b){return b.preventDefault(),a.call(this,b),!1}},a.formatters.length=function(a){return a.length},a.formatters.mask=function(a,b,c,d){var e;return e=a.substring(0,b),e+=a.substring(a.length-c)}}.call(this),function(){var a;a=this.rivets,a.configure({adapter:{subscribe:function(a,b,c){return null!=a.on?a.on("change:"+b,c):void 0},unsubscribe:function(a,b,c){return null!=a.off?a.off("change:"+b,c):void 0},read:function(a,b){return a[b]},publish:function(a,b,c){return a[b]=c}}})}.call(this);
|
@@ -1,5 +1,5 @@
|
|
1
1
|
// Rivets.js
|
2
|
-
// version: 0.5.
|
2
|
+
// version: 0.5.12
|
3
3
|
// author: Michael Richards
|
4
4
|
// license: MIT
|
5
5
|
(function() {
|
@@ -21,7 +21,6 @@
|
|
21
21
|
Rivets.Binding = (function() {
|
22
22
|
function Binding(view, el, type, key, keypath, options) {
|
23
23
|
var identifier, regexp, value, _ref;
|
24
|
-
|
25
24
|
this.view = view;
|
26
25
|
this.el = el;
|
27
26
|
this.type = type;
|
@@ -36,7 +35,7 @@
|
|
36
35
|
this.set = __bind(this.set, this);
|
37
36
|
this.eventHandler = __bind(this.eventHandler, this);
|
38
37
|
this.formattedValue = __bind(this.formattedValue, this);
|
39
|
-
if (!(this.binder =
|
38
|
+
if (!(this.binder = this.view.binders[type])) {
|
40
39
|
_ref = this.view.binders;
|
41
40
|
for (identifier in _ref) {
|
42
41
|
value = _ref[identifier];
|
@@ -62,7 +61,6 @@
|
|
62
61
|
|
63
62
|
Binding.prototype.formattedValue = function(value) {
|
64
63
|
var args, formatter, id, _i, _len, _ref;
|
65
|
-
|
66
64
|
_ref = this.formatters;
|
67
65
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
68
66
|
formatter = _ref[_i];
|
@@ -80,7 +78,6 @@
|
|
80
78
|
|
81
79
|
Binding.prototype.eventHandler = function(fn) {
|
82
80
|
var binding, handler;
|
83
|
-
|
84
81
|
handler = (binding = this).view.config.handler;
|
85
82
|
return function(ev) {
|
86
83
|
return handler.call(fn, this, ev, binding);
|
@@ -89,7 +86,6 @@
|
|
89
86
|
|
90
87
|
Binding.prototype.set = function(value) {
|
91
88
|
var _ref;
|
92
|
-
|
93
89
|
value = value instanceof Function && !this.binder["function"] ? this.formattedValue(value.call(this.model)) : this.formattedValue(value);
|
94
90
|
return (_ref = this.binder.routine) != null ? _ref.call(this, this.el, value) : void 0;
|
95
91
|
};
|
@@ -100,7 +96,6 @@
|
|
100
96
|
|
101
97
|
Binding.prototype.publish = function() {
|
102
98
|
var args, formatter, id, value, _i, _len, _ref, _ref1, _ref2;
|
103
|
-
|
104
99
|
value = Rivets.Util.getInputValue(this.el);
|
105
100
|
_ref = this.formatters.slice(0).reverse();
|
106
101
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
@@ -116,7 +111,6 @@
|
|
116
111
|
|
117
112
|
Binding.prototype.bind = function() {
|
118
113
|
var dependency, keypath, model, _i, _len, _ref, _ref1, _ref2, _results;
|
119
|
-
|
120
114
|
if ((_ref = this.binder.bind) != null) {
|
121
115
|
_ref.call(this, this.el);
|
122
116
|
}
|
@@ -149,7 +143,6 @@
|
|
149
143
|
|
150
144
|
Binding.prototype.unbind = function() {
|
151
145
|
var dependency, keypath, model, _i, _len, _ref, _ref1, _ref2, _results;
|
152
|
-
|
153
146
|
if ((_ref = this.binder.unbind) != null) {
|
154
147
|
_ref.call(this, this.el);
|
155
148
|
}
|
@@ -177,7 +170,6 @@
|
|
177
170
|
|
178
171
|
Binding.prototype.update = function(models) {
|
179
172
|
var _ref;
|
180
|
-
|
181
173
|
if (models == null) {
|
182
174
|
models = {};
|
183
175
|
}
|
@@ -211,7 +203,6 @@
|
|
211
203
|
|
212
204
|
function ComponentBinding(view, el, type) {
|
213
205
|
var attribute, _i, _len, _ref, _ref1;
|
214
|
-
|
215
206
|
this.view = view;
|
216
207
|
this.el = el;
|
217
208
|
this.type = type;
|
@@ -236,8 +227,7 @@
|
|
236
227
|
ComponentBinding.prototype.sync = function() {};
|
237
228
|
|
238
229
|
ComponentBinding.prototype.locals = function(models) {
|
239
|
-
var inverse, key, model, result, _ref, _ref1;
|
240
|
-
|
230
|
+
var inverse, key, model, path, result, _i, _len, _ref, _ref1;
|
241
231
|
if (models == null) {
|
242
232
|
models = this.view.models;
|
243
233
|
}
|
@@ -245,11 +235,15 @@
|
|
245
235
|
_ref = this.inflections;
|
246
236
|
for (key in _ref) {
|
247
237
|
inverse = _ref[key];
|
248
|
-
|
238
|
+
_ref1 = inverse.split('.');
|
239
|
+
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
240
|
+
path = _ref1[_i];
|
241
|
+
result[key] = (result[key] || models)[path];
|
242
|
+
}
|
249
243
|
}
|
250
244
|
for (key in models) {
|
251
245
|
model = models[key];
|
252
|
-
if (
|
246
|
+
if (result[key] == null) {
|
253
247
|
result[key] = model;
|
254
248
|
}
|
255
249
|
}
|
@@ -258,13 +252,11 @@
|
|
258
252
|
|
259
253
|
ComponentBinding.prototype.update = function(models) {
|
260
254
|
var _ref;
|
261
|
-
|
262
255
|
return (_ref = this.componentView) != null ? _ref.update(this.locals(models)) : void 0;
|
263
256
|
};
|
264
257
|
|
265
258
|
ComponentBinding.prototype.bind = function() {
|
266
259
|
var el, _ref;
|
267
|
-
|
268
260
|
if (this.componentView != null) {
|
269
261
|
return (_ref = this.componentView) != null ? _ref.bind() : void 0;
|
270
262
|
} else {
|
@@ -276,7 +268,6 @@
|
|
276
268
|
|
277
269
|
ComponentBinding.prototype.unbind = function() {
|
278
270
|
var _ref;
|
279
|
-
|
280
271
|
return (_ref = this.componentView) != null ? _ref.unbind() : void 0;
|
281
272
|
};
|
282
273
|
|
@@ -284,10 +275,38 @@
|
|
284
275
|
|
285
276
|
})(Rivets.Binding);
|
286
277
|
|
278
|
+
Rivets.TextBinding = (function(_super) {
|
279
|
+
__extends(TextBinding, _super);
|
280
|
+
|
281
|
+
function TextBinding(view, el, type, key, keypath, options) {
|
282
|
+
this.view = view;
|
283
|
+
this.el = el;
|
284
|
+
this.type = type;
|
285
|
+
this.key = key;
|
286
|
+
this.keypath = keypath;
|
287
|
+
this.options = options != null ? options : {};
|
288
|
+
this.sync = __bind(this.sync, this);
|
289
|
+
this.formatters = this.options.formatters || [];
|
290
|
+
this.model = this.key ? this.view.models[this.key] : this.view.models;
|
291
|
+
}
|
292
|
+
|
293
|
+
TextBinding.prototype.binder = {
|
294
|
+
routine: function(node, value) {
|
295
|
+
return node.data = value != null ? value : '';
|
296
|
+
}
|
297
|
+
};
|
298
|
+
|
299
|
+
TextBinding.prototype.sync = function() {
|
300
|
+
return TextBinding.__super__.sync.apply(this, arguments);
|
301
|
+
};
|
302
|
+
|
303
|
+
return TextBinding;
|
304
|
+
|
305
|
+
})(Rivets.Binding);
|
306
|
+
|
287
307
|
Rivets.View = (function() {
|
288
308
|
function View(els, models, options) {
|
289
|
-
var k, option, v, _base, _i, _len, _ref, _ref1, _ref2
|
290
|
-
|
309
|
+
var k, option, v, _base, _i, _len, _ref, _ref1, _ref2;
|
291
310
|
this.els = els;
|
292
311
|
this.models = models;
|
293
312
|
this.options = options != null ? options : {};
|
@@ -317,7 +336,7 @@
|
|
317
336
|
_ref2 = Rivets[option];
|
318
337
|
for (k in _ref2) {
|
319
338
|
v = _ref2[k];
|
320
|
-
if ((
|
339
|
+
if ((_base = this[option])[k] == null) {
|
321
340
|
_base[k] = v;
|
322
341
|
}
|
323
342
|
}
|
@@ -327,7 +346,6 @@
|
|
327
346
|
|
328
347
|
View.prototype.bindingRegExp = function() {
|
329
348
|
var prefix;
|
330
|
-
|
331
349
|
prefix = this.config.prefix;
|
332
350
|
if (prefix) {
|
333
351
|
return new RegExp("^data-" + prefix + "-");
|
@@ -338,25 +356,21 @@
|
|
338
356
|
|
339
357
|
View.prototype.componentRegExp = function() {
|
340
358
|
var _ref, _ref1;
|
341
|
-
|
342
359
|
return new RegExp("^" + ((_ref = (_ref1 = this.config.prefix) != null ? _ref1.toUpperCase() : void 0) != null ? _ref : 'RV') + "-");
|
343
360
|
};
|
344
361
|
|
345
362
|
View.prototype.build = function() {
|
346
363
|
var bindingRegExp, buildBinding, componentRegExp, el, parse, skipNodes, _i, _len, _ref,
|
347
364
|
_this = this;
|
348
|
-
|
349
365
|
this.bindings = [];
|
350
366
|
skipNodes = [];
|
351
367
|
bindingRegExp = this.bindingRegExp();
|
352
368
|
componentRegExp = this.componentRegExp();
|
353
|
-
buildBinding = function(node, type, declaration) {
|
369
|
+
buildBinding = function(binding, node, type, declaration) {
|
354
370
|
var context, ctx, dependencies, key, keypath, options, path, pipe, pipes, splitPath;
|
355
|
-
|
356
371
|
options = {};
|
357
372
|
pipes = (function() {
|
358
373
|
var _i, _len, _ref, _results;
|
359
|
-
|
360
374
|
_ref = declaration.split('|');
|
361
375
|
_results = [];
|
362
376
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
@@ -367,7 +381,6 @@
|
|
367
381
|
})();
|
368
382
|
context = (function() {
|
369
383
|
var _i, _len, _ref, _results;
|
370
|
-
|
371
384
|
_ref = pipes.shift().split('<');
|
372
385
|
_results = [];
|
373
386
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
@@ -390,11 +403,10 @@
|
|
390
403
|
if (dependencies = context.shift()) {
|
391
404
|
options.dependencies = dependencies.split(/\s+/);
|
392
405
|
}
|
393
|
-
return _this.bindings.push(new Rivets
|
406
|
+
return _this.bindings.push(new Rivets[binding](_this, node, type, key, keypath, options));
|
394
407
|
};
|
395
408
|
parse = function(node) {
|
396
409
|
var attribute, attributes, binder, childNode, delimiters, identifier, n, parser, regexp, restTokens, startToken, text, token, tokens, type, value, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref, _ref1, _ref2, _ref3, _ref4, _results;
|
397
|
-
|
398
410
|
if (__indexOf.call(skipNodes, node) < 0) {
|
399
411
|
if (node.nodeType === Node.TEXT_NODE) {
|
400
412
|
parser = Rivets.TextTemplateParser;
|
@@ -403,18 +415,17 @@
|
|
403
415
|
if (!(tokens.length === 1 && tokens[0].type === parser.types.text)) {
|
404
416
|
startToken = tokens[0], restTokens = 2 <= tokens.length ? __slice.call(tokens, 1) : [];
|
405
417
|
node.data = startToken.value;
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
case 1:
|
411
|
-
buildBinding(node, 'textNode', startToken.value);
|
418
|
+
if (startToken.type === 0) {
|
419
|
+
node.data = startToken.value;
|
420
|
+
} else {
|
421
|
+
buildBinding('TextBinding', node, null, startToken.value);
|
412
422
|
}
|
413
423
|
for (_i = 0, _len = restTokens.length; _i < _len; _i++) {
|
414
424
|
token = restTokens[_i];
|
415
|
-
|
425
|
+
text = document.createTextNode(token.value);
|
426
|
+
node.parentNode.appendChild(text);
|
416
427
|
if (token.type === 1) {
|
417
|
-
buildBinding(text,
|
428
|
+
buildBinding('TextBinding', text, null, token.value);
|
418
429
|
}
|
419
430
|
}
|
420
431
|
}
|
@@ -457,7 +468,7 @@
|
|
457
468
|
attribute = _ref3[_l];
|
458
469
|
if (bindingRegExp.test(attribute.name)) {
|
459
470
|
type = attribute.name.replace(bindingRegExp, '');
|
460
|
-
buildBinding(node, type, attribute.value);
|
471
|
+
buildBinding('Binding', node, type, attribute.value);
|
461
472
|
}
|
462
473
|
}
|
463
474
|
}
|
@@ -479,7 +490,6 @@
|
|
479
490
|
|
480
491
|
View.prototype.select = function(fn) {
|
481
492
|
var binding, _i, _len, _ref, _results;
|
482
|
-
|
483
493
|
_ref = this.bindings;
|
484
494
|
_results = [];
|
485
495
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
@@ -493,7 +503,6 @@
|
|
493
503
|
|
494
504
|
View.prototype.bind = function() {
|
495
505
|
var binding, _i, _len, _ref, _results;
|
496
|
-
|
497
506
|
_ref = this.bindings;
|
498
507
|
_results = [];
|
499
508
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
@@ -505,7 +514,6 @@
|
|
505
514
|
|
506
515
|
View.prototype.unbind = function() {
|
507
516
|
var binding, _i, _len, _ref, _results;
|
508
|
-
|
509
517
|
_ref = this.bindings;
|
510
518
|
_results = [];
|
511
519
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
@@ -517,7 +525,6 @@
|
|
517
525
|
|
518
526
|
View.prototype.sync = function() {
|
519
527
|
var binding, _i, _len, _ref, _results;
|
520
|
-
|
521
528
|
_ref = this.bindings;
|
522
529
|
_results = [];
|
523
530
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
@@ -529,7 +536,6 @@
|
|
529
536
|
|
530
537
|
View.prototype.publish = function() {
|
531
538
|
var binding, _i, _len, _ref, _results;
|
532
|
-
|
533
539
|
_ref = this.select(function(b) {
|
534
540
|
return b.binder.publishes;
|
535
541
|
});
|
@@ -543,7 +549,6 @@
|
|
543
549
|
|
544
550
|
View.prototype.update = function(models) {
|
545
551
|
var binding, key, model, _i, _len, _ref, _results;
|
546
|
-
|
547
552
|
if (models == null) {
|
548
553
|
models = {};
|
549
554
|
}
|
@@ -574,7 +579,6 @@
|
|
574
579
|
|
575
580
|
TextTemplateParser.parse = function(template, delimiters) {
|
576
581
|
var index, lastIndex, lastToken, length, substring, tokens, value;
|
577
|
-
|
578
582
|
tokens = [];
|
579
583
|
length = template.length;
|
580
584
|
index = 0;
|
@@ -657,7 +661,6 @@
|
|
657
661
|
},
|
658
662
|
getInputValue: function(el) {
|
659
663
|
var o, _i, _len, _results;
|
660
|
-
|
661
664
|
if (window.jQuery != null) {
|
662
665
|
el = jQuery(el);
|
663
666
|
switch (el[0].type) {
|
@@ -704,7 +707,6 @@
|
|
704
707
|
},
|
705
708
|
routine: function(el, value) {
|
706
709
|
var _ref;
|
707
|
-
|
708
710
|
if (el.type === 'radio') {
|
709
711
|
return el.checked = ((_ref = el.value) != null ? _ref.toString() : void 0) === (value != null ? value.toString() : void 0);
|
710
712
|
} else {
|
@@ -722,7 +724,6 @@
|
|
722
724
|
},
|
723
725
|
routine: function(el, value) {
|
724
726
|
var _ref;
|
725
|
-
|
726
727
|
if (el.type === 'radio') {
|
727
728
|
return el.checked = ((_ref = el.value) != null ? _ref.toString() : void 0) !== (value != null ? value.toString() : void 0);
|
728
729
|
} else {
|
@@ -749,7 +750,6 @@
|
|
749
750
|
},
|
750
751
|
routine: function(el, value) {
|
751
752
|
var o, _i, _len, _ref, _ref1, _ref2, _results;
|
752
|
-
|
753
753
|
if (window.jQuery != null) {
|
754
754
|
el = jQuery(el);
|
755
755
|
if ((value != null ? value.toString() : void 0) !== ((_ref = el.val()) != null ? _ref.toString() : void 0)) {
|
@@ -782,7 +782,6 @@
|
|
782
782
|
block: true,
|
783
783
|
bind: function(el) {
|
784
784
|
var attr, declaration;
|
785
|
-
|
786
785
|
if (this.marker == null) {
|
787
786
|
attr = ['data', this.view.config.prefix, this.type].join('-').replace('--', '-');
|
788
787
|
declaration = el.getAttribute(attr);
|
@@ -794,12 +793,10 @@
|
|
794
793
|
},
|
795
794
|
unbind: function() {
|
796
795
|
var _ref;
|
797
|
-
|
798
796
|
return (_ref = this.nested) != null ? _ref.unbind() : void 0;
|
799
797
|
},
|
800
798
|
routine: function(el, value) {
|
801
799
|
var key, model, models, options, _ref;
|
802
|
-
|
803
800
|
if (!!value === (this.nested == null)) {
|
804
801
|
if (value) {
|
805
802
|
models = {};
|
@@ -823,7 +820,8 @@
|
|
823
820
|
}
|
824
821
|
},
|
825
822
|
update: function(models) {
|
826
|
-
|
823
|
+
var _ref;
|
824
|
+
return (_ref = this.nested) != null ? _ref.update(models) : void 0;
|
827
825
|
}
|
828
826
|
},
|
829
827
|
unless: {
|
@@ -859,7 +857,6 @@
|
|
859
857
|
block: true,
|
860
858
|
bind: function(el) {
|
861
859
|
var attr;
|
862
|
-
|
863
860
|
if (this.marker == null) {
|
864
861
|
attr = ['data', this.view.config.prefix, this.type].join('-').replace('--', '-');
|
865
862
|
this.marker = document.createComment(" rivets: " + this.type + " ");
|
@@ -871,7 +868,6 @@
|
|
871
868
|
},
|
872
869
|
unbind: function(el) {
|
873
870
|
var view, _i, _len, _ref, _results;
|
874
|
-
|
875
871
|
if (this.iterated != null) {
|
876
872
|
_ref = this.iterated;
|
877
873
|
_results = [];
|
@@ -883,8 +879,7 @@
|
|
883
879
|
}
|
884
880
|
},
|
885
881
|
routine: function(el, collection) {
|
886
|
-
var data, i, index, k, key, model, modelName, options, previous, template, v, view, _i, _j, _len, _len1, _ref, _ref1, _ref2,
|
887
|
-
|
882
|
+
var data, i, index, k, key, model, modelName, options, previous, template, v, view, _i, _j, _len, _len1, _ref, _ref1, _ref2, _results;
|
888
883
|
modelName = this.args[0];
|
889
884
|
collection = collection || [];
|
890
885
|
if (this.iterated.length > collection.length) {
|
@@ -905,7 +900,7 @@
|
|
905
900
|
_ref1 = this.view.models;
|
906
901
|
for (key in _ref1) {
|
907
902
|
model = _ref1[key];
|
908
|
-
if (
|
903
|
+
if (data[key] == null) {
|
909
904
|
data[key] = model;
|
910
905
|
}
|
911
906
|
}
|
@@ -915,9 +910,9 @@
|
|
915
910
|
formatters: this.view.options.formatters,
|
916
911
|
config: {}
|
917
912
|
};
|
918
|
-
|
919
|
-
for (k in
|
920
|
-
v =
|
913
|
+
_ref2 = this.view.options.config;
|
914
|
+
for (k in _ref2) {
|
915
|
+
v = _ref2[k];
|
921
916
|
options.config[k] = v;
|
922
917
|
}
|
923
918
|
options.config.preloadData = true;
|
@@ -936,7 +931,6 @@
|
|
936
931
|
},
|
937
932
|
update: function(models) {
|
938
933
|
var data, key, model, view, _i, _len, _ref, _results;
|
939
|
-
|
940
934
|
data = {};
|
941
935
|
for (key in models) {
|
942
936
|
model = models[key];
|
@@ -955,7 +949,6 @@
|
|
955
949
|
},
|
956
950
|
"class-*": function(el, value) {
|
957
951
|
var elClass;
|
958
|
-
|
959
952
|
elClass = " " + el.className + " ";
|
960
953
|
if (!value === (elClass.indexOf(" " + this.args[0] + " ") !== -1)) {
|
961
954
|
return el.className = value ? "" + el.className + " " + this.args[0] : elClass.replace(" " + this.args[0] + " ", ' ').trim();
|
@@ -970,12 +963,6 @@
|
|
970
963
|
}
|
971
964
|
};
|
972
965
|
|
973
|
-
Rivets.internalBinders = {
|
974
|
-
textNode: function(node, value) {
|
975
|
-
return node.data = value != null ? value : '';
|
976
|
-
}
|
977
|
-
};
|
978
|
-
|
979
966
|
Rivets.components = {};
|
980
967
|
|
981
968
|
Rivets.config = {
|
@@ -995,7 +982,6 @@
|
|
995
982
|
exports.config = Rivets.config;
|
996
983
|
exports.configure = function(options) {
|
997
984
|
var property, value;
|
998
|
-
|
999
985
|
if (options == null) {
|
1000
986
|
options = {};
|
1001
987
|
}
|
@@ -1006,7 +992,6 @@
|
|
1006
992
|
};
|
1007
993
|
return exports.bind = function(el, models, options) {
|
1008
994
|
var view;
|
1009
|
-
|
1010
995
|
if (models == null) {
|
1011
996
|
models = {};
|
1012
997
|
}
|