Skip to content

Commit

Permalink
Set span styling via individual style properties
Browse files Browse the repository at this point in the history
This can help avoid triggering Context Security Policy warnings.
  • Loading branch information
pugnascotia committed Apr 6, 2017
1 parent 3e06d9c commit 29b7dcb
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 29b7dcb

Please sign in to comment.