From 9b9a0dadcce82ae42ac09ad396d647739af20a06 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Sat, 9 Jan 2010 15:02:43 -0800 Subject: removed nglr namespace --- Rakefile | 35 +- TODO.text | 2 +- angular-minified.js | 122 ++ angular.js | 4732 +++++++++++++++++++++++++++++++++++++++-- jsTestDriver.conf | 3 + lib/shrinksafe/js.jar | Bin 756883 -> 0 bytes lib/shrinksafe/shrinksafe.jar | Bin 17685 -> 0 bytes src/API.js | 8 +- src/Binder.js | 106 +- src/ControlBar.js | 22 +- src/DataStore.js | 72 +- src/Filters.js | 8 +- src/JSON.js | 20 +- src/Loader.js | 145 +- src/Model.js | 26 +- src/Parser.js | 116 +- src/Scope.js | 62 +- src/Server.js | 32 +- src/Users.js | 8 +- src/Validators.js | 2 +- src/Widgets.js | 244 +-- src/Widgets.js.orig | 764 ------- src/XSitePost.js | 100 - src/angular-bootstrap.js | 3 +- src/angular.prefix | 2 + src/angular.suffix | 1 + src/test/Runner.js | 26 +- src/test/Steps.js | 2 +- test/BinderTest.js | 209 +- test/ConsoleTest.js | 9 +- test/DataStoreTest.js | 96 +- test/EntityDeclarationTest.js | 8 +- test/FileControllerTest.js | 24 +- test/FiltersTest.js | 16 +- test/JsonTest.js | 54 +- test/LoaderTest.js | 18 +- test/ModelTest.js | 12 +- test/ParserTest.js | 108 +- test/ScopeTest.js | 32 +- test/ServerTest.js | 10 +- test/UsersTest.js | 4 +- test/WidgetsTest.js | 95 +- test/XSitePostTest.js | 47 - test/formsTest.js | 4 +- test/testabilityPatch.js | 16 +- 45 files changed, 5514 insertions(+), 1911 deletions(-) create mode 100644 angular-minified.js delete mode 100644 lib/shrinksafe/js.jar delete mode 100644 lib/shrinksafe/shrinksafe.jar delete mode 100644 src/Widgets.js.orig delete mode 100644 src/XSitePost.js create mode 100644 src/angular.prefix create mode 100644 src/angular.suffix delete mode 100644 test/XSitePostTest.js diff --git a/Rakefile b/Rakefile index 56482e39..a4823809 100644 --- a/Rakefile +++ b/Rakefile @@ -2,9 +2,11 @@ include FileUtils desc 'Compile JavaScript' task :compile do - compiled = %x(java -jar lib/shrinksafe/shrinksafe.jar \ - lib/webtoolkit/webtoolkit.base64.js \ + concat = %x(cat \ lib/underscore/underscore.js \ + src/angular.prefix \ + lib/webtoolkit/webtoolkit.base64.js \ + lib/swfobject.js/swfobject.js \ src/Loader.js \ src/API.js \ src/Binder.js \ @@ -19,35 +21,16 @@ task :compile do src/Users.js \ src/Validators.js \ src/Widgets.js \ - src/angular-bootstrap.js \ + src/angular.suffix \ ) f = File.new("angular.js", 'w') - f.write(compiled) + f.write(concat) f.close -end -desc 'Compile JavaScript with Google Closure Compiler' -task :compileclosure do -# --compilation_level ADVANCED_OPTIMIZATIONS \ %x(java -jar lib/compiler-closure/compiler.jar \ - --js lib/webtoolkit/webtoolkit.base64.js \ - --js lib/underscore/underscore.js \ - --js src/Loader.js \ - --js src/API.js \ - --js src/Binder.js \ - --js src/ControlBar.js \ - --js src/DataStore.js \ - --js src/Filters.js \ - --js src/JSON.js \ - --js src/Model.js \ - --js src/Parser.js \ - --js src/Scope.js \ - --js src/Server.js \ - --js src/Users.js \ - --js src/Validators.js \ - --js src/Widgets.js \ - --js src/angular-bootstrap.js \ - --js_output_file angular.js) + --compilation_level ADVANCED_OPTIMIZATIONS \ + --js angular.js \ + --js_output_file angular-minified.js) end namespace :server do diff --git a/TODO.text b/TODO.text index fab19695..d4d013a5 100644 --- a/TODO.text +++ b/TODO.text @@ -3,4 +3,4 @@ - angular.defaults = {} - var scope = angular.compile(element, options); * angular.js is not self boot straping by default. -* +* Remove SWFObject diff --git a/angular-minified.js b/angular-minified.js new file mode 100644 index 00000000..a9faa563 --- /dev/null +++ b/angular-minified.js @@ -0,0 +1,122 @@ +function u(){return function(s){return s}}function x(){return function(){}}function y(s){return function(v){this[s]=v}}function z(s){return function(){return s}} +(function(){var s=this,v=s.Ma;function w(f){this.$=f}var a=typeof StopIteration!=="undefined"?StopIteration:"__break__",b=s.Ma=function(f){return new w(f)};if(typeof exports!=="undefined")exports.Ma=b;var c=Array.prototype.slice,d=Array.prototype.unshift,e=Object.prototype.toString,g=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable;b.Ce="0.5.1";b.b=function(f,h,j){try{if(f.forEach)f.forEach(h,j);else if(b.q(f)||b.Lb(f))for(var k=0,m=f.length;k=k.ca&&(k={value:m,ca:q})});return k.value};b.min=function(f,h,j){if(!h&&b.q(f))return Math.min.apply(Math,f);var k={ca:Infinity};b.b(f,function(m,q,t){q=h?h.call(j,m,q,t):m;qm?1:0}),"value")};b.Sf=function(f,h,j){j=j||b.ga;for(var k=0,m=f.length;k>1;j(f[q])=0})})};b.gg=function(){for(var f=b.A(arguments),h=b.max(b.bb(f,"length")),j=new Array(h),k=0;k0?m-h:h-m)>=0)return k;k[q++]=m}};b.B=function(f,h){var j=b.L(arguments,2);return function(){return f.apply(h||s,j.concat(b.A(arguments)))}};b.Ne=function(f){var h= +b.L(arguments);if(h.length==0)h=b.Ua(f);b.b(h,function(j){f[j]=b.B(f[j],f)});return f};b.Ta=function(f,h){var j=b.L(arguments,2);return setTimeout(function(){return f.apply(f,j)},h)};b.defer=function(f){return b.Ta.apply(b,[f,1].concat(b.L(arguments)))};b.fg=function(f,h){return function(){var j=[f].concat(b.A(arguments));return h.apply(h,j)}};b.Ze=function(){var f=b.A(arguments);return function(){for(var h=b.A(arguments),j=f.length-1;j>=0;j--)h=[f[j].apply(this,h)];return h[0]}};b.ia=function(f){if(b.q(f))return b.Rd(0, +f.length);var h=[];for(var j in f)g.call(f,j)&&h.push(j);return h};b.gb=function(f){return b.map(f,b.ga)};b.Ua=function(f){return b.select(b.ia(f),function(h){return b.K(f[h])}).sort()};b.extend=function(f,h){for(var j in h)f[j]=h[j];return f};b.ua=function(f){if(b.q(f))return f.slice(0);return b.extend({},f)};b.isEqual=function(f,h){if(f===h)return true;var j=typeof f;if(j!=typeof h)return false;if(f==h)return true;if(!f&&h||f&&!h)return false;if(f.isEqual)return f.isEqual(h);if(b.pd(f)&&b.pd(h))return f.getTime()=== +h.getTime();if(b.Mb(f)&&b.Mb(h))return true;if(b.rd(f)&&b.rd(h))return f.source===h.source&&f.global===h.global&&f.ignoreCase===h.ignoreCase&&f.multiline===h.multiline;if(j!=="object")return false;if(f.length&&f.length!==h.length)return false;j=b.ia(f);var k=b.ia(h);if(j.length!=k.length)return false;for(var m in f)if(!b.isEqual(f[m],h[m]))return false;return true};b.tf=function(f){return b.ia(f).length==0};b.sf=function(f){return!!(f&&f.nodeType==1)};b.Lb=function(f){return f&&b.ha(f.length)&&!b.q(f)&& +!i.call(f,"length")};b.Mb=function(f){return b.ha(f)&&isNaN(f)};b.uf=function(f){return f===null};b.H=function(f){return typeof f=="undefined"};for(var l=["Array","Date","Function","Number","RegExp","String"],n=0,o=l.length;n)[^\t]*)'/g,"$1\r").replace(/\t=(.*?)%>/g,"',$1,'").split("\t").join("');").split("%>").join("p.push('").split("\r").join("\\'")+"');}return p.join('');");return h?f(h):f};b.forEach=b.b;b.kf=b.of=b.reduce;b.lf=b.reduceRight;b.filter=b.select;b.every=b.all;b.some=b.Hc;b.Ib=b.gd;b.Wf=b.L;b.Af=b.Ua;function r(f,h){return h?b(f).rb():f}b.b(b.Ua(b),function(f){var h=b[f];w.prototype[f]=function(){d.call(arguments,this.$);return r(h.apply(b, +arguments),this.Na)}});b.b(["pop","push","reverse","shift","sort","splice","unshift"],function(f){var h=Array.prototype[f];w.prototype[f]=function(){h.apply(this.$,arguments);return r(this.$,this.Na)}});b.b(["concat","join","slice"],function(f){var h=Array.prototype[f];w.prototype[f]=function(){return r(h.apply(this.$,arguments),this.Na)}});w.prototype.rb=function(){this.Na=true;return this};w.prototype.value=function(){return this.$}})(); +(function(s,v){var w={I:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",wa:function(a){var b="",c,d,e,g,i,l,n=0;for(a=w.Cc(a);n>2;c=(c&3)<<4|d>>4;i=(d&15)<<2|e>>6;l=e&63;if(isNaN(d))i=l=64;else if(isNaN(e))l=64;b=b+this.I.charAt(g)+this.I.charAt(c)+this.I.charAt(i)+this.I.charAt(l)}return b},ef:function(a){var b="",c,d,e,g,i,l=0;for(a=a.replace(/[^A-Za-z0-9\+\/\=]/g,"");l>4;d=(d&15)<<4|g>>2;e=(g&3)<<6|i;b+=String.fromCharCode(c);if(g!=64)b+=String.fromCharCode(d);if(i!=64)b+=String.fromCharCode(e)}return b=w.Bc(b)},Cc: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},Bc: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 v.getAttribute=="undefined")v.getAttribute=x();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(_.H(s.Cf))nglr={};if(_.H(s.Fe))angular={};if(_.H(angular.j))angular.j={};if(_.H(angular.filter))angular.filter={};if(_.H(s.console))s.console={log:x(),error:x()};if(_.H(alert))alert=function(){console.log(arguments);s.alert.apply(s,arguments)};consoleLog=function(a,b){var c=v.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(!_.K(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.X.compile(b); +_.xb(a,function(e){if(d(e)){c=e;return true}});return c}},gf:function(a,b){return angular.Ka.find(a,function(c){return c.N==b},null)},filter:function(a,b){var c=[];c.Nc=function(o){for(var p=0;p-1;case "object":for(var r in o)if(r.charAt(0)!=="$"&&e(o[r],p))return true;return false; +case "array":for(r=0;r=0&&a.splice(d,1);a.unshift((c?"-":"+")+b);return a}, +Gf: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:""},zf:function(a,b,c){var d=a[b];if(!d){d={};a[b]=d}merge(c,d);return a}};angular.O={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")+'"'},cc:function(a){a=angular.O.quote(a);for(var b=[], +c=0;c-1;){c1||Binder.ba(a[0])!==null};Binder.ba=function(a){return(a=a.replace(/\n/gm," ").match(/^\{\{(.*)\}\}$/))?a[1]:null};Binder.prototype.Qd=function(a){var b={};a.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(c,d,e){if(d)b[decodeURIComponent(d)]=decodeURIComponent(e)});return b};Binder.prototype.Zb=function(a){var b= +this;a=a||this.fb.Gb();var c=a.indexOf("#");if(!(c<0)){a=this.Qd(a.substring(c+1));jQuery.b(b.anchor,function(d){delete b.anchor[d]});jQuery.b(a,function(d,e){b.anchor[d]=e})}};Binder.prototype.Pd=function(a){console.log("URL change detected",a);this.Zb(a);this.d()};Binder.prototype.ge=function(){var a=this.fb.Gb(),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.fb.Zd(a);return a};Binder.prototype.d=function(){(new Date).getTime();var a=jQuery(this.Q).scope();a.s("$invalidWidgets",[]);a.d();(new Date).getTime();this.ge();_.b(this.lc,function(b){b()})};Binder.prototype.va=function(a){var b=jQuery(this.Q),c=b.find(a);if(b.od(a))c=c.Ee();return c};Binder.prototype.dd=function(){this.va("[ng-init]").b(function(){var a=jQuery(this),b=a.scope();try{b.eval(a.g("ng-init"))}catch(c){alert("EVAL ERROR:\n"+a.g("ng-init")+ +"\n"+toJson(c,true))}})};Binder.prototype.da=function(a){this.va("[ng-entity]").g("ng-watch",function(){try{var b=jQuery(this);return a.da(b.g("ng-entity"))+(b.g("ng-watch")||"")}catch(c){alert(c)}})};Binder.prototype.compile=function(){var a=jQuery(this.Q),b=this;if(this.o.He){var c=this.va(":submit").Yb("[ng-action]");c.g("ng-action","$save()");c.Yb(":disabled").Yb("ng-bind-attr").g("ng-bind-attr",'{disabled:"{{$invalidWidgets}}"}')}this.ac(this.Q)(this.Q,a.scope(),"");this.va("a[ng-action]").xd("click", +function(){var d=jQuery(this);try{d.scope().eval(d.g("ng-action"));d.fc("ng-error");d.gc("ng-exception")}catch(e){d.Oa("ng-exception");d.g("ng-error",toJson(e,true))}b.d();return false})};Binder.prototype.ce=function(a,b,c){b=b.concat();var d=b.pop(),e=Binder.Ea(a.nodeValue);if(e.length>1||Binder.ba(e[0])){var g=a.parentNode;if(isLeafNode(g)){g.setAttribute("ng-bind-template",a.nodeValue);c.push({path:b,c:function(p){return new BindUpdater(p,p.getAttribute("ng-bind-template"))}})}else for(var i=0;i< +e.length;i++){var l=e[i],n=Binder.ba(l),o;if(n){o=v.createElement("span");jQuery(o).g("ng-bind",n);i===0&&c.push({path:b.concat(d+i),c:Binder.prototype.Xb})}else if(msie&&l.charAt(0)==" "){o=v.createElement("span");o.innerHTML=" "+l.substring(1)}else o=v.createTextNode(l);g.insertBefore(o,a)}g.removeChild(a)}};Binder.prototype.ac=function(a){var b=[];this.bc(a,[],b);return function(c,d,e){for(var g=b.length,i=0;i +2&&a.setAttribute("ng-bind-attr",d)}a.getAttribute||console.log(a);var o=a.getAttribute("ng-repeat");if(o){a.removeAttribute("ng-repeat");var p=this.ac(a);d=v.createComment("ng-repeat: "+o);e=a.parentNode;e.insertBefore(d,a);e.removeChild(a);var r=function(h,j,k){var m=jQuery(a).ua();m.Sa("display","");m.g("ng-repeat-index",""+k);m.data("scope",h);p(m[0],h,j+k+":");return m};c.push({path:b,c:function(h,j,k){return new RepeaterUpdater(jQuery(h),o,r,k)}})}else{a.getAttribute("ng-eval")&&c.push({path:b, +c:this.Hd});a.getAttribute("ng-bind")&&c.push({path:b,c:this.Xb});a.getAttribute("ng-bind-attr")&&c.push({path:b,c:this.Dd});a.getAttribute("ng-hide")&&c.push({path:b,c:this.Id});a.getAttribute("ng-show")&&c.push({path:b,c:this.Jd});a.getAttribute("ng-class")&&c.push({path:b,c:this.Ed});a.getAttribute("ng-class-odd")&&c.push({path:b,c:this.Gd});a.getAttribute("ng-class-even")&&c.push({path:b,c:this.Fd});a.getAttribute("ng-style")&&c.push({path:b,c:this.Kd});a.getAttribute("ng-watch")&&c.push({path:b, +c:this.Ld});d=a.nodeName;if(d=="INPUT"||d=="TEXTAREA"||d=="SELECT"||d=="BUTTON"){var f=this;c.push({path:b,c:function(h,j,k){h.name=k+h.name.split(":").pop();return f.me.Sc(jQuery(h),j)}})}if(d=="OPTION")if(!jQuery("')};FileController.prototype.i=function(a){var b=this.view.find("input").g("checked")?this.value:null;if(this.e===b)return false;else{a.s(this.hc,b);return true}};FileController.prototype.d=function(a){if((a=a.h(this.hc))&&this.value!==a){this.value=a;this.view.find("a").g("href", +this.value.url).text(this.value.text);this.view.find("span").text(angular.filter.Pa(this.value.size))}this.view.find("input").g("checked",!!a)};NullController=y("view");NullController.prototype.i=z(true);NullController.prototype.d=x();NullController.nd=new NullController;ButtonController=y("view");ButtonController.prototype.i=z(true);ButtonController.prototype.d=x();TextController=function(a,b){this.view=a;this.exp=b;this.j=a.getAttribute("ng-validate");this.Vd=typeof a.attributes["ng-required"]!= +"undefined";this.Nb=null;this.e=undefined;this.D=a.value;a.getAttribute("ng-widget")==="datepicker"&&jQuery(a).df()};TextController.prototype.i=function(a){var b=this.view.value;if(this.e===b)return false;else{a.z(this.exp,b);this.e=b;return true}};TextController.prototype.d=function(a){var b=this.view,c=a.h(this.exp);if(typeof c==="undefined"){c=this.D;a.z(this.exp,c)}c=c?c:"";if(this.e!=c)this.e=b.value=c;var d=false;b.removeAttribute("ng-error");if(this.Vd)d=!(c&&c.length>0);var e=d?"Required Value": +null;if(!d&&this.j&&c){e=a.je(this.j,c);d=!!e}if(this.Nb!==e){this.Nb=d;if(e!==null){b.setAttribute("ng-error",e);a.zd(this)}jQuery(b).eb("ng-validation-error",d)}};CheckboxController=function(a,b){this.view=a;this.exp=b;this.e=undefined;this.D=a.checked?a.value:""};CheckboxController.prototype.i=function(a){var b=this.view;b=b.checked?b.value:"";if(this.e===b)return false;else{a.z(this.exp,b);this.e=b;return true}};CheckboxController.prototype.d=function(a){var b=this.view,c=a.eval(this.exp);if(typeof c=== +"undefined"){c=this.D;a.z(this.exp,c)}b.checked=b.value==""+c};SelectController=function(a,b){this.view=a;this.exp=b;this.e=undefined;this.D=a.value};SelectController.prototype.i=function(a){if(this.view.selectedIndex<0)a.z(this.exp,null);else{var b=this.view.value;if(this.e===b)return false;else{a.z(this.exp,b);this.e=b;return true}}};SelectController.prototype.d=function(a){var b=this.view,c=a.h(this.exp);if(typeof c==="undefined"){c=this.D;a.z(this.exp,c)}if(c!==this.e){b.value=c?c:"";this.e=c}}; +MultiSelectController=function(a,b){this.view=a;this.exp=b;this.e=undefined;this.D=this.selected()};MultiSelectController.prototype.selected=function(){for(var a=[],b=this.view.options,c=0;cd;--b)this.ta.pop().element.removeNode();if(l&& +l.element[0].nodeName==="OPTION")if(d=jQuery(l.element[0].parentNode).data("controller")){d.e=undefined;d.d(a)}})};PopUp=y("Q");PopUp.nb="mouseleave mouseout click dblclick keypress keyup";PopUp.prototype.B=function(){this.Q.find(".ng-validation-error,.ng-exception").xd("mouseover",PopUp.Od)};PopUp.Od=function(){PopUp.ab();var a=jQuery(this);a.B(PopUp.nb,PopUp.ab);var b=a.position(),c=v.documentElement,d=(self.innerWidth||c&&c.clientWidth||v.body.clientWidth)-b.left;c=a.mf("ng-exception")?"EXCEPTION:": +"Validation error...";a=a.g("ng-error");d=d>375?"left":"right";c=jQuery("
"+c+"
"+a+"
");jQuery("body").append(c);if(d==="left")a=b.left+this.offsetWidth+11;else{a=b.left-315;c.find(".ng-arrow-right").Sa({left:301})}c.Sa({left:a+"px",top:b.top-3+"px"});return true};PopUp.ab=function(){jQuery("#ng-callout").Zf(PopUp.nb,PopUp.ab).remove();return true};Status=function(a){this.Sb= +a.append(Status.sc).find("#ng-loading");this.Ha=0};Status.sc='
loading....
';Status.prototype.Lc=function(){this.Ha===0&&this.Sb.cb();this.Ha++};Status.prototype.ad=function(){this.Ha--;this.Ha===0&&this.Sb.Jb("fold")}})(window,document); diff --git a/angular.js b/angular.js index 2ac33572..0e1527f2 100644 --- a/angular.js +++ b/angular.js @@ -1,164 +1,4568 @@ -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); +// Underscore.js +// (c) 2009 Jeremy Ashkenas, DocumentCloud Inc. +// Underscore is freely distributable under the terms of the MIT license. +// Portions of Underscore are inspired by or borrowed from Prototype.js, +// Oliver Steele's Functional, and John Resig's Micro-Templating. +// For all details and documentation: +// http://documentcloud.github.com/underscore/ + +(function() { + + /*------------------------- Baseline setup ---------------------------------*/ + + // Establish the root object, "window" in the browser, or "global" on the server. + var root = this; + + // Save the previous value of the "_" variable. + var previousUnderscore = root._; + + // If Underscore is called as a function, it returns a wrapped object that + // can be used OO-style. This wrapper holds altered versions of all the + // underscore functions. Wrapped objects may be chained. + var wrapper = function(obj) { this._wrapped = obj; }; + + // Establish the object that gets thrown to break out of a loop iteration. + var breaker = typeof StopIteration !== 'undefined' ? StopIteration : '__break__'; + + // Create a safe reference to the Underscore object for reference below. + var _ = root._ = function(obj) { return new wrapper(obj); }; + + // Export the Underscore object for CommonJS. + if (typeof exports !== 'undefined') exports._ = _; + + // Create quick reference variables for speed access to core prototypes. + var slice = Array.prototype.slice, + unshift = Array.prototype.unshift, + toString = Object.prototype.toString, + hasOwnProperty = Object.prototype.hasOwnProperty, + propertyIsEnumerable = Object.prototype.propertyIsEnumerable; + + // Current version. + _.VERSION = '0.5.1'; + + /*------------------------ Collection Functions: ---------------------------*/ + + // The cornerstone, an each implementation. + // Handles objects implementing forEach, arrays, and raw objects. + _.each = function(obj, iterator, context) { + var index = 0; + try { + if (obj.forEach) { + obj.forEach(iterator, context); + } else if (_.isArray(obj) || _.isArguments(obj)) { + for (var i=0, l=obj.length; i= result.computed && (result = {value : value, computed : computed}); + }); + return result.value; + }; + + // Return the minimum element (or element-based computation). + _.min = function(obj, iterator, context) { + if (!iterator && _.isArray(obj)) return Math.min.apply(Math, obj); + var result = {computed : Infinity}; + _.each(obj, function(value, index, list) { + var computed = iterator ? iterator.call(context, value, index, list) : value; + computed < result.computed && (result = {value : value, computed : computed}); + }); + return result.value; + }; + + // Sort the object's values by a criteria produced by an iterator. + _.sortBy = function(obj, iterator, context) { + return _.pluck(_.map(obj, function(value, index, list) { + return { + value : value, + criteria : iterator.call(context, value, index, list) + }; + }).sort(function(left, right) { + var a = left.criteria, b = right.criteria; + return a < b ? -1 : a > b ? 1 : 0; + }), 'value'); + }; + + // Use a comparator function to figure out at what index an object should + // be inserted so as to maintain order. Uses binary search. + _.sortedIndex = function(array, obj, iterator) { + iterator = iterator || _.identity; + var low = 0, high = array.length; + while (low < high) { + var mid = (low + high) >> 1; + iterator(array[mid]) < iterator(obj) ? low = mid + 1 : high = mid; + } + return low; + }; + + // Convert anything iterable into a real, live array. + _.toArray = function(iterable) { + if (!iterable) return []; + if (iterable.toArray) return iterable.toArray(); + if (_.isArray(iterable)) return iterable; + if (_.isArguments(iterable)) return slice.call(iterable); + return _.map(iterable, function(val){ return val; }); + }; + + // Return the number of elements in an object. + _.size = function(obj) { + return _.toArray(obj).length; + }; + + /*-------------------------- Array Functions: ------------------------------*/ + + // Get the first element of an array. Passing "n" will return the first N + // values in the array. Aliased as "head". The "guard" check allows it to work + // with _.map. + _.first = function(array, n, guard) { + return n && !guard ? slice.call(array, 0, n) : array[0]; + }; + + // Returns everything but the first entry of the array. Aliased as "tail". + // Especially useful on the arguments object. Passing an "index" will return + // the rest of the values in the array from that index onward. The "guard" + //check allows it to work with _.map. + _.rest = function(array, index, guard) { + return slice.call(array, _.isUndefined(index) || guard ? 1 : index); + }; + + // Get the last element of an array. + _.last = function(array) { + return array[array.length - 1]; + }; + + // Trim out all falsy values from an array. + _.compact = function(array) { + return _.select(array, function(value){ return !!value; }); + }; + + // Return a completely flattened version of an array. + _.flatten = function(array) { + return _.reduce(array, [], function(memo, value) { + if (_.isArray(value)) return memo.concat(_.flatten(value)); + memo.push(value); + return memo; + }); + }; + + // Return a version of the array that does not contain the specified value(s). + _.without = function(array) { + var values = _.rest(arguments); + return _.select(array, function(value){ return !_.include(values, value); }); + }; + + // Produce a duplicate-free version of the array. If the array has already + // been sorted, you have the option of using a faster algorithm. + _.uniq = function(array, isSorted) { + return _.reduce(array, [], function(memo, el, i) { + if (0 == i || (isSorted === true ? _.last(memo) != el : !_.include(memo, el))) memo.push(el); + return memo; + }); + }; + + // Produce an array that contains every item shared between all the + // passed-in arrays. + _.intersect = function(array) { + var rest = _.rest(arguments); + return _.select(_.uniq(array), function(item) { + return _.all(rest, function(other) { + return _.indexOf(other, item) >= 0; + }); + }); + }; + + // Zip together multiple lists into a single array -- elements that share + // an index go together. + _.zip = function() { + var args = _.toArray(arguments); + var length = _.max(_.pluck(args, 'length')); + var results = new Array(length); + for (var i=0; i 0 ? i - stop : stop - i) >= 0) return range; + range[idx++] = i; + } + }; + + /* ----------------------- Function Functions: -----------------------------*/ + + // Create a function bound to a given object (assigning 'this', and arguments, + // optionally). Binding with arguments is also known as 'curry'. + _.bind = function(func, obj) { + var args = _.rest(arguments, 2); + return function() { + return func.apply(obj || root, args.concat(_.toArray(arguments))); + }; + }; + + // Bind all of an object's methods to that object. Useful for ensuring that + // all callbacks defined on an object belong to it. + _.bindAll = function(obj) { + var funcs = _.rest(arguments); + if (funcs.length == 0) funcs = _.functions(obj); + _.each(funcs, function(f) { obj[f] = _.bind(obj[f], obj); }); + return obj; + }; + + // Delays a function for the given number of milliseconds, and then calls + // it with the arguments supplied. + _.delay = function(func, wait) { + var args = _.rest(arguments, 2); + return setTimeout(function(){ return func.apply(func, args); }, wait); + }; + + // Defers a function, scheduling it to run after the current call stack has + // cleared. + _.defer = function(func) { + return _.delay.apply(_, [func, 1].concat(_.rest(arguments))); + }; + + // Returns the first function passed as an argument to the second, + // allowing you to adjust arguments, run code before and after, and + // conditionally execute the original function. + _.wrap = function(func, wrapper) { + return function() { + var args = [func].concat(_.toArray(arguments)); + return wrapper.apply(wrapper, args); + }; + }; + + // Returns a function that is the composition of a list of functions, each + // consuming the return value of the function that follows. + _.compose = function() { + var funcs = _.toArray(arguments); + return function() { + var args = _.toArray(arguments); + for (var i=funcs.length-1; i >= 0; i--) { + args = [funcs[i].apply(this, args)]; + } + return args[0]; + }; + }; + + /* ------------------------- Object Functions: ---------------------------- */ + + // Retrieve the names of an object's properties. + _.keys = function(obj) { + if(_.isArray(obj)) return _.range(0, obj.length); + var keys = []; + for (var key in obj) if (hasOwnProperty.call(obj, key)) keys.push(key); + return keys; + }; + + // Retrieve the values of an object's properties. + _.values = function(obj) { + return _.map(obj, _.identity); + }; + + // Return a sorted list of the function names available in Underscore. + _.functions = function(obj) { + return _.select(_.keys(obj), function(key){ return _.isFunction(obj[key]); }).sort(); + }; + + // Extend a given object with all of the properties in a source object. + _.extend = function(destination, source) { + for (var property in source) destination[property] = source[property]; + return destination; + }; + + // Create a (shallow-cloned) duplicate of an object. + _.clone = function(obj) { + if (_.isArray(obj)) return obj.slice(0); + return _.extend({}, obj); + }; + + // Perform a deep comparison to check if two objects are equal. + _.isEqual = function(a, b) { + // Check object identity. + if (a === b) return true; + // Different types? + var atype = typeof(a), btype = typeof(b); + if (atype != btype) return false; + // Basic equality test (watch out for coercions). + if (a == b) return true; + // One is falsy and the other truthy. + if ((!a && b) || (a && !b)) return false; + // One of them implements an isEqual()? + if (a.isEqual) return a.isEqual(b); + // Check dates' integer values. + if (_.isDate(a) && _.isDate(b)) return a.getTime() === b.getTime(); + // Both are NaN? + if (_.isNaN(a) && _.isNaN(b)) return true; + // Compare regular expressions. + if (_.isRegExp(a) && _.isRegExp(b)) + return a.source === b.source && + a.global === b.global && + a.ignoreCase === b.ignoreCase && + a.multiline === b.multiline; + // If a is not an object by this point, we can't handle it. + if (atype !== 'object') return false; + // Check for different array lengths before comparing contents. + if (a.length && (a.length !== b.length)) return false; + // Nothing else worked, deep compare the contents. + var aKeys = _.keys(a), bKeys = _.keys(b); + // Different object sizes? + if (aKeys.length != bKeys.length) return false; + // Recursive comparison of contents. + for (var key in a) if (!_.isEqual(a[key], b[key])) return false; + return true; + }; + + // Is a given array or object empty? + _.isEmpty = function(obj) { + return _.keys(obj).length == 0; + }; + + // Is a given value a DOM element? + _.isElement = function(obj) { + return !!(obj && obj.nodeType == 1); + }; + + // Is a given variable an arguments object? + _.isArguments = function(obj) { + return obj && _.isNumber(obj.length) && !_.isArray(obj) && !propertyIsEnumerable.call(obj, 'length'); + }; + + // Is the given value NaN -- this one is interesting. NaN != NaN, and + // isNaN(undefined) == true, so we make sure it's a number first. + _.isNaN = function(obj) { + return _.isNumber(obj) && isNaN(obj); + }; + + // Is a given value equal to null? + _.isNull = function(obj) { + return obj === null; + }; + + // Is a given variable undefined? + _.isUndefined = function(obj) { + return typeof obj == 'undefined'; + }; + + // Define the isArray, isDate, isFunction, isNumber, isRegExp, and isString + // functions based on their toString identifiers. + var types = ['Array', 'Date', 'Function', 'Number', 'RegExp', 'String']; + for (var i=0, l=types.length; i)[^\t]*)'/g, "$1\r") + .replace(/\t=(.*?)%>/g, "',$1,'") + .split("\t").join("');") + .split("%>").join("p.push('") + .split("\r").join("\\'") + + "');}return p.join('');"); + return data ? fn(data) : fn; + }; + + /*------------------------------- Aliases ----------------------------------*/ + + _.forEach = _.each; + _.foldl = _.inject = _.reduce; + _.foldr = _.reduceRight; + _.filter = _.select; + _.every = _.all; + _.some = _.any; + _.head = _.first; + _.tail = _.rest; + _.methods = _.functions; + + /*------------------------ Setup the OOP Wrapper: --------------------------*/ + + // Helper function to continue chaining intermediate results. + var result = function(obj, chain) { + return chain ? _(obj).chain() : obj; + }; + + // Add all of the Underscore functions to the wrapper object. + _.each(_.functions(_), function(name) { + var method = _[name]; + wrapper.prototype[name] = function() { + unshift.call(arguments, this._wrapped); + return result(method.apply(_, arguments), this._chain); + }; + }); + + // Add all mutator Array functions to the wrapper. + _.each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) { + var method = Array.prototype[name]; + wrapper.prototype[name] = function() { + method.apply(this._wrapped, arguments); + return result(this._wrapped, this._chain); + }; + }); + + // Add all accessor Array functions to the wrapper. + _.each(['concat', 'join', 'slice'], function(name) { + var method = Array.prototype[name]; + wrapper.prototype[name] = function() { + return result(method.apply(this._wrapped, arguments), this._chain); + }; + }); + + // Start chaining a wrapped Underscore object. + wrapper.prototype.chain = function() { + this._chain = true; + return this; + }; + + // Extracts the result from a wrapped and chained object. + wrapper.prototype.value = function() { + return this._wrapped; + }; + +})(); + +(function(window, document){/** +* +* Base64 encode / decode +* http://www.webtoolkit.info/ +* +**/ + +var Base64 = { + + // private property + _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=", + + // public method for encoding + encode : function (input) { + var output = ""; + var chr1, chr2, chr3, enc1, enc2, enc3, enc4; + var i = 0; + + input = Base64._utf8_encode(input); + + while (i < input.length) { + + chr1 = input.charCodeAt(i++); + chr2 = input.charCodeAt(i++); + chr3 = input.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if (isNaN(chr2)) { + enc3 = enc4 = 64; + } else if (isNaN(chr3)) { + enc4 = 64; + } + + output = output + + this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) + + this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4); + + } + + return output; + }, + + // public method for decoding + decode : function (input) { + var output = ""; + var chr1, chr2, chr3; + var enc1, enc2, enc3, enc4; + var i = 0; + + input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); + + while (i < input.length) { + + enc1 = this._keyStr.indexOf(input.charAt(i++)); + enc2 = this._keyStr.indexOf(input.charAt(i++)); + enc3 = this._keyStr.indexOf(input.charAt(i++)); + enc4 = this._keyStr.indexOf(input.charAt(i++)); + + chr1 = (enc1 << 2) | (enc2 >> 4); + chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); + chr3 = ((enc3 & 3) << 6) | enc4; + + output = output + String.fromCharCode(chr1); + + if (enc3 != 64) { + output = output + String.fromCharCode(chr2); + } + if (enc4 != 64) { + output = output + String.fromCharCode(chr3); + } + + } + + output = Base64._utf8_decode(output); + + return output; + + }, + + // private method for UTF-8 encoding + _utf8_encode : function (string) { + string = string.replace(/\r\n/g,"\n"); + var utftext = ""; + + for (var n = 0; n < string.length; n++) { + + var c = string.charCodeAt(n); + + if (c < 128) { + utftext += String.fromCharCode(c); + } + else if((c > 127) && (c < 2048)) { + utftext += String.fromCharCode((c >> 6) | 192); + utftext += String.fromCharCode((c & 63) | 128); + } + else { + utftext += String.fromCharCode((c >> 12) | 224); + utftext += String.fromCharCode(((c >> 6) & 63) | 128); + utftext += String.fromCharCode((c & 63) | 128); + } + + } + + return utftext; + }, + + // private method for UTF-8 decoding + _utf8_decode : function (utftext) { + var string = ""; + var i = 0; + var c = c1 = c2 = 0; + + while ( i < utftext.length ) { + + c = utftext.charCodeAt(i); + + if (c < 128) { + string += String.fromCharCode(c); + i++; + } + else if((c > 191) && (c < 224)) { + c2 = utftext.charCodeAt(i+1); + string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); + i += 2; + } + else { + c2 = utftext.charCodeAt(i+1); + c3 = utftext.charCodeAt(i+2); + string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); + i += 3; + } + + } + + return string; + } + +};// Copyright (C) 2008,2009 BRAT Tech LLC + +// IE compatibility + +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(alert)) { + alert = function(){console.log(arguments); window.alert.apply(window, arguments); }; +} + +consoleLog = function(level, objs) { + var log = document.createElement("div"); + log.className = level; + var msg = ""; + var sep = ""; + for ( var i = 0; i < objs.length; i++) { + var obj = objs[i]; + msg += sep + (typeof obj == 'string' ? obj : toJson(obj)); + sep = " "; + } + log.appendChild(document.createTextNode(msg)); + consoleNode.appendChild(log); +}; + +isNode = function(inp) { + return inp && + inp.tagName && + inp.nodeName && + inp.ownerDocument && + inp.removeAttribute; +}; + +isLeafNode = function(node) { + switch (node.nodeName) { + case "OPTION": + case "PRE": + case "TITLE": + return true; + default: + return false; + } +}; + +noop = function() { +}; +setHtml = function(node, html) { + if (isLeafNode(node)) { + if (msie) { + node.innerText = html; + } else { + node.textContent = html; + } + } else { + node.innerHTML = html; + } +}; + +escapeHtml = function(html) { + if (!html || !html.replace) + return html; + return html. + replace(/&/g, '&'). + replace(//g, '>'); +}; + +escapeAttr = function(html) { + if (!html || !html.replace) + return html; + return html.replace(//g, '>').replace(/\"/g, + '"'); +}; + +bind = function(_this, _function) { + if (!_this) + throw "Missing this"; + if (!_.isFunction(_function)) + throw "Missing function"; + return function() { + return _function.apply(_this, arguments); + }; +}; + +shiftBind = function(_this, _function) { + return function() { + var args = [ this ]; + for ( var i = 0; i < arguments.length; i++) { + args.push(arguments[i]); + } + return _function.apply(_this, args); + }; +}; + +outerHTML = function(node) { + var temp = document.createElement('div'); + temp.appendChild(node); + var outerHTML = temp.innerHTML; + temp.removeChild(node); + return outerHTML; +}; + +trim = function(str) { + return str.replace(/^ */, '').replace(/ *$/, ''); +}; + +toBoolean = function(value) { + var v = ("" + value).toLowerCase(); + if (v == 'f' || v == '0' || v == 'false' || v == 'no') + value = false; + return !!value; +}; + +merge = function(src, dst) { + for ( var key in src) { + var value = dst[key]; + var type = typeof value; + if (type == 'undefined') { + dst[key] = fromJson(toJson(src[key])); + } else if (type == 'object' && value.constructor != array && + key.substring(0, 1) != "$") { + merge(src[key], value); + } + } +}; + +// //////////////////////////// +// Loader +// //////////////////////////// + +Loader = function(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); + msie = jQuery.browser.msie; + this.configureJQueryPlugins(); + this.computeConfiguration(); + this.bindHtml(); +}; + +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() { + 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"); + + 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); + + 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)); + } + }; + 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); + }; + console.error = function() { + consoleLog('ng-console-error', arguments); + }; + } +}; + +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) { + this.location = location; + this.delay = 25; + this.setTimeout = function(fn, delay) { + window.setTimeout(fn, delay); + }; + this.listener = function(url) { + return url; + }; + 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 = nglr[id]; + delete nglr[id]; + try { + (notifyFn||noop)(); + } catch (e) { + alert(e); + } + } 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; + self.existingURL = url; +}; + +UrlWatcher.prototype.getUrl = function() { + return window.location.href; +}; + +angular['compile'] = function(root, config) { + config = config || {}; + var defaults = { + server: "" + }; + //todo: don't load stylesheet by default + //todo: don't start watcher + var loader = new Loader(root, jQuery("head"), _(defaults).extend(config)); + loader.load(); + return jQuery(root).scope(); +}; + +angular.Global = { + typeOf:function(obj){ + var type = typeof obj; + switch(type) { + case "object": + if (obj === null) return "null"; + if (obj instanceof Array) return "array"; + if (obj instanceof Date) return "date"; + if (obj.nodeType == 1) return "element"; + } + return type; + } +}; + +angular.Collection = {}; +angular.Object = {}; +angular.Array = { + includeIf:function(array, value, condition) { + var index = _.indexOf(array, value); + if (condition) { + if (index == -1) + array.push(value); + } else { + array.splice(index, 1); + } + return array; + }, + 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]); + if (!isNaN(value)){ + sum += value; + } + } + return sum; + }, + remove:function(array, value) { + var index = _.indexOf(array, value); + if (index >=0) + array.splice(index, 1); + return value; + }, + find:function(array, condition, defaultValue) { + if (!condition) return undefined; + var fn = angular.Function.compile(condition); + _.detect(array, function($){ + if (fn($)){ + defaultValue = $; + return true; + } + }); + return defaultValue; + }, + findById:function(array, id) { + return angular.Array.find(array, function($){return $.$id == id;}, null); + }, + filter:function(array, expression) { + var predicates = []; + predicates.check = function(value) { + for (var j = 0; j < predicates.length; j++) { + if(!predicates[j](value)) { + return false; + } + } + return true; + }; + var getter = Scope.getter; + var search = function(obj, text){ + if (text.charAt(0) === '!') { + return !search(obj, text.substr(1)); + } + switch (typeof obj) { + case "boolean": + case "number": + case "string": + return ('' + obj).toLowerCase().indexOf(text) > -1; + case "object": + for ( var objKey in obj) { + if (objKey.charAt(0) !== '$' && search(obj[objKey], text)) { + return true; + } + } + return false; + case "array": + for ( var i = 0; i < obj.length; i++) { + if (search(obj[i], text)) { + return true; + } + } + return false; + default: + return false; + } + }; + switch (typeof expression) { + case "boolean": + case "number": + case "string": + expression = {$:expression}; + case "object": + for (var key in expression) { + if (key == '$') { + (function(){ + var text = (''+expression[key]).toLowerCase(); + if (!text) return; + predicates.push(function(value) { + return search(value, text); + }); + })(); + } else { + (function(){ + var path = key; + var text = (''+expression[key]).toLowerCase(); + if (!text) return; + predicates.push(function(value) { + return search(getter(value, path), text); + }); + })(); + } + } + break; + case "function": + predicates.push(expression); + break; + default: + return array; + } + var filtered = []; + for ( var j = 0; j < array.length; j++) { + var value = array[j]; + if (predicates.check(value)) { + filtered.push(value); + } + } + return filtered; + }, + add:function(array, value) { + array.push(_.isUndefined(value)? {} : value); + return array; + }, + count:function(array, condition) { + if (!condition) return array.length; + var fn = angular.Function.compile(condition); + return _.reduce(array, 0, function(count, $){return count + (fn($)?1:0);}); + }, + orderBy:function(array, expression, descend) { + function reverse(comp, descending) { + return toBoolean(descending) ? + function(a,b){return comp(b,a);} : comp; + } + function compare(v1, v2){ + var t1 = typeof v1; + var t2 = typeof v2; + if (t1 == t2) { + if (t1 == "string") v1 = v1.toLowerCase(); + if (t1 == "string") v2 = v2.toLowerCase(); + if (v1 === v2) return 0; + return v1 < v2 ? -1 : 1; + } else { + return t1 < t2 ? -1 : 1; + } + } + expression = _.isArray(expression) ? expression: [expression]; + expression = _.map(expression, function($){ + var descending = false; + if (typeof $ == "string" && ($.charAt(0) == '+' || $.charAt(0) == '-')) { + descending = $.charAt(0) == '-'; + $ = $.substring(1); + } + var get = $ ? angular.Function.compile($) : _.identity; + return reverse(function(a,b){ + return compare(get(a),get(b)); + }, descending); + }); + var comparator = function(o1, o2){ + for ( var i = 0; i < expression.length; i++) { + var comp = expression[i](o1, o2); + if (comp != 0) return comp; + } + return 0; + }; + return _.clone(array).sort(reverse(comparator, descend)); + }, + orderByToggle:function(predicate, attribute) { + var STRIP = /^([+|-])?(.*)/; + var ascending = false; + var index = -1; + _.detect(predicate, function($, i){ + if ($ == attribute) { + ascending = true; + index = i; + return true; + } + if (($.charAt(0)=='+'||$.charAt(0)=='-') && $.substring(1) == attribute) { + ascending = $.charAt(0) == '+'; + index = i; + return true; + }; + }); + if (index >= 0) { + predicate.splice(index, 1); + } + predicate.unshift((ascending ? "-" : "+") + attribute); + return predicate; + }, + orderByDirection:function(predicate, attribute, ascend, descend) { + ascend = ascend || 'ng-ascend'; + descend = descend || 'ng-descend'; + var att = predicate[0] || ''; + var direction = true; + if (att.charAt(0) == '-') { + att = att.substring(1); + direction = false; + } else if(att.charAt(0) == '+') { + att = att.substring(1); + } + return att == attribute ? (direction ? ascend : descend) : ""; + }, + merge:function(array, index, mergeValue) { + var value = array[index]; + if (!value) { + value = {}; + array[index] = value; + } + merge(mergeValue, value); + return array; + } +}; +angular.String = { + quote:function(string) { + return '"' + string.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(string) { + var str = angular.String.quote(string); + var chars = []; + for ( var i = 0; i < str.length; i++) { + var ch = str.charCodeAt(i); + if (ch < 128) { + chars.push(str.charAt(i)); + } else { + var encode = "000" + ch.toString(16); + chars.push("\\u" + encode.substring(encode.length - 4)); + } + } + return chars.join(''); + }, + 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$/))){ + var date = new Date(0); + date.setUTCFullYear(match[1], match[2] - 1, match[3]); + date.setUTCHours(match[4], match[5], match[6], 0); + return date; + } + return string; + } +}; +angular.Date = { + toString:function(date){ + function pad(n) { return n < 10 ? "0" + n : n; } + return (date.getUTCFullYear()) + '-' + + pad(date.getUTCMonth() + 1) + '-' + + pad(date.getUTCDate()) + 'T' + + pad(date.getUTCHours()) + ':' + + pad(date.getUTCMinutes()) + ':' + + pad(date.getUTCSeconds()) + 'Z'; + } + }; +angular.Function = { + compile:function(expression) { + if (_.isFunction(expression)){ + return expression; + } else if (expression){ + var scope = new Scope(); + return function($) { + scope.state = $; + return scope.eval(expression); + }; + } else { + return function($){return $;}; + } + } +}; + +(function(){ + function extend(dst, src, names){ + _.extend(dst, src); + _.each((names||[]), function(name){ + dst[name] = _[name]; + }); + }; + extend(angular.Global, {}, + ['extend', 'clone','isEqual', + 'isElement', 'isArray', 'isFunction', 'isUndefined']); + 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, + ['first', 'last', 'compact', 'flatten', 'without', + 'uniq', 'intersect', 'zip', 'indexOf', 'lastIndexOf']); + extend(angular.Object, angular.Collection, + ['keys', 'values']); + extend(angular.String, angular.Global); + extend(angular.Function, angular.Global, + ['bind', 'bindAll', 'delay', 'defer', 'wrap', 'compose']); +})();// Copyright (C) 2009 BRAT Tech LLC +Binder = function(doc, widgetFactory, urlWatcher, config) { + this.doc = doc; + this.urlWatcher = urlWatcher; + this.anchor = {}; + this.widgetFactory = widgetFactory; + this.config = config || {}; + this.updateListeners = []; +}; + +Binder.parseBindings = function(string) { + var results = []; + var lastIndex = 0; + var index; + while((index = string.indexOf('{{', lastIndex)) > -1) { + if (lastIndex < index) + results.push(string.substr(lastIndex, index - lastIndex)); + lastIndex = index; + + index = string.indexOf('}}', index); + index = index < 0 ? string.length : index + 2; + + results.push(string.substr(lastIndex, index - lastIndex)); + lastIndex = index; + } + if (lastIndex != string.length) + results.push(string.substr(lastIndex, string.length - lastIndex)); + return results.length === 0 ? [ string ] : results; +}; + +Binder.hasBinding = function(string) { + var bindings = Binder.parseBindings(string); + return bindings.length > 1 || Binder.binding(bindings[0]) !== null; +}; + +Binder.binding = function(string) { + var binding = string.replace(/\n/gm, ' ').match(/^\{\{(.*)\}\}$/); + return binding ? binding[1] : null; +}; + + +Binder.prototype.parseQueryString = function(query) { + var params = {}; + query.replace(/(?:^|&)([^&=]*)=?([^&]*)/g, + function (match, left, right) { + if (left) params[decodeURIComponent(left)] = decodeURIComponent(right); + }); + return params; +}; + +Binder.prototype.parseAnchor = function(url) { + var self = this; + url = url || this.urlWatcher.getUrl(); + + var anchorIndex = url.indexOf('#'); + if (anchorIndex < 0) return; + var anchor = url.substring(anchorIndex + 1); + + var anchorQuery = this.parseQueryString(anchor); + jQuery.each(self.anchor, function(key, newValue) { + delete self.anchor[key]; + }); + jQuery.each(anchorQuery, function(key, newValue) { + self.anchor[key] = newValue; + }); +}; + +Binder.prototype.onUrlChange = function (url) { + console.log("URL change detected", url); + this.parseAnchor(url); + this.updateView(); +}; + +Binder.prototype.updateAnchor = function() { + var url = this.urlWatcher.getUrl(); + var anchorIndex = url.indexOf('#'); + if (anchorIndex > -1) + url = url.substring(0, anchorIndex); + url += "#"; + var sep = ''; + for (var key in this.anchor) { + var value = this.anchor[key]; + if (typeof value === 'undefined' || value === null) { + delete this.anchor[key]; + } else { + url += sep + encodeURIComponent(key); + if (value !== true) + url += "=" + encodeURIComponent(value); + sep = '&'; + } + } + this.urlWatcher.setUrl(url); + return url; +}; + +Binder.prototype.updateView = function() { + var start = new Date().getTime(); + var scope = jQuery(this.doc).scope(); + scope.set("$invalidWidgets", []); + scope.updateView(); + var end = new Date().getTime(); + this.updateAnchor(); + _.each(this.updateListeners, function(fn) {fn();}); +}; + +Binder.prototype.docFindWithSelf = function(exp){ + var doc = jQuery(this.doc); + var selection = doc.find(exp); + if (doc.is(exp)){ + selection = selection.andSelf(); + } + return selection; +}; + +Binder.prototype.executeInit = function() { + this.docFindWithSelf("[ng-init]").each(function() { + var jThis = jQuery(this); + var scope = jThis.scope(); + try { + scope.eval(jThis.attr('ng-init')); + } catch (e) { + alert("EVAL ERROR:\n" + jThis.attr('ng-init') + '\n' + toJson(e, true)); + } + }); +}; + +Binder.prototype.entity = function (scope) { + this.docFindWithSelf("[ng-entity]").attr("ng-watch", function() { + try { + var jNode = jQuery(this); + var decl = scope.entity(jNode.attr("ng-entity")); + return decl + (jNode.attr('ng-watch') || ""); + } catch (e) { + alert(e); + } + }); +}; + +Binder.prototype.compile = function() { + var jNode = jQuery(this.doc); + var self = this; + if (this.config.autoSubmit) { + 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(), ""); + this.docFindWithSelf("a[ng-action]").live('click', function (event) { + var jNode = jQuery(this); + try { + jNode.scope().eval(jNode.attr('ng-action')); + jNode.removeAttr('ng-error'); + jNode.removeClass("ng-exception"); + } catch (e) { + jNode.addClass("ng-exception"); + jNode.attr('ng-error', toJson(e, true)); + } + self.updateView(); + return false; + }); +}; + +Binder.prototype.translateBinding = function(node, parentPath, factories) { + var path = parentPath.concat(); + var offset = path.pop(); + var parts = Binder.parseBindings(node.nodeValue); + if (parts.length > 1 || Binder.binding(parts[0])) { + var parent = node.parentNode; + if (isLeafNode(parent)) { + parent.setAttribute('ng-bind-template', node.nodeValue); + factories.push({path:path, fn:function(node, scope, prefix) { + return new BindUpdater(node, node.getAttribute('ng-bind-template')); + }}); + } else { + for (var i = 0; i < parts.length; i++) { + var part = parts[i]; + var binding = Binder.binding(part); + var newNode; + if (binding) { + newNode = document.createElement("span"); + var jNewNode = jQuery(newNode); + jNewNode.attr("ng-bind", binding); + if (i === 0) { + factories.push({path:path.concat(offset + i), fn:Binder.prototype.ng_bind}); + } + } else if (msie && part.charAt(0) == ' ') { + newNode = document.createElement("span"); + newNode.innerHTML = ' ' + part.substring(1); + } else { + newNode = document.createTextNode(part); + } + parent.insertBefore(newNode, node); + } + } + parent.removeChild(node); + } +}; + +Binder.prototype.precompile = function(root) { + var factories = []; + this.precompileNode(root, [], factories); + return function (template, scope, prefix) { + var len = factories.length; + for (var i = 0; i < len; i++) { + var factory = factories[i]; + var node = template; + var path = factory.path; + for (var j = 0; j < path.length; j++) { + node = node.childNodes[path[j]]; + } + try { + scope.addWidget(factory.fn(node, scope, prefix)); + } catch (e) { + alert(e); + } + } + }; +}; + +Binder.prototype.precompileNode = function(node, path, factories) { + var nodeType = node.nodeType; + if (nodeType == Node.TEXT_NODE) { + this.translateBinding(node, path, factories); + return; + } else if (nodeType != Node.ELEMENT_NODE && nodeType != Node.DOCUMENT_NODE) { + return; + } + + if (!node.getAttribute) return; + var nonBindable = node.getAttribute('ng-non-bindable'); + if (nonBindable || nonBindable === "") return; + + var attributes = node.attributes; + if (attributes) { + var bindings = node.getAttribute('ng-bind-attr'); + node.removeAttribute('ng-bind-attr'); + bindings = bindings ? fromJson(bindings) : {}; + var attrLen = attributes.length; + for (var i = 0; i < attrLen; i++) { + var attr = attributes[i]; + var attrName = attr.name; + // http://www.glennjones.net/Post/809/getAttributehrefbug.htm + var attrValue = msie && attrName == 'href' ? + decodeURI(node.getAttribute(attrName, 2)) : attr.value; + if (Binder.hasBinding(attrValue)) { + bindings[attrName] = attrValue; + } + } + var json = toJson(bindings); + if (json.length > 2) { + node.setAttribute("ng-bind-attr", json); + } + } + + if (!node.getAttribute) console.log(node); + var repeaterExpression = node.getAttribute('ng-repeat'); + if (repeaterExpression) { + node.removeAttribute('ng-repeat'); + var precompiled = this.precompile(node); + var view = document.createComment("ng-repeat: " + repeaterExpression); + var parentNode = node.parentNode; + parentNode.insertBefore(view, node); + parentNode.removeChild(node); + var template = function(childScope, prefix, i) { + var clone = jQuery(node).clone(); + clone.css('display', ''); + clone.attr('ng-repeat-index', "" + i); + clone.data('scope', childScope); + precompiled(clone[0], childScope, prefix + i + ":"); + return clone; + }; + factories.push({path:path, fn:function(node, scope, prefix) { + return new RepeaterUpdater(jQuery(node), repeaterExpression, template, prefix); + }}); + return; + } + + if (node.getAttribute('ng-eval')) factories.push({path:path, fn:this.ng_eval}); + if (node.getAttribute('ng-bind')) factories.push({path:path, fn:this.ng_bind}); + if (node.getAttribute('ng-bind-attr')) factories.push({path:path, fn:this.ng_bind_attr}); + if (node.getAttribute('ng-hide')) factories.push({path:path, fn:this.ng_hide}); + if (node.getAttribute('ng-show')) factories.push({path:path, fn:this.ng_show}); + if (node.getAttribute('ng-class')) factories.push({path:path, fn:this.ng_class}); + if (node.getAttribute('ng-class-odd')) factories.push({path:path, fn:this.ng_class_odd}); + if (node.getAttribute('ng-class-even')) factories.push({path:path, fn:this.ng_class_even}); + if (node.getAttribute('ng-style')) factories.push({path:path, fn:this.ng_style}); + if (node.getAttribute('ng-watch')) factories.push({path:path, fn:this.ng_watch}); + var nodeName = node.nodeName; + if ((nodeName == 'INPUT' ) || + nodeName == 'TEXTAREA' || + nodeName == 'SELECT' || + nodeName == 'BUTTON') { + var self = this; + factories.push({path:path, fn:function(node, scope, prefix) { + node.name = prefix + node.name.split(":").pop(); + return self.widgetFactory.createController(jQuery(node), scope); + }}); + } + if (nodeName == 'OPTION') { + var html = jQuery('' + + '' + + '' + + '' + + ''); +}; + +FileController.prototype._on_cancel = function() { +}; + +FileController.prototype._on_complete = function() { +}; + +FileController.prototype._on_httpStatus = function(status) { + alert("httpStatus:" + this.scopeName + " status:" + status); +}; + +FileController.prototype._on_ioError = function() { + alert("ioError:" + this.scopeName); +}; + +FileController.prototype._on_open = function() { + alert("open:" + this.scopeName); +}; + +FileController.prototype._on_progress = function(bytesLoaded, bytesTotal) { +}; + +FileController.prototype._on_securityError = function() { + alert("securityError:" + this.scopeName); +}; + +FileController.prototype._on_uploadCompleteData = function(data) { + var value = fromJson(data); + value.url = this.attachmentsPath + '/' + value.id + '/' + value.text; + this.view.find("input").attr('checked', true); + var scope = this.view.scope(); + this.value = value; + this.updateModel(scope); + this.value = null; + scope.get('$binder').updateView(); +}; + +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.upload(); +}; + +FileController.prototype.updateModel = function(scope) { + var isChecked = this.view.find("input").attr('checked'); + var value = isChecked ? this.value : null; + if (this.lastValue === value) { + return false; + } else { + scope.set(this.scopeName, value); + return true; + } +}; + +FileController.prototype.updateView = function(scope) { + var modelValue = scope.get(this.scopeName); + if (modelValue && this.value !== modelValue) { + this.value = modelValue; + 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', !!modelValue); +}; + +FileController.prototype.upload = function() { + if (this.name) { + this.uploader.uploadFile(this.attachmentsPath); + } +}; + + +/////////////////////// +// NullController +/////////////////////// +NullController = function(view) {this.view = view;}; +NullController.prototype.updateModel = function() { return true; }; +NullController.prototype.updateView = function() { }; +NullController.instance = new NullController(); + + +/////////////////////// +// ButtonController +/////////////////////// +ButtonController = function(view) {this.view = view;}; +ButtonController.prototype.updateModel = function(scope) { return true; }; +ButtonController.prototype.updateView = function(scope) {}; + +/////////////////////// +// TextController +/////////////////////// +TextController = function(view, exp) { + this.view = view; + this.exp = exp; + this.validator = view.getAttribute('ng-validate'); + this.required = typeof view.attributes['ng-required'] != "undefined"; + this.lastErrorText = null; + this.lastValue = undefined; + this.initialValue = view.value; + var widget = view.getAttribute('ng-widget'); + if (widget === 'datepicker') { + jQuery(view).datepicker(); + } +}; + +TextController.prototype.updateModel = function(scope) { + var value = this.view.value; + if (this.lastValue === value) { + return false; + } else { + scope.setEval(this.exp, value); + this.lastValue = value; + return true; + } +}; + +TextController.prototype.updateView = function(scope) { + var view = this.view; + var value = scope.get(this.exp); + if (typeof value === "undefined") { + value = this.initialValue; + scope.setEval(this.exp, value); + } + value = value ? value : ''; + if (this.lastValue != value) { + view.value = value; + this.lastValue = value; + } + var isValidationError = false; + view.removeAttribute('ng-error'); + if (this.required) { + isValidationError = !(value && value.length > 0); + } + var errorText = isValidationError ? "Required Value" : null; + if (!isValidationError && this.validator && value) { + errorText = scope.validate(this.validator, value); + isValidationError = !!errorText; + } + if (this.lastErrorText !== errorText) { + this.lastErrorText = isValidationError; + if (errorText !== null) { + view.setAttribute('ng-error', errorText); + scope.markInvalid(this); + } + jQuery(view).toggleClass('ng-validation-error', isValidationError); + } +}; + +/////////////////////// +// CheckboxController +/////////////////////// +CheckboxController = function(view, exp) { + this.view = view; + this.exp = exp; + this.lastValue = undefined; + this.initialValue = view.checked ? view.value : ""; +}; + +CheckboxController.prototype.updateModel = function(scope) { + var input = this.view; + var value = input.checked ? input.value : ''; + if (this.lastValue === value) { + return false; + } else { + scope.setEval(this.exp, value); + this.lastValue = value; + return true; + } +}; + +CheckboxController.prototype.updateView = function(scope) { + var input = this.view; + var value = scope.eval(this.exp); + if (typeof value === "undefined") { + value = this.initialValue; + scope.setEval(this.exp, value); + } + input.checked = input.value == (''+value); +}; + +/////////////////////// +// SelectController +/////////////////////// +SelectController = function(view, exp) { + this.view = view; + this.exp = exp; + this.lastValue = undefined; + this.initialValue = view.value; +}; + +SelectController.prototype.updateModel = function(scope) { + var input = this.view; + if (input.selectedIndex < 0) { + scope.setEval(this.exp, null); + } else { + var value = this.view.value; + if (this.lastValue === value) { + return false; + } else { + scope.setEval(this.exp, value); + this.lastValue = value; + return true; + } + } +}; + +SelectController.prototype.updateView = function(scope) { + var input = this.view; + var value = scope.get(this.exp); + if (typeof value === 'undefined') { + value = this.initialValue; + scope.setEval(this.exp, value); + } + if (value !== this.lastValue) { + input.value = value ? value : ""; + this.lastValue = value; + } +}; + +/////////////////////// +// MultiSelectController +/////////////////////// +MultiSelectController = function(view, exp) { + this.view = view; + this.exp = exp; + this.lastValue = undefined; + this.initialValue = this.selected(); +}; + +MultiSelectController.prototype.selected = function () { + var value = []; + var options = this.view.options; + for ( var i = 0; i < options.length; i++) { + var option = options[i]; + if (option.selected) { + value.push(option.value); + } + } + return value; +}; + +MultiSelectController.prototype.updateModel = function(scope) { + var value = this.selected(); + // TODO: This is wrong! no caching going on here as we are always comparing arrays + if (this.lastValue === value) { + return false; + } else { + scope.setEval(this.exp, value); + this.lastValue = value; + return true; + } +}; + +MultiSelectController.prototype.updateView = function(scope) { + var input = this.view; + var selected = scope.get(this.exp); + if (typeof selected === "undefined") { + selected = this.initialValue; + scope.setEval(this.exp, selected); + } + if (selected !== this.lastValue) { + var options = input.options; + for ( var i = 0; i < options.length; i++) { + var option = options[i]; + option.selected = _.include(selected, option.value); + } + this.lastValue = selected; + } +}; + +/////////////////////// +// RadioController +/////////////////////// +RadioController = function(view, exp) { + this.view = view; + this.exp = exp; + this.lastChecked = undefined; + this.lastValue = undefined; + this.inputValue = view.value; + this.initialValue = view.checked ? view.value : null; +}; + +RadioController.prototype.updateModel = function(scope) { + var input = this.view; + if (this.lastChecked) { + return false; + } else { + input.checked = true; + this.lastValue = scope.setEval(this.exp, this.inputValue); + this.lastChecked = true; + return true; + } +}; + +RadioController.prototype.updateView = function(scope) { + var input = this.view; + var value = scope.get(this.exp); + if (this.initialValue && typeof value === "undefined") { + value = this.initialValue; + scope.setEval(this.exp, value); + } + if (this.lastValue != value) { + this.lastChecked = input.checked = this.inputValue == (''+value); + this.lastValue = value; + } +}; + +/////////////////////// +//ElementController +/////////////////////// +BindUpdater = function(view, exp) { + this.view = view; + this.exp = Binder.parseBindings(exp); + this.hasError = false; + this.scopeSelf = {element:view}; +}; + +BindUpdater.toText = function(obj) { + var e = escapeHtml; + switch(typeof obj) { + case "string": + case "boolean": + case "number": + return e(obj); + case "function": + return BindUpdater.toText(obj()); + case "object": + if (isNode(obj)) { + return outerHTML(obj); + } else if (obj instanceof angular.filter.Meta) { + switch(typeof obj.html) { + case "string": + case "number": + return obj.html; + case "function": + return obj.html(); + case "object": + if (isNode(obj.html)) + return outerHTML(obj.html); + default: + break; + } + switch(typeof obj.text) { + case "string": + case "number": + return e(obj.text); + case "function": + return e(obj.text()); + default: + break; + } + } + if (obj === null) + return ""; + return e(toJson(obj, true)); + default: + return ""; + } +}; + +BindUpdater.prototype.updateModel = function(scope) {}; +BindUpdater.prototype.updateView = function(scope) { + var html = []; + var parts = this.exp; + var length = parts.length; + for(var i=0; i iteratorLength; --r) { + var unneeded = this.children.pop(); + unneeded.element.removeNode(); + } + // Special case for option in select + if (child && child.element[0].nodeName === "OPTION") { + var select = jQuery(child.element[0].parentNode); + var cntl = select.data('controller'); + if (cntl) { + cntl.lastValue = undefined; + cntl.updateView(scope); + } + } + }); +}; + +////////////////////////////////// +// PopUp +////////////////////////////////// + +PopUp = function(doc) { + this.doc = doc; +}; + +PopUp.OUT_EVENT = "mouseleave mouseout click dblclick keypress keyup"; + +PopUp.prototype.bind = function () { + var self = this; + this.doc.find('.ng-validation-error,.ng-exception'). + live("mouseover", PopUp.onOver); +}; + +PopUp.onOver = function(e) { + PopUp.onOut(); + var jNode = jQuery(this); + jNode.bind(PopUp.OUT_EVENT, PopUp.onOut); + var position = jNode.position(); + var de = document.documentElement; + var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth; + var hasArea = w - position.left; + var width = 300; + var title = jNode.hasClass("ng-exception") ? "EXCEPTION:" : "Validation error..."; + var msg = jNode.attr("ng-error"); + + var x; + var arrowPos = hasArea>(width+75) ? "left" : "right"; + var tip = jQuery( + "
" + + "
" + + "
"+title+"
" + + "
"+msg+"
" + + "
"); + jQuery("body").append(tip); + if(arrowPos === 'left'){ + x = position.left + this.offsetWidth + 11; + }else{ + x = position.left - (width + 15); + tip.find('.ng-arrow-right').css({left:width+1}); + } + + tip.css({left: x+"px", top: (position.top - 3)+"px"}); + return true; +}; + +PopUp.onOut = function() { + jQuery('#ng-callout'). + unbind(PopUp.OUT_EVENT, PopUp.onOut). + remove(); + return true; +}; + +////////////////////////////////// +// Status +////////////////////////////////// + + +Status = function(body) { + this.loader = body.append(Status.DOM).find("#ng-loading"); + this.requestCount = 0; +}; + +Status.DOM ='
loading....
'; + +Status.prototype.beginRequest = function () { + if (this.requestCount === 0) { + this.loader.show(); + } + this.requestCount++; +}; + +Status.prototype.endRequest = function () { + this.requestCount--; + if (this.requestCount === 0) { + this.loader.hide("fold"); + } +}; +})(window, document); \ No newline at end of file diff --git a/jsTestDriver.conf b/jsTestDriver.conf index 97136e7b..ebd45d9d 100644 --- a/jsTestDriver.conf +++ b/jsTestDriver.conf @@ -15,3 +15,6 @@ load: exclude: - src/angular-bootstrap.js + - src/angular.prefix + - src/angular.suffix + \ No newline at end of file diff --git a/lib/shrinksafe/js.jar b/lib/shrinksafe/js.jar deleted file mode 100644 index c081d16b..00000000 Binary files a/lib/shrinksafe/js.jar and /dev/null differ diff --git a/lib/shrinksafe/shrinksafe.jar b/lib/shrinksafe/shrinksafe.jar deleted file mode 100644 index eeb7b14e..00000000 Binary files a/lib/shrinksafe/shrinksafe.jar and /dev/null differ diff --git a/src/API.js b/src/API.js index c51fe01d..6fb6e8fc 100644 --- a/src/API.js +++ b/src/API.js @@ -66,7 +66,7 @@ angular.Array = { } return true; }; - var getter = nglr.Scope.getter; + var getter = Scope.getter; var search = function(obj, text){ if (text.charAt(0) === '!') { return !search(obj, text.substr(1)); @@ -147,7 +147,7 @@ angular.Array = { }, orderBy:function(array, expression, descend) { function reverse(comp, descending) { - return nglr.toBoolean(descending) ? + return toBoolean(descending) ? function(a,b){return comp(b,a);} : comp; } function compare(v1, v2){ @@ -224,7 +224,7 @@ angular.Array = { value = {}; array[index] = value; } - nglr.merge(mergeValue, value); + merge(mergeValue, value); return array; } }; @@ -281,7 +281,7 @@ angular.Function = { if (_.isFunction(expression)){ return expression; } else if (expression){ - var scope = new nglr.Scope(); + var scope = new Scope(); return function($) { scope.state = $; return scope.eval(expression); diff --git a/src/Binder.js b/src/Binder.js index 8b4d27fb..3589cb88 100644 --- a/src/Binder.js +++ b/src/Binder.js @@ -1,5 +1,5 @@ // Copyright (C) 2009 BRAT Tech LLC -nglr.Binder = function(doc, widgetFactory, urlWatcher, config) { +Binder = function(doc, widgetFactory, urlWatcher, config) { this.doc = doc; this.urlWatcher = urlWatcher; this.anchor = {}; @@ -8,7 +8,7 @@ nglr.Binder = function(doc, widgetFactory, urlWatcher, config) { this.updateListeners = []; }; -nglr.Binder.parseBindings = function(string) { +Binder.parseBindings = function(string) { var results = []; var lastIndex = 0; var index; @@ -28,18 +28,18 @@ nglr.Binder.parseBindings = function(string) { return results.length === 0 ? [ string ] : results; }; -nglr.Binder.hasBinding = function(string) { - var bindings = nglr.Binder.parseBindings(string); - return bindings.length > 1 || nglr.Binder.binding(bindings[0]) !== null; +Binder.hasBinding = function(string) { + var bindings = Binder.parseBindings(string); + return bindings.length > 1 || Binder.binding(bindings[0]) !== null; }; -nglr.Binder.binding = function(string) { +Binder.binding = function(string) { var binding = string.replace(/\n/gm, ' ').match(/^\{\{(.*)\}\}$/); return binding ? binding[1] : null; }; -nglr.Binder.prototype.parseQueryString = function(query) { +Binder.prototype.parseQueryString = function(query) { var params = {}; query.replace(/(?:^|&)([^&=]*)=?([^&]*)/g, function (match, left, right) { @@ -48,7 +48,7 @@ nglr.Binder.prototype.parseQueryString = function(query) { return params; }; -nglr.Binder.prototype.parseAnchor = function(url) { +Binder.prototype.parseAnchor = function(url) { var self = this; url = url || this.urlWatcher.getUrl(); @@ -65,13 +65,13 @@ nglr.Binder.prototype.parseAnchor = function(url) { }); }; -nglr.Binder.prototype.onUrlChange = function (url) { +Binder.prototype.onUrlChange = function (url) { console.log("URL change detected", url); this.parseAnchor(url); this.updateView(); }; -nglr.Binder.prototype.updateAnchor = function() { +Binder.prototype.updateAnchor = function() { var url = this.urlWatcher.getUrl(); var anchorIndex = url.indexOf('#'); if (anchorIndex > -1) @@ -93,7 +93,7 @@ nglr.Binder.prototype.updateAnchor = function() { return url; }; -nglr.Binder.prototype.updateView = function() { +Binder.prototype.updateView = function() { var start = new Date().getTime(); var scope = jQuery(this.doc).scope(); scope.set("$invalidWidgets", []); @@ -103,7 +103,7 @@ nglr.Binder.prototype.updateView = function() { _.each(this.updateListeners, function(fn) {fn();}); }; -nglr.Binder.prototype.docFindWithSelf = function(exp){ +Binder.prototype.docFindWithSelf = function(exp){ var doc = jQuery(this.doc); var selection = doc.find(exp); if (doc.is(exp)){ @@ -112,31 +112,31 @@ nglr.Binder.prototype.docFindWithSelf = function(exp){ return selection; }; -nglr.Binder.prototype.executeInit = function() { +Binder.prototype.executeInit = function() { this.docFindWithSelf("[ng-init]").each(function() { var jThis = jQuery(this); var scope = jThis.scope(); try { scope.eval(jThis.attr('ng-init')); } catch (e) { - nglr.alert("EVAL ERROR:\n" + jThis.attr('ng-init') + '\n' + nglr.toJson(e, true)); + alert("EVAL ERROR:\n" + jThis.attr('ng-init') + '\n' + toJson(e, true)); } }); }; -nglr.Binder.prototype.entity = function (scope) { +Binder.prototype.entity = function (scope) { this.docFindWithSelf("[ng-entity]").attr("ng-watch", function() { try { var jNode = jQuery(this); var decl = scope.entity(jNode.attr("ng-entity")); return decl + (jNode.attr('ng-watch') || ""); } catch (e) { - nglr.alert(e); + alert(e); } }); }; -nglr.Binder.prototype.compile = function() { +Binder.prototype.compile = function() { var jNode = jQuery(this.doc); var self = this; if (this.config.autoSubmit) { @@ -153,37 +153,37 @@ nglr.Binder.prototype.compile = function() { jNode.removeClass("ng-exception"); } catch (e) { jNode.addClass("ng-exception"); - jNode.attr('ng-error', nglr.toJson(e, true)); + jNode.attr('ng-error', toJson(e, true)); } self.updateView(); return false; }); }; -nglr.Binder.prototype.translateBinding = function(node, parentPath, factories) { +Binder.prototype.translateBinding = function(node, parentPath, factories) { var path = parentPath.concat(); var offset = path.pop(); - var parts = nglr.Binder.parseBindings(node.nodeValue); - if (parts.length > 1 || nglr.Binder.binding(parts[0])) { + var parts = Binder.parseBindings(node.nodeValue); + if (parts.length > 1 || Binder.binding(parts[0])) { var parent = node.parentNode; - if (nglr.isLeafNode(parent)) { + if (isLeafNode(parent)) { parent.setAttribute('ng-bind-template', node.nodeValue); factories.push({path:path, fn:function(node, scope, prefix) { - return new nglr.BindUpdater(node, node.getAttribute('ng-bind-template')); + return new BindUpdater(node, node.getAttribute('ng-bind-template')); }}); } else { for (var i = 0; i < parts.length; i++) { var part = parts[i]; - var binding = nglr.Binder.binding(part); + var binding = Binder.binding(part); var newNode; if (binding) { newNode = document.createElement("span"); var jNewNode = jQuery(newNode); jNewNode.attr("ng-bind", binding); if (i === 0) { - factories.push({path:path.concat(offset + i), fn:nglr.Binder.prototype.ng_bind}); + factories.push({path:path.concat(offset + i), fn:Binder.prototype.ng_bind}); } - } else if (nglr.msie && part.charAt(0) == ' ') { + } else if (msie && part.charAt(0) == ' ') { newNode = document.createElement("span"); newNode.innerHTML = ' ' + part.substring(1); } else { @@ -196,7 +196,7 @@ nglr.Binder.prototype.translateBinding = function(node, parentPath, factories) { } }; -nglr.Binder.prototype.precompile = function(root) { +Binder.prototype.precompile = function(root) { var factories = []; this.precompileNode(root, [], factories); return function (template, scope, prefix) { @@ -211,13 +211,13 @@ nglr.Binder.prototype.precompile = function(root) { try { scope.addWidget(factory.fn(node, scope, prefix)); } catch (e) { - nglr.alert(e); + alert(e); } } }; }; -nglr.Binder.prototype.precompileNode = function(node, path, factories) { +Binder.prototype.precompileNode = function(node, path, factories) { var nodeType = node.nodeType; if (nodeType == Node.TEXT_NODE) { this.translateBinding(node, path, factories); @@ -234,19 +234,19 @@ nglr.Binder.prototype.precompileNode = function(node, path, factories) { if (attributes) { var bindings = node.getAttribute('ng-bind-attr'); node.removeAttribute('ng-bind-attr'); - bindings = bindings ? nglr.fromJson(bindings) : {}; + bindings = bindings ? fromJson(bindings) : {}; var attrLen = attributes.length; for (var i = 0; i < attrLen; i++) { var attr = attributes[i]; var attrName = attr.name; // http://www.glennjones.net/Post/809/getAttributehrefbug.htm - var attrValue = nglr.msie && attrName == 'href' ? + var attrValue = msie && attrName == 'href' ? decodeURI(node.getAttribute(attrName, 2)) : attr.value; - if (nglr.Binder.hasBinding(attrValue)) { + if (Binder.hasBinding(attrValue)) { bindings[attrName] = attrValue; } } - var json = nglr.toJson(bindings); + var json = toJson(bindings); if (json.length > 2) { node.setAttribute("ng-bind-attr", json); } @@ -270,7 +270,7 @@ nglr.Binder.prototype.precompileNode = function(node, path, factories) { return clone; }; factories.push({path:path, fn:function(node, scope, prefix) { - return new nglr.RepeaterUpdater(jQuery(node), repeaterExpression, template, prefix); + return new RepeaterUpdater(jQuery(node), repeaterExpression, template, prefix); }}); return; } @@ -309,42 +309,42 @@ nglr.Binder.prototype.precompileNode = function(node, path, factories) { } }; -nglr.Binder.prototype.ng_eval = function(node) { - return new nglr.EvalUpdater(node, node.getAttribute('ng-eval')); +Binder.prototype.ng_eval = function(node) { + return new EvalUpdater(node, node.getAttribute('ng-eval')); }; -nglr.Binder.prototype.ng_bind = function(node) { - return new nglr.BindUpdater(node, "{{" + node.getAttribute('ng-bind') + "}}"); +Binder.prototype.ng_bind = function(node) { + return new BindUpdater(node, "{{" + node.getAttribute('ng-bind') + "}}"); }; -nglr.Binder.prototype.ng_bind_attr = function(node) { - return new nglr.BindAttrUpdater(node, nglr.fromJson(node.getAttribute('ng-bind-attr'))); +Binder.prototype.ng_bind_attr = function(node) { + return new BindAttrUpdater(node, fromJson(node.getAttribute('ng-bind-attr'))); }; -nglr.Binder.prototype.ng_hide = function(node) { - return new nglr.HideUpdater(node, node.getAttribute('ng-hide')); +Binder.prototype.ng_hide = function(node) { + return new HideUpdater(node, node.getAttribute('ng-hide')); }; -nglr.Binder.prototype.ng_show = function(node) { - return new nglr.ShowUpdater(node, node.getAttribute('ng-show')); +Binder.prototype.ng_show = function(node) { + return new ShowUpdater(node, node.getAttribute('ng-show')); }; -nglr.Binder.prototype.ng_class = function(node) { - return new nglr.ClassUpdater(node, node.getAttribute('ng-class')); +Binder.prototype.ng_class = function(node) { + return new ClassUpdater(node, node.getAttribute('ng-class')); }; -nglr.Binder.prototype.ng_class_even = function(node) { - return new nglr.ClassEvenUpdater(node, node.getAttribute('ng-class-even')); +Binder.prototype.ng_class_even = function(node) { + return new ClassEvenUpdater(node, node.getAttribute('ng-class-even')); }; -nglr.Binder.prototype.ng_class_odd = function(node) { - return new nglr.ClassOddUpdater(node, node.getAttribute('ng-class-odd')); +Binder.prototype.ng_class_odd = function(node) { + return new ClassOddUpdater(node, node.getAttribute('ng-class-odd')); }; -nglr.Binder.prototype.ng_style = function(node) { - return new nglr.StyleUpdater(node, node.getAttribute('ng-style')); +Binder.prototype.ng_style = function(node) { + return new StyleUpdater(node, node.getAttribute('ng-style')); }; -nglr.Binder.prototype.ng_watch = function(node, scope) { +Binder.prototype.ng_watch = function(node, scope) { scope.watch(node.getAttribute('ng-watch')); }; diff --git a/src/ControlBar.js b/src/ControlBar.js index 3e1f0b57..b66a1464 100644 --- a/src/ControlBar.js +++ b/src/ControlBar.js @@ -1,16 +1,16 @@ // Copyright (C) 2008,2009 BRAT Tech LLC -nglr.ControlBar = function (document, serverUrl) { +ControlBar = function (document, serverUrl) { this.document = document; this.serverUrl = serverUrl; this.window = window; this.callbacks = []; }; -nglr.ControlBar.prototype.bind = function () { +ControlBar.prototype.bind = function () { }; -nglr.ControlBar.HTML = +ControlBar.HTML = '
' + '
' + '
' + @@ -18,25 +18,25 @@ nglr.ControlBar.HTML = '
' + '
'; -nglr.ControlBar.prototype.login = function (loginSubmitFn) { +ControlBar.prototype.login = function (loginSubmitFn) { this.callbacks.push(loginSubmitFn); if (this.callbacks.length == 1) { this.doTemplate("/user_session/new.mini?return_url=" + encodeURIComponent(this.urlWithoutAnchor())); } }; -nglr.ControlBar.prototype.logout = function (loginSubmitFn) { +ControlBar.prototype.logout = function (loginSubmitFn) { this.callbacks.push(loginSubmitFn); if (this.callbacks.length == 1) { this.doTemplate("/user_session/do_destroy.mini"); } }; -nglr.ControlBar.prototype.urlWithoutAnchor = function (path) { +ControlBar.prototype.urlWithoutAnchor = function (path) { return this.window.location.href.split("#")[0]; }; -nglr.ControlBar.prototype.doTemplate = function (path) { +ControlBar.prototype.doTemplate = function (path) { var self = this; var id = new Date().getTime(); var url = this.urlWithoutAnchor(); @@ -49,7 +49,7 @@ nglr.ControlBar.prototype.doTemplate = function (path) { resizable: false, modal:true, title: 'Authentication: <angular/>' }); - nglr["_iframe_notify_" + id] = function() { + callbacks["_iframe_notify_" + id] = function() { loginView.dialog("destroy"); loginView.remove(); jQuery.each(self.callbacks, function(i, callback){ @@ -59,13 +59,13 @@ nglr.ControlBar.prototype.doTemplate = function (path) { }; }; -nglr.ControlBar.FORBIDEN = +ControlBar.FORBIDEN = '
' + 'Sorry, you do not have permission for this!'+ '
'; -nglr.ControlBar.prototype.notAuthorized = function () { +ControlBar.prototype.notAuthorized = function () { if (this.forbidenView) return; - this.forbidenView = jQuery(nglr.ControlBar.FORBIDEN); + this.forbidenView = jQuery(ControlBar.FORBIDEN); this.forbidenView.dialog({bgiframe:true, height:70, modal:true}); }; diff --git a/src/DataStore.js b/src/DataStore.js index 97ab92ff..bdf882a0 100644 --- a/src/DataStore.js +++ b/src/DataStore.js @@ -1,6 +1,6 @@ // Copyright (C) 2009 BRAT Tech LLC -nglr.DataStore = function(post, users, anchor) { +DataStore = function(post, users, anchor) { this.post = post; this.users = users; this._cache = {$collections:[]}; @@ -8,14 +8,14 @@ nglr.DataStore = function(post, users, anchor) { this.bulkRequest = []; }; -nglr.DataStore.prototype.cache = function(document) { - if (document.constructor != nglr.Model) { - throw "Parameter must be an instance of Entity! " + nglr.toJson(document); +DataStore.prototype.cache = function(document) { + if (document.constructor != Model) { + throw "Parameter must be an instance of Entity! " + toJson(document); } var key = document.$entity + '/' + document.$id; var cachedDocument = this._cache[key]; if (cachedDocument) { - nglr.Model.copyDirectFields(document, cachedDocument); + Model.copyDirectFields(document, cachedDocument); } else { this._cache[key] = document; cachedDocument = document; @@ -23,7 +23,7 @@ nglr.DataStore.prototype.cache = function(document) { return cachedDocument; }; -nglr.DataStore.prototype.load = function(instance, id, callback, failure) { +DataStore.prototype.load = function(instance, id, callback, failure) { if (id && id !== '*') { var self = this; this._jsonRequest(["GET", instance.$entity + "/" + id], function(response) { @@ -31,13 +31,13 @@ nglr.DataStore.prototype.load = function(instance, id, callback, failure) { instance.$migrate(); var clone = instance.$$entity(instance); self.cache(clone); - (callback||nglr.noop)(instance); + (callback||noop)(instance); }, failure); } return instance; }; -nglr.DataStore.prototype.loadMany = function(entity, ids, callback) { +DataStore.prototype.loadMany = function(entity, ids, callback) { var self=this; var list = []; var callbackCount = 0; @@ -45,26 +45,26 @@ nglr.DataStore.prototype.loadMany = function(entity, ids, callback) { list.push(self.load(entity(), id, function(){ callbackCount++; if (callbackCount == ids.length) { - (callback||nglr.noop)(list); + (callback||noop)(list); } })); }); return list; } -nglr.DataStore.prototype.loadOrCreate = function(instance, id, callback) { +DataStore.prototype.loadOrCreate = function(instance, id, callback) { var self=this; return this.load(instance, id, callback, function(response){ if (response.$status_code == 404) { instance.$id = id; - (callback||nglr.noop)(instance); + (callback||noop)(instance); } else { throw response; } }); }; -nglr.DataStore.prototype.loadAll = function(entity, callback) { +DataStore.prototype.loadAll = function(entity, callback) { var self = this; var list = []; list.$$accept = function(doc){ @@ -78,12 +78,12 @@ nglr.DataStore.prototype.loadAll = function(entity, callback) { document.$loadFrom(rows[i]); list.push(self.cache(document)); } - (callback||nglr.noop)(list); + (callback||noop)(list); }); return list; }; -nglr.DataStore.prototype.save = function(document, callback) { +DataStore.prototype.save = function(document, callback) { var self = this; var data = {}; document.$saveTo(data); @@ -103,7 +103,7 @@ nglr.DataStore.prototype.save = function(document, callback) { }); }; -nglr.DataStore.prototype.remove = function(document, callback) { +DataStore.prototype.remove = function(document, callback) { var self = this; var data = {}; document.$saveTo(data); @@ -117,11 +117,11 @@ nglr.DataStore.prototype.remove = function(document, callback) { } } }); - (callback||nglr.noop)(response); + (callback||noop)(response); }); }; -nglr.DataStore.prototype._jsonRequest = function(request, callback, failure) { +DataStore.prototype._jsonRequest = function(request, callback, failure) { request.$$callback = callback; request.$$failure = failure||function(response){ throw response; @@ -129,7 +129,7 @@ nglr.DataStore.prototype._jsonRequest = function(request, callback, failure) { this.bulkRequest.push(request); }; -nglr.DataStore.prototype.flush = function() { +DataStore.prototype.flush = function() { if (this.bulkRequest.length === 0) return; var self = this; var bulkRequest = this.bulkRequest; @@ -142,7 +142,7 @@ nglr.DataStore.prototype.flush = function() { self.post(bulkRequest, callback); }); } else if(bulkResponse.$status_code) { - nglr.alert(nglr.toJson(bulkResponse)); + alert(toJson(bulkResponse)); } else { for ( var i = 0; i < bulkResponse.length; i++) { var response = bulkResponse[i]; @@ -163,7 +163,7 @@ nglr.DataStore.prototype.flush = function() { this.post(bulkRequest, callback); }; -nglr.DataStore.prototype.saveScope = function(scope, callback) { +DataStore.prototype.saveScope = function(scope, callback) { var saveCounter = 1; function onSaveDone() { saveCounter--; @@ -172,7 +172,7 @@ nglr.DataStore.prototype.saveScope = function(scope, callback) { } for(var key in scope) { var item = scope[key]; - if (item && item.$save == nglr.Model.prototype.$save) { + if (item && item.$save == Model.prototype.$save) { saveCounter++; item.$save(onSaveDone); } @@ -180,7 +180,7 @@ nglr.DataStore.prototype.saveScope = function(scope, callback) { onSaveDone(); }; -nglr.DataStore.prototype.query = function(type, query, arg, callback){ +DataStore.prototype.query = function(type, query, arg, callback){ var self = this; var queryList = []; queryList.$$accept = function(doc){ @@ -200,7 +200,7 @@ nglr.DataStore.prototype.query = function(type, query, arg, callback){ return queryList; }; -nglr.DataStore.prototype.entities = function(callback) { +DataStore.prototype.entities = function(callback) { var entities = []; var self = this; this._jsonRequest(["GET", "$entities"], function(response) { @@ -213,7 +213,7 @@ nglr.DataStore.prototype.entities = function(callback) { return entities; }; -nglr.DataStore.prototype.documentCountsByUser = function(){ +DataStore.prototype.documentCountsByUser = function(){ var counts = {}; var self = this; self.post([["GET", "$users"]], function(code, response){ @@ -224,7 +224,7 @@ nglr.DataStore.prototype.documentCountsByUser = function(){ return counts; }; -nglr.DataStore.prototype.userDocumentIdsByEntity = function(user){ +DataStore.prototype.userDocumentIdsByEntity = function(user){ var ids = {}; var self = this; self.post([["GET", "$users/" + user]], function(code, response){ @@ -235,19 +235,19 @@ nglr.DataStore.prototype.userDocumentIdsByEntity = function(user){ return ids; }; -nglr.DataStore.NullEntity = function(){}; -nglr.DataStore.NullEntity.all = function(){return [];}; -nglr.DataStore.NullEntity.query = function(){return [];}; -nglr.DataStore.NullEntity.load = function(){return {};}; -nglr.DataStore.NullEntity.title = undefined; +DataStore.NullEntity = function(){}; +DataStore.NullEntity.all = function(){return [];}; +DataStore.NullEntity.query = function(){return [];}; +DataStore.NullEntity.load = function(){return {};}; +DataStore.NullEntity.title = undefined; -nglr.DataStore.prototype.entity = function(name, defaults){ +DataStore.prototype.entity = function(name, defaults){ if (!name) { - return nglr.DataStore.NullEntity; + return DataStore.NullEntity; } var self = this; var entity = function(initialState){ - return new nglr.Model(entity, initialState); + return new Model(entity, initialState); }; // entity.name does not work as name seems to be reserved for functions entity.title = name; @@ -275,7 +275,7 @@ nglr.DataStore.prototype.entity = function(name, defaults){ return entity; }; -nglr.DataStore.prototype.join = function(join){ +DataStore.prototype.join = function(join){ var fn = function(){ throw "Joined entities can not be instantiated into a document."; }; @@ -312,7 +312,7 @@ nglr.DataStore.prototype.join = function(join){ var row = {}; joinedResult.push(row); row[baseName] = doc; - var id = nglr.Scope.getter(row, nextJoinOn); + var id = Scope.getter(row, nextJoinOn); joinIds[id] = id; }); nextJoin.join.loadMany(_.toArray(joinIds), function(result){ @@ -321,7 +321,7 @@ nglr.DataStore.prototype.join = function(join){ byId[doc.$id] = doc; }); _(joinedResult).each(function(row){ - var id = nglr.Scope.getter(row, nextJoinOn); + var id = Scope.getter(row, nextJoinOn); row[nextJoinName] = byId[id]; }); }); diff --git a/src/Filters.js b/src/Filters.js index f75f3603..dd4217be 100644 --- a/src/Filters.js +++ b/src/Filters.js @@ -60,11 +60,11 @@ angular.filter.date = function(amount) { angular.filter.json = function(object) { jQuery(this.element).addClass("ng-monospace"); - return nglr.toJson(object, true); + return toJson(object, true); }; angular.filter.trackPackage = function(trackingNo, noMatch) { - trackingNo = nglr.trim(trackingNo); + trackingNo = trim(trackingNo); var tNo = trackingNo.replace(/ /g, ''); var MATCHERS = angular.filter.trackPackage.MATCHERS; for ( var i = 0; i < MATCHERS.length; i++) { @@ -77,7 +77,7 @@ angular.filter.trackPackage = function(trackingNo, noMatch) { return new angular.filter.Meta({ text:text, url:url, - html: '' + text + '', + html: '' + text + '', trackingNo:trackingNo}); } } @@ -115,7 +115,7 @@ angular.filter.link = function(obj, title) { if (angular.validator.email(url) === null) { url = "mailto:" + url; } - var html = '' + text + ''; + var html = '' + text + ''; return new angular.filter.Meta({text:text, url:url, html:html}); } return obj; diff --git a/src/JSON.js b/src/JSON.js index 2b6393bf..84c9a857 100644 --- a/src/JSON.js +++ b/src/JSON.js @@ -1,18 +1,18 @@ -nglr.array = [].constructor; +array = [].constructor; -nglr.toJson = function(obj, pretty){ +toJson = function(obj, pretty){ var buf = []; - nglr.toJsonArray(buf, obj, pretty ? "\n " : null); + toJsonArray(buf, obj, pretty ? "\n " : null); return buf.join(''); }; -nglr.toPrettyJson = function(obj) { - return nglr.toJson(obj, true); +toPrettyJson = function(obj) { + return toJson(obj, true); }; -nglr.fromJson = function(json) { +fromJson = function(json) { try { - var parser = new nglr.Parser(json, true); + var parser = new Parser(json, true); var expression = parser.primary(); parser.assertAllConsumed(); return expression(); @@ -23,7 +23,7 @@ nglr.fromJson = function(json) { }; -nglr.toJsonArray = function(buf, obj, pretty){ +toJsonArray = function(buf, obj, pretty){ var type = typeof obj; if (obj === null) { buf.push("null"); @@ -50,7 +50,7 @@ nglr.toJsonArray = function(buf, obj, pretty){ if (typeof item == 'function' || typeof item == 'undefined') { buf.push("null"); } else { - nglr.toJsonArray(buf, item, pretty); + toJsonArray(buf, item, pretty); } sep = true; } @@ -80,7 +80,7 @@ nglr.toJsonArray = function(buf, obj, pretty){ } buf.push(angular.String.quote(key)); buf.push(":"); - nglr.toJsonArray(buf, value, childPretty); + toJsonArray(buf, value, childPretty); comma = true; } } catch (e) { diff --git a/src/Loader.js b/src/Loader.js index eae6e4f5..dfaa355a 100644 --- a/src/Loader.js +++ b/src/Loader.js @@ -22,34 +22,37 @@ if (typeof Node == 'undefined') { }; } -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)) +var callbacks = {}; + +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 (_.isUndefined(nglr.alert)) { - nglr.alert = function(){console.log(arguments); window.alert.apply(window, arguments); }; +if (_.isUndefined(alert)) { + alert = function(){console.log(arguments); window.alert.apply(window, arguments); }; } -nglr.consoleLog = function(level, objs) { +var consoleNode; + +consoleLog = function(level, objs) { var log = document.createElement("div"); log.className = level; var msg = ""; var sep = ""; for ( var i = 0; i < objs.length; i++) { var obj = objs[i]; - msg += sep + (typeof obj == 'string' ? obj : nglr.toJson(obj)); + msg += sep + (typeof obj == 'string' ? obj : toJson(obj)); sep = " "; } log.appendChild(document.createTextNode(msg)); - nglr.consoleNode.appendChild(log); + consoleNode.appendChild(log); }; -nglr.isNode = function(inp) { +isNode = function(inp) { return inp && inp.tagName && inp.nodeName && @@ -57,7 +60,7 @@ nglr.isNode = function(inp) { inp.removeAttribute; }; -nglr.isLeafNode = function(node) { +isLeafNode = function(node) { switch (node.nodeName) { case "OPTION": case "PRE": @@ -68,11 +71,11 @@ nglr.isLeafNode = function(node) { } }; -nglr.noop = function() { +noop = function() { }; -nglr.setHtml = function(node, html) { - if (nglr.isLeafNode(node)) { - if (nglr.msie) { +setHtml = function(node, html) { + if (isLeafNode(node)) { + if (msie) { node.innerText = html; } else { node.textContent = html; @@ -82,7 +85,7 @@ nglr.setHtml = function(node, html) { } }; -nglr.escapeHtml = function(html) { +escapeHtml = function(html) { if (!html || !html.replace) return html; return html. @@ -91,14 +94,14 @@ nglr.escapeHtml = function(html) { replace(/>/g, '>'); }; -nglr.escapeAttr = function(html) { +escapeAttr = function(html) { if (!html || !html.replace) return html; return html.replace(//g, '>').replace(/\"/g, '"'); }; -nglr.bind = function(_this, _function) { +bind = function(_this, _function) { if (!_this) throw "Missing this"; if (!_.isFunction(_function)) @@ -108,7 +111,7 @@ nglr.bind = function(_this, _function) { }; }; -nglr.shiftBind = function(_this, _function) { +shiftBind = function(_this, _function) { return function() { var args = [ this ]; for ( var i = 0; i < arguments.length; i++) { @@ -118,7 +121,7 @@ nglr.shiftBind = function(_this, _function) { }; }; -nglr.outerHTML = function(node) { +outerHTML = function(node) { var temp = document.createElement('div'); temp.appendChild(node); var outerHTML = temp.innerHTML; @@ -126,26 +129,26 @@ nglr.outerHTML = function(node) { return outerHTML; }; -nglr.trim = function(str) { +trim = function(str) { return str.replace(/^ */, '').replace(/ *$/, ''); }; -nglr.toBoolean = function(value) { +toBoolean = function(value) { var v = ("" + value).toLowerCase(); if (v == 'f' || v == '0' || v == 'false' || v == 'no') value = false; return !!value; }; -nglr.merge = function(src, dst) { +merge = function(src, dst) { for ( var key in src) { var value = dst[key]; var type = typeof value; if (type == 'undefined') { - dst[key] = nglr.fromJson(nglr.toJson(src[key])); - } else if (type == 'object' && value.constructor != nglr.array && + dst[key] = fromJson(toJson(src[key])); + } else if (type == 'object' && value.constructor != array && key.substring(0, 1) != "$") { - nglr.merge(src[key], value); + merge(src[key], value); } } }; @@ -154,25 +157,25 @@ nglr.merge = function(src, dst) { // Loader // //////////////////////////// -nglr.Loader = function(document, head, config) { +Loader = function(document, head, config) { this.document = jQuery(document); this.head = jQuery(head); this.config = config; this.location = window.location; }; -nglr.Loader.prototype.load = function() { +Loader.prototype.load = function() { this.configureLogging(); this.loadCss('/stylesheets/jquery-ui/smoothness/jquery-ui-1.7.1.css'); - this.loadCss('/stylesheets/nglr.css'); + this.loadCss('/stylesheets/css'); console.log("Server: " + this.config.server); - nglr.msie = jQuery.browser.msie; + msie = jQuery.browser.msie; this.configureJQueryPlugins(); this.computeConfiguration(); this.bindHtml(); }; -nglr.Loader.prototype.configureJQueryPlugins = function() { +Loader.prototype.configureJQueryPlugins = function() { console.log('Loader.configureJQueryPlugins()'); jQuery.fn.removeNode = function() { var node = this.get(0); @@ -189,15 +192,15 @@ nglr.Loader.prototype.configureJQueryPlugins = function() { return null; }; jQuery.fn.controller = function() { - return this.data('controller') || nglr.NullController.instance; + return this.data('controller') || NullController.instance; }; }; -nglr.Loader.prototype.uid = function() { +Loader.prototype.uid = function() { return "" + new Date().getTime(); }; -nglr.Loader.prototype.computeConfiguration = function() { +Loader.prototype.computeConfiguration = function() { var config = this.config; if (!config.database) { var match = config.server.match(/https?:\/\/([\w]*)/); @@ -205,27 +208,27 @@ nglr.Loader.prototype.computeConfiguration = function() { } }; -nglr.Loader.prototype.bindHtml = function() { +Loader.prototype.bindHtml = function() { console.log('Loader.bindHtml()'); - var watcher = new nglr.UrlWatcher(this.location); + var watcher = new UrlWatcher(this.location); var document = this.document; - var widgetFactory = new nglr.WidgetFactory(this.config.server, this.config.database); - var binder = new nglr.Binder(document[0], widgetFactory, watcher, this.config); - widgetFactory.onChangeListener = nglr.shiftBind(binder, binder.updateModel); - var controlBar = new nglr.ControlBar(document.find('body'), this.config.server); + 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 nglr.FrameServer(this.window) : - new nglr.Server(this.config.server, jQuery.getScript); - server = new nglr.VisualServer(server, new nglr.Status(jQuery(document.body)), onUpdate); - var users = new nglr.Users(server, controlBar); + 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 nglr.DataStore(post, users, binder.anchor); + var datastore = new DataStore(post, users, binder.anchor); binder.updateListeners.push(function(){datastore.flush();}); - var scope = new nglr.Scope( { + var scope = new Scope( { $anchor : binder.anchor, $binder : binder, $config : this.config, @@ -241,7 +244,7 @@ nglr.Loader.prototype.bindHtml = function() { jQuery.each(["get", "set", "eval", "addWatchListener", "updateView"], function(i, method){ - angular[method] = nglr.bind(scope, scope[method]); + angular[method] = bind(scope, scope[method]); }); document.data('scope', scope); @@ -265,7 +268,7 @@ nglr.Loader.prototype.bindHtml = function() { fetchCurrentUser(); console.log('PopUp.bind()'); - new nglr.PopUp(document).bind(); + new PopUp(document).bind(); console.log('$binder.parseAnchor()'); binder.parseAnchor(); @@ -276,16 +279,16 @@ nglr.Loader.prototype.bindHtml = function() { console.log('$binder.updateView()'); binder.updateView(); - watcher.listener = nglr.bind(binder, binder.onUrlChange, watcher); - watcher.onUpdate = function(){nglr.alert("update");}; + watcher.listener = bind(binder, binder.onUrlChange, watcher); + watcher.onUpdate = function(){alert("update");}; watcher.watch(); document.find("body").show(); console.log('ready()'); }; -nglr.Loader.prototype.visualPost = function(delegate) { - var status = new nglr.Status(jQuery(document.body)); +Loader.prototype.visualPost = function(delegate) { + var status = new Status(jQuery(document.body)); return function(request, delegateCallback) { status.beginRequest(request); var callback = function() { @@ -293,14 +296,14 @@ nglr.Loader.prototype.visualPost = function(delegate) { try { delegateCallback.apply(this, arguments); } catch (e) { - nglr.alert(nglr.toJson(e)); + alert(toJson(e)); } }; delegate(request, callback); }; }; -nglr.Loader.prototype.configureLogging = function() { +Loader.prototype.configureLogging = function() { var url = window.location.href + '#'; url = url.split('#')[1]; var config = { @@ -312,19 +315,19 @@ nglr.Loader.prototype.configureLogging = function() { config[part[0]] = part[1]; } if (config.debug == 'console') { - nglr.consoleNode = document.createElement("div"); - nglr.consoleNode.id = 'ng-console'; - document.getElementsByTagName('body')[0].appendChild(nglr.consoleNode); + consoleNode = document.createElement("div"); + consoleNode.id = 'ng-console'; + document.getElementsByTagName('body')[0].appendChild(consoleNode); console.log = function() { - nglr.consoleLog('ng-console-info', arguments); + consoleLog('ng-console-info', arguments); }; console.error = function() { - nglr.consoleLog('ng-console-error', arguments); + consoleLog('ng-console-error', arguments); }; } }; -nglr.Loader.prototype.loadCss = function(css) { +Loader.prototype.loadCss = function(css) { var cssTag = document.createElement('link'); cssTag.rel = "stylesheet"; cssTag.type = "text/css"; @@ -334,7 +337,7 @@ nglr.Loader.prototype.loadCss = function(css) { this.head[0].appendChild(cssTag); }; -nglr.UrlWatcher = function(location) { +UrlWatcher = function(location) { this.location = location; this.delay = 25; this.setTimeout = function(fn, delay) { @@ -346,7 +349,7 @@ nglr.UrlWatcher = function(location) { this.expectedUrl = location.href; }; -nglr.UrlWatcher.prototype.watch = function() { +UrlWatcher.prototype.watch = function() { var self = this; var pull = function() { if (self.expectedUrl !== self.location.href) { @@ -357,12 +360,12 @@ nglr.UrlWatcher.prototype.watch = function() { } self.location.href = self.expectedUrl; var id = '_iframe_notify_' + notify[1]; - var notifyFn = nglr[id]; - delete nglr[id]; + var notifyFn = callbacks[id]; + delete callbacks[id]; try { - (notifyFn||nglr.noop)(); + (notifyFn||noop)(); } catch (e) { - nglr.alert(e); + alert(e); } } else { self.listener(self.location.href); @@ -374,16 +377,16 @@ nglr.UrlWatcher.prototype.watch = function() { pull(); }; -nglr.UrlWatcher.prototype.setUrl = function(url) { +UrlWatcher.prototype.setUrl = function(url) { var existingURL = window.location.href; if (!existingURL.match(/#/)) existingURL += '#'; if (existingURL != url) window.location.href = url; - self.existingURL = url; + this.existingURL = url; }; -nglr.UrlWatcher.prototype.getUrl = function() { +UrlWatcher.prototype.getUrl = function() { return window.location.href; }; @@ -394,7 +397,7 @@ angular['compile'] = function(root, config) { }; //todo: don't load stylesheet by default //todo: don't start watcher - var loader = new nglr.Loader(root, jQuery("head"), _(defaults).extend(config)); + var loader = new Loader(root, jQuery("head"), _(defaults).extend(config)); loader.load(); return jQuery(root).scope(); }; diff --git a/src/Model.js b/src/Model.js index 5e48251f..35f6a1c1 100644 --- a/src/Model.js +++ b/src/Model.js @@ -3,14 +3,14 @@ // Single $ is special and does not get searched // Double $$ is special an is client only (does not get sent to server) -nglr.Model = function(entity, initial) { +Model = function(entity, initial) { this.$$entity = entity; this.$loadFrom(initial||{}); this.$entity = entity.title; this.$migrate(); }; -nglr.Model.copyDirectFields = function(src, dst) { +Model.copyDirectFields = function(src, dst) { if (src === dst || !src || !dst) return; var isDataField = function(src, dst, field) { return (field.substring(0,2) !== '$$') && @@ -27,39 +27,39 @@ nglr.Model.copyDirectFields = function(src, dst) { } }; -nglr.Model.prototype.$migrate = function() { - nglr.merge(this.$$entity.defaults, this); +Model.prototype.$migrate = function() { + merge(this.$$entity.defaults, this); return this; }; -nglr.Model.prototype.$merge = function(other) { - nglr.merge(other, this); +Model.prototype.$merge = function(other) { + merge(other, this); return this; }; -nglr.Model.prototype.$save = function(callback) { +Model.prototype.$save = function(callback) { this.$$entity.datastore.save(this, callback === true ? undefined : callback); if (callback === true) this.$$entity.datastore.flush(); return this; }; -nglr.Model.prototype.$delete = function(callback) { +Model.prototype.$delete = function(callback) { this.$$entity.datastore.remove(this, callback === true ? undefined : callback); if (callback === true) this.$$entity.datastore.flush(); return this; }; -nglr.Model.prototype.$loadById = function(id, callback) { +Model.prototype.$loadById = function(id, callback) { this.$$entity.datastore.load(this, id, callback); return this; }; -nglr.Model.prototype.$loadFrom = function(other) { - nglr.Model.copyDirectFields(other, this); +Model.prototype.$loadFrom = function(other) { + Model.copyDirectFields(other, this); return this; }; -nglr.Model.prototype.$saveTo = function(other) { - nglr.Model.copyDirectFields(this, other); +Model.prototype.$saveTo = function(other) { + Model.copyDirectFields(this, other); return this; }; diff --git a/src/Parser.js b/src/Parser.js index 3d72bebf..b23215be 100644 --- a/src/Parser.js +++ b/src/Parser.js @@ -1,4 +1,4 @@ -nglr.Lexer = function(text, parsStrings){ +Lexer = function(text, parsStrings){ this.text = text; // UTC dates have 20 characters, we send them through parser this.dateParseLength = parsStrings ? 20 : -1; @@ -6,7 +6,7 @@ nglr.Lexer = function(text, parsStrings){ this.index = 0; }; -nglr.Lexer.OPERATORS = { +Lexer.OPERATORS = { 'null':function(self){return null;}, 'true':function(self){return true;}, 'false':function(self){return false;}, @@ -31,7 +31,7 @@ nglr.Lexer.OPERATORS = { '!':function(self, a){return !a;} }; -nglr.Lexer.prototype.peek = function() { +Lexer.prototype.peek = function() { if (this.index + 1 < this.text.length) { return this.text.charAt(this.index + 1); } else { @@ -39,9 +39,9 @@ nglr.Lexer.prototype.peek = function() { } }; -nglr.Lexer.prototype.parse = function() { +Lexer.prototype.parse = function() { var tokens = this.tokens; - var OPERATORS = nglr.Lexer.OPERATORS; + var OPERATORS = Lexer.OPERATORS; var canStartRegExp = true; while (this.index < this.text.length) { var ch = this.text.charAt(this.index); @@ -102,22 +102,22 @@ nglr.Lexer.prototype.parse = function() { return tokens; }; -nglr.Lexer.prototype.isNumber = function(ch) { +Lexer.prototype.isNumber = function(ch) { return '0' <= ch && ch <= '9'; }; -nglr.Lexer.prototype.isWhitespace = function(ch) { +Lexer.prototype.isWhitespace = function(ch) { return ch == ' ' || ch == '\r' || ch == '\t' || ch == '\n' || ch == '\v'; }; -nglr.Lexer.prototype.isIdent = function(ch) { +Lexer.prototype.isIdent = function(ch) { return 'a' <= ch && ch <= 'z' || 'A' <= ch && ch <= 'Z' || '_' == ch || ch == '$'; }; -nglr.Lexer.prototype.readNumber = function() { +Lexer.prototype.readNumber = function() { var number = ""; var start = this.index; while (this.index < this.text.length) { @@ -134,7 +134,7 @@ nglr.Lexer.prototype.readNumber = function() { fn:function(){return number;}}); }; -nglr.Lexer.prototype.readIdent = function() { +Lexer.prototype.readIdent = function() { var ident = ""; var start = this.index; while (this.index < this.text.length) { @@ -146,7 +146,7 @@ nglr.Lexer.prototype.readIdent = function() { } this.index++; } - var fn = nglr.Lexer.OPERATORS[ident]; + var fn = Lexer.OPERATORS[ident]; if (!fn) { fn = function(self){ return self.scope.get(ident); @@ -155,8 +155,8 @@ nglr.Lexer.prototype.readIdent = function() { } this.tokens.push({index:start, text:ident, fn:fn}); }; -nglr.Lexer.ESCAPE = {"n":"\n", "f":"\f", "r":"\r", "t":"\t", "v":"\v", "'":"'", '"':'"'}; -nglr.Lexer.prototype.readString = function(quote) { +Lexer.ESCAPE = {"n":"\n", "f":"\f", "r":"\r", "t":"\t", "v":"\v", "'":"'", '"':'"'}; +Lexer.prototype.readString = function(quote) { var start = this.index; var dateParseLength = this.dateParseLength; this.index++; @@ -170,7 +170,7 @@ nglr.Lexer.prototype.readString = function(quote) { this.index += 4; string += String.fromCharCode(parseInt(hex, 16)); } else { - var rep = nglr.Lexer.ESCAPE[ch]; + var rep = Lexer.ESCAPE[ch]; if (rep) { string += rep; } else { @@ -198,7 +198,7 @@ nglr.Lexer.prototype.readString = function(quote) { (start+1) + "' in expression '" + this.text + "'."; }; -nglr.Lexer.prototype.readRegexp = function(quote) { +Lexer.prototype.readRegexp = function(quote) { var start = this.index; this.index++; var regexp = ""; @@ -233,30 +233,30 @@ nglr.Lexer.prototype.readRegexp = function(quote) { }; -nglr.Parser = function(text, parseStrings){ +Parser = function(text, parseStrings){ this.text = text; - this.tokens = new nglr.Lexer(text, parseStrings).parse(); + this.tokens = new Lexer(text, parseStrings).parse(); this.index = 0; }; -nglr.Parser.ZERO = function(){ +Parser.ZERO = function(){ return 0; }; -nglr.Parser.prototype.error = function(msg, token) { +Parser.prototype.error = function(msg, token) { throw "Token '" + token.text + "' is " + msg + " at column='" + (token.index + 1) + "' of expression '" + this.text + "' starting at '" + this.text.substring(token.index) + "'."; }; -nglr.Parser.prototype.peekToken = function() { +Parser.prototype.peekToken = function() { if (this.tokens.length === 0) throw "Unexpected end of expression: " + this.text; return this.tokens[0]; }; -nglr.Parser.prototype.peek = function(e1, e2, e3, e4) { +Parser.prototype.peek = function(e1, e2, e3, e4) { var tokens = this.tokens; if (tokens.length > 0) { var token = tokens[0]; @@ -269,7 +269,7 @@ nglr.Parser.prototype.peek = function(e1, e2, e3, e4) { return false; }; -nglr.Parser.prototype.expect = function(e1, e2, e3, e4){ +Parser.prototype.expect = function(e1, e2, e3, e4){ var token = this.peek(e1, e2, e3, e4); if (token) { this.tokens.shift(); @@ -279,7 +279,7 @@ nglr.Parser.prototype.expect = function(e1, e2, e3, e4){ return false; }; -nglr.Parser.prototype.consume = function(e1){ +Parser.prototype.consume = function(e1){ if (!this.expect(e1)) { var token = this.peek(); throw "Expecting '" + e1 + "' at column '" + @@ -289,32 +289,32 @@ nglr.Parser.prototype.consume = function(e1){ } }; -nglr.Parser.prototype._unary = function(fn, parse) { +Parser.prototype._unary = function(fn, parse) { var right = parse.apply(this); return function(self) { return fn(self, right(self)); }; }; -nglr.Parser.prototype._binary = function(left, fn, parse) { +Parser.prototype._binary = function(left, fn, parse) { var right = parse.apply(this); return function(self) { return fn(self, left(self), right(self)); }; }; -nglr.Parser.prototype.hasTokens = function () { +Parser.prototype.hasTokens = function () { return this.tokens.length > 0; }; -nglr.Parser.prototype.assertAllConsumed = function(){ +Parser.prototype.assertAllConsumed = function(){ if (this.tokens.length !== 0) { throw "Did not understand '" + this.text.substring(this.tokens[0].index) + "' while evaluating '" + this.text + "'."; } }; -nglr.Parser.prototype.statements = function(){ +Parser.prototype.statements = function(){ var statements = []; while(true) { if (this.tokens.length > 0 && !this.peek('}', ')', ';', ']')) @@ -333,7 +333,7 @@ nglr.Parser.prototype.statements = function(){ } }; -nglr.Parser.prototype.filterChain = function(){ +Parser.prototype.filterChain = function(){ var left = this.expression(); var token; while(true) { @@ -345,15 +345,15 @@ nglr.Parser.prototype.filterChain = function(){ } }; -nglr.Parser.prototype.filter = function(){ +Parser.prototype.filter = function(){ return this._pipeFunction(angular.filter); }; -nglr.Parser.prototype.validator = function(){ +Parser.prototype.validator = function(){ return this._pipeFunction(angular.validator); }; -nglr.Parser.prototype._pipeFunction = function(fnScope){ +Parser.prototype._pipeFunction = function(fnScope){ var fn = this.functionIdent(fnScope); var argsFn = []; var token; @@ -375,11 +375,11 @@ nglr.Parser.prototype._pipeFunction = function(fnScope){ } }; -nglr.Parser.prototype.expression = function(){ +Parser.prototype.expression = function(){ return this.throwStmt(); }; -nglr.Parser.prototype.throwStmt = function(){ +Parser.prototype.throwStmt = function(){ if (this.expect('throw')) { var throwExp = this.assignment(); return function (self) { @@ -390,7 +390,7 @@ nglr.Parser.prototype.throwStmt = function(){ } }; -nglr.Parser.prototype.assignment = function(){ +Parser.prototype.assignment = function(){ var left = this.logicalOR(); var token; if (token = this.expect('=')) { @@ -406,7 +406,7 @@ nglr.Parser.prototype.assignment = function(){ } }; -nglr.Parser.prototype.logicalOR = function(){ +Parser.prototype.logicalOR = function(){ var left = this.logicalAND(); var token; while(true) { @@ -418,7 +418,7 @@ nglr.Parser.prototype.logicalOR = function(){ } }; -nglr.Parser.prototype.logicalAND = function(){ +Parser.prototype.logicalAND = function(){ var left = this.negated(); var token; while(true) { @@ -430,7 +430,7 @@ nglr.Parser.prototype.logicalAND = function(){ } }; -nglr.Parser.prototype.negated = function(){ +Parser.prototype.negated = function(){ var token; if (token = this.expect('!')) { return this._unary(token.fn, this.equality); @@ -439,7 +439,7 @@ nglr.Parser.prototype.negated = function(){ } }; -nglr.Parser.prototype.equality = function(){ +Parser.prototype.equality = function(){ var left = this.relational(); var token; while(true) { @@ -451,7 +451,7 @@ nglr.Parser.prototype.equality = function(){ } }; -nglr.Parser.prototype.relational = function(){ +Parser.prototype.relational = function(){ var left = this.additive(); var token; while(true) { @@ -463,7 +463,7 @@ nglr.Parser.prototype.relational = function(){ } }; -nglr.Parser.prototype.additive = function(){ +Parser.prototype.additive = function(){ var left = this.multiplicative(); var token; while(token = this.expect('+','-')) { @@ -472,7 +472,7 @@ nglr.Parser.prototype.additive = function(){ return left; }; -nglr.Parser.prototype.multiplicative = function(){ +Parser.prototype.multiplicative = function(){ var left = this.unary(); var token; while(token = this.expect('*','/','%')) { @@ -481,18 +481,18 @@ nglr.Parser.prototype.multiplicative = function(){ return left; }; -nglr.Parser.prototype.unary = function(){ +Parser.prototype.unary = function(){ var token; if (this.expect('+')) { return this.primary(); } else if (token = this.expect('-')) { - return this._binary(nglr.Parser.ZERO, token.fn, this.multiplicative); + return this._binary(Parser.ZERO, token.fn, this.multiplicative); } else { return this.primary(); } }; -nglr.Parser.prototype.functionIdent = function(fnScope) { +Parser.prototype.functionIdent = function(fnScope) { var token = this.expect(); var element = token.text.split('.'); var instance = fnScope; @@ -509,7 +509,7 @@ nglr.Parser.prototype.functionIdent = function(fnScope) { return instance; }; -nglr.Parser.prototype.primary = function() { +Parser.prototype.primary = function() { var primary; if (this.expect('(')) { var expression = this.filterChain(); @@ -545,7 +545,7 @@ nglr.Parser.prototype.primary = function() { return primary; }; -nglr.Parser.prototype.closure = function(hasArgs) { +Parser.prototype.closure = function(hasArgs) { var args = []; if (hasArgs) { if (!this.expect(')')) { @@ -561,7 +561,7 @@ nglr.Parser.prototype.closure = function(hasArgs) { this.consume("}"); return function(self){ return function($){ - var scope = new nglr.Scope(self.scope.state); + var scope = new Scope(self.scope.state); scope.set('$', $); for ( var i = 0; i < args.length; i++) { scope.set(args[i], arguments[i]); @@ -571,16 +571,16 @@ nglr.Parser.prototype.closure = function(hasArgs) { }; }; -nglr.Parser.prototype.fieldAccess = function(object) { +Parser.prototype.fieldAccess = function(object) { var field = this.expect().text; var fn = function (self){ - return nglr.Scope.getter(object(self), field); + return Scope.getter(object(self), field); }; fn.isAssignable = field; return fn; }; -nglr.Parser.prototype.objectIndex = function(obj) { +Parser.prototype.objectIndex = function(obj) { var indexFn = this.expression(); this.consume(']'); if (this.expect('=')) { @@ -597,7 +597,7 @@ nglr.Parser.prototype.objectIndex = function(obj) { } }; -nglr.Parser.prototype.functionCall = function(fn) { +Parser.prototype.functionCall = function(fn) { var argsFn = []; if (this.peekToken().text != ')') { do { @@ -620,7 +620,7 @@ nglr.Parser.prototype.functionCall = function(fn) { }; // This is used with json array declaration -nglr.Parser.prototype.arrayDeclaration = function () { +Parser.prototype.arrayDeclaration = function () { var elementFns = []; if (this.peekToken().text != ']') { do { @@ -637,7 +637,7 @@ nglr.Parser.prototype.arrayDeclaration = function () { }; }; -nglr.Parser.prototype.object = function () { +Parser.prototype.object = function () { var keyValues = []; if (this.peekToken().text != '}') { do { @@ -659,7 +659,7 @@ nglr.Parser.prototype.object = function () { }; }; -nglr.Parser.prototype.entityDeclaration = function () { +Parser.prototype.entityDeclaration = function () { var decl = []; while(this.hasTokens()) { decl.push(this.entityDecl()); @@ -676,7 +676,7 @@ nglr.Parser.prototype.entityDeclaration = function () { }; }; -nglr.Parser.prototype.entityDecl = function () { +Parser.prototype.entityDecl = function () { var entity = this.expect().text; var instance; var defaults; @@ -705,7 +705,7 @@ nglr.Parser.prototype.entityDecl = function () { }; }; -nglr.Parser.prototype.watch = function () { +Parser.prototype.watch = function () { var decl = []; while(this.hasTokens()) { decl.push(this.watchDecl()); @@ -722,7 +722,7 @@ nglr.Parser.prototype.watch = function () { }; }; -nglr.Parser.prototype.watchDecl = function () { +Parser.prototype.watchDecl = function () { var anchorName = this.expect().text; this.consume(":"); var expression; diff --git a/src/Scope.js b/src/Scope.js index 45dd15a4..e3634cee 100644 --- a/src/Scope.js +++ b/src/Scope.js @@ -1,6 +1,6 @@ // Copyright (C) 2009 BRAT Tech LLC -nglr.Scope = function(initialState, name) { +Scope = function(initialState, name) { this.widgets = []; this.watchListeners = {}; this.name = name; @@ -14,9 +14,9 @@ nglr.Scope = function(initialState, name) { } }; -nglr.Scope.expressionCache = {}; +Scope.expressionCache = {}; -nglr.Scope.prototype.updateView = function() { +Scope.prototype.updateView = function() { var self = this; this.fireWatchers(); _.each(this.widgets, function(widget){ @@ -26,21 +26,21 @@ nglr.Scope.prototype.updateView = function() { }); }; -nglr.Scope.prototype.addWidget = function(controller) { +Scope.prototype.addWidget = function(controller) { if (controller) this.widgets.push(controller); }; -nglr.Scope.prototype.isProperty = function(exp) { +Scope.prototype.isProperty = function(exp) { for ( var i = 0; i < exp.length; i++) { var ch = exp.charAt(i); - if (ch!='.' && !nglr.Lexer.prototype.isIdent(ch)) { + if (ch!='.' && !Lexer.prototype.isIdent(ch)) { return false; } } return true; }; -nglr.Scope.getter = function(instance, path) { +Scope.getter = function(instance, path) { if (!path) return instance; var element = path.split('.'); var key; @@ -65,16 +65,16 @@ nglr.Scope.getter = function(instance, path) { } } if (typeof instance === 'function' && !instance.$$factory) { - return nglr.bind(lastInstance, instance); + return bind(lastInstance, instance); } return instance; }; -nglr.Scope.prototype.get = function(path) { - return nglr.Scope.getter(this.state, path); +Scope.prototype.get = function(path) { + return Scope.getter(this.state, path); }; -nglr.Scope.prototype.set = function(path, value) { +Scope.prototype.set = function(path, value) { var element = path.split('.'); var instance = this.state; for ( var i = 0; element.length > 1; i++) { @@ -90,17 +90,17 @@ nglr.Scope.prototype.set = function(path, value) { return value; }; -nglr.Scope.prototype.setEval = function(expressionText, value) { - this.eval(expressionText + "=" + nglr.toJson(value)); +Scope.prototype.setEval = function(expressionText, value) { + this.eval(expressionText + "=" + toJson(value)); }; -nglr.Scope.prototype.eval = function(expressionText, context) { - var expression = nglr.Scope.expressionCache[expressionText]; +Scope.prototype.eval = function(expressionText, context) { + var expression = Scope.expressionCache[expressionText]; if (!expression) { - var parser = new nglr.Parser(expressionText); + var parser = new Parser(expressionText); expression = parser.statements(); parser.assertAllConsumed(); - nglr.Scope.expressionCache[expressionText] = expression; + Scope.expressionCache[expressionText] = expression; } context = context || {}; context.scope = this; @@ -110,7 +110,7 @@ nglr.Scope.prototype.eval = function(expressionText, context) { //TODO: Refactor. This function needs to be an execution closure for widgets // move to widgets // remove expression, just have inner closure. -nglr.Scope.prototype.evalWidget = function(widget, expression, context, onSuccess, onFailure) { +Scope.prototype.evalWidget = function(widget, expression, context, onSuccess, onFailure) { try { var value = this.eval(expression, context); if (widget.hasError) { @@ -125,7 +125,7 @@ nglr.Scope.prototype.evalWidget = function(widget, expression, context, onSucces return true; } catch (e){ console.error('Eval Widget Error:', e); - var jsonError = nglr.toJson(e, true); + var jsonError = toJson(e, true); widget.hasError = true; jQuery(widget.view). addClass('ng-exception'). @@ -137,42 +137,42 @@ nglr.Scope.prototype.evalWidget = function(widget, expression, context, onSucces } }; -nglr.Scope.prototype.validate = function(expressionText, value) { - var expression = nglr.Scope.expressionCache[expressionText]; +Scope.prototype.validate = function(expressionText, value) { + var expression = Scope.expressionCache[expressionText]; if (!expression) { - expression = new nglr.Parser(expressionText).validator(); - nglr.Scope.expressionCache[expressionText] = expression; + expression = new Parser(expressionText).validator(); + Scope.expressionCache[expressionText] = expression; } var self = {scope:this}; return expression(self)(self, value); }; -nglr.Scope.prototype.entity = function(entityDeclaration) { - var expression = new nglr.Parser(entityDeclaration).entityDeclaration(); +Scope.prototype.entity = function(entityDeclaration) { + var expression = new Parser(entityDeclaration).entityDeclaration(); return expression({scope:this}); }; -nglr.Scope.prototype.markInvalid = function(widget) { +Scope.prototype.markInvalid = function(widget) { this.state.$invalidWidgets.push(widget); }; -nglr.Scope.prototype.watch = function(declaration) { +Scope.prototype.watch = function(declaration) { var self = this; - new nglr.Parser(declaration).watch()({ + new Parser(declaration).watch()({ scope:this, addListener:function(watch, exp){ self.addWatchListener(watch, function(n,o){ try { return exp({scope:self}, n, o); } catch(e) { - nglr.alert(e); + alert(e); } }); } }); }; -nglr.Scope.prototype.addWatchListener = function(watchExpression, listener) { +Scope.prototype.addWatchListener = function(watchExpression, listener) { var watcher = this.watchListeners[watchExpression]; if (!watcher) { watcher = {listeners:[], expression:watchExpression}; @@ -181,7 +181,7 @@ nglr.Scope.prototype.addWatchListener = function(watchExpression, listener) { watcher.listeners.push(listener); }; -nglr.Scope.prototype.fireWatchers = function() { +Scope.prototype.fireWatchers = function() { var self = this; var fired = false; jQuery.each(this.watchListeners, function(name, watcher) { diff --git a/src/Server.js b/src/Server.js index 94b0cc10..d00f893b 100644 --- a/src/Server.js +++ b/src/Server.js @@ -1,6 +1,6 @@ // Copyright (C) 2008,2009 BRAT Tech LLC -nglr.Server = function(url, getScript) { +Server = function(url, getScript) { this.url = url; this.nextId = 0; this.getScript = getScript; @@ -8,51 +8,51 @@ nglr.Server = function(url, getScript) { this.maxSize = 1800; }; -nglr.Server.prototype.base64url = function(txt) { +Server.prototype.base64url = function(txt) { return Base64.encode(txt); }; -nglr.Server.prototype.request = function(method, url, request, callback) { +Server.prototype.request = function(method, url, request, callback) { var requestId = this.uuid + (this.nextId++); - nglr[requestId] = function(response) { - delete nglr[requestId]; + callbacks[requestId] = function(response) { + delete angular[requestId]; callback(200, response); }; var payload = {u:url, m:method, p:request}; - payload = this.base64url(nglr.toJson(payload)); + payload = this.base64url(toJson(payload)); var totalPockets = Math.ceil(payload.length / this.maxSize); var baseUrl = this.url + "/$/" + requestId + "/" + totalPockets + "/"; for ( var pocketNo = 0; pocketNo < totalPockets; pocketNo++) { var pocket = payload.substr(pocketNo * this.maxSize, this.maxSize); - this.getScript(baseUrl + (pocketNo+1) + "?h=" + pocket, nglr.noop); + this.getScript(baseUrl + (pocketNo+1) + "?h=" + pocket, noop); } }; -nglr.FrameServer = function(frame) { +FrameServer = function(frame) { this.frame = frame; }; -nglr.FrameServer.PREFIX = "$DATASET:"; +FrameServer.PREFIX = "$DATASET:"; -nglr.FrameServer.prototype = { +FrameServer.prototype = { read:function(){ - this.data = nglr.fromJson(this.frame.name.substr(nglr.FrameServer.PREFIX.length)); + this.data = fromJson(this.frame.name.substr(FrameServer.PREFIX.length)); }, write:function(){ - this.frame.name = nglr.FrameServer.PREFIX + nglr.toJson(this.data); + this.frame.name = FrameServer.PREFIX + toJson(this.data); }, request: function(method, url, request, callback) { - //alert(method + " " + url + " " + nglr.toJson(request) + " " + nglr.toJson(callback)); + //alert(method + " " + url + " " + toJson(request) + " " + toJson(callback)); } }; -nglr.VisualServer = function(delegate, status, update) { +VisualServer = function(delegate, status, update) { this.delegate = delegate; this.update = update; this.status = status; }; -nglr.VisualServer.prototype = { +VisualServer.prototype = { request:function(method, url, request, callback) { var self = this; this.status.beginRequest(request); @@ -61,7 +61,7 @@ nglr.VisualServer.prototype = { try { callback.apply(this, arguments); } catch (e) { - nglr.alert(nglr.toJson(e)); + alert(toJson(e)); } self.update(); }); diff --git a/src/Users.js b/src/Users.js index c0c15848..d10b96df 100644 --- a/src/Users.js +++ b/src/Users.js @@ -1,10 +1,10 @@ // Copyright (C) 2008,2009 BRAT Tech LLC -nglr.Users = function(server, controlBar) { +Users = function(server, controlBar) { this.server = server; this.controlBar = controlBar; }; -nglr.Users.prototype = { +Users.prototype = { fetchCurrentUser:function(callback) { var self = this; this.server.request("GET", "/account.json", {}, function(code, response){ @@ -17,7 +17,7 @@ nglr.Users.prototype = { var self = this; this.controlBar.logout(function(){ delete self.current; - (callback||nglr.noop)(); + (callback||noop)(); }); }, @@ -25,7 +25,7 @@ nglr.Users.prototype = { var self = this; this.controlBar.login(function(){ self.fetchCurrentUser(function(){ - (callback||nglr.noop)(); + (callback||noop)(); }); }); }, diff --git a/src/Validators.js b/src/Validators.js index 94cb1d52..7cfaa2b4 100644 --- a/src/Validators.js +++ b/src/Validators.js @@ -72,7 +72,7 @@ angular.validator.url = function(value) { angular.validator.json = function(value) { try { - nglr.fromJson(value); + fromJson(value); return null; } catch (e) { return e.toString(); diff --git a/src/Widgets.js b/src/Widgets.js index de74533a..3a0f2845 100644 --- a/src/Widgets.js +++ b/src/Widgets.js @@ -1,7 +1,7 @@ // Copyright (C) 2009 BRAT Tech LLC -nglr.WidgetFactory = function(serverUrl, database) { +WidgetFactory = function(serverUrl, database) { this.nextUploadId = 0; this.serverUrl = serverUrl; this.database = database; @@ -9,7 +9,7 @@ nglr.WidgetFactory = function(serverUrl, database) { this.onChangeListener = function(){}; }; -nglr.WidgetFactory.prototype.createController = function(input, scope) { +WidgetFactory.prototype.createController = function(input, scope) { var controller; var type = input.attr('type').toLowerCase(); var exp = input.attr('name'); @@ -17,22 +17,22 @@ nglr.WidgetFactory.prototype.createController = function(input, scope) { var event = "change"; var bubbleEvent = true; if (type == 'button' || type == 'submit' || type == 'reset' || type == 'image') { - controller = new nglr.ButtonController(input[0], exp); + controller = new ButtonController(input[0], exp); event = "click"; bubbleEvent = false; } else if (type == 'text' || type == 'textarea' || type == 'hidden' || type == 'password') { - controller = new nglr.TextController(input[0], exp); + controller = new TextController(input[0], exp); event = "keyup change"; } else if (type == 'checkbox') { - controller = new nglr.CheckboxController(input[0], exp); + controller = new CheckboxController(input[0], exp); event = "click"; } else if (type == 'radio') { - controller = new nglr.RadioController(input[0], exp); + controller = new RadioController(input[0], exp); event="click"; } else if (type == 'select-one') { - controller = new nglr.SelectController(input[0], exp); + controller = new SelectController(input[0], exp); } else if (type == 'select-multiple') { - controller = new nglr.MultiSelectController(input[0], exp); + controller = new MultiSelectController(input[0], exp); } else if (type == 'file') { controller = this.createFileController(input, exp); } else { @@ -54,9 +54,9 @@ nglr.WidgetFactory.prototype.createController = function(input, scope) { return controller; }; -nglr.WidgetFactory.prototype.createFileController = function(fileInput) { +WidgetFactory.prototype.createFileController = function(fileInput) { var uploadId = '__uploadWidget_' + (this.nextUploadId++); - var view = nglr.FileController.template(uploadId); + var view = FileController.template(uploadId); fileInput.after(view); var att = { data:this.serverUrl + "/admin/ServerAPI.swf", @@ -67,13 +67,13 @@ nglr.WidgetFactory.prototype.createFileController = function(fileInput) { allowScriptAccess:"always"}; var swfNode = this.createSWF(att, par, uploadId); fileInput.remove(); - var cntl = new nglr.FileController(view, fileInput[0].name, swfNode, this.serverUrl + "/data/" + this.database); + var cntl = new FileController(view, fileInput[0].name, swfNode, this.serverUrl + "/data/" + this.database); jQuery(swfNode).data('controller', cntl); return cntl; }; -nglr.WidgetFactory.prototype.createTextWidget = function(textInput) { - var controller = new nglr.TextController(textInput); +WidgetFactory.prototype.createTextWidget = function(textInput) { + var controller = new TextController(textInput); controller.onChange(this.onChangeListener); return controller; }; @@ -82,7 +82,7 @@ nglr.WidgetFactory.prototype.createTextWidget = function(textInput) { // FileController /////////////////////// -nglr.FileController = function(view, scopeName, uploader, databaseUrl) { +FileController = function(view, scopeName, uploader, databaseUrl) { this.view = view; this.uploader = uploader; this.scopeName = scopeName; @@ -91,13 +91,13 @@ nglr.FileController = function(view, scopeName, uploader, databaseUrl) { this.lastValue = undefined; }; -nglr.FileController.dispatchEvent = function(id, event, args) { +FileController.dispatchEvent = function(id, event, args) { var object = document.getElementById(id); var controller = jQuery(object).data("controller"); - nglr.FileController.prototype['_on_' + event].apply(controller, args); + FileController.prototype['_on_' + event].apply(controller, args); }; -nglr.FileController.template = function(id) { +FileController.template = function(id) { return jQuery('' + '' + '' + @@ -106,33 +106,33 @@ nglr.FileController.template = function(id) { ''); }; -nglr.FileController.prototype._on_cancel = function() { +FileController.prototype._on_cancel = function() { }; -nglr.FileController.prototype._on_complete = function() { +FileController.prototype._on_complete = function() { }; -nglr.FileController.prototype._on_httpStatus = function(status) { - nglr.alert("httpStatus:" + this.scopeName + " status:" + status); +FileController.prototype._on_httpStatus = function(status) { + alert("httpStatus:" + this.scopeName + " status:" + status); }; -nglr.FileController.prototype._on_ioError = function() { - nglr.alert("ioError:" + this.scopeName); +FileController.prototype._on_ioError = function() { + alert("ioError:" + this.scopeName); }; -nglr.FileController.prototype._on_open = function() { - nglr.alert("open:" + this.scopeName); +FileController.prototype._on_open = function() { + alert("open:" + this.scopeName); }; -nglr.FileController.prototype._on_progress = function(bytesLoaded, bytesTotal) { +FileController.prototype._on_progress = function(bytesLoaded, bytesTotal) { }; -nglr.FileController.prototype._on_securityError = function() { - nglr.alert("securityError:" + this.scopeName); +FileController.prototype._on_securityError = function() { + alert("securityError:" + this.scopeName); }; -nglr.FileController.prototype._on_uploadCompleteData = function(data) { - var value = nglr.fromJson(data); +FileController.prototype._on_uploadCompleteData = function(data) { + var value = fromJson(data); value.url = this.attachmentsPath + '/' + value.id + '/' + value.text; this.view.find("input").attr('checked', true); var scope = this.view.scope(); @@ -142,14 +142,14 @@ nglr.FileController.prototype._on_uploadCompleteData = function(data) { scope.get('$binder').updateView(); }; -nglr.FileController.prototype._on_select = function(name, size, type) { +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.upload(); }; -nglr.FileController.prototype.updateModel = function(scope) { +FileController.prototype.updateModel = function(scope) { var isChecked = this.view.find("input").attr('checked'); var value = isChecked ? this.value : null; if (this.lastValue === value) { @@ -160,7 +160,7 @@ nglr.FileController.prototype.updateModel = function(scope) { } }; -nglr.FileController.prototype.updateView = function(scope) { +FileController.prototype.updateView = function(scope) { var modelValue = scope.get(this.scopeName); if (modelValue && this.value !== modelValue) { this.value = modelValue; @@ -172,7 +172,7 @@ nglr.FileController.prototype.updateView = function(scope) { this.view.find("input").attr('checked', !!modelValue); }; -nglr.FileController.prototype.upload = function() { +FileController.prototype.upload = function() { if (this.name) { this.uploader.uploadFile(this.attachmentsPath); } @@ -182,23 +182,23 @@ nglr.FileController.prototype.upload = function() { /////////////////////// // NullController /////////////////////// -nglr.NullController = function(view) {this.view = view;}; -nglr.NullController.prototype.updateModel = function() { return true; }; -nglr.NullController.prototype.updateView = function() { }; -nglr.NullController.instance = new nglr.NullController(); +NullController = function(view) {this.view = view;}; +NullController.prototype.updateModel = function() { return true; }; +NullController.prototype.updateView = function() { }; +NullController.instance = new NullController(); /////////////////////// // ButtonController /////////////////////// -nglr.ButtonController = function(view) {this.view = view;}; -nglr.ButtonController.prototype.updateModel = function(scope) { return true; }; -nglr.ButtonController.prototype.updateView = function(scope) {}; +ButtonController = function(view) {this.view = view;}; +ButtonController.prototype.updateModel = function(scope) { return true; }; +ButtonController.prototype.updateView = function(scope) {}; /////////////////////// // TextController /////////////////////// -nglr.TextController = function(view, exp) { +TextController = function(view, exp) { this.view = view; this.exp = exp; this.validator = view.getAttribute('ng-validate'); @@ -212,7 +212,7 @@ nglr.TextController = function(view, exp) { } }; -nglr.TextController.prototype.updateModel = function(scope) { +TextController.prototype.updateModel = function(scope) { var value = this.view.value; if (this.lastValue === value) { return false; @@ -223,7 +223,7 @@ nglr.TextController.prototype.updateModel = function(scope) { } }; -nglr.TextController.prototype.updateView = function(scope) { +TextController.prototype.updateView = function(scope) { var view = this.view; var value = scope.get(this.exp); if (typeof value === "undefined") { @@ -258,14 +258,14 @@ nglr.TextController.prototype.updateView = function(scope) { /////////////////////// // CheckboxController /////////////////////// -nglr.CheckboxController = function(view, exp) { +CheckboxController = function(view, exp) { this.view = view; this.exp = exp; this.lastValue = undefined; this.initialValue = view.checked ? view.value : ""; }; -nglr.CheckboxController.prototype.updateModel = function(scope) { +CheckboxController.prototype.updateModel = function(scope) { var input = this.view; var value = input.checked ? input.value : ''; if (this.lastValue === value) { @@ -277,7 +277,7 @@ nglr.CheckboxController.prototype.updateModel = function(scope) { } }; -nglr.CheckboxController.prototype.updateView = function(scope) { +CheckboxController.prototype.updateView = function(scope) { var input = this.view; var value = scope.eval(this.exp); if (typeof value === "undefined") { @@ -290,14 +290,14 @@ nglr.CheckboxController.prototype.updateView = function(scope) { /////////////////////// // SelectController /////////////////////// -nglr.SelectController = function(view, exp) { +SelectController = function(view, exp) { this.view = view; this.exp = exp; this.lastValue = undefined; this.initialValue = view.value; }; -nglr.SelectController.prototype.updateModel = function(scope) { +SelectController.prototype.updateModel = function(scope) { var input = this.view; if (input.selectedIndex < 0) { scope.setEval(this.exp, null); @@ -313,7 +313,7 @@ nglr.SelectController.prototype.updateModel = function(scope) { } }; -nglr.SelectController.prototype.updateView = function(scope) { +SelectController.prototype.updateView = function(scope) { var input = this.view; var value = scope.get(this.exp); if (typeof value === 'undefined') { @@ -329,14 +329,14 @@ nglr.SelectController.prototype.updateView = function(scope) { /////////////////////// // MultiSelectController /////////////////////// -nglr.MultiSelectController = function(view, exp) { +MultiSelectController = function(view, exp) { this.view = view; this.exp = exp; this.lastValue = undefined; this.initialValue = this.selected(); }; -nglr.MultiSelectController.prototype.selected = function () { +MultiSelectController.prototype.selected = function () { var value = []; var options = this.view.options; for ( var i = 0; i < options.length; i++) { @@ -348,7 +348,7 @@ nglr.MultiSelectController.prototype.selected = function () { return value; }; -nglr.MultiSelectController.prototype.updateModel = function(scope) { +MultiSelectController.prototype.updateModel = function(scope) { var value = this.selected(); // TODO: This is wrong! no caching going on here as we are always comparing arrays if (this.lastValue === value) { @@ -360,7 +360,7 @@ nglr.MultiSelectController.prototype.updateModel = function(scope) { } }; -nglr.MultiSelectController.prototype.updateView = function(scope) { +MultiSelectController.prototype.updateView = function(scope) { var input = this.view; var selected = scope.get(this.exp); if (typeof selected === "undefined") { @@ -380,7 +380,7 @@ nglr.MultiSelectController.prototype.updateView = function(scope) { /////////////////////// // RadioController /////////////////////// -nglr.RadioController = function(view, exp) { +RadioController = function(view, exp) { this.view = view; this.exp = exp; this.lastChecked = undefined; @@ -389,7 +389,7 @@ nglr.RadioController = function(view, exp) { this.initialValue = view.checked ? view.value : null; }; -nglr.RadioController.prototype.updateModel = function(scope) { +RadioController.prototype.updateModel = function(scope) { var input = this.view; if (this.lastChecked) { return false; @@ -401,7 +401,7 @@ nglr.RadioController.prototype.updateModel = function(scope) { } }; -nglr.RadioController.prototype.updateView = function(scope) { +RadioController.prototype.updateView = function(scope) { var input = this.view; var value = scope.get(this.exp); if (this.initialValue && typeof value === "undefined") { @@ -417,25 +417,25 @@ nglr.RadioController.prototype.updateView = function(scope) { /////////////////////// //ElementController /////////////////////// -nglr.BindUpdater = function(view, exp) { +BindUpdater = function(view, exp) { this.view = view; - this.exp = nglr.Binder.parseBindings(exp); + this.exp = Binder.parseBindings(exp); this.hasError = false; this.scopeSelf = {element:view}; }; -nglr.BindUpdater.toText = function(obj) { - var e = nglr.escapeHtml; +BindUpdater.toText = function(obj) { + var e = escapeHtml; switch(typeof obj) { case "string": case "boolean": case "number": return e(obj); case "function": - return nglr.BindUpdater.toText(obj()); + return BindUpdater.toText(obj()); case "object": - if (nglr.isNode(obj)) { - return nglr.outerHTML(obj); + if (isNode(obj)) { + return outerHTML(obj); } else if (obj instanceof angular.filter.Meta) { switch(typeof obj.html) { case "string": @@ -444,8 +444,8 @@ nglr.BindUpdater.toText = function(obj) { case "function": return obj.html(); case "object": - if (nglr.isNode(obj.html)) - return nglr.outerHTML(obj.html); + if (isNode(obj.html)) + return outerHTML(obj.html); default: break; } @@ -461,43 +461,43 @@ nglr.BindUpdater.toText = function(obj) { } if (obj === null) return ""; - return e(nglr.toJson(obj, true)); + return e(toJson(obj, true)); default: return ""; } }; -nglr.BindUpdater.prototype.updateModel = function(scope) {}; -nglr.BindUpdater.prototype.updateView = function(scope) { +BindUpdater.prototype.updateModel = function(scope) {}; +BindUpdater.prototype.updateView = function(scope) { var html = []; var parts = this.exp; var length = parts.length; for(var i=0; i' + - '' + - '' + - '' + - '' + - ''); -}; - -nglr.FileController.prototype._on_cancel = function() { -}; - -nglr.FileController.prototype._on_complete = function() { -}; - -nglr.FileController.prototype._on_httpStatus = function(status) { - nglr.alert("httpStatus:" + this.scopeName + " status:" + status); -}; - -nglr.FileController.prototype._on_ioError = function() { - nglr.alert("ioError:" + this.scopeName); -}; - -nglr.FileController.prototype._on_open = function() { - nglr.alert("open:" + this.scopeName); -}; - -nglr.FileController.prototype._on_progress = function(bytesLoaded, bytesTotal) { -}; - -nglr.FileController.prototype._on_securityError = function() { - nglr.alert("securityError:" + this.scopeName); -}; - -nglr.FileController.prototype._on_uploadCompleteData = function(data) { - this.value = nglr.fromJson(data); - this.value.url = this.attachmentBase + '/' + this.value.id + '/' + this.value.text; - this.view.find("input").attr('checked', true); - var scope = this.view.scope(); - this.updateModel(scope); - scope.get('$binder').updateView(); -}; - -nglr.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(filters.bytes(size)); - this.upload(); -}; - -nglr.FileController.prototype.updateModel = function(scope) { - var isChecked = this.view.find("input").attr('checked'); - var value = isChecked ? this.value : null; - if (this.lastValue === value) { - return false; - } else { - scope.set(this.scopeName, value); - return true; - } -}; - -nglr.FileController.prototype.updateView = function(scope) { - var modelValue = scope.get(this.scopeName); - if (modelValue && this.value !== modelValue) { - this.value = modelValue; - this.view.find("a"). - attr("href", this.value.url). - text(this.value.name); - this.view.find("span").text(filters.bytes(this.value.size)); - } - this.view.find("input").attr('checked', !!modelValue); -}; - -nglr.FileController.prototype.upload = function() { - if (this.name) { - this.uploader.uploadFile(this.uploadUrl); - } -}; - - -/////////////////////// -// NullController -/////////////////////// -nglr.NullController = function(view) {this.view = view;}; -nglr.NullController.prototype.updateModel = function() { return true; }; -nglr.NullController.prototype.updateView = function() { }; -nglr.NullController.instance = new nglr.NullController(); - - -/////////////////////// -// ButtonController -/////////////////////// -nglr.ButtonController = function(view) {this.view = view;}; -nglr.ButtonController.prototype.updateModel = function(scope) { return true; }; -nglr.ButtonController.prototype.updateView = function(scope) {}; - -/////////////////////// -// TextController -/////////////////////// -nglr.TextController = function(view, exp) { - this.view = view; - this.exp = exp; - this.validator = view.getAttribute('ng-validate'); - this.required = typeof view.attributes['ng-required'] != "undefined"; - this.lastErrorText = null; - this.lastValue = undefined; - this.initialValue = view.value; - var widget = view.getAttribute('ng-widget'); - if (widget === 'datepicker') { - jQuery(view).datepicker(); - } -}; - -nglr.TextController.prototype.updateModel = function(scope) { - var value = this.view.value; - if (this.lastValue === value) { - return false; - } else { - scope.set(this.exp, value); - this.lastValue = value; - return true; - } -}; - -nglr.TextController.prototype.updateView = function(scope) { - var view = this.view; - var value = scope.get(this.exp); - if (typeof value === "undefined") { - value = this.initialValue; - scope.set(this.exp, value); - } - value = value ? value : ''; - if (this.lastValue != value) { - view.value = value; - this.lastValue = value; - } - var isValidationError = false; - view.removeAttribute('ng-error'); - if (this.required) { - isValidationError = !(value && value.length > 0); - } - var errorText = isValidationError ? "Required Value" : null; - if (!isValidationError && this.validator && value) { - errorText = scope.validate(this.validator, value); - isValidationError = !!errorText; - } - if (this.lastErrorText !== errorText) { - this.lastErrorText = isValidationError; - if (errorText !== null) { - view.setAttribute('ng-error', errorText); - scope.markInvalid(this); - } - jQuery(view).toggleClass('ng-validation-error', isValidationError); - } -}; - -/////////////////////// -// CheckboxController -/////////////////////// -nglr.CheckboxController = function(view, exp) { - this.view = view; - this.exp = exp; - this.lastValue = undefined; - this.initialValue = view.checked ? view.value : ""; -}; - -nglr.CheckboxController.prototype.updateModel = function(scope) { - var input = this.view; - var value = input.checked ? input.value : ''; - if (this.lastValue === value) { - return false; - } else { - scope.setEval(this.exp, value); - this.lastValue = value; - return true; - } -}; - -nglr.CheckboxController.prototype.updateView = function(scope) { - var input = this.view; - var value = scope.eval(this.exp); - if (typeof value === "undefined") { - value = this.initialValue; - scope.setEval(this.exp, value); - } - input.checked = input.value == (''+value); -}; - -/////////////////////// -// SelectController -/////////////////////// -nglr.SelectController = function(view, exp) { - this.view = view; - this.exp = exp; - this.lastValue = undefined; - this.initialValue = view.value; -}; - -nglr.SelectController.prototype.updateModel = function(scope) { - var input = this.view; - if (input.selectedIndex < 0) { - scope.set(this.exp, null); - } else { - var value = this.view.value; - if (this.lastValue === value) { - return false; - } else { - scope.set(this.exp, value); - this.lastValue = value; - return true; - } - } -}; - -nglr.SelectController.prototype.updateView = function(scope) { - var input = this.view; - var value = scope.get(this.exp); - if (typeof value === 'undefined') { - value = this.initialValue; - scope.set(this.exp, value); - } - if (value !== this.lastValue) { - input.value = value ? value : ""; - this.lastValue = value; - } -}; - -/////////////////////// -// MultiSelectController -/////////////////////// -nglr.MultiSelectController = function(view, exp) { - this.view = view; - this.exp = exp; - this.lastValue = undefined; - this.initialValue = this.selected(); -}; - -nglr.MultiSelectController.prototype.selected = function () { - var value = []; - var options = this.view.options; - for ( var i = 0; i < options.length; i++) { - var option = options[i]; - if (option.selected) { - value.push(option.value); - } - } - return value; -}; - -nglr.MultiSelectController.prototype.updateModel = function(scope) { - var value = this.selected(); - // TODO: This is wrong! no caching going on here as we are always comparing arrays - if (this.lastValue === value) { - return false; - } else { - scope.set(this.exp, value); - this.lastValue = value; - return true; - } -}; - -nglr.MultiSelectController.prototype.updateView = function(scope) { - var input = this.view; - var selected = scope.get(this.exp); - if (typeof selected === "undefined") { - selected = this.initialValue; - scope.set(this.exp, selected); - } - if (selected !== this.lastValue) { - var options = input.options; - for ( var i = 0; i < options.length; i++) { - var option = options[i]; - option.selected = selected.contains(option.value); - } - this.lastValue = selected; - } -}; - -/////////////////////// -// RadioController -/////////////////////// -nglr.RadioController = function(view, exp) { - this.view = view; - this.exp = exp; - this.lastChecked = undefined; - this.lastValue = undefined; - this.inputValue = view.value; - this.initialValue = view.checked ? view.value : null; -}; - -nglr.RadioController.prototype.updateModel = function(scope) { - var input = this.view; - if (this.lastChecked) { - return false; - } else { - input.checked = true; - this.lastValue = scope.set(this.exp, this.inputValue); - this.lastChecked = true; - return true; - } -}; - -nglr.RadioController.prototype.updateView = function(scope) { - var input = this.view; - var value = scope.get(this.exp); - if (this.initialValue && typeof value === "undefined") { - value = this.initialValue; - scope.set(this.exp, value); - } - if (this.lastValue != value) { - this.lastChecked = input.checked = this.inputValue == (''+value); - this.lastValue = value; - } -}; - -/////////////////////// -//ElementController -/////////////////////// -nglr.BindUpdater = function(view, exp) { - this.view = view; - this.exp = exp.parseBindings(); - this.hasError = false; - this.scopeSelf = {element:view}; -}; - -nglr.BindUpdater.toText = function(obj) { - var e = nglr.escapeHtml; - switch(typeof obj) { - case "string": - case "boolean": - case "number": - return e(obj); - case "function": - return nglr.BindUpdater.toText(obj()); - case "object": - if (nglr.isNode(obj)) { - return nglr.outerHTML(obj); - } else if (obj && obj.TAG === filters.Meta.TAG) { - switch(typeof obj.html) { - case "string": - case "number": - return obj.html; - case "function": - return obj.html(); - default: - break; - } - switch(typeof obj.text) { - case "string": - case "number": - return e(obj.text); - case "function": - return e(obj.text()); - default: - break; - } - } - if (obj === null) - return ""; - return e(nglr.toJson(obj, true)); - default: - return ""; - } -}; - -nglr.BindUpdater.prototype.updateModel = function(scope) {}; -nglr.BindUpdater.prototype.updateView = function(scope) { - var html = []; - var parts = this.exp; - var length = parts.length; - for(var i=0; i iteratorLength; --r) { - var unneeded = this.children.pop(); - unneeded.element.removeNode(); - } - // Special case for option in select - if (child && child.element[0].nodeName === "OPTION") { - var select = jQuery(child.element[0].parentNode); - var cntl = select.data('controller'); - if (cntl) { - cntl.lastValue = undefined; - cntl.updateView(scope); - } - } - }); -}; - -////////////////////////////////// -// PopUp -////////////////////////////////// - -nglr.PopUp = function(doc) { - this.doc = doc; -}; - -nglr.PopUp.OUT_EVENT = "mouseleave mouseout click dblclick keypress keyup"; - -nglr.PopUp.prototype.bind = function () { - var self = this; - this.doc.find('.ng-validation-error,.ng-exception'). - live("mouseover", nglr.PopUp.onOver); -}; - -nglr.PopUp.onOver = function(e) { - nglr.PopUp.onOut(); - var jNode = jQuery(this); - jNode.bind(nglr.PopUp.OUT_EVENT, nglr.PopUp.onOut); - var position = jNode.position(); - var de = document.documentElement; - var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth; - var hasArea = w - position.left; - var width = 300; - var title = jNode.hasClass("ng-exception") ? "EXCEPTION:" : "Validation error..."; - var msg = jNode.attr("ng-error"); - - var x; - var arrowPos = hasArea>(width+75) ? "left" : "right"; - var tip = jQuery( - "
" + - "
" + - "
"+title+"
" + - "
"+msg+"
" + - "
"); - jQuery("body").append(tip); - if(arrowPos === 'left'){ - x = position.left + this.offsetWidth + 11; - }else{ - x = position.left - (width + 15); - tip.find('.ng-arrow-right').css({left:width+1}); - } - - tip.css({left: x+"px", top: (position.top - 3)+"px"}); - return true; -}; - -nglr.PopUp.onOut = function() { - jQuery('#ng-callout'). - unbind(nglr.PopUp.OUT_EVENT, nglr.PopUp.onOut). - remove(); - return true; -}; - -////////////////////////////////// -// Status -////////////////////////////////// - -nglr.Status = function (body) { - this.body = body; - this.requestCount = 0; -}; -nglr.Status.ANGULAR = "<a class='ng-angular-logo' href='http://www.getangular.com'>&lt;angular/&gt;</a>™"; - -nglr.Status.prototype.beginRequest = function () { - if (this.requestCount === 0) { -<<<<<<< HEAD:public/javascripts/nglr/Widgets.js - this.dialogView = jQuery('
Please Wait...
'); -======= - this.dialogView = jQuery('
Please Wait...
'); - this.progressWidget = this.dialogView.find("div"); - this.progressWidget.progressbar({value:0}); ->>>>>>> master:public/javascripts/nglr/Widgets.js - this.dialogView.dialog({bgiframe:true, minHeight:50, modal:true}); - this.maxRequestCount = 0; - } - this.requestCount++; - this.maxRequestCount++; -}; - -nglr.Status.prototype.endRequest = function () { - this.requestCount--; - if (this.requestCount === 0) { - this.dialogView.dialog("destroy"); - this.dialogView.remove(); - this.dialogView = null; - } -}; diff --git a/src/XSitePost.js b/src/XSitePost.js deleted file mode 100644 index 7d81e207..00000000 --- a/src/XSitePost.js +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright (C) 2008,2009 BRAT Tech LLC - -if (typeof nglr == 'undefined') nglr = {}; - -if (typeof console == 'undefined') console = {}; -if (typeof console.log == 'undefined') - console.log = function() {}; -if (typeof console.error == 'undefined') - console.error = function() {}; - -nglr.XSitePost = function(baseUrl, window, prefix) { - this.baseUrl = baseUrl; - this.post = jQuery.post; - this.window = window; - this.inQueue = {}; - this.outQueue = []; - this.maxMsgSize = 100000; - this.delay = 20; - this.prefix = prefix; - this.setTimeout=function(fn, delay){window.setTimeout(fn, delay);}; -}; - -nglr.XSitePost.prototype.init = function() { - this.window.name = ''; - this.response('ready', 'null'); -}; - -nglr.XSitePost.prototype.incomingFragment = function(fragment) { - var parts = fragment.split(";"); - this.incomingMsg(parts.shift(), 1*parts.shift(), 1*parts.shift(), parts.shift()); -}; - -nglr.XSitePost.prototype.incomingMsg = function(id, partNo, totalParts, msgPart) { - var msg = this.inQueue[id]; - if (!msg) { - msg = {id:id, parts:[], count:0}; - this.inQueue[id] = msg; - } - msg.parts[partNo] = msgPart; - msg.count++; - if (totalParts === msg.count) { - delete this.inQueue[id]; - var request = this.decodePost(msg.parts.join('')); - var self = this; - this.post(this.baseUrl + request.url, request.params, function(response, status){ - self.response(id, response, status); - }); - } -}; - -nglr.XSitePost.prototype.response = function(id, response, status) { - var start = 0; - var end; - var msg = Base64.encode(response); - var msgLen = msg.length; - var total = Math.ceil(msgLen / this.maxMsgSize); - var part = 0; - while (start < msgLen) { - end = Math.min(msgLen, start + this.maxMsgSize); - this.outQueue.push(id + ':'+part+':'+total+':' + msg.substring(start, end)); - start = end; - part++; - } -}; - -nglr.XSitePost.prototype.decodePost = function(post) { - var parts = post.split(':'); - var url = Base64.decode(parts.shift()); - var params = {}; - while(parts.length !== 0) { - var key = parts.shift(); - var value = Base64.decode(parts.shift()); - params[key] = value; - } - return {url:url, params:params}; -}; - -nglr.XSitePost.prototype.listen = function() { - console.log("listen()"); - var self = this; - var window = this.window; - var outQueue = this.outQueue; - var setTimeout = this.setTimeout; - var prefix = this.prefix; - var prefixLen = prefix.length; - var prefixRec = prefix + '>'; - var prefixRecLen = prefixRec.length; - window.name = prefix; - var pull = function(){ - var value = window.name; - if (value == prefix && outQueue.length > 0) { - window.name = prefix + '<' + outQueue.shift(); - } else if (value.substr(0, prefixRecLen) == prefixRec) { - self.incomingFragment(value.substr(prefixRecLen)); - window.name = prefix; - } - setTimeout(pull, self.delay); - }; - pull(); -}; diff --git a/src/angular-bootstrap.js b/src/angular-bootstrap.js index 8ac4f9f3..b13bbf34 100644 --- a/src/angular-bootstrap.js +++ b/src/angular-bootstrap.js @@ -80,9 +80,8 @@ doc = window.document.getElementById(id); } } - var angular = window.angularFactory(scriptConfig); if (scriptConfig.autoBind && doc) { - window.angularScope = angular.compile(doc); + window.angularScope = angular.compile(doc, scriptConfig); } if (typeof previousOnLoad === 'function') { try { diff --git a/src/angular.prefix b/src/angular.prefix new file mode 100644 index 00000000..522c17bf --- /dev/null +++ b/src/angular.prefix @@ -0,0 +1,2 @@ + +(function(window, document){ \ No newline at end of file diff --git a/src/angular.suffix b/src/angular.suffix new file mode 100644 index 00000000..4b3cc37b --- /dev/null +++ b/src/angular.suffix @@ -0,0 +1 @@ +})(window, document); \ No newline at end of file diff --git a/src/test/Runner.js b/src/test/Runner.js index c7dd431a..5840282e 100644 --- a/src/test/Runner.js +++ b/src/test/Runner.js @@ -1,11 +1,11 @@ -if (!nglr.test) nglr.test = {}; +if (typeof test == 'undefined') test = {}; -nglr.test.ScenarioRunner = function(scenarios, body) { +test.ScenarioRunner = function(scenarios, body) { this.scenarios = scenarios; this.body = body; }; -nglr.test.ScenarioRunner.prototype = { +test.ScenarioRunner.prototype = { run:function(){ this.setUpUI(); this.runScenarios(); @@ -25,22 +25,22 @@ nglr.test.ScenarioRunner.prototype = { }); }, runScenarios:function(){ - var runner = new nglr.test.Runner(this.console, this.testFrame); + var runner = new test.Runner(this.console, this.testFrame); _.stepper(this.scenarios, function(next, scenario, name){ - new nglr.test.Scenario(name, scenario).run(runner, next); + new test.Scenario(name, scenario).run(runner, next); }, function(){ } ); } }; -nglr.test.Runner = function(console, frame){ +test.Runner = function(console, frame){ this.console = console; this.current = null; this.tests = []; this.frame = frame; }; -nglr.test.Runner.prototype = { +test.Runner.prototype = { start:function(name){ var current = this.current = { name:name, @@ -75,7 +75,7 @@ nglr.test.Runner.prototype = { var buf = []; for ( var i = 1; i < arguments.length; i++) { var arg = arguments[i]; - buf.push(typeof arg == "string" ?arg:nglr.toJson(arg)); + buf.push(typeof arg == "string" ?arg:toJson(arg)); } var log = jQuery('
'); log.text(buf.join(" ")); @@ -86,11 +86,11 @@ nglr.test.Runner.prototype = { } }; -nglr.test.Scenario = function(name, scenario){ +test.Scenario = function(name, scenario){ this.name = name; this.scenario = scenario; }; -nglr.test.Scenario.prototype = { +test.Scenario.prototype = { run:function(runner, callback) { var self = this; _.stepper(this.scenario, function(next, steps, name){ @@ -115,7 +115,7 @@ nglr.test.Scenario.prototype = { else if (step.When) fn = angular.test.WHEN[step.When]; else if (step.Then) fn = angular.test.THEN[step.Then]; return fn || function (){ - throw "ERROR: Need Given/When/Then got: " + nglr.toJson(step); + throw "ERROR: Need Given/When/Then got: " + toJson(step); }; }, context: function(runner) { @@ -149,14 +149,14 @@ nglr.test.Scenario.prototype = { callback(); return; } - runner.log("info", nglr.toJson(step)); + runner.log("info", toJson(step)); var fn = this.verb(step); var context = this.context(runner); _.extend(context, step); try { (fn.call(context)||function(c){c();})(callback); } catch (e) { - runner.log("error", "ERROR: " + nglr.toJson(e)); + runner.log("error", "ERROR: " + toJson(e)); } } }; diff --git a/src/test/Steps.js b/src/test/Steps.js index af4b84d6..cc9ff549 100644 --- a/src/test/Steps.js +++ b/src/test/Steps.js @@ -14,7 +14,7 @@ angular.test.GIVEN = { }; }, dataset:function(){ - this.frame.name="$DATASET:" + nglr.toJson({dataset:this.dataset}); + this.frame.name="$DATASET:" + toJson({dataset:this.dataset}); } }; angular.test.WHEN = { diff --git a/test/BinderTest.js b/test/BinderTest.js index d033996d..0ffd2120 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -3,10 +3,10 @@ BinderTest = TestCase('BinderTest'); function compile(content, initialScope, config) { var h = html(content); config = config || {autoSubmit:true}; - var scope = new nglr.Scope(initialScope, "ROOT"); + var scope = new Scope(initialScope, "ROOT"); h.data('scope', scope); - var binder = new nglr.Binder(h[0], new nglr.WidgetFactory(), new MockUrlWatcher(), config); - var datastore = new nglr.DataStore(); + var binder = new Binder(h[0], new WidgetFactory(), new MockUrlWatcher(), config); + var datastore = new DataStore(); scope.set("$datastore", datastore); scope.set("$binder", binder); scope.set("$anchor", binder.anchor); @@ -19,80 +19,79 @@ function compileToHtml(content) { return compile(content).node.sortedHtml(); } - BinderTest.prototype.testParseTextWithNoBindings = function(){ - var parts = nglr.Binder.parseBindings("a"); + var parts = Binder.parseBindings("a"); assertEquals(parts.length, 1); assertEquals(parts[0], "a"); - assertTrue(!nglr.Binder.binding(parts[0])); + assertTrue(!Binder.binding(parts[0])); }; BinderTest.prototype.testParseEmptyText = function(){ - var parts = nglr.Binder.parseBindings(""); + var parts = Binder.parseBindings(""); assertEquals(parts.length, 1); assertEquals(parts[0], ""); - assertTrue(!nglr.Binder.binding(parts[0])); + assertTrue(!Binder.binding(parts[0])); }; BinderTest.prototype.testParseInnerBinding = function(){ - var parts = nglr.Binder.parseBindings("a{{b}}c"); + var parts = Binder.parseBindings("a{{b}}c"); assertEquals(parts.length, 3); assertEquals(parts[0], "a"); - assertTrue(!nglr.Binder.binding(parts[0])); + assertTrue(!Binder.binding(parts[0])); assertEquals(parts[1], "{{b}}"); - assertEquals(nglr.Binder.binding(parts[1]), "b"); + assertEquals(Binder.binding(parts[1]), "b"); assertEquals(parts[2], "c"); - assertTrue(!nglr.Binder.binding(parts[2])); + assertTrue(!Binder.binding(parts[2])); }; BinderTest.prototype.testParseEndingBinding = function(){ - var parts = nglr.Binder.parseBindings("a{{b}}"); + var parts = Binder.parseBindings("a{{b}}"); assertEquals(parts.length, 2); assertEquals(parts[0], "a"); - assertTrue(!nglr.Binder.binding(parts[0])); + assertTrue(!Binder.binding(parts[0])); assertEquals(parts[1], "{{b}}"); - assertEquals(nglr.Binder.binding(parts[1]), "b"); + assertEquals(Binder.binding(parts[1]), "b"); }; BinderTest.prototype.testParseBeggingBinding = function(){ - var parts = nglr.Binder.parseBindings("{{b}}c"); + var parts = Binder.parseBindings("{{b}}c"); assertEquals(parts.length, 2); assertEquals(parts[0], "{{b}}"); - assertEquals(nglr.Binder.binding(parts[0]), "b"); + assertEquals(Binder.binding(parts[0]), "b"); assertEquals(parts[1], "c"); - assertTrue(!nglr.Binder.binding(parts[1])); + assertTrue(!Binder.binding(parts[1])); }; BinderTest.prototype.testParseLoanBinding = function(){ - var parts = nglr.Binder.parseBindings("{{b}}"); + var parts = Binder.parseBindings("{{b}}"); assertEquals(parts.length, 1); assertEquals(parts[0], "{{b}}"); - assertEquals(nglr.Binder.binding(parts[0]), "b"); + assertEquals(Binder.binding(parts[0]), "b"); }; BinderTest.prototype.testParseTwoBindings = function(){ - var parts = nglr.Binder.parseBindings("{{b}}{{c}}"); + var parts = Binder.parseBindings("{{b}}{{c}}"); assertEquals(parts.length, 2); assertEquals(parts[0], "{{b}}"); - assertEquals(nglr.Binder.binding(parts[0]), "b"); + assertEquals(Binder.binding(parts[0]), "b"); assertEquals(parts[1], "{{c}}"); - assertEquals(nglr.Binder.binding(parts[1]), "c"); + assertEquals(Binder.binding(parts[1]), "c"); }; BinderTest.prototype.testParseTwoBindingsWithTextInMiddle = function(){ - var parts = nglr.Binder.parseBindings("{{b}}x{{c}}"); + var parts = Binder.parseBindings("{{b}}x{{c}}"); assertEquals(parts.length, 3); assertEquals(parts[0], "{{b}}"); - assertEquals(nglr.Binder.binding(parts[0]), "b"); + assertEquals(Binder.binding(parts[0]), "b"); assertEquals(parts[1], "x"); - assertTrue(!nglr.Binder.binding(parts[1])); + assertTrue(!Binder.binding(parts[1])); assertEquals(parts[2], "{{c}}"); - assertEquals(nglr.Binder.binding(parts[2]), "c"); + assertEquals(Binder.binding(parts[2]), "c"); }; BinderTest.prototype.testParseMultiline = function(){ - var parts = nglr.Binder.parseBindings('"X\nY{{A\nB}}C\nD"'); - assertTrue(!!nglr.Binder.binding('{{A\nB}}')); + var parts = Binder.parseBindings('"X\nY{{A\nB}}C\nD"'); + assertTrue(!!Binder.binding('{{A\nB}}')); assertEquals(parts.length, 3); assertEquals(parts[0], '"X\nY'); assertEquals(parts[1], '{{A\nB}}'); @@ -100,9 +99,9 @@ BinderTest.prototype.testParseMultiline = function(){ }; BinderTest.prototype.testHasBinding = function(){ - assertTrue(nglr.Binder.hasBinding("{{a}}")); - assertTrue(!nglr.Binder.hasBinding("a")); - assertTrue(nglr.Binder.hasBinding("{{b}}x{{c}}")); + assertTrue(Binder.hasBinding("{{a}}")); + assertTrue(!Binder.hasBinding("a")); + assertTrue(Binder.hasBinding("{{b}}x{{c}}")); }; @@ -119,9 +118,9 @@ BinderTest.prototype.testChangingTextfieldUpdatesModel = function(){ BinderTest.prototype.testChangingTextareaUpdatesModel = function(){ var form = html(''); - var scope = new nglr.Scope({model:{}}); + var scope = new Scope({model:{}}); form.data('scope', scope); - var binder = new nglr.Binder(form.get(0), new nglr.WidgetFactory(), new MockUrlWatcher()); + var binder = new Binder(form.get(0), new WidgetFactory(), new MockUrlWatcher()); binder.compile(); binder.updateView(); assertEquals(scope.get('model').note, 'abc'); @@ -130,9 +129,9 @@ BinderTest.prototype.testChangingTextareaUpdatesModel = function(){ BinderTest.prototype.testChangingRadioUpdatesModel = function(){ var form = html('' + ''); - var scope = new nglr.Scope({model:{}}); + var scope = new Scope({model:{}}); form.data('scope', scope); - var binder = new nglr.Binder(form.get(0), new nglr.WidgetFactory(), new MockUrlWatcher()); + var binder = new Binder(form.get(0), new WidgetFactory(), new MockUrlWatcher()); binder.compile(); binder.updateView(); assertEquals(scope.get('model').price, 'A'); @@ -140,9 +139,9 @@ BinderTest.prototype.testChangingRadioUpdatesModel = function(){ BinderTest.prototype.testChangingCheckboxUpdatesModel = function(){ var form = html(''); - var scope = new nglr.Scope({model:{}}); + var scope = new Scope({model:{}}); form.data('scope', scope); - var binder = new nglr.Binder(form.get(0), new nglr.WidgetFactory(), new MockUrlWatcher()); + var binder = new Binder(form.get(0), new WidgetFactory(), new MockUrlWatcher()); binder.compile(); binder.updateView(); assertEquals('A', scope.get('model').price); @@ -156,9 +155,9 @@ BinderTest.prototype.testBindUpdate = function() { BinderTest.prototype.testChangingSelectNonSelectedUpdatesModel = function(){ var form = html(''); - var scope = new nglr.Scope({model:{}}); + var scope = new Scope({model:{}}); form.data('scope', scope); - var binder = new nglr.Binder(form.get(0), new nglr.WidgetFactory(), new MockUrlWatcher()); + var binder = new Binder(form.get(0), new WidgetFactory(), new MockUrlWatcher()); binder.compile(); binder.updateView(); assertEquals('A', scope.get('model').price); @@ -170,9 +169,9 @@ BinderTest.prototype.testChangingMultiselectUpdatesModel = function(){ '' + '' + ''); - var scope = new nglr.Scope({Invoice:{}}); + var scope = new Scope({Invoice:{}}); form.data('scope', scope); - var binder = new nglr.Binder(form.get(0), new nglr.WidgetFactory(), new MockUrlWatcher()); + var binder = new Binder(form.get(0), new WidgetFactory(), new MockUrlWatcher()); binder.compile(); binder.updateView(); assertJsonEquals(["A", "B"], scope.get('Invoice').options); @@ -180,9 +179,9 @@ BinderTest.prototype.testChangingMultiselectUpdatesModel = function(){ BinderTest.prototype.testChangingSelectSelectedUpdatesModel = function(){ var form = html(''); - var scope = new nglr.Scope({model:{}}); + var scope = new Scope({model:{}}); form.data('scope', scope); - var binder = new nglr.Binder(form.get(0), new nglr.WidgetFactory(), new MockUrlWatcher()); + var binder = new Binder(form.get(0), new WidgetFactory(), new MockUrlWatcher()); binder.compile(); binder.updateView(); assertEquals(scope.get('model').price, 'b'); @@ -190,18 +189,18 @@ BinderTest.prototype.testChangingSelectSelectedUpdatesModel = function(){ BinderTest.prototype.testExecuteInitialization = function() { var form = html('
'); - var scope = new nglr.Scope(); + var scope = new Scope(); form.data('scope', scope); - var binder = new nglr.Binder(form.get(0)); + var binder = new Binder(form.get(0)); binder.executeInit(); assertEquals(scope.get('a'), 123); }; BinderTest.prototype.testExecuteInitializationStatements = function() { var form = html('
'); - var scope = new nglr.Scope(); + var scope = new Scope(); form.data('scope', scope); - var binder = new nglr.Binder(form.get(0)); + var binder = new Binder(form.get(0)); binder.executeInit(); assertEquals(scope.get('a'), 123); assertEquals(scope.get('b'), 345); @@ -209,9 +208,9 @@ BinderTest.prototype.testExecuteInitializationStatements = function() { BinderTest.prototype.testApplyTextBindings = function(){ var form = html('
x
'); - var scope = new nglr.Scope({model:{a:123}}); + var scope = new Scope({model:{a:123}}); form.data('scope', scope); - var binder = new nglr.Binder(form.get(0), null, new MockUrlWatcher()); + var binder = new Binder(form.get(0), null, new MockUrlWatcher()); binder.compile(); binder.updateView(); assertEquals('123', form.text()); @@ -224,15 +223,15 @@ BinderTest.prototype.testReplaceBindingInTextWithSpan = function() { BinderTest.prototype.testReplaceBindingCreatesCorrectNumberOfWidgets = function() { var h = html("space{{a}}{{a}}a{{a}}{{a}}"); - h.data('scope', new nglr.Scope()); - var binder = new nglr.Binder(h.get(0), new nglr.WidgetFactory()); + h.data('scope', new Scope()); + var binder = new Binder(h.get(0), new WidgetFactory()); binder.compile(); assertEquals(4, h.scope().widgets.length); }; BinderTest.prototype.testBindingSpaceConfusesIE = function() { - if (!nglr.msie) return; + if (!msie) return; var span = document.createElement("span"); span.innerHTML = ' '; var nbsp = span.firstChild.nodeValue; @@ -246,30 +245,30 @@ BinderTest.prototype.testBindingSpaceConfusesIE = function() { BinderTest.prototype.testBindingOfAttributes = function() { var form = html(""); - form.data('scope', new nglr.Scope()); - var binder = new nglr.Binder(form.get(0)); + form.data('scope', new Scope()); + var binder = new Binder(form.get(0)); binder.compile(); var attrbinding = form.find("a").attr("ng-bind-attr"); - var bindings = nglr.fromJson(attrbinding); + var bindings = fromJson(attrbinding); assertEquals("http://s/a{{b}}c", decodeURI(bindings.href)); assertTrue(!bindings.foo); }; BinderTest.prototype.testMarkMultipleAttributes = function() { var form = html(""); - form.data('scope', new nglr.Scope()); - var binder = new nglr.Binder(form.get(0)); + form.data('scope', new Scope()); + var binder = new Binder(form.get(0)); binder.compile(); var attrbinding = form.find("a").attr("ng-bind-attr"); - var bindings = nglr.fromJson(attrbinding); + var bindings = fromJson(attrbinding); assertEquals(decodeURI(bindings.href), "http://s/a{{b}}c"); assertEquals(bindings.foo, "{{d}}"); }; BinderTest.prototype.testAttributesNoneBound = function() { var form = html(""); - form.data('scope', new nglr.Scope()); - var binder = new nglr.Binder(form.get(0)); + form.data('scope', new Scope()); + var binder = new Binder(form.get(0)); binder.compile(); var a = form.find("a"); assertEquals(a.get(0).nodeName, "A"); @@ -278,8 +277,8 @@ BinderTest.prototype.testAttributesNoneBound = function() { BinderTest.prototype.testExistingAttrbindingIsAppended = function() { var form = html(""); - form.data('scope', new nglr.Scope()); - var binder = new nglr.Binder(form.get(0)); + form.data('scope', new Scope()); + var binder = new Binder(form.get(0)); binder.compile(); var a = form.find("a"); assertEquals('{"b":"{{def}}","href":"http://s/{{abc}}"}', a.attr('ng-bind-attr')); @@ -287,8 +286,8 @@ BinderTest.prototype.testExistingAttrbindingIsAppended = function() { BinderTest.prototype.testAttributesAreEvaluated = function(){ var form = html(''); - form.data('scope', new nglr.Scope({a:1, b:2})); - var binder = new nglr.Binder(form.get(0), null, new MockUrlWatcher()); + form.data('scope', new Scope({a:1, b:2})); + var binder = new Binder(form.get(0), null, new MockUrlWatcher()); binder.compile(); binder.updateView(); var a = form.find("a"); @@ -305,8 +304,8 @@ BinderTest.prototype.testInputsAreUpdated = function(){ '' + '' + ''); - var binder = new nglr.Binder(form.get(0), new nglr.WidgetFactory(), new MockUrlWatcher()); - form.data('scope', new nglr.Scope({A:{text:"t1", textarea:"t2", radio:"r", checkbox:"c", select:"S"}})); + var binder = new Binder(form.get(0), new WidgetFactory(), new MockUrlWatcher()); + form.data('scope', new Scope({A:{text:"t1", textarea:"t2", radio:"r", checkbox:"c", select:"S"}})); binder.compile(); binder.updateView(); assertEquals(form.find("input[type=text]").attr('value'), 't1'); @@ -349,7 +348,7 @@ BinderTest.prototype.testButtonElementActionExecutesInScope = function(){ }; BinderTest.prototype.testParseEmptyAnchor = function(){ - var binder = new nglr.Binder(null, null, new MockUrlWatcher()); + var binder = new Binder(null, null, new MockUrlWatcher()); var anchor = binder.anchor; binder.parseAnchor("a#x=1"); assertEquals(1, binder.anchor.x); @@ -360,7 +359,7 @@ BinderTest.prototype.testParseEmptyAnchor = function(){ }; BinderTest.prototype.testParseAnchor = function(){ - var binder = new nglr.Binder(null, null, new MockUrlWatcher()); + var binder = new Binder(null, null, new MockUrlWatcher()); binder.parseAnchor("a#x=1"); assertEquals(binder.anchor.x, "1"); binder.parseAnchor("a#a=b&c=%20&d"); @@ -371,7 +370,7 @@ BinderTest.prototype.testParseAnchor = function(){ }; BinderTest.prototype.testWriteAnchor = function(){ - var binder = new nglr.Binder(null, null, new MockUrlWatcher()); + var binder = new Binder(null, null, new MockUrlWatcher()); binder.urlWatcher.setUrl('a'); binder.anchor.a = 'b'; binder.anchor.c = ' '; @@ -381,9 +380,9 @@ BinderTest.prototype.testWriteAnchor = function(){ }; BinderTest.prototype.testWriteAnchorAsPartOfTheUpdateView = function(){ - var binder = new nglr.Binder(html("
")[0], null, new MockUrlWatcher()); + var binder = new Binder(html("
")[0], null, new MockUrlWatcher()); binder.urlWatcher.setUrl('a'); - $(binder.doc).data('scope', new nglr.Scope()); + $(binder.doc).data('scope', new Scope()); binder.anchor.a = 'b'; binder.updateView(); assertEquals(binder.urlWatcher.getUrl(), "a#a=b"); @@ -391,9 +390,9 @@ BinderTest.prototype.testWriteAnchorAsPartOfTheUpdateView = function(){ BinderTest.prototype.testRepeaterUpdateBindings = function(){ var form = html('
'); - var binder = new nglr.Binder(form.get(0), null, new MockUrlWatcher()); + var binder = new Binder(form.get(0), null, new MockUrlWatcher()); var items = [{a:"A"}, {a:"B"}]; - form.data('scope', new nglr.Scope({model:{items:items}})); + form.data('scope', new Scope({model:{items:items}})); binder.compile(); binder.updateView(); @@ -423,8 +422,8 @@ BinderTest.prototype.testRepeaterUpdateBindings = function(){ BinderTest.prototype.testRepeaterContentDoesNotBind = function(){ var form = html('
'); - form.data('scope', new nglr.Scope({model:{items:[{a:"A"}]}})); - var binder = new nglr.Binder(form.get(0), null, new MockUrlWatcher()); + form.data('scope', new Scope({model:{items:[{a:"A"}]}})); + var binder = new Binder(form.get(0), null, new MockUrlWatcher()); binder.compile(); binder.updateView(); assertEquals('
    ' + @@ -450,9 +449,9 @@ BinderTest.prototype.testRepeaterInputContentDoesNotBind = function(){ var form = html('
    • ' + '
    '); - var binder = new nglr.Binder(form.get(0), null, new MockUrlWatcher()); + var binder = new Binder(form.get(0), null, new MockUrlWatcher()); var items = [{a:"A"}]; - form.data('scope', new nglr.Scope({model:{items:items}})); + form.data('scope', new Scope({model:{items:items}})); assertEquals(form.find(":input").attr("value"), "OLD"); }; @@ -492,9 +491,9 @@ BinderTest.prototype.testDoNotOverwriteCustomAction = function(){ BinderTest.prototype.testReplaceFileUploadWithSwf = function(){ expectAsserts(1); var form = jQuery("body").append('
    '); - form.data('scope', new nglr.Scope()); + form.data('scope', new Scope()); var factory = {}; - var binder = new nglr.Binder(form.get(0), factory, new MockUrlWatcher()); + var binder = new Binder(form.get(0), factory, new MockUrlWatcher()); factory.createController = function(node){ assertEquals(node.attr('type'), 'file'); return {updateModel:function(){}}; @@ -505,8 +504,8 @@ BinderTest.prototype.testReplaceFileUploadWithSwf = function(){ BinderTest.prototype.testRepeaterAdd = function(){ var doc = $('
    '); - var binder = new nglr.Binder(doc[0], new nglr.WidgetFactory(), new MockUrlWatcher()); - doc.data('scope', new nglr.Scope({items:[{x:'a'}, {x:'b'}], $binder:binder})); + var binder = new Binder(doc[0], new WidgetFactory(), new MockUrlWatcher()); + doc.data('scope', new Scope({items:[{x:'a'}, {x:'b'}], $binder:binder})); binder.compile(); binder.updateView(); assertEquals('a', doc.find(':input')[0].value); @@ -520,16 +519,16 @@ BinderTest.prototype.testRepeaterAdd = function(){ BinderTest.prototype.testIfTextBindingThrowsErrorDecorateTheSpan = function(){ var doc = $('
    {{error.throw()}}
    '); - var scope = new nglr.Scope(); + var scope = new Scope(); doc.data('scope', scope); - var binder = new nglr.Binder(doc[0], new nglr.WidgetFactory(), new MockUrlWatcher()); + var binder = new Binder(doc[0], new WidgetFactory(), new MockUrlWatcher()); binder.compile(); scope.set('error.throw', function(){throw "ErrorMsg1";}); binder.updateView(); var span = doc.find('span'); assertTrue(span.hasClass('ng-exception')); - assertEquals('ErrorMsg1', nglr.fromJson(span.text())); + assertEquals('ErrorMsg1', fromJson(span.text())); assertEquals('"ErrorMsg1"', span.attr('ng-error')); scope.set('error.throw', function(){throw "MyError";}); @@ -548,9 +547,9 @@ BinderTest.prototype.testIfTextBindingThrowsErrorDecorateTheSpan = function(){ BinderTest.prototype.testIfAttrBindingThrowsErrorDecorateTheSpan = function(){ var doc = $('
    '); - var scope = new nglr.Scope(); + var scope = new Scope(); doc.data('scope', scope); - var binder = new nglr.Binder(doc[0], new nglr.WidgetFactory(), new MockUrlWatcher()); + var binder = new Binder(doc[0], new WidgetFactory(), new MockUrlWatcher()); binder.compile(); scope.set('error.throw', function(){throw "ErrorMsg";}); @@ -570,9 +569,9 @@ BinderTest.prototype.testNestedRepeater = function() { var doc = html('
    ' + '
      ' + '
      '); - var scope = new nglr.Scope(); + var scope = new Scope(); doc.data('scope', scope); - var binder = new nglr.Binder(doc[0], new nglr.WidgetFactory(), new MockUrlWatcher()); + var binder = new Binder(doc[0], new WidgetFactory(), new MockUrlWatcher()); binder.compile(); scope.set('model', [{name:'a', item:['a1', 'a2']}, {name:'b', item:['b1', 'b2']}]); @@ -594,9 +593,9 @@ BinderTest.prototype.testNestedRepeater = function() { BinderTest.prototype.testRadioButtonGetsPrefixed = function () { var doc = html(''); - var scope = new nglr.Scope(); + var scope = new Scope(); doc.data('scope', scope); - var binder = new nglr.Binder(doc[0], new nglr.WidgetFactory(), new MockUrlWatcher()); + var binder = new Binder(doc[0], new WidgetFactory(), new MockUrlWatcher()); binder.compile(); scope.set('model', ['a1', 'a2']); @@ -611,9 +610,9 @@ BinderTest.prototype.testRadioButtonGetsPrefixed = function () { BinderTest.prototype.testHideBindingExpression = function() { var doc = html('
      '); - var scope = new nglr.Scope(); + var scope = new Scope(); doc.data('scope', scope); - var binder = new nglr.Binder(doc[0], new nglr.WidgetFactory(), new MockUrlWatcher()); + var binder = new Binder(doc[0], new WidgetFactory(), new MockUrlWatcher()); binder.compile(); scope.set('hidden', 3); @@ -629,9 +628,9 @@ BinderTest.prototype.testHideBindingExpression = function() { BinderTest.prototype.testHideBinding = function() { var doc = html('
      '); - var scope = new nglr.Scope(); + var scope = new Scope(); doc.data('scope', scope); - var binder = new nglr.Binder(doc[0], new nglr.WidgetFactory(), new MockUrlWatcher()); + var binder = new Binder(doc[0], new WidgetFactory(), new MockUrlWatcher()); binder.compile(); scope.set('hidden', 'true'); @@ -652,9 +651,9 @@ BinderTest.prototype.testHideBinding = function() { BinderTest.prototype.testShowBinding = function() { var doc = html('
      '); - var scope = new nglr.Scope(); + var scope = new Scope(); doc.data('scope', scope); - var binder = new nglr.Binder(doc[0], new nglr.WidgetFactory(), new MockUrlWatcher()); + var binder = new Binder(doc[0], new WidgetFactory(), new MockUrlWatcher()); binder.compile(); scope.set('show', 'true'); @@ -684,9 +683,9 @@ BinderTest.prototype.testBindClassUndefined = function() { BinderTest.prototype.testBindClass = function() { var doc = html('
      '); - var scope = new nglr.Scope(); + var scope = new Scope(); doc.data('scope', scope); - var binder = new nglr.Binder(doc[0], new nglr.WidgetFactory(), new MockUrlWatcher()); + var binder = new Binder(doc[0], new WidgetFactory(), new MockUrlWatcher()); binder.compile(); scope.set('class', 'testClass'); @@ -713,9 +712,9 @@ BinderTest.prototype.testBindClassEvenOdd = function() { BinderTest.prototype.testBindStyle = function() { var doc = html('
      '); - var scope = new nglr.Scope(); + var scope = new Scope(); doc.data('scope', scope); - var binder = new nglr.Binder(doc[0], new nglr.WidgetFactory(), new MockUrlWatcher()); + var binder = new Binder(doc[0], new WidgetFactory(), new MockUrlWatcher()); binder.compile(); scope.eval('style={color:"red"}'); @@ -734,7 +733,7 @@ BinderTest.prototype.testActionOnAHrefThrowsError = function(){ var state = compile('Add Phone', model); var input = state.node.find('a'); input.click(); - assertEquals('abc', nglr.fromJson(input.attr('ng-error')).a); + assertEquals('abc', fromJson(input.attr('ng-error')).a); assertNotNull(input.data('qtip')); assertTrue("should have an error class", input.hasClass('ng-exception')); @@ -890,7 +889,7 @@ BinderTest.prototype.testItShouldCallListenersWhenAnchorChanges = function() { }; BinderTest.prototype.testParseQueryString = function(){ - var binder = new nglr.Binder(); + var binder = new Binder(); assertJsonEquals({"a":"1"}, binder.parseQueryString("a=1")); assertJsonEquals({"a":"1", "b":"two"}, binder.parseQueryString("a=1&b=two")); assertJsonEquals({}, binder.parseQueryString("")); @@ -905,8 +904,8 @@ BinderTest.prototype.testParseQueryString = function(){ BinderTest.prototype.testSetBinderAnchorTriggersListeners = function(){ expectAsserts(2); var doc = html("
      ")[0]; - var binder = new nglr.Binder(doc, null, new MockUrlWatcher()); - var scope = new nglr.Scope({$binder:binder, $anchor:binder.anchor}); + var binder = new Binder(doc, null, new MockUrlWatcher()); + var scope = new Scope({$binder:binder, $anchor:binder.anchor}); jQuery(doc).data('scope', scope); scope.addWatchListener("$anchor.name", function(newVal, oldVal) { diff --git a/test/ConsoleTest.js b/test/ConsoleTest.js index 56e223bd..f659752f 100644 --- a/test/ConsoleTest.js +++ b/test/ConsoleTest.js @@ -1,13 +1,12 @@ ConsoleTest = TestCase('ConsoleTest'); ConsoleTest.prototype.testConsoleWrite = function(){ - var consoleNode = $("
      ")[0]; - nglr.consoleNode = consoleNode; - nglr.consoleLog("error", ["Hello", "world"]); + consoleNode = $("
      ")[0]; + consoleLog("error", ["Hello", "world"]); assertEquals($(consoleNode)[0].nodeName, 'DIV'); assertEquals($(consoleNode).text(), 'Hello world'); assertEquals($('div', consoleNode)[0].className, 'error'); - nglr.consoleLog("error",["Bye"]); + consoleLog("error",["Bye"]); assertEquals($(consoleNode).text(), 'Hello worldBye'); - nglr.consoleNode = null; + consoleNode = null; }; \ No newline at end of file diff --git a/test/DataStoreTest.js b/test/DataStoreTest.js index 9fe6c3df..2dd4a582 100644 --- a/test/DataStoreTest.js +++ b/test/DataStoreTest.js @@ -11,14 +11,14 @@ DataStoreTest.prototype.testSavePostsToServer = function(){ assertEquals("123", posted.$id); assertEquals("1", posted.$version); assertFalse('function' == typeof posted.save); - response = nglr.fromJson(nglr.toJson(posted)); + response = fromJson(toJson(posted)); response.$entity = "abc"; response.$id = "123"; response.$version = "2"; callback(200, [response]); }; var model; - var datastore = new nglr.DataStore(post); + var datastore = new DataStore(post); model = datastore.entity('abc', {name: "value"})(); model.$id = "123"; model.$version = "1"; @@ -44,7 +44,7 @@ DataStoreTest.prototype.testLoadGetsFromServer = function(){ response = [{$entity:'abc', $id:'1', $version:'2', key:"value"}]; callback(200, response); }; - var datastore = new nglr.DataStore(post); + var datastore = new DataStore(post); var model = datastore.entity("abc", {merge:true})(); assertEquals(datastore.load(model, '1', function(obj){ @@ -72,14 +72,14 @@ DataStoreTest.prototype.testRemove = function(){ assertEquals("123", posted.$id); assertEquals("1", posted.$version); assertFalse('function' == typeof posted.save); - response = nglr.fromJson(nglr.toJson(posted)); + response = fromJson(toJson(posted)); response.$entity = "abc"; response.$id = "123"; response.$version = "2"; callback(200, [response]); }; var model; - var datastore = new nglr.DataStore(post); + var datastore = new DataStore(post); model = datastore.entity('abc', {name: "value"})(); model.$id = "123"; model.$version = "1"; @@ -101,7 +101,7 @@ DataStoreTest.prototype.test401ResponseDoesNotCallCallback = function(){ callback(200, {$status_code: 401}); }; - var datastore = new nglr.DataStore(post, {login:function(){ + var datastore = new DataStore(post, {login:function(){ assertTrue(true); }}); @@ -119,7 +119,7 @@ DataStoreTest.prototype.test403ResponseDoesNotCallCallback = function(){ callback(200, [{$status_code: 403}]); }; - var datastore = new nglr.DataStore(post, {notAuthorized:function(){ + var datastore = new DataStore(post, {notAuthorized:function(){ assertTrue(true); }}); @@ -136,14 +136,14 @@ DataStoreTest.prototype.testLoadCalledWithoutIdShouldBeNoop = function(){ var post = function(url, callback){ assertTrue(false); }; - var datastore = new nglr.DataStore(post); + var datastore = new DataStore(post); var model = datastore.entity("abc")(); assertEquals(datastore.load(model, undefined), model); assertEquals(model.$entity, "abc"); }; DataStoreTest.prototype.testEntityFactory = function(){ - var ds = new nglr.DataStore(); + var ds = new DataStore(); var Recipe = ds.entity("Recipe", {a:1, b:2}); assertEquals(Recipe.title, "Recipe"); assertEquals(Recipe.defaults.a, 1); @@ -161,7 +161,7 @@ DataStoreTest.prototype.testEntityFactory = function(){ }; DataStoreTest.prototype.testEntityFactoryNoDefaults = function(){ - var ds = new nglr.DataStore(); + var ds = new DataStore(); var Recipe = ds.entity("Recipe"); assertEquals(Recipe.title, "Recipe"); @@ -170,7 +170,7 @@ DataStoreTest.prototype.testEntityFactoryNoDefaults = function(){ }; DataStoreTest.prototype.testEntityFactoryWithInitialValues = function(){ - var ds = new nglr.DataStore(); + var ds = new DataStore(); var Recipe = ds.entity("Recipe"); var recipe = Recipe({name: "name"}); @@ -178,7 +178,7 @@ DataStoreTest.prototype.testEntityFactoryWithInitialValues = function(){ }; DataStoreTest.prototype.testEntityLoad = function(){ - var ds = new nglr.DataStore(); + var ds = new DataStore(); var Recipe = ds.entity("Recipe", {a:1, b:2}); ds.load = function(instance, id, callback){ callback.apply(instance); @@ -192,7 +192,7 @@ DataStoreTest.prototype.testEntityLoad = function(){ }; DataStoreTest.prototype.testSaveScope = function(){ - var ds = new nglr.DataStore(); + var ds = new DataStore(); var log = ""; var Person = ds.entity("Person"); var person1 = Person({name:"A", $entity:"Person", $id:"1", $version:"1"}, ds); @@ -215,7 +215,7 @@ DataStoreTest.prototype.testSaveScope = function(){ }; DataStoreTest.prototype.testEntityLoadAllRows = function(){ - var ds = new nglr.DataStore(); + var ds = new DataStore(); var Recipe = ds.entity("Recipe"); var list = []; ds.loadAll = function(entity, callback){ @@ -236,7 +236,7 @@ DataStoreTest.prototype.testLoadAll = function(){ assertEquals("A", data[0][1]); callback(200, [[{$entity:'A', $id:'1'},{$entity:'A', $id:'2'}]]); }; - var datastore = new nglr.DataStore(post); + var datastore = new DataStore(post); var list = datastore.entity("A").all(function(){ assertTrue(true); }); @@ -256,7 +256,7 @@ DataStoreTest.prototype.testQuery = function(){ callback(200, [[{$entity:"Employee", $id: "456", managerId: "123ABC"}]]); }; - var datastore = new nglr.DataStore(post); + var datastore = new DataStore(post); var Employee = datastore.entity("Employee"); var list = Employee.query('managerId', "123abc", function(){ assertTrue(true); @@ -269,7 +269,7 @@ DataStoreTest.prototype.testQuery = function(){ DataStoreTest.prototype.testLoadingDocumentRefreshesExistingArrays = function() { expectAsserts(12); var post; - var datastore = new nglr.DataStore(function(r, c){post(r,c);}); + var datastore = new DataStore(function(r, c){post(r,c);}); var Book = datastore.entity('Book'); post = function(req, callback) { callback(200, [[{$id:1, $entity:"Book", name:"Moby"}, @@ -285,7 +285,7 @@ DataStoreTest.prototype.testLoadingDocumentRefreshesExistingArrays = function() assertEquals("Dick", queryBooks[1].name); post = function(req, callback) { - assertEquals('[["GET","Book/1"]]', nglr.toJson(req)); + assertEquals('[["GET","Book/1"]]', toJson(req)); callback(200, [{$id:1, $entity:"Book", name:"Moby Dick"}]); }; var book = Book.load(1); @@ -307,7 +307,7 @@ DataStoreTest.prototype.testLoadingDocumentRefreshesExistingArrays = function() DataStoreTest.prototype.testEntityProperties = function() { expectAsserts(2); - var datastore = new nglr.DataStore(); + var datastore = new DataStore(); var callback = {}; datastore._jsonRequest = function(request, callbackFn) { @@ -322,11 +322,11 @@ DataStoreTest.prototype.testEntityProperties = function() { DataStoreTest.prototype.testLoadInstanceIsNotFromCache = function() { var post; - var datastore = new nglr.DataStore(function(r, c){post(r,c);}); + var datastore = new DataStore(function(r, c){post(r,c);}); var Book = datastore.entity('Book'); post = function(req, callback) { - assertEquals('[["GET","Book/1"]]', nglr.toJson(req)); + assertEquals('[["GET","Book/1"]]', toJson(req)); callback(200, [{$id:1, $entity:"Book", name:"Moby Dick"}]); }; var book = Book.load(1); @@ -336,14 +336,14 @@ DataStoreTest.prototype.testLoadInstanceIsNotFromCache = function() { }; DataStoreTest.prototype.testLoadStarsIsNewDocument = function() { - var datastore = new nglr.DataStore(); + var datastore = new DataStore(); var Book = datastore.entity('Book'); var book = Book.load('*'); assertEquals('Book', book.$entity); }; DataStoreTest.prototype.testUndefinedEntityReturnsNullValueObject = function() { - var datastore = new nglr.DataStore(); + var datastore = new DataStore(); var Entity = datastore.entity(undefined); var all = Entity.all(); assertEquals(0, all.length); @@ -355,7 +355,7 @@ DataStoreTest.prototype.testFetchEntities = function(){ assertJsonEquals(["GET", "$entities"], data[0]); callback(200, [{A:0, B:0}]); }; - var datastore = new nglr.DataStore(post); + var datastore = new DataStore(post); var entities = datastore.entities(function(){ assertTrue(true); }); @@ -367,20 +367,20 @@ DataStoreTest.prototype.testFetchEntities = function(){ }; DataStoreTest.prototype.testItShouldMigrateSchema = function() { - var datastore = new nglr.DataStore(); + var datastore = new DataStore(); var Entity = datastore.entity("Entity", {a:[], user:{name:"Misko", email:""}}); var doc = Entity().$loadFrom({b:'abc', user:{email:"misko@hevery.com"}}); assertFalse( - nglr.toJson({a:[], b:'abc', user:{name:"Misko", email:"misko@hevery.com"}}) == - nglr.toJson(doc)); + toJson({a:[], b:'abc', user:{name:"Misko", email:"misko@hevery.com"}}) == + toJson(doc)); doc.$migrate(); assertEquals( - nglr.toJson({a:[], b:'abc', user:{name:"Misko", email:"misko@hevery.com"}}), - nglr.toJson(doc)); + toJson({a:[], b:'abc', user:{name:"Misko", email:"misko@hevery.com"}}), + toJson(doc)); }; DataStoreTest.prototype.testItShouldCollectRequestsForBulk = function() { - var ds = new nglr.DataStore(); + var ds = new DataStore(); var Book = ds.entity("Book"); var Library = ds.entity("Library"); Book.all(); @@ -391,7 +391,7 @@ DataStoreTest.prototype.testItShouldCollectRequestsForBulk = function() { }; DataStoreTest.prototype.testEmptyFlushShouldDoNothing = function () { - var ds = new nglr.DataStore(function(){ + var ds = new DataStore(function(){ fail("expecting noop"); }); ds.flush(); @@ -400,17 +400,17 @@ DataStoreTest.prototype.testEmptyFlushShouldDoNothing = function () { DataStoreTest.prototype.testFlushShouldCallAllCallbacks = function() { var log = ""; function post(request, callback){ - log += 'BulkRequest:' + nglr.toJson(request) + ';'; + log += 'BulkRequest:' + toJson(request) + ';'; callback(200, [[{$id:'ABC'}], {$id:'XYZ'}]); } - var ds = new nglr.DataStore(post); + var ds = new DataStore(post); var Book = ds.entity("Book"); var Library = ds.entity("Library"); Book.all(function(instance){ - log += nglr.toJson(instance) + ';'; + log += toJson(instance) + ';'; }); Library.load("123", function(instance){ - log += nglr.toJson(instance) + ';'; + log += toJson(instance) + ';'; }); assertEquals("", log); ds.flush(); @@ -421,7 +421,7 @@ DataStoreTest.prototype.testFlushShouldCallAllCallbacks = function() { DataStoreTest.prototype.testSaveOnNotLoggedInRetriesAfterLoggin = function(){ var log = ""; var book; - var ds = new nglr.DataStore(null, {login:function(c){c();}}); + var ds = new DataStore(null, {login:function(c){c();}}); ds.post = function (request, callback){ assertJsonEquals([["POST", "", book]], request); ds.post = function(request, callback){ @@ -439,7 +439,7 @@ DataStoreTest.prototype.testSaveOnNotLoggedInRetriesAfterLoggin = function(){ DataStoreTest.prototype.testItShouldRemoveItemFromCollectionWhenDeleted = function() { expectAsserts(6); - var ds = new nglr.DataStore(); + var ds = new DataStore(); ds.post = function(request, callback){ assertJsonEquals([["GET", "Book"]], request); callback(200, [[{name:"Moby Dick", $id:123, $entity:'Book'}]]); @@ -462,7 +462,7 @@ DataStoreTest.prototype.testItShouldRemoveItemFromCollectionWhenDeleted = functi DataStoreTest.prototype.testItShouldAddToAll = function() { expectAsserts(8); - var ds = new nglr.DataStore(); + var ds = new DataStore(); ds.post = function(request, callback){ assertJsonEquals([["GET", "Book"]], request); callback(200, [[]]); @@ -490,7 +490,7 @@ DataStoreTest.prototype.testItShouldAddToAll = function() { DataStoreTest.prototype.testItShouldReturnCreatedDocumentCountByUser = function(){ expectAsserts(2); - var datastore = new nglr.DataStore( + var datastore = new DataStore( function(request, callback){ assertJsonEquals([["GET", "$users"]], request); callback(200, [{misko:1, adam:1}]); @@ -502,7 +502,7 @@ DataStoreTest.prototype.testItShouldReturnCreatedDocumentCountByUser = function( DataStoreTest.prototype.testItShouldReturnDocumentIdsForUeserByEntity = function(){ expectAsserts(2); - var datastore = new nglr.DataStore( + var datastore = new DataStore( function(request, callback){ assertJsonEquals([["GET", "$users/misko@hevery.com"]], request); callback(200, [{Book:["1"], Library:["2"]}]); @@ -514,7 +514,7 @@ DataStoreTest.prototype.testItShouldReturnDocumentIdsForUeserByEntity = function DataStoreTest.prototype.testItShouldReturnNewInstanceOn404 = function(){ expectAsserts(7); var log = ""; - var datastore = new nglr.DataStore( + var datastore = new DataStore( function(request, callback){ assertJsonEquals([["GET", "User/misko"]], request); callback(200, [{$status_code:404}]); @@ -532,13 +532,13 @@ DataStoreTest.prototype.testItShouldReturnNewInstanceOn404 = function(){ DataStoreTest.prototype.testItShouldReturnNewInstanceOn404 = function(){ var log = ""; - var datastore = new nglr.DataStore( + var datastore = new DataStore( function(request, callback){ assertJsonEquals([["GET", "User/misko"],["GET", "User/adam"]], request); callback(200, [{$id:'misko'},{$id:'adam'}]); }); var User = datastore.entity("User"); - var users = User.loadMany(['misko', 'adam'], function(i){log+="cb "+nglr.toJson(i)+";";}); + var users = User.loadMany(['misko', 'adam'], function(i){log+="cb "+toJson(i)+";";}); datastore.flush(); assertEquals("misko", users[0].$id); assertEquals("adam", users[1].$id); @@ -546,7 +546,7 @@ DataStoreTest.prototype.testItShouldReturnNewInstanceOn404 = function(){ }; DataStoreTest.prototype.testItShouldCreateJoinAndQuery = function() { - var datastore = new nglr.DataStore(); + var datastore = new DataStore(); var Invoice = datastore.entity("Invoice"); var Customer = datastore.entity("Customer"); var InvoiceWithCustomer = datastore.join({ @@ -568,7 +568,7 @@ DataStoreTest.prototype.testItShouldCreateJoinAndQuery = function() { }; DataStoreTest.prototype.testItShouldThrowIfMoreThanOneEntityIsPrimary = function() { - var datastore = new nglr.DataStore(); + var datastore = new DataStore(); var Invoice = datastore.entity("Invoice"); var Customer = datastore.entity("Customer"); assertThrows("Exactly one entity needs to be primary.", function(){ @@ -580,7 +580,7 @@ DataStoreTest.prototype.testItShouldThrowIfMoreThanOneEntityIsPrimary = function }; DataStoreTest.prototype.testItShouldThrowIfLoopInReferences = function() { - var datastore = new nglr.DataStore(); + var datastore = new DataStore(); var Invoice = datastore.entity("Invoice"); var Customer = datastore.entity("Customer"); assertThrows("Infinite loop in join: invoice -> customer", function(){ @@ -592,7 +592,7 @@ DataStoreTest.prototype.testItShouldThrowIfLoopInReferences = function() { }; DataStoreTest.prototype.testItShouldThrowIfReferenceToNonExistantJoin = function() { - var datastore = new nglr.DataStore(); + var datastore = new DataStore(); var Invoice = datastore.entity("Invoice"); var Customer = datastore.entity("Customer"); assertThrows("Named entity 'x' is undefined.", function(){ @@ -604,7 +604,7 @@ DataStoreTest.prototype.testItShouldThrowIfReferenceToNonExistantJoin = function }; DataStoreTest.prototype.testItShouldThrowIfQueryOnNonPrimary = function() { - var datastore = new nglr.DataStore(); + var datastore = new DataStore(); var Invoice = datastore.entity("Invoice"); var Customer = datastore.entity("Customer"); var InvoiceWithCustomer = datastore.join({ diff --git a/test/EntityDeclarationTest.js b/test/EntityDeclarationTest.js index 5cab90f4..d64dd775 100644 --- a/test/EntityDeclarationTest.js +++ b/test/EntityDeclarationTest.js @@ -2,7 +2,7 @@ EntityDeclarationTest = TestCase('EntityDeclarationTest'); EntityDeclarationTest.prototype.testEntityTypeOnly = function(){ expectAsserts(2); - var scope = new nglr.Scope({$datastore:{entity:function(name){ + var scope = new Scope({$datastore:{entity:function(name){ assertEquals("Person", name); }}}); var init = scope.entity("Person"); @@ -11,7 +11,7 @@ EntityDeclarationTest.prototype.testEntityTypeOnly = function(){ EntityDeclarationTest.prototype.testWithDefaults = function(){ expectAsserts(4); - var scope = new nglr.Scope({$datastore:{entity:function(name, init){ + var scope = new Scope({$datastore:{entity:function(name, init){ assertEquals("Person", name); assertEquals("=a:", init.a); assertEquals(0, init.b.length); @@ -22,7 +22,7 @@ EntityDeclarationTest.prototype.testWithDefaults = function(){ EntityDeclarationTest.prototype.testWithName = function(){ expectAsserts(2); - var scope = new nglr.Scope({$datastore:{entity:function(name, init){ + var scope = new Scope({$datastore:{entity:function(name, init){ assertEquals("Person", name); return function (){ return {}; }; }}}); @@ -34,7 +34,7 @@ EntityDeclarationTest.prototype.testMultipleEntities = function(){ expectAsserts(3); var expect = ['Person', 'Book']; var i=0; - var scope = new nglr.Scope({$datastore:{entity:function(name, init){ + var scope = new Scope({$datastore:{entity:function(name, init){ assertEquals(expect[i], name); i++; return function (){ return {}; }; diff --git a/test/FileControllerTest.js b/test/FileControllerTest.js index ca5925e4..09eb6fc5 100644 --- a/test/FileControllerTest.js +++ b/test/FileControllerTest.js @@ -3,7 +3,7 @@ FileControllerTest = TestCase('FileControllerTest'); FileControllerTest.prototype.testOnSelectUpdateView = function(){ var view = jQuery(''); var swf = {}; - var controller = new nglr.FileController(view, null, swf); + var controller = new FileController(view, null, swf); swf.uploadFile = function(path){}; controller._on_select('A', 9, '9 bytes'); assertEquals(view.find('a').text(), "A"); @@ -11,14 +11,14 @@ FileControllerTest.prototype.testOnSelectUpdateView = function(){ }; FileControllerTest.prototype.testUpdateModelView = function(){ - var view = nglr.FileController.template(''); + var view = FileController.template(''); var input = $(''); var controller; - var scope = new nglr.Scope({value:{}, $binder:{updateView:function(){ + var scope = new Scope({value:{}, $binder:{updateView:function(){ controller.updateView(scope); }}}); view.data('scope', scope); - controller = new nglr.FileController(view, 'value.input', null, "http://server_base"); + controller = new FileController(view, 'value.input', null, "http://server_base"); var value = '{"text":"A", "size":123, "id":"890"}'; controller._on_uploadCompleteData(value); controller.updateView(scope); @@ -34,7 +34,7 @@ FileControllerTest.prototype.testUpdateModelView = function(){ FileControllerTest.prototype.testFileUpload = function(){ expectAsserts(1); var swf = {}; - var controller = new nglr.FileController(null, null, swf, "http://server_base"); + var controller = new FileController(null, null, swf, "http://server_base"); swf.uploadFile = function(path){ assertEquals("http://server_base/_attachments", path); }; @@ -47,16 +47,16 @@ FileControllerTest.prototype.testFileUploadNoFileIsNoop = function(){ var swf = {uploadFile:function(path){ fail(); }}; - var controller = new nglr.FileController(null, swf); + var controller = new FileController(null, swf); controller.upload("basePath", null); }; FileControllerTest.prototype.testRemoveAttachment = function(){ - var doc = nglr.FileController.template(); + var doc = FileController.template(); var input = $(''); - var scope = new nglr.Scope(); + var scope = new Scope(); input.data('scope', scope); - var controller = new nglr.FileController(doc, 'file', null, null); + var controller = new FileController(doc, 'file', null, null); controller.updateView(scope); assertEquals(false, doc.find('input').attr('checked')); @@ -75,10 +75,10 @@ FileControllerTest.prototype.testRemoveAttachment = function(){ }; FileControllerTest.prototype.testShouldEmptyOutOnUndefined = function () { - var view = nglr.FileController.template('hello'); - var controller = new nglr.FileController(view, 'abc', null, null); + var view = FileController.template('hello'); + var controller = new FileController(view, 'abc', null, null); - var scope = new nglr.Scope(); + var scope = new Scope(); scope.set('abc', {text: 'myname', url: 'myurl', size: 1234}); controller.updateView(scope); diff --git a/test/FiltersTest.js b/test/FiltersTest.js index 8943fdd4..c219f24f 100644 --- a/test/FiltersTest.js +++ b/test/FiltersTest.js @@ -3,7 +3,7 @@ FiltersTest = TestCase('FiltersTest'); FiltersTest.prototype.testCurrency = function(){ var html = $(''); var context = {element:html[0]}; - var currency = nglr.bind(context, angular.filter.currency); + var currency = bind(context, angular.filter.currency); assertEquals(currency(0), '$0.00'); assertEquals(html.hasClass('ng-format-negative'), false); @@ -15,8 +15,8 @@ FiltersTest.prototype.testCurrency = function(){ FiltersTest.prototype.testFilterThisIsContext = function(){ expectAsserts(2); - var scope = new nglr.Scope(); - nglr.Scope.expressionCache = {}; + var scope = new Scope(); + Scope.expressionCache = {}; var context = {element:123}; angular.filter.testFn = function () { assertEquals('Context not equal', this, context); @@ -28,7 +28,7 @@ FiltersTest.prototype.testFilterThisIsContext = function(){ FiltersTest.prototype.testNumberFormat = function(){ var context = {jqElement:$('')}; - var number = nglr.bind(context, angular.filter.number); + var number = bind(context, angular.filter.number); assertEquals('0', number(0, 0)); assertEquals('0.00', number(0)); @@ -40,7 +40,7 @@ FiltersTest.prototype.testNumberFormat = function(){ }; FiltersTest.prototype.testJson = function () { - assertEquals(nglr.toJson({a:"b"}, true), angular.filter.json({a:"b"})); + assertEquals(toJson({a:"b"}, true), angular.filter.json({a:"b"})); }; FiltersTest.prototype.testPackageTracking = function () { @@ -48,9 +48,9 @@ FiltersTest.prototype.testPackageTracking = function () { var val = angular.filter.trackPackage(trackingNo, title); assertNotNull("Did Not Match: " + trackingNo, val); assertEquals(angular.filter.Meta.TAG, val.TAG); - assertEquals(title + ": " + nglr.trim(trackingNo), val.text); + assertEquals(title + ": " + trim(trackingNo), val.text); assertNotNull(val.url); - assertEquals(nglr.trim(trackingNo), val.trackingNo); + assertEquals(trim(trackingNo), val.trackingNo); assertEquals('' + val.text + '', val.html); }; assert('UPS', ' 1Z 999 999 99 9999 999 9 '); @@ -83,7 +83,7 @@ FiltersTest.prototype.testLink = function() { }; FiltersTest.prototype.testBytes = function(){ - var controller = new nglr.FileController(); + var controller = new FileController(); assertEquals(angular.filter.bytes(123), '123 bytes'); assertEquals(angular.filter.bytes(1234), '1.2 KB'); assertEquals(angular.filter.bytes(1234567), '1.1 MB'); diff --git a/test/JsonTest.js b/test/JsonTest.js index 5c3644f5..cf49bec3 100644 --- a/test/JsonTest.js +++ b/test/JsonTest.js @@ -1,69 +1,69 @@ JsonTest = TestCase("JsonTest"); JsonTest.prototype.testPrimitives = function () { - assertEquals("null", nglr.toJson(0/0)); - assertEquals("null", nglr.toJson(null)); - assertEquals("true", nglr.toJson(true)); - assertEquals("false", nglr.toJson(false)); - assertEquals("123.45", nglr.toJson(123.45)); - assertEquals('"abc"', nglr.toJson("abc")); - assertEquals('"a \\t \\n \\r b \\\\"', nglr.toJson("a \t \n \r b \\")); + assertEquals("null", toJson(0/0)); + assertEquals("null", toJson(null)); + assertEquals("true", toJson(true)); + assertEquals("false", toJson(false)); + assertEquals("123.45", toJson(123.45)); + assertEquals('"abc"', toJson("abc")); + assertEquals('"a \\t \\n \\r b \\\\"', toJson("a \t \n \r b \\")); }; JsonTest.prototype.testEscaping = function () { - assertEquals("\"7\\\\\\\"7\"", nglr.toJson("7\\\"7")); + assertEquals("\"7\\\\\\\"7\"", toJson("7\\\"7")); }; JsonTest.prototype.testObjects = function () { - assertEquals('{"a":1,"b":2}', nglr.toJson({a:1,b:2})); - assertEquals('{"a":{"b":2}}', nglr.toJson({a:{b:2}})); - assertEquals('{"a":{"b":{"c":0}}}', nglr.toJson({a:{b:{c:0}}})); - assertEquals('{"a":{"b":null}}', nglr.toJson({a:{b:0/0}})); + assertEquals('{"a":1,"b":2}', toJson({a:1,b:2})); + assertEquals('{"a":{"b":2}}', toJson({a:{b:2}})); + assertEquals('{"a":{"b":{"c":0}}}', toJson({a:{b:{c:0}}})); + assertEquals('{"a":{"b":null}}', toJson({a:{b:0/0}})); }; JsonTest.prototype.testObjectPretty = function () { - assertEquals('{\n "a":1,\n "b":2}', nglr.toJson({a:1,b:2}, true)); - assertEquals('{\n "a":{\n "b":2}}', nglr.toJson({a:{b:2}}, true)); + assertEquals('{\n "a":1,\n "b":2}', toJson({a:1,b:2}, true)); + assertEquals('{\n "a":{\n "b":2}}', toJson({a:{b:2}}, true)); }; JsonTest.prototype.testArray = function () { - assertEquals('[]', nglr.toJson([])); - assertEquals('[1,"b"]', nglr.toJson([1,"b"])); + assertEquals('[]', toJson([])); + assertEquals('[1,"b"]', toJson([1,"b"])); }; JsonTest.prototype.testIgnoreFunctions = function () { - assertEquals('[null,1]', nglr.toJson([function(){},1])); - assertEquals('{}', nglr.toJson({a:function(){}})); + assertEquals('[null,1]', toJson([function(){},1])); + assertEquals('{}', toJson({a:function(){}})); }; JsonTest.prototype.testParseNull = function () { - assertNull(nglr.fromJson("null")); + assertNull(fromJson("null")); }; JsonTest.prototype.testParseBoolean = function () { - assertTrue(nglr.fromJson("true")); - assertFalse(nglr.fromJson("false")); + assertTrue(fromJson("true")); + assertFalse(fromJson("false")); }; JsonTest.prototype.test$$isIgnored = function () { - assertEquals("{}", nglr.toJson({$$:0})); + assertEquals("{}", toJson({$$:0})); }; JsonTest.prototype.testArrayWithEmptyItems = function () { var a = []; a[1] = "X"; - assertEquals('[null,"X"]', nglr.toJson(a)); + assertEquals('[null,"X"]', toJson(a)); }; JsonTest.prototype.testItShouldEscapeUnicode = function () { assertEquals(1, "\u00a0".length); - assertEquals(8, nglr.toJson("\u00a0").length); - assertEquals(1, nglr.fromJson(nglr.toJson("\u00a0")).length); + assertEquals(8, toJson("\u00a0").length); + assertEquals(1, fromJson(toJson("\u00a0")).length); }; JsonTest.prototype.testItShouldUTCDates = function() { var date = angular.String.toDate("2009-10-09T01:02:03Z"); - assertEquals('"2009-10-09T01:02:03Z"', nglr.toJson(date)); + assertEquals('"2009-10-09T01:02:03Z"', toJson(date)); assertEquals(date.getTime(), - nglr.fromJson('"2009-10-09T01:02:03Z"').getTime()); + fromJson('"2009-10-09T01:02:03Z"').getTime()); }; diff --git a/test/LoaderTest.js b/test/LoaderTest.js index 91a804a5..88ae3efa 100644 --- a/test/LoaderTest.js +++ b/test/LoaderTest.js @@ -3,7 +3,7 @@ LoaderTest = TestCase('LoaderTest'); LoaderTest.prototype.testLoadCss = function(){ if ($.browser.safari) return; var head = jQuery('')[0]; - var loader = new nglr.Loader(document, head, {}); + var loader = new Loader(document, head, {}); var log = ''; loader.config.server = 'http://'; loader.loadCss('x'); @@ -11,15 +11,15 @@ LoaderTest.prototype.testLoadCss = function(){ }; LoaderTest.prototype.testDefaultDatabasePathFromSubdomain = function() { - var loader = new nglr.Loader(null, null, {server:"http://account.getangular.com", database:"database"}); + var loader = new Loader(null, null, {server:"http://account.getangular.com", database:"database"}); loader.computeConfiguration(); assertEquals("database", loader.config.database); - loader = new nglr.Loader(null, null, {server:"http://account.getangular.com"}); + loader = new Loader(null, null, {server:"http://account.getangular.com"}); loader.computeConfiguration(); assertEquals("account", loader.config.database); - loader = new nglr.Loader(null, null, {server:"https://account.getangular.com"}); + loader = new Loader(null, null, {server:"https://account.getangular.com"}); loader.computeConfiguration(); assertEquals("account", loader.config.database); }; @@ -31,7 +31,7 @@ UrlWatcherTest = TestCase('UrlWatcherTest'); UrlWatcherTest.prototype.testUrlWatcher = function () { expectAsserts(2); var location = {href:"http://server", hash:""}; - var watcher = new nglr.UrlWatcher(location); + var watcher = new UrlWatcher(location); watcher.delay = 1; watcher.listener = function(url){ assertEquals('http://getangular.test', url); @@ -49,9 +49,9 @@ UrlWatcherTest.prototype.testUrlWatcher = function () { UrlWatcherTest.prototype.testItShouldFireOnUpdateEventWhenSpecialURLSet = function(){ expectAsserts(2); var location = {href:"http://server", hash:"#$iframe_notify=1234"}; - var watcher = new nglr.UrlWatcher(location); - nglr._iframe_notify_1234 = function () { - assertEquals("undefined", typeof nglr._iframe_notify_1234); + var watcher = new UrlWatcher(location); + callbacks._iframe_notify_1234 = function () { + assertEquals("undefined", typeof callbacks._iframe_notify_1234); assertEquals("http://server2#", location.href); }; watcher.delay = 1; @@ -66,5 +66,5 @@ UrlWatcherTest.prototype.testItShouldFireOnUpdateEventWhenSpecialURLSet = functi FunctionTest = TestCase("FunctionTest"); FunctionTest.prototype.testEscapeHtml = function () { - assertEquals("<div>&amp;</div>", nglr.escapeHtml('
      &
      ')); + assertEquals("<div>&amp;</div>", escapeHtml('
      &
      ')); }; \ No newline at end of file diff --git a/test/ModelTest.js b/test/ModelTest.js index 5d9119a1..dbd97778 100644 --- a/test/ModelTest.js +++ b/test/ModelTest.js @@ -1,7 +1,7 @@ ModelTest = TestCase('ModelTest'); ModelTest.prototype.testLoadSaveOperations = function(){ - var m1 = new nglr.DataStore().entity('A')(); + var m1 = new DataStore().entity('A')(); m1.a = 1; var m2 = {b:1}; @@ -13,7 +13,7 @@ ModelTest.prototype.testLoadSaveOperations = function(){ }; ModelTest.prototype.testLoadfromDoesNotClobberFunctions = function(){ - var m1 = new nglr.DataStore().entity('A')(); + var m1 = new DataStore().entity('A')(); m1.id = function(){return 'OK';}; m1.$loadFrom({id:null}); assertEquals(m1.id(), 'OK'); @@ -24,7 +24,7 @@ ModelTest.prototype.testLoadfromDoesNotClobberFunctions = function(){ }; ModelTest.prototype.testDataStoreDoesNotGetClobbered = function(){ - var ds = new nglr.DataStore(); + var ds = new DataStore(); var m = ds.entity('A')(); assertTrue(m.$$entity.datastore === ds); m.$loadFrom({}); @@ -33,7 +33,7 @@ ModelTest.prototype.testDataStoreDoesNotGetClobbered = function(){ ModelTest.prototype.testManagedModelDelegatesMethodsToDataStore = function(){ expectAsserts(7); - var datastore = new nglr.DataStore(); + var datastore = new DataStore(); var model = datastore.entity("A", {a:1})(); var fn = {}; datastore.save = function(instance, callback) { @@ -56,7 +56,7 @@ ModelTest.prototype.testManagedModelDelegatesMethodsToDataStore = function(){ ModelTest.prototype.testManagedModelCanBeForcedToFlush = function(){ expectAsserts(6); - var datastore = new nglr.DataStore(); + var datastore = new DataStore(); var model = datastore.entity("A", {a:1})(); datastore.save = function(instance, callback) { @@ -77,7 +77,7 @@ ModelTest.prototype.testManagedModelCanBeForcedToFlush = function(){ ModelTest.prototype.testItShouldMakeDeepCopyOfInitialValues = function (){ var initial = {a:[]}; - var entity = new nglr.DataStore().entity("A", initial); + var entity = new DataStore().entity("A", initial); var model = entity(); model.a.push(1); assertEquals(0, entity().a.length); diff --git a/test/ParserTest.js b/test/ParserTest.js index 7fe8e6a4..058010f3 100644 --- a/test/ParserTest.js +++ b/test/ParserTest.js @@ -1,7 +1,7 @@ LexerTest = TestCase('LexerTest'); LexerTest.prototype.testTokenizeAString = function(){ - var lexer = new nglr.Lexer("a.bc[22]+1.3|f:'a\\\'c':\"d\\\"e\""); + var lexer = new Lexer("a.bc[22]+1.3|f:'a\\\'c':\"d\\\"e\""); var tokens = lexer.parse(); var i = 0; assertEquals(tokens[i].index, 0); @@ -54,7 +54,7 @@ LexerTest.prototype.testTokenizeAString = function(){ LexerTest.prototype.testTokenizeRegExp = function(){ - var lexer = new nglr.Lexer("/r 1/"); + var lexer = new Lexer("/r 1/"); var tokens = lexer.parse(); var i = 0; assertEquals(tokens[i].index, 0); @@ -64,7 +64,7 @@ LexerTest.prototype.testTokenizeRegExp = function(){ LexerTest.prototype.testQuotedString = function(){ var str = "['\\'', \"\\\"\"]"; - var lexer = new nglr.Lexer(str); + var lexer = new Lexer(str); var tokens = lexer.parse(); assertEquals(1, tokens[1].index); @@ -77,21 +77,21 @@ LexerTest.prototype.testQuotedString = function(){ LexerTest.prototype.testQuotedStringEscape = function(){ var str = '"\\"\\n\\f\\r\\t\\v\\u00A0"'; - var lexer = new nglr.Lexer(str); + var lexer = new Lexer(str); var tokens = lexer.parse(); assertEquals('"\n\f\r\t\v\u00A0', tokens[0].text); }; LexerTest.prototype.testTokenizeUnicode = function(){ - var lexer = new nglr.Lexer('"\\u00A0"'); + var lexer = new Lexer('"\\u00A0"'); var tokens = lexer.parse(); assertEquals(1, tokens.length); assertEquals('\u00a0', tokens[0].text); }; LexerTest.prototype.testTokenizeRegExpWithOptions = function(){ - var lexer = new nglr.Lexer("/r/g"); + var lexer = new Lexer("/r/g"); var tokens = lexer.parse(); var i = 0; assertEquals(tokens[i].index, 0); @@ -101,7 +101,7 @@ LexerTest.prototype.testTokenizeRegExpWithOptions = function(){ }; LexerTest.prototype.testTokenizeRegExpWithEscape = function(){ - var lexer = new nglr.Lexer("/\\/\\d/"); + var lexer = new Lexer("/\\/\\d/"); var tokens = lexer.parse(); var i = 0; assertEquals(tokens[i].index, 0); @@ -110,14 +110,14 @@ LexerTest.prototype.testTokenizeRegExpWithEscape = function(){ }; LexerTest.prototype.testIgnoreWhitespace = function(){ - var lexer = new nglr.Lexer("a \t \n \r b"); + var lexer = new Lexer("a \t \n \r b"); var tokens = lexer.parse(); assertEquals(tokens[0].text, 'a'); assertEquals(tokens[1].text, 'b'); }; LexerTest.prototype.testRelation = function(){ - var lexer = new nglr.Lexer("! == != < > <= >="); + var lexer = new Lexer("! == != < > <= >="); var tokens = lexer.parse(); assertEquals(tokens[0].text, '!'); assertEquals(tokens[1].text, '=='); @@ -129,7 +129,7 @@ LexerTest.prototype.testRelation = function(){ }; LexerTest.prototype.testStatements = function(){ - var lexer = new nglr.Lexer("a;b;"); + var lexer = new Lexer("a;b;"); var tokens = lexer.parse(); assertEquals(tokens[0].text, 'a'); assertEquals(tokens[1].text, ';'); @@ -140,7 +140,7 @@ LexerTest.prototype.testStatements = function(){ ParserTest = TestCase('ParserTest'); ParserTest.prototype.testExpressions = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); assertEquals(scope.eval("-1"), -1); assertEquals(scope.eval("1 + 2.5"), 3.5); assertEquals(scope.eval("1 + -2.5"), -1.5); @@ -151,7 +151,7 @@ ParserTest.prototype.testExpressions = function(){ }; ParserTest.prototype.testComparison = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); assertEquals(scope.eval("false"), false); assertEquals(scope.eval("!true"), false); assertEquals(scope.eval("1==1"), true); @@ -163,14 +163,14 @@ ParserTest.prototype.testComparison = function(){ }; ParserTest.prototype.testLogical = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); assertEquals(scope.eval("0&&2"), 0&&2); assertEquals(scope.eval("0||2"), 0||2); assertEquals(scope.eval("0||1&&2"), 0||1&&2); }; ParserTest.prototype.testString = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); assertEquals(scope.eval("'a' + 'b c'"), "ab c"); }; @@ -182,7 +182,7 @@ ParserTest.prototype.testFilters = function(){ angular.filter.upper = {_case:function(input) { return input.toUpperCase(); }}; - var scope = new nglr.Scope(); + var scope = new Scope(); try { scope.eval("1|nonExistant"); fail(); @@ -196,7 +196,7 @@ ParserTest.prototype.testFilters = function(){ }; ParserTest.prototype.testScopeAccess = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); scope.set('a', 123); scope.set('b.c', 456); assertEquals(scope.eval("a", scope), 123); @@ -205,16 +205,16 @@ ParserTest.prototype.testScopeAccess = function(){ }; ParserTest.prototype.testGrouping = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); assertEquals(scope.eval("(1+2)*3"), (1+2)*3); }; ParserTest.prototype.testAssignments = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); assertEquals(scope.eval("a=12"), 12); assertEquals(scope.get("a"), 12); - scope = new nglr.Scope(); + scope = new Scope(); assertEquals(scope.eval("x.y.z=123;"), 123); assertEquals(scope.get("x.y.z"), 123); @@ -224,13 +224,13 @@ ParserTest.prototype.testAssignments = function(){ }; ParserTest.prototype.testFunctionCallsNoArgs = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); scope.set('const', function(a,b){return 123;}); assertEquals(scope.eval("const()"), 123); }; ParserTest.prototype.testFunctionCalls = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); scope.set('add', function(a,b){ return a+b; }); @@ -238,7 +238,7 @@ ParserTest.prototype.testFunctionCalls = function(){ }; ParserTest.prototype.testCalculationBug = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); scope.set('taxRate', 8); scope.set('subTotal', 100); assertEquals(scope.eval("taxRate / 100 * subTotal"), 8); @@ -246,7 +246,7 @@ ParserTest.prototype.testCalculationBug = function(){ }; ParserTest.prototype.testArray = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); assertEquals(scope.eval("[]").length, 0); assertEquals(scope.eval("[1, 2]").length, 2); assertEquals(scope.eval("[1, 2]")[0], 1); @@ -254,7 +254,7 @@ ParserTest.prototype.testArray = function(){ }; ParserTest.prototype.testArrayAccess = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); assertEquals(scope.eval("[1][0]"), 1); assertEquals(scope.eval("[[1]][0][0]"), 1); assertEquals(scope.eval("[].length"), 0); @@ -262,33 +262,33 @@ ParserTest.prototype.testArrayAccess = function(){ }; ParserTest.prototype.testObject = function(){ - var scope = new nglr.Scope(); - assertEquals(nglr.toJson(scope.eval("{}")), "{}"); - assertEquals(nglr.toJson(scope.eval("{a:'b'}")), '{"a":"b"}'); - assertEquals(nglr.toJson(scope.eval("{'a':'b'}")), '{"a":"b"}'); - assertEquals(nglr.toJson(scope.eval("{\"a\":'b'}")), '{"a":"b"}'); + var scope = new Scope(); + assertEquals(toJson(scope.eval("{}")), "{}"); + assertEquals(toJson(scope.eval("{a:'b'}")), '{"a":"b"}'); + assertEquals(toJson(scope.eval("{'a':'b'}")), '{"a":"b"}'); + assertEquals(toJson(scope.eval("{\"a\":'b'}")), '{"a":"b"}'); }; ParserTest.prototype.testObjectAccess = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); assertEquals("WC", scope.eval("{false:'WC', true:'CC'}[false]")); }; ParserTest.prototype.testJSON = function(){ - var scope = new nglr.Scope(); - assertEquals(nglr.toJson(scope.eval("[{}]")), "[{}]"); - assertEquals(nglr.toJson(scope.eval("[{a:[]}, {b:1}]")), '[{"a":[]},{"b":1}]'); + var scope = new Scope(); + assertEquals(toJson(scope.eval("[{}]")), "[{}]"); + assertEquals(toJson(scope.eval("[{a:[]}, {b:1}]")), '[{"a":[]},{"b":1}]'); }; ParserTest.prototype.testMultippleStatements = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); assertEquals(scope.eval("a=1;b=3;a+b"), 4); assertEquals(scope.eval(";;1;;"), 1); }; ParserTest.prototype.testParseThrow = function(){ expectAsserts(1); - var scope = new nglr.Scope(); + var scope = new Scope(); scope.set('e', 'abc'); try { scope.eval("throw e"); @@ -298,7 +298,7 @@ ParserTest.prototype.testParseThrow = function(){ }; ParserTest.prototype.testMethodsGetDispatchedWithCorrectThis = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); var C = function (){ this.a=123; }; @@ -310,7 +310,7 @@ ParserTest.prototype.testMethodsGetDispatchedWithCorrectThis = function(){ assertEquals(123, scope.eval("obj.getA()")); }; ParserTest.prototype.testMethodsArgumentsGetCorrectThis = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); var C = function (){ this.a=123; }; @@ -326,13 +326,13 @@ ParserTest.prototype.testMethodsArgumentsGetCorrectThis = function(){ }; ParserTest.prototype.testObjectPointsToScopeValue = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); scope.set('a', "abc"); assertEquals("abc", scope.eval("{a:a}").a); }; ParserTest.prototype.testFieldAccess = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); var fn = function(){ return {name:'misko'}; }; @@ -341,14 +341,14 @@ ParserTest.prototype.testFieldAccess = function(){ }; ParserTest.prototype.testArrayIndexBug = function () { - var scope = new nglr.Scope(); + var scope = new Scope(); scope.set('items', [{}, {name:'misko'}]); assertEquals("misko", scope.eval('items[1].name')); }; ParserTest.prototype.testArrayAssignment = function () { - var scope = new nglr.Scope(); + var scope = new Scope(); scope.set('items', []); assertEquals("abc", scope.eval('items[1] = "abc"')); @@ -359,30 +359,30 @@ ParserTest.prototype.testArrayAssignment = function () { }; ParserTest.prototype.testFiltersCanBeGrouped = function () { - var scope = new nglr.Scope({name:'MISKO'}); + var scope = new Scope({name:'MISKO'}); assertEquals('misko', scope.eval('n = (name|lowercase)')); assertEquals('misko', scope.eval('n')); }; ParserTest.prototype.testFiltersCanBeGrouped = function () { - var scope = new nglr.Scope({name:'MISKO'}); + var scope = new Scope({name:'MISKO'}); assertEquals('misko', scope.eval('n = (name|lowercase)')); assertEquals('misko', scope.eval('n')); }; ParserTest.prototype.testRemainder = function () { - var scope = new nglr.Scope(); + var scope = new Scope(); assertEquals(1, scope.eval('1%2')); }; ParserTest.prototype.testSumOfUndefinedIsNotUndefined = function () { - var scope = new nglr.Scope(); + var scope = new Scope(); assertEquals(1, scope.eval('1+undefined')); assertEquals(1, scope.eval('undefined+1')); }; ParserTest.prototype.testMissingThrowsError = function() { - var scope = new nglr.Scope(); + var scope = new Scope(); try { scope.eval('[].count('); fail(); @@ -392,7 +392,7 @@ ParserTest.prototype.testMissingThrowsError = function() { }; ParserTest.prototype.testItShouldParseOnChangeIntoHashSet = function () { - var scope = new nglr.Scope({count:0}); + var scope = new Scope({count:0}); scope.watch("$anchor.a:count=count+1;$anchor.a:count=count+20;b:count=count+300"); scope.watchListeners["$anchor.a"].listeners[0](); @@ -403,7 +403,7 @@ ParserTest.prototype.testItShouldParseOnChangeIntoHashSet = function () { assertEquals(321, scope.get("count")); }; ParserTest.prototype.testItShouldParseOnChangeBlockIntoHashSet = function () { - var scope = new nglr.Scope({count:0}); + var scope = new Scope({count:0}); var listeners = {a:[], b:[]}; scope.watch("a:{count=count+1;count=count+20;};b:count=count+300", function(n, fn){listeners[n].push(fn);}); @@ -417,12 +417,12 @@ ParserTest.prototype.testItShouldParseOnChangeBlockIntoHashSet = function () { }; ParserTest.prototype.testItShouldParseEmptyOnChangeAsNoop = function () { - var scope = new nglr.Scope(); + var scope = new Scope(); scope.watch("", function(){fail();}); }; ParserTest.prototype.testItShouldCreateClosureFunctionWithNoArguments = function () { - var scope = new nglr.Scope(); + var scope = new Scope(); var fn = scope.eval("{:value}"); scope.set("value", 1); assertEquals(1, fn()); @@ -433,7 +433,7 @@ ParserTest.prototype.testItShouldCreateClosureFunctionWithNoArguments = function }; ParserTest.prototype.testItShouldCreateClosureFunctionWithArguments = function () { - var scope = new nglr.Scope(); + var scope = new Scope(); var fn = scope.eval("{(a):value+a}"); scope.set("value", 1); assertEquals(11, fn(10)); @@ -444,14 +444,14 @@ ParserTest.prototype.testItShouldCreateClosureFunctionWithArguments = function ( }; ParserTest.prototype.testItShouldHaveDefaultArugument = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); var fn = scope.eval("{:$*2}"); assertEquals(4, fn(2)); }; ParserTest.prototype.testReturnFunctionsAreNotBound = function(){ - var scope = new nglr.Scope(); - scope.set("$datastore", new nglr.DataStore()); + var scope = new Scope(); + scope.set("$datastore", new DataStore()); scope.entity("Group"); var Group = scope.get("Group"); assertEquals("eval Group", "function", typeof scope.eval("Group")); diff --git a/test/ScopeTest.js b/test/ScopeTest.js index c66a2329..e1c5c8ce 100644 --- a/test/ScopeTest.js +++ b/test/ScopeTest.js @@ -23,13 +23,13 @@ ScopeTest.prototype.testNoScopeDoesNotCauseInfiniteRecursion = function(){ }; ScopeTest.prototype.testScopeEval = function(){ - var scope = new nglr.Scope({b:345}); + var scope = new Scope({b:345}); assertEquals(scope.eval('b = 123'), 123); assertEquals(scope.get('b'), 123); }; ScopeTest.prototype.testScopeFromPrototype = function(){ - var scope = new nglr.Scope({b:123}); + var scope = new Scope({b:123}); scope.eval('a = b'); scope.eval('b = 456'); assertEquals(scope.get('a'), 123); @@ -37,32 +37,32 @@ ScopeTest.prototype.testScopeFromPrototype = function(){ }; ScopeTest.prototype.testSetScopeGet = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); scope.set('a', 987); assertEquals(scope.get('a'), 987); assertEquals(scope.eval('a'), 987); }; ScopeTest.prototype.testGetChain = function(){ - var scope = new nglr.Scope({a:{b:987}}); + var scope = new Scope({a:{b:987}}); assertEquals(scope.get('a.b'), 987); assertEquals(scope.eval('a.b'), 987); }; ScopeTest.prototype.testGetUndefinedChain = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); assertEquals(typeof scope.get('a.b'), 'undefined'); }; ScopeTest.prototype.testSetChain = function(){ - var scope = new nglr.Scope({a:{}}); + var scope = new Scope({a:{}}); scope.set('a.b', 987); assertEquals(scope.get('a.b'), 987); assertEquals(scope.eval('a.b'), 987); }; ScopeTest.prototype.testSetGetOnChain = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); scope.set('a.b', 987); assertEquals(scope.get('a.b'), 987); assertEquals(scope.eval('a.b'), 987); @@ -70,7 +70,7 @@ ScopeTest.prototype.testSetGetOnChain = function(){ ScopeTest.prototype.testGlobalFunctionAccess =function(){ window['scopeAddTest'] = function (a, b) {return a+b;}; - var scope = new nglr.Scope({window:window}); + var scope = new Scope({window:window}); assertEquals(scope.eval('window.scopeAddTest(1,2)'), 3); scope.set('add', function (a, b) {return a+b;}); @@ -82,7 +82,7 @@ ScopeTest.prototype.testGlobalFunctionAccess =function(){ ScopeTest.prototype.testValidationEval = function(){ expectAsserts(4); - var scope = new nglr.Scope(); + var scope = new Scope(); angular.validator.testValidator = function(value, expect){ assertEquals(scope, this.scope); return value == expect ? null : "Error text"; @@ -96,7 +96,7 @@ ScopeTest.prototype.testValidationEval = function(){ ScopeTest.prototype.testCallingNonExistantMethodShouldProduceFriendlyException = function() { expectAsserts(1); - var scope = new nglr.Scope({obj:{}}); + var scope = new Scope({obj:{}}); try { scope.eval("obj.iDontExist()"); fail(); @@ -106,7 +106,7 @@ ScopeTest.prototype.testCallingNonExistantMethodShouldProduceFriendlyException = }; ScopeTest.prototype.testAccessingWithInvalidPathShouldThrowError = function() { - var scope = new nglr.Scope(); + var scope = new Scope(); try { scope.get('a.{{b}}'); fail(); @@ -116,25 +116,25 @@ ScopeTest.prototype.testAccessingWithInvalidPathShouldThrowError = function() { }; ScopeTest.prototype.testItShouldHave$parent = function() { - var parent = new nglr.Scope({}, "ROOT"); - var child = new nglr.Scope(parent.state); + var parent = new Scope({}, "ROOT"); + var child = new Scope(parent.state); assertSame("parent", child.state.$parent, parent.state); assertSame("root", child.state.$root, parent.state); }; ScopeTest.prototype.testItShouldHave$root = function() { - var scope = new nglr.Scope({}, "ROOT"); + var scope = new Scope({}, "ROOT"); assertSame(scope.state.$root, scope.state); }; ScopeTest.prototype.testItShouldBuildPathOnUndefined = function(){ - var scope = new nglr.Scope({}, "ROOT"); + var scope = new Scope({}, "ROOT"); scope.setEval("a.$b.c", 1); assertJsonEquals({$b:{c:1}}, scope.get("a")); }; ScopeTest.prototype.testItShouldMapUnderscoreFunctions = function(){ - var scope = new nglr.Scope({}, "ROOT"); + var scope = new Scope({}, "ROOT"); scope.set("a", [1,2,3]); assertEquals('function', typeof scope.get("a.$size")); scope.eval("a.$includeIf(4,true)"); diff --git a/test/ServerTest.js b/test/ServerTest.js index d1f662f9..e367c90a 100644 --- a/test/ServerTest.js +++ b/test/ServerTest.js @@ -1,7 +1,7 @@ ServerTest = TestCase("ServerTest"); ServerTest.prototype.testBreakLargeRequestIntoPackets = function() { var log = ""; - var server = new nglr.Server("http://server", function(url){ + var server = new Server("http://server", function(url){ log += "|" + url; }); server.maxSize = 30; @@ -10,7 +10,7 @@ ServerTest.prototype.testBreakLargeRequestIntoPackets = function() { assertEquals(200, code); assertEquals("response", r); }); - nglr.uuid0("response"); + callbacks.uuid0("response"); assertEquals( "|http://server/$/uuid0/2/1?h=eyJtIjoiUE9TVCIsInAiOnt9LCJ1Ij" + "|http://server/$/uuid0/2/2?h=oiL2RhdGEvZGF0YWJhc2UifQ==", @@ -18,7 +18,7 @@ ServerTest.prototype.testBreakLargeRequestIntoPackets = function() { }; ServerTest.prototype.testItShouldEncodeUsingUrlRules = function() { - var server = new nglr.Server("http://server"); + var server = new Server("http://server"); assertEquals("fn5-fn5-", server.base64url("~~~~~~")); assertEquals("fn5_fn5_", server.base64url("~~\u007f~~\u007f")); }; @@ -28,13 +28,13 @@ FrameServerTest = TestCase("FrameServerTest"); FrameServerTest.prototype = { testRead:function(){ var window = {name:'$DATASET:"MyData"'}; - var server = new nglr.FrameServer(window); + var server = new FrameServer(window); server.read(); assertEquals("MyData", server.data); }, testWrite:function(){ var window = {}; - var server = new nglr.FrameServer(window); + var server = new FrameServer(window); server.data = "TestData" server.write(); assertEquals('$DATASET:"TestData"', window.name); diff --git a/test/UsersTest.js b/test/UsersTest.js index c808885c..f0ff545a 100644 --- a/test/UsersTest.js +++ b/test/UsersTest.js @@ -10,10 +10,10 @@ UsersTest.prototype = { testItShouldFetchCurrentUser:function(){ expectAsserts(5); var user; - var users = new nglr.Users({request:function(method, url, request, callback){ + var users = new Users({request:function(method, url, request, callback){ assertEquals("GET", method); assertEquals("/account.json", url); - assertEquals("{}", nglr.toJson(request)); + assertEquals("{}", toJson(request)); callback(200, {$status_code:200, user:{name:'misko'}}); }}); users.fetchCurrentUser(function(u){ diff --git a/test/WidgetsTest.js b/test/WidgetsTest.js index a245abda..fe20e664 100644 --- a/test/WidgetsTest.js +++ b/test/WidgetsTest.js @@ -2,8 +2,8 @@ WidgetTest = TestCase('WidgetTest'); WidgetTest.prototype.testRequired = function () { var view = $(''); - var scope = new nglr.Scope({$invalidWidgets:[]}); - var cntl = new nglr.TextController(view[0], 'a'); + var scope = new Scope({$invalidWidgets:[]}); + var cntl = new TextController(view[0], 'a'); cntl.updateView(scope); assertTrue(view.hasClass('ng-validation-error')); assertEquals("Required Value", view.attr('ng-error')); @@ -15,8 +15,8 @@ WidgetTest.prototype.testRequired = function () { WidgetTest.prototype.testValidator = function () { var view = $(''); - var scope = new nglr.Scope({$invalidWidgets:[]}); - var cntl = new nglr.TextController(view[0], 'a'); + var scope = new Scope({$invalidWidgets:[]}); + var cntl = new TextController(view[0], 'a'); angular.validator.testValidator = function(value, expect){ return value == expect ? null : "Error text"; }; @@ -43,8 +43,8 @@ WidgetTest.prototype.testValidator = function () { WidgetTest.prototype.testRequiredValidator = function () { var view = $(''); - var scope = new nglr.Scope({$invalidWidgets:[]}); - var cntl = new nglr.TextController(view[0], 'a'); + var scope = new Scope({$invalidWidgets:[]}); + var cntl = new TextController(view[0], 'a'); angular.validator.testValidator = function(value, expect){ return value == expect ? null : "Error text"; }; @@ -67,29 +67,29 @@ WidgetTest.prototype.testRequiredValidator = function () { delete angular.validator['testValidator']; }; -TextController = TestCase("TextController"); +TextControllerTest = TestCase("TextControllerTest"); -TextController.prototype.testDatePicker = function() { +TextControllerTest.prototype.testDatePicker = function() { var input = $(''); - input.data('scope', new nglr.Scope()); + input.data('scope', new Scope()); var body = $(document.body); body.append(input); - var binder = new nglr.Binder(input[0], new nglr.WidgetFactory()); + var binder = new Binder(input[0], new WidgetFactory()); assertTrue('before', input.data('datepicker') === undefined); binder.compile(); assertTrue('after', input.data('datepicker') !== null); assertTrue(body.html(), input.hasClass('hasDatepicker')); }; -RepeaterUpdater = TestCase("RepeaterUpdater"); +RepeaterUpdaterTest = TestCase("RepeaterUpdaterTest"); -RepeaterUpdater.prototype.testRemoveThenAdd = function() { +RepeaterUpdaterTest.prototype.testRemoveThenAdd = function() { var view = $("
      "); var template = function () { return $("
    • "); }; - var repeater = new nglr.RepeaterUpdater(view.find("span"), "a in b", template, ""); - var scope = new nglr.Scope(); + var repeater = new RepeaterUpdater(view.find("span"), "a in b", template, ""); + var scope = new Scope(); scope.set('b', [1,2]); repeater.updateView(scope); @@ -102,14 +102,14 @@ RepeaterUpdater.prototype.testRemoveThenAdd = function() { assertEquals(1, view.find("li").size()); }; -RepeaterUpdater.prototype.testShouldBindWidgetOnRepeaterClone = function(){ +RepeaterUpdaterTest.prototype.testShouldBindWidgetOnRepeaterClone = function(){ //fail(); }; -RepeaterUpdater.prototype.testShouldThrowInformativeSyntaxError= function(){ +RepeaterUpdaterTest.prototype.testShouldThrowInformativeSyntaxError= function(){ expectAsserts(1); try { - var repeater = new nglr.RepeaterUpdater(null, "a=b"); + var repeater = new RepeaterUpdater(null, "a=b"); } catch (e) { assertEquals("Expected ng-repeat in form of 'item in collection' but got 'a=b'.", e); } @@ -118,17 +118,17 @@ RepeaterUpdater.prototype.testShouldThrowInformativeSyntaxError= function(){ SelectControllerTest = TestCase("SelectControllerTest"); SelectControllerTest.prototype.testShouldUpdateModelNullOnNothingSelected = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); var view = {selectedIndex:-1, options:[]}; - var cntl = new nglr.SelectController(view, 'abc'); + var cntl = new SelectController(view, 'abc'); cntl.updateModel(scope); assertNull(scope.get('abc')); }; SelectControllerTest.prototype.testShouldUpdateModelWhenNothingSelected = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); var view = {value:'123'}; - var cntl = new nglr.SelectController(view, 'abc'); + var cntl = new SelectController(view, 'abc'); cntl.updateView(scope); assertEquals("123", scope.get('abc')); }; @@ -137,8 +137,8 @@ BindUpdaterTest = TestCase("BindUpdaterTest"); BindUpdaterTest.prototype.testShouldDisplayNothingForUndefined = function () { var view = $(''); - var controller = new nglr.BindUpdater(view[0], "{{a}}"); - var scope = new nglr.Scope(); + var controller = new BindUpdater(view[0], "{{a}}"); + var scope = new Scope(); scope.set('a', undefined); controller.updateView(scope); @@ -151,20 +151,20 @@ BindUpdaterTest.prototype.testShouldDisplayNothingForUndefined = function () { BindUpdaterTest.prototype.testShouldDisplayJsonForNonStrings = function () { var view = $(''); - var controller = new nglr.BindUpdater(view[0], "{{obj}}"); + var controller = new BindUpdater(view[0], "{{obj}}"); - controller.updateView(new nglr.Scope({obj:[]})); + controller.updateView(new Scope({obj:[]})); assertEquals("[]", view.text()); - controller.updateView(new nglr.Scope({obj:{text:'abc'}})); - assertEquals('abc', nglr.fromJson(view.text()).text); + controller.updateView(new Scope({obj:{text:'abc'}})); + assertEquals('abc', fromJson(view.text()).text); }; BindUpdaterTest.prototype.testShouldInsertHtmlNode = function () { var view = $(''); - var controller = new nglr.BindUpdater(view[0], "&{{obj}}"); - var scope = new nglr.Scope(); + var controller = new BindUpdater(view[0], "&{{obj}}"); + var scope = new Scope(); scope.set("obj", $('
      myDiv
      ')[0]); controller.updateView(scope); @@ -174,8 +174,8 @@ BindUpdaterTest.prototype.testShouldInsertHtmlNode = function () { BindUpdaterTest.prototype.testShouldDisplayTextMethod = function () { var view = $('
      '); - var controller = new nglr.BindUpdater(view[0], "{{obj}}"); - var scope = new nglr.Scope(); + var controller = new BindUpdater(view[0], "{{obj}}"); + var scope = new Scope(); scope.set("obj", new angular.filter.Meta({text:function(){return "abc";}})); controller.updateView(scope); @@ -187,13 +187,13 @@ BindUpdaterTest.prototype.testShouldDisplayTextMethod = function () { scope.set("obj", {text:"123"}); controller.updateView(scope); - assertEquals("123", nglr.fromJson(view.text()).text); + assertEquals("123", fromJson(view.text()).text); }; BindUpdaterTest.prototype.testShouldDisplayHtmlMethod = function () { var view = $('
      '); - var controller = new nglr.BindUpdater(view[0], "{{obj}}"); - var scope = new nglr.Scope(); + var controller = new BindUpdater(view[0], "{{obj}}"); + var scope = new Scope(); scope.set("obj", new angular.filter.Meta({html:function(){return "a
      b
      c";}})); controller.updateView(scope); @@ -205,13 +205,13 @@ BindUpdaterTest.prototype.testShouldDisplayHtmlMethod = function () { scope.set("obj", {html:"123"}); controller.updateView(scope); - assertEquals("123", nglr.fromJson(view.text()).html); + assertEquals("123", fromJson(view.text()).html); }; BindUpdaterTest.prototype.testUdateBoolean = function() { var view = $('
      '); - var controller = new nglr.BindUpdater(view[0], "{{true}}, {{false}}"); - controller.updateView(new nglr.Scope()); + var controller = new BindUpdater(view[0], "{{true}}, {{false}}"); + controller.updateView(new Scope()); assertEquals('true, false', view.text()); }; @@ -219,9 +219,9 @@ BindAttrUpdaterTest = TestCase("BindAttrUpdaterTest"); BindAttrUpdaterTest.prototype.testShouldLoadBlankImageWhenBindingIsUndefined = function () { var view = $(''); - var controller = new nglr.BindAttrUpdater(view[0], {src: '{{imageUrl}}'}); + var controller = new BindAttrUpdater(view[0], {src: '{{imageUrl}}'}); - var scope = new nglr.Scope(); + var scope = new Scope(); scope.set('imageUrl', undefined); scope.set('config.server', 'http://server'); @@ -229,16 +229,15 @@ BindAttrUpdaterTest.prototype.testShouldLoadBlankImageWhenBindingIsUndefined = f assertEquals("http://server/images/blank.gif", view.attr('src')); }; -RepeaterUpdaterTest = TestCase("RepeaterUpdaterTest"); RepeaterUpdaterTest.prototype.testShouldNotDieWhenRepeatExpressionIsNull = function() { - var rep = new nglr.RepeaterUpdater(null, "$item in items", null, null); - var scope = new nglr.Scope(); + var rep = new RepeaterUpdater(null, "$item in items", null, null); + var scope = new Scope(); scope.set('items', undefined); rep.updateView(scope); }; RepeaterUpdaterTest.prototype.testShouldIterateOverKeys = function() { - var rep = new nglr.RepeaterUpdater(null, "($k,_v) in items", null, null); + var rep = new RepeaterUpdater(null, "($k,_v) in items", null, null); assertEquals("items", rep.iteratorExp); assertEquals("_v", rep.valueExp); assertEquals("$k", rep.keyExp); @@ -247,14 +246,14 @@ RepeaterUpdaterTest.prototype.testShouldIterateOverKeys = function() { EvalUpdaterTest = TestCase("EvalUpdaterTest"); EvalUpdaterTest.prototype.testEvalThrowsException = function(){ var view = $('
      '); - var eval = new nglr.EvalUpdater(view[0], 'undefined()'); + var eval = new EvalUpdater(view[0], 'undefined()'); - eval.updateView(new nglr.Scope()); + eval.updateView(new Scope()); assertTrue(!!view.attr('ng-error')); assertTrue(view.hasClass('ng-exception')); eval.exp = "1"; - eval.updateView(new nglr.Scope()); + eval.updateView(new Scope()); assertFalse(!!view.attr('ng-error')); assertFalse(view.hasClass('ng-exception')); }; @@ -262,8 +261,8 @@ EvalUpdaterTest.prototype.testEvalThrowsException = function(){ RadioControllerTest = TestCase("RadioController"); RadioControllerTest.prototype.testItShouldTreatTrueStringAsBoolean = function () { var view = $(''); - var radio = new nglr.RadioController(view[0], 'select'); - var scope = new nglr.Scope({select:true}); + var radio = new RadioController(view[0], 'select'); + var scope = new Scope({select:true}); radio.updateView(scope); assertTrue(view[0].checked); }; diff --git a/test/XSitePostTest.js b/test/XSitePostTest.js deleted file mode 100644 index 8a3e4d6f..00000000 --- a/test/XSitePostTest.js +++ /dev/null @@ -1,47 +0,0 @@ -XSitePost = TestCase("XSitePost"); - -var e = function(text){ return Base64.encode(text); }; - -XSitePost.prototype.testMessageReceived = function () { - expectAsserts(4); - var xPost = new nglr.XSitePost(); - xPost.baseUrl = "http://getangular.test"; - xPost.post = function(url, request, callback){ - assertEquals('http://getangular.test/url', url); - assertEquals('abc', request.a); - assertEquals('xyz', request.x); - }; - xPost.incomingFragment('#id;0;1;'+e('/url')+':a:'+e('abc')+':x:'+e('xyz')); - assertEquals('{}', nglr.toJson(xPost.inQueue)); -}; - -XSitePost.prototype.testMessageReceivedInParts = function () { - expectAsserts(5); - var xPost = new nglr.XSitePost(); - xPost.baseUrl = "http://getangular.test"; - xPost.post = function(url, request, callback){ - assertEquals('http://getangular.test/url', url); - assertEquals('abc', request.a); - assertEquals('xyz', request.x); - }; - xPost.incomingFragment('#id;1;2;:x:'+e('xyz')); - assertNotSame('{}', nglr.toJson(xPost.inQueue)); - xPost.incomingFragment('#id;0;2;'+e('/url')+':a:'+e('abc')); - assertEquals('{}', nglr.toJson(xPost.inQueue)); -}; - -XSitePost.prototype.testPostResponsIsEnqueued = function () { - var xPost = new nglr.XSitePost(); - xPost.maxMsgSize = 11; - xPost.response("id", "response", "status"); - - assertEquals('["id:0:2:cmVzcG9uc2U","id:1:2:="]', - nglr.toJson(xPost.outQueue)); -}; - -XSitePost.prototype.testPush = function () { - var window = {}; - var xPost = new nglr.XSitePost(window); - xPost.response("id", "response", "status"); - assertEquals('id:0:1:cmVzcG9uc2U=', xPost.outQueue[0]); -}; diff --git a/test/formsTest.js b/test/formsTest.js index 66c4ec69..ccade915 100644 --- a/test/formsTest.js +++ b/test/formsTest.js @@ -2,7 +2,7 @@ nglrTest = TestCase('nglrTest'); nglrTest.prototype.testShiftBind = function(){ expectAsserts(3); - nglr.shiftBind('this', function(target, arg) { + shiftBind('this', function(target, arg) { assertEquals(this, 'this'); assertEquals(target, 'target'); assertEquals(arg, 'arg'); @@ -11,7 +11,7 @@ nglrTest.prototype.testShiftBind = function(){ nglrTest.prototype.testBind = function(){ expectAsserts(2); - nglr.bind('this', function(arg) { + bind('this', function(arg) { assertEquals(this, 'this'); assertEquals(arg, 'arg'); }).apply('XXX', ['arg']); diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index 13378d36..dde21846 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -6,8 +6,8 @@ HIDDEN = jQuery.browser.msie ? ' style="display: none; "' : ' style="display: none;"'; -nglr.msie = jQuery.browser.msie; -nglr.alert = function(msg) {jstestdriver.console.log("ALERT: " + msg);}; +msie = jQuery.browser.msie; +alert = function(msg) {jstestdriver.console.log("ALERT: " + msg);}; function noop(){} @@ -50,7 +50,7 @@ jQuery.fn.sortedHtml = function() { var toString = function(index, node) { node = node || this; if (node.nodeName == "#text") { - html += nglr.escapeHtml(node.nodeValue); + html += escapeHtml(node.nodeValue); } else { html += '<' + node.nodeName.toLowerCase(); var attributes = node.attributes || []; @@ -89,14 +89,14 @@ jQuery.fn.sortedHtml = function() { }; function encode64(obj){ - return Base64.encode(nglr.toJson(obj)); + return Base64.encode(toJson(obj)); } function decode64(base64){ - return nglr.fromJson(Base64.decode(base64)); + return fromJson(Base64.decode(base64)); } -nglr.Loader.prototype.configureJQueryPlugins(); +Loader.prototype.configureJQueryPlugins(); function assertHidden(node) { var display = node.css('display'); @@ -110,7 +110,7 @@ function assertVisible(node) { } function assertJsonEquals(expected, actual) { - assertEquals(nglr.toJson(expected), nglr.toJson(actual)); + assertEquals(toJson(expected), toJson(actual)); } function assertUndefined(value) { @@ -118,7 +118,7 @@ function assertUndefined(value) { } function assertDefined(value) { - assertTrue(nglr.toJson(value), !!value); + assertTrue(toJson(value), !!value); } function assertThrows(error, fn){ -- cgit v1.2.3