-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix(jqLite): use get/setAttribute so that jqLite works on SVG #4129
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -279,29 +279,35 @@ function JQLiteData(element, key, value) { | |
} | ||
|
||
function JQLiteHasClass(element, selector) { | ||
return ((" " + element.className + " ").replace(/[\n\t]/g, " "). | ||
return ((" " + (element.getAttribute('class') || '') + " ").replace(/[\n\t]/g, " "). | ||
indexOf( " " + selector + " " ) > -1); | ||
} | ||
|
||
function JQLiteRemoveClass(element, cssClasses) { | ||
if (cssClasses) { | ||
forEach(cssClasses.split(' '), function(cssClass) { | ||
element.className = trim( | ||
(" " + element.className + " ") | ||
element.setAttribute('class', trim( | ||
(" " + (element.getAttribute('class') || '') + " ") | ||
.replace(/[\n\t]/g, " ") | ||
.replace(" " + trim(cssClass) + " ", " ") | ||
.replace(" " + trim(cssClass) + " ", " ")) | ||
); | ||
}); | ||
} | ||
} | ||
|
||
function JQLiteAddClass(element, cssClasses) { | ||
if (cssClasses) { | ||
var existingClasses = (' ' + (element.getAttribute('class') || '') + ' ') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If Igor's comment about reading There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. true There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. getAttribute is needed here because svg elements return a special objects for className property and not a string. |
||
.replace(/[\n\t]/g, " "); | ||
|
||
forEach(cssClasses.split(' '), function(cssClass) { | ||
if (!JQLiteHasClass(element, cssClass)) { | ||
element.className = trim(element.className + ' ' + trim(cssClass)); | ||
cssClass = trim(cssClass); | ||
if (existingClasses.indexOf(' ' + cssClass + ' ') === -1) { | ||
existingClasses += cssClass + ' '; | ||
} | ||
}); | ||
|
||
element.setAttribute('class', trim(existingClasses)); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,7 +156,9 @@ var $AnimateProvider = ['$provide', function($provide) { | |
className = isString(className) ? | ||
className : | ||
isArray(className) ? className.join(' ') : ''; | ||
element.addClass(className); | ||
forEach(element, function (element) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wouldn't forEach try to iterate over element properties if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The element passed to So Maybe a change in the naming of the variable would make this more clear? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what @rodyhaddad said. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh. ok. that makes sense. |
||
JQLiteAddClass(element, className); | ||
}); | ||
done && $timeout(done, 0, false); | ||
}, | ||
|
||
|
@@ -177,7 +179,9 @@ var $AnimateProvider = ['$provide', function($provide) { | |
className = isString(className) ? | ||
className : | ||
isArray(className) ? className.join(' ') : ''; | ||
element.removeClass(className); | ||
forEach(element, function (element) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
JQLiteRemoveClass(element, className); | ||
}); | ||
done && $timeout(done, 0, false); | ||
}, | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not necessary, reading className property is not an issue for us and the property is updated with every setAttribute call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is; SVG Nodes are special.
className
is an object for them :(There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@btford is right here. In this case, the
className
is of typeSVGAnimatedString
. This has a propertybaseVal
that you can read if you like but writing to it has no affect on the actual CSS class attribute of the element.getAttribute
andsetAttribute
seem like the only reasonable solution.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup