1 | 'use strict';
|
2 |
|
3 | exports.type = 'perItem';
|
4 |
|
5 | exports.active = true;
|
6 |
|
7 | exports.description = 'removes viewBox attribute when possible';
|
8 |
|
9 | var viewBoxElems = ['svg', 'pattern', 'symbol'];
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | exports.fn = function(item) {
|
27 |
|
28 | if (
|
29 | item.isElem(viewBoxElems) &&
|
30 | item.hasAttr('viewBox') &&
|
31 | item.hasAttr('width') &&
|
32 | item.hasAttr('height')
|
33 | ) {
|
34 |
|
35 | var nums = item.attr('viewBox').value.split(/[ ,]+/g);
|
36 |
|
37 | if (
|
38 | nums[0] === '0' &&
|
39 | nums[1] === '0' &&
|
40 | item.attr('width').value.replace(/px$/, '') === nums[2] &&
|
41 | item.attr('height').value.replace(/px$/, '') === nums[3]
|
42 | ) {
|
43 | item.removeAttr('viewBox');
|
44 | }
|
45 |
|
46 | }
|
47 |
|
48 | };
|