-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new plugin: remove useless 'stroke' and 'fill' attrs (close svg#75)
- Loading branch information
deepsweet
committed
Dec 11, 2012
1 parent
d75c830
commit db91885
Showing
6 changed files
with
89 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
'use strict'; | ||
|
||
var regStrokeProps = /^stroke/, | ||
regFillProps = /^fill/; | ||
|
||
/** | ||
* Remove useless stroke and fill attrs. | ||
* | ||
* @param {Object} item current iteration item | ||
* @param {Object} params plugin params | ||
* @return {Boolean} if false, item will be filtered out | ||
* | ||
* @author Kir Belevich | ||
*/ | ||
exports.removeUselessStrokeAndFill = function(item, params) { | ||
|
||
if (item.isElem()) { | ||
|
||
// remove stroke* | ||
if ( | ||
params.stroke && | ||
(!item.hasAttr('stroke') || | ||
item.hasAttr('stroke-opacity', '0') || | ||
item.hasAttr('stroke-width', '0') | ||
) | ||
) { | ||
item.eachAttr(function(attr) { | ||
if (regStrokeProps.test(attr.name)) { | ||
item.removeAttr(attr.name); | ||
} | ||
}); | ||
} | ||
|
||
// remove fill* | ||
if ( | ||
params.fill && | ||
item.hasAttr('fill', 'none') || | ||
item.hasAttr('fill-opacity', '0') | ||
) { | ||
item.eachAttr(function(attr) { | ||
if (regFillProps.test(attr.name)) { | ||
item.removeAttr(attr.name); | ||
} | ||
}); | ||
|
||
item.addAttr({ | ||
name: 'fill', | ||
value: 'none', | ||
prefix: '', | ||
local: 'fill' | ||
}); | ||
} | ||
|
||
} | ||
|
||
}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.