Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use new css api when available #5646

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
clearTimeout: true,
setInterval: true,
clearInterval: true,
CSSStyleSheet: true,
Blob: true,
cvox: true,
alert: true,
prompt: true,
XMLHttpRequest: true,
Expand Down
34 changes: 34 additions & 0 deletions demo/csp-simple.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta http-equiv="Content-Security-Policy" content="
style-src 'self' ;
img-src 'self' data: ;
script-src 'self' 'nonce-bootstrap-script' https://mkslanc.github.io;
worker-src 'self' blob:
">
<title>Editor</title>
</head>
<body>
<pre id="editor"></pre>

<script src="../build/src-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>

<script nonce="bootstrap-script">

var editor = ace.edit("editor", {
theme: "ace/theme/tomorrow_night_eighties",
mode: "ace/mode/html",
maxLines: 30,
wrap: true,
autoScrollEditorIntoView: true
});

</script>

<script src="./show_own_source.js"></script>

</body>
</html>
2 changes: 1 addition & 1 deletion demo/csp.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta http-equiv="Content-Security-Policy" content="
style-src 'self' ;
img-src 'self' ;
script-src 'self' 'nonce-bootstrap-script';
script-src 'self' 'nonce-bootstrap-script' https://mkslanc.github.io;
worker-src 'self' blob:
">
<title>Editor</title>
Expand Down
25 changes: 24 additions & 1 deletion src/lib/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,38 @@
if (id)
cssText += "\n/*# sourceURL=ace/css/" + id + " */";

if (!USE_STYLE_TAG) {
try {
var stylesheet = styles[id];
if (!stylesheet) {
stylesheet = styles[id] = new CSSStyleSheet();
stylesheet.replaceSync(cssText);

Check warning on line 268 in src/lib/dom.js

View check run for this annotation

Codecov / codecov/patch

src/lib/dom.js#L268

Added line #L268 was not covered by tests
}
container.adoptedStyleSheets.push(stylesheet);
USE_STYLE_TAG = false;
return;

Check warning on line 272 in src/lib/dom.js

View check run for this annotation

Codecov / codecov/patch

src/lib/dom.js#L270-L272

Added lines #L270 - L272 were not covered by tests
} catch(e) {
if (USE_STYLE_TAG === null) {
USE_STYLE_TAG = true;
} else {
setTimeout(function() {
throw e;

Check warning on line 278 in src/lib/dom.js

View check run for this annotation

Codecov / codecov/patch

src/lib/dom.js#L277-L278

Added lines #L277 - L278 were not covered by tests
});
}
}
}

var style = exports.createElement("style");
style.appendChild(doc.createTextNode(cssText));
if (id)
style.id = id;

if (container == doc)
container = exports.getDocumentHead(doc);
container.insertBefore(style, container.firstChild);
}
var USE_STYLE_TAG = null;
var styles = Object.create(null);

exports.importCssString = importCssString;

/**
Expand Down
Loading