Skip to content

Commit

Permalink
Merge 8fa3622 into d0c3355
Browse files Browse the repository at this point in the history
  • Loading branch information
AprilArcus committed May 1, 2015
2 parents d0c3355 + 8fa3622 commit 0631ee4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .svgo.yml
Expand Up @@ -47,4 +47,5 @@ plugins:
- transformsWithOnePath
- sortAttrs
- removeTitle
- removeDesc
- removeDesc
- addClassesToSVGElement
38 changes: 38 additions & 0 deletions plugins/addClassesToSVGElement.js
@@ -0,0 +1,38 @@
'use strict';

exports.type = 'full';

exports.active = false;

/**
* Add classnames to an outer <svg> element.
*
* @author April Arcus
*/
exports.fn = function(data, params) {

var classNames = params.classNames || [ params.className ]
var svg = data.content[0]

if (svg.isElem('svg')) {

if (svg.hasAttr('class')) {
svg.attr('class').value =
svg.attr('class').value
.split(' ')
.concat(classNames)
.join(' ');
} else {
svg.addAttr({
name: 'class',
value: classNames.join(' '),
prefix: '',
local: 'class'
});
}

}

return data;

};

0 comments on commit 0631ee4

Please sign in to comment.