Skip to content

Commit 42c4810

Browse files
author
Jason Smith
committed
Used shadowdom and magic to make editor easier
1 parent 043cb79 commit 42c4810

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

src/PatternkitDrupalTwigLib.php

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,13 @@ public function getEditor($subtype = NULL,
8686
: $config;
8787
// @todo Move to own JS file & Drupal Settings config var.
8888
$markup = <<<HTML
89-
<div id="editor_holder"></div>
89+
<div id="magic-pixie-dust"></div>
9090
<script type="text/javascript">
91+
let target = document.getElementById("magic-pixie-dust");
92+
let shadow = target.attachShadow({mode: 'open'});
93+
94+
shadow.innerHTML = '<link rel="stylesheet" id="theme_stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css"><link rel="stylesheet" id="icon_stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.0.3/css/font-awesome.css"><div id="editor_holder"></div>';
95+
9196
var data = {};
9297
data.schema = $schema_json;
9398
data.starting = $starting_json;
@@ -102,10 +107,10 @@ public function getEditor($subtype = NULL,
102107
103108
// Initialize the editor with a JSON schema
104109
var editor = new JSONEditor(
105-
document.getElementById('editor_holder'), {
110+
target.shadowRoot.getElementById('editor_holder'), {
106111
schema: data.schema,
107-
theme: 'jqueryui',
108-
iconlib: 'jqueryui',
112+
theme: 'bootstrap3',
113+
iconlib: 'fontawesome4',
109114
keep_oneof_values: false,
110115
ajax: true
111116
}
@@ -120,11 +125,18 @@ public function getEditor($subtype = NULL,
120125
</script>
121126
HTML;
122127

123-
// @todo Toggle based on developer settings.
124-
drupal_add_js(drupal_get_path('module', 'patternkit')
125-
. '/js/jsoneditor.js');
126-
127-
return $markup;
128+
return array(
129+
'#type' => 'markup',
130+
'#markup' => $markup,
131+
'#attached' => array(
132+
'library' => array(
133+
array('system', 'ui'),
134+
),
135+
'js' => array(
136+
drupal_get_path('module', 'patternkit') . '/js/jsoneditor.js',
137+
),
138+
),
139+
);
128140
}
129141

130142
/**

0 commit comments

Comments
 (0)