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

Commit 23c0956

Browse files
committed
refactor($compile): remove safeAddClass
This helper function does try/catch in case the element is an SVG element. jqLite does handle this properly (because it uses `setAttribute`. jQuery does not handle this and so we need to make sure we use `jqLiteAddClass` function.
1 parent 9a5ba89 commit 23c0956

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

src/ng/compile.js

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -887,16 +887,6 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
887887
};
888888

889889

890-
function safeAddClass($element, className) {
891-
try {
892-
$element.addClass(className);
893-
} catch(e) {
894-
// ignore, since it means that we are trying to set class on
895-
// SVG element, where class name is read-only.
896-
}
897-
}
898-
899-
900890
var startSymbol = $interpolate.startSymbol(),
901891
endSymbol = $interpolate.endSymbol(),
902892
denormalizeTemplate = (startSymbol == '{{' || endSymbol == '}}')
@@ -919,7 +909,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
919909
} : noop;
920910

921911
compile.$$addBindingClass = debugInfoEnabled ? function $$addBindingClass($element) {
922-
safeAddClass($element, 'ng-binding');
912+
jqLiteAddClass($element[0], 'ng-binding');
923913
} : noop;
924914

925915
compile.$$addScopeInfo = debugInfoEnabled ? function $$addScopeInfo($element, scope, isolated, noTemplate) {
@@ -928,7 +918,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
928918
} : noop;
929919

930920
compile.$$addScopeClass = debugInfoEnabled ? function $$addScopeClass($element, isolated) {
931-
safeAddClass($element, isolated ? 'ng-isolate-scope' : 'ng-scope');
921+
jqLiteAddClass($element[0], isolated ? 'ng-isolate-scope' : 'ng-scope');
932922
} : noop;
933923

934924
return compile;
@@ -1842,7 +1832,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
18421832
// copy the new attributes on the old attrs object
18431833
forEach(src, function(value, key) {
18441834
if (key == 'class') {
1845-
safeAddClass($element, value);
1835+
jqLiteAddClass($element[0], value);
18461836
dst['class'] = (dst['class'] ? dst['class'] + ' ' : '') + value;
18471837
} else if (key == 'style') {
18481838
$element.attr('style', $element.attr('style') + ';' + value);
@@ -1941,7 +1931,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
19411931
replaceWith(linkRootElement, jqLite(beforeTemplateLinkNode), linkNode);
19421932

19431933
// Copy in CSS classes from original node
1944-
safeAddClass(jqLite(linkNode), oldClasses);
1934+
jqLiteAddClass(linkNode, oldClasses);
19451935
}
19461936
if (afterTemplateNodeLinkFn.transcludeOnThisElement) {
19471937
childBoundTranscludeFn = createBoundTranscludeFn(scope, afterTemplateNodeLinkFn.transclude, boundTranscludeFn);

0 commit comments

Comments
 (0)