-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
Change mergeClasses method name to uniqueClasses Changed the name of the class added to injected SVGs from "iconic-injected-svg" to "injected-svg"
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,12 +14,12 @@ | |
var isLocal = window.location.protocol === 'file:'; | ||
var hasSvgSupport = document.implementation.hasFeature('http://www.w3.org/TR/SVG11/feature#BasicStructure', '1.1'); | ||
|
||
function mergeClasses( list ) { | ||
function uniqueClasses(list) { | ||
list = list.split(' '); | ||
|
||
var hash = {}; | ||
var i = list.length; | ||
var out = []; | ||
var i = list.length; | ||
var out = []; | ||
|
||
while (i--) { | ||
if (!hash.hasOwnProperty(list[i])) { | ||
|
@@ -216,11 +216,9 @@ | |
svg.setAttribute('title', imgTitle); | ||
} | ||
|
||
var imgClass = el.getAttribute('class'); | ||
if (imgClass) { | ||
var classMerge = [svg.getAttribute('class'), 'iconic-injected-svg', imgClass].join(' '); | ||
svg.setAttribute('class', mergeClasses(classMerge)); | ||
} | ||
// Concat the SVG classes + 'injected-svg' + the img classes | ||
var classMerge = [].concat(svg.getAttribute('class') || [], 'injected-svg', el.getAttribute('class') || []).join(' '); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
stryju
Contributor
|
||
svg.setAttribute('class', uniqueClasses(classMerge)); | ||
|
||
var imgStyle = el.getAttribute('style'); | ||
if (imgStyle) { | ||
|
2 comments
on commit 4350111
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.
I used concat
with empty array fallbacks so the join
doesn't add extra spaces when there aren't any SVG or img
element classes defined. (and trim
isn't available pre-IE9, though that's not really an issue since neither is SVG ;})
['', 'injected-svg', ''].join(' '); // -> " injected-svg "
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.
👍
still, i'd consider the getClass
helper method to make it cleaner :-)
wouldn't it be better to fallback to
''
, not[]
, for the sake of simplicity?or better yet - use a helper method:
WDYT?