1<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2<html xmlns="http://www.w3.org/1999/xhtml" style="height: 99%;"><head>
3  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4  <title>Project - CANopenNode</title>
5  <style type="text/css">
6    body{
7       background-color: rgb(165, 186, 221);
8       margin: 0px;
9       height: 100%;
10    }
11    table{
12      width: 100%;
13    }
14    td {
15      border: 1px solid black;
16      padding: 1px 0.6em 1px 0.3em;
17      width: 50%;
18    }
19    table div{
20      position: relative;
21      height: 2em;
22      margin-top: 0.3em;
23    }
24    table pre{
25      margin: 0px;
26    }
27    textarea{
28      width: 100%;
29      height: 10em;
30    }
31    .right{
32      position: absolute;
33      right: 0px;
34    }
35  </style>
36  <script type="text/javascript">
37    var editorWindowOK = false;
38
39    function loadProject(name){
40      var loc = getURLPath(name);
41      var req = new XMLHttpRequest();
42      req.open('GET', loc, false);
43      req.send(null);
44      document.getElementById('textXML').value = req.responseText;
45    }
46
47    function updateFields(){
48      var xmlText = document.getElementById("textXML");
49      var el = xmlText.value.substring(xmlText.value.indexOf("<file"));
50      var el = el.substring(0, el.indexOf("/>")+2);
51		var filename = ""
52		if(el.length){
53			var el = new XML(el);
54	      fileName = el.@fileName.toString();
55			document.title = fileName + " - CANopenNode";
56			var span = document.getElementById("title");
57			span.replaceChild(document.createTextNode(fileName), span.firstChild);
58
59	      var date = "V " + el.@fileVersion.toString() + "; Updated: " + el.@fileCreationDate.toString() + ", " +
60							el.@fileCreationTime.toString() + ", by " + el.@fileCreator.toString();
61	      span = document.getElementById("date");
62	      span.replaceChild(document.createTextNode(date), span.firstChild);
63		}
64
65      //for use with firefox addon "Save Text Area 0.4.5"
66      //https://addons.mozilla.org/en-US/firefox/addon/1046
67      updateFileName("textXML", "_project.xml");
68      updateFileName("textHTM", fileName+".html");
69      updateFileName("textODH", "CO_OD.h");
70      updateFileName("textODC", "CO_OD.c");
71      updateFileName("textEDS", fileName+".eds");
72      updateFileName("textXDD", fileName+".xdd");
73
74      document.getElementById("iframe").src = "";
75    }
76
77    function openEditor(newWindow){
78      var path = document.getElementById("locEditor").value;
79      var loc = getURLPath(path + "/device.xul");
80
81      if(newWindow){
82        editorWindow = window.open(loc, '_blank', 'left=0,top=150,width=1024,height=768,resizable=yes,scrollbars=yes,location=no,status=no');
83        editorWindow.focus();
84      }
85      else{
86        var iframe = document.getElementById("iframe");
87        iframe.src = loc;
88        editorWindow = iframe.contentWindow;
89      }
90
91      document.getElementById("textHTM").value = "-";
92      document.getElementById("textODH").value = "-";
93      document.getElementById("textODC").value = "-";
94      document.getElementById("textEDS").value = "-";
95      document.getElementById("textXDD").value = "-";
96
97      //verify if editor window is OK
98      editorWindowOK = false;
99      setTimeout(verifyEditorWindow, 10000);
100    }
101
102    function verifyEditorWindow(){
103      if(editorWindowOK == false)
104        alert("Error with Editor!\n(Wrong location)");
105    }
106
107    function openAbout(){
108      var path = document.getElementById("locEditor").value;
109      var loc = getURLPath(path + "/about.html");
110      var w = window.open(loc, 'About', 'left=0,top=150,height=600,width=800,resizable=yes,scrollbars=yes,location=yes,status=yes');
111      w.focus();
112    }
113
114    function receiveMessage(event){
115      //function receives a message from editor window, which is editing a project file. This event is triggered
116      //after editor sends some data. For more information see http://developer.mozilla.org/en/DOM/window.postMessage
117
118      //if (event.origin !== "http://example.com:8080") return; //for safety
119
120      var head = event.data.substring(0, 3);  //first three characters of the message
121      var body = event.data.substring(3);    //other text of the message
122
123      switch(head){
124        case "RDY":  //editor was loaded
125          editorWindow.postMessage(document.getElementById('textXML').value, '*');
126          document.getElementById("fileBoxes").style.display = "none";
127          document.getElementById("iframe").style.height = "100%";
128          editorWindowOK = true;
129          break;
130        case "CLS":  //editor was closed
131          document.getElementById("iframe").style.height = "0px";
132          document.getElementById("fileBoxes").style.display = "block";
133          break;
134        case "XML":  //xml contents was sent
135          var tb = document.getElementById("textXML");
136          tb.value = body;
137          //tb.setAttribute("value", body); //faster code
138          updateFields();
139          break;
140        case "HTM":  //html contents was sent
141          var tb = document.getElementById("textHTM");
142          tb.value = body;
143          //tb.setAttribute("value", body); //faster code
144          break;
145        case "ODH":  //CO_OD.h contents was sent
146          var tb = document.getElementById("textODH");
147          tb.value = body;
148          //tb.setAttribute("value", body); //faster code
149          break;
150        case "ODC":  //CO_OD.c contents was sent
151          var tb = document.getElementById("textODC");
152          tb.value = body;
153          //tb.setAttribute("value", body); //faster code
154          break;
155        case "EDS":  //EDS contents was sent
156          var tb = document.getElementById("textEDS");
157          tb.value = body;
158          //tb.setAttribute("value", body); //faster code
159          break;
160        case "XDD":  //XDD contents was sent
161          var tb = document.getElementById("textXDD");
162          tb.value = body;
163          //tb.setAttribute("value", body); //faster code
164          break;
165        default: alert("Message command was not recognized: " + head);
166      }
167    }
168    window.addEventListener("message", receiveMessage, false);
169
170    function viewFile(value, pre){
171      var w = window.open("", '_blank', 'left=0,top=150,width=1024,height=768,resizable=yes,scrollbars=yes,location=yes,status=yes,menubar=yes');
172      w.document.open();
173      if(pre){
174        value = value.replace(/&/g, "&amp;");
175        value = value.replace(/</g, "&lt;");
176        value = value.replace(/>/g, "&gt;");
177        w.document.write("<pre>"+value+"</pre>");
178      }
179      else{
180        w.document.write(value);
181        //disable anchors
182        var anchors = w.document.getElementsByTagName("a");
183        for(var i = 0; i < anchors.length; i++){
184          anchors[i].removeAttribute("href");
185        }
186      }
187      w.document.close();
188    }
189
190    function getURLPath(path){
191      //Function returns absolute path based on input path. If input path is relative, it is relative to path of this html document.
192      //Input path can be one of the following (either '/' or '\' can be used):
193        //- http://www.example.com/example/example.html
194        //- file:///C:/example/example.html
195        //- C:/example/example.html
196        //- example/example.html
197        //- /example/example.html
198        //- ../example/example.html
199      var absloutePath;
200      path = path.replace(/\\/g,"/");
201      var i = path.indexOf(":");
202      if(i >= 0){
203        absloutePath = path;
204        if(i == 1) absloutePath = "file:///" + absloutePath;
205      }
206      else{
207        absloutePath = location.href;
208        absloutePath = absloutePath.substring(0, absloutePath.lastIndexOf("/"));
209        while(path.substring(0, 3) == "../"){
210          path = path.substring(3);
211          absloutePath = absloutePath.substring(0, absloutePath.lastIndexOf("/"));
212        }
213        var hash = "/";
214        if(path.charAt(0) == "/") hash = "";
215        absloutePath = absloutePath + hash + path;
216      }
217      return absloutePath;
218    }
219
220    function getLocalPath(path){
221      //Function returns absolute path based on input path. If input path is relative, it is relative to path of this html document.
222      //Input path can be one of the following (either '/' or '\' can be used):
223        //- C:\example\example.html
224        //- example\example.html
225        //- \example\example.html
226        //- ..\example\example.html
227      path = path.replace(/\//g,"\\");
228      if(path.indexOf(":") >= 0) return path;
229
230      var absloutePath = location.href;
231      if(absloutePath.substring(0, 8) != "file:///") return "";
232      absloutePath = absloutePath.substring(8, absloutePath.lastIndexOf("/"));
233      absloutePath = absloutePath.replace(/\//g,"\\");
234      while(path.substring(0, 3) == "..\\"){
235        path = path.substring(3);
236        absloutePath = absloutePath.substring(0, absloutePath.lastIndexOf("\\"));
237      }
238      var hash = "\\";
239      if(path.charAt(0) == "\\") hash = "";
240      absloutePath = absloutePath + hash + path;
241      return absloutePath;
242    }
243
244    function updateFileName(field, name){
245      document.getElementById(field).setAttribute("fileName", name);
246    }
247  </script>
248</head><body onload="loadProject('_project.xml'); updateFields();">
249<div id="fileBoxes" style="margin: 8px; display: block;">
250<div style="padding: 0.5em;">
251  <span id="title" style="font-size: 1.5em; font-weight: bold;">---</span>
252  <span id="date" style="margin-left: 2em;">---</span>
253  <input style="margin-left: 2em; font-size: 1.3em;" value="Open Editor" onclick="openEditor(false);" type="button">
254  at location:
255  <input id="locEditor" value="../../../Object_Dictionary_Editor" onblur="this.setAttribute('value', this.value);" type="text">
256  <input class="right" style="right: 1em;" value="Help" onclick="openAbout();" type="button">
257</div>
258<table>
259  <tbody><tr>
260    <td>
261      <div>
262        <b>CANopenNode project file:</b>
263        <input class="right" value="View source" onclick="viewFile(document.getElementById('textXML').value, true);" type="button">
264      </div>
265      <pre><textarea id="textXML" fileName="_project.xml" wrap="off" onchange="updateFields();">-</textarea></pre>
266    </td>
267    <td>
268      <div>
269        <b>Documentation HTML file:</b>
270        <input value="Preview" onclick="viewFile(document.getElementById('textHTM').value, false);" type="button">
271        <input class="right" value="View source" onclick="viewFile(document.getElementById('textHTM').value, true);" type="button">
272      </div>
273      <textarea id="textHTM" fileName="documentation.html" wrap="off">-</textarea>
274    </td>
275  </tr><tr>
276    <td>
277      <div>
278        <b>Source code CO_OD.h file:</b>
279        <input class="right" value="View source" onclick="viewFile(document.getElementById('textODH').value, true);" type="button">
280      </div>
281      <textarea id="textODH" fileName="CO_OD.h" wrap="off">-</textarea>
282    </td>
283    <td>
284      <div>
285        <b>Source code CO_OD.c file:</b>
286        <input class="right" value="View source" onclick="viewFile(document.getElementById('textODC').value, true);" type="button">
287      </div>
288      <textarea id="textODC" fileName="CO_OD.c" wrap="off">-</textarea>
289    </td>
290  </tr>
291  <tr>
292    <td>
293      <div>
294        <b>EDS specification file:</b>
295        <input class="right" value="View source" onclick="viewFile(document.getElementById('textEDS').value, true);" type="button">
296      </div>
297      <textarea id="textEDS" fileName="Electronic data sheet.eds" wrap="off">-</textarea>
298    </td>
299    <td>
300      <div>
301        <b>Errors and warnings:</b>
302        <input class="right" value="View source" onclick="viewFile(document.getElementById('textXDD').value, true);" type="button">
303      </div>
304      <textarea id="textXDD" fileName="Electronic data sheet.xdd" wrap="off">-</textarea>
305    </td>
306  </tr>
307</tbody></table>
308<em style="text-align: center; display: block;"><a href="http://canopennode.sourceforge.net/">CANopenNode</a> Editor - project file.</em>
309</div>
310<iframe style="border: 0px none ; width: 100%; height: 0px;" src="" id="iframe"></iframe>
311</body></html>