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