From 7e14dff90516a41ff1903cc44fe3389710f15556 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 17 Feb 2010 16:05:26 -0800 Subject: fix this on filter to point to scope --- angular-minified.js | 28 ++++++++++++++-------------- angular.js | 1 + src/Scope.js | 1 + test/FiltersTest.js | 3 ++- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/angular-minified.js b/angular-minified.js index ac4dd0c4..bc103b44 100644 --- a/angular-minified.js +++ b/angular-minified.js @@ -4,11 +4,11 @@ default:return false}}function ka(a,b){if(ja(a))if(V)a.innerText=b;else a.textCo b.appendChild(a);var c=b.innerHTML;b.removeChild(a);return c}function W(a){var b=(""+a).toLowerCase();if(b=="f"||b=="0"||b=="false"||b=="no")a=false;return!!a}function X(a,b){for(var c in a){var d=b[c],e=typeof d;if(e=="undefined")b[c]=L(v(a[c]));else e=="object"&&d.constructor!=array&&c.substring(0,1)!="$"&&X(a[c],d)}}function ma(a){this.location=a;this.delay=25;this.setTimeout=function(b,c){p.setTimeout(b,c)};this.Ha=function(b){return b};this.N=a.href}function Ma(){var a=k.fn;a.scope=function(){for(var b= this;b&&b.get(0);){var c=b.data("scope");if(c)return c;b=b.parent()}return null};a.controller=function(){return this.data("controller")||R.Kb}}function Na(a){if(a.Gc=="console"&&!Q){Q=x.createElement("div");Q.id="ng-console";x.getElementsByTagName("body")[0].appendChild(Q);K=function(){ia("ng-console-info",arguments)};console.error=function(){ia("ng-console-error",arguments)}}}function ca(a,b){var c={};o(b,function(d,e){c[e]=_(d).bind(a)});return c}function Oa(a,b){var c=new na(b.server,b.database), d=new w(a[0],c,h,b.location,b);d.sa.push(b.Nc);c=new S(a.find("body"),b.server,b.database);var e=b.database=="$MEMORY"?new da(p):new oa(b.server,k.getScript);e=new pa(e,new Y(a.find("body")),function(){d.d()});var f=new qa(e,c),g="/data/"+b.database,h=new Z(function(l,q){e.P("POST",g,l,q)},f,d.anchor);d.l=h;d.sa.push(function(){h.W()});var i=new u({$anchor:d.anchor,$updateView:_(d.d).bind(d),$config:b,$invalidWidgets:[],$console:p.console,$datastore:ca(h,{load:h.load,loadMany:h.ma,loadOrCreate:h.Ka, -loadAll:h.Ja,save:h.save,remove:h.remove,flush:h.W,query:h.Sa,entity:h.G,entities:h.entities,documentCountsByUser:h.zb,userDocumentIdsByEntity:h.sc,join:h.join}),$save:function(l){h.mc(i.k,l,d.anchor)},$window:p,$uid:function(){return""+(new Date).getTime()},$users:f},"ROOT");a.data("scope",i);d.G(i);d.compile();c.bind();(new z(a)).bind();var j=_(ca(i,{set:i.i,get:i.get,eval:i.eval})).extend({init:function(){b.location.listen(_(d.gc).bind(d));d.Pa();d.Eb();d.d();return j},element:a[0],updateView:_(d.d).bind(d), +loadAll:h.Ja,save:h.save,remove:h.remove,flush:h.W,query:h.Sa,entity:h.G,entities:h.entities,documentCountsByUser:h.zb,userDocumentIdsByEntity:h.sc,join:h.join}),$save:function(l){h.mc(i.j,l,d.anchor)},$window:p,$uid:function(){return""+(new Date).getTime()},$users:f},"ROOT");a.data("scope",i);d.G(i);d.compile();c.bind();(new z(a)).bind();var j=_(ca(i,{set:i.i,get:i.get,eval:i.eval})).extend({init:function(){b.location.listen(_(d.gc).bind(d));d.Pa();d.Eb();d.d();return j},element:a[0],updateView:_(d.d).bind(d), config:b});return j}function F(a,b,c){var d=_.last(b);o(c,function(e){d[e]=_[e]});m[a]=m[a]||{};o(b,function(e){B(m[a],e)})}function w(a,b,c,d,e){this.F=a;this.location=d;this.l=c;this.anchor={};this.xc=b;this.tb=e||{};this.sa=[]}function S(a,b,c){this.eb=a;this.fa=b;this.ka=c;this.ib=p;this.H=[]}function Z(a,b,c){this.post=a;this.Xa=b;this.K=[];this.ha={$collections:this.K};this.anchor=c;this.S=[]}function T(a,b){return{format:a,parse:b||a}}function ra(a){return""+a}function v(a,b){var c=[];ea(c, a,b?"\n ":null,_([]));return c.join("")}function L(a){try{var b=new D(a,true),c=b.da();b.L();return c()}catch(d){ba("fromJson error: ",a,d);throw d;}}function ea(a,b,c,d){if(typeof b=="object"){if(d.include(b)){a.push("RECURSION");return}d.push(b)}var e=typeof b;if(b===null)a.push("null");else if(e==="function")return;else if(e==="boolean")a.push(""+b);else if(e==="number")isNaN(b)?a.push("null"):a.push(""+b);else if(e==="string")return a.push(m.String.quoteUnicode(b));else if(e==="object")if(b instanceof Array){a.push("[");var f=b.length;e=false;for(var g=0;g=0&&a.splice(d,1);a.unshift((c?"-":"+")+b);return a},orderByDirection:function(a,b,c,d){c=c||"ng-ascend";d=d||"ng-descend";a=a[0]||"";var e=true;if(a.charAt(0)=="-"){a=a.substring(1);e=false}else if(a.charAt(0)=="+")a=a.substring(1);return a==b?e?c:d:""},merge:function(a, b,c){var d=a[b];if(!d){d={};a[b]=d}X(c,d);return a}},Pa={quote:function(a){return'"'+a.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/\t/g,"\\t").replace(/\v/g,"\\v")+'"'},quoteUnicode:function(a){a=m.String.quote(a);for(var b=[],c=0;c-1;){c1||w.M(a[0])!==null};w.M=function(a){return(a=a.replace(/\n/gm," ").match(/^\{\{(.*)\}\}$/))?a[1]:null};w.prototype={hc:function(a){var b={};a.replace(/(?:^|&)([^&=]*)=?([^&]*)/g, function(c,d,e){if(d)b[decodeURIComponent(d)]=decodeURIComponent(e)});return b},Pa:function(){var a=this,b=this.location.get()||"",c=b.indexOf("#");if(!(c<0)){b=this.hc(b.substring(c+1));o(a.anchor,function(d,e){delete a.anchor[e]});o(b,function(d,e){a.anchor[e]=d})}},gc:function(){this.Pa();this.d()},qc:function(){var a=this.location.get()||"",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]; @@ -66,21 +66,21 @@ d==";"){a.push({index:this.index,text:d});this.index++;c=true}else if(c&&d=="/") this.text.charAt(this.index);if(c=="."||this.Y(c)||this.isNumber(c))a+=c;else break;this.index++}c=E.ua[a];if(!c){c=function(d){return d.scope.get(a)};c.X=a}this.h.push({index:b,text:a,b:c})},kc:function(a){var b=this.index,c=this.xb;this.index++;for(var d="",e=false;this.index0){e=e[0];var f=e.text;if(f==a||f==b||f==c||f==d||!a&&!b&&!c&&!d)return e}return false},a:function(a,b,c,d){if(a=this.I(a,b,c,d)){this.h.shift();return this.Ec=a}return false},j:function(a){if(!this.a(a)){var b=this.I();throw"Expecting '"+a+"' at column '"+(b.index+1)+"' in '"+this.text+"' got '"+this.text.substring(b.index)+"'.";}},fb:function(a,b){return function(c){return a(c,b(c))}},z:function(a,b,c){return function(d){return b(d, +this.text;return this.h[0]},I:function(a,b,c,d){var e=this.h;if(e.length>0){e=e[0];var f=e.text;if(f==a||f==b||f==c||f==d||!a&&!b&&!c&&!d)return e}return false},a:function(a,b,c,d){if(a=this.I(a,b,c,d)){this.h.shift();return this.Ec=a}return false},k:function(a){if(!this.a(a)){var b=this.I();throw"Expecting '"+a+"' at column '"+(b.index+1)+"' in '"+this.text+"' got '"+this.text.substring(b.index)+"'.";}},fb:function(a,b){return function(c){return a(c,b(c))}},z:function(a,b,c){return function(d){return b(d, a(d),c(d))}},Ea:function(){return this.h.length>0},L:function(){if(this.h.length!==0)throw"Did not understand '"+this.text.substring(this.h[0].index)+"' while evaluating '"+this.text+"'.";},ra:function(){for(var a=[];;){this.h.length>0&&!this.I("}",")",";","]")&&a.push(this.Ca());if(!this.a(";"))return function(b){for(var c,d=0;d","<=", ">="))a=this.z(a,b.b,this.Ua());return a},mb:function(){for(var a=this.Na(),b;b=this.a("+","-");)a=this.z(a,b.b,this.Na());return a},Na:function(){for(var a=this.ga(),b;b=this.a("*","/","%");)a=this.z(a,b.b,this.ga());return a},ga:function(){var a;return this.a("+")?this.da():(a=this.a("-"))?this.z(D.db,a.b,this.ga()):(a=this.a("!"))?this.fb(a.b,this.ga()):this.da()},Ib:function(a){var b=this.a(),c=b.text.split(".");a=a;for(var d,e=0;e1;d++){var e=a.shift(),f=c[e];if(!f){f={};c[e]=f}c=f}return c[a.shift()]=b},q:function(a,b){this.eval(a+"="+v(b))},eval:function(a,b){var c= -u.V[a];if(!c){var d=new D(a);c=d.ra();d.L();u.V[a]=c}b=b||{};b.scope=this;return c(b)},o:function(a,b,c,d,e){try{var f=this.eval(b,c);if(a.C){a.C=false;k(a.view).removeClass("ng-exception").removeAttr("ng-error")}d&&d.apply(a,[f]);return true}catch(g){ba("Eval Widget Error:",g);b=v(g,true);a.C=true;k(a.view).addClass("ng-exception").attr("ng-error",b);e&&e.apply(a,[g,b]);return false}},uc:function(a,b,c){var d=u.V[a];if(!d){d=(new D(a)).Q();u.V[a]=d}a={scope:this,self:this.k,$element:c};return d(a)(a, -b)},G:function(a,b){return(new D(a)).Db()({scope:this,l:b})},sb:function(){for(var a=this.k.$invalidWidgets;a.length>0;)a.pop()},Sb:function(a){this.k.$invalidWidgets.push(a)},watch:function(a){var b=this;(new D(a)).watch()({scope:this,jb:function(c,d){b.kb(c,function(e,f){try{return d({scope:b},e,f)}catch(g){alert(g)}})}})},kb:function(a,b){var c=this.ta[a];if(!c){c={Ia:[],s:a};this.ta[a]=c}c.Ia.push(b)},Gb:function(){var a=this,b=false;o(this.ta,function(c){var d=a.eval(c.s);if(d!==c.c){o(c.Ia, -function(e){e(d,c.c);b=true});c.c=d}});return b}};oa.prototype={pb:function(a){return fa.Ab(a)},P:function(a,b,c,d){var e=this.tc+this.Tb++;a=this.pb(v({u:b,m:a,p:c}));b=Math.ceil(a.length/this.oa);c=this.url+"/$/"+e+"/"+b+"/";N[e]=function(h){delete N[e];d(200,h)};for(var f=0;f1;d++){var e=a.shift(),f=c[e];if(!f){f={};c[e]=f}c=f}return c[a.shift()]=b},q:function(a,b){this.eval(a+"="+v(b))},eval:function(a,b){var c= +u.V[a];if(!c){var d=new D(a);c=d.ra();d.L();u.V[a]=c}b=b||{};b.scope=this;b.self=this.j;return c(b)},o:function(a,b,c,d,e){try{var f=this.eval(b,c);if(a.C){a.C=false;k(a.view).removeClass("ng-exception").removeAttr("ng-error")}d&&d.apply(a,[f]);return true}catch(g){ba("Eval Widget Error:",g);b=v(g,true);a.C=true;k(a.view).addClass("ng-exception").attr("ng-error",b);e&&e.apply(a,[g,b]);return false}},uc:function(a,b,c){var d=u.V[a];if(!d){d=(new D(a)).Q();u.V[a]=d}a={scope:this,self:this.j,$element:c}; +return d(a)(a,b)},G:function(a,b){return(new D(a)).Db()({scope:this,l:b})},sb:function(){for(var a=this.j.$invalidWidgets;a.length>0;)a.pop()},Sb:function(a){this.j.$invalidWidgets.push(a)},watch:function(a){var b=this;(new D(a)).watch()({scope:this,jb:function(c,d){b.kb(c,function(e,f){try{return d({scope:b},e,f)}catch(g){alert(g)}})}})},kb:function(a,b){var c=this.ta[a];if(!c){c={Ia:[],s:a};this.ta[a]=c}c.Ia.push(b)},Gb:function(){var a=this,b=false;o(this.ta,function(c){var d=a.eval(c.s);if(d!== +c.c){o(c.Ia,function(e){e(d,c.c);b=true});c.c=d}});return b}};oa.prototype={pb:function(a){return fa.Ab(a)},P:function(a,b,c,d){var e=this.tc+this.Tb++;a=this.pb(v({u:b,m:a,p:c}));b=Math.ceil(a.length/this.oa);c=this.url+"/$/"+e+"/"+b+"/";N[e]=function(h){delete N[e];d(200,h)};for(var f=0;fc)return"Value can not be greater than "+c+".";return null}else return"Value is not a number."},integer:function(a,b,c){if(b=ga.number(a,b,c))return b;if(!(""+a).match(/^\s*[\d+]*\s*$/)||a!=Math.round(a))return"Value is not a whole number.";return null},date:function(a){if(a.match(/^\d\d?\/\d\d?\/\d\d\d\d$/))return null;return"Value is not a date. (Expecting format: 12/31/2009)."}, ssn:function(a){if(a.match(/^\d\d\d-\d\d-\d\d\d\d$/))return null;return"SSN needs to be in 999-99-9999 format."},email:function(a){if(a.match(/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/))return null;return"Email needs to be in username@host.com format."},phone:function(a){if(a.match(/^1\(\d\d\d\)\d\d\d-\d\d\d\d$/))return null;if(a.match(/^\+\d{2,3} (\(\d{1,5}\))?[\d ]+\d$/))return null;return"Phone number needs to be in 1(987)654-3210 format in North America or +999 (123) 45678 906 internationaly."}, @@ -98,7 +98,7 @@ c}}};M.Va=function(a){switch(typeof a){case "string":case "boolean":case "number case "function":return C(a.text());default:break}}if(a===null)return"";return C(v(a,true));default:return""}};M.prototype={e:n,d:function(a){for(var b=[],c=this.exp,d=c.length,e=0;ed;--b)this.children.pop().element.remove();if(h&&h.element[0].nodeName==="OPTION")if(d=k(h.element[0].parentNode).data("controller")){d.c=undefined;d.d(a)}})}};z.va="mouseleave mouseout click dblclick keypress keyup";z.fc=function(){z.pa();var a=k(this);a.bind(z.va,z.pa);var b=a.position(),c=x.documentElement,d=(self.innerWidth||c&&c.clientWidth|| x.body.clientWidth)-b.left;c=a.hasClass("ng-exception")?"EXCEPTION:":"Validation error...";a=a.attr("ng-error");d=d>375?"left":"right";c=k("
"+c+"
"+a+"
");k("body").append(c);if(d==="left")a=b.left+this.offsetWidth+11;else{a=b.left-315;c.find(".ng-arrow-right").css({left:301})}c.css({left:a+"px",top:b.top-3+"px"});return true};z.pa=function(){k("#ng-callout").unbind(z.va, z.pa).remove();return true};z.prototype={bind:function(){this.F.find(".ng-validation-error,.ng-exception").live("mouseover",z.fc)}};Y.$a='
loading....
';Y.prototype={qb:function(){if(this.ea===0)(this.La=this.La||this.body.append(Y.$a).find("#ng-loading")).show();this.ea++},Bb:function(){this.ea--;this.ea===0&&this.La.hide("fold")}}})(window,document); diff --git a/angular.js b/angular.js index 2684315a..d195e173 100644 --- a/angular.js +++ b/angular.js @@ -2961,6 +2961,7 @@ Scope.prototype = { } context = context || {}; context.scope = this; + context.self = this.state; return expression(context); }, diff --git a/src/Scope.js b/src/Scope.js index c0998168..4de57dd2 100644 --- a/src/Scope.js +++ b/src/Scope.js @@ -105,6 +105,7 @@ Scope.prototype = { } context = context || {}; context.scope = this; + context.self = this.state; return expression(context); }, diff --git a/test/FiltersTest.js b/test/FiltersTest.js index e6e8b662..9552c820 100644 --- a/test/FiltersTest.js +++ b/test/FiltersTest.js @@ -17,7 +17,8 @@ FiltersTest.prototype.testFilterThisIsContext = function(){ expectAsserts(2); var scope = new Scope(); Scope.expressionCache = {}; - var context = {$element:123, self:{name:'misko'}}; + scope.set('name', 'misko'); + var context = {$element:123}; angular.filter.testFn = function () { assertEquals('Context not equal', 123, this.$element); assertEquals('scope not equal', 'misko', this.name); -- cgit v1.2.3