From 829d49a0301beac7ddd9cf3a60d152d60d95fd17 Mon Sep 17 00:00:00 2001 From: Lukas Roettgers Date: Tue, 1 Oct 2019 15:28:43 +0200 Subject: [PATCH] Fixing CSP restriction of setAttribute --- src/index.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 3744e3f..8257d2b 100644 --- a/src/index.js +++ b/src/index.js @@ -857,8 +857,18 @@ export function backupAttr(el, name) { } export function restoreAttr(el, name) { - const key = `original_${name}` - el.setAttribute(name, el[key]) + const key = "original_".concat(name) + if (name === 'style' && !el[key]) { + //== clear all styles, CSP save + const elementStyle= el.style + for (let prop of elementStyle) { + if (elementStyle.hasOwnProperty(prop) && elementStyle[prop]) { + elementStyle[prop] = "" + } + } + } else { + el.setAttribute(name, el[key]); + } } // source: http://youmightnotneedjquery.com/