ractive
Version:
Next-generation DOM manipulation
1 lines • 25.1 kB
JavaScript
(function(t){"use strict";var e=function(){var t,e;return t=function(n){var i,r;if(n)for(r in n)n.hasOwnProperty(r)&&(this[r]=n[r]);i={preserveWhitespace:!1,append:!1,twoway:!0,formatters:{},modifyArrays:!0};for(r in i)i.hasOwnProperty(r)&&void 0===this[r]&&(this[r]=i[r]);if(void 0!==this.el&&(this.el=e(this.el)),this._subs={},void 0===this.viewmodel&&(this.viewmodel=new t.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(!t.compile)throw Error('Missing Ractive.compile - cannot compile partial "'+r+'". Either precompile or use the version that includes the compiler');this.partials[r]=t.compile(this.partials[r],this)}if("string"==typeof this.template){if(!t.compile)throw Error("Missing Ractive.compile - cannot compile template. Either precompile or use the version that includes the compiler");this.template=t.compile(this.template,this)}this.el&&this.render({el:this.el,callback:this.callback,append:this.append})},t.prototype={render:function(n){var i=n.el?e(n.el):this.el;if(!i)throw Error("You must specify a DOM element to render to");n.append||(i.innerHTML=""),n.callback&&(this.callback=n.callback),this.rendered=new t.DomFragment({model:this.template,root:this,parentNode:i}),i.appendChild(this.rendered.docFrag)},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(e,n){var i,r,o,s,a,h;if(!n)return e;for(r=n.length,i=0;r>i;i+=1)o=n[i],s=o.name,a=o.args||[],h=this.formatters[s]||t.formatters[s],h&&(e=h.apply(this,[e].concat(a)));return e}},e=function(t){var e,n;if("undefined"!=typeof window){if(n=window.document,!t)throw Error("No container element specified");if(t.tagName)return t;if("string"==typeof t&&(e=n.getElementById(t),!e&&n.querySelector&&(e=n.querySelector(t)),e.tagName))return e;if(t[0]&&t[0].tagName)return t[0];throw Error("Could not find container element")}},t}();(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,n;e=function(t){return"[object Array]"===Object.prototype.toString.call(t)},n=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.viewmodel.registerView(this),!this.keypath&&this.model.inv&&this.update(!1)},t._Fragment=function(t){var e,n,i,r,o;if(this.parent=t.parent,this.index=t.index,this.items=[],this.indexRefs={},this.parent&&this.parent.parentFragment){r=this.parent.parentFragment.indexRefs;for(o in r)r.hasOwnProperty(o)&&(this.indexRefs[o]=r[o])}for(t.indexRef&&(this.indexRefs[t.indexRef]=t.index),i={root:t.root,parentFragment:this,parent:this,parentNode:t.parentNode,contextStack:t.contextStack},e=t.model?t.model.length:0,n=0;e>n;n+=1)i.model=t.model[n],i.index=n,this.items[this.items.length]=this.createItem(i)},t._sectionUpdate=function(i){var r,o,s,a,h;if(r={model:this.model.frag,root:this.root,parentNode:this.parentNode,parent:this},this.parentNode&&(r.anchor=this.parentFragment.findNextNode(this)),o=e(i),o&&this.root.modifyArrays&&t.modifyArray(i,this.keypath,this.root.viewmodel),o&&0===i.length&&(s=!0),this.model.inv){if(i&&!s)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(o){if(i.length<this.length)for(h=this.fragments.splice(i.length,this.length-i.length);h.length;)h.pop().teardown();else if(i.length>this.length)for(a=this.length;i.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=i.length}else n(i)?this.length||(r.contextStack=this.contextStack.concat(this.keypath),r.index=0,this.fragments[0]=this.createFragment(r),this.length=1):i&&!s?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 n=this;return this._subs[t]?this._subs[t].push(e):this._subs[t]=[e],{cancel:function(){n.off(t,e)}}},t.off=function(t,e){var n,i;e||(t?this._subs[t]=[]:this._subs={}),n=this._subs[t],n&&(i=n.indexOf(e),-1!==i&&n.splice(i,1))},t.fire=function(t){var e,n,i,r=this._subs[t];if(r)for(e=Array.prototype.slice.call(arguments,1),n=0,i=r.length;i>n;n+=1)r[n].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,n,i,r;i=function(t){return"[object Array]"===Object.prototype.toString.call(t)},r=function(t){return"[object Object]"===Object.prototype.toString.call(t)&&"function"!=typeof t},t.ViewModel=function(t){this.data=t||{},this.pendingResolution=[],this.observers={},this.dependents=[]},t.ViewModel.prototype={set:function(t,n){var o,s,a,h,d,u,c,p;if(r(t))for(o in t)t.hasOwnProperty(o)&&this.set(o,t[o]);else{for(this.dependents.forEach(function(e){e.setting||(e.setting=!0,e.fire("set",t,n),e.fire("set:"+t,n),e.setting=!1)}),s=i(t)?t.concat():e(t),p=s.join("."),h=this.data;s.length>1;)a=s.shift(),h[a]||(h[a]=/^[0-9]+$/.test(s[0])?[]:{}),h=h[a];for(a=s[0],h[a]=n,this._notifyObservers(p,n),d=this.pendingResolution.length;d--;)u=this.pendingResolution.splice(d,1)[0],c=this.resolveRef(u.view.model.ref,u.view.contextStack),c?u.callback(c.keypath,c.value):this.registerUnresolvedKeypath(u)}},get:function(t){var n,r;if(!t)return void 0;for(n=i(t)?t.concat():e(t),r=this.data;n.length;)if(r&&(r=r[n.shift()]),void 0===r)return r;return"function"==typeof r?r.call(this,t):r},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,n,i,r,o=this;return t.parentFragment&&t.parentFragment.indexRefs.hasOwnProperty(t.model.ref)?(r=t.parentFragment.indexRefs[t.model.ref],i=t.model.fmtrs?t.root._format(r,t.model.fmtrs):r,t.update(i),void 0):(n=function(e,n){t.keypath=e,t.observerRefs=o.observe({keypath:e,priority:t.model.p||0,view:t}),t.model.fmtrs&&(n=t.root._format(n,t.model.fmtrs)),t.update(n)},e=this.resolveRef(t.model.ref,t.contextStack),e?n(e.keypath,e.value):(t.model.fmtrs&&t.update(t.root._format(void 0,t.model.fmtrs)),this.registerUnresolvedKeypath({view:t,callback:n})),void 0)},resolveRef:function(t,e){var n,i,r;if("."===t)return i=e[e.length-1],r=this.get(i),{keypath:i,value:r};for(e=e.concat();e.length;)if(n=e.pop(),i=n+"."+t,r=this.get(i),void 0!==r)return{keypath:i,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 n,i,r,o,s,a=this,h=this.observers[t]||[];for(n=0;h.length>n;n+=1)if(r=h[n])for(i=0;r.length>i;i+=1)o=r[i],s=t!==o.originalAddress?a.get(o.originalAddress):e,o.view.model.fmtrs&&(s=o.view.root._format(s,o.view.model.fmtrs)),o.view.update(s)},observe:function(t){var e,n,i=this,r=t.keypath,o=t.priority,s=[];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(n=function(e){var n,a;n=i.observers[e]=i.observers[e]||[],n=n[o]=n[o]||[],a={originalAddress:r},t.view&&(a.view=t.view),t.callback&&(a.callback=t.callback),n[n.length]=a,s[s.length]={keypath:e,priority:o,observer:a}},e=t.keypath;-1!==e.lastIndexOf(".");)n(e),e=e.substr(0,e.lastIndexOf("."));return n(e),s},unobserve:function(t){var e,n,i,r,o;if(e=this.observers[t.keypath],e&&(n=e[t.priority])){if(n.indexOf)i=n.indexOf(t.observer);else for(r=0,o=n.length;o>r;r+=1)if(n[r]===t.observer){i=r;break}-1!==i&&(n.splice(i,1),0===n.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,n=[];for(e=0;this.pendingResolution.length>e;e+=1)this.pendingResolution[e].view!==t&&(n[n.length]=this.pendingResolution[e]);this.pendingResolution=n},n=/\[\s*([0-9]+)\s*\]/g,e=function(t){var e;return e=t.replace(n,".$1"),e.split(".")}}(e),function(t){var e,n,i,r,o,s,a,h,d,u;e=t.types,i="undefined"!=typeof window?window.document:null,n=function(t,e){var n,r=[];for(n=i.createElement("div"),n.innerHTML=t;n.firstChild;)r[r.length]=n.firstChild,e.appendChild(n.firstChild);return r},t.DomFragment=function(e){return this.docFrag=i.createDocumentFragment(),"string"==typeof e.model?(this.nodes=n(e.model,this.docFrag),void 0):(t._Fragment.call(this,e),void 0)},t.DomFragment.prototype={createItem:function(t){if("string"==typeof t.model)return new r(t,this.docFrag);switch(t.model.type){case e.INTERPOLATOR:return new h(t,this.docFrag);case e.SECTION:return new u(t,this.docFrag);case e.TRIPLE:return new d(t,this.docFrag);case e.ELEMENT:return new o(t,this.docFrag);case e.PARTIAL:return new s(t,this.docFrag);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():null},findNextNode:function(t){var e=t.index;return this.items[e+1]?this.items[e+1].firstNode():null}},s=function(e,n){this.fragment=new t.DomFragment({model:e.root.partials[e.model.ref]||[],root:e.root,parentNode:e.parentNode,contextStack:e.contextStack,parent:this}),n.appendChild(this.fragment.docFrag)},s.prototype={teardown:function(){this.fragment.teardown()}},r=function(t,e){this.node=i.createTextNode(t.model),this.root=t.root,this.parentNode=t.parentNode,e.appendChild(this.node)},r.prototype={teardown:function(){this.root.el.contains(this.node)&&this.parentNode.removeChild(this.node)},firstNode:function(){return this.node}},o=function(e,n){var r,o,s,h,d,u;if(r=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,r.attrs&&r.attrs.xmlns){if(o=r.attrs.xmlns,"string"!=typeof o)throw"Namespace attribute cannot contain mustaches"}else o=this.parentNode.namespaceURI;this.node=i.createElementNS(o,r.tag),r.frag&&("string"==typeof r.frag?this.node.innerHTML=r.frag:(this.children=new t.DomFragment({model:r.frag,root:e.root,parentNode:this.node,contextStack:e.contextStack,parent:this}),this.node.appendChild(this.children.docFrag))),this.attributes=[];for(h in r.attrs)r.attrs.hasOwnProperty(h)&&(d=r.attrs[h],s=new a({parent:this,name:h,value:void 0===d?null:d,root:e.root,parentNode:this.node,contextStack:e.contextStack}),this.attributes[this.attributes.length]=s,s.isTwowayNameAttr?u=s:s.update());u&&(u.updateViewModel(),u.update()),n.appendChild(this.node)},o.prototype={teardown:function(){for(this.root.el.contains(this.node)&&this.parentNode.removeChild(this.node),this.children&&this.children.teardown();this.attributes.length;)this.attributes.pop().teardown()},firstNode:function(){return this.node}},a=function(e){var n,i,r,o,s,a,h,d,u;if(n=e.name,i=e.value,this.parent=e.parent,r=n.indexOf(":"),-1!==r){if(o=n.substr(0,r),"xmlns"===o)s=null;else for(a=e.parentNode;a&&!s;)s=a.getAttribute("xmlns:"+o),a=a.parentNode||e.parent.parentFragment.parent.node||e.parent.parentFragment.parent.parentNode;s&&(this.namespace=s)}return null===i||"string"==typeof i?(s?e.parentNode.setAttributeNS(s,n.replace(o+":",""),i):e.parentNode.setAttribute(n,i),void 0):(this.root=e.root,this.parentNode=e.parentNode,this.name=n,this.children=[],this.parentFragment=this.parent.parentFragment,this.fragment=new t.TextFragment({model:i,root:this.root,parent:this,contextStack:e.contextStack}),this.root.twoway&&(h=this.parent.model.tag.toLowerCase(),u=this.name.toLowerCase(),d=!("name"!==u&&"value"!==u&&"checked"!==u||"input"!==h&&"textarea"!==h&&"select"!==h)),d&&(this.bind(u,this.root.lazy),"name"===u&&(this.isTwowayNameAttr=!0)),this.ready=!0,this.isTwowayNameAttr||this.update(),void 0)},a.prototype={bind:function(e,n){var i,r=this,o=this.root.viewmodel,s=this.parentNode;if(!this.fragment)return!1;if(1!==this.fragment.items.length||this.fragment.items[0].type!==t.types.INTERPOLATOR)throw"Not a valid two-way data binding candidate - must be a single interpolator";this.interpolator=this.fragment.items[0],i=this.interpolator.keypath||this.interpolator.model.ref,"checkbox"===s.type||"radio"===s.type?"name"===e?(s.setAttribute("name","{{"+i+"}}"),this.updateViewModel=function(){s.checked&&o.set(i,s.value)}):"checked"===e&&(this.updateViewModel=function(){o.set(i,s.checked)}):this.updateViewModel=function(){var t;t=r.interpolator.model.fmtrs?r.root._format(s.value,r.interpolator.model.fmtrs):s.value,"0"===t?t=0:""!==t&&(t=+t||t),o.set(i,t)},this.updateViewModel&&(this.twoway=!0,s.addEventListener("change",this.updateViewModel),s.addEventListener("click",this.updateViewModel),s.addEventListener("blur",this.updateViewModel),n||(s.addEventListener("keyup",this.updateViewModel),s.addEventListener("keydown",this.updateViewModel),s.addEventListener("keypress",this.updateViewModel),s.addEventListener("input",this.updateViewModel)))},teardown:function(){if(this.updateViewModel&&(this.node.removeEventListener("change",this.updateViewModel),this.node.removeEventListener("click",this.updateViewModel),this.node.removeEventListener("blur",this.updateViewModel),this.node.removeEventListener("keyup",this.updateViewModel),this.node.removeEventListener("keydown",this.updateViewModel),this.node.removeEventListener("keypress",this.updateViewModel),this.node.removeEventListener("input",this.updateViewModel)),this.children)for(;this.children.length;)this.children.pop().teardown()},bubble:function(){this.update()},update:function(){var t,e;if(this.twoway){if(e=this.name.toLowerCase(),this.value=this.interpolator.value,"name"===e&&("checkbox"===this.parentNode.type||"radio"===this.parentNode.type))return this.parentNode.checked=this.value===this.parentNode.value?!0:!1,void 0;if("value"===e&&i.activeElement===this.parentNode)return;return void 0===this.value&&(this.value=""),this.parentNode[e]=this.value,void 0}this.ready&&(t=this.value,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)))}},h=function(e,n){this.node=i.createTextNode(""),n.appendChild(this.node),t._Mustache.call(this,e)},h.prototype={teardown:function(){this.observerRefs?this.viewmodel.unobserveAll(this.observerRefs):this.viewmodel.cancelKeypathResolution(this),this.root.el.contains(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}},d=function(e,n){this.nodes=[],this.docFrag=i.createDocumentFragment(),this.initialising=!0,t._Mustache.call(this,e),n.appendChild(this.docFrag),this.initialising=!1},d.prototype={teardown:function(){if(this.root.el.contains(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){if(t!==this.html){for(this.html=t;this.nodes.length;)this.parentNode.removeChild(this.nodes.pop());this.nodes=n(t,this.docFrag),this.initialising||this.parentNode.insertBefore(this.docFrag,this.parentFragment.findNextNode(this))}}},u=function(e,n){this.fragments=[],this.length=0,this.docFrag=i.createDocumentFragment(),this.initialising=!0,t._Mustache.call(this,e),n.appendChild(this.docFrag),this.initialising=!1},u.prototype={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:function(e){t._sectionUpdate.call(this,e),this.initialising||this.parentNode.insertBefore(this.docFrag,this.parentFragment.findNextNode(this))},createFragment:function(e){var n=new t.DomFragment(e);return this.docFrag.appendChild(n.docFrag),n}}}(e),function(t){var e,n,i,r,o;e=t.types,t.TextFragment=function(e){t._Fragment.call(this,e),this.value=this.items.join("")},t.TextFragment.prototype={createItem:function(t){if("string"==typeof t.model)return new n(t.model);switch(t.model.type){case e.INTERPOLATOR:return new i(t);case e.TRIPLE:return new r(t);case e.SECTION:return new o(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("")}},n=function(t){this.text=t},n.prototype={toString:function(){return this.text},teardown:function(){}},i=function(e){t._Mustache.call(this,e)},i.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=i,o=function(e){this.fragments=[],this.length=0,t._Mustache.call(this,e)},o.prototype={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 n,i,r;n=this,i=function(){t.apply(this,arguments),this.init&&this.init.apply(this,arguments)};for(r in n.prototype)n.prototype.hasOwnProperty(r)&&(i.prototype[r]=n.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');i.prototype[r]=e[r]}return i.extend=n.extend,i}}(e),function(t){var e;t.modifyArray=function(t,n,i){var r,o,s,a;t._ractive?(r=t._ractive.viewmodels,o=t._ractive.keypathsByIndex,s=r.indexOf(i),-1===s&&(s=r.length,r[s]=i),a=o[s],-1===a.indexOf(n)&&(a[a.length]=n)):(t._ractive={viewmodels:[i],keypathsByIndex:[[n]]},e(t))},e=function(t){var e=function(t){var e,n;e=t._ractive.viewmodels,n=t._ractive.keypathsByIndex,e.forEach(function(e,i){var r=n[i];r.forEach(function(n){e.set(n,t)})})};["pop","push","reverse","shift","sort","splice","unshift"].forEach(function(n){t[n]=function(){var i=Array.prototype[n].apply(this,arguments);return e(t),i}})}}(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){var e,n,i;i="undefined"!=typeof window?window:{},function(t,e){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,o;return n=Date.now(),r=Math.max(0,16-(n-e)),o=i.setTimeout(function(){t(n+r)},r),e=n+r,o}),i.cancelAnimationFrame||(i.cancelAnimationFrame=function(t){i.clearTimeout(t)})}(["ms","moz","webkit","o"],0,i),e=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,e;for(t=0;this.animations.length>t;t+=1)e=this.animations[t],e.tick()||this.animations.splice(t--,1);this.animations.length?i.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())}},e.prototype={tick:function(){var t,e,n,i;return this.running?(i=Date.now(),t=i-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,n=this.from+e*this.delta,this.viewmodel.set(this.keypath,n),this.step&&this.step(e,n),!0)):!1},stop:function(){this.running=!1}},t.prototype.animate=function(i,r,o){var s,a,h,d,u;if(o=o||{},r=parseFloat(r),isNaN(r))throw"Cannot animate to a non-numeric property";if(a=parseFloat(this.get(i)),isNaN(r))throw"Cannot animate from a non-numeric property";for(u=n.animations.length;u--;)n.animations[u].keypath===i&&n.animations[u].stop();o.easing&&(s="function"==typeof o.easing?o.easing:this.easing&&this.easing[o.easing]?this.easing[o.easing]:t.easing[o.easing],"function"!=typeof s&&(s=null)),h=void 0===o.duration?400:o.duration,d=new e({keypath:i,from:a,to:r,viewmodel:this.viewmodel,duration:h,easing:s,step:o.step,complete:o.complete}),n.push(d)}}(e),"undefined"!=typeof module&&module.exports?module.exports=e:"function"==typeof define&&define.amd?define(function(){return e}):t.Ractive=e})(this);