123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- 'use strict';
- exports.type = 'full';
- exports.active = true;
- exports.description = 'removes unused namespaces declaration';
- exports.fn = function(data) {
- var svgElem,
- xmlnsCollection = [];
-
- function removeNSfromCollection(ns) {
- var pos = xmlnsCollection.indexOf(ns);
-
- if (pos > -1) {
- xmlnsCollection.splice(pos, 1);
- }
- }
-
- function monkeys(items) {
- var i = 0,
- length = items.content.length;
- while(i < length) {
- var item = items.content[i];
- if (item.isElem('svg')) {
- item.eachAttr(function(attr) {
-
- if (attr.prefix === 'xmlns' && attr.local) {
- xmlnsCollection.push(attr.local);
- }
- });
-
- if (xmlnsCollection.length) {
-
- svgElem = item;
- }
- }
- if (xmlnsCollection.length) {
-
- if (item.prefix) {
- removeNSfromCollection(item.prefix);
- }
-
- item.eachAttr(function(attr) {
- removeNSfromCollection(attr.prefix);
- });
- }
-
- if (xmlnsCollection.length && item.content) {
- monkeys(item);
- }
- i++;
- }
- return items;
- }
- data = monkeys(data);
-
- if (xmlnsCollection.length) {
- xmlnsCollection.forEach(function(name) {
- svgElem.removeAttr('xmlns:' + name);
- });
- }
- return data;
- };
|