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.

setStyleAttrs.js 776B

12345678910111213141516171819202122232425
  1. module.exports = (el, $) => {
  2. let i;
  3. let style = [];
  4. for (i in el.styleProps) {
  5. // add !important
  6. if (typeof el.styleProps[i].selector.spec !== 'undefined') {
  7. if (el.styleProps[i].selector.spec[0] === 2) {
  8. el.styleProps[i].value += ' !important';
  9. }
  10. }
  11. style.push(`${el.styleProps[i].prop}: ${el.styleProps[i].value.replace(/["]/g, '\'')};`);
  12. }
  13. // sorting will arrange styles like padding: before padding-bottom: which will preserve the expected styling
  14. style = style.sort((a, b) => {
  15. const aProp = a.split(':')[0];
  16. const bProp = b.split(':')[0];
  17. return (aProp > bProp ? 1 : aProp < bProp ? -1 : 0);
  18. });
  19. $(el).attr('style', style.join(' '));
  20. };