aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/.jshintrc3
-rw-r--r--src/Angular.js24
-rw-r--r--src/ng/compile.js20
-rw-r--r--src/ng/directive/ngClass.js23
4 files changed, 44 insertions, 26 deletions
diff --git a/src/.jshintrc b/src/.jshintrc
index e29b09f3..2467d667 100644
--- a/src/.jshintrc
+++ b/src/.jshintrc
@@ -100,6 +100,7 @@
"assertNotHasOwnProperty": false,
"getter": false,
"getBlockElements": false,
+ "tokenDifference": false,
/* AngularPublic.js */
"version": false,
@@ -162,4 +163,4 @@
"nullFormCtrl": false
}
-} \ No newline at end of file
+}
diff --git a/src/Angular.js b/src/Angular.js
index 8409f971..b27f4b06 100644
--- a/src/Angular.js
+++ b/src/Angular.js
@@ -80,7 +80,8 @@
-assertArgFn,
-assertNotHasOwnProperty,
-getter,
- -getBlockElements
+ -getBlockElements,
+ -tokenDifference
*/
@@ -1350,3 +1351,24 @@ function getBlockElements(block) {
return jqLite(elements);
}
+
+/**
+ * Return the string difference between tokens of the original string compared to the old string
+ * @param {str1} string original string value
+ * @param {str2} string new string value
+ */
+function tokenDifference(str1, str2) {
+ var values = '',
+ tokens1 = str1.split(/\s+/),
+ tokens2 = str2.split(/\s+/);
+
+ outer:
+ for(var i=0;i<tokens1.length;i++) {
+ var token = tokens1[i];
+ for(var j=0;j<tokens2.length;j++) {
+ if(token == tokens2[j]) continue outer;
+ }
+ values += (values.length > 0 ? ' ' : '') + token;
+ }
+ return values;
+}
diff --git a/src/ng/compile.js b/src/ng/compile.js
index 4d83f379..ce3d0514 100644
--- a/src/ng/compile.js
+++ b/src/ng/compile.js
@@ -688,8 +688,8 @@ function $CompileProvider($provide) {
if(key == 'class') {
value = value || '';
var current = this.$$element.attr('class') || '';
- this.$removeClass(tokenDifference(current, value).join(' '));
- this.$addClass(tokenDifference(value, current).join(' '));
+ this.$removeClass(tokenDifference(current, value));
+ this.$addClass(tokenDifference(value, current));
} else {
var booleanKey = getBooleanAttrName(this.$$element[0], key),
normalizedVal,
@@ -747,22 +747,6 @@ function $CompileProvider($provide) {
$exceptionHandler(e);
}
});
-
- function tokenDifference(str1, str2) {
- var values = [],
- tokens1 = str1.split(/\s+/),
- tokens2 = str2.split(/\s+/);
-
- outer:
- for(var i=0;i<tokens1.length;i++) {
- var token = tokens1[i];
- for(var j=0;j<tokens2.length;j++) {
- if(token == tokens2[j]) continue outer;
- }
- values.push(token);
- }
- return values;
- }
},
diff --git a/src/ng/directive/ngClass.js b/src/ng/directive/ngClass.js
index a0d23a28..10ef7fd1 100644
--- a/src/ng/directive/ngClass.js
+++ b/src/ng/directive/ngClass.js
@@ -21,9 +21,9 @@ function classDirective(name, selector) {
var mod = $index & 1;
if (mod !== old$index & 1) {
if (mod === selector) {
- addClass(scope.$eval(attr[name]));
+ addClass(flattenClasses(scope.$eval(attr[name])));
} else {
- removeClass(scope.$eval(attr[name]));
+ removeClass(flattenClasses(scope.$eval(attr[name])));
}
}
});
@@ -32,22 +32,33 @@ function classDirective(name, selector) {
function ngClassWatchAction(newVal) {
if (selector === true || scope.$index % 2 === selector) {
+ var newClasses = flattenClasses(newVal || '');
if (oldVal && !equals(newVal,oldVal)) {
- removeClass(oldVal);
+ var oldClasses = flattenClasses(oldVal);
+ var toRemove = tokenDifference(oldClasses, newClasses);
+ if(toRemove.length > 0) {
+ removeClass(toRemove);
+ }
+
+ var toAdd = tokenDifference(newClasses, oldClasses);
+ if(toAdd.length > 0) {
+ addClass(toAdd);
+ }
+ } else {
+ addClass(newClasses);
}
- addClass(newVal);
}
oldVal = copy(newVal);
}
function removeClass(classVal) {
- attr.$removeClass(flattenClasses(classVal));
+ attr.$removeClass(classVal);
}
function addClass(classVal) {
- attr.$addClass(flattenClasses(classVal));
+ attr.$addClass(classVal);
}
function flattenClasses(classVal) {