removeDimensions.js 662 B

1234567891011121314151617181920212223242526272829303132
  1. 'use strict';
  2. exports.type = 'perItem';
  3. exports.active = false;
  4. exports.description = 'removes width and height in presence of viewBox';
  5. /**
  6. * Remove width/height attributes when a viewBox attribute is present.
  7. *
  8. * @example
  9. * <svg width="100" height="50" viewBox="0 0 100 50">
  10. * ↓
  11. * <svg viewBox="0 0 100 50">
  12. *
  13. * @param {Object} item current iteration item
  14. * @return {Boolean} if true, with and height will be filtered out
  15. *
  16. * @author Benny Schudel
  17. */
  18. exports.fn = function(item) {
  19. if (
  20. item.isElem('svg') &&
  21. item.hasAttr('viewBox')
  22. ) {
  23. item.removeAttr('width');
  24. item.removeAttr('height');
  25. }
  26. };