diff --git a/ajax/libs/rivets/0.7.0-rc3/rivets.bundled.min.js b/ajax/libs/rivets/0.7.0-rc3/rivets.bundled.min.js new file mode 100644 index 000000000..0093ec919 --- /dev/null +++ b/ajax/libs/rivets/0.7.0-rc3/rivets.bundled.min.js @@ -0,0 +1,6 @@ +// Rivets.js + Sightglass.js +// version: 0.7.0-rc3 +// author: Michael Richards +// license: MIT +(function(){function t(t,i,s,r){return new e(t,i,s,r)}function e(t,e,s,r){this.options=r||{},this.options.adapters=this.options.adapters||{},this.obj=t,this.keypath=e,this.callback=s,this.objectPath=[],this.parse(),i(this.target=this.realize())&&this.set(!0,this.key,this.target,this.callback)}function i(t){return"object"==typeof t&&null!==t}function s(t){throw new Error("[sightglass] "+t)}t.adapters={},e.tokenize=function(t,e,i){for(tokens=[],current={i:i,path:""},index=0;indexe;e++)if(e in this&&this[e]===t)return e;return-1};t={options:["prefix","templateDelimiters","rootInterface","preloadData","handler"],extensions:["binders","formatters","components","adapters"],"public":{binders:{},components:{},formatters:{},adapters:{},prefix:"rv",templateDelimiters:["{","}"],rootInterface:".",preloadData:!0,handler:function(t,e,i){return this.call(t,e,i.view.models)},configure:function(e){var i,n,r,s;null==e&&(e={});for(r in e)if(s=e[r],"binders"===r||"components"===r||"formatters"===r||"adapters"===r)for(n in s)i=s[n],t[r][n]=i;else t["public"][r]=s},bind:function(e,i,n){var r;return null==i&&(i={}),null==n&&(n={}),r=new t.View(e,i,n),r.bind(),r}}},window.jQuery||window.$?(n="on"in jQuery.prototype?["on","off"]:["bind","unbind"],e=n[0],i=n[1],t.Util={bindEvent:function(t,i,n){return jQuery(t)[e](i,n)},unbindEvent:function(t,e,n){return jQuery(t)[i](e,n)},getInputValue:function(t){var e;return e=jQuery(t),"checkbox"===e.attr("type")?e.is(":checked"):e.val()}}):t.Util={bindEvent:function(){return"addEventListener"in window?function(t,e,i){return t.addEventListener(e,i,!1)}:function(t,e,i){return t.attachEvent("on"+e,i)}}(),unbindEvent:function(){return"removeEventListener"in window?function(t,e,i){return t.removeEventListener(e,i,!1)}:function(t,e,i){return t.detachEvent("on"+e,i)}}(),getInputValue:function(t){var e,i,n,r;if("checkbox"===t.type)return t.checked;if("select-multiple"===t.type){for(r=[],i=0,n=t.length;n>i;i++)e=t[i],e.selected&&r.push(e.value);return r}return t.value}},t.TypeParser=function(){function t(){}return t.types={primitive:0,keypath:1},t.parse=function(t){return/^'.*'$|^".*"$/.test(t)?{type:this.types.primitive,value:t.slice(1,-1)}:"true"===t?{type:this.types.primitive,value:!0}:"false"===t?{type:this.types.primitive,value:!1}:"null"===t?{type:this.types.primitive,value:null}:"undefined"===t?{type:this.types.primitive,value:void 0}:isNaN(Number(t))===!1?{type:this.types.primitive,value:Number(t)}:{type:this.types.keypath,value:t}},t}(),t.TextTemplateParser=function(){function t(){}return t.types={text:0,binding:1},t.parse=function(t,e){var i,n,r,s,o,u,h;for(u=[],s=t.length,i=0,n=0;s>n;){if(i=t.indexOf(e[0],n),0>i){u.push({type:this.types.text,value:t.slice(n)});break}if(i>0&&i>n&&u.push({type:this.types.text,value:t.slice(n,i)}),n=i+e[0].length,i=t.indexOf(e[1],n),0>i){o=t.slice(n-e[1].length),r=u[u.length-1],(null!=r?r.type:void 0)===this.types.text?r.value+=o:u.push({type:this.types.text,value:o});break}h=t.slice(n,i).trim(),u.push({type:this.types.binding,value:h}),n=i+e[1].length}return u},t}(),t.View=function(){function e(e,i,n){var s,o,u,h,l,a,p,d,c,f,b,v;for(this.els=e,this.models=i,null==n&&(n={}),this.update=r(this.update,this),this.publish=r(this.publish,this),this.sync=r(this.sync,this),this.unbind=r(this.unbind,this),this.bind=r(this.bind,this),this.select=r(this.select,this),this.build=r(this.build,this),this.componentRegExp=r(this.componentRegExp,this),this.bindingRegExp=r(this.bindingRegExp,this),this.options=r(this.options,this),this.els.jquery||this.els instanceof Array||(this.els=[this.els]),c=t.extensions,l=0,p=c.length;p>l;l++){if(o=c[l],this[o]={},n[o]){f=n[o];for(s in f)u=f[s],this[o][s]=u}b=t["public"][o];for(s in b)u=b[s],null==(h=this[o])[s]&&(h[s]=u)}for(v=t.options,a=0,d=v.length;d>a;a++)o=v[a],this[o]=n[o]||t["public"][o];this.build()}return e.prototype.options=function(){var e,i,n,r,s;for(i={},s=t.extensions.concat(t.options),n=0,r=s.length;r>n;n++)e=s[n],i[e]=this[e];return i},e.prototype.bindingRegExp=function(){return new RegExp("^"+this.prefix+"-")},e.prototype.componentRegExp=function(){return new RegExp("^"+this.prefix.toUpperCase()+"-")},e.prototype.build=function(){var e,i,n,r,s,o,u,h;for(this.bindings=[],e=this.bindingRegExp(),n=this.componentRegExp(),i=function(e){return function(i,n,r,s){var o,u,h,l,a,p,d;return a={},d=function(){var t,e,i,n;for(i=s.split("|"),n=[],t=0,e=i.length;e>t;t++)p=i[t],n.push(p.trim());return n}(),o=function(){var t,e,i,n;for(i=d.shift().split("<"),n=[],t=0,e=i.length;e>t;t++)u=i[t],n.push(u.trim());return n}(),l=o.shift(),a.formatters=d,(h=o.shift())&&(a.dependencies=h.split(/\s+/)),e.bindings.push(new t[i](e,n,r,l,a))}}(this),s=function(r){return function(o){var u,h,l,a,p,d,c,f,b,v,y,g,m,w,x,k,E,N,V,T,O,R,B,C,j,S,U,A;if(3===o.nodeType){if(b=t.TextTemplateParser,(d=r.templateDelimiters)&&(m=b.parse(o.data,d)).length&&(1!==m.length||m[0].type!==b.types.text)){for(k=0,T=m.length;T>k;k++)g=m[k],y=document.createTextNode(g.value),o.parentNode.insertBefore(y,o),1===g.type&&i("TextBinding",y,null,g.value);o.parentNode.removeChild(o)}}else if(1===o.nodeType)if(n.test(o.nodeName))w=o.nodeName.replace(n,"").toLowerCase(),r.bindings.push(new t.ComponentBinding(r,o,w));else{for(a="SCRIPT"===o.nodeName||"STYLE"===o.nodeName,C=o.attributes,E=0,O=C.length;O>E;E++)if(u=C[E],e.test(u.name)){if(w=u.name.replace(e,""),!(l=r.binders[w])){j=r.binders;for(c in j)x=j[c],"*"!==c&&-1!==c.indexOf("*")&&(v=new RegExp("^"+c.replace(/\*/g,".+")+"$"),v.test(w)&&(l=x))}l||(l=r.binders["*"]),l.block&&(a=!0,h=[u])}for(S=h||o.attributes,N=0,R=S.length;R>N;N++)u=S[N],e.test(u.name)&&(w=u.name.replace(e,""),i("Binding",o,w,u.value))}if(!a){for(U=function(){var t,e,i,n;for(i=o.childNodes,n=[],e=0,t=i.length;t>e;e++)f=i[e],n.push(f);return n}(),A=[],V=0,B=U.length;B>V;V++)p=U[V],A.push(s(p));return A}}}(this),h=this.els,o=0,u=h.length;u>o;o++)r=h[o],s(r);this.bindings.sort(function(t,e){return(e.binder.priority||0)-(t.binder.priority||0)})},e.prototype.select=function(t){var e,i,n,r,s;for(r=this.bindings,s=[],i=0,n=r.length;n>i;i++)e=r[i],t(e)&&s.push(e);return s},e.prototype.bind=function(){var t,e,i,n,r;for(n=this.bindings,r=[],e=0,i=n.length;i>e;e++)t=n[e],r.push(t.bind());return r},e.prototype.unbind=function(){var t,e,i,n,r;for(n=this.bindings,r=[],e=0,i=n.length;i>e;e++)t=n[e],r.push(t.unbind());return r},e.prototype.sync=function(){var t,e,i,n,r;for(n=this.bindings,r=[],e=0,i=n.length;i>e;e++)t=n[e],r.push(t.sync());return r},e.prototype.publish=function(){var t,e,i,n,r;for(n=this.select(function(t){return t.binder.publishes}),r=[],e=0,i=n.length;i>e;e++)t=n[e],r.push(t.publish());return r},e.prototype.update=function(t){var e,i,n,r,s,o,u;null==t&&(t={});for(i in t)n=t[i],this.models[i]=n;for(o=this.bindings,u=[],r=0,s=o.length;s>r;r++)e=o[r],u.push(e.update(t));return u},e}(),t.Binding=function(){function e(t,e,i,n,s){this.view=t,this.el=e,this.type=i,this.keypath=n,this.options=null!=s?s:{},this.getValue=r(this.getValue,this),this.update=r(this.update,this),this.unbind=r(this.unbind,this),this.bind=r(this.bind,this),this.publish=r(this.publish,this),this.sync=r(this.sync,this),this.set=r(this.set,this),this.eventHandler=r(this.eventHandler,this),this.formattedValue=r(this.formattedValue,this),this.parseTarget=r(this.parseTarget,this),this.observe=r(this.observe,this),this.setBinder=r(this.setBinder,this),this.formatters=this.options.formatters||[],this.dependencies=[],this.formatterObservers={},this.model=void 0,this.setBinder()}return e.prototype.setBinder=function(){var t,e,i,n;if(!(this.binder=this.view.binders[this.type])){n=this.view.binders;for(t in n)i=n[t],"*"!==t&&-1!==t.indexOf("*")&&(e=new RegExp("^"+t.replace(/\*/g,".+")+"$"),e.test(this.type)&&(this.binder=i,this.args=new RegExp("^"+t.replace(/\*/g,"(.+)")+"$").exec(this.type),this.args.shift()))}return this.binder||(this.binder=this.view.binders["*"]),this.binder instanceof Function?this.binder={routine:this.binder}:void 0},e.prototype.observe=function(e,i,n){return t.sightglass(e,i,n,{root:this.view.rootInterface,adapters:this.view.adapters})},e.prototype.parseTarget=function(){var e;return e=t.TypeParser.parse(this.keypath),0===e.type?this.value=e.value:(this.observer=this.observe(this.view.models,this.keypath,this.sync),this.model=this.observer.target)},e.prototype.formattedValue=function(e){var i,n,r,o,u,h,l,a,p,d,c,f,b,v;for(v=this.formatters,o=d=0,f=v.length;f>d;o=++d){for(u=v[o],r=u.match(/[^\s']+|'([^']|'[^\s])*'|"([^"]|"[^\s])*"/g),h=r.shift(),u=this.view.formatters[h],r=function(){var e,i,s;for(s=[],e=0,i=r.length;i>e;e++)n=r[e],s.push(t.TypeParser.parse(n));return s}(),a=[],i=c=0,b=r.length;b>c;i=++c)n=r[i],a.push(0===n.type?n.value:((p=this.formatterObservers)[o]||(p[o]={}),(l=this.formatterObservers[o][i])?void 0:(l=this.observe(this.view.models,n.value,this.sync),this.formatterObservers[o][i]=l),l.value()));(null!=u?u.read:void 0)instanceof Function?e=u.read.apply(u,[e].concat(s.call(a))):u instanceof Function&&(e=u.apply(null,[e].concat(s.call(a))))}return e},e.prototype.eventHandler=function(t){var e,i;return i=(e=this).view.handler,function(n){return i.call(t,this,n,e)}},e.prototype.set=function(t){var e;return t=t instanceof Function&&!this.binder["function"]?this.formattedValue(t.call(this.model)):this.formattedValue(t),null!=(e=this.binder.routine)?e.call(this,this.el,t):void 0},e.prototype.sync=function(){var t,e;return this.set(function(){var i,n,r,s,o,u,h;if(this.observer){if(this.model!==this.observer.target){for(o=this.dependencies,i=0,r=o.length;r>i;i++)e=o[i],e.unobserve();if(this.dependencies=[],null!=(this.model=this.observer.target)&&(null!=(u=this.options.dependencies)?u.length:void 0))for(h=this.options.dependencies,n=0,s=h.length;s>n;n++)t=h[n],e=this.observe(this.model,t,this.sync),this.dependencies.push(e)}return this.observer.value()}return this.value}.call(this))},e.prototype.publish=function(){var t,e,i,n,r,o,u,h,l;if(this.observer){for(n=this.getValue(this.el),u=this.formatters.slice(0).reverse(),r=0,o=u.length;o>r;r++)e=u[r],t=e.split(/\s+/),i=t.shift(),(null!=(h=this.view.formatters[i])?h.publish:void 0)&&(n=(l=this.view.formatters[i]).publish.apply(l,[n].concat(s.call(t))));return this.observer.setValue(n)}},e.prototype.bind=function(){var t,e,i,n,r,s,o;if(this.parseTarget(),null!=(r=this.binder.bind)&&r.call(this,this.el),null!=this.model&&(null!=(s=this.options.dependencies)?s.length:void 0))for(o=this.options.dependencies,i=0,n=o.length;n>i;i++)t=o[i],e=this.observe(this.model,t,this.sync),this.dependencies.push(e);return this.view.preloadData?this.sync():void 0},e.prototype.unbind=function(){var t,e,i,n,r,s,o,u,h,l;for(null!=(o=this.binder.unbind)&&o.call(this,this.el),null!=(u=this.observer)&&u.unobserve(),h=this.dependencies,r=0,s=h.length;s>r;r++)n=h[r],n.unobserve();this.dependencies=[],l=this.formatterObservers;for(i in l){e=l[i];for(t in e)n=e[t],n.unobserve()}return this.formatterObservers={}},e.prototype.update=function(t){var e,i;return null==t&&(t={}),this.model=null!=(e=this.observer)?e.target:void 0,this.unbind(),null!=(i=this.binder.update)&&i.call(this,t),this.bind()},e.prototype.getValue=function(e){return(this.binder.getValue||t.Util.getInputValue)(e)},e}(),t.ComponentBinding=function(e){function i(t,e,i){var n,s,o,u,l;for(this.view=t,this.el=e,this.type=i,this.unbind=r(this.unbind,this),this.bind=r(this.bind,this),this.update=r(this.update,this),this.locals=r(this.locals,this),this.component=this.view.components[this.type],this.attributes={},this.inflections={},u=this.el.attributes||[],s=0,o=u.length;o>s;s++)n=u[s],l=n.name,h.call(this.component.attributes,l)>=0?this.attributes[n.name]=n.value:this.inflections[n.name]=n.value}return u(i,e),i.prototype.sync=function(){},i.prototype.locals=function(t){var e,i,n,r,s,o,u,h,l;null==t&&(t=this.view.models),s={},h=this.inflections;for(i in h)for(e=h[i],l=e.split("."),o=0,u=l.length;u>o;o++)r=l[o],s[i]=(s[i]||t)[r];for(i in t)n=t[i],null==s[i]&&(s[i]=n);return s},i.prototype.update=function(t){var e;return null!=(e=this.componentView)?e.update(this.locals(t)):void 0},i.prototype.bind=function(){var e,i;return null!=this.componentView?null!=(i=this.componentView)?i.bind():void 0:(e=this.component.build.call(this.attributes),(this.componentView=new t.View(e,this.locals(),this.view.options)).bind(),this.el.parentNode.replaceChild(e,this.el))},i.prototype.unbind=function(){var t;return null!=(t=this.componentView)?t.unbind():void 0},i}(t.Binding),t.TextBinding=function(t){function e(t,e,i,n,s){this.view=t,this.el=e,this.type=i,this.keypath=n,this.options=null!=s?s:{},this.sync=r(this.sync,this),this.formatters=this.options.formatters||[],this.dependencies=[],this.formatterObservers={}}return u(e,t),e.prototype.binder={routine:function(t,e){return t.data=null!=e?e:""}},e.prototype.sync=function(){return e.__super__.sync.apply(this,arguments)},e}(t.Binding),t["public"].binders.text=function(t,e){return null!=t.textContent?t.textContent=null!=e?e:"":t.innerText=null!=e?e:""},t["public"].binders.html=function(t,e){return t.innerHTML=null!=e?e:""},t["public"].binders.show=function(t,e){return t.style.display=e?"":"none"},t["public"].binders.hide=function(t,e){return t.style.display=e?"none":""},t["public"].binders.enabled=function(t,e){return t.disabled=!e},t["public"].binders.disabled=function(t,e){return t.disabled=!!e},t["public"].binders.checked={publishes:!0,priority:2e3,bind:function(e){return t.Util.bindEvent(e,"change",this.publish)},unbind:function(e){return t.Util.unbindEvent(e,"change",this.publish)},routine:function(t,e){var i;return t.checked="radio"===t.type?(null!=(i=t.value)?i.toString():void 0)===(null!=e?e.toString():void 0):!!e}},t["public"].binders.unchecked={publishes:!0,priority:2e3,bind:function(e){return t.Util.bindEvent(e,"change",this.publish)},unbind:function(e){return t.Util.unbindEvent(e,"change",this.publish)},routine:function(t,e){var i;return t.checked="radio"===t.type?(null!=(i=t.value)?i.toString():void 0)!==(null!=e?e.toString():void 0):!e}},t["public"].binders.value={publishes:!0,priority:2e3,bind:function(e){return this.event="SELECT"===e.tagName?"change":"input",t.Util.bindEvent(e,this.event,this.publish)},unbind:function(e){return t.Util.unbindEvent(e,this.event,this.publish)},routine:function(t,e){var i,n,r,s,o,u,l;if(null!=window.jQuery){if(t=jQuery(t),(null!=e?e.toString():void 0)!==(null!=(s=t.val())?s.toString():void 0))return t.val(null!=e?e:"")}else if("select-multiple"===t.type){if(null!=e){for(l=[],n=0,r=t.length;r>n;n++)i=t[n],l.push(i.selected=(o=i.value,h.call(e,o)>=0));return l}}else if((null!=e?e.toString():void 0)!==(null!=(u=t.value)?u.toString():void 0))return t.value=null!=e?e:""}},t["public"].binders["if"]={block:!0,priority:3e3,bind:function(t){var e,i;return null==this.marker?(e=[this.view.prefix,this.type].join("-").replace("--","-"),i=t.getAttribute(e),this.marker=document.createComment(" rivets: "+this.type+" "+i+" "),this.bound=!1,t.removeAttribute(e),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(e,i){var n,r,s,o;if(!!i==!this.bound){if(i){s={},o=this.view.models;for(n in o)r=o[n],s[n]=r;return(this.nested||(this.nested=new t.View(e,s,this.view.options()))).bind(),this.marker.parentNode.insertBefore(e,this.marker.nextSibling),this.bound=!0}return e.parentNode.removeChild(e),this.nested.unbind(),this.bound=!1}},update:function(t){var e;return null!=(e=this.nested)?e.update(t):void 0}},t["public"].binders.unless={block:!0,priority:3e3,bind:function(e){return t["public"].binders["if"].bind.call(this,e)},unbind:function(){return t["public"].binders["if"].unbind.call(this)},routine:function(e,i){return t["public"].binders["if"].routine.call(this,e,!i)},update:function(e){return t["public"].binders["if"].update.call(this,e)}},t["public"].binders["on-*"]={"function":!0,priority:1e3,unbind:function(e){return this.handler?t.Util.unbindEvent(e,this.args[0],this.handler):void 0},routine:function(e,i){return this.handler&&t.Util.unbindEvent(e,this.args[0],this.handler),t.Util.bindEvent(e,this.args[0],this.handler=this.eventHandler(i))}},t["public"].binders["each-*"]={block:!0,priority:3e3,bind:function(t){var e,i,n,r,s;if(null==this.marker)e=[this.view.prefix,this.type].join("-").replace("--","-"),this.marker=document.createComment(" rivets: "+this.type+" "),this.iterated=[],t.removeAttribute(e),t.parentNode.insertBefore(this.marker,t),t.parentNode.removeChild(t);else for(s=this.iterated,n=0,r=s.length;r>n;n++)i=s[n],i.bind()},unbind:function(){var t,e,i,n,r;if(null!=this.iterated){for(n=this.iterated,r=[],e=0,i=n.length;i>e;e++)t=n[e],r.push(t.unbind());return r}},routine:function(e,i){var n,r,s,o,u,h,l,a,p,d,c,f,b,v,y,g,m,w,x,k,E;if(l=this.args[0],i=i||[],this.iterated.length>i.length)for(w=Array(this.iterated.length-i.length),f=0,y=w.length;y>f;f++)s=w[f],c=this.iterated.pop(),c.unbind(),this.marker.parentNode.removeChild(c.els[0]);for(o=b=0,g=i.length;g>b;o=++b)if(h=i[o],r={index:o},r[l]=h,null==this.iterated[o]){x=this.view.models;for(u in x)h=x[u],null==r[u]&&(r[u]=h);p=this.iterated.length?this.iterated[this.iterated.length-1].els[0]:this.marker,a=this.view.options(),a.preloadData=!0,d=e.cloneNode(!0),c=new t.View(d,r,a),c.bind(),this.iterated.push(c),this.marker.parentNode.insertBefore(d,p.nextSibling)}else this.iterated[o].models[l]!==h&&this.iterated[o].update(r);if("OPTION"===e.nodeName){for(k=this.view.bindings,E=[],v=0,m=k.length;m>v;v++)n=k[v],n.el===this.marker.parentNode&&"value"===n.type?E.push(n.sync()):E.push(void 0);return E}},update:function(t){var e,i,n,r,s,o,u,h;e={};for(i in t)n=t[i],i!==this.args[0]&&(e[i]=n);for(u=this.iterated,h=[],s=0,o=u.length;o>s;s++)r=u[s],h.push(r.update(e));return h}},t["public"].binders["class-*"]=function(t,e){var i;return i=" "+t.className+" ",!e==(-1!==i.indexOf(" "+this.args[0]+" "))?t.className=e?""+t.className+" "+this.args[0]:i.replace(" "+this.args[0]+" "," ").trim():void 0},t["public"].binders["*"]=function(t,e){return null!=e?t.setAttribute(this.type,e):t.removeAttribute(this.type)},t["public"].adapters["."]={id:"_rv",counter:0,weakmap:{},weakReference:function(t){var e;return t.hasOwnProperty(this.id)||(e=this.counter++,this.weakmap[e]={callbacks:{}},Object.defineProperty(t,this.id,{value:e})),this.weakmap[t[this.id]]},stubFunction:function(t,e){var i,n,r;return n=t[e],i=this.weakReference(t),r=this.weakmap,t[e]=function(){var e,s,o,u,h,l,a,p,d,c;u=n.apply(t,arguments),a=i.pointers;for(o in a)for(s=a[o],c=null!=(p=null!=(d=r[o])?d.callbacks[s]:void 0)?p:[],h=0,l=c.length;l>h;h++)e=c[h],e();return u}},observeMutations:function(t,e,i){var n,r,s,o,u,l;if(Array.isArray(t)){if(s=this.weakReference(t),null==s.pointers)for(s.pointers={},r=["push","pop","shift","unshift","sort","reverse","splice"],u=0,l=r.length;l>u;u++)n=r[u],this.stubFunction(t,n);if(null==(o=s.pointers)[e]&&(o[e]=[]),h.call(s.pointers[e],i)<0)return s.pointers[e].push(i)}},unobserveMutations:function(t,e,i){var n,r,s;return Array.isArray(t&&null!=t[this.id])&&(r=null!=(s=this.weakReference(t).pointers)?s[e]:void 0)&&(n=r.indexOf(i),n>=0)?r.splice(n,1):void 0},observe:function(t,e,i){var n,r;return n=this.weakReference(t).callbacks,null==n[e]&&(n[e]=[],r=t[e],Object.defineProperty(t,e,{enumerable:!0,get:function(){return r},set:function(s){return function(o){var u,l,a;if(o!==r){for(r=o,a=n[e].slice(),u=0,l=a.length;l>u;u++)i=a[u],h.call(n[e],i)>=0&&i();return s.observeMutations(o,t[s.id],e)}}}(this)})),h.call(n[e],i)<0&&n[e].push(i),this.observeMutations(t[e],t[this.id],e)},unobserve:function(t,e,i){var n,r;return n=this.weakmap[t[this.id]].callbacks[e],r=n.indexOf(i),r>=0&&n.splice(r,1),this.unobserveMutations(t[e],t[this.id],e)},get:function(t,e){return t[e]},set:function(t,e,i){return t[e]=i}},t.factory=function(e){return t.sightglass=e,t["public"]._=t,t["public"]},"object"==typeof("undefined"!=typeof module&&null!==module?module.exports:void 0)?module.exports=t.factory(require("sightglass")):"function"==typeof define&&define.amd?define(["sightglass"],function(e){return this.rivets=t.factory(e)}):this.rivets=t.factory(sightglass)}).call(this); \ No newline at end of file diff --git a/ajax/libs/rivets/0.7.0-rc3/rivets.js b/ajax/libs/rivets/0.7.0-rc3/rivets.js new file mode 100644 index 000000000..81f7da5f7 --- /dev/null +++ b/ajax/libs/rivets/0.7.0-rc3/rivets.js @@ -0,0 +1,1268 @@ +// Rivets.js +// version: 0.7.0-rc3 +// author: Michael Richards +// license: MIT +(function() { + var Rivets, bindMethod, unbindMethod, _ref, + __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + __slice = [].slice, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + __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; }; + + Rivets = { + options: ['prefix', 'templateDelimiters', 'rootInterface', 'preloadData', 'handler'], + extensions: ['binders', 'formatters', 'components', 'adapters'], + "public": { + binders: {}, + components: {}, + formatters: {}, + adapters: {}, + prefix: 'rv', + templateDelimiters: ['{', '}'], + rootInterface: '.', + preloadData: true, + handler: function(context, ev, binding) { + return this.call(context, ev, binding.view.models); + }, + configure: function(options) { + var descriptor, key, option, value; + if (options == null) { + options = {}; + } + for (option in options) { + value = options[option]; + if (option === 'binders' || option === 'components' || option === 'formatters' || option === 'adapters') { + for (key in value) { + descriptor = value[key]; + Rivets[option][key] = descriptor; + } + } else { + Rivets["public"][option] = value; + } + } + }, + bind: function(el, models, options) { + var view; + if (models == null) { + models = {}; + } + if (options == null) { + options = {}; + } + view = new Rivets.View(el, models, options); + view.bind(); + return view; + } + } + }; + + if (window['jQuery'] || window['$']) { + _ref = 'on' in jQuery.prototype ? ['on', 'off'] : ['bind', 'unbind'], bindMethod = _ref[0], unbindMethod = _ref[1]; + Rivets.Util = { + bindEvent: function(el, event, handler) { + return jQuery(el)[bindMethod](event, handler); + }, + unbindEvent: function(el, event, handler) { + return jQuery(el)[unbindMethod](event, handler); + }, + getInputValue: function(el) { + var $el; + $el = jQuery(el); + if ($el.attr('type') === 'checkbox') { + return $el.is(':checked'); + } else { + return $el.val(); + } + } + }; + } else { + Rivets.Util = { + bindEvent: (function() { + if ('addEventListener' in window) { + return function(el, event, handler) { + return el.addEventListener(event, handler, false); + }; + } + return function(el, event, handler) { + return el.attachEvent('on' + event, handler); + }; + })(), + unbindEvent: (function() { + if ('removeEventListener' in window) { + return function(el, event, handler) { + return el.removeEventListener(event, handler, false); + }; + } + return function(el, event, handler) { + return el.detachEvent('on' + event, handler); + }; + })(), + getInputValue: function(el) { + var o, _i, _len, _results; + if (el.type === 'checkbox') { + return el.checked; + } else if (el.type === 'select-multiple') { + _results = []; + for (_i = 0, _len = el.length; _i < _len; _i++) { + o = el[_i]; + if (o.selected) { + _results.push(o.value); + } + } + return _results; + } else { + return el.value; + } + } + }; + } + + Rivets.TypeParser = (function() { + function TypeParser() {} + + TypeParser.types = { + primitive: 0, + keypath: 1 + }; + + TypeParser.parse = function(string) { + if (/^'.*'$|^".*"$/.test(string)) { + return { + type: this.types.primitive, + value: string.slice(1, -1) + }; + } else if (string === 'true') { + return { + type: this.types.primitive, + value: true + }; + } else if (string === 'false') { + return { + type: this.types.primitive, + value: false + }; + } else if (string === 'null') { + return { + type: this.types.primitive, + value: null + }; + } else if (string === 'undefined') { + return { + type: this.types.primitive, + value: void 0 + }; + } else if (isNaN(Number(string)) === false) { + return { + type: this.types.primitive, + value: Number(string) + }; + } else { + return { + type: this.types.keypath, + value: string + }; + } + }; + + return TypeParser; + + })(); + + Rivets.TextTemplateParser = (function() { + function TextTemplateParser() {} + + TextTemplateParser.types = { + text: 0, + binding: 1 + }; + + TextTemplateParser.parse = function(template, delimiters) { + var index, lastIndex, lastToken, length, substring, tokens, value; + tokens = []; + length = template.length; + index = 0; + lastIndex = 0; + while (lastIndex < length) { + index = template.indexOf(delimiters[0], lastIndex); + if (index < 0) { + tokens.push({ + type: this.types.text, + value: template.slice(lastIndex) + }); + break; + } else { + if (index > 0 && lastIndex < index) { + tokens.push({ + type: this.types.text, + value: template.slice(lastIndex, index) + }); + } + lastIndex = index + delimiters[0].length; + index = template.indexOf(delimiters[1], lastIndex); + if (index < 0) { + substring = template.slice(lastIndex - delimiters[1].length); + lastToken = tokens[tokens.length - 1]; + if ((lastToken != null ? lastToken.type : void 0) === this.types.text) { + lastToken.value += substring; + } else { + tokens.push({ + type: this.types.text, + value: substring + }); + } + break; + } + value = template.slice(lastIndex, index).trim(); + tokens.push({ + type: this.types.binding, + value: value + }); + lastIndex = index + delimiters[1].length; + } + } + return tokens; + }; + + return TextTemplateParser; + + })(); + + Rivets.View = (function() { + function View(els, models, options) { + var k, option, v, _base, _i, _j, _len, _len1, _ref1, _ref2, _ref3, _ref4; + this.els = els; + this.models = models; + if (options == null) { + options = {}; + } + this.update = __bind(this.update, this); + this.publish = __bind(this.publish, this); + this.sync = __bind(this.sync, this); + this.unbind = __bind(this.unbind, this); + this.bind = __bind(this.bind, this); + this.select = __bind(this.select, this); + this.build = __bind(this.build, this); + this.componentRegExp = __bind(this.componentRegExp, this); + this.bindingRegExp = __bind(this.bindingRegExp, this); + this.options = __bind(this.options, this); + if (!(this.els.jquery || this.els instanceof Array)) { + this.els = [this.els]; + } + _ref1 = Rivets.extensions; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + option = _ref1[_i]; + this[option] = {}; + if (options[option]) { + _ref2 = options[option]; + for (k in _ref2) { + v = _ref2[k]; + this[option][k] = v; + } + } + _ref3 = Rivets["public"][option]; + for (k in _ref3) { + v = _ref3[k]; + if ((_base = this[option])[k] == null) { + _base[k] = v; + } + } + } + _ref4 = Rivets.options; + for (_j = 0, _len1 = _ref4.length; _j < _len1; _j++) { + option = _ref4[_j]; + this[option] = options[option] || Rivets["public"][option]; + } + this.build(); + } + + View.prototype.options = function() { + var option, options, _i, _len, _ref1; + options = {}; + _ref1 = Rivets.extensions.concat(Rivets.options); + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + option = _ref1[_i]; + options[option] = this[option]; + } + return options; + }; + + View.prototype.bindingRegExp = function() { + return new RegExp("^" + this.prefix + "-"); + }; + + View.prototype.componentRegExp = function() { + return new RegExp("^" + (this.prefix.toUpperCase()) + "-"); + }; + + View.prototype.build = function() { + var bindingRegExp, buildBinding, componentRegExp, el, parse, _i, _len, _ref1; + this.bindings = []; + bindingRegExp = this.bindingRegExp(); + componentRegExp = this.componentRegExp(); + buildBinding = (function(_this) { + return function(binding, node, type, declaration) { + var context, ctx, dependencies, keypath, options, pipe, pipes; + options = {}; + pipes = (function() { + var _i, _len, _ref1, _results; + _ref1 = declaration.split('|'); + _results = []; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + pipe = _ref1[_i]; + _results.push(pipe.trim()); + } + return _results; + })(); + context = (function() { + var _i, _len, _ref1, _results; + _ref1 = pipes.shift().split('<'); + _results = []; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + ctx = _ref1[_i]; + _results.push(ctx.trim()); + } + return _results; + })(); + keypath = context.shift(); + options.formatters = pipes; + if (dependencies = context.shift()) { + options.dependencies = dependencies.split(/\s+/); + } + return _this.bindings.push(new Rivets[binding](_this, node, type, keypath, options)); + }; + })(this); + parse = (function(_this) { + return function(node) { + var attribute, attributes, binder, block, childNode, delimiters, identifier, n, parser, regexp, text, token, tokens, type, value, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref1, _ref2, _ref3, _ref4, _results; + if (node.nodeType === 3) { + parser = Rivets.TextTemplateParser; + if (delimiters = _this.templateDelimiters) { + if ((tokens = parser.parse(node.data, delimiters)).length) { + if (!(tokens.length === 1 && tokens[0].type === parser.types.text)) { + for (_i = 0, _len = tokens.length; _i < _len; _i++) { + token = tokens[_i]; + text = document.createTextNode(token.value); + node.parentNode.insertBefore(text, node); + if (token.type === 1) { + buildBinding('TextBinding', text, null, token.value); + } + } + node.parentNode.removeChild(node); + } + } + } + } else if (node.nodeType === 1) { + if (componentRegExp.test(node.nodeName)) { + type = node.nodeName.replace(componentRegExp, '').toLowerCase(); + _this.bindings.push(new Rivets.ComponentBinding(_this, node, type)); + } else { + block = node.nodeName === 'SCRIPT' || node.nodeName === 'STYLE'; + _ref1 = node.attributes; + for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { + attribute = _ref1[_j]; + if (bindingRegExp.test(attribute.name)) { + type = attribute.name.replace(bindingRegExp, ''); + if (!(binder = _this.binders[type])) { + _ref2 = _this.binders; + for (identifier in _ref2) { + value = _ref2[identifier]; + if (identifier !== '*' && identifier.indexOf('*') !== -1) { + regexp = new RegExp("^" + (identifier.replace(/\*/g, '.+')) + "$"); + if (regexp.test(type)) { + binder = value; + } + } + } + } + binder || (binder = _this.binders['*']); + if (binder.block) { + block = true; + attributes = [attribute]; + } + } + } + _ref3 = attributes || node.attributes; + for (_k = 0, _len2 = _ref3.length; _k < _len2; _k++) { + attribute = _ref3[_k]; + if (bindingRegExp.test(attribute.name)) { + type = attribute.name.replace(bindingRegExp, ''); + buildBinding('Binding', node, type, attribute.value); + } + } + } + } + if (!block) { + _ref4 = (function() { + var _len3, _m, _ref4, _results1; + _ref4 = node.childNodes; + _results1 = []; + for (_m = 0, _len3 = _ref4.length; _m < _len3; _m++) { + n = _ref4[_m]; + _results1.push(n); + } + return _results1; + })(); + _results = []; + for (_l = 0, _len3 = _ref4.length; _l < _len3; _l++) { + childNode = _ref4[_l]; + _results.push(parse(childNode)); + } + return _results; + } + }; + })(this); + _ref1 = this.els; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + el = _ref1[_i]; + parse(el); + } + this.bindings.sort(function(a, b) { + return (b.binder.priority || 0) - (a.binder.priority || 0); + }); + }; + + View.prototype.select = function(fn) { + var binding, _i, _len, _ref1, _results; + _ref1 = this.bindings; + _results = []; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + binding = _ref1[_i]; + if (fn(binding)) { + _results.push(binding); + } + } + return _results; + }; + + View.prototype.bind = function() { + var binding, _i, _len, _ref1, _results; + _ref1 = this.bindings; + _results = []; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + binding = _ref1[_i]; + _results.push(binding.bind()); + } + return _results; + }; + + View.prototype.unbind = function() { + var binding, _i, _len, _ref1, _results; + _ref1 = this.bindings; + _results = []; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + binding = _ref1[_i]; + _results.push(binding.unbind()); + } + return _results; + }; + + View.prototype.sync = function() { + var binding, _i, _len, _ref1, _results; + _ref1 = this.bindings; + _results = []; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + binding = _ref1[_i]; + _results.push(binding.sync()); + } + return _results; + }; + + View.prototype.publish = function() { + var binding, _i, _len, _ref1, _results; + _ref1 = this.select(function(b) { + return b.binder.publishes; + }); + _results = []; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + binding = _ref1[_i]; + _results.push(binding.publish()); + } + return _results; + }; + + View.prototype.update = function(models) { + var binding, key, model, _i, _len, _ref1, _results; + if (models == null) { + models = {}; + } + for (key in models) { + model = models[key]; + this.models[key] = model; + } + _ref1 = this.bindings; + _results = []; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + binding = _ref1[_i]; + _results.push(binding.update(models)); + } + return _results; + }; + + return View; + + })(); + + Rivets.Binding = (function() { + function Binding(view, el, type, keypath, options) { + this.view = view; + this.el = el; + this.type = type; + this.keypath = keypath; + this.options = options != null ? options : {}; + this.getValue = __bind(this.getValue, this); + this.update = __bind(this.update, this); + this.unbind = __bind(this.unbind, this); + this.bind = __bind(this.bind, this); + this.publish = __bind(this.publish, this); + this.sync = __bind(this.sync, this); + this.set = __bind(this.set, this); + this.eventHandler = __bind(this.eventHandler, this); + this.formattedValue = __bind(this.formattedValue, this); + this.parseTarget = __bind(this.parseTarget, this); + this.observe = __bind(this.observe, this); + this.setBinder = __bind(this.setBinder, this); + this.formatters = this.options.formatters || []; + this.dependencies = []; + this.formatterObservers = {}; + this.model = void 0; + this.setBinder(); + } + + Binding.prototype.setBinder = function() { + var identifier, regexp, value, _ref1; + if (!(this.binder = this.view.binders[this.type])) { + _ref1 = this.view.binders; + for (identifier in _ref1) { + value = _ref1[identifier]; + if (identifier !== '*' && identifier.indexOf('*') !== -1) { + regexp = new RegExp("^" + (identifier.replace(/\*/g, '.+')) + "$"); + if (regexp.test(this.type)) { + this.binder = value; + this.args = new RegExp("^" + (identifier.replace(/\*/g, '(.+)')) + "$").exec(this.type); + this.args.shift(); + } + } + } + } + this.binder || (this.binder = this.view.binders['*']); + if (this.binder instanceof Function) { + return this.binder = { + routine: this.binder + }; + } + }; + + Binding.prototype.observe = function(obj, keypath, callback) { + return Rivets.sightglass(obj, keypath, callback, { + root: this.view.rootInterface, + adapters: this.view.adapters + }); + }; + + Binding.prototype.parseTarget = function() { + var token; + token = Rivets.TypeParser.parse(this.keypath); + if (token.type === 0) { + return this.value = token.value; + } else { + this.observer = this.observe(this.view.models, this.keypath, this.sync); + return this.model = this.observer.target; + } + }; + + Binding.prototype.formattedValue = function(value) { + var ai, arg, args, fi, formatter, id, observer, processedArgs, _base, _i, _j, _len, _len1, _ref1; + _ref1 = this.formatters; + for (fi = _i = 0, _len = _ref1.length; _i < _len; fi = ++_i) { + formatter = _ref1[fi]; + args = formatter.match(/[^\s']+|'([^']|'[^\s])*'|"([^"]|"[^\s])*"/g); + id = args.shift(); + formatter = this.view.formatters[id]; + args = (function() { + var _j, _len1, _results; + _results = []; + for (_j = 0, _len1 = args.length; _j < _len1; _j++) { + arg = args[_j]; + _results.push(Rivets.TypeParser.parse(arg)); + } + return _results; + })(); + processedArgs = []; + for (ai = _j = 0, _len1 = args.length; _j < _len1; ai = ++_j) { + arg = args[ai]; + processedArgs.push(arg.type === 0 ? arg.value : ((_base = this.formatterObservers)[fi] || (_base[fi] = {}), !(observer = this.formatterObservers[fi][ai]) ? (observer = this.observe(this.view.models, arg.value, this.sync), this.formatterObservers[fi][ai] = observer) : void 0, observer.value())); + } + if ((formatter != null ? formatter.read : void 0) instanceof Function) { + value = formatter.read.apply(formatter, [value].concat(__slice.call(processedArgs))); + } else if (formatter instanceof Function) { + value = formatter.apply(null, [value].concat(__slice.call(processedArgs))); + } + } + return value; + }; + + Binding.prototype.eventHandler = function(fn) { + var binding, handler; + handler = (binding = this).view.handler; + return function(ev) { + return handler.call(fn, this, ev, binding); + }; + }; + + Binding.prototype.set = function(value) { + var _ref1; + value = value instanceof Function && !this.binder["function"] ? this.formattedValue(value.call(this.model)) : this.formattedValue(value); + return (_ref1 = this.binder.routine) != null ? _ref1.call(this, this.el, value) : void 0; + }; + + Binding.prototype.sync = function() { + var dependency, observer; + return this.set((function() { + var _i, _j, _len, _len1, _ref1, _ref2, _ref3; + if (this.observer) { + if (this.model !== this.observer.target) { + _ref1 = this.dependencies; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + observer = _ref1[_i]; + observer.unobserve(); + } + this.dependencies = []; + if (((this.model = this.observer.target) != null) && ((_ref2 = this.options.dependencies) != null ? _ref2.length : void 0)) { + _ref3 = this.options.dependencies; + for (_j = 0, _len1 = _ref3.length; _j < _len1; _j++) { + dependency = _ref3[_j]; + observer = this.observe(this.model, dependency, this.sync); + this.dependencies.push(observer); + } + } + } + return this.observer.value(); + } else { + return this.value; + } + }).call(this)); + }; + + Binding.prototype.publish = function() { + var args, formatter, id, value, _i, _len, _ref1, _ref2, _ref3; + if (this.observer) { + value = this.getValue(this.el); + _ref1 = this.formatters.slice(0).reverse(); + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + formatter = _ref1[_i]; + args = formatter.split(/\s+/); + id = args.shift(); + if ((_ref2 = this.view.formatters[id]) != null ? _ref2.publish : void 0) { + value = (_ref3 = this.view.formatters[id]).publish.apply(_ref3, [value].concat(__slice.call(args))); + } + } + return this.observer.setValue(value); + } + }; + + Binding.prototype.bind = function() { + var dependency, observer, _i, _len, _ref1, _ref2, _ref3; + this.parseTarget(); + if ((_ref1 = this.binder.bind) != null) { + _ref1.call(this, this.el); + } + if ((this.model != null) && ((_ref2 = this.options.dependencies) != null ? _ref2.length : void 0)) { + _ref3 = this.options.dependencies; + for (_i = 0, _len = _ref3.length; _i < _len; _i++) { + dependency = _ref3[_i]; + observer = this.observe(this.model, dependency, this.sync); + this.dependencies.push(observer); + } + } + if (this.view.preloadData) { + return this.sync(); + } + }; + + Binding.prototype.unbind = function() { + var ai, args, fi, observer, _i, _len, _ref1, _ref2, _ref3, _ref4; + if ((_ref1 = this.binder.unbind) != null) { + _ref1.call(this, this.el); + } + if ((_ref2 = this.observer) != null) { + _ref2.unobserve(); + } + _ref3 = this.dependencies; + for (_i = 0, _len = _ref3.length; _i < _len; _i++) { + observer = _ref3[_i]; + observer.unobserve(); + } + this.dependencies = []; + _ref4 = this.formatterObservers; + for (fi in _ref4) { + args = _ref4[fi]; + for (ai in args) { + observer = args[ai]; + observer.unobserve(); + } + } + return this.formatterObservers = {}; + }; + + Binding.prototype.update = function(models) { + var _ref1, _ref2; + if (models == null) { + models = {}; + } + this.model = (_ref1 = this.observer) != null ? _ref1.target : void 0; + this.unbind(); + if ((_ref2 = this.binder.update) != null) { + _ref2.call(this, models); + } + return this.bind(); + }; + + Binding.prototype.getValue = function(el) { + return (this.binder.getValue || Rivets.Util.getInputValue)(el); + }; + + return Binding; + + })(); + + Rivets.ComponentBinding = (function(_super) { + __extends(ComponentBinding, _super); + + function ComponentBinding(view, el, type) { + var attribute, _i, _len, _ref1, _ref2; + this.view = view; + this.el = el; + this.type = type; + this.unbind = __bind(this.unbind, this); + this.bind = __bind(this.bind, this); + this.update = __bind(this.update, this); + this.locals = __bind(this.locals, this); + this.component = this.view.components[this.type]; + this.attributes = {}; + this.inflections = {}; + _ref1 = this.el.attributes || []; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + attribute = _ref1[_i]; + if (_ref2 = attribute.name, __indexOf.call(this.component.attributes, _ref2) >= 0) { + this.attributes[attribute.name] = attribute.value; + } else { + this.inflections[attribute.name] = attribute.value; + } + } + } + + ComponentBinding.prototype.sync = function() {}; + + ComponentBinding.prototype.locals = function(models) { + var inverse, key, model, path, result, _i, _len, _ref1, _ref2; + if (models == null) { + models = this.view.models; + } + result = {}; + _ref1 = this.inflections; + for (key in _ref1) { + inverse = _ref1[key]; + _ref2 = inverse.split('.'); + for (_i = 0, _len = _ref2.length; _i < _len; _i++) { + path = _ref2[_i]; + result[key] = (result[key] || models)[path]; + } + } + for (key in models) { + model = models[key]; + if (result[key] == null) { + result[key] = model; + } + } + return result; + }; + + ComponentBinding.prototype.update = function(models) { + var _ref1; + return (_ref1 = this.componentView) != null ? _ref1.update(this.locals(models)) : void 0; + }; + + ComponentBinding.prototype.bind = function() { + var el, _ref1; + if (this.componentView != null) { + return (_ref1 = this.componentView) != null ? _ref1.bind() : void 0; + } else { + el = this.component.build.call(this.attributes); + (this.componentView = new Rivets.View(el, this.locals(), this.view.options)).bind(); + return this.el.parentNode.replaceChild(el, this.el); + } + }; + + ComponentBinding.prototype.unbind = function() { + var _ref1; + return (_ref1 = this.componentView) != null ? _ref1.unbind() : void 0; + }; + + return ComponentBinding; + + })(Rivets.Binding); + + Rivets.TextBinding = (function(_super) { + __extends(TextBinding, _super); + + function TextBinding(view, el, type, keypath, options) { + this.view = view; + this.el = el; + this.type = type; + this.keypath = keypath; + this.options = options != null ? options : {}; + this.sync = __bind(this.sync, this); + this.formatters = this.options.formatters || []; + this.dependencies = []; + this.formatterObservers = {}; + } + + TextBinding.prototype.binder = { + routine: function(node, value) { + return node.data = value != null ? value : ''; + } + }; + + TextBinding.prototype.sync = function() { + return TextBinding.__super__.sync.apply(this, arguments); + }; + + return TextBinding; + + })(Rivets.Binding); + + Rivets["public"].binders.text = function(el, value) { + if (el.textContent != null) { + return el.textContent = value != null ? value : ''; + } else { + return el.innerText = value != null ? value : ''; + } + }; + + Rivets["public"].binders.html = function(el, value) { + return el.innerHTML = value != null ? value : ''; + }; + + Rivets["public"].binders.show = function(el, value) { + return el.style.display = value ? '' : 'none'; + }; + + Rivets["public"].binders.hide = function(el, value) { + return el.style.display = value ? 'none' : ''; + }; + + Rivets["public"].binders.enabled = function(el, value) { + return el.disabled = !value; + }; + + Rivets["public"].binders.disabled = function(el, value) { + return el.disabled = !!value; + }; + + Rivets["public"].binders.checked = { + publishes: true, + priority: 2000, + bind: function(el) { + return Rivets.Util.bindEvent(el, 'change', this.publish); + }, + unbind: function(el) { + return Rivets.Util.unbindEvent(el, 'change', this.publish); + }, + routine: function(el, value) { + var _ref1; + if (el.type === 'radio') { + return el.checked = ((_ref1 = el.value) != null ? _ref1.toString() : void 0) === (value != null ? value.toString() : void 0); + } else { + return el.checked = !!value; + } + } + }; + + Rivets["public"].binders.unchecked = { + publishes: true, + priority: 2000, + bind: function(el) { + return Rivets.Util.bindEvent(el, 'change', this.publish); + }, + unbind: function(el) { + return Rivets.Util.unbindEvent(el, 'change', this.publish); + }, + routine: function(el, value) { + var _ref1; + if (el.type === 'radio') { + return el.checked = ((_ref1 = el.value) != null ? _ref1.toString() : void 0) !== (value != null ? value.toString() : void 0); + } else { + return el.checked = !value; + } + } + }; + + Rivets["public"].binders.value = { + publishes: true, + priority: 2000, + bind: function(el) { + this.event = el.tagName === 'SELECT' ? 'change' : 'input'; + return Rivets.Util.bindEvent(el, this.event, this.publish); + }, + unbind: function(el) { + return Rivets.Util.unbindEvent(el, this.event, this.publish); + }, + routine: function(el, value) { + var o, _i, _len, _ref1, _ref2, _ref3, _results; + if (window.jQuery != null) { + el = jQuery(el); + if ((value != null ? value.toString() : void 0) !== ((_ref1 = el.val()) != null ? _ref1.toString() : void 0)) { + return el.val(value != null ? value : ''); + } + } else { + if (el.type === 'select-multiple') { + if (value != null) { + _results = []; + for (_i = 0, _len = el.length; _i < _len; _i++) { + o = el[_i]; + _results.push(o.selected = (_ref2 = o.value, __indexOf.call(value, _ref2) >= 0)); + } + return _results; + } + } else if ((value != null ? value.toString() : void 0) !== ((_ref3 = el.value) != null ? _ref3.toString() : void 0)) { + return el.value = value != null ? value : ''; + } + } + } + }; + + Rivets["public"].binders["if"] = { + block: true, + priority: 3000, + bind: function(el) { + var attr, declaration; + if (this.marker == null) { + attr = [this.view.prefix, this.type].join('-').replace('--', '-'); + declaration = el.getAttribute(attr); + this.marker = document.createComment(" rivets: " + this.type + " " + declaration + " "); + this.bound = false; + el.removeAttribute(attr); + el.parentNode.insertBefore(this.marker, el); + return el.parentNode.removeChild(el); + } + }, + unbind: function() { + var _ref1; + return (_ref1 = this.nested) != null ? _ref1.unbind() : void 0; + }, + routine: function(el, value) { + var key, model, models, _ref1; + if (!!value === !this.bound) { + if (value) { + models = {}; + _ref1 = this.view.models; + for (key in _ref1) { + model = _ref1[key]; + models[key] = model; + } + (this.nested || (this.nested = new Rivets.View(el, models, this.view.options()))).bind(); + this.marker.parentNode.insertBefore(el, this.marker.nextSibling); + return this.bound = true; + } else { + el.parentNode.removeChild(el); + this.nested.unbind(); + return this.bound = false; + } + } + }, + update: function(models) { + var _ref1; + return (_ref1 = this.nested) != null ? _ref1.update(models) : void 0; + } + }; + + Rivets["public"].binders.unless = { + block: true, + priority: 3000, + bind: function(el) { + return Rivets["public"].binders["if"].bind.call(this, el); + }, + unbind: function() { + return Rivets["public"].binders["if"].unbind.call(this); + }, + routine: function(el, value) { + return Rivets["public"].binders["if"].routine.call(this, el, !value); + }, + update: function(models) { + return Rivets["public"].binders["if"].update.call(this, models); + } + }; + + Rivets["public"].binders['on-*'] = { + "function": true, + priority: 1000, + unbind: function(el) { + if (this.handler) { + return Rivets.Util.unbindEvent(el, this.args[0], this.handler); + } + }, + routine: function(el, value) { + if (this.handler) { + Rivets.Util.unbindEvent(el, this.args[0], this.handler); + } + return Rivets.Util.bindEvent(el, this.args[0], this.handler = this.eventHandler(value)); + } + }; + + Rivets["public"].binders['each-*'] = { + block: true, + priority: 3000, + bind: function(el) { + var attr, view, _i, _len, _ref1; + if (this.marker == null) { + attr = [this.view.prefix, this.type].join('-').replace('--', '-'); + this.marker = document.createComment(" rivets: " + this.type + " "); + this.iterated = []; + el.removeAttribute(attr); + el.parentNode.insertBefore(this.marker, el); + el.parentNode.removeChild(el); + } else { + _ref1 = this.iterated; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + view = _ref1[_i]; + view.bind(); + } + } + }, + unbind: function(el) { + var view, _i, _len, _ref1, _results; + if (this.iterated != null) { + _ref1 = this.iterated; + _results = []; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + view = _ref1[_i]; + _results.push(view.unbind()); + } + return _results; + } + }, + routine: function(el, collection) { + var binding, data, i, index, key, model, modelName, options, previous, template, view, _i, _j, _k, _len, _len1, _len2, _ref1, _ref2, _ref3, _results; + modelName = this.args[0]; + collection = collection || []; + if (this.iterated.length > collection.length) { + _ref1 = Array(this.iterated.length - collection.length); + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + i = _ref1[_i]; + view = this.iterated.pop(); + view.unbind(); + this.marker.parentNode.removeChild(view.els[0]); + } + } + for (index = _j = 0, _len1 = collection.length; _j < _len1; index = ++_j) { + model = collection[index]; + data = { + index: index + }; + data[modelName] = model; + if (this.iterated[index] == null) { + _ref2 = this.view.models; + for (key in _ref2) { + model = _ref2[key]; + if (data[key] == null) { + data[key] = model; + } + } + previous = this.iterated.length ? this.iterated[this.iterated.length - 1].els[0] : this.marker; + options = this.view.options(); + options.preloadData = true; + template = el.cloneNode(true); + view = new Rivets.View(template, data, options); + view.bind(); + this.iterated.push(view); + this.marker.parentNode.insertBefore(template, previous.nextSibling); + } else if (this.iterated[index].models[modelName] !== model) { + this.iterated[index].update(data); + } + } + if (el.nodeName === 'OPTION') { + _ref3 = this.view.bindings; + _results = []; + for (_k = 0, _len2 = _ref3.length; _k < _len2; _k++) { + binding = _ref3[_k]; + if (binding.el === this.marker.parentNode && binding.type === 'value') { + _results.push(binding.sync()); + } else { + _results.push(void 0); + } + } + return _results; + } + }, + update: function(models) { + var data, key, model, view, _i, _len, _ref1, _results; + data = {}; + for (key in models) { + model = models[key]; + if (key !== this.args[0]) { + data[key] = model; + } + } + _ref1 = this.iterated; + _results = []; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + view = _ref1[_i]; + _results.push(view.update(data)); + } + return _results; + } + }; + + Rivets["public"].binders['class-*'] = function(el, value) { + var elClass; + elClass = " " + el.className + " "; + if (!value === (elClass.indexOf(" " + this.args[0] + " ") !== -1)) { + return el.className = value ? "" + el.className + " " + this.args[0] : elClass.replace(" " + this.args[0] + " ", ' ').trim(); + } + }; + + Rivets["public"].binders['*'] = function(el, value) { + if (value != null) { + return el.setAttribute(this.type, value); + } else { + return el.removeAttribute(this.type); + } + }; + + Rivets["public"].adapters['.'] = { + id: '_rv', + counter: 0, + weakmap: {}, + weakReference: function(obj) { + var id; + if (!obj.hasOwnProperty(this.id)) { + id = this.counter++; + this.weakmap[id] = { + callbacks: {} + }; + Object.defineProperty(obj, this.id, { + value: id + }); + } + return this.weakmap[obj[this.id]]; + }, + stubFunction: function(obj, fn) { + var map, original, weakmap; + original = obj[fn]; + map = this.weakReference(obj); + weakmap = this.weakmap; + return obj[fn] = function() { + var callback, k, r, response, _i, _len, _ref1, _ref2, _ref3, _ref4; + response = original.apply(obj, arguments); + _ref1 = map.pointers; + for (r in _ref1) { + k = _ref1[r]; + _ref4 = (_ref2 = (_ref3 = weakmap[r]) != null ? _ref3.callbacks[k] : void 0) != null ? _ref2 : []; + for (_i = 0, _len = _ref4.length; _i < _len; _i++) { + callback = _ref4[_i]; + callback(); + } + } + return response; + }; + }, + observeMutations: function(obj, ref, keypath) { + var fn, functions, map, _base, _i, _len; + if (Array.isArray(obj)) { + map = this.weakReference(obj); + if (map.pointers == null) { + map.pointers = {}; + functions = ['push', 'pop', 'shift', 'unshift', 'sort', 'reverse', 'splice']; + for (_i = 0, _len = functions.length; _i < _len; _i++) { + fn = functions[_i]; + this.stubFunction(obj, fn); + } + } + if ((_base = map.pointers)[ref] == null) { + _base[ref] = []; + } + if (__indexOf.call(map.pointers[ref], keypath) < 0) { + return map.pointers[ref].push(keypath); + } + } + }, + unobserveMutations: function(obj, ref, keypath) { + var idx, keypaths, _ref1; + if (Array.isArray(obj && (obj[this.id] != null))) { + if (keypaths = (_ref1 = this.weakReference(obj).pointers) != null ? _ref1[ref] : void 0) { + idx = keypaths.indexOf(keypath); + if (idx >= 0) { + return keypaths.splice(idx, 1); + } + } + } + }, + observe: function(obj, keypath, callback) { + var callbacks, value; + callbacks = this.weakReference(obj).callbacks; + if (callbacks[keypath] == null) { + callbacks[keypath] = []; + value = obj[keypath]; + Object.defineProperty(obj, keypath, { + enumerable: true, + get: function() { + return value; + }, + set: (function(_this) { + return function(newValue) { + var _i, _len, _ref1; + if (newValue !== value) { + value = newValue; + _ref1 = callbacks[keypath].slice(); + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + callback = _ref1[_i]; + if (__indexOf.call(callbacks[keypath], callback) >= 0) { + callback(); + } + } + return _this.observeMutations(newValue, obj[_this.id], keypath); + } + }; + })(this) + }); + } + if (__indexOf.call(callbacks[keypath], callback) < 0) { + callbacks[keypath].push(callback); + } + return this.observeMutations(obj[keypath], obj[this.id], keypath); + }, + unobserve: function(obj, keypath, callback) { + var callbacks, idx; + callbacks = this.weakmap[obj[this.id]].callbacks[keypath]; + idx = callbacks.indexOf(callback); + if (idx >= 0) { + callbacks.splice(idx, 1); + } + return this.unobserveMutations(obj[keypath], obj[this.id], keypath); + }, + get: function(obj, keypath) { + return obj[keypath]; + }, + set: function(obj, keypath, value) { + return obj[keypath] = value; + } + }; + + Rivets.factory = function(sightglass) { + Rivets.sightglass = sightglass; + Rivets["public"]._ = Rivets; + return Rivets["public"]; + }; + + if (typeof (typeof module !== "undefined" && module !== null ? module.exports : void 0) === 'object') { + module.exports = Rivets.factory(require('sightglass')); + } else if (typeof define === 'function' && define.amd) { + define(['sightglass'], function(sightglass) { + return this.rivets = Rivets.factory(sightglass); + }); + } else { + this.rivets = Rivets.factory(sightglass); + } + +}).call(this); diff --git a/ajax/libs/rivets/0.7.0-rc3/rivets.min.js b/ajax/libs/rivets/0.7.0-rc3/rivets.min.js new file mode 100644 index 000000000..430bf3337 --- /dev/null +++ b/ajax/libs/rivets/0.7.0-rc3/rivets.min.js @@ -0,0 +1,5 @@ +// Rivets.js +// version: 0.7.0-rc3 +// author: Michael Richards +// license: MIT +(function(){var t,e,i,n,r=function(t,e){return function(){return t.apply(e,arguments)}},s=[].slice,o={}.hasOwnProperty,u=function(t,e){function i(){this.constructor=t}for(var n in e)o.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t},h=[].indexOf||function(t){for(var e=0,i=this.length;i>e;e++)if(e in this&&this[e]===t)return e;return-1};t={options:["prefix","templateDelimiters","rootInterface","preloadData","handler"],extensions:["binders","formatters","components","adapters"],"public":{binders:{},components:{},formatters:{},adapters:{},prefix:"rv",templateDelimiters:["{","}"],rootInterface:".",preloadData:!0,handler:function(t,e,i){return this.call(t,e,i.view.models)},configure:function(e){var i,n,r,s;null==e&&(e={});for(r in e)if(s=e[r],"binders"===r||"components"===r||"formatters"===r||"adapters"===r)for(n in s)i=s[n],t[r][n]=i;else t["public"][r]=s},bind:function(e,i,n){var r;return null==i&&(i={}),null==n&&(n={}),r=new t.View(e,i,n),r.bind(),r}}},window.jQuery||window.$?(n="on"in jQuery.prototype?["on","off"]:["bind","unbind"],e=n[0],i=n[1],t.Util={bindEvent:function(t,i,n){return jQuery(t)[e](i,n)},unbindEvent:function(t,e,n){return jQuery(t)[i](e,n)},getInputValue:function(t){var e;return e=jQuery(t),"checkbox"===e.attr("type")?e.is(":checked"):e.val()}}):t.Util={bindEvent:function(){return"addEventListener"in window?function(t,e,i){return t.addEventListener(e,i,!1)}:function(t,e,i){return t.attachEvent("on"+e,i)}}(),unbindEvent:function(){return"removeEventListener"in window?function(t,e,i){return t.removeEventListener(e,i,!1)}:function(t,e,i){return t.detachEvent("on"+e,i)}}(),getInputValue:function(t){var e,i,n,r;if("checkbox"===t.type)return t.checked;if("select-multiple"===t.type){for(r=[],i=0,n=t.length;n>i;i++)e=t[i],e.selected&&r.push(e.value);return r}return t.value}},t.TypeParser=function(){function t(){}return t.types={primitive:0,keypath:1},t.parse=function(t){return/^'.*'$|^".*"$/.test(t)?{type:this.types.primitive,value:t.slice(1,-1)}:"true"===t?{type:this.types.primitive,value:!0}:"false"===t?{type:this.types.primitive,value:!1}:"null"===t?{type:this.types.primitive,value:null}:"undefined"===t?{type:this.types.primitive,value:void 0}:isNaN(Number(t))===!1?{type:this.types.primitive,value:Number(t)}:{type:this.types.keypath,value:t}},t}(),t.TextTemplateParser=function(){function t(){}return t.types={text:0,binding:1},t.parse=function(t,e){var i,n,r,s,o,u,h;for(u=[],s=t.length,i=0,n=0;s>n;){if(i=t.indexOf(e[0],n),0>i){u.push({type:this.types.text,value:t.slice(n)});break}if(i>0&&i>n&&u.push({type:this.types.text,value:t.slice(n,i)}),n=i+e[0].length,i=t.indexOf(e[1],n),0>i){o=t.slice(n-e[1].length),r=u[u.length-1],(null!=r?r.type:void 0)===this.types.text?r.value+=o:u.push({type:this.types.text,value:o});break}h=t.slice(n,i).trim(),u.push({type:this.types.binding,value:h}),n=i+e[1].length}return u},t}(),t.View=function(){function e(e,i,n){var s,o,u,h,l,a,p,d,c,f,b,v;for(this.els=e,this.models=i,null==n&&(n={}),this.update=r(this.update,this),this.publish=r(this.publish,this),this.sync=r(this.sync,this),this.unbind=r(this.unbind,this),this.bind=r(this.bind,this),this.select=r(this.select,this),this.build=r(this.build,this),this.componentRegExp=r(this.componentRegExp,this),this.bindingRegExp=r(this.bindingRegExp,this),this.options=r(this.options,this),this.els.jquery||this.els instanceof Array||(this.els=[this.els]),c=t.extensions,l=0,p=c.length;p>l;l++){if(o=c[l],this[o]={},n[o]){f=n[o];for(s in f)u=f[s],this[o][s]=u}b=t["public"][o];for(s in b)u=b[s],null==(h=this[o])[s]&&(h[s]=u)}for(v=t.options,a=0,d=v.length;d>a;a++)o=v[a],this[o]=n[o]||t["public"][o];this.build()}return e.prototype.options=function(){var e,i,n,r,s;for(i={},s=t.extensions.concat(t.options),n=0,r=s.length;r>n;n++)e=s[n],i[e]=this[e];return i},e.prototype.bindingRegExp=function(){return new RegExp("^"+this.prefix+"-")},e.prototype.componentRegExp=function(){return new RegExp("^"+this.prefix.toUpperCase()+"-")},e.prototype.build=function(){var e,i,n,r,s,o,u,h;for(this.bindings=[],e=this.bindingRegExp(),n=this.componentRegExp(),i=function(e){return function(i,n,r,s){var o,u,h,l,a,p,d;return a={},d=function(){var t,e,i,n;for(i=s.split("|"),n=[],t=0,e=i.length;e>t;t++)p=i[t],n.push(p.trim());return n}(),o=function(){var t,e,i,n;for(i=d.shift().split("<"),n=[],t=0,e=i.length;e>t;t++)u=i[t],n.push(u.trim());return n}(),l=o.shift(),a.formatters=d,(h=o.shift())&&(a.dependencies=h.split(/\s+/)),e.bindings.push(new t[i](e,n,r,l,a))}}(this),s=function(r){return function(o){var u,h,l,a,p,d,c,f,b,v,y,g,m,w,x,k,E,N,V,T,O,R,B,C,j,S,U,A;if(3===o.nodeType){if(b=t.TextTemplateParser,(d=r.templateDelimiters)&&(m=b.parse(o.data,d)).length&&(1!==m.length||m[0].type!==b.types.text)){for(k=0,T=m.length;T>k;k++)g=m[k],y=document.createTextNode(g.value),o.parentNode.insertBefore(y,o),1===g.type&&i("TextBinding",y,null,g.value);o.parentNode.removeChild(o)}}else if(1===o.nodeType)if(n.test(o.nodeName))w=o.nodeName.replace(n,"").toLowerCase(),r.bindings.push(new t.ComponentBinding(r,o,w));else{for(a="SCRIPT"===o.nodeName||"STYLE"===o.nodeName,C=o.attributes,E=0,O=C.length;O>E;E++)if(u=C[E],e.test(u.name)){if(w=u.name.replace(e,""),!(l=r.binders[w])){j=r.binders;for(c in j)x=j[c],"*"!==c&&-1!==c.indexOf("*")&&(v=new RegExp("^"+c.replace(/\*/g,".+")+"$"),v.test(w)&&(l=x))}l||(l=r.binders["*"]),l.block&&(a=!0,h=[u])}for(S=h||o.attributes,N=0,R=S.length;R>N;N++)u=S[N],e.test(u.name)&&(w=u.name.replace(e,""),i("Binding",o,w,u.value))}if(!a){for(U=function(){var t,e,i,n;for(i=o.childNodes,n=[],e=0,t=i.length;t>e;e++)f=i[e],n.push(f);return n}(),A=[],V=0,B=U.length;B>V;V++)p=U[V],A.push(s(p));return A}}}(this),h=this.els,o=0,u=h.length;u>o;o++)r=h[o],s(r);this.bindings.sort(function(t,e){return(e.binder.priority||0)-(t.binder.priority||0)})},e.prototype.select=function(t){var e,i,n,r,s;for(r=this.bindings,s=[],i=0,n=r.length;n>i;i++)e=r[i],t(e)&&s.push(e);return s},e.prototype.bind=function(){var t,e,i,n,r;for(n=this.bindings,r=[],e=0,i=n.length;i>e;e++)t=n[e],r.push(t.bind());return r},e.prototype.unbind=function(){var t,e,i,n,r;for(n=this.bindings,r=[],e=0,i=n.length;i>e;e++)t=n[e],r.push(t.unbind());return r},e.prototype.sync=function(){var t,e,i,n,r;for(n=this.bindings,r=[],e=0,i=n.length;i>e;e++)t=n[e],r.push(t.sync());return r},e.prototype.publish=function(){var t,e,i,n,r;for(n=this.select(function(t){return t.binder.publishes}),r=[],e=0,i=n.length;i>e;e++)t=n[e],r.push(t.publish());return r},e.prototype.update=function(t){var e,i,n,r,s,o,u;null==t&&(t={});for(i in t)n=t[i],this.models[i]=n;for(o=this.bindings,u=[],r=0,s=o.length;s>r;r++)e=o[r],u.push(e.update(t));return u},e}(),t.Binding=function(){function e(t,e,i,n,s){this.view=t,this.el=e,this.type=i,this.keypath=n,this.options=null!=s?s:{},this.getValue=r(this.getValue,this),this.update=r(this.update,this),this.unbind=r(this.unbind,this),this.bind=r(this.bind,this),this.publish=r(this.publish,this),this.sync=r(this.sync,this),this.set=r(this.set,this),this.eventHandler=r(this.eventHandler,this),this.formattedValue=r(this.formattedValue,this),this.parseTarget=r(this.parseTarget,this),this.observe=r(this.observe,this),this.setBinder=r(this.setBinder,this),this.formatters=this.options.formatters||[],this.dependencies=[],this.formatterObservers={},this.model=void 0,this.setBinder()}return e.prototype.setBinder=function(){var t,e,i,n;if(!(this.binder=this.view.binders[this.type])){n=this.view.binders;for(t in n)i=n[t],"*"!==t&&-1!==t.indexOf("*")&&(e=new RegExp("^"+t.replace(/\*/g,".+")+"$"),e.test(this.type)&&(this.binder=i,this.args=new RegExp("^"+t.replace(/\*/g,"(.+)")+"$").exec(this.type),this.args.shift()))}return this.binder||(this.binder=this.view.binders["*"]),this.binder instanceof Function?this.binder={routine:this.binder}:void 0},e.prototype.observe=function(e,i,n){return t.sightglass(e,i,n,{root:this.view.rootInterface,adapters:this.view.adapters})},e.prototype.parseTarget=function(){var e;return e=t.TypeParser.parse(this.keypath),0===e.type?this.value=e.value:(this.observer=this.observe(this.view.models,this.keypath,this.sync),this.model=this.observer.target)},e.prototype.formattedValue=function(e){var i,n,r,o,u,h,l,a,p,d,c,f,b,v;for(v=this.formatters,o=d=0,f=v.length;f>d;o=++d){for(u=v[o],r=u.match(/[^\s']+|'([^']|'[^\s])*'|"([^"]|"[^\s])*"/g),h=r.shift(),u=this.view.formatters[h],r=function(){var e,i,s;for(s=[],e=0,i=r.length;i>e;e++)n=r[e],s.push(t.TypeParser.parse(n));return s}(),a=[],i=c=0,b=r.length;b>c;i=++c)n=r[i],a.push(0===n.type?n.value:((p=this.formatterObservers)[o]||(p[o]={}),(l=this.formatterObservers[o][i])?void 0:(l=this.observe(this.view.models,n.value,this.sync),this.formatterObservers[o][i]=l),l.value()));(null!=u?u.read:void 0)instanceof Function?e=u.read.apply(u,[e].concat(s.call(a))):u instanceof Function&&(e=u.apply(null,[e].concat(s.call(a))))}return e},e.prototype.eventHandler=function(t){var e,i;return i=(e=this).view.handler,function(n){return i.call(t,this,n,e)}},e.prototype.set=function(t){var e;return t=t instanceof Function&&!this.binder["function"]?this.formattedValue(t.call(this.model)):this.formattedValue(t),null!=(e=this.binder.routine)?e.call(this,this.el,t):void 0},e.prototype.sync=function(){var t,e;return this.set(function(){var i,n,r,s,o,u,h;if(this.observer){if(this.model!==this.observer.target){for(o=this.dependencies,i=0,r=o.length;r>i;i++)e=o[i],e.unobserve();if(this.dependencies=[],null!=(this.model=this.observer.target)&&(null!=(u=this.options.dependencies)?u.length:void 0))for(h=this.options.dependencies,n=0,s=h.length;s>n;n++)t=h[n],e=this.observe(this.model,t,this.sync),this.dependencies.push(e)}return this.observer.value()}return this.value}.call(this))},e.prototype.publish=function(){var t,e,i,n,r,o,u,h,l;if(this.observer){for(n=this.getValue(this.el),u=this.formatters.slice(0).reverse(),r=0,o=u.length;o>r;r++)e=u[r],t=e.split(/\s+/),i=t.shift(),(null!=(h=this.view.formatters[i])?h.publish:void 0)&&(n=(l=this.view.formatters[i]).publish.apply(l,[n].concat(s.call(t))));return this.observer.setValue(n)}},e.prototype.bind=function(){var t,e,i,n,r,s,o;if(this.parseTarget(),null!=(r=this.binder.bind)&&r.call(this,this.el),null!=this.model&&(null!=(s=this.options.dependencies)?s.length:void 0))for(o=this.options.dependencies,i=0,n=o.length;n>i;i++)t=o[i],e=this.observe(this.model,t,this.sync),this.dependencies.push(e);return this.view.preloadData?this.sync():void 0},e.prototype.unbind=function(){var t,e,i,n,r,s,o,u,h,l;for(null!=(o=this.binder.unbind)&&o.call(this,this.el),null!=(u=this.observer)&&u.unobserve(),h=this.dependencies,r=0,s=h.length;s>r;r++)n=h[r],n.unobserve();this.dependencies=[],l=this.formatterObservers;for(i in l){e=l[i];for(t in e)n=e[t],n.unobserve()}return this.formatterObservers={}},e.prototype.update=function(t){var e,i;return null==t&&(t={}),this.model=null!=(e=this.observer)?e.target:void 0,this.unbind(),null!=(i=this.binder.update)&&i.call(this,t),this.bind()},e.prototype.getValue=function(e){return(this.binder.getValue||t.Util.getInputValue)(e)},e}(),t.ComponentBinding=function(e){function i(t,e,i){var n,s,o,u,l;for(this.view=t,this.el=e,this.type=i,this.unbind=r(this.unbind,this),this.bind=r(this.bind,this),this.update=r(this.update,this),this.locals=r(this.locals,this),this.component=this.view.components[this.type],this.attributes={},this.inflections={},u=this.el.attributes||[],s=0,o=u.length;o>s;s++)n=u[s],l=n.name,h.call(this.component.attributes,l)>=0?this.attributes[n.name]=n.value:this.inflections[n.name]=n.value}return u(i,e),i.prototype.sync=function(){},i.prototype.locals=function(t){var e,i,n,r,s,o,u,h,l;null==t&&(t=this.view.models),s={},h=this.inflections;for(i in h)for(e=h[i],l=e.split("."),o=0,u=l.length;u>o;o++)r=l[o],s[i]=(s[i]||t)[r];for(i in t)n=t[i],null==s[i]&&(s[i]=n);return s},i.prototype.update=function(t){var e;return null!=(e=this.componentView)?e.update(this.locals(t)):void 0},i.prototype.bind=function(){var e,i;return null!=this.componentView?null!=(i=this.componentView)?i.bind():void 0:(e=this.component.build.call(this.attributes),(this.componentView=new t.View(e,this.locals(),this.view.options)).bind(),this.el.parentNode.replaceChild(e,this.el))},i.prototype.unbind=function(){var t;return null!=(t=this.componentView)?t.unbind():void 0},i}(t.Binding),t.TextBinding=function(t){function e(t,e,i,n,s){this.view=t,this.el=e,this.type=i,this.keypath=n,this.options=null!=s?s:{},this.sync=r(this.sync,this),this.formatters=this.options.formatters||[],this.dependencies=[],this.formatterObservers={}}return u(e,t),e.prototype.binder={routine:function(t,e){return t.data=null!=e?e:""}},e.prototype.sync=function(){return e.__super__.sync.apply(this,arguments)},e}(t.Binding),t["public"].binders.text=function(t,e){return null!=t.textContent?t.textContent=null!=e?e:"":t.innerText=null!=e?e:""},t["public"].binders.html=function(t,e){return t.innerHTML=null!=e?e:""},t["public"].binders.show=function(t,e){return t.style.display=e?"":"none"},t["public"].binders.hide=function(t,e){return t.style.display=e?"none":""},t["public"].binders.enabled=function(t,e){return t.disabled=!e},t["public"].binders.disabled=function(t,e){return t.disabled=!!e},t["public"].binders.checked={publishes:!0,priority:2e3,bind:function(e){return t.Util.bindEvent(e,"change",this.publish)},unbind:function(e){return t.Util.unbindEvent(e,"change",this.publish)},routine:function(t,e){var i;return t.checked="radio"===t.type?(null!=(i=t.value)?i.toString():void 0)===(null!=e?e.toString():void 0):!!e}},t["public"].binders.unchecked={publishes:!0,priority:2e3,bind:function(e){return t.Util.bindEvent(e,"change",this.publish)},unbind:function(e){return t.Util.unbindEvent(e,"change",this.publish)},routine:function(t,e){var i;return t.checked="radio"===t.type?(null!=(i=t.value)?i.toString():void 0)!==(null!=e?e.toString():void 0):!e}},t["public"].binders.value={publishes:!0,priority:2e3,bind:function(e){return this.event="SELECT"===e.tagName?"change":"input",t.Util.bindEvent(e,this.event,this.publish)},unbind:function(e){return t.Util.unbindEvent(e,this.event,this.publish)},routine:function(t,e){var i,n,r,s,o,u,l;if(null!=window.jQuery){if(t=jQuery(t),(null!=e?e.toString():void 0)!==(null!=(s=t.val())?s.toString():void 0))return t.val(null!=e?e:"")}else if("select-multiple"===t.type){if(null!=e){for(l=[],n=0,r=t.length;r>n;n++)i=t[n],l.push(i.selected=(o=i.value,h.call(e,o)>=0));return l}}else if((null!=e?e.toString():void 0)!==(null!=(u=t.value)?u.toString():void 0))return t.value=null!=e?e:""}},t["public"].binders["if"]={block:!0,priority:3e3,bind:function(t){var e,i;return null==this.marker?(e=[this.view.prefix,this.type].join("-").replace("--","-"),i=t.getAttribute(e),this.marker=document.createComment(" rivets: "+this.type+" "+i+" "),this.bound=!1,t.removeAttribute(e),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(e,i){var n,r,s,o;if(!!i==!this.bound){if(i){s={},o=this.view.models;for(n in o)r=o[n],s[n]=r;return(this.nested||(this.nested=new t.View(e,s,this.view.options()))).bind(),this.marker.parentNode.insertBefore(e,this.marker.nextSibling),this.bound=!0}return e.parentNode.removeChild(e),this.nested.unbind(),this.bound=!1}},update:function(t){var e;return null!=(e=this.nested)?e.update(t):void 0}},t["public"].binders.unless={block:!0,priority:3e3,bind:function(e){return t["public"].binders["if"].bind.call(this,e)},unbind:function(){return t["public"].binders["if"].unbind.call(this)},routine:function(e,i){return t["public"].binders["if"].routine.call(this,e,!i)},update:function(e){return t["public"].binders["if"].update.call(this,e)}},t["public"].binders["on-*"]={"function":!0,priority:1e3,unbind:function(e){return this.handler?t.Util.unbindEvent(e,this.args[0],this.handler):void 0},routine:function(e,i){return this.handler&&t.Util.unbindEvent(e,this.args[0],this.handler),t.Util.bindEvent(e,this.args[0],this.handler=this.eventHandler(i))}},t["public"].binders["each-*"]={block:!0,priority:3e3,bind:function(t){var e,i,n,r,s;if(null==this.marker)e=[this.view.prefix,this.type].join("-").replace("--","-"),this.marker=document.createComment(" rivets: "+this.type+" "),this.iterated=[],t.removeAttribute(e),t.parentNode.insertBefore(this.marker,t),t.parentNode.removeChild(t);else for(s=this.iterated,n=0,r=s.length;r>n;n++)i=s[n],i.bind()},unbind:function(){var t,e,i,n,r;if(null!=this.iterated){for(n=this.iterated,r=[],e=0,i=n.length;i>e;e++)t=n[e],r.push(t.unbind());return r}},routine:function(e,i){var n,r,s,o,u,h,l,a,p,d,c,f,b,v,y,g,m,w,x,k,E;if(l=this.args[0],i=i||[],this.iterated.length>i.length)for(w=Array(this.iterated.length-i.length),f=0,y=w.length;y>f;f++)s=w[f],c=this.iterated.pop(),c.unbind(),this.marker.parentNode.removeChild(c.els[0]);for(o=b=0,g=i.length;g>b;o=++b)if(h=i[o],r={index:o},r[l]=h,null==this.iterated[o]){x=this.view.models;for(u in x)h=x[u],null==r[u]&&(r[u]=h);p=this.iterated.length?this.iterated[this.iterated.length-1].els[0]:this.marker,a=this.view.options(),a.preloadData=!0,d=e.cloneNode(!0),c=new t.View(d,r,a),c.bind(),this.iterated.push(c),this.marker.parentNode.insertBefore(d,p.nextSibling)}else this.iterated[o].models[l]!==h&&this.iterated[o].update(r);if("OPTION"===e.nodeName){for(k=this.view.bindings,E=[],v=0,m=k.length;m>v;v++)n=k[v],n.el===this.marker.parentNode&&"value"===n.type?E.push(n.sync()):E.push(void 0);return E}},update:function(t){var e,i,n,r,s,o,u,h;e={};for(i in t)n=t[i],i!==this.args[0]&&(e[i]=n);for(u=this.iterated,h=[],s=0,o=u.length;o>s;s++)r=u[s],h.push(r.update(e));return h}},t["public"].binders["class-*"]=function(t,e){var i;return i=" "+t.className+" ",!e==(-1!==i.indexOf(" "+this.args[0]+" "))?t.className=e?""+t.className+" "+this.args[0]:i.replace(" "+this.args[0]+" "," ").trim():void 0},t["public"].binders["*"]=function(t,e){return null!=e?t.setAttribute(this.type,e):t.removeAttribute(this.type)},t["public"].adapters["."]={id:"_rv",counter:0,weakmap:{},weakReference:function(t){var e;return t.hasOwnProperty(this.id)||(e=this.counter++,this.weakmap[e]={callbacks:{}},Object.defineProperty(t,this.id,{value:e})),this.weakmap[t[this.id]]},stubFunction:function(t,e){var i,n,r;return n=t[e],i=this.weakReference(t),r=this.weakmap,t[e]=function(){var e,s,o,u,h,l,a,p,d,c;u=n.apply(t,arguments),a=i.pointers;for(o in a)for(s=a[o],c=null!=(p=null!=(d=r[o])?d.callbacks[s]:void 0)?p:[],h=0,l=c.length;l>h;h++)e=c[h],e();return u}},observeMutations:function(t,e,i){var n,r,s,o,u,l;if(Array.isArray(t)){if(s=this.weakReference(t),null==s.pointers)for(s.pointers={},r=["push","pop","shift","unshift","sort","reverse","splice"],u=0,l=r.length;l>u;u++)n=r[u],this.stubFunction(t,n);if(null==(o=s.pointers)[e]&&(o[e]=[]),h.call(s.pointers[e],i)<0)return s.pointers[e].push(i)}},unobserveMutations:function(t,e,i){var n,r,s;return Array.isArray(t&&null!=t[this.id])&&(r=null!=(s=this.weakReference(t).pointers)?s[e]:void 0)&&(n=r.indexOf(i),n>=0)?r.splice(n,1):void 0},observe:function(t,e,i){var n,r;return n=this.weakReference(t).callbacks,null==n[e]&&(n[e]=[],r=t[e],Object.defineProperty(t,e,{enumerable:!0,get:function(){return r},set:function(s){return function(o){var u,l,a;if(o!==r){for(r=o,a=n[e].slice(),u=0,l=a.length;l>u;u++)i=a[u],h.call(n[e],i)>=0&&i();return s.observeMutations(o,t[s.id],e)}}}(this)})),h.call(n[e],i)<0&&n[e].push(i),this.observeMutations(t[e],t[this.id],e)},unobserve:function(t,e,i){var n,r;return n=this.weakmap[t[this.id]].callbacks[e],r=n.indexOf(i),r>=0&&n.splice(r,1),this.unobserveMutations(t[e],t[this.id],e)},get:function(t,e){return t[e]},set:function(t,e,i){return t[e]=i}},t.factory=function(e){return t.sightglass=e,t["public"]._=t,t["public"]},"object"==typeof("undefined"!=typeof module&&null!==module?module.exports:void 0)?module.exports=t.factory(require("sightglass")):"function"==typeof define&&define.amd?define(["sightglass"],function(e){return this.rivets=t.factory(e)}):this.rivets=t.factory(sightglass)}).call(this); \ No newline at end of file diff --git a/ajax/libs/rivets/0.7.0/rivets.bundled.min.js b/ajax/libs/rivets/0.7.0/rivets.bundled.min.js new file mode 100644 index 000000000..f3bfe9c3c --- /dev/null +++ b/ajax/libs/rivets/0.7.0/rivets.bundled.min.js @@ -0,0 +1,6 @@ +// Rivets.js + Sightglass.js +// version: 0.7.0 +// author: Michael Richards +// license: MIT +(function(){function t(t,i,s,n){return new e(t,i,s,n)}function e(t,e,s,n){this.options=n||{},this.options.adapters=this.options.adapters||{},this.obj=t,this.keypath=e,this.callback=s,this.objectPath=[],this.parse(),i(this.target=this.realize())&&this.set(!0,this.key,this.target,this.callback)}function i(t){return"object"==typeof t&&null!==t}function s(t){throw new Error("[sightglass] "+t)}t.adapters={},e.tokenize=function(t,e,i){for(tokens=[],current={i:i,path:""},index=0;indexe;e++)if(e in this&&this[e]===t)return e;return-1};t={options:["prefix","templateDelimiters","rootInterface","preloadData","handler"],extensions:["binders","formatters","components","adapters"],"public":{binders:{},components:{},formatters:{},adapters:{},prefix:"rv",templateDelimiters:["{","}"],rootInterface:".",preloadData:!0,handler:function(t,e,i){return this.call(t,e,i.view.models)},configure:function(e){var i,n,r,s;null==e&&(e={});for(r in e)if(s=e[r],"binders"===r||"components"===r||"formatters"===r||"adapters"===r)for(n in s)i=s[n],t[r][n]=i;else t["public"][r]=s},bind:function(e,i,n){var r;return null==i&&(i={}),null==n&&(n={}),r=new t.View(e,i,n),r.bind(),r}}},window.jQuery||window.$?(n="on"in jQuery.prototype?["on","off"]:["bind","unbind"],e=n[0],i=n[1],t.Util={bindEvent:function(t,i,n){return jQuery(t)[e](i,n)},unbindEvent:function(t,e,n){return jQuery(t)[i](e,n)},getInputValue:function(t){var e;return e=jQuery(t),"checkbox"===e.attr("type")?e.is(":checked"):e.val()}}):t.Util={bindEvent:function(){return"addEventListener"in window?function(t,e,i){return t.addEventListener(e,i,!1)}:function(t,e,i){return t.attachEvent("on"+e,i)}}(),unbindEvent:function(){return"removeEventListener"in window?function(t,e,i){return t.removeEventListener(e,i,!1)}:function(t,e,i){return t.detachEvent("on"+e,i)}}(),getInputValue:function(t){var e,i,n,r;if("checkbox"===t.type)return t.checked;if("select-multiple"===t.type){for(r=[],i=0,n=t.length;n>i;i++)e=t[i],e.selected&&r.push(e.value);return r}return t.value}},t.TypeParser=function(){function t(){}return t.types={primitive:0,keypath:1},t.parse=function(t){return/^'.*'$|^".*"$/.test(t)?{type:this.types.primitive,value:t.slice(1,-1)}:"true"===t?{type:this.types.primitive,value:!0}:"false"===t?{type:this.types.primitive,value:!1}:"null"===t?{type:this.types.primitive,value:null}:"undefined"===t?{type:this.types.primitive,value:void 0}:isNaN(Number(t))===!1?{type:this.types.primitive,value:Number(t)}:{type:this.types.keypath,value:t}},t}(),t.TextTemplateParser=function(){function t(){}return t.types={text:0,binding:1},t.parse=function(t,e){var i,n,r,s,o,u,h;for(u=[],s=t.length,i=0,n=0;s>n;){if(i=t.indexOf(e[0],n),0>i){u.push({type:this.types.text,value:t.slice(n)});break}if(i>0&&i>n&&u.push({type:this.types.text,value:t.slice(n,i)}),n=i+e[0].length,i=t.indexOf(e[1],n),0>i){o=t.slice(n-e[1].length),r=u[u.length-1],(null!=r?r.type:void 0)===this.types.text?r.value+=o:u.push({type:this.types.text,value:o});break}h=t.slice(n,i).trim(),u.push({type:this.types.binding,value:h}),n=i+e[1].length}return u},t}(),t.View=function(){function e(e,i,n){var s,o,u,h,l,a,p,d,c,f,b,v;for(this.els=e,this.models=i,null==n&&(n={}),this.update=r(this.update,this),this.publish=r(this.publish,this),this.sync=r(this.sync,this),this.unbind=r(this.unbind,this),this.bind=r(this.bind,this),this.select=r(this.select,this),this.build=r(this.build,this),this.componentRegExp=r(this.componentRegExp,this),this.bindingRegExp=r(this.bindingRegExp,this),this.options=r(this.options,this),this.els.jquery||this.els instanceof Array||(this.els=[this.els]),c=t.extensions,l=0,p=c.length;p>l;l++){if(o=c[l],this[o]={},n[o]){f=n[o];for(s in f)u=f[s],this[o][s]=u}b=t["public"][o];for(s in b)u=b[s],null==(h=this[o])[s]&&(h[s]=u)}for(v=t.options,a=0,d=v.length;d>a;a++)o=v[a],this[o]=n[o]||t["public"][o];this.build()}return e.prototype.options=function(){var e,i,n,r,s;for(i={},s=t.extensions.concat(t.options),n=0,r=s.length;r>n;n++)e=s[n],i[e]=this[e];return i},e.prototype.bindingRegExp=function(){return new RegExp("^"+this.prefix+"-")},e.prototype.componentRegExp=function(){return new RegExp("^"+this.prefix.toUpperCase()+"-")},e.prototype.build=function(){var e,i,n,r,s,o,u,h;for(this.bindings=[],e=this.bindingRegExp(),n=this.componentRegExp(),i=function(e){return function(i,n,r,s){var o,u,h,l,a,p,d;return a={},d=function(){var t,e,i,n;for(i=s.split("|"),n=[],t=0,e=i.length;e>t;t++)p=i[t],n.push(p.trim());return n}(),o=function(){var t,e,i,n;for(i=d.shift().split("<"),n=[],t=0,e=i.length;e>t;t++)u=i[t],n.push(u.trim());return n}(),l=o.shift(),a.formatters=d,(h=o.shift())&&(a.dependencies=h.split(/\s+/)),e.bindings.push(new t[i](e,n,r,l,a))}}(this),s=function(r){return function(o){var u,h,l,a,p,d,c,f,b,v,y,g,m,w,x,k,E,N,V,T,O,R,B,C,j,S,U,A;if(3===o.nodeType){if(b=t.TextTemplateParser,(d=r.templateDelimiters)&&(m=b.parse(o.data,d)).length&&(1!==m.length||m[0].type!==b.types.text)){for(k=0,T=m.length;T>k;k++)g=m[k],y=document.createTextNode(g.value),o.parentNode.insertBefore(y,o),1===g.type&&i("TextBinding",y,null,g.value);o.parentNode.removeChild(o)}}else if(1===o.nodeType)if(n.test(o.nodeName))w=o.nodeName.replace(n,"").toLowerCase(),r.bindings.push(new t.ComponentBinding(r,o,w));else{for(a="SCRIPT"===o.nodeName||"STYLE"===o.nodeName,C=o.attributes,E=0,O=C.length;O>E;E++)if(u=C[E],e.test(u.name)){if(w=u.name.replace(e,""),!(l=r.binders[w])){j=r.binders;for(c in j)x=j[c],"*"!==c&&-1!==c.indexOf("*")&&(v=new RegExp("^"+c.replace(/\*/g,".+")+"$"),v.test(w)&&(l=x))}l||(l=r.binders["*"]),l.block&&(a=!0,h=[u])}for(S=h||o.attributes,N=0,R=S.length;R>N;N++)u=S[N],e.test(u.name)&&(w=u.name.replace(e,""),i("Binding",o,w,u.value))}if(!a){for(U=function(){var t,e,i,n;for(i=o.childNodes,n=[],e=0,t=i.length;t>e;e++)f=i[e],n.push(f);return n}(),A=[],V=0,B=U.length;B>V;V++)p=U[V],A.push(s(p));return A}}}(this),h=this.els,o=0,u=h.length;u>o;o++)r=h[o],s(r);this.bindings.sort(function(t,e){return(e.binder.priority||0)-(t.binder.priority||0)})},e.prototype.select=function(t){var e,i,n,r,s;for(r=this.bindings,s=[],i=0,n=r.length;n>i;i++)e=r[i],t(e)&&s.push(e);return s},e.prototype.bind=function(){var t,e,i,n,r;for(n=this.bindings,r=[],e=0,i=n.length;i>e;e++)t=n[e],r.push(t.bind());return r},e.prototype.unbind=function(){var t,e,i,n,r;for(n=this.bindings,r=[],e=0,i=n.length;i>e;e++)t=n[e],r.push(t.unbind());return r},e.prototype.sync=function(){var t,e,i,n,r;for(n=this.bindings,r=[],e=0,i=n.length;i>e;e++)t=n[e],r.push(t.sync());return r},e.prototype.publish=function(){var t,e,i,n,r;for(n=this.select(function(t){return t.binder.publishes}),r=[],e=0,i=n.length;i>e;e++)t=n[e],r.push(t.publish());return r},e.prototype.update=function(t){var e,i,n,r,s,o,u;null==t&&(t={});for(i in t)n=t[i],this.models[i]=n;for(o=this.bindings,u=[],r=0,s=o.length;s>r;r++)e=o[r],u.push(e.update(t));return u},e}(),t.Binding=function(){function e(t,e,i,n,s){this.view=t,this.el=e,this.type=i,this.keypath=n,this.options=null!=s?s:{},this.getValue=r(this.getValue,this),this.update=r(this.update,this),this.unbind=r(this.unbind,this),this.bind=r(this.bind,this),this.publish=r(this.publish,this),this.sync=r(this.sync,this),this.set=r(this.set,this),this.eventHandler=r(this.eventHandler,this),this.formattedValue=r(this.formattedValue,this),this.parseTarget=r(this.parseTarget,this),this.observe=r(this.observe,this),this.setBinder=r(this.setBinder,this),this.formatters=this.options.formatters||[],this.dependencies=[],this.formatterObservers={},this.model=void 0,this.setBinder()}return e.prototype.setBinder=function(){var t,e,i,n;if(!(this.binder=this.view.binders[this.type])){n=this.view.binders;for(t in n)i=n[t],"*"!==t&&-1!==t.indexOf("*")&&(e=new RegExp("^"+t.replace(/\*/g,".+")+"$"),e.test(this.type)&&(this.binder=i,this.args=new RegExp("^"+t.replace(/\*/g,"(.+)")+"$").exec(this.type),this.args.shift()))}return this.binder||(this.binder=this.view.binders["*"]),this.binder instanceof Function?this.binder={routine:this.binder}:void 0},e.prototype.observe=function(e,i,n){return t.sightglass(e,i,n,{root:this.view.rootInterface,adapters:this.view.adapters})},e.prototype.parseTarget=function(){var e;return e=t.TypeParser.parse(this.keypath),0===e.type?this.value=e.value:(this.observer=this.observe(this.view.models,this.keypath,this.sync),this.model=this.observer.target)},e.prototype.formattedValue=function(e){var i,n,r,o,u,h,l,a,p,d,c,f,b,v;for(v=this.formatters,o=d=0,f=v.length;f>d;o=++d){for(u=v[o],r=u.match(/[^\s']+|'([^']|'[^\s])*'|"([^"]|"[^\s])*"/g),h=r.shift(),u=this.view.formatters[h],r=function(){var e,i,s;for(s=[],e=0,i=r.length;i>e;e++)n=r[e],s.push(t.TypeParser.parse(n));return s}(),a=[],i=c=0,b=r.length;b>c;i=++c)n=r[i],a.push(0===n.type?n.value:((p=this.formatterObservers)[o]||(p[o]={}),(l=this.formatterObservers[o][i])?void 0:(l=this.observe(this.view.models,n.value,this.sync),this.formatterObservers[o][i]=l),l.value()));(null!=u?u.read:void 0)instanceof Function?e=u.read.apply(u,[e].concat(s.call(a))):u instanceof Function&&(e=u.apply(null,[e].concat(s.call(a))))}return e},e.prototype.eventHandler=function(t){var e,i;return i=(e=this).view.handler,function(n){return i.call(t,this,n,e)}},e.prototype.set=function(t){var e;return t=t instanceof Function&&!this.binder["function"]?this.formattedValue(t.call(this.model)):this.formattedValue(t),null!=(e=this.binder.routine)?e.call(this,this.el,t):void 0},e.prototype.sync=function(){var t,e;return this.set(function(){var i,n,r,s,o,u,h;if(this.observer){if(this.model!==this.observer.target){for(o=this.dependencies,i=0,r=o.length;r>i;i++)e=o[i],e.unobserve();if(this.dependencies=[],null!=(this.model=this.observer.target)&&(null!=(u=this.options.dependencies)?u.length:void 0))for(h=this.options.dependencies,n=0,s=h.length;s>n;n++)t=h[n],e=this.observe(this.model,t,this.sync),this.dependencies.push(e)}return this.observer.value()}return this.value}.call(this))},e.prototype.publish=function(){var t,e,i,n,r,o,u,h,l;if(this.observer){for(n=this.getValue(this.el),u=this.formatters.slice(0).reverse(),r=0,o=u.length;o>r;r++)e=u[r],t=e.split(/\s+/),i=t.shift(),(null!=(h=this.view.formatters[i])?h.publish:void 0)&&(n=(l=this.view.formatters[i]).publish.apply(l,[n].concat(s.call(t))));return this.observer.setValue(n)}},e.prototype.bind=function(){var t,e,i,n,r,s,o;if(this.parseTarget(),null!=(r=this.binder.bind)&&r.call(this,this.el),null!=this.model&&(null!=(s=this.options.dependencies)?s.length:void 0))for(o=this.options.dependencies,i=0,n=o.length;n>i;i++)t=o[i],e=this.observe(this.model,t,this.sync),this.dependencies.push(e);return this.view.preloadData?this.sync():void 0},e.prototype.unbind=function(){var t,e,i,n,r,s,o,u,h,l;for(null!=(o=this.binder.unbind)&&o.call(this,this.el),null!=(u=this.observer)&&u.unobserve(),h=this.dependencies,r=0,s=h.length;s>r;r++)n=h[r],n.unobserve();this.dependencies=[],l=this.formatterObservers;for(i in l){e=l[i];for(t in e)n=e[t],n.unobserve()}return this.formatterObservers={}},e.prototype.update=function(t){var e,i;return null==t&&(t={}),this.model=null!=(e=this.observer)?e.target:void 0,this.unbind(),null!=(i=this.binder.update)&&i.call(this,t),this.bind()},e.prototype.getValue=function(e){return(this.binder.getValue||t.Util.getInputValue)(e)},e}(),t.ComponentBinding=function(e){function i(t,e,i){var n,s,o,u,l;for(this.view=t,this.el=e,this.type=i,this.unbind=r(this.unbind,this),this.bind=r(this.bind,this),this.update=r(this.update,this),this.locals=r(this.locals,this),this.component=this.view.components[this.type],this.attributes={},this.inflections={},u=this.el.attributes||[],s=0,o=u.length;o>s;s++)n=u[s],l=n.name,h.call(this.component.attributes,l)>=0?this.attributes[n.name]=n.value:this.inflections[n.name]=n.value}return u(i,e),i.prototype.sync=function(){},i.prototype.locals=function(t){var e,i,n,r,s,o,u,h,l;null==t&&(t=this.view.models),s={},h=this.inflections;for(i in h)for(e=h[i],l=e.split("."),o=0,u=l.length;u>o;o++)r=l[o],s[i]=(s[i]||t)[r];for(i in t)n=t[i],null==s[i]&&(s[i]=n);return s},i.prototype.update=function(t){var e;return null!=(e=this.componentView)?e.update(this.locals(t)):void 0},i.prototype.bind=function(){var e,i;return null!=this.componentView?null!=(i=this.componentView)?i.bind():void 0:(e=this.component.build.call(this.attributes),(this.componentView=new t.View(e,this.locals(),this.view.options)).bind(),this.el.parentNode.replaceChild(e,this.el))},i.prototype.unbind=function(){var t;return null!=(t=this.componentView)?t.unbind():void 0},i}(t.Binding),t.TextBinding=function(t){function e(t,e,i,n,s){this.view=t,this.el=e,this.type=i,this.keypath=n,this.options=null!=s?s:{},this.sync=r(this.sync,this),this.formatters=this.options.formatters||[],this.dependencies=[],this.formatterObservers={}}return u(e,t),e.prototype.binder={routine:function(t,e){return t.data=null!=e?e:""}},e.prototype.sync=function(){return e.__super__.sync.apply(this,arguments)},e}(t.Binding),t["public"].binders.text=function(t,e){return null!=t.textContent?t.textContent=null!=e?e:"":t.innerText=null!=e?e:""},t["public"].binders.html=function(t,e){return t.innerHTML=null!=e?e:""},t["public"].binders.show=function(t,e){return t.style.display=e?"":"none"},t["public"].binders.hide=function(t,e){return t.style.display=e?"none":""},t["public"].binders.enabled=function(t,e){return t.disabled=!e},t["public"].binders.disabled=function(t,e){return t.disabled=!!e},t["public"].binders.checked={publishes:!0,priority:2e3,bind:function(e){return t.Util.bindEvent(e,"change",this.publish)},unbind:function(e){return t.Util.unbindEvent(e,"change",this.publish)},routine:function(t,e){var i;return t.checked="radio"===t.type?(null!=(i=t.value)?i.toString():void 0)===(null!=e?e.toString():void 0):!!e}},t["public"].binders.unchecked={publishes:!0,priority:2e3,bind:function(e){return t.Util.bindEvent(e,"change",this.publish)},unbind:function(e){return t.Util.unbindEvent(e,"change",this.publish)},routine:function(t,e){var i;return t.checked="radio"===t.type?(null!=(i=t.value)?i.toString():void 0)!==(null!=e?e.toString():void 0):!e}},t["public"].binders.value={publishes:!0,priority:2e3,bind:function(e){return this.event="SELECT"===e.tagName?"change":"input",t.Util.bindEvent(e,this.event,this.publish)},unbind:function(e){return t.Util.unbindEvent(e,this.event,this.publish)},routine:function(t,e){var i,n,r,s,o,u,l;if(null!=window.jQuery){if(t=jQuery(t),(null!=e?e.toString():void 0)!==(null!=(s=t.val())?s.toString():void 0))return t.val(null!=e?e:"")}else if("select-multiple"===t.type){if(null!=e){for(l=[],n=0,r=t.length;r>n;n++)i=t[n],l.push(i.selected=(o=i.value,h.call(e,o)>=0));return l}}else if((null!=e?e.toString():void 0)!==(null!=(u=t.value)?u.toString():void 0))return t.value=null!=e?e:""}},t["public"].binders["if"]={block:!0,priority:3e3,bind:function(t){var e,i;return null==this.marker?(e=[this.view.prefix,this.type].join("-").replace("--","-"),i=t.getAttribute(e),this.marker=document.createComment(" rivets: "+this.type+" "+i+" "),this.bound=!1,t.removeAttribute(e),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(e,i){var n,r,s,o;if(!!i==!this.bound){if(i){s={},o=this.view.models;for(n in o)r=o[n],s[n]=r;return(this.nested||(this.nested=new t.View(e,s,this.view.options()))).bind(),this.marker.parentNode.insertBefore(e,this.marker.nextSibling),this.bound=!0}return e.parentNode.removeChild(e),this.nested.unbind(),this.bound=!1}},update:function(t){var e;return null!=(e=this.nested)?e.update(t):void 0}},t["public"].binders.unless={block:!0,priority:3e3,bind:function(e){return t["public"].binders["if"].bind.call(this,e)},unbind:function(){return t["public"].binders["if"].unbind.call(this)},routine:function(e,i){return t["public"].binders["if"].routine.call(this,e,!i)},update:function(e){return t["public"].binders["if"].update.call(this,e)}},t["public"].binders["on-*"]={"function":!0,priority:1e3,unbind:function(e){return this.handler?t.Util.unbindEvent(e,this.args[0],this.handler):void 0},routine:function(e,i){return this.handler&&t.Util.unbindEvent(e,this.args[0],this.handler),t.Util.bindEvent(e,this.args[0],this.handler=this.eventHandler(i))}},t["public"].binders["each-*"]={block:!0,priority:3e3,bind:function(t){var e,i,n,r,s;if(null==this.marker)e=[this.view.prefix,this.type].join("-").replace("--","-"),this.marker=document.createComment(" rivets: "+this.type+" "),this.iterated=[],t.removeAttribute(e),t.parentNode.insertBefore(this.marker,t),t.parentNode.removeChild(t);else for(s=this.iterated,n=0,r=s.length;r>n;n++)i=s[n],i.bind()},unbind:function(){var t,e,i,n,r;if(null!=this.iterated){for(n=this.iterated,r=[],e=0,i=n.length;i>e;e++)t=n[e],r.push(t.unbind());return r}},routine:function(e,i){var n,r,s,o,u,h,l,a,p,d,c,f,b,v,y,g,m,w,x,k,E;if(l=this.args[0],i=i||[],this.iterated.length>i.length)for(w=Array(this.iterated.length-i.length),f=0,y=w.length;y>f;f++)s=w[f],c=this.iterated.pop(),c.unbind(),this.marker.parentNode.removeChild(c.els[0]);for(o=b=0,g=i.length;g>b;o=++b)if(h=i[o],r={index:o},r[l]=h,null==this.iterated[o]){x=this.view.models;for(u in x)h=x[u],null==r[u]&&(r[u]=h);p=this.iterated.length?this.iterated[this.iterated.length-1].els[0]:this.marker,a=this.view.options(),a.preloadData=!0,d=e.cloneNode(!0),c=new t.View(d,r,a),c.bind(),this.iterated.push(c),this.marker.parentNode.insertBefore(d,p.nextSibling)}else this.iterated[o].models[l]!==h&&this.iterated[o].update(r);if("OPTION"===e.nodeName){for(k=this.view.bindings,E=[],v=0,m=k.length;m>v;v++)n=k[v],n.el===this.marker.parentNode&&"value"===n.type?E.push(n.sync()):E.push(void 0);return E}},update:function(t){var e,i,n,r,s,o,u,h;e={};for(i in t)n=t[i],i!==this.args[0]&&(e[i]=n);for(u=this.iterated,h=[],s=0,o=u.length;o>s;s++)r=u[s],h.push(r.update(e));return h}},t["public"].binders["class-*"]=function(t,e){var i;return i=" "+t.className+" ",!e==(-1!==i.indexOf(" "+this.args[0]+" "))?t.className=e?""+t.className+" "+this.args[0]:i.replace(" "+this.args[0]+" "," ").trim():void 0},t["public"].binders["*"]=function(t,e){return null!=e?t.setAttribute(this.type,e):t.removeAttribute(this.type)},t["public"].adapters["."]={id:"_rv",counter:0,weakmap:{},weakReference:function(t){var e;return t.hasOwnProperty(this.id)||(e=this.counter++,this.weakmap[e]={callbacks:{}},Object.defineProperty(t,this.id,{value:e})),this.weakmap[t[this.id]]},stubFunction:function(t,e){var i,n,r;return n=t[e],i=this.weakReference(t),r=this.weakmap,t[e]=function(){var e,s,o,u,h,l,a,p,d,c;u=n.apply(t,arguments),a=i.pointers;for(o in a)for(s=a[o],c=null!=(p=null!=(d=r[o])?d.callbacks[s]:void 0)?p:[],h=0,l=c.length;l>h;h++)e=c[h],e();return u}},observeMutations:function(t,e,i){var n,r,s,o,u,l;if(Array.isArray(t)){if(s=this.weakReference(t),null==s.pointers)for(s.pointers={},r=["push","pop","shift","unshift","sort","reverse","splice"],u=0,l=r.length;l>u;u++)n=r[u],this.stubFunction(t,n);if(null==(o=s.pointers)[e]&&(o[e]=[]),h.call(s.pointers[e],i)<0)return s.pointers[e].push(i)}},unobserveMutations:function(t,e,i){var n,r,s;return Array.isArray(t&&null!=t[this.id])&&(r=null!=(s=this.weakReference(t).pointers)?s[e]:void 0)&&(n=r.indexOf(i),n>=0)?r.splice(n,1):void 0},observe:function(t,e,i){var n,r;return n=this.weakReference(t).callbacks,null==n[e]&&(n[e]=[],r=t[e],Object.defineProperty(t,e,{enumerable:!0,get:function(){return r},set:function(s){return function(o){var u,l,a;if(o!==r){for(r=o,a=n[e].slice(),u=0,l=a.length;l>u;u++)i=a[u],h.call(n[e],i)>=0&&i();return s.observeMutations(o,t[s.id],e)}}}(this)})),h.call(n[e],i)<0&&n[e].push(i),this.observeMutations(t[e],t[this.id],e)},unobserve:function(t,e,i){var n,r;return n=this.weakmap[t[this.id]].callbacks[e],r=n.indexOf(i),r>=0&&n.splice(r,1),this.unobserveMutations(t[e],t[this.id],e)},get:function(t,e){return t[e]},set:function(t,e,i){return t[e]=i}},t.factory=function(e){return t.sightglass=e,t["public"]._=t,t["public"]},"object"==typeof("undefined"!=typeof module&&null!==module?module.exports:void 0)?module.exports=t.factory(require("sightglass")):"function"==typeof define&&define.amd?define(["sightglass"],function(e){return this.rivets=t.factory(e)}):this.rivets=t.factory(sightglass)}).call(this); \ No newline at end of file diff --git a/ajax/libs/rivets/0.7.0/rivets.js b/ajax/libs/rivets/0.7.0/rivets.js new file mode 100644 index 000000000..8326a5f8d --- /dev/null +++ b/ajax/libs/rivets/0.7.0/rivets.js @@ -0,0 +1,1268 @@ +// Rivets.js +// version: 0.7.0 +// author: Michael Richards +// license: MIT +(function() { + var Rivets, bindMethod, unbindMethod, _ref, + __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + __slice = [].slice, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + __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; }; + + Rivets = { + options: ['prefix', 'templateDelimiters', 'rootInterface', 'preloadData', 'handler'], + extensions: ['binders', 'formatters', 'components', 'adapters'], + "public": { + binders: {}, + components: {}, + formatters: {}, + adapters: {}, + prefix: 'rv', + templateDelimiters: ['{', '}'], + rootInterface: '.', + preloadData: true, + handler: function(context, ev, binding) { + return this.call(context, ev, binding.view.models); + }, + configure: function(options) { + var descriptor, key, option, value; + if (options == null) { + options = {}; + } + for (option in options) { + value = options[option]; + if (option === 'binders' || option === 'components' || option === 'formatters' || option === 'adapters') { + for (key in value) { + descriptor = value[key]; + Rivets[option][key] = descriptor; + } + } else { + Rivets["public"][option] = value; + } + } + }, + bind: function(el, models, options) { + var view; + if (models == null) { + models = {}; + } + if (options == null) { + options = {}; + } + view = new Rivets.View(el, models, options); + view.bind(); + return view; + } + } + }; + + if (window['jQuery'] || window['$']) { + _ref = 'on' in jQuery.prototype ? ['on', 'off'] : ['bind', 'unbind'], bindMethod = _ref[0], unbindMethod = _ref[1]; + Rivets.Util = { + bindEvent: function(el, event, handler) { + return jQuery(el)[bindMethod](event, handler); + }, + unbindEvent: function(el, event, handler) { + return jQuery(el)[unbindMethod](event, handler); + }, + getInputValue: function(el) { + var $el; + $el = jQuery(el); + if ($el.attr('type') === 'checkbox') { + return $el.is(':checked'); + } else { + return $el.val(); + } + } + }; + } else { + Rivets.Util = { + bindEvent: (function() { + if ('addEventListener' in window) { + return function(el, event, handler) { + return el.addEventListener(event, handler, false); + }; + } + return function(el, event, handler) { + return el.attachEvent('on' + event, handler); + }; + })(), + unbindEvent: (function() { + if ('removeEventListener' in window) { + return function(el, event, handler) { + return el.removeEventListener(event, handler, false); + }; + } + return function(el, event, handler) { + return el.detachEvent('on' + event, handler); + }; + })(), + getInputValue: function(el) { + var o, _i, _len, _results; + if (el.type === 'checkbox') { + return el.checked; + } else if (el.type === 'select-multiple') { + _results = []; + for (_i = 0, _len = el.length; _i < _len; _i++) { + o = el[_i]; + if (o.selected) { + _results.push(o.value); + } + } + return _results; + } else { + return el.value; + } + } + }; + } + + Rivets.TypeParser = (function() { + function TypeParser() {} + + TypeParser.types = { + primitive: 0, + keypath: 1 + }; + + TypeParser.parse = function(string) { + if (/^'.*'$|^".*"$/.test(string)) { + return { + type: this.types.primitive, + value: string.slice(1, -1) + }; + } else if (string === 'true') { + return { + type: this.types.primitive, + value: true + }; + } else if (string === 'false') { + return { + type: this.types.primitive, + value: false + }; + } else if (string === 'null') { + return { + type: this.types.primitive, + value: null + }; + } else if (string === 'undefined') { + return { + type: this.types.primitive, + value: void 0 + }; + } else if (isNaN(Number(string)) === false) { + return { + type: this.types.primitive, + value: Number(string) + }; + } else { + return { + type: this.types.keypath, + value: string + }; + } + }; + + return TypeParser; + + })(); + + Rivets.TextTemplateParser = (function() { + function TextTemplateParser() {} + + TextTemplateParser.types = { + text: 0, + binding: 1 + }; + + TextTemplateParser.parse = function(template, delimiters) { + var index, lastIndex, lastToken, length, substring, tokens, value; + tokens = []; + length = template.length; + index = 0; + lastIndex = 0; + while (lastIndex < length) { + index = template.indexOf(delimiters[0], lastIndex); + if (index < 0) { + tokens.push({ + type: this.types.text, + value: template.slice(lastIndex) + }); + break; + } else { + if (index > 0 && lastIndex < index) { + tokens.push({ + type: this.types.text, + value: template.slice(lastIndex, index) + }); + } + lastIndex = index + delimiters[0].length; + index = template.indexOf(delimiters[1], lastIndex); + if (index < 0) { + substring = template.slice(lastIndex - delimiters[1].length); + lastToken = tokens[tokens.length - 1]; + if ((lastToken != null ? lastToken.type : void 0) === this.types.text) { + lastToken.value += substring; + } else { + tokens.push({ + type: this.types.text, + value: substring + }); + } + break; + } + value = template.slice(lastIndex, index).trim(); + tokens.push({ + type: this.types.binding, + value: value + }); + lastIndex = index + delimiters[1].length; + } + } + return tokens; + }; + + return TextTemplateParser; + + })(); + + Rivets.View = (function() { + function View(els, models, options) { + var k, option, v, _base, _i, _j, _len, _len1, _ref1, _ref2, _ref3, _ref4; + this.els = els; + this.models = models; + if (options == null) { + options = {}; + } + this.update = __bind(this.update, this); + this.publish = __bind(this.publish, this); + this.sync = __bind(this.sync, this); + this.unbind = __bind(this.unbind, this); + this.bind = __bind(this.bind, this); + this.select = __bind(this.select, this); + this.build = __bind(this.build, this); + this.componentRegExp = __bind(this.componentRegExp, this); + this.bindingRegExp = __bind(this.bindingRegExp, this); + this.options = __bind(this.options, this); + if (!(this.els.jquery || this.els instanceof Array)) { + this.els = [this.els]; + } + _ref1 = Rivets.extensions; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + option = _ref1[_i]; + this[option] = {}; + if (options[option]) { + _ref2 = options[option]; + for (k in _ref2) { + v = _ref2[k]; + this[option][k] = v; + } + } + _ref3 = Rivets["public"][option]; + for (k in _ref3) { + v = _ref3[k]; + if ((_base = this[option])[k] == null) { + _base[k] = v; + } + } + } + _ref4 = Rivets.options; + for (_j = 0, _len1 = _ref4.length; _j < _len1; _j++) { + option = _ref4[_j]; + this[option] = options[option] || Rivets["public"][option]; + } + this.build(); + } + + View.prototype.options = function() { + var option, options, _i, _len, _ref1; + options = {}; + _ref1 = Rivets.extensions.concat(Rivets.options); + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + option = _ref1[_i]; + options[option] = this[option]; + } + return options; + }; + + View.prototype.bindingRegExp = function() { + return new RegExp("^" + this.prefix + "-"); + }; + + View.prototype.componentRegExp = function() { + return new RegExp("^" + (this.prefix.toUpperCase()) + "-"); + }; + + View.prototype.build = function() { + var bindingRegExp, buildBinding, componentRegExp, el, parse, _i, _len, _ref1; + this.bindings = []; + bindingRegExp = this.bindingRegExp(); + componentRegExp = this.componentRegExp(); + buildBinding = (function(_this) { + return function(binding, node, type, declaration) { + var context, ctx, dependencies, keypath, options, pipe, pipes; + options = {}; + pipes = (function() { + var _i, _len, _ref1, _results; + _ref1 = declaration.split('|'); + _results = []; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + pipe = _ref1[_i]; + _results.push(pipe.trim()); + } + return _results; + })(); + context = (function() { + var _i, _len, _ref1, _results; + _ref1 = pipes.shift().split('<'); + _results = []; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + ctx = _ref1[_i]; + _results.push(ctx.trim()); + } + return _results; + })(); + keypath = context.shift(); + options.formatters = pipes; + if (dependencies = context.shift()) { + options.dependencies = dependencies.split(/\s+/); + } + return _this.bindings.push(new Rivets[binding](_this, node, type, keypath, options)); + }; + })(this); + parse = (function(_this) { + return function(node) { + var attribute, attributes, binder, block, childNode, delimiters, identifier, n, parser, regexp, text, token, tokens, type, value, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref1, _ref2, _ref3, _ref4, _results; + if (node.nodeType === 3) { + parser = Rivets.TextTemplateParser; + if (delimiters = _this.templateDelimiters) { + if ((tokens = parser.parse(node.data, delimiters)).length) { + if (!(tokens.length === 1 && tokens[0].type === parser.types.text)) { + for (_i = 0, _len = tokens.length; _i < _len; _i++) { + token = tokens[_i]; + text = document.createTextNode(token.value); + node.parentNode.insertBefore(text, node); + if (token.type === 1) { + buildBinding('TextBinding', text, null, token.value); + } + } + node.parentNode.removeChild(node); + } + } + } + } else if (node.nodeType === 1) { + if (componentRegExp.test(node.nodeName)) { + type = node.nodeName.replace(componentRegExp, '').toLowerCase(); + _this.bindings.push(new Rivets.ComponentBinding(_this, node, type)); + } else { + block = node.nodeName === 'SCRIPT' || node.nodeName === 'STYLE'; + _ref1 = node.attributes; + for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { + attribute = _ref1[_j]; + if (bindingRegExp.test(attribute.name)) { + type = attribute.name.replace(bindingRegExp, ''); + if (!(binder = _this.binders[type])) { + _ref2 = _this.binders; + for (identifier in _ref2) { + value = _ref2[identifier]; + if (identifier !== '*' && identifier.indexOf('*') !== -1) { + regexp = new RegExp("^" + (identifier.replace(/\*/g, '.+')) + "$"); + if (regexp.test(type)) { + binder = value; + } + } + } + } + binder || (binder = _this.binders['*']); + if (binder.block) { + block = true; + attributes = [attribute]; + } + } + } + _ref3 = attributes || node.attributes; + for (_k = 0, _len2 = _ref3.length; _k < _len2; _k++) { + attribute = _ref3[_k]; + if (bindingRegExp.test(attribute.name)) { + type = attribute.name.replace(bindingRegExp, ''); + buildBinding('Binding', node, type, attribute.value); + } + } + } + } + if (!block) { + _ref4 = (function() { + var _len3, _m, _ref4, _results1; + _ref4 = node.childNodes; + _results1 = []; + for (_m = 0, _len3 = _ref4.length; _m < _len3; _m++) { + n = _ref4[_m]; + _results1.push(n); + } + return _results1; + })(); + _results = []; + for (_l = 0, _len3 = _ref4.length; _l < _len3; _l++) { + childNode = _ref4[_l]; + _results.push(parse(childNode)); + } + return _results; + } + }; + })(this); + _ref1 = this.els; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + el = _ref1[_i]; + parse(el); + } + this.bindings.sort(function(a, b) { + return (b.binder.priority || 0) - (a.binder.priority || 0); + }); + }; + + View.prototype.select = function(fn) { + var binding, _i, _len, _ref1, _results; + _ref1 = this.bindings; + _results = []; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + binding = _ref1[_i]; + if (fn(binding)) { + _results.push(binding); + } + } + return _results; + }; + + View.prototype.bind = function() { + var binding, _i, _len, _ref1, _results; + _ref1 = this.bindings; + _results = []; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + binding = _ref1[_i]; + _results.push(binding.bind()); + } + return _results; + }; + + View.prototype.unbind = function() { + var binding, _i, _len, _ref1, _results; + _ref1 = this.bindings; + _results = []; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + binding = _ref1[_i]; + _results.push(binding.unbind()); + } + return _results; + }; + + View.prototype.sync = function() { + var binding, _i, _len, _ref1, _results; + _ref1 = this.bindings; + _results = []; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + binding = _ref1[_i]; + _results.push(binding.sync()); + } + return _results; + }; + + View.prototype.publish = function() { + var binding, _i, _len, _ref1, _results; + _ref1 = this.select(function(b) { + return b.binder.publishes; + }); + _results = []; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + binding = _ref1[_i]; + _results.push(binding.publish()); + } + return _results; + }; + + View.prototype.update = function(models) { + var binding, key, model, _i, _len, _ref1, _results; + if (models == null) { + models = {}; + } + for (key in models) { + model = models[key]; + this.models[key] = model; + } + _ref1 = this.bindings; + _results = []; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + binding = _ref1[_i]; + _results.push(binding.update(models)); + } + return _results; + }; + + return View; + + })(); + + Rivets.Binding = (function() { + function Binding(view, el, type, keypath, options) { + this.view = view; + this.el = el; + this.type = type; + this.keypath = keypath; + this.options = options != null ? options : {}; + this.getValue = __bind(this.getValue, this); + this.update = __bind(this.update, this); + this.unbind = __bind(this.unbind, this); + this.bind = __bind(this.bind, this); + this.publish = __bind(this.publish, this); + this.sync = __bind(this.sync, this); + this.set = __bind(this.set, this); + this.eventHandler = __bind(this.eventHandler, this); + this.formattedValue = __bind(this.formattedValue, this); + this.parseTarget = __bind(this.parseTarget, this); + this.observe = __bind(this.observe, this); + this.setBinder = __bind(this.setBinder, this); + this.formatters = this.options.formatters || []; + this.dependencies = []; + this.formatterObservers = {}; + this.model = void 0; + this.setBinder(); + } + + Binding.prototype.setBinder = function() { + var identifier, regexp, value, _ref1; + if (!(this.binder = this.view.binders[this.type])) { + _ref1 = this.view.binders; + for (identifier in _ref1) { + value = _ref1[identifier]; + if (identifier !== '*' && identifier.indexOf('*') !== -1) { + regexp = new RegExp("^" + (identifier.replace(/\*/g, '.+')) + "$"); + if (regexp.test(this.type)) { + this.binder = value; + this.args = new RegExp("^" + (identifier.replace(/\*/g, '(.+)')) + "$").exec(this.type); + this.args.shift(); + } + } + } + } + this.binder || (this.binder = this.view.binders['*']); + if (this.binder instanceof Function) { + return this.binder = { + routine: this.binder + }; + } + }; + + Binding.prototype.observe = function(obj, keypath, callback) { + return Rivets.sightglass(obj, keypath, callback, { + root: this.view.rootInterface, + adapters: this.view.adapters + }); + }; + + Binding.prototype.parseTarget = function() { + var token; + token = Rivets.TypeParser.parse(this.keypath); + if (token.type === 0) { + return this.value = token.value; + } else { + this.observer = this.observe(this.view.models, this.keypath, this.sync); + return this.model = this.observer.target; + } + }; + + Binding.prototype.formattedValue = function(value) { + var ai, arg, args, fi, formatter, id, observer, processedArgs, _base, _i, _j, _len, _len1, _ref1; + _ref1 = this.formatters; + for (fi = _i = 0, _len = _ref1.length; _i < _len; fi = ++_i) { + formatter = _ref1[fi]; + args = formatter.match(/[^\s']+|'([^']|'[^\s])*'|"([^"]|"[^\s])*"/g); + id = args.shift(); + formatter = this.view.formatters[id]; + args = (function() { + var _j, _len1, _results; + _results = []; + for (_j = 0, _len1 = args.length; _j < _len1; _j++) { + arg = args[_j]; + _results.push(Rivets.TypeParser.parse(arg)); + } + return _results; + })(); + processedArgs = []; + for (ai = _j = 0, _len1 = args.length; _j < _len1; ai = ++_j) { + arg = args[ai]; + processedArgs.push(arg.type === 0 ? arg.value : ((_base = this.formatterObservers)[fi] || (_base[fi] = {}), !(observer = this.formatterObservers[fi][ai]) ? (observer = this.observe(this.view.models, arg.value, this.sync), this.formatterObservers[fi][ai] = observer) : void 0, observer.value())); + } + if ((formatter != null ? formatter.read : void 0) instanceof Function) { + value = formatter.read.apply(formatter, [value].concat(__slice.call(processedArgs))); + } else if (formatter instanceof Function) { + value = formatter.apply(null, [value].concat(__slice.call(processedArgs))); + } + } + return value; + }; + + Binding.prototype.eventHandler = function(fn) { + var binding, handler; + handler = (binding = this).view.handler; + return function(ev) { + return handler.call(fn, this, ev, binding); + }; + }; + + Binding.prototype.set = function(value) { + var _ref1; + value = value instanceof Function && !this.binder["function"] ? this.formattedValue(value.call(this.model)) : this.formattedValue(value); + return (_ref1 = this.binder.routine) != null ? _ref1.call(this, this.el, value) : void 0; + }; + + Binding.prototype.sync = function() { + var dependency, observer; + return this.set((function() { + var _i, _j, _len, _len1, _ref1, _ref2, _ref3; + if (this.observer) { + if (this.model !== this.observer.target) { + _ref1 = this.dependencies; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + observer = _ref1[_i]; + observer.unobserve(); + } + this.dependencies = []; + if (((this.model = this.observer.target) != null) && ((_ref2 = this.options.dependencies) != null ? _ref2.length : void 0)) { + _ref3 = this.options.dependencies; + for (_j = 0, _len1 = _ref3.length; _j < _len1; _j++) { + dependency = _ref3[_j]; + observer = this.observe(this.model, dependency, this.sync); + this.dependencies.push(observer); + } + } + } + return this.observer.value(); + } else { + return this.value; + } + }).call(this)); + }; + + Binding.prototype.publish = function() { + var args, formatter, id, value, _i, _len, _ref1, _ref2, _ref3; + if (this.observer) { + value = this.getValue(this.el); + _ref1 = this.formatters.slice(0).reverse(); + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + formatter = _ref1[_i]; + args = formatter.split(/\s+/); + id = args.shift(); + if ((_ref2 = this.view.formatters[id]) != null ? _ref2.publish : void 0) { + value = (_ref3 = this.view.formatters[id]).publish.apply(_ref3, [value].concat(__slice.call(args))); + } + } + return this.observer.setValue(value); + } + }; + + Binding.prototype.bind = function() { + var dependency, observer, _i, _len, _ref1, _ref2, _ref3; + this.parseTarget(); + if ((_ref1 = this.binder.bind) != null) { + _ref1.call(this, this.el); + } + if ((this.model != null) && ((_ref2 = this.options.dependencies) != null ? _ref2.length : void 0)) { + _ref3 = this.options.dependencies; + for (_i = 0, _len = _ref3.length; _i < _len; _i++) { + dependency = _ref3[_i]; + observer = this.observe(this.model, dependency, this.sync); + this.dependencies.push(observer); + } + } + if (this.view.preloadData) { + return this.sync(); + } + }; + + Binding.prototype.unbind = function() { + var ai, args, fi, observer, _i, _len, _ref1, _ref2, _ref3, _ref4; + if ((_ref1 = this.binder.unbind) != null) { + _ref1.call(this, this.el); + } + if ((_ref2 = this.observer) != null) { + _ref2.unobserve(); + } + _ref3 = this.dependencies; + for (_i = 0, _len = _ref3.length; _i < _len; _i++) { + observer = _ref3[_i]; + observer.unobserve(); + } + this.dependencies = []; + _ref4 = this.formatterObservers; + for (fi in _ref4) { + args = _ref4[fi]; + for (ai in args) { + observer = args[ai]; + observer.unobserve(); + } + } + return this.formatterObservers = {}; + }; + + Binding.prototype.update = function(models) { + var _ref1, _ref2; + if (models == null) { + models = {}; + } + this.model = (_ref1 = this.observer) != null ? _ref1.target : void 0; + this.unbind(); + if ((_ref2 = this.binder.update) != null) { + _ref2.call(this, models); + } + return this.bind(); + }; + + Binding.prototype.getValue = function(el) { + return (this.binder.getValue || Rivets.Util.getInputValue)(el); + }; + + return Binding; + + })(); + + Rivets.ComponentBinding = (function(_super) { + __extends(ComponentBinding, _super); + + function ComponentBinding(view, el, type) { + var attribute, _i, _len, _ref1, _ref2; + this.view = view; + this.el = el; + this.type = type; + this.unbind = __bind(this.unbind, this); + this.bind = __bind(this.bind, this); + this.update = __bind(this.update, this); + this.locals = __bind(this.locals, this); + this.component = this.view.components[this.type]; + this.attributes = {}; + this.inflections = {}; + _ref1 = this.el.attributes || []; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + attribute = _ref1[_i]; + if (_ref2 = attribute.name, __indexOf.call(this.component.attributes, _ref2) >= 0) { + this.attributes[attribute.name] = attribute.value; + } else { + this.inflections[attribute.name] = attribute.value; + } + } + } + + ComponentBinding.prototype.sync = function() {}; + + ComponentBinding.prototype.locals = function(models) { + var inverse, key, model, path, result, _i, _len, _ref1, _ref2; + if (models == null) { + models = this.view.models; + } + result = {}; + _ref1 = this.inflections; + for (key in _ref1) { + inverse = _ref1[key]; + _ref2 = inverse.split('.'); + for (_i = 0, _len = _ref2.length; _i < _len; _i++) { + path = _ref2[_i]; + result[key] = (result[key] || models)[path]; + } + } + for (key in models) { + model = models[key]; + if (result[key] == null) { + result[key] = model; + } + } + return result; + }; + + ComponentBinding.prototype.update = function(models) { + var _ref1; + return (_ref1 = this.componentView) != null ? _ref1.update(this.locals(models)) : void 0; + }; + + ComponentBinding.prototype.bind = function() { + var el, _ref1; + if (this.componentView != null) { + return (_ref1 = this.componentView) != null ? _ref1.bind() : void 0; + } else { + el = this.component.build.call(this.attributes); + (this.componentView = new Rivets.View(el, this.locals(), this.view.options)).bind(); + return this.el.parentNode.replaceChild(el, this.el); + } + }; + + ComponentBinding.prototype.unbind = function() { + var _ref1; + return (_ref1 = this.componentView) != null ? _ref1.unbind() : void 0; + }; + + return ComponentBinding; + + })(Rivets.Binding); + + Rivets.TextBinding = (function(_super) { + __extends(TextBinding, _super); + + function TextBinding(view, el, type, keypath, options) { + this.view = view; + this.el = el; + this.type = type; + this.keypath = keypath; + this.options = options != null ? options : {}; + this.sync = __bind(this.sync, this); + this.formatters = this.options.formatters || []; + this.dependencies = []; + this.formatterObservers = {}; + } + + TextBinding.prototype.binder = { + routine: function(node, value) { + return node.data = value != null ? value : ''; + } + }; + + TextBinding.prototype.sync = function() { + return TextBinding.__super__.sync.apply(this, arguments); + }; + + return TextBinding; + + })(Rivets.Binding); + + Rivets["public"].binders.text = function(el, value) { + if (el.textContent != null) { + return el.textContent = value != null ? value : ''; + } else { + return el.innerText = value != null ? value : ''; + } + }; + + Rivets["public"].binders.html = function(el, value) { + return el.innerHTML = value != null ? value : ''; + }; + + Rivets["public"].binders.show = function(el, value) { + return el.style.display = value ? '' : 'none'; + }; + + Rivets["public"].binders.hide = function(el, value) { + return el.style.display = value ? 'none' : ''; + }; + + Rivets["public"].binders.enabled = function(el, value) { + return el.disabled = !value; + }; + + Rivets["public"].binders.disabled = function(el, value) { + return el.disabled = !!value; + }; + + Rivets["public"].binders.checked = { + publishes: true, + priority: 2000, + bind: function(el) { + return Rivets.Util.bindEvent(el, 'change', this.publish); + }, + unbind: function(el) { + return Rivets.Util.unbindEvent(el, 'change', this.publish); + }, + routine: function(el, value) { + var _ref1; + if (el.type === 'radio') { + return el.checked = ((_ref1 = el.value) != null ? _ref1.toString() : void 0) === (value != null ? value.toString() : void 0); + } else { + return el.checked = !!value; + } + } + }; + + Rivets["public"].binders.unchecked = { + publishes: true, + priority: 2000, + bind: function(el) { + return Rivets.Util.bindEvent(el, 'change', this.publish); + }, + unbind: function(el) { + return Rivets.Util.unbindEvent(el, 'change', this.publish); + }, + routine: function(el, value) { + var _ref1; + if (el.type === 'radio') { + return el.checked = ((_ref1 = el.value) != null ? _ref1.toString() : void 0) !== (value != null ? value.toString() : void 0); + } else { + return el.checked = !value; + } + } + }; + + Rivets["public"].binders.value = { + publishes: true, + priority: 2000, + bind: function(el) { + this.event = el.tagName === 'SELECT' ? 'change' : 'input'; + return Rivets.Util.bindEvent(el, this.event, this.publish); + }, + unbind: function(el) { + return Rivets.Util.unbindEvent(el, this.event, this.publish); + }, + routine: function(el, value) { + var o, _i, _len, _ref1, _ref2, _ref3, _results; + if (window.jQuery != null) { + el = jQuery(el); + if ((value != null ? value.toString() : void 0) !== ((_ref1 = el.val()) != null ? _ref1.toString() : void 0)) { + return el.val(value != null ? value : ''); + } + } else { + if (el.type === 'select-multiple') { + if (value != null) { + _results = []; + for (_i = 0, _len = el.length; _i < _len; _i++) { + o = el[_i]; + _results.push(o.selected = (_ref2 = o.value, __indexOf.call(value, _ref2) >= 0)); + } + return _results; + } + } else if ((value != null ? value.toString() : void 0) !== ((_ref3 = el.value) != null ? _ref3.toString() : void 0)) { + return el.value = value != null ? value : ''; + } + } + } + }; + + Rivets["public"].binders["if"] = { + block: true, + priority: 3000, + bind: function(el) { + var attr, declaration; + if (this.marker == null) { + attr = [this.view.prefix, this.type].join('-').replace('--', '-'); + declaration = el.getAttribute(attr); + this.marker = document.createComment(" rivets: " + this.type + " " + declaration + " "); + this.bound = false; + el.removeAttribute(attr); + el.parentNode.insertBefore(this.marker, el); + return el.parentNode.removeChild(el); + } + }, + unbind: function() { + var _ref1; + return (_ref1 = this.nested) != null ? _ref1.unbind() : void 0; + }, + routine: function(el, value) { + var key, model, models, _ref1; + if (!!value === !this.bound) { + if (value) { + models = {}; + _ref1 = this.view.models; + for (key in _ref1) { + model = _ref1[key]; + models[key] = model; + } + (this.nested || (this.nested = new Rivets.View(el, models, this.view.options()))).bind(); + this.marker.parentNode.insertBefore(el, this.marker.nextSibling); + return this.bound = true; + } else { + el.parentNode.removeChild(el); + this.nested.unbind(); + return this.bound = false; + } + } + }, + update: function(models) { + var _ref1; + return (_ref1 = this.nested) != null ? _ref1.update(models) : void 0; + } + }; + + Rivets["public"].binders.unless = { + block: true, + priority: 3000, + bind: function(el) { + return Rivets["public"].binders["if"].bind.call(this, el); + }, + unbind: function() { + return Rivets["public"].binders["if"].unbind.call(this); + }, + routine: function(el, value) { + return Rivets["public"].binders["if"].routine.call(this, el, !value); + }, + update: function(models) { + return Rivets["public"].binders["if"].update.call(this, models); + } + }; + + Rivets["public"].binders['on-*'] = { + "function": true, + priority: 1000, + unbind: function(el) { + if (this.handler) { + return Rivets.Util.unbindEvent(el, this.args[0], this.handler); + } + }, + routine: function(el, value) { + if (this.handler) { + Rivets.Util.unbindEvent(el, this.args[0], this.handler); + } + return Rivets.Util.bindEvent(el, this.args[0], this.handler = this.eventHandler(value)); + } + }; + + Rivets["public"].binders['each-*'] = { + block: true, + priority: 3000, + bind: function(el) { + var attr, view, _i, _len, _ref1; + if (this.marker == null) { + attr = [this.view.prefix, this.type].join('-').replace('--', '-'); + this.marker = document.createComment(" rivets: " + this.type + " "); + this.iterated = []; + el.removeAttribute(attr); + el.parentNode.insertBefore(this.marker, el); + el.parentNode.removeChild(el); + } else { + _ref1 = this.iterated; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + view = _ref1[_i]; + view.bind(); + } + } + }, + unbind: function(el) { + var view, _i, _len, _ref1, _results; + if (this.iterated != null) { + _ref1 = this.iterated; + _results = []; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + view = _ref1[_i]; + _results.push(view.unbind()); + } + return _results; + } + }, + routine: function(el, collection) { + var binding, data, i, index, key, model, modelName, options, previous, template, view, _i, _j, _k, _len, _len1, _len2, _ref1, _ref2, _ref3, _results; + modelName = this.args[0]; + collection = collection || []; + if (this.iterated.length > collection.length) { + _ref1 = Array(this.iterated.length - collection.length); + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + i = _ref1[_i]; + view = this.iterated.pop(); + view.unbind(); + this.marker.parentNode.removeChild(view.els[0]); + } + } + for (index = _j = 0, _len1 = collection.length; _j < _len1; index = ++_j) { + model = collection[index]; + data = { + index: index + }; + data[modelName] = model; + if (this.iterated[index] == null) { + _ref2 = this.view.models; + for (key in _ref2) { + model = _ref2[key]; + if (data[key] == null) { + data[key] = model; + } + } + previous = this.iterated.length ? this.iterated[this.iterated.length - 1].els[0] : this.marker; + options = this.view.options(); + options.preloadData = true; + template = el.cloneNode(true); + view = new Rivets.View(template, data, options); + view.bind(); + this.iterated.push(view); + this.marker.parentNode.insertBefore(template, previous.nextSibling); + } else if (this.iterated[index].models[modelName] !== model) { + this.iterated[index].update(data); + } + } + if (el.nodeName === 'OPTION') { + _ref3 = this.view.bindings; + _results = []; + for (_k = 0, _len2 = _ref3.length; _k < _len2; _k++) { + binding = _ref3[_k]; + if (binding.el === this.marker.parentNode && binding.type === 'value') { + _results.push(binding.sync()); + } else { + _results.push(void 0); + } + } + return _results; + } + }, + update: function(models) { + var data, key, model, view, _i, _len, _ref1, _results; + data = {}; + for (key in models) { + model = models[key]; + if (key !== this.args[0]) { + data[key] = model; + } + } + _ref1 = this.iterated; + _results = []; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + view = _ref1[_i]; + _results.push(view.update(data)); + } + return _results; + } + }; + + Rivets["public"].binders['class-*'] = function(el, value) { + var elClass; + elClass = " " + el.className + " "; + if (!value === (elClass.indexOf(" " + this.args[0] + " ") !== -1)) { + return el.className = value ? "" + el.className + " " + this.args[0] : elClass.replace(" " + this.args[0] + " ", ' ').trim(); + } + }; + + Rivets["public"].binders['*'] = function(el, value) { + if (value != null) { + return el.setAttribute(this.type, value); + } else { + return el.removeAttribute(this.type); + } + }; + + Rivets["public"].adapters['.'] = { + id: '_rv', + counter: 0, + weakmap: {}, + weakReference: function(obj) { + var id; + if (!obj.hasOwnProperty(this.id)) { + id = this.counter++; + this.weakmap[id] = { + callbacks: {} + }; + Object.defineProperty(obj, this.id, { + value: id + }); + } + return this.weakmap[obj[this.id]]; + }, + stubFunction: function(obj, fn) { + var map, original, weakmap; + original = obj[fn]; + map = this.weakReference(obj); + weakmap = this.weakmap; + return obj[fn] = function() { + var callback, k, r, response, _i, _len, _ref1, _ref2, _ref3, _ref4; + response = original.apply(obj, arguments); + _ref1 = map.pointers; + for (r in _ref1) { + k = _ref1[r]; + _ref4 = (_ref2 = (_ref3 = weakmap[r]) != null ? _ref3.callbacks[k] : void 0) != null ? _ref2 : []; + for (_i = 0, _len = _ref4.length; _i < _len; _i++) { + callback = _ref4[_i]; + callback(); + } + } + return response; + }; + }, + observeMutations: function(obj, ref, keypath) { + var fn, functions, map, _base, _i, _len; + if (Array.isArray(obj)) { + map = this.weakReference(obj); + if (map.pointers == null) { + map.pointers = {}; + functions = ['push', 'pop', 'shift', 'unshift', 'sort', 'reverse', 'splice']; + for (_i = 0, _len = functions.length; _i < _len; _i++) { + fn = functions[_i]; + this.stubFunction(obj, fn); + } + } + if ((_base = map.pointers)[ref] == null) { + _base[ref] = []; + } + if (__indexOf.call(map.pointers[ref], keypath) < 0) { + return map.pointers[ref].push(keypath); + } + } + }, + unobserveMutations: function(obj, ref, keypath) { + var idx, keypaths, _ref1; + if (Array.isArray(obj && (obj[this.id] != null))) { + if (keypaths = (_ref1 = this.weakReference(obj).pointers) != null ? _ref1[ref] : void 0) { + idx = keypaths.indexOf(keypath); + if (idx >= 0) { + return keypaths.splice(idx, 1); + } + } + } + }, + observe: function(obj, keypath, callback) { + var callbacks, value; + callbacks = this.weakReference(obj).callbacks; + if (callbacks[keypath] == null) { + callbacks[keypath] = []; + value = obj[keypath]; + Object.defineProperty(obj, keypath, { + enumerable: true, + get: function() { + return value; + }, + set: (function(_this) { + return function(newValue) { + var _i, _len, _ref1; + if (newValue !== value) { + value = newValue; + _ref1 = callbacks[keypath].slice(); + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + callback = _ref1[_i]; + if (__indexOf.call(callbacks[keypath], callback) >= 0) { + callback(); + } + } + return _this.observeMutations(newValue, obj[_this.id], keypath); + } + }; + })(this) + }); + } + if (__indexOf.call(callbacks[keypath], callback) < 0) { + callbacks[keypath].push(callback); + } + return this.observeMutations(obj[keypath], obj[this.id], keypath); + }, + unobserve: function(obj, keypath, callback) { + var callbacks, idx; + callbacks = this.weakmap[obj[this.id]].callbacks[keypath]; + idx = callbacks.indexOf(callback); + if (idx >= 0) { + callbacks.splice(idx, 1); + } + return this.unobserveMutations(obj[keypath], obj[this.id], keypath); + }, + get: function(obj, keypath) { + return obj[keypath]; + }, + set: function(obj, keypath, value) { + return obj[keypath] = value; + } + }; + + Rivets.factory = function(sightglass) { + Rivets.sightglass = sightglass; + Rivets["public"]._ = Rivets; + return Rivets["public"]; + }; + + if (typeof (typeof module !== "undefined" && module !== null ? module.exports : void 0) === 'object') { + module.exports = Rivets.factory(require('sightglass')); + } else if (typeof define === 'function' && define.amd) { + define(['sightglass'], function(sightglass) { + return this.rivets = Rivets.factory(sightglass); + }); + } else { + this.rivets = Rivets.factory(sightglass); + } + +}).call(this); diff --git a/ajax/libs/rivets/0.7.0/rivets.min.js b/ajax/libs/rivets/0.7.0/rivets.min.js new file mode 100644 index 000000000..6a258b63b --- /dev/null +++ b/ajax/libs/rivets/0.7.0/rivets.min.js @@ -0,0 +1,5 @@ +// Rivets.js +// version: 0.7.0 +// author: Michael Richards +// license: MIT +(function(){var t,e,i,n,r=function(t,e){return function(){return t.apply(e,arguments)}},s=[].slice,o={}.hasOwnProperty,u=function(t,e){function i(){this.constructor=t}for(var n in e)o.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t},h=[].indexOf||function(t){for(var e=0,i=this.length;i>e;e++)if(e in this&&this[e]===t)return e;return-1};t={options:["prefix","templateDelimiters","rootInterface","preloadData","handler"],extensions:["binders","formatters","components","adapters"],"public":{binders:{},components:{},formatters:{},adapters:{},prefix:"rv",templateDelimiters:["{","}"],rootInterface:".",preloadData:!0,handler:function(t,e,i){return this.call(t,e,i.view.models)},configure:function(e){var i,n,r,s;null==e&&(e={});for(r in e)if(s=e[r],"binders"===r||"components"===r||"formatters"===r||"adapters"===r)for(n in s)i=s[n],t[r][n]=i;else t["public"][r]=s},bind:function(e,i,n){var r;return null==i&&(i={}),null==n&&(n={}),r=new t.View(e,i,n),r.bind(),r}}},window.jQuery||window.$?(n="on"in jQuery.prototype?["on","off"]:["bind","unbind"],e=n[0],i=n[1],t.Util={bindEvent:function(t,i,n){return jQuery(t)[e](i,n)},unbindEvent:function(t,e,n){return jQuery(t)[i](e,n)},getInputValue:function(t){var e;return e=jQuery(t),"checkbox"===e.attr("type")?e.is(":checked"):e.val()}}):t.Util={bindEvent:function(){return"addEventListener"in window?function(t,e,i){return t.addEventListener(e,i,!1)}:function(t,e,i){return t.attachEvent("on"+e,i)}}(),unbindEvent:function(){return"removeEventListener"in window?function(t,e,i){return t.removeEventListener(e,i,!1)}:function(t,e,i){return t.detachEvent("on"+e,i)}}(),getInputValue:function(t){var e,i,n,r;if("checkbox"===t.type)return t.checked;if("select-multiple"===t.type){for(r=[],i=0,n=t.length;n>i;i++)e=t[i],e.selected&&r.push(e.value);return r}return t.value}},t.TypeParser=function(){function t(){}return t.types={primitive:0,keypath:1},t.parse=function(t){return/^'.*'$|^".*"$/.test(t)?{type:this.types.primitive,value:t.slice(1,-1)}:"true"===t?{type:this.types.primitive,value:!0}:"false"===t?{type:this.types.primitive,value:!1}:"null"===t?{type:this.types.primitive,value:null}:"undefined"===t?{type:this.types.primitive,value:void 0}:isNaN(Number(t))===!1?{type:this.types.primitive,value:Number(t)}:{type:this.types.keypath,value:t}},t}(),t.TextTemplateParser=function(){function t(){}return t.types={text:0,binding:1},t.parse=function(t,e){var i,n,r,s,o,u,h;for(u=[],s=t.length,i=0,n=0;s>n;){if(i=t.indexOf(e[0],n),0>i){u.push({type:this.types.text,value:t.slice(n)});break}if(i>0&&i>n&&u.push({type:this.types.text,value:t.slice(n,i)}),n=i+e[0].length,i=t.indexOf(e[1],n),0>i){o=t.slice(n-e[1].length),r=u[u.length-1],(null!=r?r.type:void 0)===this.types.text?r.value+=o:u.push({type:this.types.text,value:o});break}h=t.slice(n,i).trim(),u.push({type:this.types.binding,value:h}),n=i+e[1].length}return u},t}(),t.View=function(){function e(e,i,n){var s,o,u,h,l,a,p,d,c,f,b,v;for(this.els=e,this.models=i,null==n&&(n={}),this.update=r(this.update,this),this.publish=r(this.publish,this),this.sync=r(this.sync,this),this.unbind=r(this.unbind,this),this.bind=r(this.bind,this),this.select=r(this.select,this),this.build=r(this.build,this),this.componentRegExp=r(this.componentRegExp,this),this.bindingRegExp=r(this.bindingRegExp,this),this.options=r(this.options,this),this.els.jquery||this.els instanceof Array||(this.els=[this.els]),c=t.extensions,l=0,p=c.length;p>l;l++){if(o=c[l],this[o]={},n[o]){f=n[o];for(s in f)u=f[s],this[o][s]=u}b=t["public"][o];for(s in b)u=b[s],null==(h=this[o])[s]&&(h[s]=u)}for(v=t.options,a=0,d=v.length;d>a;a++)o=v[a],this[o]=n[o]||t["public"][o];this.build()}return e.prototype.options=function(){var e,i,n,r,s;for(i={},s=t.extensions.concat(t.options),n=0,r=s.length;r>n;n++)e=s[n],i[e]=this[e];return i},e.prototype.bindingRegExp=function(){return new RegExp("^"+this.prefix+"-")},e.prototype.componentRegExp=function(){return new RegExp("^"+this.prefix.toUpperCase()+"-")},e.prototype.build=function(){var e,i,n,r,s,o,u,h;for(this.bindings=[],e=this.bindingRegExp(),n=this.componentRegExp(),i=function(e){return function(i,n,r,s){var o,u,h,l,a,p,d;return a={},d=function(){var t,e,i,n;for(i=s.split("|"),n=[],t=0,e=i.length;e>t;t++)p=i[t],n.push(p.trim());return n}(),o=function(){var t,e,i,n;for(i=d.shift().split("<"),n=[],t=0,e=i.length;e>t;t++)u=i[t],n.push(u.trim());return n}(),l=o.shift(),a.formatters=d,(h=o.shift())&&(a.dependencies=h.split(/\s+/)),e.bindings.push(new t[i](e,n,r,l,a))}}(this),s=function(r){return function(o){var u,h,l,a,p,d,c,f,b,v,y,g,m,w,x,k,E,N,V,T,O,R,B,C,j,S,U,A;if(3===o.nodeType){if(b=t.TextTemplateParser,(d=r.templateDelimiters)&&(m=b.parse(o.data,d)).length&&(1!==m.length||m[0].type!==b.types.text)){for(k=0,T=m.length;T>k;k++)g=m[k],y=document.createTextNode(g.value),o.parentNode.insertBefore(y,o),1===g.type&&i("TextBinding",y,null,g.value);o.parentNode.removeChild(o)}}else if(1===o.nodeType)if(n.test(o.nodeName))w=o.nodeName.replace(n,"").toLowerCase(),r.bindings.push(new t.ComponentBinding(r,o,w));else{for(a="SCRIPT"===o.nodeName||"STYLE"===o.nodeName,C=o.attributes,E=0,O=C.length;O>E;E++)if(u=C[E],e.test(u.name)){if(w=u.name.replace(e,""),!(l=r.binders[w])){j=r.binders;for(c in j)x=j[c],"*"!==c&&-1!==c.indexOf("*")&&(v=new RegExp("^"+c.replace(/\*/g,".+")+"$"),v.test(w)&&(l=x))}l||(l=r.binders["*"]),l.block&&(a=!0,h=[u])}for(S=h||o.attributes,N=0,R=S.length;R>N;N++)u=S[N],e.test(u.name)&&(w=u.name.replace(e,""),i("Binding",o,w,u.value))}if(!a){for(U=function(){var t,e,i,n;for(i=o.childNodes,n=[],e=0,t=i.length;t>e;e++)f=i[e],n.push(f);return n}(),A=[],V=0,B=U.length;B>V;V++)p=U[V],A.push(s(p));return A}}}(this),h=this.els,o=0,u=h.length;u>o;o++)r=h[o],s(r);this.bindings.sort(function(t,e){return(e.binder.priority||0)-(t.binder.priority||0)})},e.prototype.select=function(t){var e,i,n,r,s;for(r=this.bindings,s=[],i=0,n=r.length;n>i;i++)e=r[i],t(e)&&s.push(e);return s},e.prototype.bind=function(){var t,e,i,n,r;for(n=this.bindings,r=[],e=0,i=n.length;i>e;e++)t=n[e],r.push(t.bind());return r},e.prototype.unbind=function(){var t,e,i,n,r;for(n=this.bindings,r=[],e=0,i=n.length;i>e;e++)t=n[e],r.push(t.unbind());return r},e.prototype.sync=function(){var t,e,i,n,r;for(n=this.bindings,r=[],e=0,i=n.length;i>e;e++)t=n[e],r.push(t.sync());return r},e.prototype.publish=function(){var t,e,i,n,r;for(n=this.select(function(t){return t.binder.publishes}),r=[],e=0,i=n.length;i>e;e++)t=n[e],r.push(t.publish());return r},e.prototype.update=function(t){var e,i,n,r,s,o,u;null==t&&(t={});for(i in t)n=t[i],this.models[i]=n;for(o=this.bindings,u=[],r=0,s=o.length;s>r;r++)e=o[r],u.push(e.update(t));return u},e}(),t.Binding=function(){function e(t,e,i,n,s){this.view=t,this.el=e,this.type=i,this.keypath=n,this.options=null!=s?s:{},this.getValue=r(this.getValue,this),this.update=r(this.update,this),this.unbind=r(this.unbind,this),this.bind=r(this.bind,this),this.publish=r(this.publish,this),this.sync=r(this.sync,this),this.set=r(this.set,this),this.eventHandler=r(this.eventHandler,this),this.formattedValue=r(this.formattedValue,this),this.parseTarget=r(this.parseTarget,this),this.observe=r(this.observe,this),this.setBinder=r(this.setBinder,this),this.formatters=this.options.formatters||[],this.dependencies=[],this.formatterObservers={},this.model=void 0,this.setBinder()}return e.prototype.setBinder=function(){var t,e,i,n;if(!(this.binder=this.view.binders[this.type])){n=this.view.binders;for(t in n)i=n[t],"*"!==t&&-1!==t.indexOf("*")&&(e=new RegExp("^"+t.replace(/\*/g,".+")+"$"),e.test(this.type)&&(this.binder=i,this.args=new RegExp("^"+t.replace(/\*/g,"(.+)")+"$").exec(this.type),this.args.shift()))}return this.binder||(this.binder=this.view.binders["*"]),this.binder instanceof Function?this.binder={routine:this.binder}:void 0},e.prototype.observe=function(e,i,n){return t.sightglass(e,i,n,{root:this.view.rootInterface,adapters:this.view.adapters})},e.prototype.parseTarget=function(){var e;return e=t.TypeParser.parse(this.keypath),0===e.type?this.value=e.value:(this.observer=this.observe(this.view.models,this.keypath,this.sync),this.model=this.observer.target)},e.prototype.formattedValue=function(e){var i,n,r,o,u,h,l,a,p,d,c,f,b,v;for(v=this.formatters,o=d=0,f=v.length;f>d;o=++d){for(u=v[o],r=u.match(/[^\s']+|'([^']|'[^\s])*'|"([^"]|"[^\s])*"/g),h=r.shift(),u=this.view.formatters[h],r=function(){var e,i,s;for(s=[],e=0,i=r.length;i>e;e++)n=r[e],s.push(t.TypeParser.parse(n));return s}(),a=[],i=c=0,b=r.length;b>c;i=++c)n=r[i],a.push(0===n.type?n.value:((p=this.formatterObservers)[o]||(p[o]={}),(l=this.formatterObservers[o][i])?void 0:(l=this.observe(this.view.models,n.value,this.sync),this.formatterObservers[o][i]=l),l.value()));(null!=u?u.read:void 0)instanceof Function?e=u.read.apply(u,[e].concat(s.call(a))):u instanceof Function&&(e=u.apply(null,[e].concat(s.call(a))))}return e},e.prototype.eventHandler=function(t){var e,i;return i=(e=this).view.handler,function(n){return i.call(t,this,n,e)}},e.prototype.set=function(t){var e;return t=t instanceof Function&&!this.binder["function"]?this.formattedValue(t.call(this.model)):this.formattedValue(t),null!=(e=this.binder.routine)?e.call(this,this.el,t):void 0},e.prototype.sync=function(){var t,e;return this.set(function(){var i,n,r,s,o,u,h;if(this.observer){if(this.model!==this.observer.target){for(o=this.dependencies,i=0,r=o.length;r>i;i++)e=o[i],e.unobserve();if(this.dependencies=[],null!=(this.model=this.observer.target)&&(null!=(u=this.options.dependencies)?u.length:void 0))for(h=this.options.dependencies,n=0,s=h.length;s>n;n++)t=h[n],e=this.observe(this.model,t,this.sync),this.dependencies.push(e)}return this.observer.value()}return this.value}.call(this))},e.prototype.publish=function(){var t,e,i,n,r,o,u,h,l;if(this.observer){for(n=this.getValue(this.el),u=this.formatters.slice(0).reverse(),r=0,o=u.length;o>r;r++)e=u[r],t=e.split(/\s+/),i=t.shift(),(null!=(h=this.view.formatters[i])?h.publish:void 0)&&(n=(l=this.view.formatters[i]).publish.apply(l,[n].concat(s.call(t))));return this.observer.setValue(n)}},e.prototype.bind=function(){var t,e,i,n,r,s,o;if(this.parseTarget(),null!=(r=this.binder.bind)&&r.call(this,this.el),null!=this.model&&(null!=(s=this.options.dependencies)?s.length:void 0))for(o=this.options.dependencies,i=0,n=o.length;n>i;i++)t=o[i],e=this.observe(this.model,t,this.sync),this.dependencies.push(e);return this.view.preloadData?this.sync():void 0},e.prototype.unbind=function(){var t,e,i,n,r,s,o,u,h,l;for(null!=(o=this.binder.unbind)&&o.call(this,this.el),null!=(u=this.observer)&&u.unobserve(),h=this.dependencies,r=0,s=h.length;s>r;r++)n=h[r],n.unobserve();this.dependencies=[],l=this.formatterObservers;for(i in l){e=l[i];for(t in e)n=e[t],n.unobserve()}return this.formatterObservers={}},e.prototype.update=function(t){var e,i;return null==t&&(t={}),this.model=null!=(e=this.observer)?e.target:void 0,this.unbind(),null!=(i=this.binder.update)&&i.call(this,t),this.bind()},e.prototype.getValue=function(e){return(this.binder.getValue||t.Util.getInputValue)(e)},e}(),t.ComponentBinding=function(e){function i(t,e,i){var n,s,o,u,l;for(this.view=t,this.el=e,this.type=i,this.unbind=r(this.unbind,this),this.bind=r(this.bind,this),this.update=r(this.update,this),this.locals=r(this.locals,this),this.component=this.view.components[this.type],this.attributes={},this.inflections={},u=this.el.attributes||[],s=0,o=u.length;o>s;s++)n=u[s],l=n.name,h.call(this.component.attributes,l)>=0?this.attributes[n.name]=n.value:this.inflections[n.name]=n.value}return u(i,e),i.prototype.sync=function(){},i.prototype.locals=function(t){var e,i,n,r,s,o,u,h,l;null==t&&(t=this.view.models),s={},h=this.inflections;for(i in h)for(e=h[i],l=e.split("."),o=0,u=l.length;u>o;o++)r=l[o],s[i]=(s[i]||t)[r];for(i in t)n=t[i],null==s[i]&&(s[i]=n);return s},i.prototype.update=function(t){var e;return null!=(e=this.componentView)?e.update(this.locals(t)):void 0},i.prototype.bind=function(){var e,i;return null!=this.componentView?null!=(i=this.componentView)?i.bind():void 0:(e=this.component.build.call(this.attributes),(this.componentView=new t.View(e,this.locals(),this.view.options)).bind(),this.el.parentNode.replaceChild(e,this.el))},i.prototype.unbind=function(){var t;return null!=(t=this.componentView)?t.unbind():void 0},i}(t.Binding),t.TextBinding=function(t){function e(t,e,i,n,s){this.view=t,this.el=e,this.type=i,this.keypath=n,this.options=null!=s?s:{},this.sync=r(this.sync,this),this.formatters=this.options.formatters||[],this.dependencies=[],this.formatterObservers={}}return u(e,t),e.prototype.binder={routine:function(t,e){return t.data=null!=e?e:""}},e.prototype.sync=function(){return e.__super__.sync.apply(this,arguments)},e}(t.Binding),t["public"].binders.text=function(t,e){return null!=t.textContent?t.textContent=null!=e?e:"":t.innerText=null!=e?e:""},t["public"].binders.html=function(t,e){return t.innerHTML=null!=e?e:""},t["public"].binders.show=function(t,e){return t.style.display=e?"":"none"},t["public"].binders.hide=function(t,e){return t.style.display=e?"none":""},t["public"].binders.enabled=function(t,e){return t.disabled=!e},t["public"].binders.disabled=function(t,e){return t.disabled=!!e},t["public"].binders.checked={publishes:!0,priority:2e3,bind:function(e){return t.Util.bindEvent(e,"change",this.publish)},unbind:function(e){return t.Util.unbindEvent(e,"change",this.publish)},routine:function(t,e){var i;return t.checked="radio"===t.type?(null!=(i=t.value)?i.toString():void 0)===(null!=e?e.toString():void 0):!!e}},t["public"].binders.unchecked={publishes:!0,priority:2e3,bind:function(e){return t.Util.bindEvent(e,"change",this.publish)},unbind:function(e){return t.Util.unbindEvent(e,"change",this.publish)},routine:function(t,e){var i;return t.checked="radio"===t.type?(null!=(i=t.value)?i.toString():void 0)!==(null!=e?e.toString():void 0):!e}},t["public"].binders.value={publishes:!0,priority:2e3,bind:function(e){return this.event="SELECT"===e.tagName?"change":"input",t.Util.bindEvent(e,this.event,this.publish)},unbind:function(e){return t.Util.unbindEvent(e,this.event,this.publish)},routine:function(t,e){var i,n,r,s,o,u,l;if(null!=window.jQuery){if(t=jQuery(t),(null!=e?e.toString():void 0)!==(null!=(s=t.val())?s.toString():void 0))return t.val(null!=e?e:"")}else if("select-multiple"===t.type){if(null!=e){for(l=[],n=0,r=t.length;r>n;n++)i=t[n],l.push(i.selected=(o=i.value,h.call(e,o)>=0));return l}}else if((null!=e?e.toString():void 0)!==(null!=(u=t.value)?u.toString():void 0))return t.value=null!=e?e:""}},t["public"].binders["if"]={block:!0,priority:3e3,bind:function(t){var e,i;return null==this.marker?(e=[this.view.prefix,this.type].join("-").replace("--","-"),i=t.getAttribute(e),this.marker=document.createComment(" rivets: "+this.type+" "+i+" "),this.bound=!1,t.removeAttribute(e),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(e,i){var n,r,s,o;if(!!i==!this.bound){if(i){s={},o=this.view.models;for(n in o)r=o[n],s[n]=r;return(this.nested||(this.nested=new t.View(e,s,this.view.options()))).bind(),this.marker.parentNode.insertBefore(e,this.marker.nextSibling),this.bound=!0}return e.parentNode.removeChild(e),this.nested.unbind(),this.bound=!1}},update:function(t){var e;return null!=(e=this.nested)?e.update(t):void 0}},t["public"].binders.unless={block:!0,priority:3e3,bind:function(e){return t["public"].binders["if"].bind.call(this,e)},unbind:function(){return t["public"].binders["if"].unbind.call(this)},routine:function(e,i){return t["public"].binders["if"].routine.call(this,e,!i)},update:function(e){return t["public"].binders["if"].update.call(this,e)}},t["public"].binders["on-*"]={"function":!0,priority:1e3,unbind:function(e){return this.handler?t.Util.unbindEvent(e,this.args[0],this.handler):void 0},routine:function(e,i){return this.handler&&t.Util.unbindEvent(e,this.args[0],this.handler),t.Util.bindEvent(e,this.args[0],this.handler=this.eventHandler(i))}},t["public"].binders["each-*"]={block:!0,priority:3e3,bind:function(t){var e,i,n,r,s;if(null==this.marker)e=[this.view.prefix,this.type].join("-").replace("--","-"),this.marker=document.createComment(" rivets: "+this.type+" "),this.iterated=[],t.removeAttribute(e),t.parentNode.insertBefore(this.marker,t),t.parentNode.removeChild(t);else for(s=this.iterated,n=0,r=s.length;r>n;n++)i=s[n],i.bind()},unbind:function(){var t,e,i,n,r;if(null!=this.iterated){for(n=this.iterated,r=[],e=0,i=n.length;i>e;e++)t=n[e],r.push(t.unbind());return r}},routine:function(e,i){var n,r,s,o,u,h,l,a,p,d,c,f,b,v,y,g,m,w,x,k,E;if(l=this.args[0],i=i||[],this.iterated.length>i.length)for(w=Array(this.iterated.length-i.length),f=0,y=w.length;y>f;f++)s=w[f],c=this.iterated.pop(),c.unbind(),this.marker.parentNode.removeChild(c.els[0]);for(o=b=0,g=i.length;g>b;o=++b)if(h=i[o],r={index:o},r[l]=h,null==this.iterated[o]){x=this.view.models;for(u in x)h=x[u],null==r[u]&&(r[u]=h);p=this.iterated.length?this.iterated[this.iterated.length-1].els[0]:this.marker,a=this.view.options(),a.preloadData=!0,d=e.cloneNode(!0),c=new t.View(d,r,a),c.bind(),this.iterated.push(c),this.marker.parentNode.insertBefore(d,p.nextSibling)}else this.iterated[o].models[l]!==h&&this.iterated[o].update(r);if("OPTION"===e.nodeName){for(k=this.view.bindings,E=[],v=0,m=k.length;m>v;v++)n=k[v],n.el===this.marker.parentNode&&"value"===n.type?E.push(n.sync()):E.push(void 0);return E}},update:function(t){var e,i,n,r,s,o,u,h;e={};for(i in t)n=t[i],i!==this.args[0]&&(e[i]=n);for(u=this.iterated,h=[],s=0,o=u.length;o>s;s++)r=u[s],h.push(r.update(e));return h}},t["public"].binders["class-*"]=function(t,e){var i;return i=" "+t.className+" ",!e==(-1!==i.indexOf(" "+this.args[0]+" "))?t.className=e?""+t.className+" "+this.args[0]:i.replace(" "+this.args[0]+" "," ").trim():void 0},t["public"].binders["*"]=function(t,e){return null!=e?t.setAttribute(this.type,e):t.removeAttribute(this.type)},t["public"].adapters["."]={id:"_rv",counter:0,weakmap:{},weakReference:function(t){var e;return t.hasOwnProperty(this.id)||(e=this.counter++,this.weakmap[e]={callbacks:{}},Object.defineProperty(t,this.id,{value:e})),this.weakmap[t[this.id]]},stubFunction:function(t,e){var i,n,r;return n=t[e],i=this.weakReference(t),r=this.weakmap,t[e]=function(){var e,s,o,u,h,l,a,p,d,c;u=n.apply(t,arguments),a=i.pointers;for(o in a)for(s=a[o],c=null!=(p=null!=(d=r[o])?d.callbacks[s]:void 0)?p:[],h=0,l=c.length;l>h;h++)e=c[h],e();return u}},observeMutations:function(t,e,i){var n,r,s,o,u,l;if(Array.isArray(t)){if(s=this.weakReference(t),null==s.pointers)for(s.pointers={},r=["push","pop","shift","unshift","sort","reverse","splice"],u=0,l=r.length;l>u;u++)n=r[u],this.stubFunction(t,n);if(null==(o=s.pointers)[e]&&(o[e]=[]),h.call(s.pointers[e],i)<0)return s.pointers[e].push(i)}},unobserveMutations:function(t,e,i){var n,r,s;return Array.isArray(t&&null!=t[this.id])&&(r=null!=(s=this.weakReference(t).pointers)?s[e]:void 0)&&(n=r.indexOf(i),n>=0)?r.splice(n,1):void 0},observe:function(t,e,i){var n,r;return n=this.weakReference(t).callbacks,null==n[e]&&(n[e]=[],r=t[e],Object.defineProperty(t,e,{enumerable:!0,get:function(){return r},set:function(s){return function(o){var u,l,a;if(o!==r){for(r=o,a=n[e].slice(),u=0,l=a.length;l>u;u++)i=a[u],h.call(n[e],i)>=0&&i();return s.observeMutations(o,t[s.id],e)}}}(this)})),h.call(n[e],i)<0&&n[e].push(i),this.observeMutations(t[e],t[this.id],e)},unobserve:function(t,e,i){var n,r;return n=this.weakmap[t[this.id]].callbacks[e],r=n.indexOf(i),r>=0&&n.splice(r,1),this.unobserveMutations(t[e],t[this.id],e)},get:function(t,e){return t[e]},set:function(t,e,i){return t[e]=i}},t.factory=function(e){return t.sightglass=e,t["public"]._=t,t["public"]},"object"==typeof("undefined"!=typeof module&&null!==module?module.exports:void 0)?module.exports=t.factory(require("sightglass")):"function"==typeof define&&define.amd?define(["sightglass"],function(e){return this.rivets=t.factory(e)}):this.rivets=t.factory(sightglass)}).call(this); \ No newline at end of file diff --git a/ajax/libs/rivets/package.json b/ajax/libs/rivets/package.json index 6d2bb8e23..63a8c0721 100644 --- a/ajax/libs/rivets/package.json +++ b/ajax/libs/rivets/package.json @@ -1,7 +1,7 @@ { "name": "rivets", "filename": "rivets.min.js", - "version": "0.6.10", + "version": "0.7.0", "description": "Data binding + templating solution.", "license": "MIT", "homepage": "http://rivetsjs.com",