|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.1 KB
|
| Line | |
|---|
| 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 | * Remove viewBox attr which coincides with a width/height box.
|
|---|
| 13 | *
|
|---|
| 14 | * @see http://www.w3.org/TR/SVG/coords.html#ViewBoxAttribute
|
|---|
| 15 | *
|
|---|
| 16 | * @example
|
|---|
| 17 | * <svg width="100" height="50" viewBox="0 0 100 50">
|
|---|
| 18 | * ⬇
|
|---|
| 19 | * <svg width="100" height="50">
|
|---|
| 20 | *
|
|---|
| 21 | * @param {Object} item current iteration item
|
|---|
| 22 | * @return {Boolean} if false, item will be filtered out
|
|---|
| 23 | *
|
|---|
| 24 | * @author Kir Belevich
|
|---|
| 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] && // could use parseFloat too
|
|---|
| 41 | item.attr('height').value.replace(/px$/, '') === nums[3]
|
|---|
| 42 | ) {
|
|---|
| 43 | item.removeAttr('viewBox');
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.