2 * Copyright 2013 Laurent Bovet <laurent.bovet@windmaster.ch>
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 var scripts = document.getElementsByTagName('script');
18 var script = scripts[ scripts.length - 1 ];
20 if (script.attributes["data-schema"]) {
22 if (script.attributes["data-docson"]) {
23 docson = script.attributes["data-docson"].value;
25 docson = script.src.replace("widget.js", "index.html");
27 document.write("<iframe id='" + script.attributes["data-schema"].value +
28 "' style='padding: 0; border: 0; width:100%; background: transparent' src='" +
30 script.attributes["data-schema"].value + "'></iframe>");
31 function receiveMessage(event) {
32 console.log("<", event)
33 if (event.data.id && event.data.id == "docson") {
34 var frame = document.getElementById(event.data.url);
35 if(event.data.action == "resized") {
36 frame.height = event.data.height + 18;
38 if(event.data.action == "ready") {
39 console.log(frame.parentNode)
40 frame.contentWindow.postMessage({ id: "docson", font: window.getComputedStyle(frame.parentNode).fontFamily}, "*");
45 window.addEventListener("message", receiveMessage, false);
47 alert("<p style='color:red'>Missing data-schema (url to schema)</p>")