UNPKG

ractive

Version:

Next-generation DOM manipulation

1 lines 22.8 kB
(function(t){"use strict";var e=function(t){var e,i;return e=function(t){var n,r;if(t)for(r in t)t.hasOwnProperty(r)&&(this[r]=t[r]);n={preserveWhitespace:!1,append:!1,twoway:!0,formatters:{},modifyArrays:!0};for(r in n)n.hasOwnProperty(r)&&void 0===this[r]&&(this[r]=n[r]);if(void 0!==this.el&&(this.el=i(this.el)),this._subs={},void 0===this.viewmodel&&(this.viewmodel=new e.ViewModel),this.viewmodel.dependents.push(this),this.data&&this.viewmodel.set(this.data),this.partials)for(r in this.partials)if(this.partials.hasOwnProperty(r)&&"string"==typeof this.partials[r]){if(!e.compile)throw Error('Missing Ractive.compile - cannot compile partial "'+r+'". Either precompile or use the version that includes the compiler');this.partials[r]=e.compile(this.partials[r],this)}if("string"==typeof this.template){if(!e.compile)throw Error("Missing Ractive.compile - cannot compile template. Either precompile or use the version that includes the compiler");this.template=e.compile(this.template,this)}this.el&&this.render({el:this.el,callback:this.callback,append:this.append})},e.prototype={render:function(t){var n=t.el?i(t.el):this.el;if(!n)throw Error("You must specify a DOM element to render to");t.append||(n.innerHTML=""),t.callback&&(this.callback=t.callback),this.rendered=new e.DomFragment({model:this.template,root:this,parentNode:n})},teardown:function(){this.rendered.teardown()},set:function(){return this.viewmodel.set.apply(this.viewmodel,arguments),this},get:function(){return this.viewmodel.get.apply(this.viewmodel,arguments)},update:function(){return this.viewmodel.update.apply(this.viewmodel,arguments),this},_format:function(t,i){var n,r,s,o,a,h;if(!i)return t;for(r=i.length,n=0;r>n;n+=1)s=i[n],o=s.name,a=s.args||[],h=this.formatters[o]||e.formatters[o],h&&(t=h.apply(this,[t].concat(a)));return t}},i=function(e){var i,n;if(t.document){if(n=t.document,!e)throw Error("No container element specified");if(e.tagName)return e;if("string"==typeof e&&(i=n.getElementById(e),!i&&n.querySelector&&(i=n.querySelector(e)),i.tagName))return i;if(e[0]&&e[0].tagName)return e[0];throw Error("Could not find container element")}},e}(this);(function(t){t.types={TEXT:1,INTERPOLATOR:2,TRIPLE:3,SECTION:4,INVERTED:5,CLOSING:6,ELEMENT:7,PARTIAL:8,COMMENT:9,DELIMCHANGE:10,MUSTACHE:11,TAG:12,ATTR_VALUE_TOKEN:13}})(e),function(t){var e,i;e=function(t){return"[object Array]"===Object.prototype.toString.call(t)},i=function(t){return"[object Object]"===Object.prototype.toString.call(t)&&"function"!=typeof t},t._Mustache=function(t){this.root=t.root,this.model=t.model,this.viewmodel=t.root.viewmodel,this.parent=t.parent,this.parentFragment=t.parentFragment,this.contextStack=t.contextStack||[],this.index=t.index||0,(t.parentNode||t.anchor)&&(this.parentNode=t.parentNode,this.anchor=t.anchor),this.type=t.model.type,this.initialize&&this.initialize(),this.viewmodel.registerView(this),!this.keypath&&this.model.inv&&this.update(!1)},t._Fragment=function(t){var e,i,n,r,s;if(!this.preInit||!this.preInit(t)){if(this.parent=t.parent,this.index=t.index,this.items=[],this.indexRefs={},this.parent&&this.parent.parentFragment){r=this.parent.parentFragment.indexRefs;for(s in r)r.hasOwnProperty(s)&&(this.indexRefs[s]=r[s])}for(t.indexRef&&(this.indexRefs[t.indexRef]=t.index),n={root:t.root,parentFragment:this,parent:this,parentNode:t.parentNode,contextStack:t.contextStack},e=t.model?t.model.length:0,i=0;e>i;i+=1)n.model=t.model[i],n.index=i,this.items[this.items.length]=this.createItem(n)}},t._sectionUpdate=function(n){var r,s,o,a,h;if(r={model:this.model.frag,root:this.root,parentNode:this.parentNode,parent:this},this.parentNode&&(r.anchor=this.parentFragment.findNextNode(this)),s=e(n),s&&this.root.modifyArrays&&t.modifyArray(n,this.keypath,this.root.viewmodel),s&&0===n.length&&(o=!0),this.model.inv){if(n&&!o)this.length&&(this.unrender(),this.length=0);else if(!this.length)return r.contextStack=this.contextStack,r.index=0,this.fragments[0]=this.createFragment(r),this.length=1,void 0;return this.postUpdate&&this.postUpdate(),void 0}if(s){if(n.length<this.length)for(h=this.views.splice(n.length,this.length-n.length);h.length;)h.pop().teardown();else if(n.length>this.length)for(a=this.length;n.length>a;a+=1)r.contextStack=this.contextStack.concat(this.keypath+"."+a),r.index=a,this.model.i&&(r.indexRef=this.model.i),this.fragments[a]=this.createFragment(r);this.length=n.length}else i(n)?this.length||(r.contextStack=this.contextStack.concat(this.keypath),r.index=0,this.fragments[0]=this.createFragment(r),this.length=1):n&&!o?this.length||(r.contextStack=this.contextStack,r.index=0,this.fragments[0]=this.createFragment(r),this.length=1):this.length&&(this.unrender(),this.length=0);this.postUpdate&&this.postUpdate()}}(e),function(t){t.on=function(t,e){var i=this;return this._subs[t]?this._subs[t].push(e):this._subs[t]=[e],{cancel:function(){i.off(t,e)}}},t.off=function(t,e){var i,n;e||(t?this._subs[t]=[]:this._subs={}),i=this._subs[t],i&&(n=i.indexOf(e),-1!==n&&i.splice(n,1))},t.fire=function(t){var e,i,n,r=this._subs[t];if(r)for(e=Array.prototype.slice.call(arguments,1),i=0,n=r.length;n>i;i+=1)r[i].apply(this,e)}}(e.prototype),function(t){t.formatters={equals:function(t,e){return t===e},greaterThan:function(t,e){return t>e},greaterThanEquals:function(t,e){return t>=e},lessThan:function(t,e){return e>t},lessThanEquals:function(t,e){return e>=t}}}(e),function(t){var e,i;t.ViewModel=function(t){this.data=t||{},this.pendingResolution=[],this.observers={},this.dependents=[]},t.ViewModel.prototype={set:function(t,i){var n,r,s,o,a,h,u,l;if("object"!=typeof t){for(this.dependents.forEach(function(e){e.setting||(e.setting=!0,e.fire("set",t,i),e.fire("set:"+t,i),e.setting=!1)}),r=e(t),l=r.join("."),o=this.data;r.length>1;)s=r.shift(),o=o[s]||{};for(s=r[0],o[s]=i,this._notifyObservers(l,i),a=this.pendingResolution.length;a--;)h=this.pendingResolution.splice(a,1)[0],u=this.resolveRef(h.view.model.ref,h.view.contextStack),u?h.callback(u.keypath,u.value):this.registerUnresolvedKeypath(h)}else for(n in t)t.hasOwnProperty(n)&&this.set(n,t[n])},get:function(t){var i,n;if(!t)return void 0;for(i=e(t),n=this.data;i.length;)if(n&&(n=n[i.shift()]),void 0===n)return n;return"function"==typeof n?n.call(this,t):n},update:function(t){var e;if(t)this._notifyObservers(t,this.get(t));else for(e in this.data)this.data.hasOwnProperty(e)&&this._notifyObservers(e,this.get(e))},registerView:function(t){var e,i,n,r,s=this;return t.parentFragment&&t.parentFragment.indexRefs.hasOwnProperty(t.model.ref)?(r=t.parentFragment.indexRefs[t.model.ref],n=t.model.fmtrs?t.root._format(r,t.model.fmtrs):r,t.update(n),void 0):(i=function(e,i){t.keypath=e,t.observerRefs=s.observe({keypath:e,priority:t.model.p||0,view:t}),t.model.fmtrs&&(i=t.root._format(i,t.model.fmtrs)),t.update(i)},e=this.resolveRef(t.model.ref,t.contextStack),e?i(e.keypath,e.value):this.registerUnresolvedKeypath({view:t,callback:i}),void 0)},resolveRef:function(t,e){var i,n,r;if("."===t)return n=e[e.length-1],r=this.get(n),{keypath:n,value:r};for(e=e.concat();e.length;)if(i=e.pop(),n=i+"."+t,r=this.get(n),void 0!==r)return{keypath:n,value:r};return r=this.get(t),void 0!==r?{keypath:t,value:r}:void 0},registerUnresolvedKeypath:function(t){this.pendingResolution[this.pendingResolution.length]=t},_notifyObservers:function(t,e){var i,n,r,s,o,a=this,h=this.observers[t]||[];for(i=0;h.length>i;i+=1)if(r=h[i])for(n=0;r.length>n;n+=1)s=r[n],o=t!==s.originalAddress?a.get(s.originalAddress):e,s.view.model.fmtrs&&(o=s.view.root._format(o,s.view.model.fmtrs)),s.view.update(o)},observe:function(t){var e,i,n=this,r=t.keypath,s=t.priority,o=[];if(2===arguments.length&&"string"==typeof arguments[0]&&"function"==typeof arguments[1])return this.observe({keypath:arguments[0],callback:arguments[1],priority:0});if(!t.keypath)return void 0;for(i=function(e){var i,a;i=n.observers[e]=n.observers[e]||[],i=i[s]=i[s]||[],a={originalAddress:r},t.view&&(a.view=t.view),t.callback&&(a.callback=t.callback),i[i.length]=a,o[o.length]={keypath:e,priority:s,observer:a}},e=t.keypath;-1!==e.lastIndexOf(".");)i(e),e=e.substr(0,e.lastIndexOf("."));return i(e),o},unobserve:function(t){var e,i,n,r,s;if(e=this.observers[t.keypath],e&&(i=e[t.priority])){if(i.indexOf)n=i.indexOf(t.observer);else for(r=0,s=i.length;s>r;r+=1)if(i[r]===t.observer){n=r;break}-1!==n&&(i.splice(n,1),0===i.length&&delete e[t.priority],0===e.length&&delete this.observers[t.keypath])}},unobserveAll:function(t){for(;t.length;)this.unobserve(t.shift())}},t.ViewModel.prototype.cancelKeypathResolution=Array.prototype.filter?function(t){this.pendingResolution=this.pendingResolution.filter(function(e){return e.view!==t})}:function(t){var e,i=[];for(e=0;this.pendingResolution.length>e;e+=1)this.pendingResolution[e].view!==t&&(i[i.length]=this.pendingResolution[e]);this.pendingResolution=i},i=/\[\s*([0-9]+)\s*\]/g,e=function(t){var e;return e=t.replace(i,".$1"),e.split(".")}}(e),function(t,e){var i,n,r,s,o,a,h,u,l,c,f;i=t.types,s=e.document,r=function(t,e){return t.contains?t.contains(e):!0},n=function(t,e,i){var n,r,o,a=[];for(i=i||null,n=s.createElement("div"),n.innerHTML=t,o=n.childNodes.length,r=0;o>r;r+=1)a[r]=n.childNodes[r];for(r=0;o>r;r+=1)e.insertBefore(a[r],i);return a},t.DomFragment=function(e){t._Fragment.call(this,e)},t.DomFragment.prototype={preInit:function(t){return"string"==typeof t.model?(this.nodes=n(t.model,t.parentNode,t.anchor),!0):void 0},createItem:function(t){if("string"==typeof t.model)return new o(t);switch(t.model.type){case i.INTERPOLATOR:return new l(t);case i.SECTION:return new f(t);case i.TRIPLE:return new c(t);case i.ELEMENT:return new a(t);case i.PARTIAL:return new h(t);default:throw"WTF? not sure what happened here..."}},teardown:function(){var t;if(this.nodes)for(;this.nodes.length;)t=this.nodes.pop(),t.parentNode.removeChild(t);else for(;this.items.length;)this.items.pop().teardown()},firstNode:function(){return this.items[0]?this.items[0].firstNode():this.parentSection?this.parentSection.findNextNode(this):null},findNextNode:function(t){var e=t.index;return this.items[e+1]?this.items[e+1].firstNode():this.parentSection?this.parentSection.findNextNode(this):null}},h=function(e){this.fragment=new t.DomFragment({model:e.root.partials[e.model.ref]||[],root:e.root,parentNode:e.parentNode,contextStack:e.contextStack,anchor:e.anchor,parent:this})},h.prototype={teardown:function(){this.fragment.teardown()}},o=function(t){this.node=s.createTextNode(t.model),this.index=t.index,this.root=t.root,this.parentNode=t.parentNode,this.parentNode.insertBefore(this.node,t.anchor||null)},o.prototype={teardown:function(){r(this.root.el,this.node)&&this.parentNode.removeChild(this.node)},firstNode:function(){return this.node}},a=function(e){var i,n,r,o,a,h;if(n=this.model=e.model,this.root=e.root,this.viewmodel=e.root.viewmodel,this.parentFragment=e.parentFragment,this.parentNode=e.parentNode,this.index=e.index,n.attrs&&n.attrs.xmlns){if(r=n.attrs.xmlns,"string"!=typeof r)throw"Namespace attribute cannot contain mustaches"}else r=this.parentNode.namespaceURI;this.node=s.createElementNS(r,n.tag),this.attributes=[];for(a in n.attrs)n.attrs.hasOwnProperty(a)&&(h=n.attrs[a],o=new u({parent:this,name:a,value:h,root:e.root,parentNode:this.node,contextStack:e.contextStack}),"value"!==a||!this.root.twoway||"input"!==n.tag.toLowerCase()&&"textarea"!==n.tag.toLowerCase()||(i=o),this.attributes[this.attributes.length]=o);i&&this.bind(i,e.root.lazy),n.frag&&("string"==typeof n.frag?this.node.innerHTML=n.frag:this.children=new t.DomFragment({model:n.frag,root:e.root,parentNode:this.node,contextStack:e.contextStack,anchor:null,parent:this})),this.parentNode.insertBefore(this.node,e.anchor||null)},a.prototype={bind:function(e,i){var n,r,s,o,a=this.viewmodel,h=this.node;if(r=!0,!e.fragment||1!==e.fragment.items.length||e.fragment.items[0].type!==t.types.INTERPOLATOR||e.fragment.items[0].model.formatters&&e.fragment.items[0].model.formatters.length)throw"Not a valid two-way data binding candidate - must be a single interpolator with no formatters";s=e.fragment.items[0],o=s.keypath||s.model.partialKeypath,n=function(){var t=h.value;"0"===t?t=0:""!==t&&(t=+t||t),a.set(o,t)},n(),h.addEventListener("change",n),i||h.addEventListener("keyup",n)},teardown:function(){for(r(this.root.el,this.node)&&this.parentNode.removeChild(this.node),this.children&&this.children.teardown();this.attributes.length;)this.attributes.pop().teardown()},firstNode:function(){return this.node}},u=function(e){var i,n,r,s,o,a;if(i=e.name,n=e.value,this.parent=e.parent,r=i.indexOf(":"),-1!==r){if(s=i.substr(0,r),"xmlns"===s)o=null;else for(a=e.parentNode;a&&!o;)o=a.getAttribute("xmlns:"+s),a=a.parentNode||e.parent.parentFragment.parent.node||e.parent.parentFragment.parent.parentNode;o&&(this.namespace=o)}return"string"==typeof n?(o?e.parentNode.setAttributeNS(o,i.replace(s+":",""),n):e.parentNode.setAttribute(i,n),void 0):(this.parentNode=e.parentNode,this.name=i,this.children=[],this.parentFragment=this.parent.parentFragment,this.fragment=new t.TextFragment({model:n,root:e.root,parent:this,contextStack:e.contextStack}),this.ready=!0,this.update(),void 0)},u.prototype={teardown:function(){if(this.children)for(;this.children.length;)this.children.pop().teardown()},bubble:function(){this.update()},update:function(){var t=this.value;this.ready&&(this.value=""+this.fragment,this.value!==t&&(this.namespace?this.parentNode.setAttributeNS(this.namespace,this.name,this.value):this.parentNode.setAttribute(this.name,this.value)))}},l=function(e){t._Mustache.call(this,e)},l.prototype={initialize:function(){this.node=s.createTextNode(""),this.parentNode.insertBefore(this.node,this.anchor||null)},teardown:function(){this.observerRefs?this.viewmodel.unobserveAll(this.observerRefs):this.viewmodel.cancelKeypathResolution(this),r(this.root.el,this.node)&&this.parentNode.removeChild(this.node)},update:function(t){t!==this.text&&(this.text=t,this.node.data=t)},firstNode:function(){return this.node}},c=function(e){t._Mustache.call(this,e)},c.prototype={initialize:function(){this.nodes=[]},teardown:function(){if(r(this.root.el,this.parentNode))for(;this.nodes.length;)this.parentNode.removeChild(this.nodes.pop());this.observerRefs?this.viewmodel.unobserveAll(this.observerRefs):this.viewmodel.cancelKeypathResolution(this)},firstNode:function(){return this.nodes[0]?this.nodes[0]:this.parentFragment.findNextNode(this)},update:function(t){var e;if(t!==this.html){for(this.html=t;this.nodes.length;)this.parentNode.removeChild(this.nodes.pop());e=this.anchor||this.parentFragment.findNextNode(this),this.nodes=n(t,this.parentNode,e)}}},f=function(e){t._Mustache.call(this,e)},f.prototype={initialize:function(){this.fragments=[],this.length=0},teardown:function(){this.unrender(),this.observerRefs?this.viewmodel.unobserveAll(this.observerRefs):this.viewmodel.cancelKeypathResolution(this)},firstNode:function(){return this.fragments[0]?this.fragments[0].firstNode():this.parentFragment.findNextNode(this)},findNextNode:function(t){return this.fragments[t.index+1]?this.fragments[t.index+1].firstNode():this.parentFragment.findNextNode(this)},unrender:function(){for(;this.fragments.length;)this.fragments.shift().teardown()},update:t._sectionUpdate,createFragment:function(e){return new t.DomFragment(e)}}}(e,this),function(t){var e,i,n,r,s;e=t.types,t.TextFragment=function(e){t._Fragment.call(this,e)},t.TextFragment.prototype={init:function(){this.value=this.items.join("")},createItem:function(t){if("string"==typeof t.model)return new i(t.model);switch(t.model.type){case e.INTERPOLATOR:return new n(t);case e.TRIPLE:return new r(t);case e.SECTION:return new s(t);default:throw"Something went wrong in a rather interesting way"}},bubble:function(){this.value=this.items.join(""),this.parent.bubble()},teardown:function(){var t,e;for(t=this.items.length,e=0;t>e;e+=1)this.items[e].teardown()},toString:function(){return this.items.join("")}},i=function(t){this.text=t},i.prototype={toString:function(){return this.text},teardown:function(){}},n=function(e){t._Mustache.call(this,e)},n.prototype={update:function(t){this.value=t,this.parent.bubble()},teardown:function(){this.observerRefs?this.viewmodel.unobserveAll(this.observerRefs):this.viewmodel.cancelKeypathResolution(this)},toString:function(){return void 0===this.value?"":this.value}},r=n,s=function(e){t._Mustache.call(this,e)},s.prototype={initialize:function(){this.fragments=[],this.length=0},teardown:function(){this.unrender(),this.observerRefs?this.viewmodel.unobserveAll(this.observerRefs):this.viewmodel.cancelKeypathResolution(this)},unrender:function(){for(;this.fragments.length;)this.fragments.shift().teardown();this.length=0},bubble:function(){this.value=this.fragments.join(""),this.parent.bubble()},update:function(e){t._sectionUpdate.call(this,e)},createFragment:function(e){return new t.TextFragment(e)},postUpdate:function(){this.value=this.fragments.join(""),this.parent.bubble()},toString:function(){return this.fragments.join("")}}}(e),function(t){t.extend=function(e){var i,n,r;i=this,n=function(){t.apply(this,arguments),this.init&&this.init.apply(this,arguments)};for(r in i.prototype)i.prototype.hasOwnProperty(r)&&(n.prototype[r]=i.prototype[r]);for(r in e)if(e.hasOwnProperty(r)){if(t.prototype.hasOwnProperty(r))throw Error('Cannot override "'+r+'" method or property of Ractive prototype');n.prototype[r]=e[r]}return n.extend=i.extend,n}}(e),function(t){var e;t.modifyArray=function(t,i,n){var r,s,o,a;t._ractive?(r=t._ractive.viewmodels,s=t._ractive.keypathsByIndex,o=r.indexOf(n),-1===o&&(o=r.length,r[o]=n),a=s[o],-1===a.indexOf(i)&&(a[a.length]=i)):(t._ractive={viewmodels:[n],keypathsByIndex:[[i]]},e(t))},e=function(t){var e=function(t){var e,i;e=t._ractive.viewmodels,i=t._ractive.keypathsByIndex,e.forEach(function(e,n){var r=i[n];r.forEach(function(i){e.set(i,t)})})};["pop","push","reverse","shift","sort","splice","unshift"].forEach(function(i){t[i]=function(){var n=Array.prototype[i].apply(this,arguments);return e(t),n}})}}(e),function(t){t.easing={easeInQuad:function(t){return Math.pow(t,2)},easeOutQuad:function(t){return-(Math.pow(t-1,2)-1)},easeInOutQuad:function(t){return 1>(t/=.5)?.5*Math.pow(t,2):-.5*((t-=2)*t-2)},easeInCubic:function(t){return Math.pow(t,3)},easeOutCubic:function(t){return Math.pow(t-1,3)+1},easeInOutCubic:function(t){return 1>(t/=.5)?.5*Math.pow(t,3):.5*(Math.pow(t-2,3)+2)},easeInQuart:function(t){return Math.pow(t,4)},easeOutQuart:function(t){return-(Math.pow(t-1,4)-1)},easeInOutQuart:function(t){return 1>(t/=.5)?.5*Math.pow(t,4):-.5*((t-=2)*Math.pow(t,3)-2)},easeInQuint:function(t){return Math.pow(t,5)},easeOutQuint:function(t){return Math.pow(t-1,5)+1},easeInOutQuint:function(t){return 1>(t/=.5)?.5*Math.pow(t,5):.5*(Math.pow(t-2,5)+2)},easeInSine:function(t){return-Math.cos(t*(Math.PI/2))+1},easeOutSine:function(t){return Math.sin(t*(Math.PI/2))},easeInOutSine:function(t){return-.5*(Math.cos(Math.PI*t)-1)},easeInExpo:function(t){return 0===t?0:Math.pow(2,10*(t-1))},easeOutExpo:function(t){return 1===t?1:-Math.pow(2,-10*t)+1},easeInOutExpo:function(t){return 0===t?0:1===t?1:1>(t/=.5)?.5*Math.pow(2,10*(t-1)):.5*(-Math.pow(2,-10*--t)+2)},easeInCirc:function(t){return-(Math.sqrt(1-t*t)-1)},easeOutCirc:function(t){return Math.sqrt(1-Math.pow(t-1,2))},easeInOutCirc:function(t){return 1>(t/=.5)?-.5*(Math.sqrt(1-t*t)-1):.5*(Math.sqrt(1-(t-=2)*t)+1)},easeOutBounce:function(t){return 1/2.75>t?7.5625*t*t:2/2.75>t?7.5625*(t-=1.5/2.75)*t+.75:2.5/2.75>t?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375},easeInBack:function(t){var e=1.70158;return t*t*((e+1)*t-e)},easeOutBack:function(t){var e=1.70158;return(t-=1)*t*((e+1)*t+e)+1},easeInOutBack:function(t){var e=1.70158;return 1>(t/=.5)?.5*t*t*(((e*=1.525)+1)*t-e):.5*((t-=2)*t*(((e*=1.525)+1)*t+e)+2)},elastic:function(t){return-1*Math.pow(4,-8*t)*Math.sin((6*t-1)*2*Math.PI/2)+1},swingFromTo:function(t){var e=1.70158;return 1>(t/=.5)?.5*t*t*(((e*=1.525)+1)*t-e):.5*((t-=2)*t*(((e*=1.525)+1)*t+e)+2)},swingFrom:function(t){var e=1.70158;return t*t*((e+1)*t-e)},swingTo:function(t){var e=1.70158;return(t-=1)*t*((e+1)*t+e)+1},bounce:function(t){return 1/2.75>t?7.5625*t*t:2/2.75>t?7.5625*(t-=1.5/2.75)*t+.75:2.5/2.75>t?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375},bouncePast:function(t){return 1/2.75>t?7.5625*t*t:2/2.75>t?2-(7.5625*(t-=1.5/2.75)*t+.75):2.5/2.75>t?2-(7.5625*(t-=2.25/2.75)*t+.9375):2-(7.5625*(t-=2.625/2.75)*t+.984375)},easeFromTo:function(t){return 1>(t/=.5)?.5*Math.pow(t,4):-.5*((t-=2)*Math.pow(t,3)-2)},easeFrom:function(t){return Math.pow(t,4)},easeTo:function(t){return Math.pow(t,.25)}}}(e),function(t,e){var i,n;(function(t,e,i){var n;for(n=0;t.length>n&&!i.requestAnimationFrame;++n)i.requestAnimationFrame=i[t[n]+"RequestAnimationFrame"],i.cancelAnimationFrame=i[t[n]+"CancelAnimationFrame"]||i[t[n]+"CancelRequestAnimationFrame"];i.requestAnimationFrame||(i.requestAnimationFrame=function(t){var n,r,s;return n=Date.now(),r=Math.max(0,16-(n-e)),s=i.setTimeout(function(){t(n+r)},r),e=n+r,s}),i.cancelAnimationFrame||(i.cancelAnimationFrame=function(t){i.clearTimeout(t)})})(["ms","moz","webkit","o"],0,e),i=function(t){var e;this.startTime=Date.now();for(e in t)t.hasOwnProperty(e)&&(this[e]=t[e]);this.delta=this.to-this.from,this.running=!0},n={animations:[],tick:function(){var t,i;for(t=0;this.animations.length>t;t+=1)i=this.animations[t],i.tick()||this.animations.splice(t--,1);this.animations.length?e.requestAnimationFrame(this.boundTick):this.running=!1},boundTick:function(){n.tick()},push:function(t){this.animations[this.animations.length]=t,this.running||(this.running=!0,this.tick())}},i.prototype={tick:function(){var t,e,i,n;return this.running?(n=Date.now(),t=n-this.startTime,t>=this.duration?(this.viewmodel.set(this.keypath,this.to),this.complete&&this.complete(1),this.running=!1,!1):(e=this.easing?this.easing(t/this.duration):t/this.duration,i=this.from+e*this.delta,this.viewmodel.set(this.keypath,i),this.step&&this.step(e,i),!0)):!1},stop:function(){this.running=!1}},t.prototype.animate=function(e,r,s){var o,a,h,u,l;if(r=parseFloat(r),isNaN(r))throw"Cannot animate to a non-numeric property";if(a=parseFloat(this.get(e)),isNaN(r))throw"Cannot animate from a non-numeric property";for(l=n.animations.length;l--;)n.animations[l].keypath===e&&n.animations[l].stop();s&&s.easing&&(o="function"==typeof s.easing?s.easing:this.easing&&this.easing[s.easing]?this.easing[s.easing]:t.easing[s.easing],"function"!=typeof o&&(o=null)),h=s&&void 0!==s.duration?s.duration:400,u=new i({keypath:e,from:a,to:r,viewmodel:this.viewmodel,duration:h,easing:o}),n.push(u)}}(e,this),"undefined"!=typeof module&&module.exports?module.exports=e:"function"==typeof define&&define.amd?define(function(){return e}):t.Ractive=e})(this);