Created
May 4, 2011 09:01
-
-
Save SteveSanderson/954957 to your computer and use it in GitHub Desktop.
KO with control flow bindings prototype
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Knockout JavaScript library v1.3.0ctp | |
// (c) Steven Sanderson - http://knockoutjs.com/ | |
// License: MIT (http://www.opensource.org/licenses/mit-license.php) | |
(function(window,undefined){ | |
function c(d){throw d;}var n=void 0,o=null,p=window.ko={};p.b=function(d,e){for(var b=d.split("."),a=window,f=0;f<b.length-1;f++)a=a[b[f]];a[b[b.length-1]]=e};p.h=function(d,e,b){d[e]=b}; | |
p.a=new function(){function d(a,f){if(a.tagName!="INPUT"||!a.type)return!1;if(f.toLowerCase()!="click")return!1;var h=a.type.toLowerCase();return h=="checkbox"||h=="radio"}var e=/^(\s|\u00A0)+|(\s|\u00A0)+$/g,b={click:1,dblclick:1,mousedown:1,mouseup:1,mousemove:1,mouseover:1,mouseout:1,mouseenter:1,mouseleave:1};return{ha:["authenticity_token",/^__RequestVerificationToken(_.*)?$/],j:function(a,f){for(var h=0,b=a.length;h<b;h++)f(a[h])},g:function(a,f){if(typeof a.indexOf=="function")return a.indexOf(f); | |
for(var h=0,b=a.length;h<b;h++)if(a[h]===f)return h;return-1},Ba:function(a,f,h){for(var b=0,d=a.length;b<d;b++)if(f.call(h,a[b]))return a[b];return o},P:function(a,f){var b=p.a.g(a,f);b>=0&&a.splice(b,1)},O:function(a,f){for(var a=a||[],b=[],d=0,e=a.length;d<e;d++)b.push(f(a[d]));return b},N:function(a,f){for(var a=a||[],b=[],d=0,e=a.length;d<e;d++)f(a[d])&&b.push(a[d]);return b},B:function(a,f){for(var b=0,d=f.length;b<d;b++)a.push(f[b]);return a},w:function(a){for(;a.firstChild;)p.removeNode(a.firstChild)}, | |
Za:function(a,f){p.a.w(a);f&&p.a.j(f,function(f){a.appendChild(f)})},pa:function(a,f){var b=a.nodeType?[a]:a;if(b.length>0){for(var d=b[0],e=d.parentNode,i=0,k=f.length;i<k;i++)e.insertBefore(f[i],d);i=0;for(k=b.length;i<k;i++)p.removeNode(b[i])}},qa:function(a,f){navigator.userAgent.indexOf("MSIE 6")>=0?a.setAttribute("selected",f):a.selected=f},m:function(a){return(a||"").replace(e,"")},cb:function(a,f){for(var b=[],d=(a||"").split(f),e=0,i=d.length;e<i;e++){var k=p.a.m(d[e]);k!==""&&b.push(k)}return b}, | |
$a:function(a,f){a=a||"";if(f.length>a.length)return!1;return a.substring(0,f.length)===f},Ka:function(a,f,b){if(f===n)return(new Function("return "+a))();return(new Function("sc_inner","sc_outer","with(sc_outer) { with(sc_inner) { return ("+a+") } }"))(f,b||{})},Ia:function(a,f){if(f.compareDocumentPosition)return(f.compareDocumentPosition(a)&16)==16;for(;a!=o;){if(a==f)return!0;a=a.parentNode}return!1},S:function(a){return p.a.Ia(a,document)},t:function(a,f,b){if(typeof jQuery!="undefined"){if(d(a, | |
f))var e=b,b=function(a,f){var b=this.checked;if(f)this.checked=f.Da!==!0;e.call(this,a);this.checked=b};jQuery(a).bind(f,b)}else typeof a.addEventListener=="function"?a.addEventListener(f,b,!1):typeof a.attachEvent!="undefined"?a.attachEvent("on"+f,function(f){b.call(a,f)}):c(Error("Browser doesn't support addEventListener or attachEvent"))},ua:function(a,f){(!a||!a.nodeType)&&c(Error("element must be a DOM node when calling triggerEvent"));if(typeof jQuery!="undefined"){var e=[];d(a,f)&&e.push({Da:a.checked}); | |
jQuery(a).trigger(f,e)}else if(typeof document.createEvent=="function")typeof a.dispatchEvent=="function"?(e=document.createEvent(f in b?"MouseEvents":"HTMLEvents"),e.initEvent(f,!0,!0,window,0,0,0,0,0,!1,!1,!1,!1,0,a),a.dispatchEvent(e)):c(Error("The supplied element doesn't support dispatchEvent"));else if(typeof a.fireEvent!="undefined"){if(f=="click"&&a.tagName=="INPUT"&&(a.type.toLowerCase()=="checkbox"||a.type.toLowerCase()=="radio"))a.checked=a.checked!==!0;a.fireEvent("on"+f)}else c(Error("Browser doesn't support triggering events"))}, | |
d:function(a){return p.F(a)?a():a},Ha:function(a,f){return p.a.g((a.className||"").split(/\s+/),f)>=0},ta:function(a,f,b){var d=p.a.Ha(a,f);if(b&&!d)a.className=(a.className||"")+" "+f;else if(d&&!b){for(var b=(a.className||"").split(/\s+/),d="",e=0;e<b.length;e++)b[e]!=f&&(d+=b[e]+" ");a.className=p.a.m(d)}},Wa:function(a,f){for(var a=p.a.d(a),f=p.a.d(f),b=[],d=a;d<=f;d++)b.push(d);return b},la:function(a){for(var f=[],b=a.length-1;b>=0;b--)f.push(a[b]);return f},U:/MSIE 6/i.test(navigator.userAgent), | |
Pa:/MSIE 7/i.test(navigator.userAgent),ia:function(a,f){for(var b=p.a.la(a.getElementsByTagName("INPUT")).concat(p.a.la(a.getElementsByTagName("TEXTAREA"))),d=typeof f=="string"?function(a){return a.name===f}:function(a){return f.test(a.name)},e=[],i=b.length-1;i>=0;i--)d(b[i])&&e.push(b[i]);return e},H:function(a){if(typeof a=="string"&&(a=p.a.m(a))){if(window.JSON&&window.JSON.parse)return window.JSON.parse(a);return(new Function("return "+a))()}return o},aa:function(a){(typeof JSON=="undefined"|| | |
typeof JSON.stringify=="undefined")&&c(Error("Cannot find JSON.stringify(). Some browsers (e.g., IE < 8) don't support it natively, but you can overcome this by adding a script reference to json2.js, downloadable from http://www.json.org/json2.js"));return JSON.stringify(p.a.d(a))},Va:function(a,f,b){var b=b||{},d=b.params||{},e=b.includeFields||this.ha,i=a;if(typeof a=="object"&&a.tagName=="FORM")for(var i=a.action,k=e.length-1;k>=0;k--)for(var l=p.a.ia(a,e[k]),q=l.length-1;q>=0;q--)d[l[q].name]= | |
l[q].value;var f=p.a.d(f),m=document.createElement("FORM");m.style.display="none";m.action=i;m.method="post";for(var r in f)a=document.createElement("INPUT"),a.name=r,a.value=p.a.aa(p.a.d(f[r])),m.appendChild(a);for(r in d)a=document.createElement("INPUT"),a.name=r,a.value=d[r],m.appendChild(a);document.body.appendChild(m);b.submitter?b.submitter(m):m.submit();setTimeout(function(){m.parentNode.removeChild(m)},0)}}};p.b("ko.utils",p.a);p.b("ko.utils.arrayForEach",p.a.j); | |
p.b("ko.utils.arrayFirst",p.a.Ba);p.b("ko.utils.arrayFilter",p.a.N);p.b("ko.utils.arrayGetDistinctValues",p.a.bb);p.b("ko.utils.arrayIndexOf",p.a.g);p.b("ko.utils.arrayMap",p.a.O);p.b("ko.utils.arrayPushAll",p.a.B);p.b("ko.utils.arrayRemoveItem",p.a.P);p.b("ko.utils.fieldsIncludedWithJsonPost",p.a.ha);p.b("ko.utils.getFormFields",p.a.ia);p.b("ko.utils.postJson",p.a.Va);p.b("ko.utils.parseJson",p.a.H);p.b("ko.utils.registerEventHandler",p.a.t);p.b("ko.utils.stringifyJson",p.a.aa); | |
p.b("ko.utils.range",p.a.Wa);p.b("ko.utils.toggleDomNodeCssClass",p.a.ta);p.b("ko.utils.triggerEvent",p.a.ua);p.b("ko.utils.unwrapObservable",p.a.d);Function.prototype.bind||(Function.prototype.bind=function(d){var e=this,b=Array.prototype.slice.call(arguments),d=b.shift();return function(){return e.apply(d,b.concat(Array.prototype.slice.call(arguments)))}}); | |
p.a.e=new function(){var d=0,e="__ko__"+(new Date).getTime(),b={};return{get:function(a,b){var d=p.a.e.getAll(a,!1);return d===n?n:d[b]},set:function(a,b,d){d===n&&p.a.e.getAll(a,!1)===n||(p.a.e.getAll(a,!0)[b]=d)},getAll:function(a,f){var h=a[e];if(!h){if(!f)return;h=a[e]="ko"+d++;b[h]={}}return b[h]},clear:function(a){var f=a[e];f&&(delete b[f],a[e]=o)}}}; | |
p.a.p=new function(){function d(a,f){var d=p.a.e.get(a,b);d===n&&f&&(d=[],p.a.e.set(a,b,d));return d}function e(a){var b=d(a,!1);if(b)for(var b=b.slice(0),e=0;e<b.length;e++)b[e](a);p.a.e.clear(a);typeof jQuery=="function"&&typeof jQuery.cleanData=="function"&&jQuery.cleanData([a])}var b="__ko_domNodeDisposal__"+(new Date).getTime();return{ea:function(a,b){typeof b!="function"&&c(Error("Callback must be a function"));d(a,!0).push(b)},oa:function(a,f){var e=d(a,!1);e&&(p.a.P(e,f),e.length==0&&p.a.e.set(a, | |
b,n))},u:function(a){if(!(a.nodeType!=1&&a.nodeType!=9)){e(a);var b=[];p.a.B(b,a.getElementsByTagName("*"));for(var a=0,d=b.length;a<d;a++)e(b[a])}},removeNode:function(a){p.u(a);a.parentNode&&a.parentNode.removeChild(a)}}};p.u=p.a.p.u;p.removeNode=p.a.p.removeNode;p.b("ko.cleanNode",p.u);p.b("ko.removeNode",p.removeNode);p.b("ko.utils.domNodeDisposal",p.a.p);p.b("ko.utils.domNodeDisposal.addDisposeCallback",p.a.p.ea);p.b("ko.utils.domNodeDisposal.removeDisposeCallback",p.a.p.oa); | |
p.k=function(){function d(){return((1+Math.random())*4294967296|0).toString(16).substring(1)}function e(a,b){if(a)if(a.nodeType==8){var d=p.k.ma(a.nodeValue);d!=o&&b.push({Ga:a,Sa:d})}else if(a.nodeType==1)for(var d=0,g=a.childNodes,j=g.length;d<j;d++)e(g[d],b)}var b={};return{X:function(a){typeof a!="function"&&c(Error("You can only pass a function to ko.memoization.memoize()"));var f=d()+d();b[f]=a;return"<\!--[ko_memo:"+f+"]--\>"},va:function(a,f){var d=b[a];d===n&&c(Error("Couldn't find any memo with ID "+ | |
a+". Perhaps it's already been unmemoized."));try{return d.apply(o,f||[]),!0}finally{delete b[a]}},wa:function(a,b){var d=[];e(a,d);for(var g=0,j=d.length;g<j;g++){var i=d[g].Ga,k=[i];b&&p.a.B(k,b);p.k.va(d[g].Sa,k);i.nodeValue="";i.parentNode&&i.parentNode.removeChild(i)}},ma:function(a){return(a=a.match(/^\[ko_memo\:(.*?)\]$/))?a[1]:o}}}();p.b("ko.memoization",p.k);p.b("ko.memoization.memoize",p.k.X);p.b("ko.memoization.unmemoize",p.k.va);p.b("ko.memoization.parseMemoText",p.k.ma); | |
p.b("ko.memoization.unmemoizeDomNodeAndDescendants",p.k.wa);p.ga={};function x(d){var e=this;if(d)for(var b in d){var a=p.ga[b];typeof a=="function"&&(e=a(e,d[b]))}return e}p.b("ko.extenders",p.ga);p.ab=function(d,e){this.Q=d;this.n=function(){this.Oa=!0;e()}.bind(this);p.h(this,"dispose",this.n)}; | |
p.ba=function(){var d=[];this.ca=function(e,b){var a=b?e.bind(b):e,f=new p.ab(a,function(){p.a.P(d,f)});d.push(f);return f};this.z=function(e){p.a.j(d.slice(0),function(b){b&&b.Oa!==!0&&b.Q(e)})};this.Ma=function(){return d.length};this.extend=x;p.h(this,"subscribe",this.ca);p.h(this,"extend",this.extend);p.h(this,"notifySubscribers",this.z);p.h(this,"getSubscriptionsCount",this.Ma)};p.ka=function(d){return typeof d.ca=="function"&&typeof d.z=="function"};p.b("ko.subscribable",p.ba); | |
p.b("ko.isSubscribable",p.ka);p.C=function(){var d=[];return{Ca:function(e){d.push({Q:e,fa:[]})},end:function(){d.pop()},na:function(e){p.ka(e)||c("Only subscribable things can act as dependencies");if(d.length>0){var b=d[d.length-1];p.a.g(b.fa,e)>=0||(b.fa.push(e),b.Q(e))}}}}();var y={undefined:!0,"boolean":!0,number:!0,string:!0};function z(d,e){return d===o||typeof d in y?d===e:!1} | |
p.s=function(d){function e(){if(arguments.length>0){if(!e.equalityComparer||!e.equalityComparer(b,arguments[0]))b=arguments[0],e.z(b);return this}else return p.C.na(e),b}var b=d;e.o=p.s;e.J=function(){e.z(b)};e.equalityComparer=z;p.ba.call(e);p.h(e,"valueHasMutated",e.J);return e};p.F=function(d){if(d===o||d===n||d.o===n)return!1;if(d.o===p.s)return!0;return p.F(d.o)};p.G=function(d){if(typeof d=="function"&&d.o===p.s)return!0;if(typeof d=="function"&&d.o===p.i&&d.Na)return!0;return!1}; | |
p.b("ko.observable",p.s);p.b("ko.isObservable",p.F);p.b("ko.isWriteableObservable",p.G); | |
p.Ua=function(d){arguments.length==0&&(d=[]);d!==o&&d!==n&&!("length"in d)&&c(new "The argument passed when initializing an observable array must be an array, or null, or undefined.");var e=new p.s(d);p.a.j(["pop","push","reverse","shift","sort","splice","unshift"],function(b){e[b]=function(){var a=e(),a=a[b].apply(a,arguments);e.J();return a}});p.a.j(["slice"],function(b){e[b]=function(){var a=e();return a[b].apply(a,arguments)}});e.remove=function(b){for(var a=e(),f=[],d=[],g=typeof b=="function"? | |
b:function(a){return a===b},j=0,i=a.length;j<i;j++){var k=a[j];g(k)?d.push(k):f.push(k)}e(f);return d};e.Xa=function(b){if(b===n){var a=e();e([]);return a}if(!b)return[];return e.remove(function(a){return p.a.g(b,a)>=0})};e.R=function(b){for(var a=e(),f=typeof b=="function"?b:function(a){return a===b},d=a.length-1;d>=0;d--)f(a[d])&&(a[d]._destroy=!0);e.J()};e.Fa=function(b){if(b===n)return e.R(function(){return!0});if(!b)return[];return e.R(function(a){return p.a.g(b,a)>=0})};e.indexOf=function(b){var a= | |
e();return p.a.g(a,b)};e.replace=function(b,a){var d=e.indexOf(b);d>=0&&(e()[d]=a,e.J())};p.h(e,"remove",e.remove);p.h(e,"removeAll",e.Xa);p.h(e,"destroy",e.R);p.h(e,"destroyAll",e.Fa);p.h(e,"indexOf",e.indexOf);return e};p.b("ko.observableArray",p.Ua); | |
p.i=function(d,e,b){function a(){p.a.j(q,function(a){a.n()});q=[]}function f(){if(j&&typeof b.disposeWhen=="function"&&b.disposeWhen())h.n();else{try{a(),p.C.Ca(function(a){q.push(a.ca(f))}),g=b.owner?b.read.call(b.owner):b.read()}finally{p.C.end()}h.z(g);j=!0}}function h(){if(arguments.length>0)if(typeof b.write==="function"){var a=arguments[0];b.owner?b.write.call(b.owner,a):b.write(a)}else c("Cannot write a value to a dependentObservable unless you specify a 'write' option. If you wish to read the current value, don't pass any parameters."); | |
else return j||f(),p.C.na(h),g}var g,j=!1;d&&typeof d=="object"?b=d:(b=b||{},b.read=d||b.read,b.owner=e||b.owner);typeof b.read!="function"&&c("Pass a function that returns the value of the dependentObservable");var i=typeof b.disposeWhenNodeIsRemoved=="object"?b.disposeWhenNodeIsRemoved:o,k=o;if(i){k=function(){h.n()};p.a.p.ea(i,k);var l=b.disposeWhen;b.disposeWhen=function(){return!p.a.S(i)||typeof l=="function"&&l()}}var q=[];h.o=p.i;h.La=function(){return q.length};h.Na=typeof b.write==="function"; | |
h.n=function(){i&&p.a.p.oa(i,k);a()};p.ba.call(h);b.deferEvaluation!==!0&&f();p.h(h,"dispose",h.n);p.h(h,"getDependenciesCount",h.La);return h};p.i.o=p.s;p.b("ko.dependentObservable",p.i); | |
(function(){function d(a,f,h){h=h||new b;a=f(a);if(!(typeof a=="object"&&a!==o&&a!==n))return a;var g=a instanceof Array?[]:{};h.save(a,g);e(a,function(b){var e=f(a[b]);switch(typeof e){case "boolean":case "number":case "string":case "function":g[b]=e;break;case "object":case "undefined":var k=h.get(e);g[b]=k!==n?k:d(e,f,h)}});return g}function e(a,b){if(a instanceof Array)for(var d=0;d<a.length;d++)b(d);else for(d in a)b(d)}function b(){var a=[],b=[];this.save=function(d,e){var j=p.a.g(a,d);j>=0? | |
b[j]=e:(a.push(d),b.push(e))};this.get=function(d){d=p.a.g(a,d);return d>=0?b[d]:n}}p.sa=function(a){arguments.length==0&&c(Error("When calling ko.toJS, pass the object you want to convert."));return d(a,function(a){for(var b=0;p.F(a)&&b<10;b++)a=a();return a})};p.toJSON=function(a){a=p.sa(a);return p.a.aa(a)}})();p.b("ko.toJS",p.sa);p.b("ko.toJSON",p.toJSON); | |
p.f={l:function(d){if(d.tagName=="OPTION"){if(d.__ko__hasDomDataOptionValue__===!0)return p.a.e.get(d,p.c.options.Y);return d.getAttribute("value")}else return d.tagName=="SELECT"?d.selectedIndex>=0?p.f.l(d.options[d.selectedIndex]):n:d.value},L:function(d,e){if(d.tagName=="OPTION")switch(typeof e){case "string":case "number":p.a.e.set(d,p.c.options.Y,n);"__ko__hasDomDataOptionValue__"in d&&delete d.__ko__hasDomDataOptionValue__;d.value=e;break;default:p.a.e.set(d,p.c.options.Y,e),d.__ko__hasDomDataOptionValue__= | |
!0,d.value=""}else if(d.tagName=="SELECT")for(var b=d.options.length-1;b>=0;b--){if(p.f.l(d.options[b])==e){d.selectedIndex=b;break}}else{if(e===o||e===n)e="";d.value=e}}};p.b("ko.selectExtensions",p.f);p.b("ko.selectExtensions.readValue",p.f.l);p.b("ko.selectExtensions.writeValue",p.f.L); | |
p.r=function(){function d(a,b){return a.replace(e,function(a,d){return b[d]})}var e=/\[ko_token_(\d+)\]/g,b=/^[\_$a-z][\_$a-z0-9]*(\[.*?\])*(\.[\_$a-z][\_$a-z0-9]*(\[.*?\])*)*$/i,a=["true","false"];return{H:function(a){a=p.a.m(a);if(a.length<3)return{};for(var b=[],e=o,j,i=a.charAt(0)=="{"?1:0;i<a.length;i++){var k=a.charAt(i);if(e===o)switch(k){case '"':case "'":case "/":e=i;j=k;break;case "{":e=i;j="}";break;case "[":e=i,j="]"}else if(k==j){k=a.substring(e,i+1);b.push(k);var l="[ko_token_"+(b.length- | |
1)+"]",a=a.substring(0,e)+l+a.substring(i+1);i-=k.length-l.length;e=o}}e={};a=a.split(",");j=0;for(i=a.length;j<i;j++){var l=a[j],q=l.indexOf(":");q>0&&q<l.length-1&&(k=p.a.m(l.substring(0,q)),l=p.a.m(l.substring(q+1)),k.charAt(0)=="{"&&(k=k.substring(1)),l.charAt(l.length-1)=="}"&&(l=l.substring(0,l.length-1)),k=p.a.m(d(k,b)),l=p.a.m(d(l,b)),e[k]=l)}return e},T:function(d){var e=p.r.H(d),g=[],j;for(j in e){var i=e[j],k;k=i;k=p.a.g(a,p.a.m(k).toLowerCase())>=0?!1:k.match(b)!==o;k&&(g.length>0&&g.push(", "), | |
g.push(j+" : function(__ko_value) { "+i+" = __ko_value; }"))}g.length>0&&(d=d+", '_ko_property_writers' : { "+g.join("")+" } ");return d}}}();p.b("ko.jsonExpressionRewriting",p.r);p.b("ko.jsonExpressionRewriting.parseJson",p.r.H);p.b("ko.jsonExpressionRewriting.insertPropertyAccessorsIntoJson",p.r.T); | |
(function(){function d(a,b,d){for(var g,j=0;g=b.childNodes[j];j++)g.nodeType===1&&e(a,g,d)}function e(a,e,h){var g;e.getAttribute(b)&&(g=p.M(e,o,a,n,h));(!g||g.bindChildren!==!1)&&d(a,e,h)}var b="data-bind";p.c={};p.M=function(a,d,e,g,j){function i(a){return function(){return q[a]}}function k(){return q}var l=!0,g=g||b,q,m={},r=!0;new p.i(function(){var b;if(!(b=typeof d=="function"?d():d)){var s=a.getAttribute(g);try{var w=" { "+p.r.T(s)+" } ";b=p.a.Ka(w,e===o?window:e,j?j.outerScope:n)}catch(u){c(Error("Unable to parse binding attribute.\nMessage: "+ | |
u+";\nAttribute value: "+s))}}q=b;if(l)for(var v in q)if(m[v]={},(b=p.c[v])&&typeof b.init=="function")(b=b.init.call(b,a,i(v),k,e,m[v],j))&&b.bindChildren===!1&&(r=!1);for(v in q)(b=p.c[v])&&typeof b.update=="function"&&b.update.call(b,a,i(v),k,e,m[v],j)},o,{disposeWhenNodeIsRemoved:a});l=!1;return{bindChildren:r}};p.A=function(a,b,e){(!b||b.nodeType!==1)&&c(Error("ko.applyBindingsToDescendants: first parameter should be your view model; second parameter should be a DOM node"));d(a,b,e)};p.ya=function(a, | |
b,d){b&&b.nodeType!==1&&c(Error("ko.applyBindings: first parameter should be your view model; second parameter should be a DOM node"));b=b||window.document.body;e(a,b,d)};p.b("ko.bindingHandlers",p.c);p.b("ko.applyBindings",p.ya);p.b("ko.applyBindingsToDescendants",p.A);p.b("ko.applyBindingsToNode",p.M)})();p.a.j(["click"],function(d){p.c[d]={init:function(e,b,a,f){return p.c.event.init.call(this,e,function(){var a={};a[d]=b();return a},a,f)}}}); | |
p.c.event={init:function(d,e,b,a){var f=e()||{},h;for(h in f)(function(){var f=h;typeof f=="string"&&p.a.t(d,f,function(d){var h,k=e()[f],l=b();try{h=k.apply(a,arguments)}finally{if(h!==!0)d.preventDefault?d.preventDefault():d.returnValue=!1}if(l[f+"Bubble"]===!1)d.cancelBubble=!0,d.stopPropagation&&d.stopPropagation()})})()}}; | |
p.c.submit={init:function(d,e,b,a){typeof e()!="function"&&c(Error("The value for a submit binding must be a function to invoke on submit"));p.a.t(d,"submit",function(b){var h,g=e();try{h=g.call(a,d)}finally{if(h!==!0)b.preventDefault?b.preventDefault():b.returnValue=!1}})}};p.c.visible={update:function(d,e){var b=p.a.d(e()),a=d.style.display!="none";if(b&&!a)d.style.display="";else if(!b&&a)d.style.display="none"}}; | |
p.c.enable={update:function(d,e){var b=p.a.d(e());if(b&&d.disabled)d.removeAttribute("disabled");else if(!b&&!d.disabled)d.disabled=!0}};p.c.disable={update:function(d,e){p.c.enable.update(d,function(){return!p.a.d(e())})}}; | |
p.c.value={init:function(d,e,b){var a=b().valueUpdate||"change",f=!1;p.a.$a(a,"after")&&(f=!0,a=a.substring(5));var h=f?function(a){setTimeout(a,0)}:function(a){a()};p.a.t(d,a,function(){h(function(){var a=e(),f=p.f.l(d);p.G(a)?a(f):(a=b(),a._ko_property_writers&&a._ko_property_writers.value&&a._ko_property_writers.value(f))})})},update:function(d,e){var b=p.a.d(e()),a=p.f.l(d),f=b!=a;b===0&&a!==0&&a!=="0"&&(f=!0);f&&(a=function(){p.f.L(d,b)},a(),d.tagName=="SELECT"&&setTimeout(a,0));d.tagName=="SELECT"&& | |
(a=p.f.l(d),a!==b&&p.a.ua(d,"change"))}}; | |
p.c.options={update:function(d,e,b){d.tagName!="SELECT"&&c(Error("options binding applies only to SELECT elements"));var a=p.a.O(p.a.N(d.childNodes,function(a){return a.tagName&&a.tagName=="OPTION"&&a.selected}),function(a){return p.f.l(a)||a.innerText||a.textContent}),f=d.scrollTop,h=p.a.d(e());p.a.w(d);if(h){var g=b();typeof h.length!="number"&&(h=[h]);if(g.optionsCaption){var j=document.createElement("OPTION");j.innerHTML=g.optionsCaption;p.f.L(j,n);d.appendChild(j)}b=0;for(e=h.length;b<e;b++){var j= | |
document.createElement("OPTION"),i=typeof g.optionsValue=="string"?h[b][g.optionsValue]:h[b],k=g.optionsText;optionText=typeof k=="function"?k(h[b]):typeof k=="string"?h[b][k]:i;i=p.a.d(i);optionText=p.a.d(optionText);p.f.L(j,i);j.innerHTML=optionText.toString();d.appendChild(j)}h=d.getElementsByTagName("OPTION");b=g=0;for(e=h.length;b<e;b++)p.a.g(a,p.f.l(h[b]))>=0&&(p.a.qa(h[b],!0),g++);if(f)d.scrollTop=f}}};p.c.options.Y="__ko.bindingHandlers.options.optionValueDomData__"; | |
p.c.selectedOptions={ja:function(d){for(var e=[],d=d.childNodes,b=0,a=d.length;b<a;b++){var f=d[b];f.tagName=="OPTION"&&f.selected&&e.push(p.f.l(f))}return e},init:function(d,e,b){p.a.t(d,"change",function(){var a=e();p.G(a)?a(p.c.selectedOptions.ja(this)):(a=b(),a._ko_property_writers&&a._ko_property_writers.value&&a._ko_property_writers.value(p.c.selectedOptions.ja(this)))})},update:function(d,e){d.tagName!="SELECT"&&c(Error("values binding applies only to SELECT elements"));var b=p.a.d(e());if(b&& | |
typeof b.length=="number")for(var a=d.childNodes,f=0,h=a.length;f<h;f++){var g=a[f];g.tagName=="OPTION"&&p.a.qa(g,p.a.g(b,p.f.l(g))>=0)}}};p.c.text={update:function(d,e){var b=p.a.d(e());if(b===o||b===n)b="";typeof d.innerText=="string"?d.innerText=b:d.textContent=b}};p.c.html={update:function(d,e){var b=p.a.d(e());if(b===o||b===n)b="";d.innerHTML=b}};p.c.css={update:function(d,e){var b=p.a.d(e()||{}),a;for(a in b)if(typeof a=="string"){var f=p.a.d(b[a]);p.a.ta(d,a,f)}}}; | |
p.c.style={update:function(d,e){var b=p.a.d(e()||{}),a;for(a in b)if(typeof a=="string"){var f=p.a.d(b[a]);d.style[a]=f||""}}};p.c.uniqueName={init:function(d,e){if(e())d.name="ko_unique_"+ ++p.c.uniqueName.Ea,p.a.U&&d.mergeAttributes(document.createElement("<input name='"+d.name+"'/>"),!1)}};p.c.uniqueName.Ea=0; | |
p.c.checked={init:function(d,e,b){p.a.t(d,"click",function(){var a;if(d.type=="checkbox")a=d.checked;else if(d.type=="radio"&&d.checked)a=d.value;else return;var f=e();d.type=="checkbox"&&p.a.d(f)instanceof Array?(a=p.a.g(p.a.d(f),d.value),d.checked&&a<0?f.push(d.value):!d.checked&&a>=0&&f.splice(a,1)):p.G(f)?f()!==a&&f(a):(f=b(),f._ko_property_writers&&f._ko_property_writers.checked&&f._ko_property_writers.checked(a))});d.type=="radio"&&!d.name&&p.c.uniqueName.init(d,function(){return!0})},update:function(d, | |
e){var b=p.a.d(e());if(d.type=="checkbox")d.checked=b instanceof Array?p.a.g(b,d.value)>=0:b,b&&p.a.U&&d.mergeAttributes(document.createElement("<input type='checkbox' checked='checked' />"),!1);else if(d.type=="radio")d.checked=d.value==b,d.value==b&&(p.a.U||p.a.Pa)&&d.mergeAttributes(document.createElement("<input type='radio' checked='checked' />"),!1)}}; | |
p.c.attr={update:function(d,e){var b=p.a.d(e())||{},a;for(a in b)if(typeof a=="string"){var f=p.a.d(b[a]);f===!1||f===o||f===n?d.removeAttribute(a):d.setAttribute(a,f.toString())}}};p.c["if"]={init:function(d,e,b,a,f){f.W=d.innerHTML;f.K=!1;p.a.w(d);return{bindChildren:!1}},update:function(d,e,b,a,f){if((e=p.a.d(e()))&&!f.K)f.K=!0,d.innerHTML=f.W,this.activateChildNodes(d,e,a);else if(f.K&&!e)f.K=!1,p.a.w(d)},activateChildNodes:function(d,e,b){p.A(b,d)}}; | |
p.c["with"]={init:p.c["if"].init,update:p.c["if"].update,activateChildNodes:function(d,e){p.A(e,d)}};p.c.foreach={init:function(d,e,b,a,f){f.W=d.innerHTML;p.a.w(d);return{bindChildren:!1}},update:function(d,e,b,a,f){e=p.a.d(e());p.a.$(d,e,function(a){var b=document.createElement("DIV");b.innerHTML=f.W;p.A(a,b,{outerScope:{$data:a}});return b.childNodes})}}; | |
p.da=function(){this.renderTemplate=function(){c("Override renderTemplate in your ko.templateEngine subclass")};this.isTemplateRewritten=function(){c("Override isTemplateRewritten in your ko.templateEngine subclass")};this.rewriteTemplate=function(){c("Override rewriteTemplate in your ko.templateEngine subclass")};this.createJavaScriptEvaluatorBlock=function(){c("Override createJavaScriptEvaluatorBlock in your ko.templateEngine subclass")}};p.b("ko.templateEngine",p.da); | |
p.I=function(){var d=/(<[a-z]+\d*(\s+(?!data-bind=)[a-z0-9]+(=(\"[^\"]*\"|\'[^\']*\'))?)*\s+)data-bind=(["'])([\s\S]*?)\5/gi;return{Ja:function(d,b){b.isTemplateRewritten(d)||b.rewriteTemplate(d,function(a){return p.I.Ta(a,b)})},Ta:function(e,b){return e.replace(d,function(a,d,e,g,j,i,k){a=p.r.T(k);return b.createJavaScriptEvaluatorBlock("ko.templateRewriting.applyMemoizedBindingsToNextSibling(function() { return (function() { return { "+a+" } })() })")+d})},za:function(d){return p.k.X(function(b, | |
a){b.nextSibling&&p.M(b.nextSibling,d,a)})}}}();p.b("ko.templateRewriting",p.I);p.b("ko.templateRewriting.applyMemoizedBindingsToNextSibling",p.I.za); | |
(function(){function d(b,a,d,h,g){var j=p.a.d(h),g=g||{},i=g.templateEngine||e;p.I.Ja(d,i);d=i.renderTemplate(d,j,g);(typeof d.length!="number"||d.length>0&&typeof d[0].nodeType!="number")&&c("Template engine must return an array of DOM nodes");d&&p.a.j(d,function(a){p.k.wa(a,[h])});switch(a){case "replaceChildren":p.a.Za(b,d);break;case "replaceNode":p.a.pa(b,d);break;case "ignoreTargetNode":break;default:c(Error("Unknown renderMode: "+a))}g.afterRender&&g.afterRender(d,h);return d}var e;p.ra=function(b){b!= | |
n&&!(b instanceof p.da)&&c("templateEngine must inherit from ko.templateEngine");e=b};p.Z=function(b,a,f,h,g){f=f||{};(f.templateEngine||e)==n&&c("Set a template engine before calling renderTemplate");g=g||"replaceChildren";if(h){var j=h.nodeType?h:h.length>0?h[0]:o;return new p.i(function(){var e=typeof b=="function"?b(a):b,e=d(h,g,e,a,f);g=="replaceNode"&&(h=e,j=h.nodeType?h:h.length>0?h[0]:o)},o,{disposeWhen:function(){return!j||!p.a.S(j)},disposeWhenNodeIsRemoved:j&&g=="replaceNode"?j.parentNode: | |
j})}else return p.k.X(function(d){p.Z(b,a,f,d,"replaceNode")})};p.Ya=function(b,a,e,h){return new p.i(function(){var g=p.a.d(a)||[];typeof g.length=="undefined"&&(g=[g]);g=p.a.N(g,function(a){return e.includeDestroyed||!a._destroy});p.a.$(h,g,function(a){var h=typeof b=="function"?b(a):b;return d(o,"ignoreTargetNode",h,a,e)},e)},o,{disposeWhenNodeIsRemoved:h})};p.c.template={update:function(b,a,d,e){a=p.a.d(a());d=typeof a=="string"?a:a.name;if(typeof a.foreach!="undefined")e=p.Ya(d,a.foreach||[], | |
{templateOptions:a.templateOptions,afterAdd:a.afterAdd,beforeRemove:a.beforeRemove,includeDestroyed:a.includeDestroyed,afterRender:a.afterRender},b);else var g=a.data,e=p.Z(d,typeof g=="undefined"?e:g,{templateOptions:a.templateOptions,afterRender:a.afterRender},b);(a=p.a.e.get(b,"__ko__templateSubscriptionDomDataKey__"))&&typeof a.n=="function"&&a.n();p.a.e.set(b,"__ko__templateSubscriptionDomDataKey__",e)}}})();p.b("ko.setTemplateEngine",p.ra);p.b("ko.renderTemplate",p.Z); | |
p.a.v=function(d,e,b){if(b===n)return p.a.v(d,e,1)||p.a.v(d,e,10)||p.a.v(d,e,Number.MAX_VALUE);else{for(var d=d||[],e=e||[],a=d,f=e,h=[],g=0;g<=f.length;g++)h[g]=[];for(var g=0,j=Math.min(a.length,b);g<=j;g++)h[0][g]=g;g=1;for(j=Math.min(f.length,b);g<=j;g++)h[g][0]=g;for(var j=a.length,i,k=f.length,g=1;g<=j;g++){var l=Math.min(k,g+b);for(i=Math.max(1,g-b);i<=l;i++)h[i][g]=a[g-1]===f[i-1]?h[i-1][g-1]:Math.min(h[i-1][g]===n?Number.MAX_VALUE:h[i-1][g]+1,h[i][g-1]===n?Number.MAX_VALUE:h[i][g-1]+1)}b= | |
d.length;a=e.length;f=[];g=h[a][b];if(g===n)h=o;else{for(;b>0||a>0;){j=h[a][b];i=a>0?h[a-1][b]:g+1;k=b>0?h[a][b-1]:g+1;l=a>0&&b>0?h[a-1][b-1]:g+1;if(i===n||i<j-1)i=g+1;if(k===n||k<j-1)k=g+1;l<j-1&&(l=g+1);i<=k&&i<l?(f.push({status:"added",value:e[a-1]}),a--):(k<i&&k<l?f.push({status:"deleted",value:d[b-1]}):(f.push({status:"retained",value:d[b-1]}),a--),b--)}h=f.reverse()}return h}};p.b("ko.utils.compareArrays",p.a.v); | |
(function(){function d(d,b,a){var f=[],d=p.i(function(){var d=b(a)||[];f.length>0&&p.a.pa(f,d);f.splice(0,f.length);p.a.B(f,d)},o,{disposeWhenNodeIsRemoved:d,disposeWhen:function(){return f.length==0||!p.a.S(f[0])}});return{Ra:f,i:d}}p.a.$=function(e,b,a,f){for(var b=b||[],f=f||{},h=p.a.e.get(e,"setDomNodeChildrenFromArrayMapping_lastMappingResult")===n,g=p.a.e.get(e,"setDomNodeChildrenFromArrayMapping_lastMappingResult")||[],j=p.a.O(g,function(a){return a.Aa}),i=p.a.v(j,b),b=[],k=0,l=[],j=[],q=o, | |
m=0,r=i.length;m<r;m++)switch(i[m].status){case "retained":var t=g[k];b.push(t);t.D.length>0&&(q=t.D[t.D.length-1]);k++;break;case "deleted":g[k].i.n();p.a.j(g[k].D,function(a){l.push({element:a,index:m,value:i[m].value});q=a});k++;break;case "added":var s=d(e,a,i[m].value),t=s.Ra;b.push({Aa:i[m].value,D:t,i:s.i});for(var s=0,w=t.length;s<w;s++){var u=t[s];j.push({element:u,index:m,value:i[m].value});q==o?e.firstChild?e.insertBefore(u,e.firstChild):e.appendChild(u):q.nextSibling?e.insertBefore(u, | |
q.nextSibling):e.appendChild(u);q=u}}p.a.j(l,function(a){p.u(a.element)});a=!1;if(!h){if(f.afterAdd)for(m=0;m<j.length;m++)f.afterAdd(j[m].element,j[m].index,j[m].value);if(f.beforeRemove){for(m=0;m<l.length;m++)f.beforeRemove(l[m].element,l[m].index,l[m].value);a=!0}}a||p.a.j(l,function(a){a.element.parentNode&&a.element.parentNode.removeChild(a.element)});p.a.e.set(e,"setDomNodeChildrenFromArrayMapping_lastMappingResult",b)}})();p.b("ko.utils.setDomNodeChildrenFromArrayMapping",p.a.$); | |
p.V=function(){this.q=function(){if(typeof jQuery=="undefined"||!jQuery.tmpl)return 0;if(jQuery.tmpl.tag){if(jQuery.tmpl.tag.tmpl&&jQuery.tmpl.tag.tmpl.open&&jQuery.tmpl.tag.tmpl.open.toString().indexOf("__")>=0)return 3;return 2}return 1}();this.getTemplateNode=function(d){var b=document.getElementById(d);b==o&&c(Error("Cannot find template with ID="+d));return b};var d=RegExp("__ko_apos__","g");this.renderTemplate=function(e,b,a){a=a||{};this.q==0&&c(Error("jquery.tmpl not detected.\nTo use KO's default template engine, reference jQuery and jquery.tmpl. See Knockout installation documentation for more details.")); | |
if(this.q==1)return e='<script type="text/html">'+this.getTemplateNode(e).text+"<\/script>",b=jQuery.tmpl(e,b)[0].text.replace(d,"'"),jQuery.clean([b],document);if(!(e in jQuery.template)){var f=this.getTemplateNode(e).text;jQuery.template(e,f)}b=[b];b=jQuery.tmpl(e,b,a.templateOptions);b.appendTo(document.createElement("div"));jQuery.fragments={};return b};this.isTemplateRewritten=function(d){if(d in jQuery.template)return!0;return this.getTemplateNode(d).Qa===!0};this.rewriteTemplate=function(d, | |
b){var a=this.getTemplateNode(d),f=b(a.text);this.q==1&&(f=p.a.m(f),f=f.replace(/([\s\S]*?)(\${[\s\S]*?}|{{[\=a-z][\s\S]*?}}|$)/g,function(a,b,d){return b.replace(/\'/g,"__ko_apos__")+d}));a.text=f;a.Qa=!0};this.createJavaScriptEvaluatorBlock=function(d){if(this.q==1)return"{{= "+d+"}}";return"{{ko_code ((function() { return "+d+" })()) }}"};this.xa=function(d,b){document.write("<script type='text/html' id='"+d+"'>"+b+"<\/script>")};p.h(this,"addTemplate",this.xa);this.q>1&&(jQuery.tmpl.tag.ko_code= | |
{open:(this.q<3?"_":"__")+".push($1 || '');"})};p.V.prototype=new p.da;p.ra(new p.V);p.b("ko.jqueryTmplTemplateEngine",p.V); | |
})(window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment