Skip to content

Commit e0d69e4

Browse files
committed
use new css api when available
1 parent 0e0571a commit e0d69e4

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
@@ -271,15 +271,38 @@ function importCssString(cssText, id, target) {
271271
if (id)
272272
cssText += "\n/*# sourceURL=ace/css/" + id + " */";
273273

274+
if (!USE_STYLE_TAG) {
275+
try {
276+
var stylesheet = styles[id];
277+
if (!stylesheet) {
278+
stylesheet = styles[id] = new CSSStyleSheet();
279+
stylesheet.replaceSync(cssText);
280+
}
281+
container.adoptedStyleSheets.push(stylesheet);
282+
USE_STYLE_TAG = false;
283+
return;
284+
} catch(e) {
285+
if (USE_STYLE_TAG === null) {
286+
USE_STYLE_TAG = true;
287+
} else {
288+
setTimeout(function() {
289+
throw e;
290+
});
291+
}
292+
}
293+
}
294+
274295
var style = exports.createElement("style");
275296
style.appendChild(doc.createTextNode(cssText));
276297
if (id)
277298
style.id = id;
278-
279299
if (container == doc)
280300
container = exports.getDocumentHead(doc);
281301
container.insertBefore(style, container.firstChild);
282302
}
303+
var USE_STYLE_TAG = null;
304+
var styles = Object.create(null);
305+
283306
exports.importCssString = importCssString;
284307

285308
/**

0 commit comments

Comments
 (0)