@@ -81,15 +81,17 @@ public function getEditor($subtype = NULL,
81
81
return t ('Unable to lookup the schema for this subtype. ' );
82
82
}
83
83
84
+ $ hostname = $ _SERVER ['HTTP_HOST ' ];
85
+
84
86
$ schema_json = drupal_json_encode ($ pattern ->schema );
85
87
$ starting_json = $ config !== NULL ? drupal_json_encode ($ config ->fields )
86
88
: $ config ;
87
89
// @todo Move to own JS file & Drupal Settings config var.
88
90
$ markup = <<<HTML
89
91
<div id="magic-pixie-dust"></div>
90
92
<script type="text/javascript">
91
- let target = document.getElementById("magic-pixie-dust");
92
- let shadow = target.attachShadow({mode: 'open'});
93
+ var target = document.getElementById("magic-pixie-dust");
94
+ var shadow = target.attachShadow({mode: 'open'});
93
95
94
96
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
97
@@ -105,14 +107,79 @@ public function getEditor($subtype = NULL,
105
107
JSONEditor.defaults.options.startval = data.starting;
106
108
}
107
109
110
+ // Override how references are resolved.
111
+ JSONEditor.base_url = '// $ hostname/'
112
+ JSONEditor.prototype._loadExternalRefs = function(schema, callback) {
113
+ var self = this;
114
+ var refs = this._getExternalRefs(schema);
115
+
116
+ var done = 0, waiting = 0, callback_fired = false;
117
+
118
+ $ each(refs,function(url) {
119
+ if(self.refs[url]) return;
120
+ if(!self.options.ajax) throw "Must set ajax option to true to load external ref "+url;
121
+ self.refs[url] = 'loading';
122
+ waiting++;
123
+
124
+ var r = new XMLHttpRequest();
125
+
126
+ var replacement = this.base_url + 'patternkit/ajax/webrh/$1/schema$2'
127
+ var uri = url.replace(/(\w+)\.json(#.*)/, replacement);
128
+
129
+ r.open("GET", uri, true);
130
+ r.onreadystatechange = function () {
131
+ if (r.readyState != 4) return;
132
+ // Request succeeded
133
+ if(r.status === 200) {
134
+ var response;
135
+ try {
136
+ response = JSON.parse(r.responseText);
137
+ }
138
+ catch(e) {
139
+ window.console.log(e);
140
+ throw "Failed to parse external ref "+url;
141
+ }
142
+ if(!response || typeof response !== "object") throw "External ref does not contain a valid schema - "+url;
143
+
144
+ self.refs[url] = response;
145
+ self._loadExternalRefs(response,function() {
146
+ done++;
147
+ if(done >= waiting && !callback_fired) {
148
+ callback_fired = true;
149
+ callback();
150
+ }
151
+ });
152
+ }
153
+ // Request failed
154
+ else {
155
+ window.console.log(r);
156
+ throw "Failed to fetch ref via ajax- "+url;
157
+ }
158
+ };
159
+ r.send();
160
+ });
161
+
162
+ if(!waiting) {
163
+ callback();
164
+ }
165
+ }
166
+
167
+
108
168
// Initialize the editor with a JSON schema
109
169
var editor = new JSONEditor(
110
170
target.shadowRoot.getElementById('editor_holder'), {
111
171
schema: data.schema,
112
172
theme: 'bootstrap3',
113
173
iconlib: 'fontawesome4',
114
174
keep_oneof_values: false,
115
- ajax: true
175
+ disable_edit_json: true,
176
+ disable_collapse: true,
177
+ //disable_properties: true,
178
+ //no_additional_properties: true,
179
+ ajax: true,
180
+ refs: {
181
+ "config.json": "/sites/all/modules/custom/webrh/webrh/src/library/atoms/config/api/config.json"
182
+ }
116
183
}
117
184
);
118
185
JSONEditor.plugins.sceditor.emoticonsEnabled = false;
@@ -129,9 +196,6 @@ public function getEditor($subtype = NULL,
129
196
'#type ' => 'markup ' ,
130
197
'#markup ' => $ markup ,
131
198
'#attached ' => array (
132
- 'library ' => array (
133
- array ('system ' , 'ui ' ),
134
- ),
135
199
'js ' => array (
136
200
drupal_get_path ('module ' , 'patternkit ' ) . '/js/jsoneditor.js ' ,
137
201
),
@@ -180,7 +244,7 @@ protected function getRawMetadata() {
180
244
$ file_basename = $ file ->getBasename ('. ' . $ file_ext );
181
245
182
246
// Build an array of all the filenames of interest, keyed by name.
183
- $ components [$ file_basename ][$ file_ext ] = $ file_path ;
247
+ $ components [$ file_basename ][$ file_ext ] = " $ file_path/ $ file_basename . $ file_ext " ;
184
248
}
185
249
186
250
foreach ($ components as $ module_name => $ data ) {
0 commit comments