From f8faa1f2f7c65e96f21fa5a8ef0cf7bb46f0372d Mon Sep 17 00:00:00 2001 From: deepsweet Date: Sat, 29 Sep 2012 17:36:19 +0400 Subject: [PATCH] new plugin cleanupEnableBackground --- .svgo | 3 +++ plugins/cleanupEnableBackground.js | 39 ++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 plugins/cleanupEnableBackground.js diff --git a/.svgo b/.svgo index 9f173811..ae42f414 100644 --- a/.svgo +++ b/.svgo @@ -54,6 +54,9 @@ },{ "name": "removeViewBox", "active": true + },{ + "name": "cleanupEnableBackground", + "active": true },{ "name": "removeHiddenElems", "active": true, diff --git a/plugins/cleanupEnableBackground.js b/plugins/cleanupEnableBackground.js new file mode 100644 index 00000000..2f0192c5 --- /dev/null +++ b/plugins/cleanupEnableBackground.js @@ -0,0 +1,39 @@ +var regEnableBackground = /^new\s0\s0\s(\d+)\s(\d+)$/, + container = require('./_collections').elems.container; + +/** + * Remove or cleanup enable-background attr which coincides with a width/height box. + * + * @see http://www.w3.org/TR/SVG/filters.html#EnableBackgroundProperty + * + * @param {Object} item current iteration item + * @param {Object} params plugin params + * @return {Boolean} if false, item will be filtered out + * + * @author Kir Belevich + */ +exports.cleanupEnableBackground = function(item, params) { + + if ( + item.isElem(container) && + item.hasAttr('enable-background') && + item.hasAttr('width') && + item.hasAttr('height') + ) { + + if (match = item.attr('enable-background').value.match(regEnableBackground)) { + if ( + item.attr('width').value == match[1] && + item.attr('height').value == match[2] + ) { + if (item.isElem('svg')) { + item.removeAttr('enable-background'); + } else { + item.attr('enable-background').value = 'new'; + } + } + } + + } + +};