123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- 'use strict';
- var DEFAULT_SEPARATOR = ':';
- exports.type = 'perItem';
- exports.active = false;
- exports.description = 'removes specified attributes';
- exports.params = {
- elemSeparator: DEFAULT_SEPARATOR,
- preserveCurrentColor: false,
- attrs: []
- };
- exports.fn = function(item, params) {
-
- if (!Array.isArray(params.attrs)) {
- params.attrs = [params.attrs];
- }
- if (item.isElem()) {
- var elemSeparator = typeof params.elemSeparator == 'string' ? params.elemSeparator : DEFAULT_SEPARATOR;
- var preserveCurrentColor = typeof params.preserveCurrentColor == 'boolean' ? params.preserveCurrentColor : false;
-
- var patterns = params.attrs.map(function(pattern) {
-
- if (pattern.indexOf(elemSeparator) === -1) {
- pattern = ['.*', elemSeparator, pattern, elemSeparator, '.*'].join('');
-
- } else if (pattern.split(elemSeparator).length < 3) {
- pattern = [pattern, elemSeparator, '.*'].join('');
- }
-
- return pattern.split(elemSeparator)
- .map(function(value) {
-
- if (value === '*') { value = '.*'; }
- return new RegExp(['^', value, '$'].join(''), 'i');
- });
- });
-
- patterns.forEach(function(pattern) {
-
- if (pattern[0].test(item.elem)) {
-
- item.eachAttr(function(attr) {
- var name = attr.name;
- var value = attr.value;
- var isFillCurrentColor = preserveCurrentColor && name == 'fill' && value == 'currentColor';
- var isStrokeCurrentColor = preserveCurrentColor && name == 'stroke' && value == 'currentColor';
- if (!(isFillCurrentColor || isStrokeCurrentColor)) {
-
- if (pattern[1].test(name)) {
-
- if (pattern[2].test(attr.value)) {
- item.removeAttr(name);
- }
- }
- }
- });
- }
- });
- }
- };
|