Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
fix($compile): don't touch static element attributes
Browse files Browse the repository at this point in the history
Compiler should not reassign values to element attributes if its not neccessary due
to interpolation or special attribute magic (ng-src -> src)

This resolves several issues on IE caused by reassigning script.src attribute which
caused all of the scripts to be reloaded.
  • Loading branch information
IgorMinar committed Mar 20, 2012
1 parent 15213ec commit 9cb2195
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/service/compiler.js
Expand Up @@ -861,16 +861,21 @@ function $CompileProvider($provide) {


function addAttrInterpolateDirective(node, directives, value, name) {
var interpolateFn = $interpolate(value, true);
if (SIDE_EFFECT_ATTRS[name]) {
name = SIDE_EFFECT_ATTRS[name];
if (isBooleanAttr(node, name)) {
value = true;
}
} else if (!interpolateFn) {
// we are not a side-effect attr, and we have no side-effects -> ignore
var interpolateFn = $interpolate(value, true),
realName = SIDE_EFFECT_ATTRS[name],
specialAttrDir = (realName && (realName !== name));

realName = realName || name;

if (specialAttrDir && isBooleanAttr(node, name)) {
value = true;
}

// no interpolation found and we are not a side-effect attr -> ignore
if (!interpolateFn && !specialAttrDir) {
return;
}

directives.push({
priority: 100,
compile: function(element, attr) {
Expand All @@ -884,14 +889,14 @@ function $CompileProvider($provide) {

// we define observers array only for interpolated attrs
// and ignore observers for non interpolated attrs to save some memory
attr.$observers[name] = [];
attr[name] = undefined;
attr.$observers[realName] = [];
attr[realName] = undefined;
scope.$watch(interpolateFn, function(value) {
attr.$set(name, value);
attr.$set(realName, value);
});
};
} else {
attr.$set(name, value);
attr.$set(realName, value);
}
}
});
Expand Down

0 comments on commit 9cb2195

Please sign in to comment.