!function(e,t){"function"==typeof define&&define.amd?define(["knockout"],t):"object"==typeof exports?module.exports=t(require("knockout")):e.KnockoutElse=t(e.ko)}(this,function(e){"use strict";function t(e){return!!e&&"object"==typeof e&&e.constructor===Object}function n(e){return 8==e.nodeType&&u.test(o?e.text:e.nodeValue)}function i(t){var n,i=document.createElement("div");t.content?n=t.content:"SCRIPT"===t.tagName?(n=document.createElement("div"),n.innerHTML=t.text):n=t;var s=e.utils.arrayFirst(e.virtualElements.childNodes(n),function(e){return e&&e.attributes&&e.attributes["data-template"]});return i.insertBefore(s.cloneNode(!0),null),e.removeNode(s),i}function s(e,t){return{status:"existing",value:e,index:t}}function a(t){this.element=t.element,this.container=n(this.element)?this.element.parentNode:this.element,this.$context=t.$context,this.data=t.data,this.as=t.as,this.noContext=t.noContext,this.templateNode=i(t.name?document.getElementById(t.name).cloneNode(!0):t.element),this.afterQueueFlush=t.afterQueueFlush,this.beforeQueueFlush=t.beforeQueueFlush,this.changeQueue=[],this.lastNodesList=[],this.indexesToDelete=[],this.rendering_queued=!1,this.existingElements=e.utils.arrayFilter(e.virtualElements.childNodes(this.container),function(e){return e&&e.attributes&&e.attributes["data-init"]});var a=e.unwrap(this.data);a.map&&this.onArrayChange(a.map(s)),e.isObservable(this.data)&&(this.data.indexOf||(this.data=this.data.extend({trackArrayChanges:!0})),this.changeSubs=this.data.subscribe(this.onArrayChange,this,"arrayChange"))}var o=document&&"<!--test-->"===document.createComment("test").text,u=o?/^<!--\s*ko(?:\s+([\s\S]+))?\s*-->$/:/^\s*ko(?:\s+([\s\S]+))?\s*$/;a.animateFrame=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.msRequestAnimationFrame||function(e){return window.setTimeout(e,1e3/60)},a.prototype.dispose=function(){this.changeSubs&&this.changeSubs.dispose()},a.prototype.onArrayChange=function(t){var n=this,i={added:[],existing:[],deleted:[]};e.utils.arrayForEach(t,function(e){i[e.status].push(e)}),i.deleted.length>0&&(this.changeQueue.push.apply(this.changeQueue,i.deleted),this.changeQueue.push({status:"clearDeletedIndexes"})),this.changeQueue.push.apply(this.changeQueue,i.existing),this.changeQueue.push.apply(this.changeQueue,i.added),this.changeQueue.length>0&&!this.rendering_queued&&(this.rendering_queued=!0,a.animateFrame.call(window,function(){n.processQueue()}))},a.prototype.processQueue=function(){var t=this;"function"==typeof this.beforeQueueFlush&&this.beforeQueueFlush(this.changeQueue),e.utils.arrayForEach(this.changeQueue,function(e){t[e.status](e.index,e.value)}),this.rendering_queued=!1,"function"==typeof this.afterQueueFlush&&this.afterQueueFlush(this.changeQueue),this.changeQueue=[]},a.prototype.existing=function(t,n){var i;i=this.noContext?this.$context.extend({$item:n}):this.$context.createChildContext(n,this.as||null);var s=this.existingElements[t];this.lastNodesList.splice(t,0,s),e.applyBindings(i,s)},a.prototype.added=function(t,n){var i,s=this.lastNodesList[t-1]||null,a=this.templateNode.cloneNode(!0),o=e.virtualElements.childNodes(a);i=this.noContext?this.$context.extend({$item:n}):this.$context.createChildContext(n,this.as||null),this.lastNodesList.splice(t,0,o[o.length-1]),e.applyBindingsToDescendants(i,a);for(var u=o.length-1;u>=0;--u){var r=o[u];if(!r)return;e.virtualElements.insertAfter(this.element,r,s)}},a.prototype.deleted=function(t,n){var i=this.lastNodesList[t],s=this.lastNodesList[t-1]||this.element;do i=i.previousSibling,e.removeNode(i&&i.nextSibling||e.virtualElements.firstChild(this.element));while(i&&i!==s);this.lastNodesList[t]=this.lastNodesList[t-1],this.indexesToDelete.push(t)},a.prototype.clearDeletedIndexes=function(){for(var e=this.indexesToDelete.length-1;e>=0;--e)this.lastNodesList.splice(this.indexesToDelete[e],1);this.indexesToDelete=[]},e.bindingHandlers.foreachInit={init:function(n,i,s,o,u){var r,l=i();return t(l)?(l.element=l.element||n,l.$context=u,r=new a(l)):r=new a({element:n,data:e.unwrap(u.$rawData)===l?u.$rawData:l,$context:u}),e.utils.domNodeDisposal.addDisposeCallback(n,function(){r.dispose()}),{controlsDescendantBindings:!0}},InitializedForeach:a},e.virtualElements.allowedBindings.foreachInit=!0,e.bindingHandlers.textInit={init:function(t,n){var i=n(),s=e.utils.peekObservable(i),a=t.innerText;"function"==typeof i.convert&&(a=i.convert(a));var o=i.field||i;o(a,s),e.applyBindingsToNode(t,{text:o})}},e.bindingHandlers.valueInit={init:function(t,n){var i=n(),s=e.utils.peekObservable(i),a=t.value;"function"==typeof i.convert&&(a=i.convert(a));var o=i.field||i;o(a,s),e.applyBindingsToNode(t,{value:o})}},e.bindingHandlers.init={init:function(t,i){var s=i(),a=e.utils.peekObservable(s),o=n(t)?e.virtualElements.firstChild(t):t,u=s.val||o.innerText||o.value||o.textContent;"function"==typeof s.convert&&(u=s.convert(u));var r=s.field||s;r(u,a)}},e.virtualElements.allowedBindings.init=!0});