-
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load a stylesheet into the shadow-root
For #409
- Loading branch information
Showing
8 changed files
with
26 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/* day8/re-frame-10x */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,22 @@ | ||
(ns day8.re-frame-10x.tools.shadow-dom) | ||
|
||
(defn attach-stylesheet [shadow-root css-str] | ||
(let [stylesheet (js/CSSStyleSheet.) | ||
_ (.replaceSync stylesheet css-str)] | ||
(set! (.-adoptedStyleSheets shadow-root) (js/Array. stylesheet)))) | ||
|
||
(defn shadow-root | ||
"Creates a new div element with the id attached to the js-document <body>, | ||
attaches a shadow DOM tree and returns a reference to its ShadowRoot." | ||
[js-document id] | ||
[js-document id css-str] | ||
(let [container (.getElementById js-document id)] | ||
(if container | ||
(.-shadowRoot container) | ||
(let [body (.-body js-document) | ||
container (.createElement js-document "div") | ||
shadow-root (.attachShadow container #js {:mode "open"})] | ||
(attach-stylesheet shadow-root css-str) | ||
(.setAttribute container "id" id) | ||
(.appendChild body container) | ||
(js/window.focus container) | ||
shadow-root)))) | ||
shadow-root)))) |