项目原始demo,不改动
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
To repozytorium jest zarchiwizowane. Możesz wyświetlać pliki i je sklonować, ale nie możesz do niego przepychać zmian lub otwierać zgłoszeń/Pull Requestów.
 
 
 
 

52 wiersze
1.0 KiB

  1. 'use strict';
  2. exports.type = 'perItem';
  3. exports.active = true;
  4. exports.description = 'removes elements in <defs> without id';
  5. var nonRendering = require('./_collections').elemsGroups.nonRendering,
  6. defs;
  7. /**
  8. * Removes content of defs and properties that aren't rendered directly without ids.
  9. *
  10. * @param {Object} item current iteration item
  11. * @return {Boolean} if false, item will be filtered out
  12. *
  13. * @author Lev Solntsev
  14. */
  15. exports.fn = function(item) {
  16. if (item.isElem('defs')) {
  17. defs = item;
  18. item.content = (item.content || []).reduce(getUsefulItems, []);
  19. if (item.isEmpty()) return false;
  20. } else if (item.isElem(nonRendering) && !item.hasAttr('id')) {
  21. return false;
  22. }
  23. };
  24. function getUsefulItems(usefulItems, item) {
  25. if (item.hasAttr('id') || item.isElem('style')) {
  26. usefulItems.push(item);
  27. item.parentNode = defs;
  28. } else if (!item.isEmpty()) {
  29. item.content.reduce(getUsefulItems, usefulItems);
  30. }
  31. return usefulItems;
  32. }