|
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.3 KB
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | exports.type = 'perItem';
|
|---|
| 4 |
|
|---|
| 5 | exports.active = false;
|
|---|
| 6 |
|
|---|
| 7 | exports.description = 'removes width and height in presence of viewBox (opposite to removeViewBox, disable it first)';
|
|---|
| 8 |
|
|---|
| 9 | /**
|
|---|
| 10 | * Remove width/height attributes and add the viewBox attribute if it's missing
|
|---|
| 11 | *
|
|---|
| 12 | * @example
|
|---|
| 13 | * <svg width="100" height="50" />
|
|---|
| 14 | * ↓
|
|---|
| 15 | * <svg viewBox="0 0 100 50" />
|
|---|
| 16 | *
|
|---|
| 17 | * @param {Object} item current iteration item
|
|---|
| 18 | * @return {Boolean} if true, with and height will be filtered out
|
|---|
| 19 | *
|
|---|
| 20 | * @author Benny Schudel
|
|---|
| 21 | */
|
|---|
| 22 | exports.fn = function(item) {
|
|---|
| 23 |
|
|---|
| 24 | if (item.isElem('svg')) {
|
|---|
| 25 | if (item.hasAttr('viewBox')) {
|
|---|
| 26 | item.removeAttr('width');
|
|---|
| 27 | item.removeAttr('height');
|
|---|
| 28 | } else if (
|
|---|
| 29 | item.hasAttr('width') &&
|
|---|
| 30 | item.hasAttr('height') &&
|
|---|
| 31 | !isNaN(Number(item.attr('width').value)) &&
|
|---|
| 32 | !isNaN(Number(item.attr('height').value))
|
|---|
| 33 | ) {
|
|---|
| 34 | item.addAttr({
|
|---|
| 35 | name: 'viewBox',
|
|---|
| 36 | value:
|
|---|
| 37 | '0 0 ' +
|
|---|
| 38 | Number(item.attr('width').value) +
|
|---|
| 39 | ' ' +
|
|---|
| 40 | Number(item.attr('height').value),
|
|---|
| 41 | prefix: '',
|
|---|
| 42 | local: 'viewBox'
|
|---|
| 43 | });
|
|---|
| 44 | item.removeAttr('width');
|
|---|
| 45 | item.removeAttr('height');
|
|---|
| 46 | }
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.