Skip to content

Commit

Permalink
use new css api when available
Browse files Browse the repository at this point in the history
  • Loading branch information
nightwing committed Sep 28, 2024
1 parent 560f5d3 commit 87b5544
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
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 @@ function importCssString(cssText, id, target) {
if (id)
cssText += "\n/*# sourceURL=ace/css/" + id + " */";

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

Check failure on line 267 in src/lib/dom.js

View workflow job for this annotation

GitHub Actions / build (16.x)

'CSSStyleSheet' is not defined
stylesheet.replaceSync(cssText);
}
container.adoptedStyleSheets.push(stylesheet);
USE_STYLE_TAG = false;
return;
} catch(e) {
if (USE_STYLE_TAG === null) {
USE_STYLE_TAG = true;
} else {
setTimeout(function() {
throw e

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

View workflow job for this annotation

GitHub Actions / build (16.x)

Missing semicolon
});
}
}
}

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

0 comments on commit 87b5544

Please sign in to comment.