From 3ea2416f8083a21bf2f47f3381a66bf97e7f59e2 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Tue, 19 Jul 2011 16:07:25 -0700 Subject: Revert "fix(ng:class): preserve classes added post compilation" This reverts commit 2428907259fa80ec3b1b4bfd85ea20028a9f4fa5. We decided to revert this because it is not bullet proof. The issue is that we can't reliably have both angular and non-angular code in charge of the DOM. We could work around some issues here and there, but we can't do it reliably, so it's better not to support DOM manipulation that happens outside of angular. There is a good chance that once we integrate with MDVs our possition will change, but until then our position is that only angular or angular widgets/directives can change change DOM that was compiled. --- src/directives.js | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/directives.js b/src/directives.js index 6fc19eaf..d800aa80 100644 --- a/src/directives.js +++ b/src/directives.js @@ -565,25 +565,18 @@ angularDirective("ng:submit", function(expression, element) { }); }); + function ngClass(selector) { return function(expression, element){ + var existing = element[0].className + ' '; return function(element){ - if(selector(this.$index)) { - this.$watch(expression, function(newCls, oldCls) { - var cls = element.attr('class'); - if (isArray(newCls)) newCls = newCls.join(' '); - if (isArray(oldCls)) oldCls = oldCls.join(' '); - - // The time when newCls == oldCLs is when $watch just started - if (newCls == oldCls) { - cls += ' ' + newCls; - } else { - cls = cls.replace(' ' + oldCls, ' ' + newCls); - } - - element.attr('class', cls); - }); - } + this.$onEval(function(){ + if (selector(this.$index)) { + var value = this.$eval(expression); + if (isArray(value)) value = value.join(' '); + element[0].className = trim(existing + value); + } + }, element); }; }; } -- cgit v1.2.3