knockoutjs-rails 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ Copyright 2012 Jacob Swanner
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # knockoutjs-rails
2
+
3
+ knockoutjs-rails wraps the [Knockout.js](http://knockoutjs.com/) library in a rails engine for simple
4
+ use with the asset pipeline provided by Rails > v. 3.1. The gem includes the development (non-minified)
5
+ source for ease of exploration. The asset pipeline will minify in production.
6
+
7
+ Knockout is a JavaScript library that helps you to create rich, responsive display and editor user
8
+ interfaces with a clean underlying data model. Please see the
9
+ [documentation](http://knockoutjs.com/documentation/introduction.html) for details.
10
+
11
+ ## Usage
12
+
13
+ Add the following to your gemfile:
14
+
15
+ gem 'knockoutjs-rails'
16
+
17
+ Add the following directive to your Javascript manifest file (application.js):
18
+
19
+ //= require knockout
20
+
21
+ ## Versioning
22
+
23
+ knockoutjs-rails 1.1.0 == Knockout.js 1.1.0
24
+
25
+ Every attempt is made to mirror the currently shipping Knockout.js version number wherever possible.
26
+ The major and minor version numbers will always represent the Knockout.js version, but the patch level
27
+ may differ should a fix to gem need to be pushed before Knockout.js ships an update to the library.
28
+
29
+ When the versions differ, it will be noted in the README.
@@ -0,0 +1,8 @@
1
+ require "knockoutjs-rails/version"
2
+
3
+ module Knockoutjs
4
+ module Rails
5
+ class Engine < ::Rails::Engine
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module Knockoutjs
2
+ module Rails
3
+ VERSION = "1.1.0"
4
+ end
5
+ end
@@ -0,0 +1,60 @@
1
+ // Knockout JavaScript library v1.1.0
2
+ // (c) 2010 Steven Sanderson - http://knockoutjs.com/
3
+ // License: Ms-Pl (http://www.opensource.org/licenses/ms-pl.html)
4
+
5
+ function b(f){throw f;}var m=true,n=null,o=false,p=window.ko={};p.b=function(f,a){for(var c=f.split("."),d=window,e=0;e<c.length-1;e++)d=d[c[e]];d[c[c.length-1]]=a};p.g=function(f,a,c){f[a]=c};
6
+ p.a=new function(){var f=/^(\s|\u00A0)+|(\s|\u00A0)+$/g;return{aa:["authenticity_token",/^__RequestVerificationToken(_.*)?$/],h:function(a,c){for(var d=0,e=a.length;d<e;d++)c(a[d])},i:function(a,c){if(typeof a.indexOf=="function")return a.indexOf(c);for(var d=0,e=a.length;d<e;d++)if(a[d]==c)return d;return-1},va:function(a,c,d){for(var e=0,g=a.length;e<g;e++)if(c.call(d,a[e]))return a[e];return n},X:function(a,c){var d=p.a.i(a,c);d>=0&&a.splice(d,1)},W:function(a){a=a||[];for(var c=[],d=0,e=a.length;d<
7
+ e;d++)p.a.i(c,a[d])<0&&c.push(a[d]);return c},I:function(a,c){a=a||[];for(var d=[],e=0,g=a.length;e<g;e++)d.push(c(a[e]));return d},H:function(a,c){a=a||[];for(var d=[],e=0,g=a.length;e<g;e++)c(a[e])&&d.push(a[e]);return d},J:function(a,c){for(var d=0,e=c.length;d<e;d++)a.push(c[d])},$:function(a){for(;a.firstChild;){p.a.d.K(a.firstChild);a.removeChild(a.firstChild)}},Qa:function(a,c){p.a.$(a);c&&p.a.h(c,function(d){a.appendChild(d)})},ja:function(a,c){var d=a.nodeType?[a]:a;if(d.length>0){for(var e=
8
+ d[0],g=e.parentNode,h=0,j=c.length;h<j;h++)g.insertBefore(c[h],e);h=0;for(j=d.length;h<j;h++){p.a.d.K(d[h]);g.removeChild(d[h])}}},ma:function(a,c){if(navigator.userAgent.indexOf("MSIE 6")>=0)a.setAttribute("selected",c);else a.selected=c},Ga:function(a,c){if(!a||a.nodeType!=1)return[];var d=[];a.getAttribute(c)!==n&&d.push(a);for(var e=a.getElementsByTagName("*"),g=0,h=e.length;g<h;g++)e[g].getAttribute(c)!==n&&d.push(e[g]);return d},m:function(a){return(a||"").replace(f,"")},Xa:function(a,c){for(var d=
9
+ [],e=(a||"").split(c),g=0,h=e.length;g<h;g++){var j=p.a.m(e[g]);j!==""&&d.push(j)}return d},Ra:function(a,c){a=a||"";if(c.length>a.length)return o;return a.substring(0,c.length)===c},Ea:function(a,c){if(c===undefined)return(new Function("return "+a))();with(c)return eval("("+a+")")},Ca:function(a,c){if(c.compareDocumentPosition)return(c.compareDocumentPosition(a)&16)==16;for(;a!=n;){if(a==c)return m;a=a.parentNode}return o},z:function(a){return p.a.Ca(a,document)},l:function(a,c,d){if(typeof jQuery!=
10
+ "undefined")jQuery(a).bind(c,d);else if(typeof a.addEventListener=="function")a.addEventListener(c,d,o);else if(typeof a.attachEvent!="undefined")a.attachEvent("on"+c,function(e){d.call(a,e)});else b(Error("Browser doesn't support addEventListener or attachEvent"))},Ua:function(a,c){if(!(a&&a.nodeType))b(Error("element must be a DOM node when calling triggerEvent"));if(typeof document.createEvent=="function")if(typeof a.dispatchEvent=="function"){var d=document.createEvent(c=="click"?"MouseEvents":
11
+ "HTMLEvents");d.initEvent(c,m,m,window,0,0,0,0,0,o,o,o,o,0,a);a.dispatchEvent(d)}else b(Error("The supplied element doesn't support dispatchEvent"));else if(typeof a.fireEvent!="undefined"){if(c=="click")if(a.tagName=="INPUT"&&(a.type.toLowerCase()=="checkbox"||a.type.toLowerCase()=="radio"))a.checked=a.checked!==m;a.fireEvent("on"+c)}else b(Error("Browser doesn't support triggering events"))},e:function(a){return p.O(a)?a():a},Ba:function(a,c){return p.a.i((a.className||"").split(/\s+/),c)>=0},Ta:function(a,
12
+ c,d){var e=p.a.Ba(a,c);if(d&&!e)a.className=(a.className||"")+" "+c;else if(e&&!d){d=(a.className||"").split(/\s+/);e="";for(var g=0;g<d.length;g++)if(d[g]!=c)e+=d[g]+" ";a.className=p.a.m(e)}},Na:function(a,c){a=p.a.e(a);c=p.a.e(c);for(var d=[],e=a;e<=c;e++)d.push(e);return d},fa:function(a){for(var c=[],d=a.length-1;d>=0;d--)c.push(a[d]);return c},N:/MSIE 6/i.test(navigator.userAgent),ca:function(a,c){for(var d=p.a.fa(a.getElementsByTagName("INPUT")).concat(p.a.fa(a.getElementsByTagName("TEXTAREA"))),
13
+ e=typeof c=="string"?function(j){return j.name===c}:function(j){return c.test(j.name)},g=[],h=d.length-1;h>=0;h--)e(d[h])&&g.push(d[h]);return g},oa:function(a){if(typeof JSON=="undefined"||typeof JSON.stringify=="undefined")b(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.e(a))},Ma:function(a,c,d){d=d||{};var e=
14
+ d.params||{},g=d.includeFields||this.aa,h=a;if(typeof a=="object"&&a.tagName=="FORM"){h=a.action;for(var j=g.length-1;j>=0;j--)for(var i=p.a.ca(a,g[j]),k=i.length-1;k>=0;k--)e[i[k].name]=i[k].value}c=p.a.e(c);var l=document.createElement("FORM");l.style.display="none";l.action=h;l.method="post";for(var q in c){a=document.createElement("INPUT");a.name=q;a.value=p.a.oa(p.a.e(c[q]));l.appendChild(a)}for(q in e){a=document.createElement("INPUT");a.name=q;a.value=e[q];l.appendChild(a)}document.body.appendChild(l);
15
+ d.submitter?d.submitter(l):l.submit();setTimeout(function(){l.parentNode.removeChild(l)},0)},d:{Va:0,v:"__ko__"+(new Date).getTime(),Wa:{},L:function(a,c){var d=p.a.d.ba(a,o);return d===undefined?undefined:d[c]},ka:function(a,c,d){p.a.d.ba(a,m)[c]=d},ba:function(a,c){var d=a[p.a.d.v];if(!d){if(!c)return;d=a[p.a.d.v]="ko"+p.a.d.Va++;p.a.d[d]={}}return p.a.d[d]},Y:function(a){var c=a[p.a.d.v];if(c){delete p.a.d[c];a[p.a.d.v]=n}},K:function(a){if(!(a.nodeType!=1&&a.nodeType!=9)){p.a.d.Y(a);a=a.getElementsByTagName("*");
16
+ for(var c=0,d=a.length;c<d;c++)p.a.d.Y(a[c])}}}}};p.b("ko.utils",p.a);p.b("ko.utils.arrayForEach",p.a.h);p.b("ko.utils.arrayFirst",p.a.va);p.b("ko.utils.arrayFilter",p.a.H);p.b("ko.utils.arrayGetDistinctValues",p.a.W);p.b("ko.utils.arrayIndexOf",p.a.i);p.b("ko.utils.arrayMap",p.a.I);p.b("ko.utils.arrayPushAll",p.a.J);p.b("ko.utils.arrayRemoveItem",p.a.X);p.b("ko.utils.fieldsIncludedWithJsonPost",p.a.aa);p.b("ko.utils.getFormFields",p.a.ca);p.b("ko.utils.postJson",p.a.Ma);
17
+ p.b("ko.utils.stringifyJson",p.a.oa);p.b("ko.utils.range",p.a.Na);p.b("ko.utils.triggerEvent",p.a.Ua);p.b("ko.utils.unwrapObservable",p.a.e);Function.prototype.bind||(Function.prototype.bind=function(f){var a=this,c=Array.prototype.slice.call(arguments);f=c.shift();return function(){return a.apply(f,c.concat(Array.prototype.slice.call(arguments)))}});
18
+ p.j=function(){function f(){return((1+Math.random())*4294967296|0).toString(16).substring(1)}function a(d,e){if(d)if(d.nodeType==8){var g=p.j.ha(d.nodeValue);g!=n&&e.push({Aa:d,Ja:g})}else if(d.nodeType==1){g=0;for(var h=d.childNodes,j=h.length;g<j;g++)a(h[g],e)}}var c={};return{Q:function(d){if(typeof d!="function")b(Error("You can only pass a function to ko.memoization.memoize()"));var e=f()+f();c[e]=d;return"<!--[ko_memo:"+e+"]--\>"},pa:function(d,e){var g=c[d];if(g===undefined)b(Error("Couldn't find any memo with ID "+
19
+ d+". Perhaps it's already been unmemoized."));try{g.apply(n,e||[]);return m}finally{delete c[d]}},qa:function(d,e){var g=[];a(d,g);for(var h=0,j=g.length;h<j;h++){var i=g[h].Aa,k=[i];e&&p.a.J(k,e);p.j.pa(g[h].Ja,k);i.nodeValue="";i.parentNode&&i.parentNode.removeChild(i)}},ha:function(d){return(d=d.match(/^\[ko_memo\:(.*?)\]$/))?d[1]:n}}}();p.b("ko.memoization",p.j);p.b("ko.memoization.memoize",p.j.Q);p.b("ko.memoization.unmemoize",p.j.pa);p.b("ko.memoization.parseMemoText",p.j.ha);
20
+ p.b("ko.memoization.unmemoizeDomNodeAndDescendants",p.j.qa);p.Sa=function(f,a){this.xa=f;this.s=a;p.g(this,"dispose",this.s)};p.S=function(){var f=[];this.T=function(a,c){var d=new p.Sa(c?function(){a.call(c)}:a,function(){p.a.X(f,d)});f.push(d);return d};this.u=function(a){p.a.h(f.slice(0),function(c){c&&c.xa(a)})};this.Ha=function(){return f.length};p.g(this,"subscribe",this.T);p.g(this,"notifySubscribers",this.u);p.g(this,"getSubscriptionsCount",this.Ha)};
21
+ p.ea=function(f){return typeof f.T=="function"&&typeof f.u=="function"};p.b("ko.subscribable",p.S);p.b("ko.isSubscribable",p.ea);p.w=function(){var f=[];return{wa:function(){f.push([])},end:function(){return f.pop()},ia:function(a){if(!p.ea(a))b("Only subscribable things can act as dependencies");f.length>0&&f[f.length-1].push(a)}}}();
22
+ p.q=function(f){function a(d){if(arguments.length>0){c=d;a.u(c);return this}else{p.w.ia(a);return c}}var c=f;a.o=p.q;a.F=function(){a.u(c)};p.S.call(a);p.g(a,"valueHasMutated",a.F);return a};p.O=function(f){if(f===n||f===undefined||f.o===undefined)return o;if(f.o===p.q)return m;return p.O(f.o)};p.B=function(f){return typeof f=="function"&&f.o===p.q};p.b("ko.observable",p.q);p.b("ko.isObservable",p.O);p.b("ko.isWriteableObservable",p.B);
23
+ p.La=function(f){var a=new p.q(f);p.a.h(["pop","push","reverse","shift","sort","splice","unshift"],function(c){a[c]=function(){var d=a();d=d[c].apply(d,arguments);a.F();return d}});p.a.h(["slice"],function(c){a[c]=function(){var d=a();return d[c].apply(d,arguments)}});a.remove=function(c){for(var d=a(),e=[],g=[],h=typeof c=="function"?c:function(l){return l===c},j=0,i=d.length;j<i;j++){var k=d[j];h(k)?g.push(k):e.push(k)}a(e);return g};a.Oa=function(c){if(!c)return[];return a.remove(function(d){return p.a.i(c,
24
+ d)>=0})};a.Z=function(c){for(var d=a(),e=typeof c=="function"?c:function(h){return h===c},g=d.length-1;g>=0;g--)if(e(d[g]))d[g]._destroy=m;a.F()};a.za=function(c){if(!c)return[];return a.Z(function(d){return p.a.i(c,d)>=0})};a.indexOf=function(c){var d=a();return p.a.i(d,c)};a.replace=function(c,d){var e=a.indexOf(c);if(e>=0){a()[e]=d;a.F()}};p.g(a,"remove",a.remove);p.g(a,"removeAll",a.Oa);p.g(a,"destroy",a.Z);p.g(a,"destroyAll",a.za);p.g(a,"indexOf",a.indexOf);return a};
25
+ p.b("ko.observableArray",p.La);
26
+ p.n=function(f,a,c){function d(){p.a.h(j,function(l){l.s()});j=[]}function e(l){d();p.a.h(l,function(q){j.push(q.T(g))})}function g(){if(!k&&c&&typeof c.disposeWhen=="function")if(c.disposeWhen()){h.s();return}try{p.w.wa();i=a?f.call(a):f()}finally{var l=p.a.W(p.w.end());e(l)}h.u(i);k=o}function h(){if(arguments.length>0)b("Cannot write a value to a dependentObservable. Do not pass any parameters to it");p.w.ia(h);return i}if(typeof f!="function")b("Pass a function that returns the value of the dependentObservable");var j=
27
+ [],i,k=m;h.o=p.n;h.Fa=function(){return j.length};h.s=function(){d()};p.S.call(h);g();p.g(h,"dispose",h.s);p.g(h,"getDependenciesCount",h.Fa);return h};p.n.o=p.q;p.b("ko.dependentObservable",p.n);
28
+ p.f={k:function(f){if(f.tagName=="OPTION"){var a=f.getAttribute("value");if(a!==p.c.options.C)return a;return p.a.d.L(f,p.c.options.C)}else return f.tagName=="SELECT"?f.selectedIndex>=0?p.f.k(f.options[f.selectedIndex]):undefined:f.value},G:function(f,a){if(f.tagName=="OPTION"){p.a.d.ka(f,p.c.options.C,a);f.value=p.c.options.C}else if(f.tagName=="SELECT")for(var c=f.options.length-1;c>=0;c--){if(p.f.k(f.options[c])==a){f.selectedIndex=c;break}}else f.value=a}};p.b("ko.selectExtensions",p.f);
29
+ p.b("ko.selectExtensions.readValue",p.f.k);p.b("ko.selectExtensions.writeValue",p.f.G);
30
+ p.p=function(){function f(e,g){return e.replace(a,function(h,j){return g[j]})}var a=/\[ko_token_(\d+)\]/g,c=/^[\_$a-z][\_$a-z]*(\[.*?\])*(\.[\_$a-z][\_$a-z]*(\[.*?\])*)*$/i,d=["true","false"];return{ga:function(e){e=p.a.m(e);if(e.length<3)return{};for(var g=[],h=n,j,i=e.charAt(0)=="{"?1:0;i<e.length;i++){var k=e.charAt(i);if(h===n)switch(k){case '"':case "'":case "/":h=i;j=k;break;case "{":h=i;j="}";break;case "[":h=i;j="]"}else if(k==j){k=e.substring(h,i+1);g.push(k);var l="[ko_token_"+(g.length-
31
+ 1)+"]";e=e.substring(0,h)+l+e.substring(i+1);i-=k.length-l.length;h=n}}h={};e=e.split(",");j=0;for(i=e.length;j<i;j++){l=e[j];var q=l.indexOf(":");if(q>0&&q<l.length-1){k=p.a.m(l.substring(0,q));l=p.a.m(l.substring(q+1));if(k.charAt(0)=="{")k=k.substring(1);if(l.charAt(l.length-1)=="}")l=l.substring(0,l.length-1);k=p.a.m(f(k,g));l=p.a.m(f(l,g));h[k]=l}}return h},M:function(e){var g=p.p.ga(e),h=[],j;for(j in g){var i=g[j],k;k=i;k=p.a.i(d,p.a.m(k).toLowerCase())>=0?o:k.match(c)!==n;if(k){h.length>0&&
32
+ h.push(", ");h.push(j+" : function(__ko_value) { "+i+" = __ko_value; }")}}if(h.length>0)e=e+", '_ko_property_writers' : { "+h.join("")+" } ";return e}}}();p.b("ko.jsonExpressionRewriting",p.p);p.b("ko.jsonExpressionRewriting.parseJson",p.p.ga);p.b("ko.jsonExpressionRewriting.insertPropertyAccessorsIntoJson",p.p.M);p.c={};
33
+ p.V=function(f,a,c){var d=m;new p.n(function(){var e;if(!(e=typeof a=="function"?a():a)){var g=f.getAttribute("data-bind");try{var h=" { "+p.p.M(g)+" } ";e=p.a.Ea(h,c===n?window:c)}catch(j){b(Error("Unable to parse binding attribute.\nMessage: "+j+";\nAttribute value: "+g))}}e=e;if(d)for(var i in e)p.c[i]&&typeof p.c[i].init=="function"&&(0,p.c[i].init)(f,e[i],e,c);for(i in e)p.c[i]&&typeof p.c[i].update=="function"&&(0,p.c[i].update)(f,e[i],e,c)},n,{disposeWhen:function(){return!p.a.z(f)}});d=o};
34
+ p.sa=function(f,a){if(a&&a.nodeType==undefined)b(Error("ko.applyBindings: first parameter should be your view model; second parameter should be a DOM node (note: this is a breaking change since KO version 1.05)"));a=a||window.document.body;var c=p.a.Ga(a,"data-bind");p.a.h(c,function(d){p.V(d,n,f)})};p.b("ko.bindingHandlers",p.c);p.b("ko.applyBindings",p.sa);
35
+ p.c.click={init:function(f,a,c,d){p.a.l(f,"click",function(e){var g;try{g=a.call(d)}finally{if(g!==m)if(e.preventDefault)e.preventDefault();else e.returnValue=o}})}};p.c.submit={init:function(f,a,c,d){if(typeof a!="function")b(Error("The value for a submit binding must be a function to invoke on submit"));p.a.l(f,"submit",function(e){var g;try{g=a.call(d,f)}finally{if(g!==m)if(e.preventDefault)e.preventDefault();else e.returnValue=o}})}};
36
+ p.c.visible={update:function(f,a){a=p.a.e(a);var c=f.style.display!="none";if(a&&!c)f.style.display="";else if(!a&&c)f.style.display="none"}};p.c.enable={update:function(f,a){if((a=p.a.e(a))&&f.disabled)f.removeAttribute("disabled");else if(!a&&!f.disabled)f.disabled=m}};p.c.disable={update:function(f,a){p.c.enable.update(f,!p.a.e(a))}};
37
+ p.c.value={init:function(f,a,c){var d=c.valueUpdate||"change",e=o;if(p.a.Ra(d,"after")){e=m;d=d.substring(5)}var g=e?function(h){setTimeout(h,0)}:function(h){h()};if(p.B(a))p.a.l(f,d,function(){g(function(){a(p.f.k(this))}.bind(this))});else c._ko_property_writers&&c._ko_property_writers.value&&p.a.l(f,d,function(){g(function(){c._ko_property_writers.value(p.f.k(this))}.bind(this))})},update:function(f,a){var c=p.a.e(a);if(c!=p.f.k(f)){var d=function(){p.f.G(f,c)};d();f.tagName=="SELECT"&&setTimeout(d,
38
+ 0)}}};
39
+ p.c.options={update:function(f,a,c){if(f.tagName!="SELECT")b(Error("options binding applies only to SELECT elements"));var d=p.a.I(p.a.H(f.childNodes,function(i){return i.tagName&&i.tagName=="OPTION"&&i.selected}),function(i){return p.f.k(i)||i.innerText||i.textContent});a=p.a.e(a);p.a.$(f);if(a){if(typeof a.length!="number")a=[a];if(c.optionsCaption){var e=document.createElement("OPTION");e.innerHTML=c.optionsCaption;p.f.G(e,undefined);f.appendChild(e)}for(var g=0,h=a.length;g<h;g++){e=document.createElement("OPTION");var j=
40
+ typeof c.optionsValue=="string"?a[g][c.optionsValue]:a[g];if(typeof j=="object")p.f.G(e,j);else e.value=j.toString();e.innerHTML=(typeof c.optionsText=="string"?a[g][c.optionsText]:j).toString();f.appendChild(e)}f=f.getElementsByTagName("OPTION");g=a=0;for(h=f.length;g<h;g++)if(p.a.i(d,p.f.k(f[g]))>=0){p.a.ma(f[g],m);a++}}}};p.c.options.C="__ko.bindingHandlers.options.optionValueDomData__";
41
+ p.c.selectedOptions={da:function(f){var a=[];f=f.childNodes;for(var c=0,d=f.length;c<d;c++){var e=f[c];e.tagName=="OPTION"&&e.selected&&a.push(p.f.k(e))}return a},init:function(f,a,c){if(p.B(a))p.a.l(f,"change",function(){a(p.c.selectedOptions.da(this))});else c._ko_property_writers&&c._ko_property_writers.value&&p.a.l(f,"change",function(){c._ko_property_writers.value(p.c.selectedOptions.da(this))})},update:function(f,a){if(f.tagName!="SELECT")b(Error("values binding applies only to SELECT elements"));
42
+ var c=p.a.e(a);if(c&&typeof c.length=="number")for(var d=f.childNodes,e=0,g=d.length;e<g;e++){var h=d[e];h.tagName=="OPTION"&&p.a.ma(h,p.a.i(c,p.f.k(h))>=0)}}};p.c.text={update:function(f,a){a=p.a.e(a);typeof f.innerText=="string"?f.innerText=a:f.textContent=a}};p.c.css={update:function(f,a){a=a||{};for(var c in a)if(typeof c=="string"){var d=p.a.e(a[c]);p.a.Ta(f,c,d)}}};p.c.style={update:function(f,a){a=p.a.e(a||{});for(var c in a)if(typeof c=="string"){var d=p.a.e(a[c]);f.style[c]=d||""}}};
43
+ p.c.uniqueName={init:function(f,a){if(a){f.name="ko_unique_"+ ++p.c.uniqueName.ya;p.a.N&&f.mergeAttributes(document.createElement("<INPUT name='"+f.name+"'/>"),o)}}};p.c.uniqueName.ya=0;
44
+ p.c.checked={init:function(f,a,c){if(p.B(a)){var d;if(f.type=="checkbox")d=function(){a(this.checked)};else if(f.type=="radio")d=function(){this.checked&&a(this.value)};if(d){p.a.l(f,"change",d);p.a.l(f,"click",d)}}else if(c._ko_property_writers&&c._ko_property_writers.checked){if(f.type=="checkbox")d=function(){c._ko_property_writers.checked(this.checked)};else if(f.type=="radio")d=function(){this.checked&&c._ko_property_writers.checked(this.value)};if(d){p.a.l(f,"change",d);p.a.l(f,"click",d)}}f.type==
45
+ "radio"&&!f.name&&p.c.uniqueName.init(f,m)},update:function(f,a){a=p.a.e(a);if(f.type=="checkbox")(f.checked=a)&&p.a.N&&f.mergeAttributes(document.createElement("<INPUT type='checkbox' checked='checked' />"),o);else if(f.type=="radio"){f.checked=f.value==a;f.value==a&&p.a.N&&f.mergeAttributes(document.createElement("<INPUT type='radio' checked='checked' />"),o)}}};
46
+ p.U=function(){this.renderTemplate=function(){b("Override renderTemplate in your ko.templateEngine subclass")};this.isTemplateRewritten=function(){b("Override isTemplateRewritten in your ko.templateEngine subclass")};this.rewriteTemplate=function(){b("Override rewriteTemplate in your ko.templateEngine subclass")};this.createJavaScriptEvaluatorBlock=function(){b("Override createJavaScriptEvaluatorBlock in your ko.templateEngine subclass")}};p.b("ko.templateEngine",p.U);
47
+ p.D=function(){var f=/(<[a-z]+(\s+(?!data-bind=)[a-z0-9]+(=(\"[^\"]*\"|\'[^\']*\'))?)*\s+)data-bind=(["'])(.*?)\5/g;return{Da:function(a,c){c.isTemplateRewritten(a)||c.rewriteTemplate(a,function(d){return p.D.Ka(d,c)})},Ka:function(a,c){return a.replace(f,function(d,e,g,h,j,i,k){d=k;d=p.p.M(d);return c.createJavaScriptEvaluatorBlock("ko.templateRewriting.applyMemoizedBindingsToNextSibling(function() { return (function() { return { "+d+" } })() })")+e})},ta:function(a){return p.j.Q(function(c,
48
+ d){c.nextSibling&&p.V(c.nextSibling,a,d)})}}}();p.b("ko.templateRewriting",p.D);p.b("ko.templateRewriting.applyMemoizedBindingsToNextSibling",p.D.ta);
49
+ (function(){function f(c,d,e,g,h){var j=p.a.e(g);h=h||{};var i=h.templateEngine||a;p.D.Da(e,i);e=i.renderTemplate(e,j,h);if(typeof e.length!="number"||e.length>0&&typeof e[0].nodeType!="number")b("Template engine must return an array of DOM nodes");e&&p.a.h(e,function(k){p.j.qa(k,[g])});switch(d){case "replaceChildren":p.a.Qa(c,e);break;case "replaceNode":p.a.ja(c,e);break;case "ignoreTargetNode":break;default:b(Error("Unknown renderMode: "+d))}return e}var a;p.na=function(c){if(c!=undefined&&!(c instanceof
50
+ p.U))b("templateEngine must inherit from ko.templateEngine");a=c};p.R=function(c,d,e,g,h){e=e||{};if((e.templateEngine||a)==undefined)b("Set a template engine before calling renderTemplate");h=h||"replaceChildren";if(g){var j=g.nodeType?g:g.length>0?g[0]:n;return new p.n(function(){var i=f(g,h,c,d,e);if(h=="replaceNode"){g=i;j=g.nodeType?g:g.length>0?g[0]:n}},n,{disposeWhen:function(){return!j||!p.a.z(j)}})}else return p.j.Q(function(i){p.R(c,d,e,i,"replaceNode")})};p.Pa=function(c,d,e,g){new p.n(function(){var h=
51
+ p.a.e(d)||[];if(typeof h.length=="undefined")h=[h];h=p.a.H(h,function(j){return e.includeDestroyed||!j._destroy});p.a.la(g,h,function(j){return f(n,"ignoreTargetNode",c,j,e)},e)},n,{disposeWhen:function(){return!p.a.z(g)}})};p.c.template={update:function(c,d,e,g){e=typeof d=="string"?d:d.name;if(typeof d.foreach!="undefined")p.Pa(e,d.foreach||[],{afterAdd:d.afterAdd,beforeRemove:d.beforeRemove,includeDestroyed:d.includeDestroyed},c);else{d=d.data;p.R(e,typeof d=="undefined"?g:d,n,c)}}}})();
52
+ p.b("ko.setTemplateEngine",p.na);p.b("ko.renderTemplate",p.R);
53
+ p.a.r=function(f,a,c){if(c===undefined)return p.a.r(f,a,1)||p.a.r(f,a,10)||p.a.r(f,a,Number.MAX_VALUE);else{f=f||[];a=a||[];for(var d=f,e=a,g=[],h=0;h<=e.length;h++)g[h]=[];h=0;for(var j=Math.min(d.length,c);h<=j;h++)g[0][h]=h;h=1;for(j=Math.min(e.length,c);h<=j;h++)g[h][0]=h;j=d.length;var i,k=e.length;for(h=1;h<=j;h++){var l=Math.min(k,h+c);for(i=Math.max(1,h-c);i<=l;i++)g[i][h]=d[h-1]===e[i-1]?g[i-1][h-1]:Math.min(g[i-1][h]===undefined?Number.MAX_VALUE:g[i-1][h]+1,g[i][h-1]===undefined?Number.MAX_VALUE:
54
+ g[i][h-1]+1)}f=f;a=a;c=f.length;d=a.length;e=[];h=g[d][c];if(h===undefined)g=n;else{for(;c>0||d>0;){j=g[d][c];i=d>0?g[d-1][c]:h+1;k=c>0?g[d][c-1]:h+1;l=d>0&&c>0?g[d-1][c-1]:h+1;if(i===undefined||i<j-1)i=h+1;if(k===undefined||k<j-1)k=h+1;if(l<j-1)l=h+1;if(i<=k&&i<l){e.push({status:"added",value:a[d-1]});d--}else{if(k<i&&k<l)e.push({status:"deleted",value:f[c-1]});else{e.push({status:"retained",value:f[c-1]});d--}c--}}g=e.reverse()}return g}};p.b("ko.utils.compareArrays",p.a.r);
55
+ (function(){function f(a,c){var d=[];p.n(function(){var e=a(c)||[];d.length>0&&p.a.ja(d,e);d.splice(0,d.length);p.a.J(d,e)},n,{disposeWhen:function(){return d.length==0||!p.a.z(d[0])}});return d}p.a.la=function(a,c,d,e){c=c||[];e=e||{};var g=p.a.d.L(a,"setDomNodeChildrenFromArrayMapping_lastMappingResult")===undefined,h=p.a.d.L(a,"setDomNodeChildrenFromArrayMapping_lastMappingResult")||[],j=p.a.I(h,function(r){return r.ua}),i=p.a.r(j,c);c=[];var k=0,l=[];j=[];for(var q=n,u=0,w=i.length;u<w;u++)switch(i[u].status){case "retained":var s=
56
+ h[k];c.push(s);if(s.A.length>0)q=s.A[s.A.length-1];k++;break;case "deleted":p.a.h(h[k].A,function(r){l.push(r);q=r});k++;break;case "added":s=f(d,i[u].value);c.push({ua:i[u].value,A:s});for(var v=0,x=s.length;v<x;v++){var t=s[v];j.push(t);if(q==n)a.firstChild?a.insertBefore(t,a.firstChild):a.appendChild(t);else q.nextSibling?a.insertBefore(t,q.nextSibling):a.appendChild(t);q=t}}p.a.h(l,function(r){p.a.d.K(r)});d=o;if(!g){e.afterAdd&&e.afterAdd(j);if(e.beforeRemove){e.beforeRemove(l);d=m}}d||p.a.h(l,
57
+ function(r){r.parentNode&&r.parentNode.removeChild(r)});p.a.d.ka(a,"setDomNodeChildrenFromArrayMapping_lastMappingResult",c)}})();p.b("ko.utils.setDomNodeChildrenFromArrayMapping",p.a.la);
58
+ p.P=function(){function f(c){var d=document.getElementById(c);if(d==n)b(Error("Cannot find template with ID="+c));return d}this.t=function(){if(typeof jQuery=="undefined"||!jQuery.tmpl)return 0;if(jQuery.tmpl.tag)return 2;return 1}();var a=RegExp("__ko_apos__","g");this.renderTemplate=function(c,d){if(this.t==0)b(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.t==1){var e=
59
+ '<script type="text/html">'+f(c).text+"<\/script>";e=jQuery.tmpl(e,d)[0].text.replace(a,"'");return jQuery.clean([e],document)}d=[d];e=f(c).text;return jQuery.tmpl(e,d)};this.isTemplateRewritten=function(c){return f(c).Ia===m};this.rewriteTemplate=function(c,d){var e=f(c),g=d(e.text);if(this.t==1){g=p.a.m(g);g=g.replace(/([\s\S]*?)(\${[\s\S]*?}|{{[\=a-z][\s\S]*?}}|$)/g,function(h,j,i){return j.replace(/\'/g,"__ko_apos__")+i})}e.text=g;e.Ia=m};this.createJavaScriptEvaluatorBlock=function(c){if(this.t==
60
+ 1)return"{{= "+c+"}}";return"{{ko_code ((function() { return "+c+" })()) }}"};this.ra=function(c,d){document.write("<script type='text/html' id='"+c+"'>"+d+"<\/script>")};p.g(this,"addTemplate",this.ra);if(this.t>1)jQuery.tmpl.tag.ko_code={open:"_.push($1 || '');"}};p.P.prototype=new p.U;p.na(new p.P);p.b("ko.jqueryTmplTemplateEngine",p.P);
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: knockoutjs-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jacob Swanner
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-28 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: railties
16
+ requirement: &70168471624040 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.1'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70168471624040
25
+ description: Knockout is a JavaScript library that helps you to create rich, responsive
26
+ display and editor user interfaces with a clean underlying data model
27
+ email:
28
+ - jacob@jacobswanner.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/knockoutjs-rails/version.rb
34
+ - lib/knockoutjs-rails.rb
35
+ - vendor/assets/javascripts/knockout.js
36
+ - MIT-LICENSE
37
+ - README.md
38
+ homepage: https://github.com/jswanner/knockoutjs-rails
39
+ licenses: []
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 1.8.11
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: The Knockout.js JavaScript library ready for the Rails asset pipeline.
62
+ test_files: []