UNPKG

1.55 kBJavaScriptView Raw
1'use strict';
2
3exports.type = 'perItem';
4
5exports.active = true;
6
7exports.description = 'removes editors namespaces, elements and attributes';
8
9var editorNamespaces = require('./_collections').editorNamespaces,
10 prefixes = [];
11
12exports.params = {
13 additionalNamespaces: []
14};
15
16/**
17 * Remove editors namespaces, elements and attributes.
18 *
19 * @example
20 * <svg xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd">
21 * <sodipodi:namedview/>
22 * <path sodipodi:nodetypes="cccc"/>
23 *
24 * @param {Object} item current iteration item
25 * @param {Object} params plugin params
26 * @return {Boolean} if false, item will be filtered out
27 *
28 * @author Kir Belevich
29 */
30exports.fn = function(item, params) {
31
32 if (Array.isArray(params.additionalNamespaces)) {
33 editorNamespaces = editorNamespaces.concat(params.additionalNamespaces);
34 }
35
36 if (item.elem) {
37
38 if (item.isElem('svg')) {
39
40 item.eachAttr(function(attr) {
41 if (attr.prefix === 'xmlns' && editorNamespaces.indexOf(attr.value) > -1) {
42 prefixes.push(attr.local);
43
44 // <svg xmlns:sodipodi="">
45 item.removeAttr(attr.name);
46 }
47 });
48
49 }
50
51 // <* sodipodi:*="">
52 item.eachAttr(function(attr) {
53 if (prefixes.indexOf(attr.prefix) > -1) {
54 item.removeAttr(attr.name);
55 }
56 });
57
58 // <sodipodi:*>
59 if (prefixes.indexOf(item.prefix) > -1) {
60 return false;
61 }
62
63 }
64
65};