From 29b7dcb93683bd5c8863b8eb934b17089b05372f Mon Sep 17 00:00:00 2001 From: Rory Hunter Date: Thu, 6 Apr 2017 14:04:20 +0100 Subject: [PATCH] Set span styling via individual style properties This can help avoid triggering Context Security Policy warnings. --- index.js | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index 3e88157..0e4bda8 100755 --- a/index.js +++ b/index.js @@ -21,21 +21,19 @@ function copy(text, options) { mark = document.createElement('span'); mark.textContent = text; - mark.setAttribute('style', [ - // reset user styles for span element - 'all: unset', - // prevents scrolling to the end of the page - 'position: fixed', - 'top: 0', - 'clip: rect(0, 0, 0, 0)', - // used to preserve spaces and line breaks - 'white-space: pre', - // do not inherit user-select (it may be `none`) - '-webkit-user-select: text', - '-moz-user-select: text', - '-ms-user-select: text', - 'user-select: text', - ].join(';')); + // reset user styles for span element + mark.style.all = 'unset'; + // prevents scrolling to the end of the page + mark.style.position = 'fixed'; + mark.style.top = 0; + mark.style.clip = 'rect(0, 0, 0, 0)'; + // used to preserve spaces and line breaks + mark.style.whiteSpace = 'pre'; + // do not inherit user-select (it may be `none`) + mark.style.webkitUserSelect = 'text'; + mark.style.MozUserSelect = 'text'; + mark.style.msUserSelect = 'text'; + mark.style.userSelect = 'text'; document.body.appendChild(mark);