274
|
1 var isInProgress=0;
|
|
2
|
|
3 var MAX_DUMP_DEPTH = 10;
|
|
4 var mbsvg;
|
|
5
|
|
6
|
|
7
|
|
8 function dumpObj(obj, name, indent, depth) {
|
|
9 if (depth > MAX_DUMP_DEPTH) {
|
|
10 return indent + name + ": <Maximum Depth Reached>\n";
|
|
11 }
|
|
12 if (typeof obj == "object") {
|
|
13 var child = null;
|
|
14 var output = indent + name + "\n";
|
|
15 indent += "\t";
|
|
16 for (var item in obj)
|
|
17 {
|
|
18 try {
|
|
19 child = obj[item];
|
|
20 } catch (e) {
|
|
21 child = "<Unable to Evaluate>";
|
|
22 }
|
|
23 if (typeof child == "object") {
|
|
24 output += dumpObj(child, item, indent, depth + 1);
|
|
25 } else {
|
|
26 output += indent + item + ": " + child + "\n";
|
|
27 }
|
|
28 }
|
|
29 return output;
|
|
30 } else {
|
|
31 return obj;
|
|
32 }
|
|
33 }
|
|
34 function dumpObjItem(obj, name, indent, depth) {
|
|
35 if (depth > MAX_DUMP_DEPTH) {
|
|
36 return indent + name + ": <Maximum Depth Reached>\n";
|
|
37 }
|
|
38 if (typeof obj == "object") {
|
|
39 var child = null;
|
|
40 var output = indent + name + "\n";
|
|
41 indent += "\t";
|
|
42 for (var item in obj)
|
|
43 {
|
|
44 try {
|
|
45 child = obj[item];
|
|
46 } catch (e) {
|
|
47 child = "<Unable to Evaluate>";
|
|
48 }
|
|
49 if (typeof child == "object") {
|
|
50 output += dumpObjItem(child, item, indent, depth + 1);
|
|
51 } else {
|
|
52 output += indent + item + ":\n";
|
|
53 }
|
|
54 }
|
|
55 return output;
|
|
56 } else {
|
|
57 return obj;
|
|
58 }
|
|
59 }
|
|
60
|
|
61 function inkscape_load(file)
|
|
62 {
|
|
63 var inkscape = document.getElementById('inkscape');
|
|
64 inkscape.innerHTML = "<embed src="+file+" width=1000 height=800 />";
|
|
65 }
|
|
66
|
|
67 function MBSVG(file)
|
|
68 {
|
|
69 var xmlDoc=document.implementation.createDocument("http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd","",null);
|
|
70 xmlDoc.async=false;
|
|
71 xmlDoc.load(file);
|
|
72 MBSVG_loadFromDoc(this,xmlDoc);
|
|
73
|
|
74 }
|
|
75 function MBSVGString(xml)
|
|
76 {
|
|
77 var xmlParser = new DOMParser();
|
|
78 var xmlDoc = xmlParser.parseFromString( xml, 'text/xml');
|
|
79 MBSVG_loadFromDoc(this,xmlDoc);
|
|
80 }
|
|
81
|
|
82
|
|
83
|
|
84 function MBSVG_loadFromDoc(self,xmlDoc)
|
|
85 {
|
|
86 var scenesNode = xmlDoc.getElementsByTagNameNS("http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd","scene");
|
|
87 if (scenesNode == null) {
|
|
88 alert('This is not a valid scene file');
|
|
89 }
|
|
90 var len = scenesNode.length;
|
|
91 var i,j;
|
|
92 var max = 0;
|
|
93 var scenes = new Array();
|
|
94
|
|
95 // Get the length of scenes
|
|
96 for(i=0;i<len;i++) {
|
|
97 var s = scenesNode[i];
|
|
98 var start = s.getAttribute("start");
|
|
99 var end = s.getAttribute("end");
|
|
100 var ref = s.getAttribute("ref");
|
|
101 var ss = new Object();
|
|
102
|
|
103 if (end == null) end = start
|
|
104 if (max <end) max = end;
|
|
105 ss.node = s;
|
|
106 ss.start = start;
|
|
107 ss.end = end;
|
|
108 ss.ref = ref;
|
|
109 ss.layer = null;
|
|
110 scenes.push(ss);
|
|
111 }
|
|
112 if (max < 20) max = 20;
|
|
113 // Collect all layers
|
|
114 var nodes = xmlDoc.getElementsByTagNameNS("http://www.w3.org/2000/svg","svg")[0].childNodes;
|
|
115 var layers = new Array();
|
|
116 len = nodes.length;
|
|
117 for(i=0;i<len;i++) {
|
|
118 if (nodes[i].localName == 'g') {
|
|
119 var subnodes = nodes[i].childNodes;
|
|
120 for(j=0;j<subnodes.length;j++) {
|
|
121 if (subnodes[j].localName == 'g') {
|
|
122 for(var k=0;k<scenes.length;k++) {
|
|
123 if (scenes[k].ref == subnodes[j].getAttribute('id')) {
|
|
124 scenes[k].layer = nodes[i].getAttribute('id');
|
|
125 break;
|
|
126 }
|
|
127 }
|
|
128 }
|
|
129 }
|
|
130 layers.push(nodes[i]);
|
|
131 }
|
|
132 }
|
|
133 self.layers = layers;
|
|
134 self.scenes = scenes;
|
|
135 self.maxframe = max;
|
|
136 }
|
|
137
|
|
138 function renderUI(mbsvg)
|
|
139 {
|
|
140 var layers = mbsvg.layers;
|
|
141 var scenes = mbsvg.scenes;
|
|
142 var max = mbsvg.maxframe;
|
|
143 var cmd = "<table border=1>\n";
|
|
144 cmd = cmd + "<tr><td></td>";
|
|
145 for(var j=1;j<=max;j++)
|
|
146 cmd = cmd + "<td>"+j+"</td>";
|
|
147
|
|
148 for(var i=layers.length-1;i>=0;i--) {
|
|
149 var l = layers[i];
|
|
150 var id = l.getAttribute('id');
|
|
151 var label = l.getAttribute('inkscape:label');
|
|
152 cmd = cmd + "<tr><td>"+label+"</td>";
|
|
153 for(j=0;j<max;j++) {
|
|
154 var empty = 1;
|
|
155 var n = j +1;
|
|
156 var id_str = id+"#"+n
|
|
157 for(var k=0;k<scenes.length;k++) {
|
|
158 if (id != scenes[k].layer) continue;
|
|
159 if (n == scenes[k].start) {
|
|
160 cmd = cmd + "<td><img class='normal' src=start.png id='"+id_str+"' onClick='selectCell(this)' /></td>";
|
|
161 empty = 0;
|
|
162 break;
|
|
163 } else if ((n>scenes[k].start)&&(n <= scenes[k].end)) {
|
|
164 cmd = cmd + "<td><img class='normal' src=fill.png id='"+id_str+"' onClick='selectCell(this)' /></td>";
|
|
165 empty = 0;
|
|
166 break;
|
|
167 }
|
|
168 }
|
|
169 if (empty) {
|
|
170 cmd = cmd + "<td><img class='normal' src=empty.png id='"+id_str+"'onClick='selectCell(this)' /></td>";
|
|
171 }
|
|
172
|
|
173 }
|
|
174 cmd = cmd + "</tr>\n";
|
|
175 }
|
|
176 cmd = cmd + "</table>\n";
|
|
177 var frame = document.getElementById('frame');
|
|
178 frame.innerHTML=cmd;
|
|
179 }
|
|
180
|
|
181 function selectCell(obj)
|
|
182 {
|
|
183 var id = obj.getAttribute('id');
|
|
184 var layer,n;
|
|
185 var f = id.split('#');
|
|
186 layer=f[0];
|
|
187 n = f[1];
|
|
188 var img = obj.getAttribute('src');
|
|
189 var f = img.split('-');
|
|
190
|
|
191 if (f[0] == 'active')
|
|
192 return;
|
|
193 else {
|
|
194 obj.setAttribute('src', 'active-'+img);
|
|
195 }
|
|
196
|
|
197 if (last_select != null) {
|
|
198 f = last_select.getAttribute('src').split('-');
|
|
199 last_select.setAttribute('src', f[1]);
|
|
200 }
|
|
201 last_select = obj;
|
|
202 currentScene = n;
|
|
203 currentLayer = layer;
|
|
204 }
|
|
205
|
|
206
|
|
207 function onButtonClick(obj)
|
|
208 {
|
|
209 if (isInProgress != 0) return;
|
|
210 var id = obj.getAttribute('id');
|
|
211 if (id == 'Jump') {
|
|
212 if (currentScene != 0)
|
|
213 gotoScene(currentScene);
|
|
214 } else if (id == 'InsertKey') {
|
|
215 InsertKey(currentScene);
|
|
216 } else if (id == 'ExtendScene') {
|
|
217 ExtendScene(currentScene);
|
|
218 } else if (id == 'DeleteScene') {
|
|
219 DeleteScene(currentScene);
|
275
|
220 } else {
|
|
221 alert(id+' has not been implemented yet');
|
274
|
222 }
|
|
223 }
|
|
224
|
|
225 function gotoScene_cb(resObj)
|
|
226 {
|
|
227
|
|
228 }
|
|
229 var nextScene;
|
|
230 var currentScene = 0;
|
|
231 var currentLayer = '';
|
|
232 function gotoScene(n)
|
|
233 {
|
|
234 nextScene = n;
|
|
235 var soapBody = new SOAPObject("START");
|
|
236 var sr = new SOAPRequest("START", soapBody);
|
|
237 SOAPClient.Proxy = "http://localhost:19192/";
|
|
238 SOAPClient.SendRequest(sr, gotoScene1);
|
|
239 isInProgress++;
|
|
240 }
|
|
241 function gotoScene1(resp,n)
|
|
242 {
|
|
243 var soapBody = new SOAPObject("SCENE");
|
|
244 var v1 = new SOAPObject("v1");
|
|
245 v1.val(nextScene);
|
|
246 soapBody.appendChild(v1);
|
|
247 var sr = new SOAPRequest("SCENE", soapBody);
|
|
248 SOAPClient.Proxy = "http://localhost:19192/";
|
|
249 SOAPClient.SendRequest(sr, gotoScene2);
|
|
250 }
|
|
251 function gotoScene2(resp)
|
|
252 {
|
|
253 var soapBody = new SOAPObject("PUBLISH");
|
|
254 var sr = new SOAPRequest("PUBLISH", soapBody);
|
|
255 SOAPClient.Proxy = "http://localhost:19192/";
|
|
256 SOAPClient.SendRequest(sr, gotoScene3);
|
|
257 }
|
|
258
|
|
259 function gotoScene3(resp)
|
|
260 {
|
|
261 isInProgress--;
|
|
262 }
|
|
263
|
|
264
|
|
265
|
|
266 function InsertKey(n)
|
|
267 {
|
|
268 nextScene = n;
|
|
269 var soapBody = new SOAPObject("START");
|
|
270 var sr = new SOAPRequest("START", soapBody);
|
|
271 SOAPClient.Proxy = "http://localhost:19192/";
|
|
272 SOAPClient.SendRequest(sr, InsertKey1);
|
|
273 isInProgress++;
|
|
274 }
|
|
275 function InsertKey1(resp)
|
|
276 {
|
|
277 var soapBody = new SOAPObject("INSERTKEY");
|
|
278 var v1 = new SOAPObject("v1");
|
|
279 v1.attr('type','string');
|
|
280 v1.val(currentLayer);
|
|
281 soapBody.appendChild(v1);
|
|
282 var v2 = new SOAPObject("v2");
|
|
283 v2.val(nextScene);
|
|
284 soapBody.appendChild(v2);
|
|
285 var sr = new SOAPRequest("INSERTKEY", soapBody);
|
|
286 SOAPClient.Proxy = "http://localhost:19192/";
|
|
287 SOAPClient.SendRequest(sr, RefreshDocument);
|
|
288 }
|
|
289 function PublishDocument(resp)
|
|
290 {
|
|
291 mbsvg = new MBSVGString(resp.Body[0].GETDOCResponse[0].Result[0].Text);
|
|
292 renderUI(mbsvg);
|
|
293
|
|
294 var soapBody = new SOAPObject("PUBLISH");
|
|
295 var sr = new SOAPRequest("PUBLISH", soapBody);
|
|
296 SOAPClient.Proxy = "http://localhost:19192/";
|
|
297 SOAPClient.SendRequest(sr, OperationDone);
|
|
298 }
|
|
299
|
|
300 function RefreshDocument(resp)
|
|
301 {
|
|
302 var soapBody = new SOAPObject("GETDOC");
|
|
303 var sr = new SOAPRequest("GETDOC", soapBody);
|
|
304 SOAPClient.Proxy = "http://localhost:19192/";
|
|
305 SOAPClient.SendRequest(sr, PublishDocument);
|
|
306 }
|
|
307
|
|
308 function OperationDone(res)
|
|
309 {
|
|
310 isInProgress--;
|
|
311 }
|
|
312
|
|
313
|
|
314 function ExtendScene()
|
|
315 {
|
|
316 var soapBody = new SOAPObject("START");
|
|
317 var sr = new SOAPRequest("START", soapBody);
|
|
318 SOAPClient.Proxy = "http://localhost:19192/";
|
|
319 SOAPClient.SendRequest(sr,ExtendScene1);
|
|
320 isInProgress++;
|
|
321 }
|
|
322
|
|
323
|
|
324 function ExtendScene1(resp)
|
|
325 {
|
|
326 var soapBody = new SOAPObject("EXTENDSCENE");
|
|
327 var v1 = new SOAPObject("v1");
|
|
328 v1.attr('type','string');
|
|
329 v1.val(currentLayer);
|
|
330 soapBody.appendChild(v1);
|
|
331 var v2 = new SOAPObject("v2");
|
|
332 v2.val(currentScene);
|
|
333 soapBody.appendChild(v2);
|
|
334 var sr = new SOAPRequest("EXTENDSCENE", soapBody);
|
|
335 SOAPClient.Proxy = "http://localhost:19192/";
|
|
336 SOAPClient.SendRequest(sr, RefreshDocument);
|
|
337 }
|
|
338
|
|
339
|
|
340 function DeleteScene()
|
|
341 {
|
|
342 var soapBody = new SOAPObject("START");
|
|
343 var sr = new SOAPRequest("START", soapBody);
|
|
344 SOAPClient.Proxy = "http://localhost:19192/";
|
|
345 SOAPClient.SendRequest(sr,DeleteScene1);
|
|
346 isInProgress++;
|
|
347 }
|
|
348
|
|
349 function DeleteScene1(resp)
|
|
350 {
|
|
351 var soapBody = new SOAPObject("DELETESCENE");
|
|
352 var v1 = new SOAPObject("v1");
|
|
353 v1.attr('type','string');
|
|
354 v1.val(currentLayer);
|
|
355 soapBody.appendChild(v1);
|
|
356 var v2 = new SOAPObject("v2");
|
|
357 v2.val(currentScene);
|
|
358 soapBody.appendChild(v2);
|
|
359 var sr = new SOAPRequest("EXTENDSCENE", soapBody);
|
|
360 SOAPClient.Proxy = "http://localhost:19192/";
|
|
361 SOAPClient.SendRequest(sr, RefreshDocument);
|
|
362
|
|
363 }
|
|
364
|
|
365 function FetchDocument()
|
|
366 {
|
|
367 var soapBody = new SOAPObject("START");
|
|
368 var sr = new SOAPRequest("START", soapBody);
|
|
369 SOAPClient.Proxy = "http://localhost:19192/";
|
|
370 SOAPClient.SendRequest(sr,RefreshDocument);
|
|
371 isInProgress++;
|
|
372 }
|
|
373
|
|
374 var last_select = null;
|
|
375 inkscape_load("scene.mbsvg");
|
|
376 setTimeout("FetchDocument()",4000);
|
|
377
|
|
378 $('a.button').mouseover(function () {
|
|
379 if (isInProgress==0)
|
|
380 this.style.MozOpacity = 0.1;
|
|
381 }).mouseout(function () {
|
|
382 this.style.MozOpacity= 1;
|
|
383 });
|
|
384
|