|
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:
2.0 KB
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | exports.type = 'full';
|
|---|
| 4 |
|
|---|
| 5 | exports.active = false;
|
|---|
| 6 |
|
|---|
| 7 | exports.description = 'adds attributes to an outer <svg> element';
|
|---|
| 8 |
|
|---|
| 9 | var ENOCLS = `Error in plugin "addAttributesToSVGElement": absent parameters.
|
|---|
| 10 | It should have a list of "attributes" or one "attribute".
|
|---|
| 11 | Config example:
|
|---|
| 12 |
|
|---|
| 13 | plugins:
|
|---|
| 14 | - addAttributesToSVGElement:
|
|---|
| 15 | attribute: "mySvg"
|
|---|
| 16 |
|
|---|
| 17 | plugins:
|
|---|
| 18 | - addAttributesToSVGElement:
|
|---|
| 19 | attributes: ["mySvg", "size-big"]
|
|---|
| 20 |
|
|---|
| 21 | plugins:
|
|---|
| 22 | - addAttributesToSVGElement:
|
|---|
| 23 | attributes:
|
|---|
| 24 | - focusable: false
|
|---|
| 25 | - data-image: icon`;
|
|---|
| 26 |
|
|---|
| 27 | /**
|
|---|
| 28 | * Add attributes to an outer <svg> element. Example config:
|
|---|
| 29 | *
|
|---|
| 30 | * plugins:
|
|---|
| 31 | * - addAttributesToSVGElement:
|
|---|
| 32 | * attribute: 'data-icon'
|
|---|
| 33 | *
|
|---|
| 34 | * plugins:
|
|---|
| 35 | * - addAttributesToSVGElement:
|
|---|
| 36 | * attributes: ['data-icon', 'data-disabled']
|
|---|
| 37 | *
|
|---|
| 38 | * plugins:
|
|---|
| 39 | * - addAttributesToSVGElement:
|
|---|
| 40 | * attributes:
|
|---|
| 41 | * - focusable: false
|
|---|
| 42 | * - data-image: icon
|
|---|
| 43 | *
|
|---|
| 44 | * @author April Arcus
|
|---|
| 45 | */
|
|---|
| 46 | exports.fn = function(data, params) {
|
|---|
| 47 | if (!params || !(Array.isArray(params.attributes) || params.attribute)) {
|
|---|
| 48 | console.error(ENOCLS);
|
|---|
| 49 | return data;
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | var attributes = params.attributes || [ params.attribute ],
|
|---|
| 53 | svg = data.content[0];
|
|---|
| 54 |
|
|---|
| 55 | if (svg.isElem('svg')) {
|
|---|
| 56 | attributes.forEach(function (attribute) {
|
|---|
| 57 | if (typeof attribute === 'string') {
|
|---|
| 58 | if (!svg.hasAttr(attribute)) {
|
|---|
| 59 | svg.addAttr({
|
|---|
| 60 | name: attribute,
|
|---|
| 61 | prefix: '',
|
|---|
| 62 | local: attribute
|
|---|
| 63 | });
|
|---|
| 64 | }
|
|---|
| 65 | } else if (typeof attribute === 'object') {
|
|---|
| 66 | Object.keys(attribute).forEach(function (key) {
|
|---|
| 67 | if (!svg.hasAttr(key)) {
|
|---|
| 68 | svg.addAttr({
|
|---|
| 69 | name: key,
|
|---|
| 70 | value: attribute[key],
|
|---|
| 71 | prefix: '',
|
|---|
| 72 | local: key
|
|---|
| 73 | });
|
|---|
| 74 | }
|
|---|
| 75 | });
|
|---|
| 76 | }
|
|---|
| 77 | });
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | return data;
|
|---|
| 81 |
|
|---|
| 82 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.