1
0
mirror of https://github.com/svg/svgo.git synced 2025-07-29 20:21:14 +03:00

new plugin removeViewBox

This commit is contained in:
deepsweet
2012-09-29 17:35:51 +04:00
parent e0411e63d2
commit 5ac7d69342
2 changed files with 38 additions and 0 deletions

35
plugins/removeViewBox.js Normal file
View File

@ -0,0 +1,35 @@
var regViewBox = /^0\s0\s(\d+)\s(\d+)$/,
viewBoxElems = ['svg', 'marker', 'pattern', 'symbol', 'view'];
/**
* Remove viewBox attr which coincides with a width/height box.
*
* @see http://www.w3.org/TR/SVG/coords.html#ViewBoxAttribute
*
* @param {Object} item current iteration item
* @param {Object} params plugin params
* @return {Boolean} if false, item will be filtered out
*
* @author Kir Belevich
*/
exports.removeViewBox = function(item, params) {
if (
item.isElem(viewBoxElems) &&
item.hasAttr('viewBox') &&
item.hasAttr('width') &&
item.hasAttr('height')
) {
if (match = item.attr('viewBox').value.match(regViewBox)) {
if (
item.attr('width').value == match[1] &&
item.attr('height').value == match[2]
) {
item.removeAttr('viewBox');
}
}
}
};