From 214c142d9de60a7f53d8c7ada2812ffff4837e0f Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 8 Jan 2010 16:04:35 -0800 Subject: created a way to init the code without autobootstrap --- .externalToolBuilders/JSTD_Tests.launch | 10 ++ .project | 27 +++++ .settings/.jsdtscope | 13 +++ .../org.eclipse.wst.jsdt.ui.superType.container | 1 + .settings/org.eclipse.wst.jsdt.ui.superType.name | 1 + angular.js | 128 --------------------- example/calculator-auto_init.html | 12 ++ example/calculator-manual_init.html | 20 ++++ example/index.html | 11 ++ jsTestDriver.conf | 5 +- server.sh | 1 + src/Binder.js | 17 ++- src/Loader.js | 19 ++- src/angular-bootstrap.js | 49 ++++---- src/test/Runner.js | 18 +-- test.sh | 1 + test/ExternalApiTest.js | 12 ++ test/formsTest.js | 4 - test/testabilityPatch.js | 8 +- 19 files changed, 181 insertions(+), 176 deletions(-) create mode 100644 .externalToolBuilders/JSTD_Tests.launch create mode 100644 .project create mode 100644 .settings/.jsdtscope create mode 100644 .settings/org.eclipse.wst.jsdt.ui.superType.container create mode 100644 .settings/org.eclipse.wst.jsdt.ui.superType.name delete mode 100644 angular.js create mode 100644 example/calculator-auto_init.html create mode 100644 example/calculator-manual_init.html create mode 100644 example/index.html create mode 100755 server.sh create mode 100755 test.sh create mode 100644 test/ExternalApiTest.js diff --git a/.externalToolBuilders/JSTD_Tests.launch b/.externalToolBuilders/JSTD_Tests.launch new file mode 100644 index 00000000..17fb5035 --- /dev/null +++ b/.externalToolBuilders/JSTD_Tests.launch @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 00000000..0fb4c323 --- /dev/null +++ b/.project @@ -0,0 +1,27 @@ + + + angular.js + + + + + + org.eclipse.wst.jsdt.core.javascriptValidator + + + + + org.eclipse.ui.externaltools.ExternalToolBuilder + auto,full,incremental, + + + LaunchConfigHandle + <project>/.externalToolBuilders/JSTD_Tests.launch + + + + + + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/.settings/.jsdtscope b/.settings/.jsdtscope new file mode 100644 index 00000000..fcd57436 --- /dev/null +++ b/.settings/.jsdtscope @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/.settings/org.eclipse.wst.jsdt.ui.superType.container b/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100644 index 00000000..49c8cd4f --- /dev/null +++ b/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.JRE_CONTAINER \ No newline at end of file diff --git a/.settings/org.eclipse.wst.jsdt.ui.superType.name b/.settings/org.eclipse.wst.jsdt.ui.superType.name new file mode 100644 index 00000000..11006e2a --- /dev/null +++ b/.settings/org.eclipse.wst.jsdt.ui.superType.name @@ -0,0 +1 @@ +Global \ No newline at end of file diff --git a/angular.js b/angular.js deleted file mode 100644 index 0c19175d..00000000 --- a/angular.js +++ /dev/null @@ -1,128 +0,0 @@ -function r(){return function(a){return a}}function v(){return function(){}}function x(a){return function(b){this[a]=b}}function z(a){return function(){return a}}var A; -function aa(a){var b="",c,e,d,f,i,j,n=0;a=a;a=a.replace(/\r\n/g,"\n");e="";for(d=0;d127&&f<2048)e+=String.fromCharCode(f>>6|192);else{e+=String.fromCharCode(f>>12|224);e+=String.fromCharCode(f>>6&63|128)}e+=String.fromCharCode(f&63|128)}}for(a=e;n>2;c=(c&3)<<4|e>>4;i=(e&15)<<2|d>>6;j=d&63;if(isNaN(e))i=j=64;else if(isNaN(d))j=64;b=b+this.eb.charAt(f)+ -this.eb.charAt(c)+this.eb.charAt(i)+this.eb.charAt(j)}return b};(function(){var a=this,b=a.cb;function c(g){this.da=g}var e=typeof StopIteration!=="undefined"?StopIteration:"__break__",d=a.cb=function(g){return new c(g)};if(typeof exports!=="undefined")exports.cb=d;var f=Array.prototype.slice,i=Array.prototype.unshift,j=Object.prototype.toString,n=Object.prototype.hasOwnProperty,m=Object.prototype.propertyIsEnumerable;d.oe="0.5.1";d.a=function(g,h,k){try{if(g.forEach)g.forEach(h,k);else if(d.z(g)||d.dc(g))for(var l=0,p=g.length;l=l.ga&&(l={value:p,ga:s})});return l.value};d.min=function(g,h,k){if(!h&&d.z(g))return Math.min.apply(Math,g);var l={ga:Infinity};d.a(g,function(p,s,u){s=h?h.call(k,p,s,u):p;sp?1:0}),"value")};d.yf=function(g,h,k){k=k||d.ka;for(var l=0,p=g.length;l>1;k(g[s])=0})})};d.Pf=function(){for(var g=d.D(arguments),h=d.max(d.vb(g,"length")),k=new Array(h),l=0;l0?p-h:h-p)>=0)return l;l[s++]=p}};d.u=function(g,h){var k=d.Q(arguments,2);return function(){return g.apply(h||a,k.concat(d.D(arguments)))}};d.we=function(g){var h= -d.Q(arguments);if(h.length==0)h=d.nb(g);d.a(h,function(k){g[k]=d.u(g[k],g)});return g};d.lb=function(g,h){var k=d.Q(arguments,2);return setTimeout(function(){return g.apply(g,k)},h)};d.defer=function(g){return d.lb.apply(d,[g,1].concat(d.Q(arguments)))};d.Of=function(g,h){return function(){var k=[g].concat(d.D(arguments));return h.apply(h,k)}};d.Ie=function(){var g=d.D(arguments);return function(){for(var h=d.D(arguments),k=g.length-1;k>=0;k--)h=[g[k].apply(this,h)];return h[0]}};d.la=function(g){if(d.z(g))return d.Md(0, -g.length);var h=[];for(var k in g)n.call(g,k)&&h.push(k);return h};d.Ab=function(g){return d.map(g,d.ka)};d.nb=function(g){return d.select(d.la(g),function(h){return d.P(g[h])}).sort()};d.extend=function(g,h){for(var k in h)g[k]=h[k];return g};d.fa=function(g){if(d.z(g))return g.slice(0);return d.extend({},g)};d.isEqual=function(g,h){if(g===h)return true;var k=typeof g;if(k!=typeof h)return false;if(g==h)return true;if(!g&&h||g&&!h)return false;if(g.isEqual)return g.isEqual(h);if(d.pd(g)&&d.pd(h))return g.getTime()=== -h.getTime();if(d.fc(g)&&d.fc(h))return true;if(d.qd(g)&&d.qd(h))return g.source===h.source&&g.global===h.global&&g.ignoreCase===h.ignoreCase&&g.multiline===h.multiline;if(k!=="object")return false;if(g.length&&g.length!==h.length)return false;k=d.la(g);var l=d.la(h);if(k.length!=l.length)return false;for(var p in g)if(!d.isEqual(g[p],h[p]))return false;return true};d.bf=function(g){return d.la(g).length==0};d.af=function(g){return!!(g&&g.nodeType==1)};d.dc=function(g){return g&&"0"<=g.length&&g.length<= -"9"&&!d.z(g)&&!m.call(g,"length")};d.fc=function(g){return"0"<=g&&g<="9"&&isNaN(g)};d.cf=function(g){return g===null};d.K=function(g){return typeof g=="undefined"};for(var o=["Array","Date","Function","Number","RegExp","String"],q=0,w=o.length;q)[^\t]*)'/g,"$1\r").replace(/\t=(.*?)%>/g,"',$1,'").split("\t").join("');").split("%>").join("p.push('").split("\r").join("\\'")+"');}return p.join('');");return h?g(h):g};d.forEach=d.a;d.Se=d.We=d.reduce;d.Te=d.reduceRight;d.filter=d.select;d.every=d.all;d.some=d.Uc;d.ac=d.jd;d.Cf=d.Q;d.hf=d.nb;function y(g,h){return h?d(g).Ob():g}d.a(d.nb(d),function(g){var h= -d[g];c.prototype[g]=function(){i.call(arguments,this.da);return y(h.apply(d,arguments),this.db)}});d.a(["pop","push","reverse","shift","sort","splice","unshift"],function(g){var h=Array.prototype[g];c.prototype[g]=function(){h.apply(this.da,arguments);return y(this.da,this.db)}});d.a(["concat","join","slice"],function(g){var h=Array.prototype[g];c.prototype[g]=function(){return y(h.apply(this.da,arguments),this.db)}});c.prototype.Ob=function(){this.db=true;return this};c.prototype.value=function(){return this.da}})();if(typeof document.getAttribute=="undefined")document.getAttribute=v();if(typeof Node=="undefined")Node={ELEMENT_NODE:1,ATTRIBUTE_NODE:2,TEXT_NODE:3,CDATA_SECTION_NODE:4,ENTITY_REFERENCE_NODE:5,ENTITY_NODE:6,PROCESSING_INSTRUCTION_NODE:7,COMMENT_NODE:8,DOCUMENT_NODE:9,DOCUMENT_TYPE_NODE:10,DOCUMENT_FRAGMENT_NODE:11,NOTATION_NODE:12};if(_.K(window.jf))nglr={};if(_.K(window.Lb))angular={};if(_.K(angular.k))angular.k={};if(_.K(angular.filter))angular.filter={}; -if(_.K(window.console))window.console={log:v(),error:v()};if(_.K(nglr.alert))nglr.alert=function(){console.log(arguments);window.alert.apply(window,arguments)};nglr.Qb=function(a,b){var c=document.createElement("div");c.className=a;for(var e=a="",d=0;d/g,">")};nglr.hd=function(a){if(!a||!a.replace)return a;return a.replace(//g,">").replace(/\"/g,""")}; -nglr.u=function(a,b){if(!a)throw"Missing this";if(!_.P(b))throw"Missing function";return function(){return b.apply(a,arguments)}};nglr.Qd=function(a,b){return function(){for(var c=[this],e=0;e=0&&a.splice(c,1);return b},find:function(a,b,c){if(b){var e=angular.$.compile(b);_.Ub(a,function(d){if(e(d)){c=d;return true}});return c}},Pe:function(a,b){return angular.La.find(a,function(c){return c.R==b},null)},filter:function(a,b){var c= -[];c.Zc=function(m){for(var o=0;o-1;case "object":for(var q in m)if(q.charAt(0)!=="$"&&d(m[q],o))return true;return false;case "array":for(q=0;q=0&&a.splice(e,1);a.unshift((c?"-":"+")+b);return a},mf:function(a,b,c,e){c=c||"ng-ascend";e=e||"ng-descend";a=a[0]||"";var d=true;if(a.charAt(0)=="-"){a=a.substring(1);d=false}else if(a.charAt(0)=="+")a=a.substring(1);return a==b?d?c: -e:""},Ea:function(a,b,c){var e=a[b];if(!e){e={};a[b]=e}nglr.Ea(c,e);return a}}; -angular.U={quote:function(a){return'"'+a.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/\t/g,"\\t").replace(/\v/g,"\\v")+'"'},tc:function(a){a=angular.U.quote(a);for(var b=[],c=0;c-1;){c1||nglr.g.ea(a[0])!==null};nglr.g.ea=function(a){return(a=a.replace(/\n/gm," ").match(/^\{\{(.*)\}\}$/))?a[1]:null}; -function ga(a,b){var c={};b.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(e,d,f){if(d)c[decodeURIComponent(d)]=decodeURIComponent(f)});return c}function D(a,b){b=b||window.location.href;var c=b.indexOf("#");if(!(c<0)){b=b.substring(c+1);b=ga(a,b);jQuery.a(a.anchor,function(e){delete a.anchor[e]});jQuery.a(b,function(e,d){a.anchor[e]=d})}}nglr.g.prototype.Ld=function(a){console.log("URL change detected",a);D(this,a);this.c()}; -function ha(a){var b=window.location.href,c=b.indexOf("#");if(c>-1)b=b.substring(0,c);b+="#";c="";for(var e in a.anchor){var d=a.anchor[e];if(typeof d==="undefined"||d===null)delete a.anchor[e];else{b+=c+encodeURIComponent(e);if(d!==true)b+="="+encodeURIComponent(d);c="&"}}a=b;e=window.location.href;e.match(/#/)||(e+="#");if(e!=a)window.location.href=a;self.Oe=a;return b} -nglr.g.prototype.c=function(){(new Date).getTime();var a=jQuery(this.F).scope();E(a,"$invalidWidgets",[]);a.c();(new Date).getTime();ha(this);_.a(this.Cc,function(b){b()})};function fa(a){jQuery("[ng-init]",a.F).a(function(){var b=jQuery(this),c=b.scope();try{c.eval(b.e("ng-init"))}catch(e){nglr.alert("EVAL ERROR:\n"+b.e("ng-init")+"\n"+nglr.m(e,true))}})} -nglr.g.prototype.ha=function(a){jQuery("[ng-entity]",this.F).e("ng-watch",function(){try{var b=jQuery(this);return a.ha(b.e("ng-entity"))+(b.e("ng-watch")||"")}catch(c){nglr.alert(c)}})}; -nglr.g.prototype.compile=function(){var a=jQuery(this.F),b=this;if(this.w.Xc){var c=jQuery(":submit",this.F).rc("[ng-action]");c.e("ng-action","$save()");c.rc(":disabled").rc("ng-bind-attr").e("ng-bind-attr",'{disabled:"{{$invalidWidgets}}"}')}F(this,this.F)(this.F,a.scope(),"");jQuery("a[ng-action]",this.F).vd("click",function(){var e=jQuery(this);try{e.scope().eval(e.e("ng-action"));e.vc("ng-error");e.wc("ng-exception")}catch(d){e.fb("ng-exception");e.e("ng-error",nglr.m(d,true))}b.c();return false})}; -function ia(a,b,c,e){a=c.concat();c=a.pop();var d=nglr.g.Ha(b.nodeValue);if(d.length>1||nglr.g.ea(d[0])){var f=b.parentNode;if(nglr.ec(f)){f.setAttribute("ng-bind-template",b.nodeValue);e.push({path:a,b:function(o){return new nglr.S(o,o.getAttribute("ng-bind-template"))}})}else for(var i=0;i2&&b.setAttribute("ng-bind-attr",d)}b.getAttribute|| -console.log(b);var o=b.getAttribute("ng-repeat");if(o){b.removeAttribute("ng-repeat");var q=F(a,b);d=document.createComment("ng-repeat: "+o);f=b.parentNode;f.insertBefore(d,b);f.removeChild(b);var w=function(t,y,g){var h=jQuery(b).fa();h.kb("display","");h.e("ng-repeat-index",""+g);h.data("scope",t);q(h[0],t,y+g+":");return h};e.push({path:c,b:function(t,y,g){return new nglr.Xa(jQuery(t),o,w,g)}})}else{b.getAttribute("ng-eval")&&e.push({path:c,b:a.Dd});b.getAttribute("ng-bind")&&e.push({path:c,b:a.qc}); -b.getAttribute("ng-bind-attr")&&e.push({path:c,b:a.zd});b.getAttribute("ng-hide")&&e.push({path:c,b:a.Ed});b.getAttribute("ng-show")&&e.push({path:c,b:a.Fd});b.getAttribute("ng-class")&&e.push({path:c,b:a.Ad});b.getAttribute("ng-class-odd")&&e.push({path:c,b:a.Cd});b.getAttribute("ng-class-even")&&e.push({path:c,b:a.Bd});b.getAttribute("ng-style")&&e.push({path:c,b:a.Gd});b.getAttribute("ng-watch")&&e.push({path:c,b:a.Hd});d=b.nodeName;if(d=="INPUT"||d=="TEXTAREA"||d=="SELECT"||d=="BUTTON")e.push({path:c, -b:function(t,y,g){t.name=g+t.name.split(":").pop();return ja(a.$d,jQuery(t),y)}});if(d=="OPTION")if(!jQuery("')};nglr.T.prototype.j=function(a){var b=this.view.find("input").e("checked")?this.value:null;if(this.d===b)return false;else{E(a,this.xc,b);return true}}; -nglr.T.prototype.c=function(a){if((a=a.i(this.xc))&&this.value!==a){this.value=a;this.view.find("a").e("href",this.value.url).text(this.value.text);this.view.find("span").text(angular.filter.gb(this.value.size))}this.view.find("input").e("checked",!!a)};nglr.ba=x("view");nglr.ba.prototype.j=z(true);nglr.ba.prototype.c=v();nglr.ba.od=new nglr.ba;nglr.Na=x("view");nglr.Na.prototype.j=z(true);nglr.Na.prototype.c=v(); -nglr.bb=function(a,b){this.view=a;this.exp=b;this.k=a.getAttribute("ng-validate");this.Nd=typeof a.attributes["ng-required"]!="undefined";this.hc=null;this.d=undefined;this.H=a.value;a.getAttribute("ng-widget")==="datepicker"&&jQuery(a).Ne()};nglr.bb.prototype.j=function(a){var b=this.view.value;if(this.d===b)return false;else{$(a,this.exp,b);this.d=b;return true}}; -nglr.bb.prototype.c=function(a){var b=this.view,c=a.i(this.exp);if(typeof c==="undefined"){c=this.H;$(a,this.exp,c)}c=c?c:"";if(this.d!=c)this.d=b.value=c;var e=false;b.removeAttribute("ng-error");if(this.Nd)e=!(c&&c.length>0);var d=e?"Required Value":null;if(!e&&this.k&&c){e=this.k;c=c;d=nglr.h.ya[e];if(!d){d=(new nglr.q(e)).k();nglr.h.ya[e]=d}e={scope:a};d=d(e)(e,c);e=!!d}if(this.hc!==d){this.hc=e;if(d!==null){b.setAttribute("ng-error",d);a.I.he.push(this)}jQuery(b).zb("ng-validation-error",e)}}; -nglr.Oa=function(a,b){this.view=a;this.exp=b;this.d=undefined;this.H=a.checked?a.value:""};nglr.Oa.prototype.j=function(a){var b=this.view;b=b.checked?b.value:"";if(this.d===b)return false;else{$(a,this.exp,b);this.d=b;return true}};nglr.Oa.prototype.c=function(a){var b=this.view,c=a.eval(this.exp);if(typeof c==="undefined"){c=this.H;$(a,this.exp,c)}b.checked=b.value==""+c};nglr.Ya=function(a,b){this.view=a;this.exp=b;this.d=undefined;this.H=a.value}; -nglr.Ya.prototype.j=function(a){if(this.view.selectedIndex<0)$(a,this.exp,null);else{var b=this.view.value;if(this.d===b)return false;else{$(a,this.exp,b);this.d=b;return true}}};nglr.Ya.prototype.c=function(a){var b=this.view,c=a.i(this.exp);if(typeof c==="undefined"){c=this.H;$(a,this.exp,c)}if(c!==this.d){b.value=c?c:"";this.d=c}};nglr.ua=function(a,b){this.view=a;this.exp=b;this.d=undefined;this.H=this.selected()}; -nglr.ua.prototype.selected=function(){for(var a=[],b=this.view.options,c=0;ce;--b)this.xa.pop().element.removeNode();if(j&&j.element[0].nodeName==="OPTION")if(e=jQuery(j.element[0].parentNode).data("controller")){e.d=undefined;e.c(a)}})};nglr.A=x("F");nglr.A.Fb="mouseleave mouseout click dblclick keypress keyup";nglr.A.prototype.u=function(){this.F.find(".ng-validation-error,.ng-exception").vd("mouseover",nglr.A.Kd)}; -nglr.A.Kd=function(){nglr.A.ub();var a=jQuery(this);a.u(nglr.A.Fb,nglr.A.ub);var b=a.position(),c=document.documentElement,e=(self.innerWidth||c&&c.clientWidth||document.body.clientWidth)-b.left;c=a.Ue("ng-exception")?"EXCEPTION:":"Validation error...";a=a.e("ng-error");e=e>375?"left":"right";c=jQuery("
"+c+"
"+a+"
");jQuery("body").append(c);if(e==="left")a=b.left+this.offsetWidth+ -11;else{a=b.left-315;c.find(".ng-arrow-right").kb({left:301})}c.kb({left:a+"px",top:b.top-3+"px"});return true};nglr.A.ub=function(){jQuery("#ng-callout").Gf(nglr.A.Fb,nglr.A.ub).remove();return true};nglr.$a=function(a){this.lc=a.append(nglr.$a.Ic).find("#ng-loading");this.Ia=0};nglr.$a.Ic='
loading....
';function Da(a){a.Ia===0&&a.lc.wb();a.Ia++};(function(a){for(var b=/(.*)\/angular-(.*).js(#(.*))?/,c=document.getElementsByTagName("script"),e={Xc:true,Wc:true,Nb:false},d=0;d<\/script>')}if(e.Nb){m("/javascripts/webtoolkit.base64.js");m("/javascripts/swfobject.js");m("/javascripts/jQuery/jquery-1.3.2.js");m("/javascripts/jQuery/jquery-ui-1.7.1.custom.min.js");m("/javascripts/underscore/underscore.js");m("/javascripts/nglr/Loader.js");m("/javascripts/nglr/API.js");m("/javascripts/nglr/Binder.js");m("/javascripts/nglr/ControlBar.js");m("/javascripts/nglr/DataStore.js");m("/javascripts/nglr/Filters.js");m("/javascripts/nglr/JSON.js");m("/javascripts/nglr/Model.js"); -m("/javascripts/nglr/Parser.js");m("/javascripts/nglr/Scope.js");m("/javascripts/nglr/Server.js");m("/javascripts/nglr/Users.js");m("/javascripts/nglr/Validators.js");m("/javascripts/nglr/Widgets.js")}else{m("/ajax/libs/swfobject/2.2/swfobject.js","http://ajax.googleapis.com");m("/ajax/libs/jquery/1.3.2/jquery.min.js","http://ajax.googleapis.com");m("/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js","http://ajax.googleapis.com")}window.onload=function(){window.Lb.nd=function(h,k){var l=_.fa(e||{});_.extend(l, -k);(new nglr.Va(h,jQuery("head"),l)).load()};var o=window.document;if(e.Yc){o=null;for(var q=e.Yc.split("|"),w=0;w1)if(!window.document.getElementById(t[1]))continue;o=window.document.getElementById(y)}}e.Wc&&o&&window.Lb.nd(o);if(typeof a==="function")try{a.apply(this,arguments)}catch(g){}}})(window.onload); diff --git a/example/calculator-auto_init.html b/example/calculator-auto_init.html new file mode 100644 index 00000000..fa965042 --- /dev/null +++ b/example/calculator-auto_init.html @@ -0,0 +1,12 @@ + + + + + + + Quantity: + * + Cost: + = {{a * b | currency}} + + diff --git a/example/calculator-manual_init.html b/example/calculator-manual_init.html new file mode 100644 index 00000000..0d5c1bb6 --- /dev/null +++ b/example/calculator-manual_init.html @@ -0,0 +1,20 @@ + + + + + + + + Quantity: + * + Cost: + = {{a * b | currency}} + + diff --git a/example/index.html b/example/index.html new file mode 100644 index 00000000..aaaf8c80 --- /dev/null +++ b/example/index.html @@ -0,0 +1,11 @@ + + + + + + + + diff --git a/jsTestDriver.conf b/jsTestDriver.conf index 77a5f0bf..97136e7b 100644 --- a/jsTestDriver.conf +++ b/jsTestDriver.conf @@ -1,7 +1,6 @@ server: http://localhost:9876 load: - - lib/swfobject/swfobject.js - lib/webtoolkit/webtoolkit.base64.js - lib/jquery/jquery-1.3.2.js - lib/jquery/jquery-ui-1.7.1.custom.min.js @@ -13,4 +12,6 @@ load: - test/testabilityPatch.js - test/test/*.js - test/*.js - \ No newline at end of file + +exclude: + - src/angular-bootstrap.js diff --git a/server.sh b/server.sh new file mode 100755 index 00000000..7690cf8a --- /dev/null +++ b/server.sh @@ -0,0 +1 @@ +java -jar lib/jstestdriver/JsTestDriver.jar --port 9876 diff --git a/src/Binder.js b/src/Binder.js index 86e99fb8..8b4d27fb 100644 --- a/src/Binder.js +++ b/src/Binder.js @@ -103,8 +103,17 @@ nglr.Binder.prototype.updateView = function() { _.each(this.updateListeners, function(fn) {fn();}); }; +nglr.Binder.prototype.docFindWithSelf = function(exp){ + var doc = jQuery(this.doc); + var selection = doc.find(exp); + if (doc.is(exp)){ + selection = selection.andSelf(); + } + return selection; +}; + nglr.Binder.prototype.executeInit = function() { - jQuery("[ng-init]", this.doc).each(function() { + this.docFindWithSelf("[ng-init]").each(function() { var jThis = jQuery(this); var scope = jThis.scope(); try { @@ -116,7 +125,7 @@ nglr.Binder.prototype.executeInit = function() { }; nglr.Binder.prototype.entity = function (scope) { - jQuery("[ng-entity]", this.doc).attr("ng-watch", function() { + this.docFindWithSelf("[ng-entity]").attr("ng-watch", function() { try { var jNode = jQuery(this); var decl = scope.entity(jNode.attr("ng-entity")); @@ -131,12 +140,12 @@ nglr.Binder.prototype.compile = function() { var jNode = jQuery(this.doc); var self = this; if (this.config.autoSubmit) { - var submits = jQuery(":submit", this.doc).not("[ng-action]"); + var submits = this.docFindWithSelf(":submit").not("[ng-action]"); submits.attr("ng-action", "$save()"); submits.not(":disabled").not("ng-bind-attr").attr("ng-bind-attr", '{disabled:"{{$invalidWidgets}}"}'); } this.precompile(this.doc)(this.doc, jNode.scope(), ""); - jQuery("a[ng-action]", this.doc).live('click', function (event) { + this.docFindWithSelf("a[ng-action]").live('click', function (event) { var jNode = jQuery(this); try { jNode.scope().eval(jNode.attr('ng-action')); diff --git a/src/Loader.js b/src/Loader.js index fdcfa3cc..f7482d24 100644 --- a/src/Loader.js +++ b/src/Loader.js @@ -166,7 +166,6 @@ nglr.Loader.prototype.load = function() { this.loadCss('/stylesheets/jquery-ui/smoothness/jquery-ui-1.7.1.css'); this.loadCss('/stylesheets/nglr.css'); console.log("Server: " + this.config.server); - jQuery.noConflict(); nglr.msie = jQuery.browser.msie; this.configureJQueryPlugins(); this.computeConfiguration(); @@ -201,7 +200,7 @@ nglr.Loader.prototype.uid = function() { nglr.Loader.prototype.computeConfiguration = function() { var config = this.config; if (!config.database) { - var match = config.server.match(/https?:\/\/([\w]*)/) + var match = config.server.match(/https?:\/\/([\w]*)/); config.database = match ? match[1] : "$MEMORY"; } }; @@ -387,3 +386,19 @@ nglr.UrlWatcher.prototype.setUrl = function(url) { nglr.UrlWatcher.prototype.getUrl = function() { return window.location.href; }; + +window['angularFactory'] = function(config) { + var defaults = { + server: "" + }; + //todo: don't load stylesheet by default + //todo: don't start watcher + function compile(root){ + var loader = new nglr.Loader(root, jQuery("head"), _(defaults).extend(config)); + loader.load(); + return jQuery(root).scope(); + }; + return { + compile:compile + }; +}; diff --git a/src/angular-bootstrap.js b/src/angular-bootstrap.js index b7ae6a38..8ac4f9f3 100644 --- a/src/angular-bootstrap.js +++ b/src/angular-bootstrap.js @@ -39,25 +39,25 @@ }; if (scriptConfig.autoLoadDependencies) { - addScript("/javascripts/webtoolkit.base64.js"); - addScript("/javascripts/swfobject.js"); - addScript("/javascripts/jQuery/jquery-1.3.2.js"); - addScript("/javascripts/jQuery/jquery-ui-1.7.1.custom.min.js"); - addScript("/javascripts/underscore/underscore.js"); - addScript("/javascripts/nglr/Loader.js"); - addScript("/javascripts/nglr/API.js"); - addScript("/javascripts/nglr/Binder.js"); - addScript("/javascripts/nglr/ControlBar.js"); - addScript("/javascripts/nglr/DataStore.js"); - addScript("/javascripts/nglr/Filters.js"); - addScript("/javascripts/nglr/JSON.js"); - addScript("/javascripts/nglr/Model.js"); - addScript("/javascripts/nglr/Parser.js"); - addScript("/javascripts/nglr/Scope.js"); - addScript("/javascripts/nglr/Server.js"); - addScript("/javascripts/nglr/Users.js"); - addScript("/javascripts/nglr/Validators.js"); - addScript("/javascripts/nglr/Widgets.js"); + addScript("/../lib/webtoolkit/webtoolkit.base64.js"); + addScript("/../lib/swfobject/swfobject.js"); + addScript("/../lib/jquery/jquery-1.3.2.js"); + addScript("/../lib/jquery/jquery-ui-1.7.1.custom.min.js"); + addScript("/../lib/underscore/underscore.js"); + addScript("/Loader.js"); + addScript("/API.js"); + addScript("/Binder.js"); + addScript("/ControlBar.js"); + addScript("/DataStore.js"); + addScript("/Filters.js"); + addScript("/JSON.js"); + addScript("/Model.js"); + addScript("/Parser.js"); + addScript("/Scope.js"); + addScript("/Server.js"); + addScript("/Users.js"); + addScript("/Validators.js"); + addScript("/Widgets.js"); } else { addScript("/ajax/libs/swfobject/2.2/swfobject.js", "http://ajax.googleapis.com"); addScript("/ajax/libs/jquery/1.3.2/jquery.min.js", "http://ajax.googleapis.com"); @@ -65,12 +65,6 @@ } window.onload = function() { - window.angular.init = function(root, config){ - var cnfgMerged = _.clone(scriptConfig||{}); - _.extend(cnfgMerged, config); - new nglr.Loader(root, jQuery("head"), cnfgMerged).load(); - }; - var doc = window.document; if (scriptConfig.bindRootId) { doc = null; @@ -86,12 +80,13 @@ doc = window.document.getElementById(id); } } + var angular = window.angularFactory(scriptConfig); if (scriptConfig.autoBind && doc) { - window.angular.init(doc); + window.angularScope = angular.compile(doc); } if (typeof previousOnLoad === 'function') { try { - previousOnLoad.apply(this, arguments); + previousOnLoad.apply(this, arguments); } catch (e) {} } }; diff --git a/src/test/Runner.js b/src/test/Runner.js index 478ef73e..c7dd431a 100644 --- a/src/test/Runner.js +++ b/src/test/Runner.js @@ -1,3 +1,5 @@ +if (!nglr.test) nglr.test = {}; + nglr.test.ScenarioRunner = function(scenarios, body) { this.scenarios = scenarios; this.body = body; @@ -46,10 +48,10 @@ nglr.test.Runner.prototype = { scenario:jQuery('
') }; current.run = current.scenario.append( - '
' + - '.' + - '.' + - '.' + + '
' + + '.' + + '.' + + '.' + '').find(".run"); current.log = current.scenario.append('
').find(".log"); current.run.find(".name").text(name); @@ -79,7 +81,7 @@ nglr.test.Runner.prototype = { log.text(buf.join(" ")); this.current.log.append(log); this.console.scrollTop(this.console[0].scrollHeight); - if (level == "error") + if (level == "error") this.current.error = buf.join(" "); } }; @@ -114,16 +116,16 @@ nglr.test.Scenario.prototype = { else if (step.Then) fn = angular.test.THEN[step.Then]; return fn || function (){ throw "ERROR: Need Given/When/Then got: " + nglr.toJson(step); - }; + }; }, context: function(runner) { var frame = runner.frame; var window = frame[0].contentWindow; var document; - if (window.jQuery) + if (window.jQuery) document = window.jQuery(window.document); var context = { - frame:frame, + frame:frame, window:window, log:_.bind(runner.log, runner, "info"), document:document, diff --git a/test.sh b/test.sh new file mode 100755 index 00000000..8993c3ff --- /dev/null +++ b/test.sh @@ -0,0 +1 @@ +java -jar lib/jstestdriver/JsTestDriver.jar --tests all diff --git a/test/ExternalApiTest.js b/test/ExternalApiTest.js new file mode 100644 index 00000000..08771c49 --- /dev/null +++ b/test/ExternalApiTest.js @@ -0,0 +1,12 @@ +ExternalApiTest = TestCase("ExternalApiTest"); + +ExternalApiTest.prototype = { + testItShouldExposefactory:function(){ + var node = $('
{{b=a+1}}
')[0]; + var settings = {}; + var angular = angularFactory(settings); + var scope = angular.compile(node); + assertEquals(1, scope.get('a')); + assertEquals(2, scope.get('b')); + } +}; diff --git a/test/formsTest.js b/test/formsTest.js index e834e938..66c4ec69 100644 --- a/test/formsTest.js +++ b/test/formsTest.js @@ -16,7 +16,3 @@ nglrTest.prototype.testBind = function(){ assertEquals(arg, 'arg'); }).apply('XXX', ['arg']); }; - - - - diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index 5fca3524..13378d36 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -13,6 +13,12 @@ function noop(){} jstd = jstestdriver; +swfobject = { + createSwf:function(){ + fail("must mock out swfobject.createSwf in test."); + } +}; + function html(content) { return jQuery("
").html(content); } @@ -126,4 +132,4 @@ function assertThrows(error, fn){ fail("Expecting exception, none thrown"); } assertEquals(error, exception); -} \ No newline at end of file +} -- cgit v1.2.3 From eb9e66f4804cf417ce142e5515b039db73d31144 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Sat, 9 Jan 2010 13:21:24 -0800 Subject: cleanup --- Rakefile | 2 +- TODO.text | 6 ++ angular.js | 164 ++++++++++++++++++++++++++++++++++++ example/calculator-manual_init.html | 2 +- src/Loader.js | 1 + 5 files changed, 173 insertions(+), 2 deletions(-) create mode 100644 TODO.text create mode 100644 angular.js diff --git a/Rakefile b/Rakefile index 9fb7f173..56482e39 100644 --- a/Rakefile +++ b/Rakefile @@ -28,8 +28,8 @@ end desc 'Compile JavaScript with Google Closure Compiler' task :compileclosure do +# --compilation_level ADVANCED_OPTIMIZATIONS \ %x(java -jar lib/compiler-closure/compiler.jar \ - --compilation_level ADVANCED_OPTIMIZATIONS \ --js lib/webtoolkit/webtoolkit.base64.js \ --js lib/underscore/underscore.js \ --js src/Loader.js \ diff --git a/TODO.text b/TODO.text new file mode 100644 index 00000000..fab19695 --- /dev/null +++ b/TODO.text @@ -0,0 +1,6 @@ +* move angular-bootstrap.js out of anugular.js. +* 'angular' is the official namespace for public API + - angular.defaults = {} + - var scope = angular.compile(element, options); +* angular.js is not self boot straping by default. +* diff --git a/angular.js b/angular.js new file mode 100644 index 00000000..2ac33572 --- /dev/null +++ b/angular.js @@ -0,0 +1,164 @@ +var a,Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",encode:function(b){var c="",d,f,e,h,j,l,n=0;for(b=Base64._utf8_encode(b);n>2;d=(d&3)<<4|f>>4;j=(f&15)<<2|e>>6;l=e&63;if(isNaN(f))j=l=64;else if(isNaN(e))l=64;c=c+this._keyStr.charAt(h)+this._keyStr.charAt(d)+this._keyStr.charAt(j)+this._keyStr.charAt(l)}return c},decode:function(b){var c="",d,f,e,h,j,l=0;for(b=b.replace(/[^A-Za-z0-9\+\/\=]/g, +"");l>4;f=(f&15)<<4|h>>2;e=(h&3)<<6|j;c+=String.fromCharCode(d);if(h!=64)c+=String.fromCharCode(f);if(j!=64)c+=String.fromCharCode(e)}return c=Base64._utf8_decode(c)},_utf8_encode:function(b){b=b.replace(/\r\n/g,"\n");for(var c="",d=0;d127&&f<2048)c+= +String.fromCharCode(f>>6|192);else{c+=String.fromCharCode(f>>12|224);c+=String.fromCharCode(f>>6&63|128)}c+=String.fromCharCode(f&63|128)}}return c},_utf8_decode:function(b){for(var c="",d=0,f=c1=c2=0;d191&&f<224){c2=b.charCodeAt(d+1);c+=String.fromCharCode((f&31)<<6|c2&63);d+=2}else{c2=b.charCodeAt(d+1);c3=b.charCodeAt(d+2);c+=String.fromCharCode((f&15)<<12|(c2&63)<<6|c3&63);d+=3}}return c}};(function(){var b=this,c=b._,d=function(g){this._wrapped=g},f=typeof StopIteration!=="undefined"?StopIteration:"__break__",e=b._=function(g){return new d(g)};if(typeof exports!=="undefined")exports._=e;var h=Array.prototype.slice,j=Array.prototype.unshift,l=Object.prototype.toString,n=Object.prototype.hasOwnProperty,o=Object.prototype.propertyIsEnumerable;e.VERSION="0.5.1";e.each=function(g,i,k){try{if(g.forEach)g.forEach(i,k);else if(e.isArray(g)||e.isArguments(g))for(var m=0,q=g.length;m=m.computed&&(m={value:q,computed:r})});return m.value};e.min=function(g,i,k){if(!i&&e.isArray(g))return Math.min.apply(Math,g);var m={computed:Infinity};e.each(g,function(q,r,t){r=i?i.call(k,q,r,t):q;rq?1:0}),"value")};e.sortedIndex=function(g,i,k){k=k||e.identity;for(var m=0,q=g.length;m>1;k(g[r])=0})})};e.zip=function(){for(var g=e.toArray(arguments),i=e.max(e.pluck(g,"length")),k=new Array(i),m=0;m0?q-i:i-q)>=0)return m;m[r++]=q}};e.bind=function(g,i){var k=e.rest(arguments,2);return function(){return g.apply(i||b,k.concat(e.toArray(arguments)))}};e.bindAll=function(g){var i=e.rest(arguments);if(i.length==0)i=e.functions(g);e.each(i,function(k){g[k]=e.bind(g[k], +g)});return g};e.delay=function(g,i){var k=e.rest(arguments,2);return setTimeout(function(){return g.apply(g,k)},i)};e.defer=function(g){return e.delay.apply(e,[g,1].concat(e.rest(arguments)))};e.wrap=function(g,i){return function(){var k=[g].concat(e.toArray(arguments));return i.apply(i,k)}};e.compose=function(){var g=e.toArray(arguments);return function(){for(var i=e.toArray(arguments),k=g.length-1;k>=0;k--)i=[g[k].apply(this,i)];return i[0]}};e.keys=function(g){if(e.isArray(g))return e.range(0, +g.length);var i=[];for(var k in g)n.call(g,k)&&i.push(k);return i};e.values=function(g){return e.map(g,e.identity)};e.functions=function(g){return e.select(e.keys(g),function(i){return e.isFunction(g[i])}).sort()};e.extend=function(g,i){for(var k in i)g[k]=i[k];return g};e.clone=function(g){if(e.isArray(g))return g.slice(0);return e.extend({},g)};e.isEqual=function(g,i){if(g===i)return true;var k=typeof g;if(k!=typeof i)return false;if(g==i)return true;if(!g&&i||g&&!i)return false;if(g.isEqual)return g.isEqual(i); +if(e.isDate(g)&&e.isDate(i))return g.getTime()===i.getTime();if(e.isNaN(g)&&e.isNaN(i))return true;if(e.isRegExp(g)&&e.isRegExp(i))return g.source===i.source&&g.global===i.global&&g.ignoreCase===i.ignoreCase&&g.multiline===i.multiline;if(k!=="object")return false;if(g.length&&g.length!==i.length)return false;k=e.keys(g);var m=e.keys(i);if(k.length!=m.length)return false;for(var q in g)if(!e.isEqual(g[q],i[q]))return false;return true};e.isEmpty=function(g){return e.keys(g).length==0};e.isElement= +function(g){return!!(g&&g.nodeType==1)};e.isArguments=function(g){return g&&e.isNumber(g.length)&&!e.isArray(g)&&!o.call(g,"length")};e.isNaN=function(g){return e.isNumber(g)&&isNaN(g)};e.isNull=function(g){return g===null};e.isUndefined=function(g){return typeof g=="undefined"};for(var p=["Array","Date","Function","Number","RegExp","String"],s=0,v=p.length;s)[^\t]*)'/g,"$1\r").replace(/\t=(.*?)%>/g,"',$1,'").split("\t").join("');").split("%>").join("p.push('").split("\r").join("\\'")+"');}return p.join('');");return i?g(i):g};e.forEach=e.each;e.foldl=e.inject= +e.reduce;e.foldr=e.reduceRight;e.filter=e.select;e.every=e.all;e.some=e.any;e.head=e.first;e.tail=e.rest;e.methods=e.functions;var w=function(g,i){return i?e(g).chain():g};e.each(e.functions(e),function(g){var i=e[g];d.prototype[g]=function(){j.call(arguments,this._wrapped);return w(i.apply(e,arguments),this._chain)}});e.each(["pop","push","reverse","shift","sort","splice","unshift"],function(g){var i=Array.prototype[g];d.prototype[g]=function(){i.apply(this._wrapped,arguments);return w(this._wrapped, +this._chain)}});e.each(["concat","join","slice"],function(g){var i=Array.prototype[g];d.prototype[g]=function(){return w(i.apply(this._wrapped,arguments),this._chain)}});d.prototype.chain=function(){this._chain=true;return this};d.prototype.value=function(){return this._wrapped}})();if(typeof document.getAttribute=="undefined")document.getAttribute=function(){};if(typeof Node=="undefined")Node={ELEMENT_NODE:1,ATTRIBUTE_NODE:2,TEXT_NODE:3,CDATA_SECTION_NODE:4,ENTITY_REFERENCE_NODE:5,ENTITY_NODE:6,PROCESSING_INSTRUCTION_NODE:7,COMMENT_NODE:8,DOCUMENT_NODE:9,DOCUMENT_TYPE_NODE:10,DOCUMENT_FRAGMENT_NODE:11,NOTATION_NODE:12};if(_.isUndefined(window.nglr))nglr={};if(_.isUndefined(window.angular))angular={};if(_.isUndefined(angular.validator))angular.validator={}; +if(_.isUndefined(angular.filter))angular.filter={};if(_.isUndefined(window.console))window.console={log:function(){},error:function(){}};if(_.isUndefined(nglr.alert))nglr.alert=function(){console.log(arguments);window.alert.apply(window,arguments)};nglr.consoleLog=function(b,c){var d=document.createElement("div");d.className=b;for(var f=b="",e=0;e/g,">")}; +nglr.escapeAttr=function(b){if(!b||!b.replace)return b;return b.replace(//g,">").replace(/\"/g,""")};nglr.bind=function(b,c){if(!b)throw"Missing this";if(!_.isFunction(c))throw"Missing function";return function(){return c.apply(b,arguments)}};nglr.shiftBind=function(b,c){return function(){for(var d=[this],f=0;f=0&&b.splice(d,1);return c},find:function(b,c,d){if(c){var f=angular.Function.compile(c);_.detect(b,function(e){if(f(e)){d=e;return true}});return d}},findById:function(b,c){return angular.Array.find(b,function(d){return d.$id== +c},null)},filter:function(b,c){var d=[];d.check=function(o){for(var p=0;p-1;case "object":for(var s in o)if(s.charAt(0)!=="$"&&e(o[s],p))return true;return false;case "array":for(s=0;s=0&&b.splice(f,1);b.unshift((d?"-":"+")+c);return b},orderByDirection:function(b,c,d,f){d=d||"ng-ascend";f=f||"ng-descend";b=b[0]||"";var e=true;if(b.charAt(0)== +"-"){b=b.substring(1);e=false}else if(b.charAt(0)=="+")b=b.substring(1);return b==c?e?d:f:""},merge:function(b,c,d){var f=b[c];if(!f){f={};b[c]=f}nglr.merge(d,f);return b}}; +angular.String={quote:function(b){return'"'+b.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/\t/g,"\\t").replace(/\v/g,"\\v")+'"'},quoteUnicode:function(b){b=angular.String.quote(b);for(var c=[],d=0;d-1;){d1||nglr.Binder.binding(b[0])!==null};nglr.Binder.binding=function(b){return(b=b.replace(/\n/gm," ").match(/^\{\{(.*)\}\}$/))?b[1]:null};a=nglr.Binder.prototype;a.parseQueryString=function(b){var c={};b.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(d,f,e){if(f)c[decodeURIComponent(f)]=decodeURIComponent(e)});return c}; +a.parseAnchor=function(b){var c=this;b=b||this.urlWatcher.getUrl();var d=b.indexOf("#");if(!(d<0)){b=this.parseQueryString(b.substring(d+1));jQuery.each(c.anchor,function(f){delete c.anchor[f]});jQuery.each(b,function(f,e){c.anchor[f]=e})}};a.onUrlChange=function(b){console.log("URL change detected",b);this.parseAnchor(b);this.updateView()}; +a.updateAnchor=function(){var b=this.urlWatcher.getUrl(),c=b.indexOf("#");if(c>-1)b=b.substring(0,c);b+="#";c="";for(var d in this.anchor){var f=this.anchor[d];if(typeof f==="undefined"||f===null)delete this.anchor[d];else{b+=c+encodeURIComponent(d);if(f!==true)b+="="+encodeURIComponent(f);c="&"}}this.urlWatcher.setUrl(b);return b}; +a.updateView=function(){(new Date).getTime();var b=jQuery(this.doc).scope();b.set("$invalidWidgets",[]);b.updateView();(new Date).getTime();this.updateAnchor();_.each(this.updateListeners,function(c){c()})};a.docFindWithSelf=function(b){var c=jQuery(this.doc),d=c.find(b);if(c.is(b))d=d.andSelf();return d}; +a.executeInit=function(){this.docFindWithSelf("[ng-init]").each(function(){var b=jQuery(this),c=b.scope();try{c.eval(b.attr("ng-init"))}catch(d){nglr.alert("EVAL ERROR:\n"+b.attr("ng-init")+"\n"+nglr.toJson(d,true))}})};a.entity=function(b){this.docFindWithSelf("[ng-entity]").attr("ng-watch",function(){try{var c=jQuery(this);return b.entity(c.attr("ng-entity"))+(c.attr("ng-watch")||"")}catch(d){nglr.alert(d)}})}; +a.compile=function(){var b=jQuery(this.doc),c=this;if(this.config.autoSubmit){var d=this.docFindWithSelf(":submit").not("[ng-action]");d.attr("ng-action","$save()");d.not(":disabled").not("ng-bind-attr").attr("ng-bind-attr",'{disabled:"{{$invalidWidgets}}"}')}this.precompile(this.doc)(this.doc,b.scope(),"");this.docFindWithSelf("a[ng-action]").live("click",function(){var f=jQuery(this);try{f.scope().eval(f.attr("ng-action"));f.removeAttr("ng-error");f.removeClass("ng-exception")}catch(e){f.addClass("ng-exception"); +f.attr("ng-error",nglr.toJson(e,true))}c.updateView();return false})}; +a.translateBinding=function(b,c,d){c=c.concat();var f=c.pop(),e=nglr.Binder.parseBindings(b.nodeValue);if(e.length>1||nglr.Binder.binding(e[0])){var h=b.parentNode;if(nglr.isLeafNode(h)){h.setAttribute("ng-bind-template",b.nodeValue);d.push({path:c,fn:function(p){return new nglr.BindUpdater(p,p.getAttribute("ng-bind-template"))}})}else for(var j=0;j2&&b.setAttribute("ng-bind-attr",f)}b.getAttribute||console.log(b);var o=b.getAttribute("ng-repeat");if(o){b.removeAttribute("ng-repeat");var p=this.precompile(b);f=document.createComment("ng-repeat: "+o);e=b.parentNode;e.insertBefore(f,b);e.removeChild(b);var s=function(u,w,g){var i=jQuery(b).clone();i.css("display","");i.attr("ng-repeat-index",""+g);i.data("scope",u);p(i[0],u,w+g+":");return i};d.push({path:c,fn:function(u,w,g){return new nglr.RepeaterUpdater(jQuery(u),o,s,g)}})}else{b.getAttribute("ng-eval")&& +d.push({path:c,fn:this.ng_eval});b.getAttribute("ng-bind")&&d.push({path:c,fn:this.ng_bind});b.getAttribute("ng-bind-attr")&&d.push({path:c,fn:this.ng_bind_attr});b.getAttribute("ng-hide")&&d.push({path:c,fn:this.ng_hide});b.getAttribute("ng-show")&&d.push({path:c,fn:this.ng_show});b.getAttribute("ng-class")&&d.push({path:c,fn:this.ng_class});b.getAttribute("ng-class-odd")&&d.push({path:c,fn:this.ng_class_odd});b.getAttribute("ng-class-even")&&d.push({path:c,fn:this.ng_class_even});b.getAttribute("ng-style")&& +d.push({path:c,fn:this.ng_style});b.getAttribute("ng-watch")&&d.push({path:c,fn:this.ng_watch});f=b.nodeName;if(f=="INPUT"||f=="TEXTAREA"||f=="SELECT"||f=="BUTTON"){var v=this;d.push({path:c,fn:function(u,w,g){u.name=g+u.name.split(":").pop();return v.widgetFactory.createController(jQuery(u),w)}})}if(f=="OPTION")if(!jQuery("')};a=nglr.FileController.prototype;a._on_cancel=function(){};a._on_complete=function(){};a._on_httpStatus=function(b){nglr.alert("httpStatus:"+this.scopeName+" status:"+b)};a._on_ioError=function(){nglr.alert("ioError:"+this.scopeName)};a._on_open=function(){nglr.alert("open:"+this.scopeName)};a._on_progress=function(){}; +a._on_securityError=function(){nglr.alert("securityError:"+this.scopeName)};a._on_uploadCompleteData=function(b){b=nglr.fromJson(b);b.url=this.attachmentsPath+"/"+b.id+"/"+b.text;this.view.find("input").attr("checked",true);var c=this.view.scope();this.value=b;this.updateModel(c);this.value=null;c.get("$binder").updateView()};a._on_select=function(b,c){this.name=b;this.view.find("a").text(b).attr("href",b);this.view.find("span").text(angular.filter.bytes(c));this.upload()}; +a.updateModel=function(b){var c=this.view.find("input").attr("checked")?this.value:null;if(this.lastValue===c)return false;else{b.set(this.scopeName,c);return true}};a.updateView=function(b){if((b=b.get(this.scopeName))&&this.value!==b){this.value=b;this.view.find("a").attr("href",this.value.url).text(this.value.text);this.view.find("span").text(angular.filter.bytes(this.value.size))}this.view.find("input").attr("checked",!!b)};a.upload=function(){this.name&&this.uploader.uploadFile(this.attachmentsPath)}; +nglr.NullController=function(b){this.view=b};nglr.NullController.prototype.updateModel=function(){return true};nglr.NullController.prototype.updateView=function(){};nglr.NullController.instance=new nglr.NullController;nglr.ButtonController=function(b){this.view=b};nglr.ButtonController.prototype.updateModel=function(){return true};nglr.ButtonController.prototype.updateView=function(){}; +nglr.TextController=function(b,c){this.view=b;this.exp=c;this.validator=b.getAttribute("ng-validate");this.required=typeof b.attributes["ng-required"]!="undefined";this.lastErrorText=null;this.lastValue=undefined;this.initialValue=b.value;b.getAttribute("ng-widget")==="datepicker"&&jQuery(b).datepicker()};nglr.TextController.prototype.updateModel=function(b){var c=this.view.value;if(this.lastValue===c)return false;else{b.setEval(this.exp,c);this.lastValue=c;return true}}; +nglr.TextController.prototype.updateView=function(b){var c=this.view,d=b.get(this.exp);if(typeof d==="undefined"){d=this.initialValue;b.setEval(this.exp,d)}d=d?d:"";if(this.lastValue!=d)this.lastValue=c.value=d;var f=false;c.removeAttribute("ng-error");if(this.required)f=!(d&&d.length>0);var e=f?"Required Value":null;if(!f&&this.validator&&d){e=b.validate(this.validator,d);f=!!e}if(this.lastErrorText!==e){this.lastErrorText=f;if(e!==null){c.setAttribute("ng-error",e);b.markInvalid(this)}jQuery(c).toggleClass("ng-validation-error", +f)}};nglr.CheckboxController=function(b,c){this.view=b;this.exp=c;this.lastValue=undefined;this.initialValue=b.checked?b.value:""};nglr.CheckboxController.prototype.updateModel=function(b){var c=this.view;c=c.checked?c.value:"";if(this.lastValue===c)return false;else{b.setEval(this.exp,c);this.lastValue=c;return true}}; +nglr.CheckboxController.prototype.updateView=function(b){var c=this.view,d=b.eval(this.exp);if(typeof d==="undefined"){d=this.initialValue;b.setEval(this.exp,d)}c.checked=c.value==""+d};nglr.SelectController=function(b,c){this.view=b;this.exp=c;this.lastValue=undefined;this.initialValue=b.value}; +nglr.SelectController.prototype.updateModel=function(b){if(this.view.selectedIndex<0)b.setEval(this.exp,null);else{var c=this.view.value;if(this.lastValue===c)return false;else{b.setEval(this.exp,c);this.lastValue=c;return true}}};nglr.SelectController.prototype.updateView=function(b){var c=this.view,d=b.get(this.exp);if(typeof d==="undefined"){d=this.initialValue;b.setEval(this.exp,d)}if(d!==this.lastValue){c.value=d?d:"";this.lastValue=d}}; +nglr.MultiSelectController=function(b,c){this.view=b;this.exp=c;this.lastValue=undefined;this.initialValue=this.selected()};nglr.MultiSelectController.prototype.selected=function(){for(var b=[],c=this.view.options,d=0;df;--c)this.children.pop().element.removeNode();if(l&&l.element[0].nodeName==="OPTION")if(f=jQuery(l.element[0].parentNode).data("controller")){f.lastValue=undefined;f.updateView(b)}})};nglr.PopUp=function(b){this.doc=b};nglr.PopUp.OUT_EVENT="mouseleave mouseout click dblclick keypress keyup"; +nglr.PopUp.prototype.bind=function(){this.doc.find(".ng-validation-error,.ng-exception").live("mouseover",nglr.PopUp.onOver)}; +nglr.PopUp.onOver=function(){nglr.PopUp.onOut();var b=jQuery(this);b.bind(nglr.PopUp.OUT_EVENT,nglr.PopUp.onOut);var c=b.position(),d=document.documentElement,f=(self.innerWidth||d&&d.clientWidth||document.body.clientWidth)-c.left;d=b.hasClass("ng-exception")?"EXCEPTION:":"Validation error...";b=b.attr("ng-error");f=f>375?"left":"right";d=jQuery("
"+d+"
"+b+"
");jQuery("body").append(d); +if(f==="left")b=c.left+this.offsetWidth+11;else{b=c.left-315;d.find(".ng-arrow-right").css({left:301})}d.css({left:b+"px",top:c.top-3+"px"});return true};nglr.PopUp.onOut=function(){jQuery("#ng-callout").unbind(nglr.PopUp.OUT_EVENT,nglr.PopUp.onOut).remove();return true};nglr.Status=function(b){this.loader=b.append(nglr.Status.DOM).find("#ng-loading");this.requestCount=0};nglr.Status.DOM='
loading....
'; +nglr.Status.prototype.beginRequest=function(){this.requestCount===0&&this.loader.show();this.requestCount++};nglr.Status.prototype.endRequest=function(){this.requestCount--;this.requestCount===0&&this.loader.hide("fold")};(function(b){for(var c=/(.*)\/angular-(.*).js(#(.*))?/,d=document.getElementsByTagName("script"),f={autoSubmit:true,autoBind:true,autoLoadDependencies:false},e=0;e<\/script>')};if(f.autoLoadDependencies){c("/../lib/webtoolkit/webtoolkit.base64.js");c("/../lib/swfobject/swfobject.js");c("/../lib/jquery/jquery-1.3.2.js");c("/../lib/jquery/jquery-ui-1.7.1.custom.min.js");c("/../lib/underscore/underscore.js");c("/Loader.js");c("/API.js");c("/Binder.js");c("/ControlBar.js");c("/DataStore.js");c("/Filters.js");c("/JSON.js");c("/Model.js");c("/Parser.js"); +c("/Scope.js");c("/Server.js");c("/Users.js");c("/Validators.js");c("/Widgets.js")}else{c("/ajax/libs/swfobject/2.2/swfobject.js","http://ajax.googleapis.com");c("/ajax/libs/jquery/1.3.2/jquery.min.js","http://ajax.googleapis.com");c("/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js","http://ajax.googleapis.com")}window.onload=function(){var o=window.document;if(f.bindRootId){o=null;for(var p=f.bindRootId.split("|"),s=0;s1)if(!window.document.getElementById(v[1]))continue; +o=window.document.getElementById(u)}}p=window.angularFactory(f);if(f.autoBind&&o)window.angularScope=p.compile(o);if(typeof b==="function")try{b.apply(this,arguments)}catch(w){}}})(window.onload); diff --git a/example/calculator-manual_init.html b/example/calculator-manual_init.html index 0d5c1bb6..6013345e 100644 --- a/example/calculator-manual_init.html +++ b/example/calculator-manual_init.html @@ -1,7 +1,7 @@ - + + + + + + + + + Quantity: + * + Cost: + = {{a * b | currency}} + + diff --git a/src/API.js b/src/API.js index 6fb6e8fc..49089da0 100644 --- a/src/API.js +++ b/src/API.js @@ -1,5 +1,5 @@ -angular.Global = { - typeOf:function(obj){ +angular['Global'] = { + 'typeOf':function(obj){ var type = typeof obj; switch(type) { case "object": @@ -12,10 +12,10 @@ angular.Global = { } }; -angular.Collection = {}; -angular.Object = {}; -angular.Array = { - includeIf:function(array, value, condition) { +angular['Collection'] = {}; +angular['Object'] = {}; +angular['Array'] = { + 'includeIf':function(array, value, condition) { var index = _.indexOf(array, value); if (condition) { if (index == -1) @@ -25,8 +25,8 @@ angular.Array = { } return array; }, - sum:function(array, expression) { - var fn = angular.Function.compile(expression); + 'sum':function(array, expression) { + var fn = angular['Function']['compile'](expression); var sum = 0; for (var i = 0; i < array.length; i++) { var value = 1 * fn(array[i]); @@ -36,15 +36,15 @@ angular.Array = { } return sum; }, - remove:function(array, value) { + 'remove':function(array, value) { var index = _.indexOf(array, value); if (index >=0) array.splice(index, 1); return value; }, - find:function(array, condition, defaultValue) { + 'find':function(array, condition, defaultValue) { if (!condition) return undefined; - var fn = angular.Function.compile(condition); + var fn = angular['Function']['compile'](condition); _.detect(array, function($){ if (fn($)){ defaultValue = $; @@ -53,10 +53,10 @@ angular.Array = { }); return defaultValue; }, - findById:function(array, id) { + 'findById':function(array, id) { return angular.Array.find(array, function($){return $.$id == id;}, null); }, - filter:function(array, expression) { + 'filter':function(array, expression) { var predicates = []; predicates.check = function(value) { for (var j = 0; j < predicates.length; j++) { @@ -136,16 +136,16 @@ angular.Array = { } return filtered; }, - add:function(array, value) { + 'add':function(array, value) { array.push(_.isUndefined(value)? {} : value); return array; }, - count:function(array, condition) { + 'count':function(array, condition) { if (!condition) return array.length; - var fn = angular.Function.compile(condition); + var fn = angular['Function']['compile'](condition); return _.reduce(array, 0, function(count, $){return count + (fn($)?1:0);}); }, - orderBy:function(array, expression, descend) { + 'orderBy':function(array, expression, descend) { function reverse(comp, descending) { return toBoolean(descending) ? function(a,b){return comp(b,a);} : comp; @@ -169,7 +169,7 @@ angular.Array = { descending = $.charAt(0) == '-'; $ = $.substring(1); } - var get = $ ? angular.Function.compile($) : _.identity; + var get = $ ? angular['Function']['compile']($) : _.identity; return reverse(function(a,b){ return compare(get(a),get(b)); }, descending); @@ -183,7 +183,7 @@ angular.Array = { }; return _.clone(array).sort(reverse(comparator, descend)); }, - orderByToggle:function(predicate, attribute) { + 'orderByToggle':function(predicate, attribute) { var STRIP = /^([+|-])?(.*)/; var ascending = false; var index = -1; @@ -205,7 +205,7 @@ angular.Array = { predicate.unshift((ascending ? "-" : "+") + attribute); return predicate; }, - orderByDirection:function(predicate, attribute, ascend, descend) { + 'orderByDirection':function(predicate, attribute, ascend, descend) { ascend = ascend || 'ng-ascend'; descend = descend || 'ng-descend'; var att = predicate[0] || ''; @@ -218,7 +218,7 @@ angular.Array = { } return att == attribute ? (direction ? ascend : descend) : ""; }, - merge:function(array, index, mergeValue) { + 'merge':function(array, index, mergeValue) { var value = array[index]; if (!value) { value = {}; @@ -228,8 +228,8 @@ angular.Array = { return array; } }; -angular.String = { - quote:function(string) { +angular['String'] = { + 'quote':function(string) { return '"' + string.replace(/\\/g, '\\\\'). replace(/"/g, '\\"'). replace(/\n/g, '\\n'). @@ -239,8 +239,8 @@ angular.String = { replace(/\v/g, '\\v') + '"'; }, - quoteUnicode:function(string) { - var str = angular.String.quote(string); + 'quoteUnicode':function(string) { + var str = angular['String']['quote'](string); var chars = []; for ( var i = 0; i < str.length; i++) { var ch = str.charCodeAt(i); @@ -253,7 +253,7 @@ angular.String = { } return chars.join(''); }, - toDate:function(string){ + 'toDate':function(string){ var match; if (typeof string == 'string' && (match = string.match(/^(\d\d\d\d)-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)Z$/))){ @@ -265,8 +265,8 @@ angular.String = { return string; } }; -angular.Date = { - toString:function(date){ +angular['Date'] = { + 'toString':function(date){ function pad(n) { return n < 10 ? "0" + n : n; } return (date.getUTCFullYear()) + '-' + pad(date.getUTCMonth() + 1) + '-' + @@ -276,8 +276,8 @@ angular.Date = { pad(date.getUTCSeconds()) + 'Z'; } }; -angular.Function = { - compile:function(expression) { +angular['Function'] = { + 'compile':function(expression) { if (_.isFunction(expression)){ return expression; } else if (expression){ @@ -299,20 +299,20 @@ angular.Function = { dst[name] = _[name]; }); }; - extend(angular.Global, {}, + extend(angular['Global'], {}, ['extend', 'clone','isEqual', 'isElement', 'isArray', 'isFunction', 'isUndefined']); - extend(angular.Collection, angular.Global, + extend(angular['Collection'], angular['Global'], ['each', 'map', 'reduce', 'reduceRight', 'detect', 'select', 'reject', 'all', 'any', 'include', 'invoke', 'pluck', 'max', 'min', 'sortBy', 'sortedIndex', 'toArray', 'size']); - extend(angular.Array, angular.Collection, + extend(angular['Array'], angular['Collection'], ['first', 'last', 'compact', 'flatten', 'without', 'uniq', 'intersect', 'zip', 'indexOf', 'lastIndexOf']); - extend(angular.Object, angular.Collection, + extend(angular['Object'], angular['Collection'], ['keys', 'values']); - extend(angular.String, angular.Global); - extend(angular.Function, angular.Global, + extend(angular['String'], angular['Global']); + extend(angular['Function'], angular['Global'], ['bind', 'bindAll', 'delay', 'defer', 'wrap', 'compose']); })(); \ No newline at end of file diff --git a/src/DataStore.js b/src/DataStore.js index bdf882a0..6eeabb21 100644 --- a/src/DataStore.js +++ b/src/DataStore.js @@ -92,7 +92,7 @@ DataStore.prototype.save = function(document, callback) { var cachedDoc = self.cache(document); _.each(self._cache.$collections, function(collection){ if (collection.$$accept(document)) { - angular.Array.includeIf(collection, cachedDoc, true); + angular['Array']['includeIf'](collection, cachedDoc, true); } }); if (document.$$anchor) { diff --git a/src/Filters.js b/src/Filters.js index dd4217be..b3f56e75 100644 --- a/src/Filters.js +++ b/src/Filters.js @@ -22,7 +22,7 @@ angular.filter.Meta.get = function(obj, attr){ } }; -angular.filter.currency = function(amount){ +angular.filter['currency'] = function(amount){ jQuery(this.element).toggleClass('ng-format-negative', amount < 0); return '$' + angular.filter.number.apply(this, [amount, 2]); }; diff --git a/src/JSON.js b/src/JSON.js index 84c9a857..238ed489 100644 --- a/src/JSON.js +++ b/src/JSON.js @@ -38,7 +38,7 @@ toJsonArray = function(buf, obj, pretty){ buf.push('' + obj); } } else if (type === 'string') { - return buf.push(angular.String.quoteUnicode(obj)); + return buf.push(angular['String']['quoteUnicode'](obj)); } else if (type === 'object') { if (obj instanceof Array) { buf.push("["); @@ -56,7 +56,7 @@ toJsonArray = function(buf, obj, pretty){ } buf.push("]"); } else if (obj instanceof Date) { - buf.push(angular.String.quoteUnicode(angular.Date.toString(obj))); + buf.push(angular['String']['quoteUnicode'](angular['Date']['toString'](obj))); } else { buf.push("{"); if (pretty) buf.push(pretty); @@ -78,7 +78,7 @@ toJsonArray = function(buf, obj, pretty){ buf.push(","); if (pretty) buf.push(pretty); } - buf.push(angular.String.quote(key)); + buf.push(angular['String']['quote'](key)); buf.push(":"); toJsonArray(buf, value, childPretty); comma = true; diff --git a/src/Loader.js b/src/Loader.js index dfaa355a..19840567 100644 --- a/src/Loader.js +++ b/src/Loader.js @@ -23,6 +23,8 @@ if (typeof Node == 'undefined') { } var callbacks = {}; +var jQuery = window['jQuery']; +var msie = jQuery['browser']['msie']; if (!window.angular){ angular = {}; window['angular'] = angular; } if (!angular.validator) angular.validator = {}; @@ -32,8 +34,8 @@ if (!window.console) log:function() {}, error:function() {} }; -if (_.isUndefined(alert)) { - alert = function(){console.log(arguments); window.alert.apply(window, arguments); }; +if (!angular.alert) { + angular.alert = function(){console.log(arguments); window.alert.apply(window, arguments); }; } var consoleNode; @@ -169,7 +171,6 @@ Loader.prototype.load = function() { this.loadCss('/stylesheets/jquery-ui/smoothness/jquery-ui-1.7.1.css'); this.loadCss('/stylesheets/css'); console.log("Server: " + this.config.server); - msie = jQuery.browser.msie; this.configureJQueryPlugins(); this.computeConfiguration(); this.bindHtml(); @@ -177,11 +178,7 @@ Loader.prototype.load = function() { Loader.prototype.configureJQueryPlugins = function() { console.log('Loader.configureJQueryPlugins()'); - jQuery.fn.removeNode = function() { - var node = this.get(0); - node.parentNode.removeChild(node); - }; - jQuery.fn.scope = function() { + jQuery['fn']['scope'] = function() { var element = this; while (element && element.get(0)) { var scope = element.data("scope"); @@ -191,7 +188,7 @@ Loader.prototype.configureJQueryPlugins = function() { } return null; }; - jQuery.fn.controller = function() { + jQuery['fn']['controller'] = function() { return this.data('controller') || NullController.instance; }; }; @@ -229,24 +226,19 @@ Loader.prototype.bindHtml = function() { var datastore = new DataStore(post, users, binder.anchor); binder.updateListeners.push(function(){datastore.flush();}); var scope = new Scope( { - $anchor : binder.anchor, - $binder : binder, - $config : this.config, - $console : window.console, - $datastore : datastore, - $save : function(callback) { + '$anchor' : binder.anchor, + '$binder' : binder, + '$config' : this.config, + '$console' : window.console, + '$datastore' : datastore, + '$save' : function(callback) { datastore.saveScope(scope.state, callback, binder.anchor); }, - $window : window, - $uid : this.uid, - $users : users + '$window' : window, + '$uid' : this.uid, + '$users' : users }, "ROOT"); - jQuery.each(["get", "set", "eval", "addWatchListener", "updateView"], - function(i, method){ - angular[method] = bind(scope, scope[method]); - }); - document.data('scope', scope); console.log('$binder.entity()'); binder.entity(scope); @@ -284,7 +276,6 @@ Loader.prototype.bindHtml = function() { watcher.watch(); document.find("body").show(); console.log('ready()'); - }; Loader.prototype.visualPost = function(delegate) { @@ -399,6 +390,12 @@ angular['compile'] = function(root, config) { //todo: don't start watcher var loader = new Loader(root, jQuery("head"), _(defaults).extend(config)); loader.load(); - return jQuery(root).scope(); + var scope = jQuery(root).scope(); + //TODO: cleanup + return { + 'updateView':function(){return scope.updateView.apply(scope, arguments);}, + 'set':function(){return scope.set.apply(scope, arguments);}, + 'get':function(){return scope.get.apply(scope, arguments);} + }; }; diff --git a/src/Parser.js b/src/Parser.js index b23215be..cdece11e 100644 --- a/src/Parser.js +++ b/src/Parser.js @@ -185,7 +185,7 @@ Lexer.prototype.readString = function(quote) { this.tokens.push({index:start, text:string, fn:function(){ return (string.length == dateParseLength) ? - angular.String.toDate(string) : string; + angular['String']['toDate'](string) : string; }}); return; } else { @@ -346,11 +346,11 @@ Parser.prototype.filterChain = function(){ }; Parser.prototype.filter = function(){ - return this._pipeFunction(angular.filter); + return this._pipeFunction(angular['filter']); }; Parser.prototype.validator = function(){ - return this._pipeFunction(angular.validator); + return this._pipeFunction(angular['validator']); }; Parser.prototype._pipeFunction = function(fnScope){ @@ -697,7 +697,7 @@ Parser.prototype.entityDecl = function () { self.scope.set(instance, document); return "$anchor." + instance + ":{" + instance + "=" + entity + ".load($anchor." + instance + ");" + - instance + ".$$anchor=" + angular.String.quote(instance) + ";" + + instance + ".$$anchor=" + angular['String']['quote'](instance) + ";" + "};"; } else { return ""; diff --git a/src/Scope.js b/src/Scope.js index e3634cee..dff3bfbd 100644 --- a/src/Scope.js +++ b/src/Scope.js @@ -55,7 +55,7 @@ Scope.getter = function(instance, path) { instance = instance[key]; } if (_.isUndefined(instance) && key.charAt(0) == '$') { - var type = angular.Global.typeOf(lastInstance); + var type = angular['Global']['typeOf'](lastInstance); type = angular[type.charAt(0).toUpperCase()+type.substring(1)]; var fn = type ? type[[key.substring(1)]] : undefined; if (fn) { diff --git a/src/Widgets.js b/src/Widgets.js index 3a0f2845..4e4facf8 100644 --- a/src/Widgets.js +++ b/src/Widgets.js @@ -5,7 +5,13 @@ WidgetFactory = function(serverUrl, database) { this.nextUploadId = 0; this.serverUrl = serverUrl; this.database = database; - this.createSWF = swfobject.createSWF; + if (window.swfobject) { + this.createSWF = swfobject.createSWF; + } else { + this.createSWF = function(){ + alert("ERROR: swfobject not loaded!"); + }; + } this.onChangeListener = function(){}; }; @@ -145,7 +151,7 @@ FileController.prototype._on_uploadCompleteData = function(data) { FileController.prototype._on_select = function(name, size, type) { this.name = name; this.view.find("a").text(name).attr('href', name); - this.view.find("span").text(angular.filter.bytes(size)); + this.view.find("span").text(angular['filter']['bytes'](size)); this.upload(); }; @@ -167,7 +173,7 @@ FileController.prototype.updateView = function(scope) { this.view.find("a"). attr("href", this.value.url). text(this.value.text); - this.view.find("span").text(angular.filter.bytes(this.value.size)); + this.view.find("span").text(angular['filter']['bytes'](this.value.size)); } this.view.find("input").attr('checked', !!modelValue); }; @@ -677,8 +683,8 @@ RepeaterUpdater.prototype.updateView = function(scope) { }); // shrink children for ( var r = childrenLength; r > iteratorLength; --r) { - var unneeded = this.children.pop(); - unneeded.element.removeNode(); + var unneeded = this.children.pop().element[0]; + unneeded.parentNode.removeChild(unneeded); } // Special case for option in select if (child && child.element[0].nodeName === "OPTION") { diff --git a/src/test/Runner.js b/src/test/Runner.js index 5840282e..c6684951 100644 --- a/src/test/Runner.js +++ b/src/test/Runner.js @@ -110,7 +110,7 @@ test.Scenario.prototype = { }, verb:function(step){ var fn = null; - if (!step) fn = function (){ throw "Step is null!"; } + if (!step) fn = function (){ throw "Step is null!"; }; else if (step.Given) fn = angular.test.GIVEN[step.Given]; else if (step.When) fn = angular.test.WHEN[step.When]; else if (step.Then) fn = angular.test.THEN[step.Then]; diff --git a/src/test/_namespace.js b/src/test/_namespace.js index 78f430f1..e29ae72a 100644 --- a/src/test/_namespace.js +++ b/src/test/_namespace.js @@ -1,5 +1,5 @@ -if (!angular) angular = {}; -if (!angular.test) angular.test = {}; -if (!angular.test.GIVEN) angular.test.GIVEN = {}; -if (!angular.test.WHEN) angular.test.WHEN = {}; -if (!angular.test.THEN) angular.test.THEN = {}; +if (!angular) var angular = window['angular'] = {}; +if (!angular['test']) var angularTest = angular['test'] = {}; +if (!angular['test']['GIVEN']) angularTest['GIVEN'] = {}; +if (!angular['test']['WHEN']) angularTest['WHEN'] = {}; +if (!angular['test']['THEN']) angularTest['THEN'] = {}; -- cgit v1.2.3 From 1a42a3fab99ca02af0476f5a87175c53104aa2e3 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 11 Jan 2010 16:15:12 -0800 Subject: green --- angular-minified.js | 208 +++--- angular.js | 1218 ++++++++++++++++++----------------- example/calculator-manual_init.html | 1 + src/API.js | 77 +-- src/Binder.js | 8 +- src/ControlBar.js | 2 +- src/DataStore.js | 18 +- src/Filters.js | 511 ++++++++------- src/JSON.js | 2 +- src/Loader.js | 491 +++++++------- src/Scope.js | 6 +- src/Server.js | 2 +- src/Validators.js | 152 ++--- src/Widgets.js | 4 +- src/angular.prefix | 3 +- test/LoaderTest.js | 4 +- test/ServerTest.js | 4 +- 17 files changed, 1368 insertions(+), 1343 deletions(-) diff --git a/angular-minified.js b/angular-minified.js index ce5155f2..9b4eec6e 100644 --- a/angular-minified.js +++ b/angular-minified.js @@ -1,109 +1,99 @@ -function m(){return function(){}}function u(n){return function(q){this[n]=q}}function w(n){return function(){return n}} -(function(n,q){var z={z:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",$:function(a){var b="",c,d,e,f,g,h,i=0;for(a=z.Gb(a);i>2;c=(c&3)<<4|d>>4;g=(d&15)<<2|e>>6;h=e&63;if(isNaN(d))g=h=64;else if(isNaN(e))h=64;b=b+this.z.charAt(f)+this.z.charAt(c)+this.z.charAt(g)+this.z.charAt(h)}return b},Gd:function(a){var b="",c,d,e,f,g,h=0;for(a=a.replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4;d=(d&15)<<4|f>>2;e=(f&3)<<6|g;b+=String.fromCharCode(c);if(f!=64)b+=String.fromCharCode(d);if(g!=64)b+=String.fromCharCode(e)}return b=z.Fb(b)},Gb:function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;c127&&d<2048)b+=String.fromCharCode(d>>6|192);else{b+=String.fromCharCode(d>>12|224);b+=String.fromCharCode(d>> -6&63|128)}b+=String.fromCharCode(d&63|128)}}return b},Fb:function(a){for(var b="",c=0,d=c1=c2=0;c191&&d<224){c2=a.charCodeAt(c+1);b+=String.fromCharCode((d&31)<<6|c2&63);c+=2}else{c2=a.charCodeAt(c+1);c3=a.charCodeAt(c+2);b+=String.fromCharCode((d&15)<<12|(c2&63)<<6|c3&63);c+=3}}return b}};if(typeof q.getAttribute=="undefined")q.getAttribute=m();if(typeof Node=="undefined")Node={ELEMENT_NODE:1,ATTRIBUTE_NODE:2,TEXT_NODE:3, -CDATA_SECTION_NODE:4,ENTITY_REFERENCE_NODE:5,ENTITY_NODE:6,PROCESSING_INSTRUCTION_NODE:7,COMMENT_NODE:8,DOCUMENT_NODE:9,DOCUMENT_TYPE_NODE:10,DOCUMENT_FRAGMENT_NODE:11,NOTATION_NODE:12};var x={},j=n.jQuery,A=j.browser.msie;if(!n.ld){angular={};n.angular=angular}if(!angular.h)angular.h={};if(!angular.filter)angular.filter={};if(!n.console)n.console={log:m(),error:m()};if(!angular.alert)angular.alert=function(){console.log(arguments);n.alert.apply(n,arguments)};var y;consoleLog=function(a,b){var c= -q.createElement("div");c.className=a;for(var d=a="",e=0;e/g,">")};escapeAttr=function(a){if(!a||!a.replace)return a;return a.replace(//g,">").replace(/\"/g,""")};bind=function(a,b){if(!a)throw"Missing this";if(!_.isFunction(b))throw"Missing function";return function(){return b.apply(a,arguments)}};shiftBind=function(a,b){return function(){for(var c=[this],d=0;d=0&&a.splice(c,1);return b},find:function(a,b,c){if(b){var d= -angular.Function.compile(b);_.detect(a,function(e){if(d(e)){c=e;return true}});return c}},findById:function(a,b){return angular.gd.find(a,function(c){return c.C==b},null)},filter:function(a,b){var c=[];c.Pb=function(k){for(var l=0;l-1;case "object":for(var o in k)if(o.charAt(0)!== -"$"&&e(k[o],l))return true;return false;case "array":for(o=0;o=0&&a.splice(d,1);a.unshift((c?"-":"+")+b);return a},orderByDirection:function(a,b,c,d){c=c||"ng-ascend";d=d||"ng-descend";a=a[0]||"";var e=true;if(a.charAt(0)=="-"){a=a.substring(1);e=false}else if(a.charAt(0)=="+")a=a.substring(1);return a==b?e?c:d:""},merge:function(a,b,c){var d=a[b];if(!d){d={};a[b]=d}merge(c,d);return a}};angular.String={quote:function(a){return'"'+a.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g, -"\\r").replace(/\t/g,"\\t").replace(/\v/g,"\\v")+'"'},quoteUnicode:function(a){a=angular.String.quote(a);for(var b=[],c=0;c-1;){c1||Binder.N(a[0])!==null};Binder.N=function(a){return(a=a.replace(/\n/gm, -" ").match(/^\{\{(.*)\}\}$/))?a[1]:null};Binder.prototype.Jc=function(a){var b={};a.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(c,d,e){if(d)b[decodeURIComponent(d)]=decodeURIComponent(e)});return b};Binder.prototype.ib=function(a){var b=this;a=a||this.ya.Va();var c=a.indexOf("#");if(!(c<0)){a=this.Jc(a.substring(c+1));j.each(b.anchor,function(d){delete b.anchor[d]});j.each(a,function(d,e){b.anchor[d]=e})}};Binder.prototype.Ic=function(a){console.log("URL change detected",a);this.ib(a);this.c()}; -Binder.prototype.Vc=function(){var a=this.ya.Va(),b=a.indexOf("#");if(b>-1)a=a.substring(0,b);a+="#";b="";for(var c in this.anchor){var d=this.anchor[c];if(typeof d==="undefined"||d===null)delete this.anchor[c];else{a+=b+encodeURIComponent(c);if(d!==true)a+="="+encodeURIComponent(d);b="&"}}this.ya.Rc(a);return a};Binder.prototype.c=function(){(new Date).getTime();var a=j(this.F).scope();a.l("$invalidWidgets",[]);a.c();(new Date).getTime();this.Vc();_.each(this.rb,function(b){b()})};Binder.prototype.Z= -function(a){var b=j(this.F),c=b.find(a);if(b.is(a))c=c.andSelf();return c};Binder.prototype.fc=function(){this.Z("[ng-init]").each(function(){var a=j(this),b=a.scope();try{b.eval(a.attr("ng-init"))}catch(c){alert("EVAL ERROR:\n"+a.attr("ng-init")+"\n"+toJson(c,true))}})};Binder.prototype.O=function(a){this.Z("[ng-entity]").attr("ng-watch",function(){try{var b=j(this);return a.O(b.attr("ng-entity"))+(b.attr("ng-watch")||"")}catch(c){alert(c)}})};Binder.prototype.compile=function(){var a=j(this.F), -b=this;if(this.k.nd){var c=this.Z(":submit").not("[ng-action]");c.attr("ng-action","$save()");c.not(":disabled").not("ng-bind-attr").attr("ng-bind-attr",'{disabled:"{{$invalidWidgets}}"}')}this.jb(this.F)(this.F,a.scope(),"");this.Z("a[ng-action]").live("click",function(){var d=j(this);try{d.scope().eval(d.attr("ng-action"));d.removeAttr("ng-error");d.removeClass("ng-exception")}catch(e){d.addClass("ng-exception");d.attr("ng-error",toJson(e,true))}b.c();return false})};Binder.prototype.Tc=function(a, -b,c){b=b.concat();var d=b.pop(),e=Binder.ga(a.nodeValue);if(e.length>1||Binder.N(e[0])){var f=a.parentNode;if(isLeafNode(f)){f.setAttribute("ng-bind-template",a.nodeValue);c.push({path:b,b:function(l){return new BindUpdater(l,l.getAttribute("ng-bind-template"))}})}else for(var g=0;g2&&a.setAttribute("ng-bind-attr",d)}a.getAttribute||console.log(a);var k=a.getAttribute("ng-repeat");if(k){a.removeAttribute("ng-repeat");var l=this.jb(a);d=q.createComment("ng-repeat: "+k);e=a.parentNode;e.insertBefore(d,a); -e.removeChild(a);var o=function(p,r,s){var v=j(a).clone();v.css("display","");v.attr("ng-repeat-index",""+s);v.data("scope",p);l(v[0],p,r+s+":");return v};c.push({path:b,b:function(p,r,s){return new RepeaterUpdater(j(p),k,o,s)}})}else{a.getAttribute("ng-eval")&&c.push({path:b,b:this.Ac});a.getAttribute("ng-bind")&&c.push({path:b,b:this.hb});a.getAttribute("ng-bind-attr")&&c.push({path:b,b:this.wc});a.getAttribute("ng-hide")&&c.push({path:b,b:this.Bc});a.getAttribute("ng-show")&&c.push({path:b,b:this.Cc}); -a.getAttribute("ng-class")&&c.push({path:b,b:this.xc});a.getAttribute("ng-class-odd")&&c.push({path:b,b:this.zc});a.getAttribute("ng-class-even")&&c.push({path:b,b:this.yc});a.getAttribute("ng-style")&&c.push({path:b,b:this.Dc});a.getAttribute("ng-watch")&&c.push({path:b,b:this.Ec});d=a.nodeName;if(d=="INPUT"||d=="TEXTAREA"||d=="SELECT"||d=="BUTTON"){var t=this;c.push({path:b,b:function(p,r,s){p.name=s+p.name.split(":").pop();return t.ad.Ub(j(p),r)}})}if(d=="OPTION")if(!j("')};FileController.prototype.e=function(a){var b=this.view.find("input").attr("checked")?this.value:null;if(this.d===b)return false;else{a.l(this.nb,b);return true}};FileController.prototype.c=function(a){if((a=a.get(this.nb))&&this.value!==a){this.value=a;this.view.find("a").attr("href",this.value.url).text(this.value.text); -this.view.find("span").text(angular.filter.bytes(this.value.size))}this.view.find("input").attr("checked",!!a)};NullController=u("view");NullController.prototype.e=w(true);NullController.prototype.c=m();NullController.lc=new NullController;ButtonController=u("view");ButtonController.prototype.e=w(true);ButtonController.prototype.c=m();TextController=function(a,b){this.view=a;this.exp=b;this.h=a.getAttribute("ng-validate");this.Nc=typeof a.attributes["ng-required"]!="undefined";this.Ya=null;this.d= -undefined;this.s=a.value;a.getAttribute("ng-widget")==="datepicker"&&j(a).Fd()};TextController.prototype.e=function(a){var b=this.view.value;if(this.d===b)return false;else{a.p(this.exp,b);this.d=b;return true}};TextController.prototype.c=function(a){var b=this.view,c=a.get(this.exp);if(typeof c==="undefined"){c=this.s;a.p(this.exp,c)}c=c?c:"";if(this.d!=c)this.d=b.value=c;var d=false;b.removeAttribute("ng-error");if(this.Nc)d=!(c&&c.length>0);var e=d?"Required Value":null;if(!d&&this.h&&c){e=a.Yc(this.h, -c);d=!!e}if(this.Ya!==e){this.Ya=d;if(e!==null){b.setAttribute("ng-error",e);a.sc(this)}j(b).toggleClass("ng-validation-error",d)}};CheckboxController=function(a,b){this.view=a;this.exp=b;this.d=undefined;this.s=a.checked?a.value:""};CheckboxController.prototype.e=function(a){var b=this.view;b=b.checked?b.value:"";if(this.d===b)return false;else{a.p(this.exp,b);this.d=b;return true}};CheckboxController.prototype.c=function(a){var b=this.view,c=a.eval(this.exp);if(typeof c==="undefined"){c=this.s; -a.p(this.exp,c)}b.checked=b.value==""+c};SelectController=function(a,b){this.view=a;this.exp=b;this.d=undefined;this.s=a.value};SelectController.prototype.e=function(a){if(this.view.selectedIndex<0)a.p(this.exp,null);else{var b=this.view.value;if(this.d===b)return false;else{a.p(this.exp,b);this.d=b;return true}}};SelectController.prototype.c=function(a){var b=this.view,c=a.get(this.exp);if(typeof c==="undefined"){c=this.s;a.p(this.exp,c)}if(c!==this.d){b.value=c?c:"";this.d=c}};MultiSelectController= -function(a,b){this.view=a;this.exp=b;this.d=undefined;this.s=this.selected()};MultiSelectController.prototype.selected=function(){for(var a=[],b=this.view.options,c=0;cd;--b){var o= -this.children.pop().element[0];o.parentNode.removeChild(o)}if(h&&h.element[0].nodeName==="OPTION")if(d=j(h.element[0].parentNode).data("controller")){d.d=undefined;d.c(a)}})};PopUp=u("F");PopUp.Fa="mouseleave mouseout click dblclick keypress keyup";PopUp.prototype.bind=function(){this.F.find(".ng-validation-error,.ng-exception").live("mouseover",PopUp.Hc)};PopUp.Hc=function(){PopUp.wa();var a=j(this);a.bind(PopUp.Fa,PopUp.wa);var b=a.position(),c=q.documentElement,d=(self.innerWidth||c&&c.clientWidth|| -q.body.clientWidth)-b.left;c=a.hasClass("ng-exception")?"EXCEPTION:":"Validation error...";a=a.attr("ng-error");d=d>375?"left":"right";c=j("
"+c+"
"+a+"
");j("body").append(c);if(d==="left")a=b.left+this.offsetWidth+11;else{a=b.left-315;c.find(".ng-arrow-right").css({left:301})}c.css({left:a+"px",top:b.top-3+"px"});return true};PopUp.wa=function(){j("#ng-callout").unbind(PopUp.Fa, -PopUp.wa).remove();return true};Status=function(a){this.cb=a.append(Status.yb).find("#ng-loading");this.ja=0};Status.yb='
loading....
';Status.prototype.Nb=function(){this.ja===0&&this.cb.show();this.ja++};Status.prototype.cc=function(){this.ja--;this.ja===0&&this.cb.hide("fold")}})(window,document); +function p(){return function(){}}function A(n){return function(r){this[n]=r}}function E(n){return function(){return n}} +(function(n,r){function x(){}function M(a,b){var c=r.createElement("div");c.className=a;for(var d=a="",e=0;e/g,">")}function X(a){if(!a||!a.replace)return a;return a.replace(//g,">").replace(/\"/g,""")}function P(a,b){if(!a)throw"Missing this";if(!_.isFunction(b))throw"Missing function";return function(){return b.apply(a,arguments)}}function Y(a,b){return function(){for(var c=[this],d=0;d>2;c=(c&3)<<4|d>>4;g=(d&15)<<2|e>>6;h=e&63;if(isNaN(d))g=h=64;else if(isNaN(e))h=64;b=b+this.u.charAt(f)+this.u.charAt(c)+this.u.charAt(g)+this.u.charAt(h)}return b},sd:function(a){var b="",c,d,e,f,g,h=0;for(a=a.replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4;d=(d&15)<<4|f>>2;e=(f&3)<<6|g;b+=String.fromCharCode(c);if(f!=64)b+=String.fromCharCode(d);if(g!=64)b+=String.fromCharCode(e)}return b=H.xb(b)},yb:function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;c127&&d<2048)b+=String.fromCharCode(d>>6|192);else{b+=String.fromCharCode(d>>12|224);b+=String.fromCharCode(d>>6&63|128)}b+=String.fromCharCode(d& +63|128)}}return b},xb:function(a){for(var b="",c=0,d=c1=c2=0;c191&&d<224){c2=a.charCodeAt(c+1);b+=String.fromCharCode((d&31)<<6|c2&63);c+=2}else{c2=a.charCodeAt(c+1);c3=a.charCodeAt(c+2);b+=String.fromCharCode((d&15)<<12|(c2&63)<<6|c3&63);c+=3}}return b}};if(typeof r.getAttribute=="undefined")r.getAttribute=p();if(typeof Node=="undefined")Node={ELEMENT_NODE:1,ATTRIBUTE_NODE:2,TEXT_NODE:3,CDATA_SECTION_NODE:4,ENTITY_REFERENCE_NODE:5, +ENTITY_NODE:6,PROCESSING_INSTRUCTION_NODE:7,COMMENT_NODE:8,DOCUMENT_NODE:9,DOCUMENT_TYPE_NODE:10,DOCUMENT_FRAGMENT_NODE:11,NOTATION_NODE:12};var F,o=_.each,V=_.extend,I=n.console||{log:x,error:x},i=n.jQuery,G=i.browser.msie;function q(){I.log.apply(this,arguments)}function J(){I.error.apply(this,arguments)}var m=n.angular||(n.angular={}),W=m.validator||(m.validator={}),s=m.filter||(m.filter={}),K=m.callbacks||(m.callbacks={});m.alert||(m.alert=function(){q(arguments);n.alert.apply(n,arguments)}); +T.prototype={load:function(){this.Lb();this.Wa("/stylesheets/jquery-ui/smoothness/jquery-ui-1.7.1.css");this.Wa("/stylesheets/css");q("Server: "+this.i.z);this.Kb();this.Jb();this.Gb()},Kb:function(){q("Loader.configureJQueryPlugins()");i.fn.scope=function(){for(var a=this;a&&a.get(0);){var b=a.data("scope");if(b)return b;a=a.parent()}return null};i.fn.controller=function(){return this.data("controller")||NullController.cc}},Kc:function(){return""+(new Date).getTime()},Jb:function(){var a=this.i; +if(!a.G){var b=a.z.match(/https?:\/\/([\w]*)/);a.G=b?b[1]:"$MEMORY"}},Gb:function(){function a(){g.Ma(function(l){!l&&c.find("[ng-auth=eager]").length&&g.ba()})}q("Loader.bindHtml()");var b=new U(this.location),c=this.document,d=new WidgetFactory(this.i.z,this.i.G),e=new Binder(c[0],d,b,this.i);d.wc=Y(e,e.e);d=new ControlBar(c.find("body"),this.i.z);var f=this.i.G=="$MEMORY"?new FrameServer(this.window):new Server(this.i.z,i.getScript);f=new VisualServer(f,new Status(i(c.body)),function(){e.c()}); +var g=new Users(f,d),h="/data/"+this.i.G,j=new DataStore(function(l,y){f.P("POST",h,l,y)},g,e.anchor);e.lb.push(function(){j.Oa()});var k=new Scope({$anchor:e.anchor,$binder:e,$config:this.i,$console:n.console,$datastore:j,$save:function(l){j.Ec(k.s,l,e.anchor)},$window:n,$uid:this.Kc,$users:g},"ROOT");c.data("scope",k);q("$binder.entity()");e.M(k);q("$binder.compile()");e.compile();q("ControlBar.bind()");d.bind();q("$users.fetchCurrentUser()");a();q("PopUp.bind()");(new PopUp(c)).bind();q("$binder.parseAnchor()"); +e.db();q("$binder.executeInit()");e.Xb();q("$binder.updateView()");e.c();b.Ua=P(e,e.yc,b);b.zd=function(){alert("update")};b.watch();c.find("body").show();q("ready()")},Lb:function(){var a=n.location.href+"#";a=a.split("#")[1];var b={Qb:null};a=a.split("&");for(var c=0;c-1;){c1||Binder.L(a[0])!==null};Binder.L=function(a){return(a=a.replace(/\n/gm," ").match(/^\{\{(.*)\}\}$/))?a[1]:null};Binder.prototype.zc=function(a){var b={};a.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(c,d,e){if(d)b[decodeURIComponent(d)]=decodeURIComponent(e)});return b};Binder.prototype.db=function(a){var b=this;a=a||this.va.Qa();var c=a.indexOf("#");if(!(c<0)){a=this.zc(a.substring(c+1));o(b.anchor,function(d,e){delete b.anchor[e]}); +o(a,function(d,e){b.anchor[e]=d})}};Binder.prototype.yc=function(a){q("URL change detected",a);this.db(a);this.c()};Binder.prototype.Lc=function(){var a=this.va.Qa(),b=a.indexOf("#");if(b>-1)a=a.substring(0,b);a+="#";b="";for(var c in this.anchor){var d=this.anchor[c];if(typeof d==="undefined"||d===null)delete this.anchor[c];else{a+=b+encodeURIComponent(c);if(d!==true)a+="="+encodeURIComponent(d);b="&"}}this.va.Hc(a);return a};Binder.prototype.c=function(){(new Date).getTime();var a=i(this.B).scope(); +a.j("$invalidWidgets",[]);a.c();(new Date).getTime();this.Lc();_.each(this.lb,function(b){b()})};Binder.prototype.W=function(a){var b=i(this.B),c=b.find(a);if(b.is(a))c=c.andSelf();return c};Binder.prototype.Xb=function(){this.W("[ng-init]").each(function(){var a=i(this),b=a.scope();try{b.eval(a.attr("ng-init"))}catch(c){alert("EVAL ERROR:\n"+a.attr("ng-init")+"\n"+toJson(c,true))}})};Binder.prototype.M=function(a){this.W("[ng-entity]").attr("ng-watch",function(){try{var b=i(this);return a.M(b.attr("ng-entity"))+ +(b.attr("ng-watch")||"")}catch(c){alert(c)}})};Binder.prototype.compile=function(){var a=i(this.B),b=this;if(this.i.$c){var c=this.W(":submit").not("[ng-action]");c.attr("ng-action","$save()");c.not(":disabled").not("ng-bind-attr").attr("ng-bind-attr",'{disabled:"{{$invalidWidgets}}"}')}this.eb(this.B)(this.B,a.scope(),"");this.W("a[ng-action]").live("click",function(){var d=i(this);try{d.scope().eval(d.attr("ng-action"));d.removeAttr("ng-error");d.removeClass("ng-exception")}catch(e){d.addClass("ng-exception"); +d.attr("ng-error",toJson(e,true))}b.c();return false})};Binder.prototype.Jc=function(a,b,c){b=b.concat();var d=b.pop(),e=Binder.da(a.nodeValue);if(e.length>1||Binder.L(e[0])){var f=a.parentNode;if(N(f)){f.setAttribute("ng-bind-template",a.nodeValue);c.push({path:b,b:function(l){return new BindUpdater(l,l.getAttribute("ng-bind-template"))}})}else for(var g=0;g2&&a.setAttribute("ng-bind-attr",d)}a.getAttribute||q(a);var k=a.getAttribute("ng-repeat");if(k){a.removeAttribute("ng-repeat");var l=this.eb(a);d=r.createComment("ng-repeat: "+k);e=a.parentNode; +e.insertBefore(d,a);e.removeChild(a);var y=function(t,u,w){var B=i(a).clone();B.css("display","");B.attr("ng-repeat-index",""+w);B.data("scope",t);l(B[0],t,u+w+":");return B};c.push({path:b,b:function(t,u,w){return new RepeaterUpdater(i(t),k,y,w)}})}else{a.getAttribute("ng-eval")&&c.push({path:b,b:this.qc});a.getAttribute("ng-bind")&&c.push({path:b,b:this.cb});a.getAttribute("ng-bind-attr")&&c.push({path:b,b:this.mc});a.getAttribute("ng-hide")&&c.push({path:b,b:this.rc});a.getAttribute("ng-show")&& +c.push({path:b,b:this.sc});a.getAttribute("ng-class")&&c.push({path:b,b:this.nc});a.getAttribute("ng-class-odd")&&c.push({path:b,b:this.pc});a.getAttribute("ng-class-even")&&c.push({path:b,b:this.oc});a.getAttribute("ng-style")&&c.push({path:b,b:this.tc});a.getAttribute("ng-watch")&&c.push({path:b,b:this.uc});d=a.nodeName;if(d=="INPUT"||d=="TEXTAREA"||d=="SELECT"||d=="BUTTON"){var z=this;c.push({path:b,b:function(t,u,w){t.name=w+t.name.split(":").pop();return z.Rc.Mb(i(t),u)}})}if(d=="OPTION")if(!i("')};FileController.prototype.e=function(a){var b=this.view.find("input").attr("checked")?this.value:null;if(this.d===b)return false;else{a.j(this.ib,b);return true}};FileController.prototype.c= +function(a){if((a=a.get(this.ib))&&this.value!==a){this.value=a;this.view.find("a").attr("href",this.value.url).text(this.value.text);this.view.find("span").text(m.filter.bytes(this.value.size))}this.view.find("input").attr("checked",!!a)};NullController=A("view");NullController.prototype.e=E(true);NullController.prototype.c=p();NullController.cc=new NullController;ButtonController=A("view");ButtonController.prototype.e=E(true);ButtonController.prototype.c=p();TextController=function(a,b){this.view= +a;this.exp=b;this.Q=a.getAttribute("ng-validate");this.Dc=typeof a.attributes["ng-required"]!="undefined";this.Ta=null;this.d=undefined;this.p=a.value;a.getAttribute("ng-widget")==="datepicker"&&i(a).rd()};TextController.prototype.e=function(a){var b=this.view.value;if(this.d===b)return false;else{a.m(this.exp,b);this.d=b;return true}};TextController.prototype.c=function(a){var b=this.view,c=a.get(this.exp);if(typeof c==="undefined"){c=this.p;a.m(this.exp,c)}c=c?c:"";if(this.d!=c)this.d=b.value=c; +var d=false;b.removeAttribute("ng-error");if(this.Dc)d=!(c&&c.length>0);var e=d?"Required Value":null;if(!d&&this.Q&&c){e=a.Oc(this.Q,c);d=!!e}if(this.Ta!==e){this.Ta=d;if(e!==null){b.setAttribute("ng-error",e);a.ic(this)}i(b).toggleClass("ng-validation-error",d)}};CheckboxController=function(a,b){this.view=a;this.exp=b;this.d=undefined;this.p=a.checked?a.value:""};CheckboxController.prototype.e=function(a){var b=this.view;b=b.checked?b.value:"";if(this.d===b)return false;else{a.m(this.exp,b);this.d= +b;return true}};CheckboxController.prototype.c=function(a){var b=this.view,c=a.eval(this.exp);if(typeof c==="undefined"){c=this.p;a.m(this.exp,c)}b.checked=b.value==""+c};SelectController=function(a,b){this.view=a;this.exp=b;this.d=undefined;this.p=a.value};SelectController.prototype.e=function(a){if(this.view.selectedIndex<0)a.m(this.exp,null);else{var b=this.view.value;if(this.d===b)return false;else{a.m(this.exp,b);this.d=b;return true}}};SelectController.prototype.c=function(a){var b=this.view, +c=a.get(this.exp);if(typeof c==="undefined"){c=this.p;a.m(this.exp,c)}if(c!==this.d){b.value=c?c:"";this.d=c}};MultiSelectController=function(a,b){this.view=a;this.exp=b;this.d=undefined;this.p=this.selected()};MultiSelectController.prototype.selected=function(){for(var a=[],b=this.view.options,c=0;cd;--b){var y=this.children.pop().element[0];y.parentNode.removeChild(y)}if(h&&h.element[0].nodeName==="OPTION")if(d=i(h.element[0].parentNode).data("controller")){d.d=undefined;d.c(a)}})};PopUp=A("B");PopUp.Ca="mouseleave mouseout click dblclick keypress keyup";PopUp.prototype.bind=function(){this.B.find(".ng-validation-error,.ng-exception").live("mouseover", +PopUp.xc)};PopUp.xc=function(){PopUp.sa();var a=i(this);a.bind(PopUp.Ca,PopUp.sa);var b=a.position(),c=r.documentElement,d=(self.innerWidth||c&&c.clientWidth||r.body.clientWidth)-b.left;c=a.hasClass("ng-exception")?"EXCEPTION:":"Validation error...";a=a.attr("ng-error");d=d>375?"left":"right";c=i("
"+c+"
"+a+"
");i("body").append(c);if(d==="left")a=b.left+this.offsetWidth+ +11;else{a=b.left-315;c.find(".ng-arrow-right").css({left:301})}c.css({left:a+"px",top:b.top-3+"px"});return true};PopUp.sa=function(){i("#ng-callout").unbind(PopUp.Ca,PopUp.sa).remove();return true};Status=function(a){this.Ya=a.append(Status.sb).find("#ng-loading");this.ga=0};Status.sb='
loading....
';Status.prototype.Fb=function(){this.ga===0&&this.Ya.show();this.ga++};Status.prototype.Ub=function(){this.ga--;this.ga===0&&this.Ya.hide("fold")}})(window, +document); diff --git a/angular.js b/angular.js index c113d56b..bea8200d 100644 --- a/angular.js +++ b/angular.js @@ -1,5 +1,5 @@ - -(function(window, document){/** +(function(window, document){ +/** * * Base64 encode / decode * http://www.webtoolkit.info/ @@ -145,8 +145,7 @@ var Base64 = { // IE compatibility if (typeof document.getAttribute == 'undefined') - document.getAttribute = function() { - }; + document.getAttribute = function() {}; if (typeof Node == 'undefined') { Node = { ELEMENT_NODE : 1, @@ -164,25 +163,25 @@ if (typeof Node == 'undefined') { }; } -var callbacks = {}; -var jQuery = window['jQuery']; -var msie = jQuery['browser']['msie']; - -if (!window.angular){ angular = {}; window['angular'] = angular; } -if (!angular.validator) angular.validator = {}; -if (!angular.filter) angular.filter = {}; -if (!window.console) - window.console = { - log:function() {}, - error:function() {} - }; -if (!angular.alert) { - angular.alert = function(){console.log(arguments); window.alert.apply(window, arguments); }; -} - -var consoleNode; +function noop() {}; + +var consoleNode, + foreach = _.each, + extend = _.extend, + console = window['console'] || ({'log':noop, 'error':noop }), + jQuery = window['jQuery'], + msie = jQuery['browser']['msie'], + log = function(){console.log.apply(this, arguments);}, + error = function(){console.error.apply(this, arguments);}, + angular = window['angular'] || (window['angular'] = {}), + angularValidator = angular['validator'] || (angular['validator'] = {}), + angularFilter = angular['filter'] || (angular['filter'] = {}), + angularCallbacks = angular['callbacks'] || (angular['callbacks'] = {}), + angularAlert = angular['alert'] || (angular['alert'] = function(){ + log(arguments); window.alert.apply(window, arguments); + }); -consoleLog = function(level, objs) { +function consoleLog(level, objs) { var log = document.createElement("div"); log.className = level; var msg = ""; @@ -194,17 +193,17 @@ consoleLog = function(level, objs) { } log.appendChild(document.createTextNode(msg)); consoleNode.appendChild(log); -}; +} -isNode = function(inp) { +function isNode(inp) { return inp && inp.tagName && inp.nodeName && inp.ownerDocument && inp.removeAttribute; -}; +} -isLeafNode = function(node) { +function isLeafNode (node) { switch (node.nodeName) { case "OPTION": case "PRE": @@ -215,9 +214,7 @@ isLeafNode = function(node) { } }; -noop = function() { -}; -setHtml = function(node, html) { +function setHtml(node, html) { if (isLeafNode(node)) { if (msie) { node.innerText = html; @@ -227,9 +224,9 @@ setHtml = function(node, html) { } else { node.innerHTML = html; } -}; +} -escapeHtml = function(html) { +function escapeHtml(html) { if (!html || !html.replace) return html; return html. @@ -238,14 +235,14 @@ escapeHtml = function(html) { replace(/>/g, '>'); }; -escapeAttr = function(html) { +function escapeAttr(html) { if (!html || !html.replace) return html; return html.replace(//g, '>').replace(/\"/g, '"'); }; -bind = function(_this, _function) { +function bind(_this, _function) { if (!_this) throw "Missing this"; if (!_.isFunction(_function)) @@ -255,7 +252,7 @@ bind = function(_this, _function) { }; }; -shiftBind = function(_this, _function) { +function shiftBind(_this, _function) { return function() { var args = [ this ]; for ( var i = 0; i < arguments.length; i++) { @@ -265,7 +262,7 @@ shiftBind = function(_this, _function) { }; }; -outerHTML = function(node) { +function outerHTML(node) { var temp = document.createElement('div'); temp.appendChild(node); var outerHTML = temp.innerHTML; @@ -273,18 +270,18 @@ outerHTML = function(node) { return outerHTML; }; -trim = function(str) { +function trim(str) { return str.replace(/^ */, '').replace(/ *$/, ''); }; -toBoolean = function(value) { +function toBoolean(value) { var v = ("" + value).toLowerCase(); if (v == 'f' || v == '0' || v == 'false' || v == 'no') value = false; return !!value; }; -merge = function(src, dst) { +function merge(src, dst) { for ( var key in src) { var value = dst[key]; var type = typeof value; @@ -301,176 +298,178 @@ merge = function(src, dst) { // Loader // //////////////////////////// -Loader = function(document, head, config) { +function Loader(document, head, config) { this.document = jQuery(document); this.head = jQuery(head); this.config = config; this.location = window.location; }; -Loader.prototype.load = function() { - this.configureLogging(); - this.loadCss('/stylesheets/jquery-ui/smoothness/jquery-ui-1.7.1.css'); - this.loadCss('/stylesheets/css'); - console.log("Server: " + this.config.server); - this.configureJQueryPlugins(); - this.computeConfiguration(); - this.bindHtml(); -}; - -Loader.prototype.configureJQueryPlugins = function() { - console.log('Loader.configureJQueryPlugins()'); - jQuery['fn']['scope'] = function() { - var element = this; - while (element && element.get(0)) { - var scope = element.data("scope"); - if (scope) - return scope; - element = element.parent(); - } - return null; - }; - jQuery['fn']['controller'] = function() { - return this.data('controller') || NullController.instance; - }; -}; - -Loader.prototype.uid = function() { - return "" + new Date().getTime(); -}; - -Loader.prototype.computeConfiguration = function() { - var config = this.config; - if (!config.database) { - var match = config.server.match(/https?:\/\/([\w]*)/); - config.database = match ? match[1] : "$MEMORY"; - } -}; - -Loader.prototype.bindHtml = function() { - console.log('Loader.bindHtml()'); - var watcher = new UrlWatcher(this.location); - var document = this.document; - var widgetFactory = new WidgetFactory(this.config.server, this.config.database); - var binder = new Binder(document[0], widgetFactory, watcher, this.config); - widgetFactory.onChangeListener = shiftBind(binder, binder.updateModel); - var controlBar = new ControlBar(document.find('body'), this.config.server); - var onUpdate = function(){binder.updateView();}; - var server = this.config.database=="$MEMORY" ? - new FrameServer(this.window) : - new Server(this.config.server, jQuery.getScript); - server = new VisualServer(server, new Status(jQuery(document.body)), onUpdate); - var users = new Users(server, controlBar); - var databasePath = '/data/' + this.config.database; - var post = function(request, callback){ - server.request("POST", databasePath, request, callback); - }; - var datastore = new DataStore(post, users, binder.anchor); - binder.updateListeners.push(function(){datastore.flush();}); - var scope = new Scope( { - '$anchor' : binder.anchor, - '$binder' : binder, - '$config' : this.config, - '$console' : window.console, - '$datastore' : datastore, - '$save' : function(callback) { - datastore.saveScope(scope.state, callback, binder.anchor); - }, - '$window' : window, - '$uid' : this.uid, - '$users' : users - }, "ROOT"); - - document.data('scope', scope); - console.log('$binder.entity()'); - binder.entity(scope); - - console.log('$binder.compile()'); - binder.compile(); - - console.log('ControlBar.bind()'); - controlBar.bind(); - - console.log('$users.fetchCurrentUser()'); - function fetchCurrentUser() { - users.fetchCurrentUser(function(u) { - if (!u && document.find("[ng-auth=eager]").length) { - users.login(); - } - }); - } - fetchCurrentUser(); - - console.log('PopUp.bind()'); - new PopUp(document).bind(); - - console.log('$binder.parseAnchor()'); - binder.parseAnchor(); - - console.log('$binder.executeInit()'); - binder.executeInit(); - - console.log('$binder.updateView()'); - binder.updateView(); - - watcher.listener = bind(binder, binder.onUrlChange, watcher); - watcher.onUpdate = function(){alert("update");}; - watcher.watch(); - document.find("body").show(); - console.log('ready()'); -}; - -Loader.prototype.visualPost = function(delegate) { - var status = new Status(jQuery(document.body)); - return function(request, delegateCallback) { - status.beginRequest(request); - var callback = function() { - status.endRequest(); - try { - delegateCallback.apply(this, arguments); - } catch (e) { - alert(toJson(e)); +Loader.prototype = { + load: function() { + this.configureLogging(); + this.loadCss('/stylesheets/jquery-ui/smoothness/jquery-ui-1.7.1.css'); + this.loadCss('/stylesheets/css'); + log("Server: " + this.config.server); + this.configureJQueryPlugins(); + this.computeConfiguration(); + this.bindHtml(); + }, + + configureJQueryPlugins: function() { + log('Loader.configureJQueryPlugins()'); + jQuery['fn']['scope'] = function() { + var element = this; + while (element && element.get(0)) { + var scope = element.data("scope"); + if (scope) + return scope; + element = element.parent(); } + return null; }; - delegate(request, callback); - }; -}; - -Loader.prototype.configureLogging = function() { - var url = window.location.href + '#'; - url = url.split('#')[1]; - var config = { - debug : null - }; - var configs = url.split('&'); - for ( var i = 0; i < configs.length; i++) { - var part = (configs[i] + '=').split('='); - config[part[0]] = part[1]; - } - if (config.debug == 'console') { - consoleNode = document.createElement("div"); - consoleNode.id = 'ng-console'; - document.getElementsByTagName('body')[0].appendChild(consoleNode); - console.log = function() { - consoleLog('ng-console-info', arguments); + jQuery['fn']['controller'] = function() { + return this.data('controller') || NullController.instance; + }; + }, + + uid: function() { + return "" + new Date().getTime(); + }, + + computeConfiguration: function() { + var config = this.config; + if (!config.database) { + var match = config.server.match(/https?:\/\/([\w]*)/); + config.database = match ? match[1] : "$MEMORY"; + } + }, + + bindHtml: function() { + log('Loader.bindHtml()'); + var watcher = new UrlWatcher(this.location); + var document = this.document; + var widgetFactory = new WidgetFactory(this.config.server, this.config.database); + var binder = new Binder(document[0], widgetFactory, watcher, this.config); + widgetFactory.onChangeListener = shiftBind(binder, binder.updateModel); + var controlBar = new ControlBar(document.find('body'), this.config.server); + var onUpdate = function(){binder.updateView();}; + var server = this.config.database=="$MEMORY" ? + new FrameServer(this.window) : + new Server(this.config.server, jQuery.getScript); + server = new VisualServer(server, new Status(jQuery(document.body)), onUpdate); + var users = new Users(server, controlBar); + var databasePath = '/data/' + this.config.database; + var post = function(request, callback){ + server.request("POST", databasePath, request, callback); + }; + var datastore = new DataStore(post, users, binder.anchor); + binder.updateListeners.push(function(){datastore.flush();}); + var scope = new Scope( { + '$anchor' : binder.anchor, + '$binder' : binder, + '$config' : this.config, + '$console' : window.console, + '$datastore' : datastore, + '$save' : function(callback) { + datastore.saveScope(scope.state, callback, binder.anchor); + }, + '$window' : window, + '$uid' : this.uid, + '$users' : users + }, "ROOT"); + + document.data('scope', scope); + log('$binder.entity()'); + binder.entity(scope); + + log('$binder.compile()'); + binder.compile(); + + log('ControlBar.bind()'); + controlBar.bind(); + + log('$users.fetchCurrentUser()'); + function fetchCurrentUser() { + users.fetchCurrentUser(function(u) { + if (!u && document.find("[ng-auth=eager]").length) { + users.login(); + } + }); + } + fetchCurrentUser(); + + log('PopUp.bind()'); + new PopUp(document).bind(); + + log('$binder.parseAnchor()'); + binder.parseAnchor(); + + log('$binder.executeInit()'); + binder.executeInit(); + + log('$binder.updateView()'); + binder.updateView(); + + watcher.listener = bind(binder, binder.onUrlChange, watcher); + watcher.onUpdate = function(){alert("update");}; + watcher.watch(); + document.find("body").show(); + log('ready()'); + }, + + visualPost: function(delegate) { + var status = new Status(jQuery(document.body)); + return function(request, delegateCallback) { + status.beginRequest(request); + var callback = function() { + status.endRequest(); + try { + delegateCallback.apply(this, arguments); + } catch (e) { + alert(toJson(e)); + } + }; + delegate(request, callback); }; - console.error = function() { - consoleLog('ng-console-error', arguments); + }, + + configureLogging: function() { + var url = window.location.href + '#'; + url = url.split('#')[1]; + var config = { + debug : null }; + var configs = url.split('&'); + for ( var i = 0; i < configs.length; i++) { + var part = (configs[i] + '=').split('='); + config[part[0]] = part[1]; + } + if (config.debug == 'console') { + consoleNode = document.createElement("div"); + consoleNode.id = 'ng-console'; + document.getElementsByTagName('body')[0].appendChild(consoleNode); + log = function() { + consoleLog('ng-console-info', arguments); + }; + console.error = function() { + consoleLog('ng-console-error', arguments); + }; + } + }, + + loadCss: function(css) { + var cssTag = document.createElement('link'); + cssTag.rel = "stylesheet"; + cssTag.type = "text/css"; + if (!css.match(/^http:/)) + css = this.config.server + css; + cssTag.href = css; + this.head[0].appendChild(cssTag); } }; -Loader.prototype.loadCss = function(css) { - var cssTag = document.createElement('link'); - cssTag.rel = "stylesheet"; - cssTag.type = "text/css"; - if (!css.match(/^http:/)) - css = this.config.server + css; - cssTag.href = css; - this.head[0].appendChild(cssTag); -}; - -UrlWatcher = function(location) { +function UrlWatcher(location) { this.location = location; this.delay = 25; this.setTimeout = function(fn, delay) { @@ -482,47 +481,49 @@ UrlWatcher = function(location) { this.expectedUrl = location.href; }; -UrlWatcher.prototype.watch = function() { - var self = this; - var pull = function() { - if (self.expectedUrl !== self.location.href) { - var notify = self.location.hash.match(/^#\$iframe_notify=(.*)$/); - if (notify) { - if (!self.expectedUrl.match(/#/)) { - self.expectedUrl += "#"; - } - self.location.href = self.expectedUrl; - var id = '_iframe_notify_' + notify[1]; - var notifyFn = callbacks[id]; - delete callbacks[id]; - try { - (notifyFn||noop)(); - } catch (e) { - alert(e); +UrlWatcher.prototype = { + watch: function() { + var self = this; + var pull = function() { + if (self.expectedUrl !== self.location.href) { + var notify = self.location.hash.match(/^#\$iframe_notify=(.*)$/); + if (notify) { + if (!self.expectedUrl.match(/#/)) { + self.expectedUrl += "#"; + } + self.location.href = self.expectedUrl; + var id = '_iframe_notify_' + notify[1]; + var notifyFn = angularCallbacks[id]; + delete angularCallbacks[id]; + try { + (notifyFn||noop)(); + } catch (e) { + alert(e); + } + } else { + self.listener(self.location.href); + self.expectedUrl = self.location.href; } - } else { - self.listener(self.location.href); - self.expectedUrl = self.location.href; } - } - self.setTimeout(pull, self.delay); - }; - pull(); -}; - -UrlWatcher.prototype.setUrl = function(url) { - var existingURL = window.location.href; - if (!existingURL.match(/#/)) - existingURL += '#'; - if (existingURL != url) - window.location.href = url; - this.existingURL = url; -}; - -UrlWatcher.prototype.getUrl = function() { - return window.location.href; + self.setTimeout(pull, self.delay); + }; + pull(); + }, + + setUrl: function(url) { + var existingURL = window.location.href; + if (!existingURL.match(/#/)) + existingURL += '#'; + if (existingURL != url) + window.location.href = url; + this.existingURL = url; + }, + + getUrl: function() { + return window.location.href; + } }; - + angular['compile'] = function(root, config) { config = config || {}; var defaults = { @@ -539,14 +540,11 @@ angular['compile'] = function(root, config) { 'set':function(){return scope.set.apply(scope, arguments);}, 'get':function(){return scope.get.apply(scope, arguments);} }; -}; - -angular['Global'] = { +};var angularGlobal = { 'typeOf':function(obj){ + if (obj === null) return "null"; var type = typeof obj; - switch(type) { - case "object": - if (obj === null) return "null"; + if (type == "object") { if (obj instanceof Array) return "array"; if (obj instanceof Date) return "date"; if (obj.nodeType == 1) return "element"; @@ -555,9 +553,9 @@ angular['Global'] = { } }; -angular['Collection'] = {}; -angular['Object'] = {}; -angular['Array'] = { +var angularCollection = {}; +var angularObject = {}; +var angularArray = { 'includeIf':function(array, value, condition) { var index = _.indexOf(array, value); if (condition) { @@ -720,7 +718,7 @@ angular['Array'] = { var comparator = function(o1, o2){ for ( var i = 0; i < expression.length; i++) { var comp = expression[i](o1, o2); - if (comp != 0) return comp; + if (comp !== 0) return comp; } return 0; }; @@ -740,7 +738,7 @@ angular['Array'] = { ascending = $.charAt(0) == '+'; index = i; return true; - }; + } }); if (index >= 0) { predicate.splice(index, 1); @@ -771,7 +769,8 @@ angular['Array'] = { return array; } }; -angular['String'] = { + +var angularString = { 'quote':function(string) { return '"' + string.replace(/\\/g, '\\\\'). replace(/"/g, '\\"'). @@ -808,7 +807,8 @@ angular['String'] = { return string; } }; -angular['Date'] = { + +var angularDate = { 'toString':function(date){ function pad(n) { return n < 10 ? "0" + n : n; } return (date.getUTCFullYear()) + '-' + @@ -819,7 +819,8 @@ angular['Date'] = { pad(date.getUTCSeconds()) + 'Z'; } }; -angular['Function'] = { + +var angularFunction = { 'compile':function(expression) { if (_.isFunction(expression)){ return expression; @@ -836,27 +837,29 @@ angular['Function'] = { }; (function(){ - function extend(dst, src, names){ - _.extend(dst, src); - _.each((names||[]), function(name){ - dst[name] = _[name]; + function define(dst, chain, names){ + foreach(chain, function(parent){ + extend(angular[dst], parent); }); - }; - extend(angular['Global'], {}, + foreach(names, function(name){ + angular[dst][name] = _[name]; + }); + } + define('Global', [angularGlobal], ['extend', 'clone','isEqual', 'isElement', 'isArray', 'isFunction', 'isUndefined']); - extend(angular['Collection'], angular['Global'], + define('Collection', [angularGlobal, angularCollection], ['each', 'map', 'reduce', 'reduceRight', 'detect', 'select', 'reject', 'all', 'any', 'include', 'invoke', 'pluck', 'max', 'min', 'sortBy', 'sortedIndex', 'toArray', 'size']); - extend(angular['Array'], angular['Collection'], + define('Array', [angularGlobal, angularCollection], ['first', 'last', 'compact', 'flatten', 'without', 'uniq', 'intersect', 'zip', 'indexOf', 'lastIndexOf']); - extend(angular['Object'], angular['Collection'], + define('Object', [angularGlobal, angularCollection], ['keys', 'values']); - extend(angular['String'], angular['Global']); - extend(angular['Function'], angular['Global'], + define('String', [angularGlobal]); + define('Function', [angularGlobal], ['bind', 'bindAll', 'delay', 'defer', 'wrap', 'compose']); })();// Copyright (C) 2009 BRAT Tech LLC Binder = function(doc, widgetFactory, urlWatcher, config) { @@ -917,16 +920,16 @@ Binder.prototype.parseAnchor = function(url) { var anchor = url.substring(anchorIndex + 1); var anchorQuery = this.parseQueryString(anchor); - jQuery.each(self.anchor, function(key, newValue) { + foreach(self.anchor, function(newValue, key) { delete self.anchor[key]; }); - jQuery.each(anchorQuery, function(key, newValue) { + foreach(anchorQuery, function(newValue, key) { self.anchor[key] = newValue; }); }; Binder.prototype.onUrlChange = function (url) { - console.log("URL change detected", url); + log("URL change detected", url); this.parseAnchor(url); this.updateView(); }; @@ -1112,7 +1115,7 @@ Binder.prototype.precompileNode = function(node, path, factories) { } } - if (!node.getAttribute) console.log(node); + if (!node.getAttribute) log(node); var repeaterExpression = node.getAttribute('ng-repeat'); if (repeaterExpression) { node.removeAttribute('ng-repeat'); @@ -1262,7 +1265,7 @@ ControlBar.prototype.doTemplate = function (path) { callbacks["_iframe_notify_" + id] = function() { loginView.dialog("destroy"); loginView.remove(); - jQuery.each(self.callbacks, function(i, callback){ + foreach(self.callbacks, function(callback){ callback(); }); self.callbacks = []; @@ -1322,7 +1325,7 @@ DataStore.prototype.loadMany = function(entity, ids, callback) { var self=this; var list = []; var callbackCount = 0; - jQuery.each(ids, function(i, id){ + foreach(ids, function(id){ list.push(self.load(entity(), id, function(){ callbackCount++; if (callbackCount == ids.length) { @@ -1415,9 +1418,9 @@ DataStore.prototype.flush = function() { var self = this; var bulkRequest = this.bulkRequest; this.bulkRequest = []; - console.log('REQUEST:', bulkRequest); + log('REQUEST:', bulkRequest); function callback(code, bulkResponse){ - console.log('RESPONSE[' + code + ']: ', bulkResponse); + log('RESPONSE[' + code + ']: ', bulkResponse); if(bulkResponse.$status_code == 401) { self.users.login(function(){ self.post(bulkRequest, callback); @@ -1498,7 +1501,7 @@ DataStore.prototype.documentCountsByUser = function(){ var counts = {}; var self = this; self.post([["GET", "$users"]], function(code, response){ - jQuery.each(response[0], function(key, value){ + foreach(response[0], function(value, key){ counts[key] = value; }); }); @@ -1509,7 +1512,7 @@ DataStore.prototype.userDocumentIdsByEntity = function(user){ var ids = {}; var self = this; self.post([["GET", "$users/" + user]], function(code, response){ - jQuery.each(response[0], function(key, value){ + foreach(response[0], function(value, key){ ids[key] = value; }); }); @@ -1613,14 +1616,14 @@ DataStore.prototype.join = function(join){ }; // Copyright (C) 2009 BRAT Tech LLC -angular.filter.Meta = function(obj){ +angularFilter.Meta = function(obj){ if (obj) { for ( var key in obj) { this[key] = obj[key]; } } }; -angular.filter.Meta.get = function(obj, attr){ +angularFilter.Meta.get = function(obj, attr){ attr = attr || 'text'; switch(typeof obj) { case "string": @@ -1635,272 +1638,283 @@ angular.filter.Meta.get = function(obj, attr){ } }; -angular.filter['currency'] = function(amount){ - jQuery(this.element).toggleClass('ng-format-negative', amount < 0); - return '$' + angular.filter.number.apply(this, [amount, 2]); -}; - -angular.filter.number = function(amount, fractionSize){ - if (isNaN(amount) || !isFinite(amount)) { - return ''; - } - fractionSize = typeof fractionSize == 'undefined' ? 2 : fractionSize; - var isNegative = amount < 0; - amount = Math.abs(amount); - var pow = Math.pow(10, fractionSize); - var text = "" + Math.round(amount * pow); - var whole = text.substring(0, text.length - fractionSize); - whole = whole || '0'; - var frc = text.substring(text.length - fractionSize); - text = isNegative ? '-' : ''; - for (var i = 0; i < whole.length; i++) { - if ((whole.length - i)%3 === 0 && i !== 0) { - text += ','; - } - text += whole.charAt(i); - } - if (fractionSize > 0) { - for (var j = frc.length; j < fractionSize; j++) { - frc += '0'; - } - text += '.' + frc.substring(0, fractionSize); - } - return text; -}; - -angular.filter.date = function(amount) { -}; - -angular.filter.json = function(object) { - jQuery(this.element).addClass("ng-monospace"); - return toJson(object, true); -}; +var angularFilterGoogleChartApi; -angular.filter.trackPackage = function(trackingNo, noMatch) { - trackingNo = trim(trackingNo); - var tNo = trackingNo.replace(/ /g, ''); - var MATCHERS = angular.filter.trackPackage.MATCHERS; - for ( var i = 0; i < MATCHERS.length; i++) { - var carrier = MATCHERS[i]; - for ( var j = 0; j < carrier.regexp.length; j++) { - var regexp = carrier.regexp[j]; - if (regexp.test(tNo)) { - var text = carrier.name + ": " + trackingNo; - var url = carrier.url + trackingNo; - return new angular.filter.Meta({ - text:text, - url:url, - html: '' + text + '', - trackingNo:trackingNo}); +foreach({ + 'currency': function(amount){ + jQuery(this.element).toggleClass('ng-format-negative', amount < 0); + return '$' + angularFilter['number'].apply(this, [amount, 2]); + }, + + 'number': function(amount, fractionSize){ + if (isNaN(amount) || !isFinite(amount)) { + return ''; + } + fractionSize = typeof fractionSize == 'undefined' ? 2 : fractionSize; + var isNegative = amount < 0; + amount = Math.abs(amount); + var pow = Math.pow(10, fractionSize); + var text = "" + Math.round(amount * pow); + var whole = text.substring(0, text.length - fractionSize); + whole = whole || '0'; + var frc = text.substring(text.length - fractionSize); + text = isNegative ? '-' : ''; + for (var i = 0; i < whole.length; i++) { + if ((whole.length - i)%3 === 0 && i !== 0) { + text += ','; } + text += whole.charAt(i); } - } - if (trackingNo) - return noMatch || - new angular.filter.Meta({text:trackingNo + " is not recognized"}); - else - return null; -}; - -angular.filter.trackPackage.MATCHERS = [ - { name: "UPS", - url: "http://wwwapps.ups.com/WebTracking/processInputRequest?sort_by=status&tracknums_displayed=1&TypeOfInquiryNumber=T&loc=en_US&track.x=0&track.y=0&InquiryNumber1=", - regexp: [ - /^1Z[0-9A-Z]{16}$/i]}, - { name: "FedEx", - url: "http://www.fedex.com/Tracking?tracknumbers=", - regexp: [ - /^96\d{10}?$/i, - /^96\d{17}?$/i, - /^96\d{20}?$/i, - /^\d{15}$/i, - /^\d{12}$/i]}, - { name: "USPS", - url: "http://trkcnfrm1.smi.usps.com/PTSInternetWeb/InterLabelInquiry.do?origTrackNum=", - regexp: [ - /^(91\d{20})$/i, - /^(91\d{18})$/i]}]; - -angular.filter.link = function(obj, title) { - var text = title || angular.filter.Meta.get(obj); - var url = angular.filter.Meta.get(obj, "url") || angular.filter.Meta.get(obj); - if (url) { - if (angular.validator.email(url) === null) { - url = "mailto:" + url; - } - var html = '' + text + ''; - return new angular.filter.Meta({text:text, url:url, html:html}); - } - return obj; -}; - - -angular.filter.bytes = function(size) { - if(size === null) return ""; - - var suffix = 0; - while (size > 1000) { - size = size / 1024; - suffix++; - } - var txt = "" + size; - var dot = txt.indexOf('.'); - if (dot > -1 && dot + 2 < txt.length) { - txt = txt.substring(0, dot + 2); - } - return txt + " " + angular.filter.bytes.SUFFIX[suffix]; -}; -angular.filter.bytes.SUFFIX = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB']; - -angular.filter.image = function(obj, width, height) { - if (obj && obj.url) { - var style = ""; - if (width) { - style = ' style="max-width: ' + width + - 'px; max-height: ' + (height || width) + 'px;"'; + if (fractionSize > 0) { + for (var j = frc.length; j < fractionSize; j++) { + frc += '0'; + } + text += '.' + frc.substring(0, fractionSize); } - return new angular.filter.Meta({url:obj.url, text:obj.url, - html:''}); - } - return null; -}; - -angular.filter.lowercase = function (obj) { - var text = angular.filter.Meta.get(obj); - return text ? ("" + text).toLowerCase() : text; -}; - -angular.filter.uppercase = function (obj) { - var text = angular.filter.Meta.get(obj); - return text ? ("" + text).toUpperCase() : text; -}; - -angular.filter.linecount = function (obj) { - var text = angular.filter.Meta.get(obj); - if (text==='' || !text) return 1; - return text.split(/\n|\f/).length; -}; - -angular.filter['if'] = function (result, expression) { - return expression ? result : undefined; -}; - -angular.filter.unless = function (result, expression) { - return expression ? undefined : result; -}; - -angular.filter.googleChartApi = function(type, data, width, height) { - data = data || {}; - var api = angular.filter.googleChartApi; - var chart = { - cht:type, - chco:api.collect(data, 'color'), - chtt:api.title(data), - chdl:api.collect(data, 'label'), - chd:api.values(data), - chf:'bg,s,FFFFFF00' - }; - if (_.isArray(data.xLabels)) { - chart.chxt='x'; - chart.chxl='0:|' + data.xLabels.join('|'); - } - return angular.filter.googleChartApi.encode(chart, width, height); -}; - -angular.filter.googleChartApi.values = function(data){ - var seriesValues = []; - _.each(data.series||[], function(serie){ - var values = []; - _.each(serie.values||[], function(value){ - values.push(value); - }); - seriesValues.push(values.join(',')); - }); - var values = seriesValues.join('|'); - return values === "" ? null : "t:" + values; -}; - -angular.filter.googleChartApi.title = function(data){ - var titles = []; - var title = data.title || []; - _.each(_.isArray(title)?title:[title], function(text){ - titles.push(encodeURIComponent(text)); - }); - return titles.join('|'); -}; - -angular.filter.googleChartApi.collect = function(data, key){ - var outterValues = []; - var count = 0; - _.each(data.series||[], function(serie){ - var innerValues = []; - var value = serie[key] || []; - _.each(_.isArray(value)?value:[value], function(color){ - innerValues.push(encodeURIComponent(color)); - count++; + return text; + }, + + 'date': function(amount) { + }, + + 'json': function(object) { + jQuery(this.element).addClass("ng-monospace"); + return toJson(object, true); + }, + + 'trackPackage': (function(){ + var MATCHERS = [ + { name: "UPS", + url: "http://wwwapps.ups.com/WebTracking/processInputRequest?sort_by=status&tracknums_displayed=1&TypeOfInquiryNumber=T&loc=en_US&track.x=0&track.y=0&InquiryNumber1=", + regexp: [ + /^1Z[0-9A-Z]{16}$/i]}, + { name: "FedEx", + url: "http://www.fedex.com/Tracking?tracknumbers=", + regexp: [ + /^96\d{10}?$/i, + /^96\d{17}?$/i, + /^96\d{20}?$/i, + /^\d{15}$/i, + /^\d{12}$/i]}, + { name: "USPS", + url: "http://trkcnfrm1.smi.usps.com/PTSInternetWeb/InterLabelInquiry.do?origTrackNum=", + regexp: [ + /^(91\d{20})$/i, + /^(91\d{18})$/i]}]; + return function(trackingNo, noMatch) { + trackingNo = trim(trackingNo); + var tNo = trackingNo.replace(/ /g, ''); + var returnValue; + foreach(MATCHERS, function(carrier){ + foreach(carrier.regexp, function(regexp){ + if (regexp.test(tNo)) { + var text = carrier.name + ": " + trackingNo; + var url = carrier.url + trackingNo; + returnValue = new angularFilter.Meta({ + text:text, + url:url, + html: '' + text + '', + trackingNo:trackingNo}); + _.breakLoop(); + } + }); + if (returnValue) _.breakLoop(); }); - outterValues.push(innerValues.join('|')); - }); - return count?outterValues.join(','):null; -}; - -angular.filter.googleChartApi.encode= function(params, width, height) { - width = width || 200; - height = height || width; - var url = "http://chart.apis.google.com/chart?"; - var urlParam = []; - params.chs = width + "x" + height; - for ( var key in params) { - var value = params[key]; - if (value) { - urlParam.push(key + "=" + value); + if (returnValue) + return returnValue; + else if (trackingNo) + return noMatch || new angularFilter.Meta({text:trackingNo + " is not recognized"}); + else + return null; + };})(), + + 'link': function(obj, title) { + var text = title || angularFilter.Meta.get(obj); + var url = angularFilter.Meta.get(obj, "url") || angularFilter.Meta.get(obj); + if (url) { + if (angular.validator.email(url) === null) { + url = "mailto:" + url; + } + var html = '' + text + ''; + return new angularFilter.Meta({text:text, url:url, html:html}); } - } - urlParam.sort(); - url += urlParam.join("&"); - return new angular.filter.Meta({url:url, text:value, - html:''}); -}; - -angular.filter.qrcode = function(value, width, height) { - return angular.filter.googleChartApi.encode({cht:'qr', chl:encodeURIComponent(value)}, width, height); -}; -angular.filter.chart = { - pie:function(data, width, height) { - return angular.filter.googleChartApi('p', data, width, height); + return obj; }, - pie3d:function(data, width, height) { - return angular.filter.googleChartApi('p3', data, width, height); + + + 'bytes': (function(){ + var SUFFIX = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB']; + return function(size) { + if(size === null) return ""; + + var suffix = 0; + while (size > 1000) { + size = size / 1024; + suffix++; + } + var txt = "" + size; + var dot = txt.indexOf('.'); + if (dot > -1 && dot + 2 < txt.length) { + txt = txt.substring(0, dot + 2); + } + return txt + " " + SUFFIX[suffix]; + }; + })(), + + 'image': function(obj, width, height) { + if (obj && obj.url) { + var style = ""; + if (width) { + style = ' style="max-width: ' + width + + 'px; max-height: ' + (height || width) + 'px;"'; + } + return new angularFilter.Meta({url:obj.url, text:obj.url, + html:''}); + } + return null; }, - pieConcentric:function(data, width, height) { - return angular.filter.googleChartApi('pc', data, width, height); + + 'lowercase': function (obj) { + var text = angularFilter.Meta.get(obj); + return text ? ("" + text).toLowerCase() : text; }, - barHorizontalStacked:function(data, width, height) { - return angular.filter.googleChartApi('bhs', data, width, height); + + 'uppercase': function (obj) { + var text = angularFilter.Meta.get(obj); + return text ? ("" + text).toUpperCase() : text; }, - barHorizontalGrouped:function(data, width, height) { - return angular.filter.googleChartApi('bhg', data, width, height); + + 'linecount': function (obj) { + var text = angularFilter.Meta.get(obj); + if (text==='' || !text) return 1; + return text.split(/\n|\f/).length; }, - barVerticalStacked:function(data, width, height) { - return angular.filter.googleChartApi('bvs', data, width, height); + + 'if': function (result, expression) { + return expression ? result : undefined; }, - barVerticalGrouped:function(data, width, height) { - return angular.filter.googleChartApi('bvg', data, width, height); + + 'unless': function (result, expression) { + return expression ? undefined : result; }, - line:function(data, width, height) { - return angular.filter.googleChartApi('lc', data, width, height); + + 'googleChartApi': extend( + function(type, data, width, height) { + data = data || {}; + var chart = { + cht:type, + chco:angularFilterGoogleChartApi.collect(data, 'color'), + chtt:angularFilterGoogleChartApi.title(data), + chdl:angularFilterGoogleChartApi.collect(data, 'label'), + chd:angularFilterGoogleChartApi.values(data), + chf:'bg,s,FFFFFF00' + }; + if (_.isArray(data.xLabels)) { + chart.chxt='x'; + chart.chxl='0:|' + data.xLabels.join('|'); + } + return angularFilterGoogleChartApi['encode'](chart, width, height); + }, + { + 'values': function(data){ + var seriesValues = []; + foreach(data.series||[], function(serie){ + var values = []; + foreach(serie.values||[], function(value){ + values.push(value); + }); + seriesValues.push(values.join(',')); + }); + var values = seriesValues.join('|'); + return values === "" ? null : "t:" + values; + }, + + 'title': function(data){ + var titles = []; + var title = data.title || []; + foreach(_.isArray(title)?title:[title], function(text){ + titles.push(encodeURIComponent(text)); + }); + return titles.join('|'); + }, + + 'collect': function(data, key){ + var outterValues = []; + var count = 0; + foreach(data.series||[], function(serie){ + var innerValues = []; + var value = serie[key] || []; + foreach(_.isArray(value)?value:[value], function(color){ + innerValues.push(encodeURIComponent(color)); + count++; + }); + outterValues.push(innerValues.join('|')); + }); + return count?outterValues.join(','):null; + }, + + 'encode': function(params, width, height) { + width = width || 200; + height = height || width; + var url = "http://chart.apis.google.com/chart?"; + var urlParam = []; + params.chs = width + "x" + height; + foreach(params, function(value, key){ + if (value) { + urlParam.push(key + "=" + value); + } + }); + urlParam.sort(); + url += urlParam.join("&"); + return new angularFilter.Meta({url:url, + html:''}); + } + } + ), + + + 'qrcode': function(value, width, height) { + return angularFilterGoogleChartApi['encode']({cht:'qr', chl:encodeURIComponent(value)}, width, height); }, - sparkline:function(data, width, height) { - return angular.filter.googleChartApi('ls', data, width, height); + 'chart': { + pie:function(data, width, height) { + return angularFilterGoogleChartApi('p', data, width, height); + }, + pie3d:function(data, width, height) { + return angularFilterGoogleChartApi('p3', data, width, height); + }, + pieConcentric:function(data, width, height) { + return angularFilterGoogleChartApi('pc', data, width, height); + }, + barHorizontalStacked:function(data, width, height) { + return angularFilterGoogleChartApi('bhs', data, width, height); + }, + barHorizontalGrouped:function(data, width, height) { + return angularFilterGoogleChartApi('bhg', data, width, height); + }, + barVerticalStacked:function(data, width, height) { + return angularFilterGoogleChartApi('bvs', data, width, height); + }, + barVerticalGrouped:function(data, width, height) { + return angularFilterGoogleChartApi('bvg', data, width, height); + }, + line:function(data, width, height) { + return angularFilterGoogleChartApi('lc', data, width, height); + }, + sparkline:function(data, width, height) { + return angularFilterGoogleChartApi('ls', data, width, height); + }, + scatter:function(data, width, height) { + return angularFilterGoogleChartApi('s', data, width, height); + } }, - scatter:function(data, width, height) { - return angular.filter.googleChartApi('s', data, width, height); + + 'html': function(html){ + return new angularFilter.Meta({html:html}); } -}; +}, function(v,k){angularFilter[k] = v;}); -angular.filter.html = function(html){ - return new angular.filter.Meta({html:html}); -}; +angularFilterGoogleChartApi = angularFilter['googleChartApi']; array = [].constructor; toJson = function(obj, pretty){ @@ -1920,7 +1934,7 @@ fromJson = function(json) { parser.assertAllConsumed(); return expression(); } catch (e) { - console.error("fromJson error: ", json, e); + error("fromJson error: ", json, e); throw e; } }; @@ -2925,7 +2939,7 @@ Scope.prototype.evalWidget = function(widget, expression, context, onSuccess, on } return true; } catch (e){ - console.error('Eval Widget Error:', e); + error('Eval Widget Error:', e); var jsonError = toJson(e, true); widget.hasError = true; jQuery(widget.view). @@ -2985,10 +2999,10 @@ Scope.prototype.addWatchListener = function(watchExpression, listener) { Scope.prototype.fireWatchers = function() { var self = this; var fired = false; - jQuery.each(this.watchListeners, function(name, watcher) { + foreach(this.watchListeners, function(watcher) { var value = self.eval(watcher.expression); if (value !== watcher.lastValue) { - jQuery.each(watcher.listeners, function(i, listener){ + foreach(watcher.listeners, function(listener){ listener(value, watcher.lastValue); fired = true; }); @@ -3013,7 +3027,7 @@ Server.prototype.base64url = function(txt) { Server.prototype.request = function(method, url, request, callback) { var requestId = this.uuid + (this.nextId++); - callbacks[requestId] = function(response) { + angularCallbacks[requestId] = function(response) { delete angular[requestId]; callback(200, response); }; @@ -3104,84 +3118,86 @@ Users.prototype = { }; // Copyright (C) 2009 BRAT Tech LLC -angular.validator.regexp = function(value, regexp, msg) { - if (!value.match(regexp)) { - return msg || - "Value does not match expected format " + regexp + "."; - } else { - return null; - } -}; - -angular.validator.number = function(value, min, max) { - var num = 1 * value; - if (num == value) { - if (typeof min != 'undefined' && num < min) { - return "Value can not be less than " + min + "."; +foreach({ + 'regexp': function(value, regexp, msg) { + if (!value.match(regexp)) { + return msg || + "Value does not match expected format " + regexp + "."; + } else { + return null; } - if (typeof min != 'undefined' && num > max) { - return "Value can not be greater than " + max + "."; + }, + + 'number': function(value, min, max) { + var num = 1 * value; + if (num == value) { + if (typeof min != 'undefined' && num < min) { + return "Value can not be less than " + min + "."; + } + if (typeof min != 'undefined' && num > max) { + return "Value can not be greater than " + max + "."; + } + return null; + } else { + return "Value is not a number."; + } + }, + + 'integer': function(value, min, max) { + var number = angularValidator['number'](value, min, max); + if (number === null && value != Math.round(value)) { + return "Value is not a whole number."; + } + return number; + }, + + 'date': function(value, min, max) { + if (value.match(/^\d\d?\/\d\d?\/\d\d\d\d$/)) { + return null; + } + return "Value is not a date. (Expecting format: 12/31/2009)."; + }, + + 'ssn': function(value) { + if (value.match(/^\d\d\d-\d\d-\d\d\d\d$/)) { + return null; + } + return "SSN needs to be in 999-99-9999 format."; + }, + + 'email': function(value) { + if (value.match(/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/)) { + return null; + } + return "Email needs to be in username@host.com format."; + }, + + 'phone': function(value) { + if (value.match(/^1\(\d\d\d\)\d\d\d-\d\d\d\d$/)) { + return null; + } + if (value.match(/^\+\d{2,3} (\(\d{1,5}\))?[\d ]+\d$/)) { + return null; + } + return "Phone number needs to be in 1(987)654-3210 format in North America or +999 (123) 45678 906 internationaly."; + }, + + 'url': function(value) { + if (value.match(/^(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$/)) { + return null; + } + return "URL needs to be in http://server[:port]/path format."; + }, + + 'json': function(value) { + try { + fromJson(value); + return null; + } catch (e) { + return e.toString(); } - return null; - } else { - return "Value is not a number."; - } -}; - -angular.validator.integer = function(value, min, max) { - var number = angular.validator.number(value, min, max); - if (number === null && value != Math.round(value)) { - return "Value is not a whole number."; - } - return number; -}; - -angular.validator.date = function(value, min, max) { - if (value.match(/^\d\d?\/\d\d?\/\d\d\d\d$/)) { - return null; - } - return "Value is not a date. (Expecting format: 12/31/2009)."; -}; - -angular.validator.ssn = function(value) { - if (value.match(/^\d\d\d-\d\d-\d\d\d\d$/)) { - return null; - } - return "SSN needs to be in 999-99-9999 format."; -}; - -angular.validator.email = function(value) { - if (value.match(/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/)) { - return null; - } - return "Email needs to be in username@host.com format."; -}; - -angular.validator.phone = function(value) { - if (value.match(/^1\(\d\d\d\)\d\d\d-\d\d\d\d$/)) { - return null; - } - if (value.match(/^\+\d{2,3} (\(\d{1,5}\))?[\d ]+\d$/)) { - return null; - } - return "Phone number needs to be in 1(987)654-3210 format in North America or +999 (123) 45678 906 internationaly."; -}; - -angular.validator.url = function(value) { - if (value.match(/^(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$/)) { - return null; - } - return "URL needs to be in http://server[:port]/path format."; -}; - -angular.validator.json = function(value) { - try { - fromJson(value); - return null; - } catch (e) { - return e.toString(); } -}; +}, function(v,k) {angularValidator[k] = v;}); // Copyright (C) 2009 BRAT Tech LLC @@ -3709,7 +3725,7 @@ BindAttrUpdater.prototype.updateView = function(scope) { attrValues.push(value); } catch (e) { this.hasError = true; - console.error('BindAttrUpdater', e); + error('BindAttrUpdater', e); var jsonError = toJson(e, true); attrValues.push('[' + jsonError + ']'); jNode. @@ -3841,7 +3857,7 @@ RepeaterUpdater.prototype.updateView = function(scope) { var keyExp = this.keyExp; var valueExp = this.valueExp; var i = 0; - jQuery.each(iterator, function(key, value){ + foreach(iterator, function(value, key){ if (i < childrenLength) { // reuse children child = self.children[i]; diff --git a/example/calculator-manual_init.html b/example/calculator-manual_init.html index 1a6571c2..43d013fc 100644 --- a/example/calculator-manual_init.html +++ b/example/calculator-manual_init.html @@ -1,6 +1,7 @@ + + + + + + + +
+ Fetch tweets for: + + +
+
Loading...
+
    +
  • [{{tweet.user.screen_name}}]: {{tweet.text}}
  • +
+ + -- cgit v1.2.3 From 595b4ea097bcb512173b6d4a12924ea1a3d70ecd Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 18 Jan 2010 10:47:03 -0800 Subject: checkpoint for integration with angular --- Rakefile | 2 +- css/angular.css | 8 +- css/angular_images/arrow_ascend.png | Bin 0 -> 3093 bytes css/angular_images/arrow_descend.png | Bin 0 -> 3076 bytes css/angular_images/arrow_left.gif | Bin 0 -> 102 bytes css/angular_images/arrow_right.gif | Bin 0 -> 102 bytes css/angular_images/loader-bar.gif | Bin 0 -> 10819 bytes css/images/arrow_ascend.png | Bin 3093 -> 0 bytes css/images/arrow_descend.png | Bin 3076 -> 0 bytes css/images/arrow_left.gif | Bin 102 -> 0 bytes css/images/arrow_right.gif | Bin 102 -> 0 bytes css/images/loader-bar.gif | Bin 10819 -> 0 bytes jsTestDriver.conf | 4 +- lib/jasmine-jstd-adapter/JasmineAdapter.js | 96 ++ lib/jasmine/jasmine-0.10.0.js | 2261 ++++++++++++++++++++++++++++ src/Angular.js | 414 +++++ src/Loader.js | 424 ------ src/angular-bootstrap.js | 115 -- test/AngularTest.js | 60 + test/LoaderTest.js | 70 - test/testabilityPatch.js | 2 +- 21 files changed, 2838 insertions(+), 618 deletions(-) create mode 100644 css/angular_images/arrow_ascend.png create mode 100644 css/angular_images/arrow_descend.png create mode 100644 css/angular_images/arrow_left.gif create mode 100644 css/angular_images/arrow_right.gif create mode 100644 css/angular_images/loader-bar.gif delete mode 100644 css/images/arrow_ascend.png delete mode 100644 css/images/arrow_descend.png delete mode 100644 css/images/arrow_left.gif delete mode 100644 css/images/arrow_right.gif delete mode 100644 css/images/loader-bar.gif create mode 100644 lib/jasmine-jstd-adapter/JasmineAdapter.js create mode 100644 lib/jasmine/jasmine-0.10.0.js create mode 100644 src/Angular.js delete mode 100644 src/Loader.js delete mode 100644 src/angular-bootstrap.js create mode 100644 test/AngularTest.js delete mode 100644 test/LoaderTest.js diff --git a/Rakefile b/Rakefile index 8f7bc7ec..56f7a9c4 100644 --- a/Rakefile +++ b/Rakefile @@ -34,7 +34,7 @@ task :compile do concat = %x(cat \ src/angular.prefix \ lib/webtoolkit/webtoolkit.base64.js \ - src/Loader.js \ + src/Angular.js \ src/API.js \ src/Binder.js \ src/ControlBar.js \ diff --git a/css/angular.css b/css/angular.css index 08065295..f90c5d07 100644 --- a/css/angular.css +++ b/css/angular.css @@ -63,8 +63,8 @@ div.ui-widget { background-repeat: no-repeat; background-position: right; } -.ng-ascend { background-image: url(images/arrow_ascend.png); } -.ng-descend { background-image: url(images/arrow_descend.png); } +.ng-ascend { background-image: url(angular_images/arrow_ascend.png); } +.ng-descend { background-image: url(angular_images/arrow_descend.png); } /***************** * TIP @@ -83,7 +83,7 @@ div.ui-widget { } #ng-callout .ng-arrow-left{ - background-image: url(images/arrow_left.gif); + background-image: url(angular_images/arrow_left.gif); background-repeat: no-repeat; background-position: left top; position: absolute; @@ -95,7 +95,7 @@ div.ui-widget { } #ng-callout .ng-arrow-right{ - background-image: url(images/arrow_right.gif); + background-image: url(angular_images/arrow_right.gif); background-repeat: no-repeat; background-position: left top; position: absolute; diff --git a/css/angular_images/arrow_ascend.png b/css/angular_images/arrow_ascend.png new file mode 100644 index 00000000..dd27b92b Binary files /dev/null and b/css/angular_images/arrow_ascend.png differ diff --git a/css/angular_images/arrow_descend.png b/css/angular_images/arrow_descend.png new file mode 100644 index 00000000..ec1cb5df Binary files /dev/null and b/css/angular_images/arrow_descend.png differ diff --git a/css/angular_images/arrow_left.gif b/css/angular_images/arrow_left.gif new file mode 100644 index 00000000..4c9e5c66 Binary files /dev/null and b/css/angular_images/arrow_left.gif differ diff --git a/css/angular_images/arrow_right.gif b/css/angular_images/arrow_right.gif new file mode 100644 index 00000000..3252c359 Binary files /dev/null and b/css/angular_images/arrow_right.gif differ diff --git a/css/angular_images/loader-bar.gif b/css/angular_images/loader-bar.gif new file mode 100644 index 00000000..47adbf03 Binary files /dev/null and b/css/angular_images/loader-bar.gif differ diff --git a/css/images/arrow_ascend.png b/css/images/arrow_ascend.png deleted file mode 100644 index dd27b92b..00000000 Binary files a/css/images/arrow_ascend.png and /dev/null differ diff --git a/css/images/arrow_descend.png b/css/images/arrow_descend.png deleted file mode 100644 index ec1cb5df..00000000 Binary files a/css/images/arrow_descend.png and /dev/null differ diff --git a/css/images/arrow_left.gif b/css/images/arrow_left.gif deleted file mode 100644 index 4c9e5c66..00000000 Binary files a/css/images/arrow_left.gif and /dev/null differ diff --git a/css/images/arrow_right.gif b/css/images/arrow_right.gif deleted file mode 100644 index 3252c359..00000000 Binary files a/css/images/arrow_right.gif and /dev/null differ diff --git a/css/images/loader-bar.gif b/css/images/loader-bar.gif deleted file mode 100644 index 47adbf03..00000000 Binary files a/css/images/loader-bar.gif and /dev/null differ diff --git a/jsTestDriver.conf b/jsTestDriver.conf index ebd45d9d..1fbe05a7 100644 --- a/jsTestDriver.conf +++ b/jsTestDriver.conf @@ -5,7 +5,7 @@ load: - lib/jquery/jquery-1.3.2.js - lib/jquery/jquery-ui-1.7.1.custom.min.js - lib/underscore/underscore.js - - src/Loader.js + - src/Angular.js - src/*.js - src/test/_namespace.js - src/test/*.js @@ -14,7 +14,5 @@ load: - test/*.js exclude: - - src/angular-bootstrap.js - src/angular.prefix - src/angular.suffix - \ No newline at end of file diff --git a/lib/jasmine-jstd-adapter/JasmineAdapter.js b/lib/jasmine-jstd-adapter/JasmineAdapter.js new file mode 100644 index 00000000..83a1deed --- /dev/null +++ b/lib/jasmine-jstd-adapter/JasmineAdapter.js @@ -0,0 +1,96 @@ +/** + * @fileoverview Jasmine JsTestDriver Adapter. + * @author ibolmo@gmail.com (Olmo Maldonado) + */ + +(function() { + +// Suite/TestCase before and after function stacks. +var before = []; +var after = []; + +jasmine.Env.prototype.describe = (function(describe){ + + // TODO(ibolmo): Support nested describes. + return function(description, specDefinitions){ + this.currentTestCase = TestCase(description); + return describe.call(this, description, specDefinitions); + }; + +})(jasmine.Env.prototype.describe); + + +jasmine.Env.prototype.it = (function(it){ + + return function(desc, func){ + var spec = it.call(this, desc, func); + this.currentTestCase.prototype['test that it ' + desc] = func; + return spec; + }; + +})(jasmine.Env.prototype.it); + + +jasmine.Env.prototype.beforeEach = (function(beforeEach){ + + // TODO(ibolmo): Support beforeEach TestCase. + return function(beforeEachFunction) { + beforeEach.call(this, beforeEachFunction); + if (this.currentTestCase) { + this.currentTestCase.prototype.setUp = beforeEachFunction; + } else { + before.push(beforeEachFunction); + } + }; + +})(jasmine.Env.prototype.beforeEach); + + +jasmine.Env.prototype.afterEach = (function(afterEach){ + + // TODO(ibolmo): Support afterEach TestCase. + return function(afterEachFunction) { + afterEach.call(this, afterEachFunction); + if (this.currentTestCase) { + this.currentTestCase.prototype.tearDown = afterEachFunction; + } else { + after.push(afterEachFunction); + } + }; + +})(jasmine.Env.prototype.afterEach); + + +jasmine.NestedResults.prototype.addResult = (function(addResult){ + + return function(result) { + addResult.call(this, result); + if (result.type != 'MessageResult' && !result.passed()) fail(result.message); + }; + +})(jasmine.NestedResults.prototype.addResult); + + +jstestdriver.plugins.TestRunnerPlugin.prototype.runTestConfiguration = (function(runTestConfiguration){ + + return function(testRunConfiguration, onTestDone, onTestRunConfigurationComplete){ + for (var i = 0, l = before.length; i < l; i++) before[i](); + onTestRunConfigurationComplete = (function(configurationComplete){ + + return function() { + for (var i = 0, l = after.length; i < l; i++) after[i](); + configurationComplete(); + }; + + })(onTestRunConfigurationComplete); + runTestConfiguration.call(this, testRunConfiguration, onTestDone, onTestRunConfigurationComplete); + }; + +})(jstestdriver.plugins.TestRunnerPlugin.prototype.runTestConfiguration); + + +// Reset environment with overriden methods. +jasmine.currentEnv_ = null; +jasmine.getEnv(); + +})(); diff --git a/lib/jasmine/jasmine-0.10.0.js b/lib/jasmine/jasmine-0.10.0.js new file mode 100644 index 00000000..bb7547e8 --- /dev/null +++ b/lib/jasmine/jasmine-0.10.0.js @@ -0,0 +1,2261 @@ +/** + * Top level namespace for Jasmine, a lightweight JavaScript BDD/spec/testing framework. + * + * @namespace + */ +var jasmine = {}; + +/** + * @private + */ +jasmine.unimplementedMethod_ = function() { + throw new Error("unimplemented method"); +}; + +/** + * Use jasmine.undefined instead of undefined, since undefined 0; +}; + +/** + * Returns a matchable 'generic' object of the class type. For use in expecations of type when values don't matter. + * + * @example + * // don't care about which function is passed in, as long as it's a function + * expect(mySpy).wasCalledWith(jasmine.any(Function)); + * + * @param {Class} clazz + * @returns matchable object of the type clazz + */ +jasmine.any = function(clazz) { + return new jasmine.Matchers.Any(clazz); +}; + +/** + * Jasmine Spies are test doubles that can act as stubs, spies, fakes or when used in an expecation, mocks. + * + * Spies should be created in test setup, before expectations. They can then be checked, using the standard Jasmine + * expectation syntax. Spies can be checked if they were called or not and what the calling params were. + * + * A Spy has the following mehtod: wasCalled, callCount, mostRecentCall, and argsForCall (see docs) + * Spies are torn down at the end of every spec. + * + * Note: Do not call new jasmine.Spy() directly - a spy must be created using spyOn, jasmine.createSpy or jasmine.createSpyObj. + * + * @example + * // a stub + * var myStub = jasmine.createSpy('myStub'); // can be used anywhere + * + * // spy example + * var foo = { + * not: function(bool) { return !bool; } + * } + * + * // actual foo.not will not be called, execution stops + * spyOn(foo, 'not'); + + // foo.not spied upon, execution will continue to implementation + * spyOn(foo, 'not').andCallThrough(); + * + * // fake example + * var foo = { + * not: function(bool) { return !bool; } + * } + * + * // foo.not(val) will return val + * spyOn(foo, 'not').andCallFake(function(value) {return value;}); + * + * // mock example + * foo.not(7 == 7); + * expect(foo.not).wasCalled(); + * expect(foo.not).wasCalledWith(true); + * + * @constructor + * @see spyOn, jasmine.createSpy, jasmine.createSpyObj + * @param {String} name + */ +jasmine.Spy = function(name) { + /** + * The name of the spy, if provided. + */ + this.identity = name || 'unknown'; + /** + * Is this Object a spy? + */ + this.isSpy = true; + /** + * The actual function this spy stubs. + */ + this.plan = function() { + }; + /** + * Tracking of the most recent call to the spy. + * @example + * var mySpy = jasmine.createSpy('foo'); + * mySpy(1, 2); + * mySpy.mostRecentCall.args = [1, 2]; + */ + this.mostRecentCall = {}; + + /** + * Holds arguments for each call to the spy, indexed by call count + * @example + * var mySpy = jasmine.createSpy('foo'); + * mySpy(1, 2); + * mySpy(7, 8); + * mySpy.mostRecentCall.args = [7, 8]; + * mySpy.argsForCall[0] = [1, 2]; + * mySpy.argsForCall[1] = [7, 8]; + */ + this.argsForCall = []; + this.calls = []; +}; + +/** + * Tells a spy to call through to the actual implemenatation. + * + * @example + * var foo = { + * bar: function() { // do some stuff } + * } + * + * // defining a spy on an existing property: foo.bar + * spyOn(foo, 'bar').andCallThrough(); + */ +jasmine.Spy.prototype.andCallThrough = function() { + this.plan = this.originalValue; + return this; +}; + +/** + * For setting the return value of a spy. + * + * @example + * // defining a spy from scratch: foo() returns 'baz' + * var foo = jasmine.createSpy('spy on foo').andReturn('baz'); + * + * // defining a spy on an existing property: foo.bar() returns 'baz' + * spyOn(foo, 'bar').andReturn('baz'); + * + * @param {Object} value + */ +jasmine.Spy.prototype.andReturn = function(value) { + this.plan = function() { + return value; + }; + return this; +}; + +/** + * For throwing an exception when a spy is called. + * + * @example + * // defining a spy from scratch: foo() throws an exception w/ message 'ouch' + * var foo = jasmine.createSpy('spy on foo').andThrow('baz'); + * + * // defining a spy on an existing property: foo.bar() throws an exception w/ message 'ouch' + * spyOn(foo, 'bar').andThrow('baz'); + * + * @param {String} exceptionMsg + */ +jasmine.Spy.prototype.andThrow = function(exceptionMsg) { + this.plan = function() { + throw exceptionMsg; + }; + return this; +}; + +/** + * Calls an alternate implementation when a spy is called. + * + * @example + * var baz = function() { + * // do some stuff, return something + * } + * // defining a spy from scratch: foo() calls the function baz + * var foo = jasmine.createSpy('spy on foo').andCall(baz); + * + * // defining a spy on an existing property: foo.bar() calls an anonymnous function + * spyOn(foo, 'bar').andCall(function() { return 'baz';} ); + * + * @param {Function} fakeFunc + */ +jasmine.Spy.prototype.andCallFake = function(fakeFunc) { + this.plan = fakeFunc; + return this; +}; + +/** + * Resets all of a spy's the tracking variables so that it can be used again. + * + * @example + * spyOn(foo, 'bar'); + * + * foo.bar(); + * + * expect(foo.bar.callCount).toEqual(1); + * + * foo.bar.reset(); + * + * expect(foo.bar.callCount).toEqual(0); + */ +jasmine.Spy.prototype.reset = function() { + this.wasCalled = false; + this.callCount = 0; + this.argsForCall = []; + this.calls = []; + this.mostRecentCall = {}; +}; + +jasmine.createSpy = function(name) { + + var spyObj = function() { + spyObj.wasCalled = true; + spyObj.callCount++; + var args = jasmine.util.argsToArray(arguments); + spyObj.mostRecentCall.object = this; + spyObj.mostRecentCall.args = args; + spyObj.argsForCall.push(args); + spyObj.calls.push({object: this, args: args}); + return spyObj.plan.apply(this, arguments); + }; + + var spy = new jasmine.Spy(name); + + for (var prop in spy) { + spyObj[prop] = spy[prop]; + } + + spyObj.reset(); + + return spyObj; +}; + +/** + * Determines whether an object is a spy. + * + * @param {jasmine.Spy|Object} putativeSpy + * @returns {Boolean} + */ +jasmine.isSpy = function(putativeSpy) { + return putativeSpy && putativeSpy.isSpy; +}; + +/** + * Creates a more complicated spy: an Object that has every property a function that is a spy. Used for stubbing something + * large in one call. + * + * @param {String} baseName name of spy class + * @param {Array} methodNames array of names of methods to make spies + */ +jasmine.createSpyObj = function(baseName, methodNames) { + var obj = {}; + for (var i = 0; i < methodNames.length; i++) { + obj[methodNames[i]] = jasmine.createSpy(baseName + '.' + methodNames[i]); + } + return obj; +}; + +jasmine.log = function(message) { + jasmine.getEnv().currentSpec.log(message); +}; + +/** + * Function that installs a spy on an existing object's method name. Used within a Spec to create a spy. + * + * @example + * // spy example + * var foo = { + * not: function(bool) { return !bool; } + * } + * spyOn(foo, 'not'); // actual foo.not will not be called, execution stops + * + * @see jasmine.createSpy + * @param obj + * @param methodName + * @returns a Jasmine spy that can be chained with all spy methods + */ +var spyOn = function(obj, methodName) { + return jasmine.getEnv().currentSpec.spyOn(obj, methodName); +}; + +/** + * Creates a Jasmine spec that will be added to the current suite. + * + * // TODO: pending tests + * + * @example + * it('should be true', function() { + * expect(true).toEqual(true); + * }); + * + * @param {String} desc description of this specification + * @param {Function} func defines the preconditions and expectations of the spec + */ +var it = function(desc, func) { + return jasmine.getEnv().it(desc, func); +}; + +/** + * Creates a disabled Jasmine spec. + * + * A convenience method that allows existing specs to be disabled temporarily during development. + * + * @param {String} desc description of this specification + * @param {Function} func defines the preconditions and expectations of the spec + */ +var xit = function(desc, func) { + return jasmine.getEnv().xit(desc, func); +}; + +/** + * Starts a chain for a Jasmine expectation. + * + * It is passed an Object that is the actual value and should chain to one of the many + * jasmine.Matchers functions. + * + * @param {Object} actual Actual value to test against and expected value + */ +var expect = function(actual) { + return jasmine.getEnv().currentSpec.expect(actual); +}; + +/** + * Defines part of a jasmine spec. Used in cominbination with waits or waitsFor in asynchrnous specs. + * + * @param {Function} func Function that defines part of a jasmine spec. + */ +var runs = function(func) { + jasmine.getEnv().currentSpec.runs(func); +}; + +/** + * Waits for a timeout before moving to the next runs()-defined block. + * @param {Number} timeout + */ +var waits = function(timeout) { + jasmine.getEnv().currentSpec.waits(timeout); +}; + +/** + * Waits for the latchFunction to return true before proceeding to the next runs()-defined block. + * + * @param {Number} timeout + * @param {Function} latchFunction + * @param {String} message + */ +var waitsFor = function(timeout, latchFunction, message) { + jasmine.getEnv().currentSpec.waitsFor(timeout, latchFunction, message); +}; + +/** + * A function that is called before each spec in a suite. + * + * Used for spec setup, including validating assumptions. + * + * @param {Function} beforeEachFunction + */ +var beforeEach = function(beforeEachFunction) { + jasmine.getEnv().beforeEach(beforeEachFunction); +}; + +/** + * A function that is called after each spec in a suite. + * + * Used for restoring any state that is hijacked during spec execution. + * + * @param {Function} afterEachFunction + */ +var afterEach = function(afterEachFunction) { + jasmine.getEnv().afterEach(afterEachFunction); +}; + +/** + * Defines a suite of specifications. + * + * Stores the description and all defined specs in the Jasmine environment as one suite of specs. Variables declared + * are accessible by calls to beforeEach, it, and afterEach. Describe blocks can be nested, allowing for specialization + * of setup in some tests. + * + * @example + * // TODO: a simple suite + * + * // TODO: a simple suite with a nested describe block + * + * @param {String} description A string, usually the class under test. + * @param {Function} specDefinitions function that defines several specs. + */ +var describe = function(description, specDefinitions) { + return jasmine.getEnv().describe(description, specDefinitions); +}; + +/** + * Disables a suite of specifications. Used to disable some suites in a file, or files, temporarily during development. + * + * @param {String} description A string, usually the class under test. + * @param {Function} specDefinitions function that defines several specs. + */ +var xdescribe = function(description, specDefinitions) { + return jasmine.getEnv().xdescribe(description, specDefinitions); +}; + + +// Provide the XMLHttpRequest class for IE 5.x-6.x: +jasmine.XmlHttpRequest = (typeof XMLHttpRequest == "undefined") ? function() { + try { + return new ActiveXObject("Msxml2.XMLHTTP.6.0"); + } catch(e) { + } + try { + return new ActiveXObject("Msxml2.XMLHTTP.3.0"); + } catch(e) { + } + try { + return new ActiveXObject("Msxml2.XMLHTTP"); + } catch(e) { + } + try { + return new ActiveXObject("Microsoft.XMLHTTP"); + } catch(e) { + } + throw new Error("This browser does not support XMLHttpRequest."); +} : XMLHttpRequest; + +/** + * Adds suite files to an HTML document so that they are executed, thus adding them to the current + * Jasmine environment. + * + * @param {String} url path to the file to include + * @param {Boolean} opt_global + */ +jasmine.include = function(url, opt_global) { + if (opt_global) { + document.write(''); - }; - - if (scriptConfig.autoLoadDependencies) { - addScript("/../lib/webtoolkit/webtoolkit.base64.js"); - addScript("/../lib/swfobject/swfobject.js"); - addScript("/../lib/jquery/jquery-1.3.2.js"); - addScript("/../lib/jquery/jquery-ui-1.7.1.custom.min.js"); - addScript("/../lib/underscore/underscore.js"); - addScript("/Loader.js"); - addScript("/API.js"); - addScript("/Binder.js"); - addScript("/ControlBar.js"); - addScript("/DataStore.js"); - addScript("/Filters.js"); - addScript("/JSON.js"); - addScript("/Model.js"); - addScript("/Parser.js"); - addScript("/Scope.js"); - addScript("/Server.js"); - addScript("/Users.js"); - addScript("/Validators.js"); - addScript("/Widgets.js"); - } else { - addScript("/ajax/libs/swfobject/2.2/swfobject.js", "http://ajax.googleapis.com"); - addScript("/ajax/libs/jquery/1.3.2/jquery.min.js", "http://ajax.googleapis.com"); - addScript("/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js", "http://ajax.googleapis.com"); - } - - window.onload = function() { - var doc = window.document; - if (scriptConfig.bindRootId) { - doc = null; - var ids = scriptConfig.bindRootId.split('|'); - for ( var i = 0; i < ids.length && !doc; i++) { - var idCond = ids[i].split('?'); - var id = idCond[0]; - if (idCond.length > 1) { - if (!window.document.getElementById(idCond[1])) { - continue; - } - } - doc = window.document.getElementById(id); - } - } - if (scriptConfig.autoBind && doc) { - window.angularScope = angular.compile(doc, scriptConfig); - } - if (typeof previousOnLoad === 'function') { - try { - previousOnLoad.apply(this, arguments); - } catch (e) {} - } - }; -})(window.onload); - - diff --git a/test/AngularTest.js b/test/AngularTest.js new file mode 100644 index 00000000..9610ef76 --- /dev/null +++ b/test/AngularTest.js @@ -0,0 +1,60 @@ +AngularTest = TestCase('AngularTest'); + +AngularTest.prototype.testDefaultDatabasePathFromSubdomain = function() { + var loader = new Angular(null, null, {server:"http://account.getangular.com", database:"database"}); + loader.computeConfiguration(); + assertEquals("database", loader.config.database); + + loader = new Angular(null, null, {server:"http://account.getangular.com"}); + loader.computeConfiguration(); + assertEquals("account", loader.config.database); + + loader = new Angular(null, null, {server:"https://account.getangular.com"}); + loader.computeConfiguration(); + assertEquals("account", loader.config.database); +}; + + + +UrlWatcherTest = TestCase('UrlWatcherTest'); + +UrlWatcherTest.prototype.testUrlWatcher = function () { + expectAsserts(2); + var location = {href:"http://server", hash:""}; + var watcher = new UrlWatcher(location); + watcher.delay = 1; + watcher.listener = function(url){ + assertEquals('http://getangular.test', url); + }; + watcher.setTimeout = function(fn, delay){ + assertEquals(1, delay); + location.href = "http://getangular.test"; + watcher.setTimeout = function(fn, delay) { + }; + fn(); + }; + watcher.watch(); +}; + +UrlWatcherTest.prototype.testItShouldFireOnUpdateEventWhenSpecialURLSet = function(){ + expectAsserts(2); + var location = {href:"http://server", hash:"#$iframe_notify=1234"}; + var watcher = new UrlWatcher(location); + angular.callbacks._iframe_notify_1234 = function () { + assertEquals("undefined", typeof angularCallbacks._iframe_notify_1234); + assertEquals("http://server2#", location.href); + }; + watcher.delay = 1; + watcher.expectedUrl = "http://server2"; + watcher.setTimeout = function(fn, delay){ + watcher.setTimeout = function(fn, delay) {}; + fn(); + }; + watcher.watch(); +}; + +FunctionTest = TestCase("FunctionTest"); + +FunctionTest.prototype.testEscapeHtml = function () { + assertEquals("<div>&amp;</div>", escapeHtml('
&
')); +}; \ No newline at end of file diff --git a/test/LoaderTest.js b/test/LoaderTest.js deleted file mode 100644 index a474c8a4..00000000 --- a/test/LoaderTest.js +++ /dev/null @@ -1,70 +0,0 @@ -LoaderTest = TestCase('LoaderTest'); - -LoaderTest.prototype.testLoadCss = function(){ - if ($.browser.safari) return; - var head = jQuery('')[0]; - var loader = new Loader(document, head, {}); - var log = ''; - loader.config.server = 'http://'; - loader.loadCss('x'); - assertEquals($(head).find('link').attr('href'), 'http://x'); -}; - -LoaderTest.prototype.testDefaultDatabasePathFromSubdomain = function() { - var loader = new Loader(null, null, {server:"http://account.getangular.com", database:"database"}); - loader.computeConfiguration(); - assertEquals("database", loader.config.database); - - loader = new Loader(null, null, {server:"http://account.getangular.com"}); - loader.computeConfiguration(); - assertEquals("account", loader.config.database); - - loader = new Loader(null, null, {server:"https://account.getangular.com"}); - loader.computeConfiguration(); - assertEquals("account", loader.config.database); -}; - - - -UrlWatcherTest = TestCase('UrlWatcherTest'); - -UrlWatcherTest.prototype.testUrlWatcher = function () { - expectAsserts(2); - var location = {href:"http://server", hash:""}; - var watcher = new UrlWatcher(location); - watcher.delay = 1; - watcher.listener = function(url){ - assertEquals('http://getangular.test', url); - }; - watcher.setTimeout = function(fn, delay){ - assertEquals(1, delay); - location.href = "http://getangular.test"; - watcher.setTimeout = function(fn, delay) { - }; - fn(); - }; - watcher.watch(); -}; - -UrlWatcherTest.prototype.testItShouldFireOnUpdateEventWhenSpecialURLSet = function(){ - expectAsserts(2); - var location = {href:"http://server", hash:"#$iframe_notify=1234"}; - var watcher = new UrlWatcher(location); - angular.callbacks._iframe_notify_1234 = function () { - assertEquals("undefined", typeof angularCallbacks._iframe_notify_1234); - assertEquals("http://server2#", location.href); - }; - watcher.delay = 1; - watcher.expectedUrl = "http://server2"; - watcher.setTimeout = function(fn, delay){ - watcher.setTimeout = function(fn, delay) {}; - fn(); - }; - watcher.watch(); -}; - -FunctionTest = TestCase("FunctionTest"); - -FunctionTest.prototype.testEscapeHtml = function () { - assertEquals("<div>&amp;</div>", escapeHtml('
&
')); -}; \ No newline at end of file diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index dde21846..78ffd380 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -96,7 +96,7 @@ function decode64(base64){ return fromJson(Base64.decode(base64)); } -Loader.prototype.configureJQueryPlugins(); +Angular.prototype.configureJQueryPlugins(); function assertHidden(node) { var display = node.css('display'); -- cgit v1.2.3 From 0e566fe6cb41de388df6793b350fb81aaa4a8476 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 18 Jan 2010 17:56:08 -0800 Subject: tweeter demo client --- .externalToolBuilders/JSTD_Tests.launch | 7 +- angular-minified.js | 193 ++++++++++++++++--------------- angular.js | 71 +++++++----- example/business_card.html | 50 -------- example/tweeter/style.css | 87 ++++++++++++++ example/tweeter/tweeter_addressbook.html | 64 ++++++++++ example/tweeter/tweeterclient.js | 35 ++++++ src/Angular.js | 30 ++--- src/Binder.js | 1 - src/Filters.js | 17 +++ test.sh | 3 +- test/FiltersTest.js | 9 ++ 12 files changed, 369 insertions(+), 198 deletions(-) delete mode 100644 example/business_card.html create mode 100644 example/tweeter/style.css create mode 100644 example/tweeter/tweeter_addressbook.html create mode 100644 example/tweeter/tweeterclient.js diff --git a/.externalToolBuilders/JSTD_Tests.launch b/.externalToolBuilders/JSTD_Tests.launch index 17fb5035..503cbaff 100644 --- a/.externalToolBuilders/JSTD_Tests.launch +++ b/.externalToolBuilders/JSTD_Tests.launch @@ -1,10 +1,9 @@ - + - - + + - diff --git a/angular-minified.js b/angular-minified.js index e49e0324..f590b704 100644 --- a/angular-minified.js +++ b/angular-minified.js @@ -1,98 +1,99 @@ -function J(){return function(){}}function K(p){return function(){return p}} -(function(p,y){function n(){}function v(a,b,c){var d=p.console;switch(arguments.length){case 1:d.log(a);break;case 2:d.log(a,b);break;default:d.log(a,b,c);break}}function W(a,b,c){var d=p.console;switch(arguments.length){case 1:d.error(a);break;case 2:d.error(a,b);break;default:d.error(a,b,c);break}}function da(a,b){var c=y.createElement("div");c.className=a;for(var d=a="",e=0;e/g,">")}function Ca(a){if(!a||!a.replace)return a;return a.replace(//g,">").replace(/\"/g,""")}function Da(a,b){if(!a)throw"Missing this";if(!_.isFunction(b))throw"Missing function";return function(){return b.apply(a,arguments)}}function Ea(a,b){return function(){for(var c= -[this],d=0;d/g,">")}function Da(a){if(!a||!a.replace)return a;return a.replace(//g,">").replace(/\"/g,""")}function ga(a,b){if(!a)throw"Missing this";if(!_.isFunction(b))throw"Missing function";return function(){return b.apply(a,arguments)}}function Ea(a,b){return function(){for(var c= +[this],d=0;d>2;c=(c&3)<<4|d>>4;g=(d&15)<<2|e>>6;h=e&63;if(isNaN(d))g=h=64;else if(isNaN(e))h= -64;b=b+this.u.charAt(f)+this.u.charAt(c)+this.u.charAt(g)+this.u.charAt(h)}return b},qd:function(a){var b="",c,d,e,f,g,h=0;for(a=a.replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4;d=(d&15)<<4|f>>2;e=(f&3)<<6|g;b+=String.fromCharCode(c);if(f!=64)b+=String.fromCharCode(d);if(g!=64)b+=String.fromCharCode(e)}return b=ba.nb(b)},ob:function(a){a=a.replace(/\r\n/g,"\n"); -for(var b="",c=0;c127&&d<2048)b+=String.fromCharCode(d>>6|192);else{b+=String.fromCharCode(d>>12|224);b+=String.fromCharCode(d>>6&63|128)}b+=String.fromCharCode(d&63|128)}}return b},nb:function(a){for(var b="",c=0,d=c1=c2=0;c191&&d<224){c2=a.charCodeAt(c+1);b+=String.fromCharCode((d&31)<<6|c2&63);c+=2}else{c2=a.charCodeAt(c+1);c3=a.charCodeAt(c+ -2);b+=String.fromCharCode((d&15)<<12|(c2&63)<<6|c3&63);c+=3}}return b}};if(typeof y.getAttribute=="undefined")y.getAttribute=J();if(typeof Node=="undefined")Node={ELEMENT_NODE:1,ATTRIBUTE_NODE:2,TEXT_NODE:3,CDATA_SECTION_NODE:4,ENTITY_REFERENCE_NODE:5,ENTITY_NODE:6,PROCESSING_INSTRUCTION_NODE:7,COMMENT_NODE:8,DOCUMENT_NODE:9,DOCUMENT_TYPE_NODE:10,DOCUMENT_FRAGMENT_NODE:11,NOTATION_NODE:12};p.console||(p.console={log:n,error:n});var R,q=_.each,S=_.extend,k=p.jQuery,X=k.browser.msie,m=p.angular||(p.angular= -{}),Ba=m.validator||(m.validator={}),r=m.filter||(m.filter={}),ca=m.callbacks||(m.callbacks={});m.alert||(m.alert=function(){v(arguments);p.alert.apply(p,arguments)});ha.prototype={load:function(){this.Cb();v("Server: "+this.j.H);this.Bb();this.Ab();this.wb()},Bb:function(){v("Loader.configureJQueryPlugins()");k.fn.scope=function(){for(var a=this;a&&a.get(0);){var b=a.data("scope");if(b)return b;a=a.parent()}return null};k.fn.controller=function(){return this.data("controller")||Q.Ub}},Ec:function(){return""+ -(new Date).getTime()},Ab:function(){var a=this.j;if(!a.F){var b=a.H.match(/https?:\/\/([\w]*)/);a.F=b?b[1]:"$MEMORY"}},wb:function(){function a(){g.Ob(function(l){!l&&c.find("[ng-auth=eager]").length&&g.ja()})}v("Loader.bindHtml()");var b=new ia(this.location),c=this.document,d=new ma(this.j.H,this.j.F),e=new x(c[0],d,b,this.j);d.qc=Ea(e,e.e);b=new P(c.find("body"),this.j.H);var f=this.j.F=="$MEMORY"?new aa(this.window):new ja(this.j.H,k.getScript);f=new ka(f,new U(k(c.body)),function(){e.c()});var g= -new la(f,b),h="/data/"+this.j.F,i=new T(function(l,o){f.N("POST",h,l,o)},g,e.anchor);e.Za.push(function(){i.Ea()});var j=new w({$anchor:e.anchor,$binder:e,$config:this.j,$console:p.console,$datastore:i,$save:function(l){i.zc(j.q,l,e.anchor)},$window:p,$uid:this.Ec,$users:g},"ROOT");c.data("scope",j);v("$binder.entity()");e.K(j);v("$binder.compile()");e.compile();v("ControlBar.bind()");b.bind();v("$users.fetchCurrentUser()");a();v("PopUp.bind()");(new B(c)).bind();v("$binder.parseAnchor()");e.sc(); -v("$binder.updateView()");e.c();c.find("body").show();v("ready()")},Cb:function(){var a=p.location.href+"#";a=a.split("#")[1];var b={Ib:null};a=a.split("&");for(var c=0;c=0&&a.splice(c,1);return b},find:function(a,b,c){if(b){var d=m.Function.compile(b);_.detect(a,function(e){if(d(e)){c=e;return true}});return c}},findById:function(a,b){return m.Tc.find(a,function(c){return c.z==b},null)},filter:function(a,b){var c=[];c.xb=function(j){for(var l=0;l-1;case "object":for(var o in j)if(o.charAt(0)!=="$"&&e(j[o],l))return true;return false;case "array":for(o=0;o=0&&a.splice(d,1);a.unshift((c?"-":"+")+b);return a},orderByDirection:function(a,b,c,d){c=c||"ng-ascend";d=d||"ng-descend";a=a[0]||"";var e=true;if(a.charAt(0)=="-"){a=a.substring(1);e=false}else if(a.charAt(0)=="+")a=a.substring(1);return a==b?e?c:d:""},merge:function(a,b,c){var d=a[b];if(!d){d={};a[b]=d}Z(c,d);return a}},Ga={quote:function(a){return'"'+ -a.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/\t/g,"\\t").replace(/\v/g,"\\v")+'"'},quoteUnicode:function(a){a=m.String.quote(a);for(var b=[],c=0;c-1;){c1||x.J(a[0])!==null};x.J=function(a){return(a=a.replace(/\n/gm," ").match(/^\{\{(.*)\}\}$/))?a[1]:null};x.prototype={tc:function(a){var b={};a.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(c,d,e){if(d)b[decodeURIComponent(d)]=decodeURIComponent(e)});return b},sc:function(a){var b= -this;a=a||this.$a.Ga();var c=a.indexOf("#");if(!(c<0)){a=this.tc(a.substring(c+1));q(b.anchor,function(d,e){delete b.anchor[e]});q(a,function(d,e){b.anchor[e]=d})}},Fc:function(){var a=this.$a.Ga(),b=a.indexOf("#");if(b>-1)a=a.substring(0,b);a+="#";b="";for(var c in this.anchor){var d=this.anchor[c];if(typeof d==="undefined"||d===null)delete this.anchor[c];else{a+=b+encodeURIComponent(c);if(d!==true)a+="="+encodeURIComponent(d);b="&"}}return a},c:function(){(new Date).getTime();var a=k(this.B).scope(); -a.i("$invalidWidgets",[]);a.c();(new Date).getTime();this.Fc();_.each(this.Za,function(b){b()})},ga:function(a){var b=k(this.B),c=b.find(a);if(b.is(a))c=c.andSelf();return c},K:function(a){this.ga("[ng-entity]").attr("ng-watch",function(){try{var b=k(this);return a.K(b.attr("ng-entity"))+(b.attr("ng-watch")||"")}catch(c){alert(c)}})},compile:function(){var a=k(this.B),b=this;if(this.j.Yc){var c=this.ga(":submit").not("[ng-action]");c.attr("ng-action","$save()");c.not(":disabled").not("ng-bind-attr").attr("ng-bind-attr", -'{disabled:"{{$invalidWidgets}}"}')}this.Sa(this.B)(this.B,a.scope(),"");this.ga("a[ng-action]").live("click",function(){var d=k(this);try{d.scope().eval(d.attr("ng-action"));d.removeAttr("ng-error");d.removeClass("ng-exception")}catch(e){d.addClass("ng-exception");d.attr("ng-error",z(e,true))}b.c();return false})},Dc:function(a,b,c){b=b.concat();var d=b.pop(),e=x.Z(a.nodeValue);if(e.length>1||x.J(e[0])){var f=a.parentNode;if(ea(f)){f.setAttribute("ng-bind-template",a.nodeValue);c.push({path:b,b:function(l){return new N(l, -l.getAttribute("ng-bind-template"))}})}else for(var g=0;g2&&a.setAttribute("ng-bind-attr", -d)}a.getAttribute||v(a);var j=a.getAttribute("ng-repeat");if(j){a.removeAttribute("ng-repeat");var l=this.Sa(a);d=y.createComment("ng-repeat: "+j);e=a.parentNode;e.insertBefore(d,a);e.removeChild(a);function o(s,t,A){var I=k(a).clone();I.css("display","");I.attr("ng-repeat-index",""+A);I.data("scope",s);l(I[0],s,t+A+":");return I}c.push({path:b,b:function(s,t,A){return new Aa(k(s),j,o,A)}})}else{a.getAttribute("ng-eval")&&c.push({path:b,b:this.kc});a.getAttribute("ng-bind")&&c.push({path:b,b:this.Qa}); -a.getAttribute("ng-bind-attr")&&c.push({path:b,b:this.gc});a.getAttribute("ng-hide")&&c.push({path:b,b:this.lc});a.getAttribute("ng-show")&&c.push({path:b,b:this.mc});a.getAttribute("ng-class")&&c.push({path:b,b:this.hc});a.getAttribute("ng-class-odd")&&c.push({path:b,b:this.jc});a.getAttribute("ng-class-even")&&c.push({path:b,b:this.ic});a.getAttribute("ng-style")&&c.push({path:b,b:this.nc});a.getAttribute("ng-watch")&&c.push({path:b,b:this.oc});d=a.nodeName;if(d=="INPUT"||d=="TEXTAREA"||d=="SELECT"|| -d=="BUTTON"){var C=this;c.push({path:b,b:function(s,t,A){s.name=A+s.name.split(":").pop();return C.Lc.Db(k(s),t)}})}if(d=="OPTION")if(!k("')};M.prototype={e:function(a){var b=this.view.find("input").attr("checked")? -this.value:null;if(this.d===b)return false;else{a.i(this.Wa,b);return true}},c:function(a){if((a=a.get(this.Wa))&&this.value!==a){this.value=a;this.view.find("a").attr("href",this.value.url).text(this.value.text);this.view.find("span").text(m.filter.bytes(this.value.size))}this.view.find("input").attr("checked",!!a)}};Q.prototype={e:K(true),c:n};Q.Ub=new Q;var Ja=Q;na.prototype={e:function(a){var b=this.view.value;if(this.d===b)return false;else{a.m(this.exp,b);this.d=b;return true}},c:function(a){var b= -this.view,c=a.get(this.exp);if(typeof c==="undefined"){c=this.p;a.m(this.exp,c)}c=c?c:"";if(this.d!=c)this.d=b.value=c;var d=false;b.removeAttribute("ng-error");if(this.yc)d=!(c&&c.length>0);var e=d?"Required Value":null;if(!d&&this.O&&c){e=a.Ic(this.O,c);d=!!e}if(this.Ja!==e){this.Ja=d;if(e!==null){b.setAttribute("ng-error",e);a.cc(this)}k(b).toggleClass("ng-validation-error",d)}}};oa.prototype={e:function(a){var b=this.view;b=b.checked?b.value:"";if(this.d===b)return false;else{a.m(this.exp,b); -this.d=b;return true}},c:function(a){var b=this.view,c=a.eval(this.exp);if(typeof c==="undefined"){c=this.p;a.m(this.exp,c)}b.checked=b.value==""+c}};pa.prototype={e:function(a){if(this.view.selectedIndex<0)a.m(this.exp,null);else{var b=this.view.value;if(this.d===b)return false;else{a.m(this.exp,b);this.d=b;return true}}},c:function(a){var b=this.view,c=a.get(this.exp);if(typeof c==="undefined"){c=this.p;a.m(this.exp,c)}if(c!==this.d){b.value=c?c:"";this.d=c}}};qa.prototype={selected:function(){for(var a= -[],b=this.view.options,c=0;cd;--b){var o=this.children.pop().element[0];o.parentNode.removeChild(o)}if(h&&h.element[0].nodeName==="OPTION")if(d=k(h.element[0].parentNode).data("controller")){d.d= -undefined;d.c(a)}})}};B.ua="mouseleave mouseout click dblclick keypress keyup";B.rc=function(){B.ma();var a=k(this);a.bind(B.ua,B.ma);var b=a.position(),c=y.documentElement,d=(self.innerWidth||c&&c.clientWidth||y.body.clientWidth)-b.left;c=a.hasClass("ng-exception")?"EXCEPTION:":"Validation error...";a=a.attr("ng-error");d=d>375?"left":"right";c=k("
"+c+"
"+a+"
");k("body").append(c); -if(d==="left")a=b.left+this.offsetWidth+11;else{a=b.left-315;c.find(".ng-arrow-right").css({left:301})}c.css({left:a+"px",top:b.top-3+"px"});return true};B.ma=function(){k("#ng-callout").unbind(B.ua,B.ma).remove();return true};B.prototype={bind:function(){this.B.find(".ng-validation-error,.ng-exception").live("mouseover",B.rc)}};U.hb='
loading....
';U.prototype={vb:function(){this.ba===0&&this.Ma.show();this.ba++},Lb:function(){this.ba--;this.ba=== -0&&this.Ma.hide("fold")}}})(window,document); +a;this.R(b||{});this.Q=a.title;this.hb()}function F(a,b){this.text=a;this.Jb=b?20:-1;this.h=[];this.index=0}function D(a,b){this.text=a;this.h=(new F(a,b)).parse();this.index=0}function v(a,b){this.eb=[];this.qa={};this.name=b;a=a||{};function c(){}c.prototype=a;this.q=new c;this.q.Uc=a;if(b=="ROOT")this.q.Vc=this.q}function ka(a,b){this.url=a;this.fc=0;this.getScript=b;this.Jc="_"+(""+Math.random()).substr(2)+"_";this.ka=1800}function aa(a){this.frame=a}function la(a,b,c){this.Lb=a;this.update=c; +this.status=b}function ma(a,b){this.H=a;this.ea=b}function na(a,b){this.gc=0;this.ca=a;this.F=b;this.Aa=o.Jd?swfobject.Aa:function(){alert("ERROR: swfobject not loaded!")};this.rc=J()}function M(a,b,c,d){this.view=a;this.Md=c;this.Za=b;this.$c=d+"/_attachments";this.value=null;this.d=undefined}function Q(a){this.view=a}function oa(a,b){this.view=a;this.exp=b;this.O=a.getAttribute("ng-validate");this.zc=typeof a.attributes["ng-required"]!="undefined";this.Ka=null;this.d=undefined;this.p=a.value;a.getAttribute("ng-widget")=== +"datepicker"&&k(a).sd()}function pa(a,b){this.view=a;this.exp=b;this.d=undefined;this.p=a.checked?a.value:""}function qa(a,b){this.view=a;this.exp=b;this.d=undefined;this.p=a.value}function ra(a,b){this.view=a;this.exp=b;this.d=undefined;this.p=this.selected()}function sa(a,b){this.view=a;this.exp=b;this.d=this.ia=undefined;this.Ja=a.value;this.p=a.checked?a.value:null}function N(a,b){this.view=a;this.exp=x.Z(b);this.w=false;this.Bc={element:a}}function ta(a,b){this.view=a;this.vb=b}function ua(a, +b){this.view=a;this.exp=b;this.w=false}function va(a,b){this.view=a;this.exp=b}function wa(a,b){this.view=a;this.exp=b}function xa(a,b){this.view=a;this.exp=b}function ya(a,b){this.view=a;this.exp=b}function za(a,b){this.view=a;this.exp=b}function Aa(a,b){this.view=a;this.exp=b}function Ba(a,b,c,d){this.view=a;this.template=c;this.prefix=d;this.children=[];a=b.match(/^\s*(.+)\s+in\s+(.*)\s*$/);if(!a)throw"Expected ng-repeat in form of 'item in collection' but got '"+b+"'.";b=a[1];this.X=a[2];a=b.match(/^([\$\w]+)|\(([\$\w]+)\s*,\s*([\$\w]+)\)$/); +if(!a)throw"'item' in 'item in collection' should be identifier or (key, value) but get '"+b+"'.";this.Lc=a[3]||a[1];this.$b=a[2]}function B(a){this.B=a}function U(a){this.Oa=a.append(U.jb).find("#ng-loading");this.ba=0}var ba={u:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",Mb:function(a){var b="",c,d,e,f,g,h,i=0;for(a=ba.qb(a);i>2;c=(c&3)<<4|d>>4;g=(d&15)<<2|e>>6;h=e&63;if(isNaN(d))g=h=64;else if(isNaN(e))h= +64;b=b+this.u.charAt(f)+this.u.charAt(c)+this.u.charAt(g)+this.u.charAt(h)}return b},td:function(a){var b="",c,d,e,f,g,h=0;for(a=a.replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4;d=(d&15)<<4|f>>2;e=(f&3)<<6|g;b+=String.fromCharCode(c);if(f!=64)b+=String.fromCharCode(d);if(g!=64)b+=String.fromCharCode(e)}return b=ba.pb(b)},qb:function(a){a=a.replace(/\r\n/g,"\n"); +for(var b="",c=0;c127&&d<2048)b+=String.fromCharCode(d>>6|192);else{b+=String.fromCharCode(d>>12|224);b+=String.fromCharCode(d>>6&63|128)}b+=String.fromCharCode(d&63|128)}}return b},pb:function(a){for(var b="",c=0,d=c1=c2=0;c191&&d<224){c2=a.charCodeAt(c+1);b+=String.fromCharCode((d&31)<<6|c2&63);c+=2}else{c2=a.charCodeAt(c+1);c3=a.charCodeAt(c+ +2);b+=String.fromCharCode((d&15)<<12|(c2&63)<<6|c3&63);c+=3}}return b}};if(typeof y.getAttribute=="undefined")y.getAttribute=J();if(typeof Node=="undefined")Node={ELEMENT_NODE:1,ATTRIBUTE_NODE:2,TEXT_NODE:3,CDATA_SECTION_NODE:4,ENTITY_REFERENCE_NODE:5,ENTITY_NODE:6,PROCESSING_INSTRUCTION_NODE:7,COMMENT_NODE:8,DOCUMENT_NODE:9,DOCUMENT_TYPE_NODE:10,DOCUMENT_FRAGMENT_NODE:11,NOTATION_NODE:12};o.console||(o.console={log:n,error:n});var R,p=_.each,S=_.extend,k=o.jQuery,X=k.browser.msie,m=o.angular||(o.angular= +{}),Ca=m.validator||(m.validator={}),r=m.filter||(m.filter={}),ca=m.callbacks||(m.callbacks={});m.alert||(m.alert=function(){w(arguments);o.alert.apply(o,arguments)});ia.prototype={load:function(){this.Eb();w("Server: "+this.j.H);this.Db();this.Cb();this.yb()},Db:function(){w("Angular.configureJQueryPlugins()");k.fn.scope=function(){for(var a=this;a&&a.get(0);){var b=a.data("scope");if(b)return b;a=a.parent()}return null};k.fn.controller=function(){return this.data("controller")||Q.Wb}},Gc:function(){return""+ +(new Date).getTime()},Cb:function(){var a=this.j;if(!a.F){var b=a.H.match(/https?:\/\/([\w]*)/);a.F=b?b[1]:"$MEMORY"}},yb:function(){function a(){g.Qb(function(l){!l&&c.find("[ng-auth=eager]").length&&g.ja()})}w("Angular.bindHtml()");var b=this.Nc=new ja(this.location),c=this.document,d=new na(this.j.H,this.j.F),e=new x(c[0],d,b,this.j);d.rc=Ea(e,e.e);b=new P(c.find("body"),this.j.H);var f=this.j.F=="$MEMORY"?new aa(this.window):new ka(this.j.H,k.getScript);f=new la(f,new U(k(c.body)),function(){e.c()}); +var g=new ma(f,b),h="/data/"+this.j.F,i=new T(function(l,q){f.N("POST",h,l,q)},g,e.anchor);e.bb.push(function(){i.Fa()});var j=new v({$anchor:e.anchor,$binder:e,$config:this.j,$console:o.console,$datastore:i,$save:function(l){i.Ac(j.q,l,e.anchor)},$window:o,$uid:this.Gc,$users:g},"ROOT");c.data("scope",j);w("$binder.entity()");e.K(j);w("$binder.compile()");e.compile();w("ControlBar.bind()");b.bind();w("$users.fetchCurrentUser()");a();w("PopUp.bind()");(new B(c)).bind();w("$binder.parseAnchor()"); +e.Ua();c.find("body").show();w("ready()")},Eb:function(){var a=o.location.href+"#";a=a.split("#")[1];var b={Kb:null};a=a.split("&");for(var c=0;c=0&&a.splice(c,1);return b},find:function(a,b,c){if(b){var d=m.Function.compile(b);_.detect(a,function(e){if(d(e)){c=e;return true}});return c}},findById:function(a,b){return m.Wc.find(a,function(c){return c.z==b},null)},filter:function(a, +b){var c=[];c.zb=function(j){for(var l=0;l-1;case "object":for(var q in j)if(q.charAt(0)!=="$"&&e(j[q],l))return true;return false;case "array":for(q=0;q=0&&a.splice(d,1);a.unshift((c?"-":"+")+b);return a},orderByDirection:function(a,b,c,d){c=c||"ng-ascend";d=d||"ng-descend";a=a[0]||"";var e=true;if(a.charAt(0)=="-"){a=a.substring(1); +e=false}else if(a.charAt(0)=="+")a=a.substring(1);return a==b?e?c:d:""},merge:function(a,b,c){var d=a[b];if(!d){d={};a[b]=d}Z(c,d);return a}},Ga={quote:function(a){return'"'+a.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/\t/g,"\\t").replace(/\v/g,"\\v")+'"'},quoteUnicode:function(a){a=m.String.quote(a);for(var b=[],c=0;c-1;){c1||x.J(a[0])!==null};x.J=function(a){return(a=a.replace(/\n/gm," ").match(/^\{\{(.*)\}\}$/))? +a[1]:null};x.prototype={uc:function(a){var b={};a.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(c,d,e){if(d)b[decodeURIComponent(d)]=decodeURIComponent(e)});return b},Ua:function(a){var b=this;a=a||this.pa.Ha();var c=a.indexOf("#");if(!(c<0)){a=this.uc(a.substring(c+1));p(b.anchor,function(d,e){delete b.anchor[e]});p(a,function(d,e){b.anchor[e]=d})}},tc:function(a){this.Ua(a);this.c()},Hc:function(){var a=this.pa.Ha(),b=a.indexOf("#");if(b>-1)a=a.substring(0,b);a+="#";b="";for(var c in this.anchor){var d= +this.anchor[c];if(typeof d==="undefined"||d===null)delete this.anchor[c];else{a+=b+encodeURIComponent(c);if(d!==true)a+="="+encodeURIComponent(d);b="&"}}this.pa.Dc(a);return a},c:function(){(new Date).getTime();var a=k(this.B).scope();a.i("$invalidWidgets",[]);a.c();(new Date).getTime();this.Hc();_.each(this.bb,function(b){b()})},ga:function(a){var b=k(this.B),c=b.find(a);if(b.is(a))c=c.andSelf();return c},K:function(a){this.ga("[ng-entity]").attr("ng-watch",function(){try{var b=k(this);return a.K(b.attr("ng-entity"))+ +(b.attr("ng-watch")||"")}catch(c){alert(c)}})},compile:function(){var a=k(this.B),b=this;if(this.j.ad){var c=this.ga(":submit").not("[ng-action]");c.attr("ng-action","$save()");c.not(":disabled").not("ng-bind-attr").attr("ng-bind-attr",'{disabled:"{{$invalidWidgets}}"}')}this.Va(this.B)(this.B,a.scope(),"");this.ga("a[ng-action]").live("click",function(){var d=k(this);try{d.scope().eval(d.attr("ng-action"));d.removeAttr("ng-error");d.removeClass("ng-exception")}catch(e){d.addClass("ng-exception"); +d.attr("ng-error",z(e,true))}b.c();return false})},Fc:function(a,b,c){b=b.concat();var d=b.pop(),e=x.Z(a.nodeValue);if(e.length>1||x.J(e[0])){var f=a.parentNode;if(ea(f)){f.setAttribute("ng-bind-template",a.nodeValue);c.push({path:b,b:function(l){return new N(l,l.getAttribute("ng-bind-template"))}})}else for(var g=0;g2&&a.setAttribute("ng-bind-attr",d)}a.getAttribute||w(a);var j=a.getAttribute("ng-repeat");if(j){a.removeAttribute("ng-repeat");var l=this.Va(a);d=y.createComment("ng-repeat: "+j);e=a.parentNode;e.insertBefore(d,a);e.removeChild(a);function q(s,t,A){var I= +k(a).clone();I.css("display","");I.attr("ng-repeat-index",""+A);I.data("scope",s);l(I[0],s,t+A+":");return I}c.push({path:b,b:function(s,t,A){return new Ba(k(s),j,q,A)}})}else{a.getAttribute("ng-eval")&&c.push({path:b,b:this.lc});a.getAttribute("ng-bind")&&c.push({path:b,b:this.Sa});a.getAttribute("ng-bind-attr")&&c.push({path:b,b:this.hc});a.getAttribute("ng-hide")&&c.push({path:b,b:this.mc});a.getAttribute("ng-show")&&c.push({path:b,b:this.nc});a.getAttribute("ng-class")&&c.push({path:b,b:this.ic}); +a.getAttribute("ng-class-odd")&&c.push({path:b,b:this.kc});a.getAttribute("ng-class-even")&&c.push({path:b,b:this.jc});a.getAttribute("ng-style")&&c.push({path:b,b:this.oc});a.getAttribute("ng-watch")&&c.push({path:b,b:this.pc});d=a.nodeName;if(d=="INPUT"||d=="TEXTAREA"||d=="SELECT"||d=="BUTTON"){var C=this;c.push({path:b,b:function(s,t,A){s.name=A+s.name.split(":").pop();return C.Oc.Fb(k(s),t)}})}if(d=="OPTION")if(!k("')};M.prototype={e:function(a){var b=this.view.find("input").attr("checked")?this.value:null;if(this.d===b)return false;else{a.i(this.Za,b);return true}},c:function(a){if((a=a.get(this.Za))&&this.value!==a){this.value=a;this.view.find("a").attr("href",this.value.url).text(this.value.text); +this.view.find("span").text(m.filter.bytes(this.value.size))}this.view.find("input").attr("checked",!!a)}};Q.prototype={e:K(true),c:n};Q.Wb=new Q;var Ja=Q;oa.prototype={e:function(a){var b=this.view.value;if(this.d===b)return false;else{a.m(this.exp,b);this.d=b;return true}},c:function(a){var b=this.view,c=a.get(this.exp);if(typeof c==="undefined"){c=this.p;a.m(this.exp,c)}c=c?c:"";if(this.d!=c)this.d=b.value=c;var d=false;b.removeAttribute("ng-error");if(this.zc)d=!(c&&c.length>0);var e=d?"Required Value": +null;if(!d&&this.O&&c){e=a.Kc(this.O,c);d=!!e}if(this.Ka!==e){this.Ka=d;if(e!==null){b.setAttribute("ng-error",e);a.dc(this)}k(b).toggleClass("ng-validation-error",d)}}};pa.prototype={e:function(a){var b=this.view;b=b.checked?b.value:"";if(this.d===b)return false;else{a.m(this.exp,b);this.d=b;return true}},c:function(a){var b=this.view,c=a.eval(this.exp);if(typeof c==="undefined"){c=this.p;a.m(this.exp,c)}b.checked=b.value==""+c}};qa.prototype={e:function(a){if(this.view.selectedIndex<0)a.m(this.exp, +null);else{var b=this.view.value;if(this.d===b)return false;else{a.m(this.exp,b);this.d=b;return true}}},c:function(a){var b=this.view,c=a.get(this.exp);if(typeof c==="undefined"){c=this.p;a.m(this.exp,c)}if(c!==this.d){b.value=c?c:"";this.d=c}}};ra.prototype={selected:function(){for(var a=[],b=this.view.options,c=0;cd;--b){var q=this.children.pop().element[0];q.parentNode.removeChild(q)}if(h&&h.element[0].nodeName==="OPTION")if(d=k(h.element[0].parentNode).data("controller")){d.d=undefined;d.c(a)}})}};B.va="mouseleave mouseout click dblclick keypress keyup";B.sc=function(){B.ma();var a=k(this);a.bind(B.va,B.ma);var b=a.position(),c=y.documentElement,d=(self.innerWidth||c&&c.clientWidth|| +y.body.clientWidth)-b.left;c=a.hasClass("ng-exception")?"EXCEPTION:":"Validation error...";a=a.attr("ng-error");d=d>375?"left":"right";c=k("
"+c+"
"+a+"
");k("body").append(c);if(d==="left")a=b.left+this.offsetWidth+11;else{a=b.left-315;c.find(".ng-arrow-right").css({left:301})}c.css({left:a+"px",top:b.top-3+"px"});return true};B.ma=function(){k("#ng-callout").unbind(B.va, +B.ma).remove();return true};B.prototype={bind:function(){this.B.find(".ng-validation-error,.ng-exception").live("mouseover",B.sc)}};U.jb='
loading....
';U.prototype={xb:function(){this.ba===0&&this.Oa.show();this.ba++},Nb:function(){this.ba--;this.ba===0&&this.Oa.hide("fold")}}})(window,document); diff --git a/angular.js b/angular.js index e3f24ecb..dee0b57e 100644 --- a/angular.js +++ b/angular.js @@ -342,17 +342,17 @@ function merge(src, dst) { } // //////////////////////////// -// Loader +// Angular // //////////////////////////// -function Loader(document, head, config) { +function Angular(document, head, config) { this.document = jQuery(document); this.head = jQuery(head); this.config = config; this.location = window.location; } -Loader.prototype = { +Angular.prototype = { load: function() { this.configureLogging(); log("Server: " + this.config.server); @@ -362,7 +362,7 @@ Loader.prototype = { }, configureJQueryPlugins: function() { - log('Loader.configureJQueryPlugins()'); + log('Angular.configureJQueryPlugins()'); jQuery['fn']['scope'] = function() { var element = this; while (element && element.get(0)) { @@ -391,8 +391,8 @@ Loader.prototype = { }, bindHtml: function() { - log('Loader.bindHtml()'); - var watcher = new UrlWatcher(this.location); + log('Angular.bindHtml()'); + var watcher = this.watcher = new UrlWatcher(this.location); var document = this.document; var widgetFactory = new WidgetFactory(this.config.server, this.config.database); var binder = new Binder(document[0], widgetFactory, watcher, this.config); @@ -450,12 +450,6 @@ Loader.prototype = { log('$binder.parseAnchor()'); binder.parseAnchor(); - log('$binder.updateView()'); - binder.updateView(); - - //watcher.listener = bind(binder, binder.onUrlChange, watcher); - //watcher.onUpdate = function(){alert("update");}; - //watcher.watch(); document.find("body").show(); log('ready()'); }, @@ -498,16 +492,6 @@ Loader.prototype = { consoleLog('ng-console-error', arguments); }; } - }, - - loadCss: function(css) { - var cssTag = document.createElement('link'); - cssTag.rel = "stylesheet"; - cssTag.type = "text/css"; - if (!css.match(/^http:/)) - css = this.config.server + css; - cssTag.href = css; - this.head[0].appendChild(cssTag); } }; @@ -553,12 +537,12 @@ UrlWatcher.prototype = { }, setUrl: function(url) { -// var existingURL = window.location.href; -// if (!existingURL.match(/#/)) -// existingURL += '#'; -// if (existingURL != url) -// window.location.href = url; -// this.existingURL = url; + var existingURL = window.location.href; + if (!existingURL.match(/#/)) + existingURL += '#'; + if (existingURL != url) + window.location.href = url; + this.existingURL = url; }, getUrl: function() { @@ -573,18 +557,25 @@ angular['compile'] = function(root, config) { 'addUrlChangeListener': noop }; //todo: don't start watcher - var loader = new Loader(root, jQuery("head"), _(defaults).extend(config)); + var angular = new Angular(root, jQuery("head"), _(defaults).extend(config)); //todo: don't load stylesheet by default // loader.loadCss('/stylesheets/jquery-ui/smoothness/jquery-ui-1.7.1.css'); // loader.loadCss('/stylesheets/css'); - loader.load(); + angular.load(); var scope = jQuery(root).scope(); //TODO: cleanup return { 'updateView':function(){return scope.updateView();}, 'set':function(){return scope.set.apply(scope, arguments);}, 'get':function(){return scope.get.apply(scope, arguments);}, - 'init':function(){scope.get('$binder.executeInit')(); scope.updateView();} + 'init':function(){scope.get('$binder.executeInit')(); scope.updateView();}, + 'watchUrl':function(){ + var binder = scope.get('$binder'); + var watcher = angular.watcher; + watcher.listener = bind(binder, binder.onUrlChange, watcher); + watcher.onUpdate = function(){alert("update");}; + watcher.watch(); + } }; };var angularGlobal = { 'typeOf':function(obj){ @@ -977,7 +968,6 @@ Binder.prototype = { }, onUrlChange: function (url) { - log("URL change detected", url); this.parseAnchor(url); this.updateView(); }, @@ -1959,6 +1949,23 @@ foreach({ 'html': function(html){ return new angularFilter.Meta({html:html}); + }, + + 'linky': function(text){ + function regExpEscape(text) { + return text.replace(/([\/\.\*\+\?\|\(\)\[\]\{\}\\])/g, '\\$1'); + } + var URL = /(ftp|http|https):\/\/([^\(\)|\s]+)/gm; + var html = text; + var dups = {}; + foreach(text.match(URL)||[], function(url){ + url = url.replace(/\.$/, ''); + if (!dups[url]) { + html = html.replace(new RegExp(regExpEscape(url), 'gm'), ''+url+''); + dups[url] = true; + } + }); + return new angularFilter.Meta({text:text, html:html}); } }, function(v,k){angularFilter[k] = v;}); diff --git a/example/business_card.html b/example/business_card.html deleted file mode 100644 index cc45529f..00000000 --- a/example/business_card.html +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - - - - - -
- Fetch tweets for: - - -
-
Loading...
-
    -
  • [{{tweet.user.screen_name}}]: {{tweet.text}}
  • -
- - diff --git a/example/tweeter/style.css b/example/tweeter/style.css new file mode 100644 index 00000000..769a6f45 --- /dev/null +++ b/example/tweeter/style.css @@ -0,0 +1,87 @@ +.loading {display: none;} +.fetching .loading {display: block;} + +a { + color: blue; +} + +h1 { + background-color: black; + margin: 0; + padding: .25em; + color: white; + border-bottom: 5px solid gray; +} + +.box { + border: 2px solid gray; +} + +.tweeter { + margin-right: 360px; +} + +ul { + list-style: none; + margin: 0; + padding: 0; +} + +li { + margin: .25em; + padding: 2px; +} + +li img { + float: left; + margin: 2px; + margin-right: .5em; + max-height: 48px; + min-height: 48px; +} + +li.even { + background-color: lightgray; +} + + +.addressbook { + float: right; + width: 350px; +} + +.clrleft { + clear: left; +} + +.notes { + font-size: .8em; + color: gray; +} + +.username, .nickname { + font-weight: bold; +} + +.editor { + padding: 4px; +} + +label { + color: gray; + display: inline-block; + width: 75px; + text-align: right; + padding: 2px; + margin-top: 10px; +} + +.editor input[type=text], +.editor textarea { + width: 230px; + vertical-align: text-top; +} + +.editor TEXTAREA { + height: 50px; +} \ No newline at end of file diff --git a/example/tweeter/tweeter_addressbook.html b/example/tweeter/tweeter_addressbook.html new file mode 100644 index 00000000..d8b8b893 --- /dev/null +++ b/example/tweeter/tweeter_addressbook.html @@ -0,0 +1,64 @@ + + + + + + + + + + + +
+

Address Book

+ [ Filter: ] + +
+
+
+ + + + + + + + + + +
+
+
+
+

Tweets: {{$anchor.user}}

+ [ Filter: + | << All + ] +
Loading...
+ +
+ + diff --git a/example/tweeter/tweeterclient.js b/example/tweeter/tweeterclient.js new file mode 100644 index 00000000..27ec3348 --- /dev/null +++ b/example/tweeter/tweeterclient.js @@ -0,0 +1,35 @@ +function noop(){} +$(document).ready(function(){ + var scope = window.scope = angular.compile(document); + scope.getJSON = function(url, callback) { + var list = []; + var self = this; + self.set('status', 'fetching'); + $.getJSON(url, function(response){ + _(response).forEach(function(v,k){ + list[k] = v; + }); + (callback||noop)(response); + self.set('status', ''); + self.updateView(); + }); + return list; + }; + + function fetchTweets(username){ + return scope.getJSON( + username ? + "http://twitter.com/statuses/user_timeline/"+username+".json" : + "http://twitter.com/statuses/home_timeline.json"); + } + + scope.set('fetchTweets', fetchTweets); + scope.set('users', [ + {screen_name:'mhevery', name:'Mi\u0161ko Hevery', notes:'Author of .', + profile_image_url:'http://a3.twimg.com/profile_images/54360179/Me_-_Small_Banner_normal.jpg'}, + {screen_name:'abrons', name:'Adam Abrons', notes:'Author of & Ruby guru.', + profile_image_url:'http://a1.twimg.com/profile_images/533646480/PIC00024_normal.jpg'} + ]); + scope.watchUrl(); + scope.init(); +}); diff --git a/src/Angular.js b/src/Angular.js index 69cab0a2..3dc72ff7 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -227,7 +227,7 @@ Angular.prototype = { bindHtml: function() { log('Angular.bindHtml()'); - var watcher = new UrlWatcher(this.location); + var watcher = this.watcher = new UrlWatcher(this.location); var document = this.document; var widgetFactory = new WidgetFactory(this.config.server, this.config.database); var binder = new Binder(document[0], widgetFactory, watcher, this.config); @@ -285,12 +285,6 @@ Angular.prototype = { log('$binder.parseAnchor()'); binder.parseAnchor(); - log('$binder.updateView()'); - binder.updateView(); - - //watcher.listener = bind(binder, binder.onUrlChange, watcher); - //watcher.onUpdate = function(){alert("update");}; - //watcher.watch(); document.find("body").show(); log('ready()'); }, @@ -378,12 +372,13 @@ UrlWatcher.prototype = { }, setUrl: function(url) { -// var existingURL = window.location.href; -// if (!existingURL.match(/#/)) -// existingURL += '#'; -// if (existingURL != url) -// window.location.href = url; -// this.existingURL = url; + //TODO: conditionaly? + var existingURL = window.location.href; + if (!existingURL.match(/#/)) + existingURL += '#'; + if (existingURL != url) + window.location.href = url; + this.existingURL = url; }, getUrl: function() { @@ -409,6 +404,13 @@ angular['compile'] = function(root, config) { 'updateView':function(){return scope.updateView();}, 'set':function(){return scope.set.apply(scope, arguments);}, 'get':function(){return scope.get.apply(scope, arguments);}, - 'init':function(){scope.get('$binder.executeInit')(); scope.updateView();} + 'init':function(){scope.get('$binder.executeInit')(); scope.updateView();}, + 'watchUrl':function(){ + var binder = scope.get('$binder'); + var watcher = angular.watcher; + watcher.listener = bind(binder, binder.onUrlChange, watcher); + watcher.onUpdate = function(){alert("update");}; + watcher.watch(); + } }; }; \ No newline at end of file diff --git a/src/Binder.js b/src/Binder.js index 36cb6ec3..b29a07c6 100644 --- a/src/Binder.js +++ b/src/Binder.js @@ -66,7 +66,6 @@ Binder.prototype = { }, onUrlChange: function (url) { - log("URL change detected", url); this.parseAnchor(url); this.updateView(); }, diff --git a/src/Filters.js b/src/Filters.js index 666c9f30..833d5630 100644 --- a/src/Filters.js +++ b/src/Filters.js @@ -293,6 +293,23 @@ foreach({ 'html': function(html){ return new angularFilter.Meta({html:html}); + }, + + 'linky': function(text){ + function regExpEscape(text) { + return text.replace(/([\/\.\*\+\?\|\(\)\[\]\{\}\\])/g, '\\$1'); + } + var URL = /(ftp|http|https):\/\/([^\(\)|\s]+)/gm; + var html = text; + var dups = {}; + foreach(text.match(URL)||[], function(url){ + url = url.replace(/\.$/, ''); + if (!dups[url]) { + html = html.replace(new RegExp(regExpEscape(url), 'gm'), ''+url+''); + dups[url] = true; + } + }); + return new angularFilter.Meta({text:text, html:html}); } }, function(v,k){angularFilter[k] = v;}); diff --git a/test.sh b/test.sh index 8993c3ff..32e8b4b7 100755 --- a/test.sh +++ b/test.sh @@ -1 +1,2 @@ -java -jar lib/jstestdriver/JsTestDriver.jar --tests all +java -jar lib/jstestdriver/JsTestDriver.jar --tests all 2>/dev/null | grep -v lib/jasmine + diff --git a/test/FiltersTest.js b/test/FiltersTest.js index c219f24f..fee59bac 100644 --- a/test/FiltersTest.js +++ b/test/FiltersTest.js @@ -151,3 +151,12 @@ FiltersTest.prototype.testHtml = function() { angular.filter.html("acd").html); assertTrue(angular.filter.html("acd") instanceof angular.filter.Meta); }; + +FiltersTest.prototype.testLinky = function() { + assertEquals( + 'a (http://a) http://a \n http://1.2/v:~-123. c', + angular.filter.linky("a (http://a) http://a \n http://1.2/v:~-123. c").html); + assertTrue(angular.filter.linky("a") instanceof angular.filter.Meta); +}; + + -- cgit v1.2.3 From 910ddbe34eb6268e9049ca91211d43663d629879 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 18 Jan 2010 17:58:43 -0800 Subject: update image for adam --- example/tweeter/tweeterclient.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/tweeter/tweeterclient.js b/example/tweeter/tweeterclient.js index 27ec3348..f5f2d731 100644 --- a/example/tweeter/tweeterclient.js +++ b/example/tweeter/tweeterclient.js @@ -28,7 +28,7 @@ $(document).ready(function(){ {screen_name:'mhevery', name:'Mi\u0161ko Hevery', notes:'Author of .', profile_image_url:'http://a3.twimg.com/profile_images/54360179/Me_-_Small_Banner_normal.jpg'}, {screen_name:'abrons', name:'Adam Abrons', notes:'Author of & Ruby guru.', - profile_image_url:'http://a1.twimg.com/profile_images/533646480/PIC00024_normal.jpg'} + profile_image_url:'http://media.linkedin.com/mpr/mpr/shrink_80_80/p/2/000/005/0a8/044278d.jpg'} ]); scope.watchUrl(); scope.init(); -- cgit v1.2.3 From db2031c5a1df205e6db40ca6aba80930375069c0 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Tue, 19 Jan 2010 17:53:20 -0800 Subject: added debug info; fix parser bug with double negation --- example/tweeter/style.css | 7 +++++++ example/tweeter/tweeter_addressbook.html | 12 ++++++++++++ src/Parser.js | 28 +++++++++++++--------------- test/ParserTest.js | 8 ++++++++ 4 files changed, 40 insertions(+), 15 deletions(-) diff --git a/example/tweeter/style.css b/example/tweeter/style.css index 769a6f45..0f2aaecd 100644 --- a/example/tweeter/style.css +++ b/example/tweeter/style.css @@ -84,4 +84,11 @@ label { .editor TEXTAREA { height: 50px; +} + +.debug{ + font-size: .7em; + white-space: pre; + padding: 0; + margin: 0; } \ No newline at end of file diff --git a/example/tweeter/tweeter_addressbook.html b/example/tweeter/tweeter_addressbook.html index d8b8b893..70068b0a 100644 --- a/example/tweeter/tweeter_addressbook.html +++ b/example/tweeter/tweeter_addressbook.html @@ -39,6 +39,18 @@
+
+
+userFilter={{userFilter|json}} + +tweetFilter={{tweetFilter|json}} + +$anchor={{$anchor}} + +users={{users}} + +tweets={{tweets}} +

Tweets: {{$anchor.user}}

diff --git a/src/Parser.js b/src/Parser.js index 333b8413..840f5541 100644 --- a/src/Parser.js +++ b/src/Parser.js @@ -294,15 +294,13 @@ Parser.prototype = { } }, - _unary: function(fn, parse) { - var right = parse.apply(this); + _unary: function(fn, right) { return function(self) { return fn(self, right(self)); }; }, - _binary: function(left, fn, parse) { - var right = parse.apply(this); + _binary: function(left, fn, right) { return function(self) { return fn(self, left(self), right(self)); }; @@ -343,7 +341,7 @@ Parser.prototype = { var token; while(true) { if ((token = this.expect('|'))) { - left = this._binary(left, token.fn, this.filter); + left = this._binary(left, token.fn, this.filter()); } else { return left; } @@ -405,7 +403,7 @@ Parser.prototype = { this.text.substring(token.index) + "' is not assignable."; } var ident = function(){return left.isAssignable;}; - return this._binary(ident, token.fn, this.logicalOR); + return this._binary(ident, token.fn, this.logicalOR()); } else { return left; } @@ -416,7 +414,7 @@ Parser.prototype = { var token; while(true) { if ((token = this.expect('||'))) { - left = this._binary(left, token.fn, this.logicalAND); + left = this._binary(left, token.fn, this.logicalAND()); } else { return left; } @@ -428,7 +426,7 @@ Parser.prototype = { var token; while(true) { if ((token = this.expect('&&'))) { - left = this._binary(left, token.fn, this.negated); + left = this._binary(left, token.fn, this.negated()); } else { return left; } @@ -438,9 +436,9 @@ Parser.prototype = { negated: function(){ var token; if (token = this.expect('!')) { - return this._unary(token.fn, this.equality); + return this._unary(token.fn, this.assignment()); } else { - return this.equality(); + return this.equality(); } }, @@ -449,7 +447,7 @@ Parser.prototype = { var token; while(true) { if ((token = this.expect('==','!='))) { - left = this._binary(left, token.fn, this.relational); + left = this._binary(left, token.fn, this.relational()); } else { return left; } @@ -461,7 +459,7 @@ Parser.prototype = { var token; while(true) { if ((token = this.expect('<', '>', '<=', '>='))) { - left = this._binary(left, token.fn, this.additive); + left = this._binary(left, token.fn, this.additive()); } else { return left; } @@ -472,7 +470,7 @@ Parser.prototype = { var left = this.multiplicative(); var token; while(token = this.expect('+','-')) { - left = this._binary(left, token.fn, this.multiplicative); + left = this._binary(left, token.fn, this.multiplicative()); } return left; }, @@ -481,7 +479,7 @@ Parser.prototype = { var left = this.unary(); var token; while(token = this.expect('*','/','%')) { - left = this._binary(left, token.fn, this.unary); + left = this._binary(left, token.fn, this.unary()); } return left; }, @@ -491,7 +489,7 @@ Parser.prototype = { if (this.expect('+')) { return this.primary(); } else if (token = this.expect('-')) { - return this._binary(Parser.ZERO, token.fn, this.multiplicative); + return this._binary(Parser.ZERO, token.fn, this.multiplicative()); } else { return this.primary(); } diff --git a/test/ParserTest.js b/test/ParserTest.js index 058010f3..fbd9f508 100644 --- a/test/ParserTest.js +++ b/test/ParserTest.js @@ -460,3 +460,11 @@ ParserTest.prototype.testReturnFunctionsAreNotBound = function(){ assertEquals("direct Group.all", "function", typeof Group.query); }; +ParserTest.prototype.testDoubleNegationBug = function (){ + var scope = new Scope(); + assertEquals(true, scope.eval('true')); + assertEquals(false, scope.eval('!true')); + assertEquals(true, scope.eval('!!true')); + assertEquals('a', scope.eval('{true:"a", false:"b"}[!!true]')); +}; + -- cgit v1.2.3 From dc0db57b36bb6cd47dfea835a315f61b34ed8e1b Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 20 Jan 2010 06:52:50 -0800 Subject: tweek tweeter --- angular-minified.js | 170 +++++++++++++++---------------- angular.js | 56 +++++----- example/tweeter/tweeter_addressbook.html | 4 +- example/tweeter/tweeterclient.js | 4 +- src/Filters.js | 27 +++-- test/FiltersTest.js | 11 +- 6 files changed, 143 insertions(+), 129 deletions(-) diff --git a/angular-minified.js b/angular-minified.js index f590b704..ccceb4ec 100644 --- a/angular-minified.js +++ b/angular-minified.js @@ -1,99 +1,99 @@ -function J(){return function(){}}function K(o){return function(){return o}} +function K(){return function(){}}function L(o){return function(){return o}} (function(o,y){function n(){}function w(a,b,c){var d=o.console;switch(arguments.length){case 1:d.log(a);break;case 2:d.log(a,b);break;default:d.log(a,b,c);break}}function W(a,b,c){var d=o.console;switch(arguments.length){case 1:d.error(a);break;case 2:d.error(a,b);break;default:d.error(a,b,c);break}}function da(a,b){var c=y.createElement("div");c.className=a;for(var d=a="",e=0;e/g,">")}function Da(a){if(!a||!a.replace)return a;return a.replace(//g,">").replace(/\"/g,""")}function ga(a,b){if(!a)throw"Missing this";if(!_.isFunction(b))throw"Missing function";return function(){return b.apply(a,arguments)}}function Ea(a,b){return function(){for(var c= +default:return false}}function fa(a,b){if(ea(a))if(X)a.innerText=b;else a.textContent=b;else a.innerHTML=b}function D(a){if(!a||!a.replace)return a;return a.replace(/&/g,"&").replace(//g,">")}function Da(a){if(!a||!a.replace)return a;return a.replace(//g,">").replace(/\"/g,""")}function ga(a,b){if(!a)throw"Missing this";if(!_.isFunction(b))throw"Missing function";return function(){return b.apply(a,arguments)}}function Ea(a,b){return function(){for(var c= [this],d=0;d>2;c=(c&3)<<4|d>>4;g=(d&15)<<2|e>>6;h=e&63;if(isNaN(d))g=h=64;else if(isNaN(e))h= -64;b=b+this.u.charAt(f)+this.u.charAt(c)+this.u.charAt(g)+this.u.charAt(h)}return b},td:function(a){var b="",c,d,e,f,g,h=0;for(a=a.replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4;d=(d&15)<<4|f>>2;e=(f&3)<<6|g;b+=String.fromCharCode(c);if(f!=64)b+=String.fromCharCode(d);if(g!=64)b+=String.fromCharCode(e)}return b=ba.pb(b)},qb:function(a){a=a.replace(/\r\n/g,"\n"); -for(var b="",c=0;c127&&d<2048)b+=String.fromCharCode(d>>6|192);else{b+=String.fromCharCode(d>>12|224);b+=String.fromCharCode(d>>6&63|128)}b+=String.fromCharCode(d&63|128)}}return b},pb:function(a){for(var b="",c=0,d=c1=c2=0;c191&&d<224){c2=a.charCodeAt(c+1);b+=String.fromCharCode((d&31)<<6|c2&63);c+=2}else{c2=a.charCodeAt(c+1);c3=a.charCodeAt(c+ -2);b+=String.fromCharCode((d&15)<<12|(c2&63)<<6|c3&63);c+=3}}return b}};if(typeof y.getAttribute=="undefined")y.getAttribute=J();if(typeof Node=="undefined")Node={ELEMENT_NODE:1,ATTRIBUTE_NODE:2,TEXT_NODE:3,CDATA_SECTION_NODE:4,ENTITY_REFERENCE_NODE:5,ENTITY_NODE:6,PROCESSING_INSTRUCTION_NODE:7,COMMENT_NODE:8,DOCUMENT_NODE:9,DOCUMENT_TYPE_NODE:10,DOCUMENT_FRAGMENT_NODE:11,NOTATION_NODE:12};o.console||(o.console={log:n,error:n});var R,p=_.each,S=_.extend,k=o.jQuery,X=k.browser.msie,m=o.angular||(o.angular= -{}),Ca=m.validator||(m.validator={}),r=m.filter||(m.filter={}),ca=m.callbacks||(m.callbacks={});m.alert||(m.alert=function(){w(arguments);o.alert.apply(o,arguments)});ia.prototype={load:function(){this.Eb();w("Server: "+this.j.H);this.Db();this.Cb();this.yb()},Db:function(){w("Angular.configureJQueryPlugins()");k.fn.scope=function(){for(var a=this;a&&a.get(0);){var b=a.data("scope");if(b)return b;a=a.parent()}return null};k.fn.controller=function(){return this.data("controller")||Q.Wb}},Gc:function(){return""+ -(new Date).getTime()},Cb:function(){var a=this.j;if(!a.F){var b=a.H.match(/https?:\/\/([\w]*)/);a.F=b?b[1]:"$MEMORY"}},yb:function(){function a(){g.Qb(function(l){!l&&c.find("[ng-auth=eager]").length&&g.ja()})}w("Angular.bindHtml()");var b=this.Nc=new ja(this.location),c=this.document,d=new na(this.j.H,this.j.F),e=new x(c[0],d,b,this.j);d.rc=Ea(e,e.e);b=new P(c.find("body"),this.j.H);var f=this.j.F=="$MEMORY"?new aa(this.window):new ka(this.j.H,k.getScript);f=new la(f,new U(k(c.body)),function(){e.c()}); -var g=new ma(f,b),h="/data/"+this.j.F,i=new T(function(l,q){f.N("POST",h,l,q)},g,e.anchor);e.bb.push(function(){i.Fa()});var j=new v({$anchor:e.anchor,$binder:e,$config:this.j,$console:o.console,$datastore:i,$save:function(l){i.Ac(j.q,l,e.anchor)},$window:o,$uid:this.Gc,$users:g},"ROOT");c.data("scope",j);w("$binder.entity()");e.K(j);w("$binder.compile()");e.compile();w("ControlBar.bind()");b.bind();w("$users.fetchCurrentUser()");a();w("PopUp.bind()");(new B(c)).bind();w("$binder.parseAnchor()"); -e.Ua();c.find("body").show();w("ready()")},Eb:function(){var a=o.location.href+"#";a=a.split("#")[1];var b={Kb:null};a=a.split("&");for(var c=0;c>2;c=(c&3)<<4|d>>4;g=(d&15)<<2|e>>6;h=e&63;if(isNaN(d))g=h=64;else if(isNaN(e))h= +64;b=b+this.u.charAt(f)+this.u.charAt(c)+this.u.charAt(g)+this.u.charAt(h)}return b},td:function(a){var b="",c,d,e,f,g,h=0;for(a=a.replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4;d=(d&15)<<4|f>>2;e=(f&3)<<6|g;b+=String.fromCharCode(c);if(f!=64)b+=String.fromCharCode(d);if(g!=64)b+=String.fromCharCode(e)}return b=ba.ob(b)},pb:function(a){a=a.replace(/\r\n/g,"\n"); +for(var b="",c=0;c127&&d<2048)b+=String.fromCharCode(d>>6|192);else{b+=String.fromCharCode(d>>12|224);b+=String.fromCharCode(d>>6&63|128)}b+=String.fromCharCode(d&63|128)}}return b},ob:function(a){for(var b="",c=0,d=c1=c2=0;c191&&d<224){c2=a.charCodeAt(c+1);b+=String.fromCharCode((d&31)<<6|c2&63);c+=2}else{c2=a.charCodeAt(c+1);c3=a.charCodeAt(c+ +2);b+=String.fromCharCode((d&15)<<12|(c2&63)<<6|c3&63);c+=3}}return b}};if(typeof y.getAttribute=="undefined")y.getAttribute=K();if(typeof Node=="undefined")Node={ELEMENT_NODE:1,ATTRIBUTE_NODE:2,TEXT_NODE:3,CDATA_SECTION_NODE:4,ENTITY_REFERENCE_NODE:5,ENTITY_NODE:6,PROCESSING_INSTRUCTION_NODE:7,COMMENT_NODE:8,DOCUMENT_NODE:9,DOCUMENT_TYPE_NODE:10,DOCUMENT_FRAGMENT_NODE:11,NOTATION_NODE:12};o.console||(o.console={log:n,error:n});var R,q=_.each,S=_.extend,k=o.jQuery,X=k.browser.msie,m=o.angular||(o.angular= +{}),Ca=m.validator||(m.validator={}),r=m.filter||(m.filter={}),ca=m.callbacks||(m.callbacks={});m.alert||(m.alert=function(){w(arguments);o.alert.apply(o,arguments)});ia.prototype={load:function(){this.Db();w("Server: "+this.j.H);this.Cb();this.Bb();this.xb()},Cb:function(){w("Angular.configureJQueryPlugins()");k.fn.scope=function(){for(var a=this;a&&a.get(0);){var b=a.data("scope");if(b)return b;a=a.parent()}return null};k.fn.controller=function(){return this.data("controller")||Q.Wb}},Gc:function(){return""+ +(new Date).getTime()},Bb:function(){var a=this.j;if(!a.F){var b=a.H.match(/https?:\/\/([\w]*)/);a.F=b?b[1]:"$MEMORY"}},xb:function(){function a(){g.Qb(function(l){!l&&c.find("[ng-auth=eager]").length&&g.ka()})}w("Angular.bindHtml()");var b=this.Nc=new ja(this.location),c=this.document,d=new na(this.j.H,this.j.F),e=new x(c[0],d,b,this.j);d.rc=Ea(e,e.e);b=new P(c.find("body"),this.j.H);var f=this.j.F=="$MEMORY"?new aa(this.window):new ka(this.j.H,k.getScript);f=new la(f,new U(k(c.body)),function(){e.c()}); +var g=new ma(f,b),h="/data/"+this.j.F,i=new T(function(l,p){f.N("POST",h,l,p)},g,e.anchor);e.ab.push(function(){i.Ea()});var j=new v({$anchor:e.anchor,$binder:e,$config:this.j,$console:o.console,$datastore:i,$save:function(l){i.Ac(j.q,l,e.anchor)},$window:o,$uid:this.Gc,$users:g},"ROOT");c.data("scope",j);w("$binder.entity()");e.K(j);w("$binder.compile()");e.compile();w("ControlBar.bind()");b.bind();w("$users.fetchCurrentUser()");a();w("PopUp.bind()");(new B(c)).bind();w("$binder.parseAnchor()"); +e.Ta();c.find("body").show();w("ready()")},Db:function(){var a=o.location.href+"#";a=a.split("#")[1];var b={Jb:null};a=a.split("&");for(var c=0;c=0&&a.splice(c,1);return b},find:function(a,b,c){if(b){var d=m.Function.compile(b);_.detect(a,function(e){if(d(e)){c=e;return true}});return c}},findById:function(a,b){return m.Wc.find(a,function(c){return c.z==b},null)},filter:function(a, -b){var c=[];c.zb=function(j){for(var l=0;l-1;case "object":for(var q in j)if(q.charAt(0)!=="$"&&e(j[q],l))return true;return false;case "array":for(q=0;q-1;case "object":for(var p in j)if(p.charAt(0)!=="$"&&e(j[p],l))return true;return false;case "array":for(p=0;p=0&&a.splice(d,1);a.unshift((c?"-":"+")+b);return a},orderByDirection:function(a,b,c,d){c=c||"ng-ascend";d=d||"ng-descend";a=a[0]||"";var e=true;if(a.charAt(0)=="-"){a=a.substring(1); e=false}else if(a.charAt(0)=="+")a=a.substring(1);return a==b?e?c:d:""},merge:function(a,b,c){var d=a[b];if(!d){d={};a[b]=d}Z(c,d);return a}},Ga={quote:function(a){return'"'+a.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/\t/g,"\\t").replace(/\v/g,"\\v")+'"'},quoteUnicode:function(a){a=m.String.quote(a);for(var b=[],c=0;c-1;){c1||x.J(a[0])!==null};x.J=function(a){return(a=a.replace(/\n/gm," ").match(/^\{\{(.*)\}\}$/))? -a[1]:null};x.prototype={uc:function(a){var b={};a.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(c,d,e){if(d)b[decodeURIComponent(d)]=decodeURIComponent(e)});return b},Ua:function(a){var b=this;a=a||this.pa.Ha();var c=a.indexOf("#");if(!(c<0)){a=this.uc(a.substring(c+1));p(b.anchor,function(d,e){delete b.anchor[e]});p(a,function(d,e){b.anchor[e]=d})}},tc:function(a){this.Ua(a);this.c()},Hc:function(){var a=this.pa.Ha(),b=a.indexOf("#");if(b>-1)a=a.substring(0,b);a+="#";b="";for(var c in this.anchor){var d= -this.anchor[c];if(typeof d==="undefined"||d===null)delete this.anchor[c];else{a+=b+encodeURIComponent(c);if(d!==true)a+="="+encodeURIComponent(d);b="&"}}this.pa.Dc(a);return a},c:function(){(new Date).getTime();var a=k(this.B).scope();a.i("$invalidWidgets",[]);a.c();(new Date).getTime();this.Hc();_.each(this.bb,function(b){b()})},ga:function(a){var b=k(this.B),c=b.find(a);if(b.is(a))c=c.andSelf();return c},K:function(a){this.ga("[ng-entity]").attr("ng-watch",function(){try{var b=k(this);return a.K(b.attr("ng-entity"))+ -(b.attr("ng-watch")||"")}catch(c){alert(c)}})},compile:function(){var a=k(this.B),b=this;if(this.j.ad){var c=this.ga(":submit").not("[ng-action]");c.attr("ng-action","$save()");c.not(":disabled").not("ng-bind-attr").attr("ng-bind-attr",'{disabled:"{{$invalidWidgets}}"}')}this.Va(this.B)(this.B,a.scope(),"");this.ga("a[ng-action]").live("click",function(){var d=k(this);try{d.scope().eval(d.attr("ng-action"));d.removeAttr("ng-error");d.removeClass("ng-exception")}catch(e){d.addClass("ng-exception"); -d.attr("ng-error",z(e,true))}b.c();return false})},Fc:function(a,b,c){b=b.concat();var d=b.pop(),e=x.Z(a.nodeValue);if(e.length>1||x.J(e[0])){var f=a.parentNode;if(ea(f)){f.setAttribute("ng-bind-template",a.nodeValue);c.push({path:b,b:function(l){return new N(l,l.getAttribute("ng-bind-template"))}})}else for(var g=0;g2&&a.setAttribute("ng-bind-attr",d)}a.getAttribute||w(a);var j=a.getAttribute("ng-repeat");if(j){a.removeAttribute("ng-repeat");var l=this.Va(a);d=y.createComment("ng-repeat: "+j);e=a.parentNode;e.insertBefore(d,a);e.removeChild(a);function q(s,t,A){var I= -k(a).clone();I.css("display","");I.attr("ng-repeat-index",""+A);I.data("scope",s);l(I[0],s,t+A+":");return I}c.push({path:b,b:function(s,t,A){return new Ba(k(s),j,q,A)}})}else{a.getAttribute("ng-eval")&&c.push({path:b,b:this.lc});a.getAttribute("ng-bind")&&c.push({path:b,b:this.Sa});a.getAttribute("ng-bind-attr")&&c.push({path:b,b:this.hc});a.getAttribute("ng-hide")&&c.push({path:b,b:this.mc});a.getAttribute("ng-show")&&c.push({path:b,b:this.nc});a.getAttribute("ng-class")&&c.push({path:b,b:this.ic}); -a.getAttribute("ng-class-odd")&&c.push({path:b,b:this.kc});a.getAttribute("ng-class-even")&&c.push({path:b,b:this.jc});a.getAttribute("ng-style")&&c.push({path:b,b:this.oc});a.getAttribute("ng-watch")&&c.push({path:b,b:this.pc});d=a.nodeName;if(d=="INPUT"||d=="TEXTAREA"||d=="SELECT"||d=="BUTTON"){var C=this;c.push({path:b,b:function(s,t,A){s.name=A+s.name.split(":").pop();return C.Oc.Fb(k(s),t)}})}if(d=="OPTION")if(!k("").append(k(a).clone()).html().match(/.*<\/\s*option\s*>/gi))a.value= +a.text;d=a.childNodes;for(e=0;e