Skip to content

Commit 3e8792e

Browse files
committed
use new css api when available
1 parent 560f5d3 commit 3e8792e

File tree

4 files changed

+60
-3
lines changed

4 files changed

+60
-3
lines changed

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
clearTimeout: true,
2727
setInterval: true,
2828
clearInterval: true,
29+
CSSStyleSheet: true,
2930
Blob: true,
30-
cvox: true,
3131
alert: true,
3232
prompt: true,
3333
XMLHttpRequest: true,

demo/csp-simple.html

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
6+
<meta http-equiv="Content-Security-Policy" content="
7+
style-src 'self' ;
8+
img-src 'self' data: ;
9+
script-src 'self' 'nonce-bootstrap-script' https://mkslanc.github.io;
10+
worker-src 'self' blob:
11+
">
12+
<title>Editor</title>
13+
</head>
14+
<body>
15+
<pre id="editor"></pre>
16+
17+
<script src="../build/src-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>
18+
19+
<script nonce="bootstrap-script">
20+
21+
var editor = ace.edit("editor", {
22+
theme: "ace/theme/tomorrow_night_eighties",
23+
mode: "ace/mode/html",
24+
maxLines: 30,
25+
wrap: true,
26+
autoScrollEditorIntoView: true
27+
});
28+
29+
</script>
30+
31+
<script src="./show_own_source.js"></script>
32+
33+
</body>
34+
</html>

demo/csp.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<meta http-equiv="Content-Security-Policy" content="
77
style-src 'self' ;
88
img-src 'self' ;
9-
script-src 'self' 'nonce-bootstrap-script';
9+
script-src 'self' 'nonce-bootstrap-script' https://mkslanc.github.io;
1010
worker-src 'self' blob:
1111
">
1212
<title>Editor</title>

src/lib/dom.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,15 +260,38 @@ function importCssString(cssText, id, target) {
260260
if (id)
261261
cssText += "\n/*# sourceURL=ace/css/" + id + " */";
262262

263+
if (!USE_STYLE_TAG) {
264+
try {
265+
var stylesheet = styles[id];
266+
if (!stylesheet) {
267+
stylesheet = styles[id] = new CSSStyleSheet();
268+
stylesheet.replaceSync(cssText);
269+
}
270+
container.adoptedStyleSheets.push(stylesheet);
271+
USE_STYLE_TAG = false;
272+
return;
273+
} catch(e) {
274+
if (USE_STYLE_TAG === null) {
275+
USE_STYLE_TAG = true;
276+
} else {
277+
setTimeout(function() {
278+
throw e;
279+
});
280+
}
281+
}
282+
}
283+
263284
var style = exports.createElement("style");
264285
style.appendChild(doc.createTextNode(cssText));
265286
if (id)
266287
style.id = id;
267-
268288
if (container == doc)
269289
container = exports.getDocumentHead(doc);
270290
container.insertBefore(style, container.firstChild);
271291
}
292+
var USE_STYLE_TAG = null;
293+
var styles = Object.create(null);
294+
272295
exports.importCssString = importCssString;
273296

274297
/**

0 commit comments

Comments
 (0)