You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.5 KiB

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