From eb9e66f4804cf417ce142e5515b039db73d31144 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Sat, 9 Jan 2010 13:21:24 -0800 Subject: cleanup --- Rakefile | 2 +- TODO.text | 6 ++ angular.js | 164 ++++++++++++++++++++++++++++++++++++ example/calculator-manual_init.html | 2 +- src/Loader.js | 1 + 5 files changed, 173 insertions(+), 2 deletions(-) create mode 100644 TODO.text create mode 100644 angular.js diff --git a/Rakefile b/Rakefile index 9fb7f173..56482e39 100644 --- a/Rakefile +++ b/Rakefile @@ -28,8 +28,8 @@ end desc 'Compile JavaScript with Google Closure Compiler' task :compileclosure do +# --compilation_level ADVANCED_OPTIMIZATIONS \ %x(java -jar lib/compiler-closure/compiler.jar \ - --compilation_level ADVANCED_OPTIMIZATIONS \ --js lib/webtoolkit/webtoolkit.base64.js \ --js lib/underscore/underscore.js \ --js src/Loader.js \ diff --git a/TODO.text b/TODO.text new file mode 100644 index 00000000..fab19695 --- /dev/null +++ b/TODO.text @@ -0,0 +1,6 @@ +* move angular-bootstrap.js out of anugular.js. +* 'angular' is the official namespace for public API + - angular.defaults = {} + - var scope = angular.compile(element, options); +* angular.js is not self boot straping by default. +* diff --git a/angular.js b/angular.js new file mode 100644 index 00000000..2ac33572 --- /dev/null +++ b/angular.js @@ -0,0 +1,164 @@ +var a,Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",encode:function(b){var c="",d,f,e,h,j,l,n=0;for(b=Base64._utf8_encode(b);n>2;d=(d&3)<<4|f>>4;j=(f&15)<<2|e>>6;l=e&63;if(isNaN(f))j=l=64;else if(isNaN(e))l=64;c=c+this._keyStr.charAt(h)+this._keyStr.charAt(d)+this._keyStr.charAt(j)+this._keyStr.charAt(l)}return c},decode:function(b){var c="",d,f,e,h,j,l=0;for(b=b.replace(/[^A-Za-z0-9\+\/\=]/g, +"");l>4;f=(f&15)<<4|h>>2;e=(h&3)<<6|j;c+=String.fromCharCode(d);if(h!=64)c+=String.fromCharCode(f);if(j!=64)c+=String.fromCharCode(e)}return c=Base64._utf8_decode(c)},_utf8_encode:function(b){b=b.replace(/\r\n/g,"\n");for(var c="",d=0;d127&&f<2048)c+= +String.fromCharCode(f>>6|192);else{c+=String.fromCharCode(f>>12|224);c+=String.fromCharCode(f>>6&63|128)}c+=String.fromCharCode(f&63|128)}}return c},_utf8_decode:function(b){for(var c="",d=0,f=c1=c2=0;d191&&f<224){c2=b.charCodeAt(d+1);c+=String.fromCharCode((f&31)<<6|c2&63);d+=2}else{c2=b.charCodeAt(d+1);c3=b.charCodeAt(d+2);c+=String.fromCharCode((f&15)<<12|(c2&63)<<6|c3&63);d+=3}}return c}};(function(){var b=this,c=b._,d=function(g){this._wrapped=g},f=typeof StopIteration!=="undefined"?StopIteration:"__break__",e=b._=function(g){return new d(g)};if(typeof exports!=="undefined")exports._=e;var h=Array.prototype.slice,j=Array.prototype.unshift,l=Object.prototype.toString,n=Object.prototype.hasOwnProperty,o=Object.prototype.propertyIsEnumerable;e.VERSION="0.5.1";e.each=function(g,i,k){try{if(g.forEach)g.forEach(i,k);else if(e.isArray(g)||e.isArguments(g))for(var m=0,q=g.length;m=m.computed&&(m={value:q,computed:r})});return m.value};e.min=function(g,i,k){if(!i&&e.isArray(g))return Math.min.apply(Math,g);var m={computed:Infinity};e.each(g,function(q,r,t){r=i?i.call(k,q,r,t):q;rq?1:0}),"value")};e.sortedIndex=function(g,i,k){k=k||e.identity;for(var m=0,q=g.length;m>1;k(g[r])=0})})};e.zip=function(){for(var g=e.toArray(arguments),i=e.max(e.pluck(g,"length")),k=new Array(i),m=0;m0?q-i:i-q)>=0)return m;m[r++]=q}};e.bind=function(g,i){var k=e.rest(arguments,2);return function(){return g.apply(i||b,k.concat(e.toArray(arguments)))}};e.bindAll=function(g){var i=e.rest(arguments);if(i.length==0)i=e.functions(g);e.each(i,function(k){g[k]=e.bind(g[k], +g)});return g};e.delay=function(g,i){var k=e.rest(arguments,2);return setTimeout(function(){return g.apply(g,k)},i)};e.defer=function(g){return e.delay.apply(e,[g,1].concat(e.rest(arguments)))};e.wrap=function(g,i){return function(){var k=[g].concat(e.toArray(arguments));return i.apply(i,k)}};e.compose=function(){var g=e.toArray(arguments);return function(){for(var i=e.toArray(arguments),k=g.length-1;k>=0;k--)i=[g[k].apply(this,i)];return i[0]}};e.keys=function(g){if(e.isArray(g))return e.range(0, +g.length);var i=[];for(var k in g)n.call(g,k)&&i.push(k);return i};e.values=function(g){return e.map(g,e.identity)};e.functions=function(g){return e.select(e.keys(g),function(i){return e.isFunction(g[i])}).sort()};e.extend=function(g,i){for(var k in i)g[k]=i[k];return g};e.clone=function(g){if(e.isArray(g))return g.slice(0);return e.extend({},g)};e.isEqual=function(g,i){if(g===i)return true;var k=typeof g;if(k!=typeof i)return false;if(g==i)return true;if(!g&&i||g&&!i)return false;if(g.isEqual)return g.isEqual(i); +if(e.isDate(g)&&e.isDate(i))return g.getTime()===i.getTime();if(e.isNaN(g)&&e.isNaN(i))return true;if(e.isRegExp(g)&&e.isRegExp(i))return g.source===i.source&&g.global===i.global&&g.ignoreCase===i.ignoreCase&&g.multiline===i.multiline;if(k!=="object")return false;if(g.length&&g.length!==i.length)return false;k=e.keys(g);var m=e.keys(i);if(k.length!=m.length)return false;for(var q in g)if(!e.isEqual(g[q],i[q]))return false;return true};e.isEmpty=function(g){return e.keys(g).length==0};e.isElement= +function(g){return!!(g&&g.nodeType==1)};e.isArguments=function(g){return g&&e.isNumber(g.length)&&!e.isArray(g)&&!o.call(g,"length")};e.isNaN=function(g){return e.isNumber(g)&&isNaN(g)};e.isNull=function(g){return g===null};e.isUndefined=function(g){return typeof g=="undefined"};for(var p=["Array","Date","Function","Number","RegExp","String"],s=0,v=p.length;s)[^\t]*)'/g,"$1\r").replace(/\t=(.*?)%>/g,"',$1,'").split("\t").join("');").split("%>").join("p.push('").split("\r").join("\\'")+"');}return p.join('');");return i?g(i):g};e.forEach=e.each;e.foldl=e.inject= +e.reduce;e.foldr=e.reduceRight;e.filter=e.select;e.every=e.all;e.some=e.any;e.head=e.first;e.tail=e.rest;e.methods=e.functions;var w=function(g,i){return i?e(g).chain():g};e.each(e.functions(e),function(g){var i=e[g];d.prototype[g]=function(){j.call(arguments,this._wrapped);return w(i.apply(e,arguments),this._chain)}});e.each(["pop","push","reverse","shift","sort","splice","unshift"],function(g){var i=Array.prototype[g];d.prototype[g]=function(){i.apply(this._wrapped,arguments);return w(this._wrapped, +this._chain)}});e.each(["concat","join","slice"],function(g){var i=Array.prototype[g];d.prototype[g]=function(){return w(i.apply(this._wrapped,arguments),this._chain)}});d.prototype.chain=function(){this._chain=true;return this};d.prototype.value=function(){return this._wrapped}})();if(typeof document.getAttribute=="undefined")document.getAttribute=function(){};if(typeof Node=="undefined")Node={ELEMENT_NODE:1,ATTRIBUTE_NODE:2,TEXT_NODE:3,CDATA_SECTION_NODE:4,ENTITY_REFERENCE_NODE:5,ENTITY_NODE:6,PROCESSING_INSTRUCTION_NODE:7,COMMENT_NODE:8,DOCUMENT_NODE:9,DOCUMENT_TYPE_NODE:10,DOCUMENT_FRAGMENT_NODE:11,NOTATION_NODE:12};if(_.isUndefined(window.nglr))nglr={};if(_.isUndefined(window.angular))angular={};if(_.isUndefined(angular.validator))angular.validator={}; +if(_.isUndefined(angular.filter))angular.filter={};if(_.isUndefined(window.console))window.console={log:function(){},error:function(){}};if(_.isUndefined(nglr.alert))nglr.alert=function(){console.log(arguments);window.alert.apply(window,arguments)};nglr.consoleLog=function(b,c){var d=document.createElement("div");d.className=b;for(var f=b="",e=0;e/g,">")}; +nglr.escapeAttr=function(b){if(!b||!b.replace)return b;return b.replace(//g,">").replace(/\"/g,""")};nglr.bind=function(b,c){if(!b)throw"Missing this";if(!_.isFunction(c))throw"Missing function";return function(){return c.apply(b,arguments)}};nglr.shiftBind=function(b,c){return function(){for(var d=[this],f=0;f=0&&b.splice(d,1);return c},find:function(b,c,d){if(c){var f=angular.Function.compile(c);_.detect(b,function(e){if(f(e)){d=e;return true}});return d}},findById:function(b,c){return angular.Array.find(b,function(d){return d.$id== +c},null)},filter:function(b,c){var d=[];d.check=function(o){for(var p=0;p-1;case "object":for(var s in o)if(s.charAt(0)!=="$"&&e(o[s],p))return true;return false;case "array":for(s=0;s=0&&b.splice(f,1);b.unshift((d?"-":"+")+c);return b},orderByDirection:function(b,c,d,f){d=d||"ng-ascend";f=f||"ng-descend";b=b[0]||"";var e=true;if(b.charAt(0)== +"-"){b=b.substring(1);e=false}else if(b.charAt(0)=="+")b=b.substring(1);return b==c?e?d:f:""},merge:function(b,c,d){var f=b[c];if(!f){f={};b[c]=f}nglr.merge(d,f);return b}}; +angular.String={quote:function(b){return'"'+b.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/\t/g,"\\t").replace(/\v/g,"\\v")+'"'},quoteUnicode:function(b){b=angular.String.quote(b);for(var c=[],d=0;d-1;){d1||nglr.Binder.binding(b[0])!==null};nglr.Binder.binding=function(b){return(b=b.replace(/\n/gm," ").match(/^\{\{(.*)\}\}$/))?b[1]:null};a=nglr.Binder.prototype;a.parseQueryString=function(b){var c={};b.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(d,f,e){if(f)c[decodeURIComponent(f)]=decodeURIComponent(e)});return c}; +a.parseAnchor=function(b){var c=this;b=b||this.urlWatcher.getUrl();var d=b.indexOf("#");if(!(d<0)){b=this.parseQueryString(b.substring(d+1));jQuery.each(c.anchor,function(f){delete c.anchor[f]});jQuery.each(b,function(f,e){c.anchor[f]=e})}};a.onUrlChange=function(b){console.log("URL change detected",b);this.parseAnchor(b);this.updateView()}; +a.updateAnchor=function(){var b=this.urlWatcher.getUrl(),c=b.indexOf("#");if(c>-1)b=b.substring(0,c);b+="#";c="";for(var d in this.anchor){var f=this.anchor[d];if(typeof f==="undefined"||f===null)delete this.anchor[d];else{b+=c+encodeURIComponent(d);if(f!==true)b+="="+encodeURIComponent(f);c="&"}}this.urlWatcher.setUrl(b);return b}; +a.updateView=function(){(new Date).getTime();var b=jQuery(this.doc).scope();b.set("$invalidWidgets",[]);b.updateView();(new Date).getTime();this.updateAnchor();_.each(this.updateListeners,function(c){c()})};a.docFindWithSelf=function(b){var c=jQuery(this.doc),d=c.find(b);if(c.is(b))d=d.andSelf();return d}; +a.executeInit=function(){this.docFindWithSelf("[ng-init]").each(function(){var b=jQuery(this),c=b.scope();try{c.eval(b.attr("ng-init"))}catch(d){nglr.alert("EVAL ERROR:\n"+b.attr("ng-init")+"\n"+nglr.toJson(d,true))}})};a.entity=function(b){this.docFindWithSelf("[ng-entity]").attr("ng-watch",function(){try{var c=jQuery(this);return b.entity(c.attr("ng-entity"))+(c.attr("ng-watch")||"")}catch(d){nglr.alert(d)}})}; +a.compile=function(){var b=jQuery(this.doc),c=this;if(this.config.autoSubmit){var d=this.docFindWithSelf(":submit").not("[ng-action]");d.attr("ng-action","$save()");d.not(":disabled").not("ng-bind-attr").attr("ng-bind-attr",'{disabled:"{{$invalidWidgets}}"}')}this.precompile(this.doc)(this.doc,b.scope(),"");this.docFindWithSelf("a[ng-action]").live("click",function(){var f=jQuery(this);try{f.scope().eval(f.attr("ng-action"));f.removeAttr("ng-error");f.removeClass("ng-exception")}catch(e){f.addClass("ng-exception"); +f.attr("ng-error",nglr.toJson(e,true))}c.updateView();return false})}; +a.translateBinding=function(b,c,d){c=c.concat();var f=c.pop(),e=nglr.Binder.parseBindings(b.nodeValue);if(e.length>1||nglr.Binder.binding(e[0])){var h=b.parentNode;if(nglr.isLeafNode(h)){h.setAttribute("ng-bind-template",b.nodeValue);d.push({path:c,fn:function(p){return new nglr.BindUpdater(p,p.getAttribute("ng-bind-template"))}})}else for(var j=0;j2&&b.setAttribute("ng-bind-attr",f)}b.getAttribute||console.log(b);var o=b.getAttribute("ng-repeat");if(o){b.removeAttribute("ng-repeat");var p=this.precompile(b);f=document.createComment("ng-repeat: "+o);e=b.parentNode;e.insertBefore(f,b);e.removeChild(b);var s=function(u,w,g){var i=jQuery(b).clone();i.css("display","");i.attr("ng-repeat-index",""+g);i.data("scope",u);p(i[0],u,w+g+":");return i};d.push({path:c,fn:function(u,w,g){return new nglr.RepeaterUpdater(jQuery(u),o,s,g)}})}else{b.getAttribute("ng-eval")&& +d.push({path:c,fn:this.ng_eval});b.getAttribute("ng-bind")&&d.push({path:c,fn:this.ng_bind});b.getAttribute("ng-bind-attr")&&d.push({path:c,fn:this.ng_bind_attr});b.getAttribute("ng-hide")&&d.push({path:c,fn:this.ng_hide});b.getAttribute("ng-show")&&d.push({path:c,fn:this.ng_show});b.getAttribute("ng-class")&&d.push({path:c,fn:this.ng_class});b.getAttribute("ng-class-odd")&&d.push({path:c,fn:this.ng_class_odd});b.getAttribute("ng-class-even")&&d.push({path:c,fn:this.ng_class_even});b.getAttribute("ng-style")&& +d.push({path:c,fn:this.ng_style});b.getAttribute("ng-watch")&&d.push({path:c,fn:this.ng_watch});f=b.nodeName;if(f=="INPUT"||f=="TEXTAREA"||f=="SELECT"||f=="BUTTON"){var v=this;d.push({path:c,fn:function(u,w,g){u.name=g+u.name.split(":").pop();return v.widgetFactory.createController(jQuery(u),w)}})}if(f=="OPTION")if(!jQuery("')};a=nglr.FileController.prototype;a._on_cancel=function(){};a._on_complete=function(){};a._on_httpStatus=function(b){nglr.alert("httpStatus:"+this.scopeName+" status:"+b)};a._on_ioError=function(){nglr.alert("ioError:"+this.scopeName)};a._on_open=function(){nglr.alert("open:"+this.scopeName)};a._on_progress=function(){}; +a._on_securityError=function(){nglr.alert("securityError:"+this.scopeName)};a._on_uploadCompleteData=function(b){b=nglr.fromJson(b);b.url=this.attachmentsPath+"/"+b.id+"/"+b.text;this.view.find("input").attr("checked",true);var c=this.view.scope();this.value=b;this.updateModel(c);this.value=null;c.get("$binder").updateView()};a._on_select=function(b,c){this.name=b;this.view.find("a").text(b).attr("href",b);this.view.find("span").text(angular.filter.bytes(c));this.upload()}; +a.updateModel=function(b){var c=this.view.find("input").attr("checked")?this.value:null;if(this.lastValue===c)return false;else{b.set(this.scopeName,c);return true}};a.updateView=function(b){if((b=b.get(this.scopeName))&&this.value!==b){this.value=b;this.view.find("a").attr("href",this.value.url).text(this.value.text);this.view.find("span").text(angular.filter.bytes(this.value.size))}this.view.find("input").attr("checked",!!b)};a.upload=function(){this.name&&this.uploader.uploadFile(this.attachmentsPath)}; +nglr.NullController=function(b){this.view=b};nglr.NullController.prototype.updateModel=function(){return true};nglr.NullController.prototype.updateView=function(){};nglr.NullController.instance=new nglr.NullController;nglr.ButtonController=function(b){this.view=b};nglr.ButtonController.prototype.updateModel=function(){return true};nglr.ButtonController.prototype.updateView=function(){}; +nglr.TextController=function(b,c){this.view=b;this.exp=c;this.validator=b.getAttribute("ng-validate");this.required=typeof b.attributes["ng-required"]!="undefined";this.lastErrorText=null;this.lastValue=undefined;this.initialValue=b.value;b.getAttribute("ng-widget")==="datepicker"&&jQuery(b).datepicker()};nglr.TextController.prototype.updateModel=function(b){var c=this.view.value;if(this.lastValue===c)return false;else{b.setEval(this.exp,c);this.lastValue=c;return true}}; +nglr.TextController.prototype.updateView=function(b){var c=this.view,d=b.get(this.exp);if(typeof d==="undefined"){d=this.initialValue;b.setEval(this.exp,d)}d=d?d:"";if(this.lastValue!=d)this.lastValue=c.value=d;var f=false;c.removeAttribute("ng-error");if(this.required)f=!(d&&d.length>0);var e=f?"Required Value":null;if(!f&&this.validator&&d){e=b.validate(this.validator,d);f=!!e}if(this.lastErrorText!==e){this.lastErrorText=f;if(e!==null){c.setAttribute("ng-error",e);b.markInvalid(this)}jQuery(c).toggleClass("ng-validation-error", +f)}};nglr.CheckboxController=function(b,c){this.view=b;this.exp=c;this.lastValue=undefined;this.initialValue=b.checked?b.value:""};nglr.CheckboxController.prototype.updateModel=function(b){var c=this.view;c=c.checked?c.value:"";if(this.lastValue===c)return false;else{b.setEval(this.exp,c);this.lastValue=c;return true}}; +nglr.CheckboxController.prototype.updateView=function(b){var c=this.view,d=b.eval(this.exp);if(typeof d==="undefined"){d=this.initialValue;b.setEval(this.exp,d)}c.checked=c.value==""+d};nglr.SelectController=function(b,c){this.view=b;this.exp=c;this.lastValue=undefined;this.initialValue=b.value}; +nglr.SelectController.prototype.updateModel=function(b){if(this.view.selectedIndex<0)b.setEval(this.exp,null);else{var c=this.view.value;if(this.lastValue===c)return false;else{b.setEval(this.exp,c);this.lastValue=c;return true}}};nglr.SelectController.prototype.updateView=function(b){var c=this.view,d=b.get(this.exp);if(typeof d==="undefined"){d=this.initialValue;b.setEval(this.exp,d)}if(d!==this.lastValue){c.value=d?d:"";this.lastValue=d}}; +nglr.MultiSelectController=function(b,c){this.view=b;this.exp=c;this.lastValue=undefined;this.initialValue=this.selected()};nglr.MultiSelectController.prototype.selected=function(){for(var b=[],c=this.view.options,d=0;df;--c)this.children.pop().element.removeNode();if(l&&l.element[0].nodeName==="OPTION")if(f=jQuery(l.element[0].parentNode).data("controller")){f.lastValue=undefined;f.updateView(b)}})};nglr.PopUp=function(b){this.doc=b};nglr.PopUp.OUT_EVENT="mouseleave mouseout click dblclick keypress keyup"; +nglr.PopUp.prototype.bind=function(){this.doc.find(".ng-validation-error,.ng-exception").live("mouseover",nglr.PopUp.onOver)}; +nglr.PopUp.onOver=function(){nglr.PopUp.onOut();var b=jQuery(this);b.bind(nglr.PopUp.OUT_EVENT,nglr.PopUp.onOut);var c=b.position(),d=document.documentElement,f=(self.innerWidth||d&&d.clientWidth||document.body.clientWidth)-c.left;d=b.hasClass("ng-exception")?"EXCEPTION:":"Validation error...";b=b.attr("ng-error");f=f>375?"left":"right";d=jQuery("
"+d+"
"+b+"
");jQuery("body").append(d); +if(f==="left")b=c.left+this.offsetWidth+11;else{b=c.left-315;d.find(".ng-arrow-right").css({left:301})}d.css({left:b+"px",top:c.top-3+"px"});return true};nglr.PopUp.onOut=function(){jQuery("#ng-callout").unbind(nglr.PopUp.OUT_EVENT,nglr.PopUp.onOut).remove();return true};nglr.Status=function(b){this.loader=b.append(nglr.Status.DOM).find("#ng-loading");this.requestCount=0};nglr.Status.DOM='
loading....
'; +nglr.Status.prototype.beginRequest=function(){this.requestCount===0&&this.loader.show();this.requestCount++};nglr.Status.prototype.endRequest=function(){this.requestCount--;this.requestCount===0&&this.loader.hide("fold")};(function(b){for(var c=/(.*)\/angular-(.*).js(#(.*))?/,d=document.getElementsByTagName("script"),f={autoSubmit:true,autoBind:true,autoLoadDependencies:false},e=0;e<\/script>')};if(f.autoLoadDependencies){c("/../lib/webtoolkit/webtoolkit.base64.js");c("/../lib/swfobject/swfobject.js");c("/../lib/jquery/jquery-1.3.2.js");c("/../lib/jquery/jquery-ui-1.7.1.custom.min.js");c("/../lib/underscore/underscore.js");c("/Loader.js");c("/API.js");c("/Binder.js");c("/ControlBar.js");c("/DataStore.js");c("/Filters.js");c("/JSON.js");c("/Model.js");c("/Parser.js"); +c("/Scope.js");c("/Server.js");c("/Users.js");c("/Validators.js");c("/Widgets.js")}else{c("/ajax/libs/swfobject/2.2/swfobject.js","http://ajax.googleapis.com");c("/ajax/libs/jquery/1.3.2/jquery.min.js","http://ajax.googleapis.com");c("/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js","http://ajax.googleapis.com")}window.onload=function(){var o=window.document;if(f.bindRootId){o=null;for(var p=f.bindRootId.split("|"),s=0;s1)if(!window.document.getElementById(v[1]))continue; +o=window.document.getElementById(u)}}p=window.angularFactory(f);if(f.autoBind&&o)window.angularScope=p.compile(o);if(typeof b==="function")try{b.apply(this,arguments)}catch(w){}}})(window.onload); diff --git a/example/calculator-manual_init.html b/example/calculator-manual_init.html index 0d5c1bb6..6013345e 100644 --- a/example/calculator-manual_init.html +++ b/example/calculator-manual_init.html @@ -1,7 +1,7 @@ - +