~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/extensions/xmlterm/ui/content/XMLTermCommands.js

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// XMLTerm Page Commands
 
2
 
 
3
// CONVENTION: All pre-defined XMLTerm Javascript functions and global
 
4
//             variables should begin with an upper-case letter.
 
5
//             This would allow them to be easily distinguished from
 
6
//             user defined functions, which should begin with a lower case
 
7
//             letter.
 
8
 
 
9
// Global variables
 
10
///var gStyleRuleNames;
 
11
 
 
12
WRITE_LOG = function (str) {};
 
13
DEBUG_LOG = function (str) {};
 
14
 
 
15
if (navigator) {
 
16
   var userAgent = navigator.userAgent;
 
17
 
 
18
   if (userAgent && (userAgent.search(/Mozilla\/4\./i) == -1)) {
 
19
 
 
20
     if (dump) {
 
21
        WRITE_LOG = dump;
 
22
     }
 
23
  }
 
24
} else {
 
25
  if (dump) {
 
26
     WRITE_LOG = dump;
 
27
  }
 
28
}
 
29
 
 
30
var Tips = new Array();       // Usage tip strings
 
31
var TipNames = new Array();   // Usage tip names
 
32
var TipCount = 0;             // No. of tips
 
33
var SelectedTip = 0;          // Selected random tip
 
34
 
 
35
// Set prompt using form entry
 
36
function DefineTip(tip, name) {
 
37
  Tips[TipCount] = tip;
 
38
  TipNames[TipCount] = name;
 
39
  TipCount++;
 
40
  return;
 
41
}
 
42
 
 
43
DefineTip('Click the new tip link to the left to get a new tip!',
 
44
          'tips');
 
45
 
 
46
DefineTip('User level setting (at the top) controls amount of help information',
 
47
         'level');
 
48
 
 
49
DefineTip('Beginner level setting displays keyboard shortcuts at the top of the page',
 
50
         'level');
 
51
 
 
52
DefineTip('Icons setting controls whether directory listings use icons',
 
53
          'icons');
 
54
 
 
55
DefineTip('Windows setting controls whether double-clicking creates new windows',
 
56
          'windows');
 
57
 
 
58
DefineTip('Single click an explicit (underlined) hyperlink; double click implicit (usually blue) hyperlinks',
 
59
         'clicking');
 
60
 
 
61
DefineTip('Clicking on command prompt expands/collapses command output display.',
 
62
          'prompt');
 
63
 
 
64
DefineTip('Press F1 (or control-Home) key to collapse output of all commands.',
 
65
          'prompt');
 
66
 
 
67
DefineTip('"js:SetPrompt(HTMLstring);" sets prompt to any HTML string.',
 
68
          'prompt');
 
69
 
 
70
DefineTip('Beginners may click the SetPrompt button for a cool Mozilla prompt from dmoz.org!',
 
71
         'prompt');
 
72
 
 
73
DefineTip('Double-clicking on a previous command line re-executes the command.',
 
74
          'command');
 
75
 
 
76
DefineTip('Type "js:func(arg);" to execute inline Javascript function func.',
 
77
          'js');
 
78
 
 
79
DefineTip('Inline Javascript ("js:...") can be used to produce HTML output.',
 
80
          'js');
 
81
 
 
82
DefineTip('XMLterm supports full screen commands like "less", "vi", and "emacs -nw"".',
 
83
         'full-screen');
 
84
 
 
85
DefineTip('"xls" produces a clickable listing of directory contents.',
 
86
          'xls');
 
87
 
 
88
DefineTip('"xls -t" prevents display of icons even if Icons setting is "on".',
 
89
          'xls');
 
90
 
 
91
DefineTip('"xcat text-file" displays a text file with clickable URLs.',
 
92
          'xcat');
 
93
 
 
94
DefineTip('"xcat image.gif" displays an image file inline!',
 
95
          'xcat');
 
96
 
 
97
DefineTip('"xcat http://mozilla.org" displays a web page inline using IFRAMEs.',
 
98
          'xcat');
 
99
 
 
100
DefineTip('"xcat -h 1000 http://mozilla.org" displays using an IFRAME 1000 pixels high.',
 
101
          'xcat');
 
102
 
 
103
DefineTip('"xcat doc.html" display an HTML document inline using IFRAMEs.',
 
104
          'xcat');
 
105
 
 
106
// Display random usage tip
 
107
// (should cease to operate after a few cycles;
 
108
// need to use Prefs to keep track of that)
 
109
function NewTip() {
 
110
  var ranval = Math.random();
 
111
  SelectedTip = Math.floor(ranval * TipCount);
 
112
  if (SelectedTip >= TipCount) SelectedTip = 0;
 
113
 
 
114
  DEBUG_LOG("xmlterm: NewTip "+SelectedTip+","+ranval+"\n");
 
115
 
 
116
  var tipdata = document.getElementById('tipdata');
 
117
  tipdata.firstChild.data = Tips[SelectedTip];
 
118
 
 
119
  ShowHelp("",0);
 
120
 
 
121
  return false;
 
122
}
 
123
 
 
124
// Explain tip
 
125
function ExplainTip(tipName) {
 
126
  DEBUG_LOG("xmlterm: ExplainTip("+tipName+")\n");
 
127
 
 
128
  if (tipName) {
 
129
    var tipdata = document.getElementById('tipdata');
 
130
    tipdata.firstChild.data = "";
 
131
  } else {
 
132
    tipName = TipNames[SelectedTip];
 
133
  }
 
134
 
 
135
  ShowHelp('xmltermTips.html#'+tipName,0,120);
 
136
 
 
137
  return false;
 
138
}
 
139
 
 
140
// F1 key - Hide all output
 
141
function F1Key(isShift, isControl) {
 
142
  return DisplayAllOutput(false);
 
143
}
 
144
 
 
145
// F2 key - Show all output
 
146
function F2Key(isShift, isControl) {
 
147
  return DisplayAllOutput(true);
 
148
}
 
149
 
 
150
// F7 - Explain tip
 
151
function F7Key(isShift, isControl) {
 
152
  return ExplainTip();
 
153
}
 
154
 
 
155
// F8 - New tip
 
156
function F8Key(isShift, isControl) {
 
157
  return NewTip();
 
158
}
 
159
 
 
160
// F9 key
 
161
function F9Key(isShift, isControl) {
 
162
  return NewXMLTerm('');
 
163
}
 
164
 
 
165
// Scroll Home key
 
166
function ScrollHomeKey(isShift, isControl) {
 
167
  DEBUG_LOG("ScrollHomeKey("+isShift+","+isControl+")\n");
 
168
 
 
169
  if (isControl) {
 
170
    return F1Key(isShift, 0);
 
171
  } else {
 
172
    ScrollWin(isShift,isControl).scroll(0,0);
 
173
    return false;
 
174
  }
 
175
}
 
176
 
 
177
// Scroll End key
 
178
function ScrollEndKey(isShift, isControl) {
 
179
  DEBUG_LOG("ScrollEndKey("+isShift+","+isControl+")\n");
 
180
 
 
181
  if (isControl) {
 
182
    return F2Key(isShift, 0);
 
183
  } else {
 
184
    ScrollWin(isShift,isControl).scroll(0,99999);
 
185
    return false;
 
186
  }
 
187
}
 
188
 
 
189
// Scroll PageUp key
 
190
function ScrollPageUpKey(isShift, isControl) {
 
191
  DEBUG_LOG("ScrollPageUpKey("+isShift+","+isControl+")\n");
 
192
 
 
193
  ScrollWin(isShift,isControl).scrollBy(0,-120);
 
194
  return false;
 
195
}
 
196
 
 
197
// Scroll PageDown key
 
198
function ScrollPageDownKey(isShift, isControl) {
 
199
  DEBUG_LOG("ScrollPageDownKey("+isShift+","+isControl+")\n");
 
200
 
 
201
  ScrollWin(isShift,isControl).scrollBy(0,120);
 
202
  return false;
 
203
}
 
204
 
 
205
// Scroll Window
 
206
function ScrollWin(isShift, isControl) {
 
207
  if (isShift && (window.frames.length > 0)) {
 
208
    return window.frames[window.frames.length-1];
 
209
  } else {
 
210
    return window;
 
211
  }
 
212
}
 
213
 
 
214
// Set history buffer size
 
215
function SetHistory(value) {
 
216
  DEBUG_LOG("SetHistory("+value+")\n");
 
217
  window.xmlterm.setHistory(value, document.cookie);
 
218
  return false;
 
219
}
 
220
 
 
221
// Set prompt
 
222
function SetPrompt(value) {
 
223
  DEBUG_LOG("SetPrompt("+value+")\n");
 
224
  window.xmlterm.setPrompt(value, document.cookie);
 
225
  return false;
 
226
}
 
227
 
 
228
// Create new XMLTerm window
 
229
function NewXMLTerm(firstcommand) {
 
230
  newwin = window.openDialog( "chrome://xmlterm/content/xmlterm.xul",
 
231
                              "xmlterm", "chrome,dialog=no,resizable",
 
232
                              firstcommand);
 
233
  WRITE_LOG("NewXMLTerm: "+newwin+"\n")
 
234
  return false;
 
235
}
 
236
 
 
237
// Handle resize events
 
238
function Resize(event) {
 
239
  DEBUG_LOG("Resize()\n");
 
240
  window.xmlterm.resize();
 
241
  return false;
 
242
}
 
243
 
 
244
// Form Focus (workaround for form input being transmitted to xmlterm)
 
245
function FormFocus() {
 
246
  DEBUG_LOG("FormFocus()\n");
 
247
  window.xmlterm.ignoreKeyPress(true, document.cookie);
 
248
  return false;
 
249
}
 
250
 
 
251
// Form Blur (workaround for form input being transmitted to xmlterm)
 
252
function FormBlur() {
 
253
  DEBUG_LOG("FormBlur()\n");
 
254
  window.xmlterm.ignoreKeyPress(false, document.cookie);
 
255
  return false;
 
256
}
 
257
 
 
258
// Set user level, icons mode etc.
 
259
function UpdateSettings(selectName) {
 
260
 
 
261
   DEBUG_LOG("UpdateSettings: "+selectName+"\n");
 
262
 
 
263
   var selectedIndex = document.xmltform1[selectName].selectedIndex;
 
264
   var selectedOption = document.xmltform1[selectName].options[selectedIndex].value;
 
265
 
 
266
   DEBUG_LOG("UpdateSettings: selectedOption=="+selectedOption+"\n");
 
267
 
 
268
   switch(selectName) {
 
269
      case "userLevel":
 
270
         // Change user level
 
271
 
 
272
         if (selectedOption == "advanced") {
 
273
           AlterStyle("DIV.beginner",     "display", "none");
 
274
           AlterStyle("DIV.intermediate", "display", "none");
 
275
      
 
276
         } else if (selectedOption == "intermediate") {
 
277
           AlterStyle("DIV.intermediate", "display", "block");
 
278
           AlterStyle("DIV.beginner",     "display", "none");
 
279
      
 
280
         } else {
 
281
           AlterStyle("DIV.beginner",     "display", "block");
 
282
           AlterStyle("DIV.intermediate", "display", "block");
 
283
         }
 
284
      break;
 
285
 
 
286
      case "showIcons":
 
287
         // Change icon display style in the style sheet
 
288
 
 
289
         if (selectedOption == "on") {
 
290
            AlterStyle("SPAN.noicons", "display", "none");
 
291
            AlterStyle("SPAN.icons",   "display", "inline");
 
292
            AlterStyle("IMG.icons",    "display", "inline");
 
293
            AlterStyle("TR.icons",     "display", "table-row");
 
294
 
 
295
         } else {
 
296
            AlterStyle("SPAN.noicons", "display", "inline");
 
297
            AlterStyle("SPAN.icons",   "display", "none");
 
298
            AlterStyle("IMG.icons",    "display", "none");
 
299
            AlterStyle("TR.icons",     "display", "none");
 
300
         }
 
301
      break;
 
302
 
 
303
      case "windowsMode":
 
304
         break;
 
305
 
 
306
      default:
 
307
         DEBUG_LOG("UpdateSettings: Unknown selectName "+selectName+"\n");
 
308
         break;
 
309
   }
 
310
 
 
311
   window.xmltform1Index[selectName] = selectedIndex;
 
312
   window.xmltform1Option[selectName] = selectedOption;
 
313
 
 
314
   Webcast();
 
315
 
 
316
   return false;
 
317
}
 
318
 
 
319
// Alter style in stylesheet of specified document doc, or current document
 
320
// if doc is omitted.
 
321
function AlterStyle(ruleName, propertyName, propertyValue, doc) {
 
322
 
 
323
  DEBUG_LOG("AlterStyle("+ruleName+"{"+propertyName+":"+propertyValue+"})\n");
 
324
 
 
325
  if (!doc) doc = window.document;
 
326
 
 
327
  var sheet = doc.styleSheets[0];
 
328
  var r;
 
329
  for (r = 0; r < sheet.cssRules.length; r++) {
 
330
    DEBUG_LOG("selectorText["+r+"]="+sheet.cssRules[r].selectorText+"\n");
 
331
 
 
332
    if (sheet.cssRules[r].selectorText.toLowerCase() == ruleName.toLowerCase()) {
 
333
 
 
334
    // Ugly workaround for accessing rules until bug 53448 is fixed
 
335
    // (****CSS DOM IS BROKEN****; selectorText seems to be null for all rules)
 
336
    ///if (gStyleRuleNames[r] == ruleName) {
 
337
 
 
338
      DEBUG_LOG("cssText["+r+"]="+sheet.cssRules[r].cssText+"\n");
 
339
      var style = sheet.cssRules[r].style;
 
340
      DEBUG_LOG("style="+style.getPropertyValue(propertyName)+"\n");
 
341
 
 
342
      style.setProperty(propertyName,propertyValue,"");
 
343
    }
 
344
  }
 
345
  return false;
 
346
}
 
347
 
 
348
// Handle default meta command
 
349
function MetaDefault(arg1) {
 
350
  return Load("http://"+arg1);
 
351
}
 
352
 
 
353
// Load URL in XMLTermBrowser window
 
354
function Load(url) {
 
355
  DEBUG_LOG("Load:url="+url+"\n");
 
356
  window.open(url);
 
357
 
 
358
  return false;
 
359
}
 
360
 
 
361
// Control display of all output elements
 
362
function DisplayAllOutput(flag) {
 
363
  var outputElements = document.getElementsByName("output");
 
364
  for (i=0; i<outputElements.length-1; i++) {
 
365
    var outputElement = outputElements[i];
 
366
    ///outputElement.style.display = (flag) ? "block" : "none";
 
367
 
 
368
    if (flag) 
 
369
       outputElement.removeAttribute('xmlt-block-collapsed');
 
370
    else
 
371
       outputElement.setAttribute('xmlt-block-collapsed', 'true');
 
372
  }
 
373
 
 
374
  var promptElements = document.getElementsByName("prompt");
 
375
  for (i=0; i<promptElements.length-1; i++) {
 
376
    promptElement = promptElements[i];
 
377
    ///promptElement.style.setProperty("text-decoration",
 
378
    ///                                 (flag) ? "none" : "underline", "");
 
379
 
 
380
    if (flag) 
 
381
       promptElement.removeAttribute('xmlt-underline');
 
382
    else
 
383
       promptElement.setAttribute('xmlt-underline', 'true');
 
384
  }
 
385
 
 
386
  if (!flag) {
 
387
    ScrollHomeKey(0,0);
 
388
//    ScrollEndKey(0,0);
 
389
  }
 
390
 
 
391
  Webcast();
 
392
 
 
393
  return false;
 
394
}
 
395
 
 
396
// Centralized event handler
 
397
// eventType values:
 
398
//   click
 
399
//
 
400
// targetType: 
 
401
//   textlink  - hyperlink
 
402
//   prompt    - command prompt
 
403
//   command   - command line
 
404
//
 
405
//   (Following are inline or in new window depending upon window.xmltform1Option.windowsMode)
 
406
//   cdxls     - change directory and list contents   (doubleclick)
 
407
//   xcat      - display file                         (doubleclick)
 
408
//   exec      - execute file                         (doubleclick)
 
409
//
 
410
//   send      - transmit arg to LineTerm
 
411
//   sendln    - transmit arg+newline to LineTerm
 
412
//   createln  - transmit arg+newline as first command to new XMLTerm
 
413
//
 
414
// entryNumber: >=0 means process only if current entry
 
415
//              <0  means process anytime
 
416
//
 
417
// arg1:    relative pathname of file/directory
 
418
// arg2:    absolute pathname prefix (for use outside current entry;
 
419
//                      use relative pathname in current working directory)
 
420
//
 
421
function HandleEvent(eventObj, eventType, targetType, entryNumber,
 
422
                     arg1, arg2) {
 
423
  DEBUG_LOG("HandleEvent("+eventObj+","+eventType+","+targetType+","+entryNumber+","+arg1+","+arg2+")\n");
 
424
 
 
425
  // Entry independent targets
 
426
  if (targetType === "textlink") {
 
427
    // Single click opens hyperlink
 
428
    // Browser-style
 
429
    DEBUG_LOG("textlink = "+arg1+"\n");
 
430
    Load(arg1);
 
431
 
 
432
  } else if (targetType === "prompt") {
 
433
    // Single click on prompt expands/collapses command output
 
434
    var outputElement = document.getElementById("output"+entryNumber);
 
435
    var helpElement = document.getElementById("help"+entryNumber);
 
436
    var promptElement = document.getElementById("prompt"+entryNumber);
 
437
    DEBUG_LOG(promptElement.style.getPropertyValue("text-decoration"));
 
438
 
 
439
    var collapsed = outputElement.getAttribute('xmlt-block-collapsed');
 
440
 
 
441
    if (collapsed) {
 
442
    ///if (outputElement.style.display == "none") {
 
443
      ///outputElement.style.display = "block";
 
444
      ///promptElement.style.setProperty("text-decoration","none","");
 
445
 
 
446
      outputElement.removeAttribute('xmlt-block-collapsed');
 
447
      promptElement.removeAttribute('xmlt-underline');
 
448
 
 
449
    } else {
 
450
      ///outputElement.style.display = "none";
 
451
      ///promptElement.style.setProperty("text-decoration","underline","");
 
452
 
 
453
      outputElement.setAttribute('xmlt-block-collapsed', 'true');
 
454
      promptElement.setAttribute('xmlt-underline', 'true');
 
455
      if (helpElement) {
 
456
        ShowHelp("",entryNumber);
 
457
      }
 
458
    }
 
459
 
 
460
  } else if (eventType === "click") {
 
461
 
 
462
     DEBUG_LOG("clickCount="+eventObj.detail+"\n");
 
463
 
 
464
     var shiftClick = eventObj.shiftKey;
 
465
     var dblClick = (eventObj.detail == 2);
 
466
 
 
467
     // Execute shell commands only on double-click for safety
 
468
     // Use single click for "selection" and prompt expansion only
 
469
     // Windows-style
 
470
 
 
471
     var currentEntryNumber = window.xmlterm.currentEntryNumber;
 
472
 
 
473
     var currentCmdElement = document.getElementById("command"+currentEntryNumber);
 
474
     var currentCommandEmpty = true;
 
475
     if (currentCmdElement && currentCmdElement.hasChildNodes()) {
 
476
 
 
477
       if (currentCmdElement.firstChild.nodeType == Node.TEXT_NODE) {
 
478
         DEBUG_LOG("textLength = "+currentCmdElement.firstChild.data.length+"\n");
 
479
         currentCommandEmpty = (currentCmdElement.firstChild.data.length == 0);
 
480
 
 
481
       } else {
 
482
         currentCommandEmpty = false;
 
483
       }
 
484
     }
 
485
     DEBUG_LOG("empty = "+currentCommandEmpty+"\n");
 
486
 
 
487
     if (targetType === "command") {
 
488
       if (!dblClick)
 
489
         return false;
 
490
       var commandElement = document.getElementById(targetType+entryNumber);
 
491
       var command = commandElement.firstChild.data;
 
492
       if (currentCommandEmpty) {
 
493
         window.xmlterm.sendText("\025"+command+"\n", document.cookie);
 
494
       } else {
 
495
         window.xmlterm.sendText(command, document.cookie);
 
496
       }
 
497
 
 
498
     } else {
 
499
       // Targets which may be qualified only for current entry
 
500
 
 
501
       if ((entryNumber >= 0) &&
 
502
         (window.xmlterm.currentEntryNumber != entryNumber)) {
 
503
         DEBUG_LOG("NOT CURRENT COMMAND\n");
 
504
         return false;
 
505
       }
 
506
 
 
507
       var action, sendStr;
 
508
 
 
509
       if ( (targetType === "cdxls") ||
 
510
            (targetType === "xcat")  ||
 
511
            (targetType === "exec")    ) {
 
512
         // Complex commands
 
513
 
 
514
         if (!dblClick)
 
515
           return false;
 
516
 
 
517
         var filename;
 
518
         var isCurrentCommand = (Math.abs(entryNumber)+1 ==
 
519
                                 window.xmlterm.currentEntryNumber);
 
520
 
 
521
         if ( (arg2 != null) && 
 
522
              (!isCurrentCommand || (window.xmltform1Option.windowsMode === "on")) ) {
 
523
           // Full pathname
 
524
           filename = arg2+arg1;
 
525
         } else {
 
526
           // Short pathname
 
527
           filename = arg1;
 
528
           if (targetType === "exec")
 
529
             filename = "./"+filename;
 
530
         }
 
531
 
 
532
         var prefix, suffix;
 
533
         if (targetType === "cdxls") {
 
534
           // Change directory and list contents
 
535
           prefix = "cd ";
 
536
           suffix = "; xls";
 
537
         } else if (targetType === "xcat") {
 
538
           // Display file
 
539
           prefix = "xcat ";
 
540
           suffix = "";
 
541
         } else if (targetType === "exec") {
 
542
           // Execute file
 
543
           prefix = "";
 
544
           suffix = "";
 
545
         }
 
546
 
 
547
         if (shiftClick || (window.xmltform1Option.windowsMode === "on")) {
 
548
           action = "createln";
 
549
           sendStr = prefix + filename + suffix;
 
550
 
 
551
         } else if (currentCommandEmpty) {
 
552
           action = "sendln";
 
553
           sendStr = prefix + filename + suffix;
 
554
 
 
555
         } else {
 
556
           action = "send";
 
557
           sendStr = filename + " ";
 
558
         }
 
559
 
 
560
       } else {
 
561
         // Primitive action
 
562
         action = targetType;
 
563
         sendStr = arg1;
 
564
       }
 
565
 
 
566
       // Primitive actions
 
567
       if (action === "send") {
 
568
         DEBUG_LOG("send = "+sendStr+"\n");
 
569
         window.xmlterm.sendText(sendStr, document.cookie);
 
570
 
 
571
       } else if (action === "sendln") {
 
572
         DEBUG_LOG("sendln = "+sendStr+"\n\n");
 
573
         window.xmlterm.sendText("\025"+sendStr+"\n", document.cookie);
 
574
 
 
575
       } else if (action === "createln") {
 
576
         DEBUG_LOG("createln = "+sendStr+"\n\n");
 
577
         newwin = NewXMLTerm(sendStr+"\n");
 
578
       }
 
579
    }
 
580
  }
 
581
 
 
582
  Webcast();
 
583
 
 
584
  return false;
 
585
}
 
586
 
 
587
// Set history buffer count using form entry
 
588
function SetHistoryValue() {
 
589
  var field = document.getElementById('inputvalue');
 
590
  return SetHistory(field.value);
 
591
}
 
592
 
 
593
// Set prompt using form entry
 
594
function SetPromptValue() {
 
595
  var field = document.getElementById('inputvalue');
 
596
  return SetPrompt(field.value);
 
597
}
 
598
 
 
599
function Webcast() {
 
600
  if (!window.webcastIntervalId)
 
601
    return;
 
602
 
 
603
  DEBUG_LOG("XMLTermCommands.js: Webcast: "+window.webcastFile+"\n");
 
604
 
 
605
  var style = "";
 
606
 
 
607
  if (window.xmltform1Option.showIcons == "on") {
 
608
     style += "SPAN.noicons {display: none}\n";
 
609
     style += "SPAN.icons   {display: inline}\n";
 
610
     style += "IMG.icons    {display: inline}\n";
 
611
     style += "TR.icons     {display: table-row}\n";
 
612
  }
 
613
 
 
614
  var exported = window.xmlterm.exportHTML(window.webcastFile, 0644, style,
 
615
                                           0, false, document.cookie);
 
616
  DEBUG_LOG("XMLTermCommands.js: exported="+exported+"\n");
 
617
}
 
618
 
 
619
function InitiateWebcast() {
 
620
  var field = document.getElementById('inputvalue');
 
621
 
 
622
  window.webcastFile = field.value ? field.value : "";
 
623
  window.webcastFile = "/var/www/html/users/xmlt.html";
 
624
 
 
625
  WRITE_LOG("XMLTermCommands.js: InitiateWebcast: "+window.webcastFile+"\n");
 
626
 
 
627
  Webcast();
 
628
  window.webcastIntervalId = window.setInterval(Webcast, 2000);
 
629
}
 
630
 
 
631
function TerminateWebcast() {
 
632
  window.webcastFile = null;
 
633
 
 
634
  if (window.webcastIntervalId) {
 
635
      window.clearInterval(window.webcastIntervalId);
 
636
      window.webcastIntervalId = null;
 
637
  }
 
638
}
 
639
 
 
640
function ToggleWebcast() {
 
641
  if (window.webcastIntervalId)
 
642
    TerminateWebcast();
 
643
  else
 
644
    InitiateWebcast();
 
645
}
 
646
 
 
647
// Insert help element displaying URL in an IFRAME before output element
 
648
// of entryNumber, or before the SESSION element if entryNumber is zero.
 
649
// Height is the height of the IFRAME in pixels.
 
650
// If URL is the null string, simply delete the help element
 
651
 
 
652
function ShowHelp(url, entryNumber, height) {
 
653
 
 
654
  if (!height) height = 120;
 
655
 
 
656
  DEBUG_LOG("xmlterm: ShowHelp("+url+","+entryNumber+","+height+")\n");
 
657
 
 
658
  if (entryNumber) {
 
659
    beforeID = "output"+entryNumber;
 
660
    helpID = "help"+entryNumber;
 
661
  } else {
 
662
    beforeID = "session";
 
663
    helpID = "help";
 
664
  }
 
665
 
 
666
  var beforeElement = document.getElementById(beforeID);
 
667
 
 
668
  if (!beforeElement) {
 
669
    DEBUG_LOG("InsertIFrame: beforeElement ID="+beforeID+"not found\n");
 
670
    return false;
 
671
  }
 
672
 
 
673
  var parentNode = beforeElement.parentNode;
 
674
 
 
675
  var helpElement = document.getElementById(helpID);
 
676
  if (helpElement) {
 
677
    // Delete help element
 
678
    parentNode.removeChild(helpElement);
 
679
    helpElement = null;
 
680
    // *NOTE* Need to flush display here to avoid black flash?
 
681
  }
 
682
 
 
683
  if (url.length > 0) {
 
684
    // Create new help element
 
685
    helpElement = document.createElement("div");
 
686
    helpElement.setAttribute('id', helpID);
 
687
    helpElement.setAttribute('class', 'help');
 
688
 
 
689
    var closeElement = document.createElement("span");
 
690
    closeElement.setAttribute('class', 'helplink');
 
691
    closeElement.appendChild(document.createTextNode("Close help frame"));
 
692
    closeElement.appendChild(document.createElement("p"));
 
693
 
 
694
    var iframe = document.createElement("iframe");
 
695
    iframe.setAttribute('id', helpID+'frame');
 
696
    iframe.setAttribute('class', 'helpframe');
 
697
    iframe.setAttribute('width', '100%');
 
698
    iframe.setAttribute('height', height);
 
699
    iframe.setAttribute('frameborder', '0');
 
700
    iframe.setAttribute('src', url);
 
701
 
 
702
    helpElement.appendChild(iframe);
 
703
    helpElement.appendChild(closeElement);
 
704
 
 
705
    DEBUG_LOG(helpElement);
 
706
 
 
707
    // Insert help element
 
708
    parentNode.insertBefore(helpElement, beforeElement);
 
709
 
 
710
    // NOTE: Need to do this *after* node is inserted into document
 
711
    closeElement.setAttribute('onClick', 'return ShowHelp("",'+entryNumber
 
712
                                          +');');
 
713
  }
 
714
 
 
715
  return false;
 
716
}
 
717
 
 
718
// About XMLTerm
 
719
function AboutXMLTerm() {
 
720
  DEBUG_LOG("xmlterm: AboutXMLTerm\n");
 
721
 
 
722
  var tipdata = document.getElementById('tipdata');
 
723
  tipdata.firstChild.data = "";
 
724
 
 
725
  ShowHelp('xmltermAbout.html',0,120);
 
726
 
 
727
  return false;
 
728
}
 
729
 
 
730
function Redirect() {
 
731
   window.location = window.redirectURL;
 
732
}
 
733
 
 
734
 
 
735
function GetQueryParam(paramName) {
 
736
  var url = document.location.href;
 
737
 
 
738
  var paramExp = new RegExp("[?&]"+paramName+"=([^&]*)");
 
739
 
 
740
  var matches = url.match(paramExp);
 
741
 
 
742
  var paramVal = "";
 
743
  if (matches && (matches.length > 1)) {
 
744
     paramVal = matches[1];
 
745
  }
 
746
 
 
747
  return paramVal;
 
748
}
 
749
 
 
750
// onLoad event handler
 
751
function LoadHandler() {
 
752
  WRITE_LOG("xmlterm: LoadHandler ... "+window.xmlterm+"\n");
 
753
 
 
754
  // Ugly workaround for accessing rules in stylesheet until bug 53448 is fixed
 
755
  ///var sheet = document.styleSheets[0];
 
756
  //WRITE_LOG("sheet.cssRules.length="+sheet.cssRules.length+"\n");
 
757
 
 
758
  ///var styleElement = (document.getElementsByTagName("style"))[0];
 
759
  ///var styleText = styleElement.firstChild.data;
 
760
 
 
761
  ///gStyleRuleNames = styleText.match(/\b[\w-.]+(?=\s*\{)/g);
 
762
  //WRITE_LOG("gStyleRuleNames.length="+gStyleRuleNames.length+"\n");
 
763
 
 
764
  //NewTip();
 
765
 
 
766
  // Update settings
 
767
  window.xmltform1Index  = new Object();
 
768
  window.xmltform1Option = new Object();
 
769
 
 
770
  window.xmltform1Index.userLevel = 2;
 
771
  window.xmltform1Option.userLevel = "advanced";
 
772
 
 
773
  window.xmltform1Index.showIcons = 0;
 
774
  window.xmltform1Option.showIcons = "off";
 
775
 
 
776
  window.xmltform1Index.windowsMode = 0;
 
777
  window.xmltform1Option.windowsMode = "off";
 
778
 
 
779
  if (!window.xmlterm && exportCount) {
 
780
    var redirectURL = document.location.href;
 
781
    var urlLen = redirectURL.indexOf("?");
 
782
 
 
783
    if (urlLen > 0) redirectURL = redirectURL.substr(0,urlLen);
 
784
 
 
785
    DEBUG_LOG("exportCount="+exportCount+"\n");
 
786
 
 
787
    var minrefresh = GetQueryParam("minrefresh");
 
788
    var maxrefresh = GetQueryParam("maxrefresh");
 
789
    var refresh = GetQueryParam("refresh");
 
790
    var id = GetQueryParam("id");
 
791
 
 
792
    if (minrefresh) {
 
793
       if (!maxrefresh) maxrefresh = 10*minrefresh;
 
794
       if (!refresh) refresh = minrefresh;
 
795
       if (!id) id = 0;
 
796
 
 
797
       if (exportCount > id*1)
 
798
         refresh = minrefresh;
 
799
       else
 
800
         refresh = 2*refresh;
 
801
 
 
802
       if (refresh > maxrefresh) refresh=maxrefresh;
 
803
 
 
804
       var refreshTime = refresh*1000;
 
805
 
 
806
       redirectURL += "?minrefresh="+minrefresh + "&maxrefresh="+maxrefresh +"&refresh="+refresh + "&id="+exportCount;
 
807
 
 
808
       DEBUG_LOG("redirectURL="+redirectURL+"\n");
 
809
 
 
810
       window.redirectURL = redirectURL;
 
811
       window.timeoutId = window.setTimeout(Redirect, refreshTime);
 
812
    }
 
813
 
 
814
    window.scrollTo(0,4000);       // Scroll to bottom of page
 
815
  }
 
816
 
 
817
  return false;
 
818
 
 
819
  // The following code fragment is skipped because the chrome takes care of
 
820
  // XMLterm initialization. This should eventually be deleted
 
821
  if (window.xmlterm) {
 
822
     // XMLTerm already initialized
 
823
     return false;
 
824
  }
 
825
 
 
826
  DEBUG_LOG("LoadHandler: WINDOW.ARGUMENTS="+window.arguments+"\n");
 
827
 
 
828
  WRITE_LOG("Trying to make an XMLTerm Shell through the component manager...\n");
 
829
 
 
830
  var xmltshell = Components.classes["@mozilla.org/xmlterm/xmltermshell;1"].createInstance();
 
831
 
 
832
  xmltshell = xmltshell.QueryInterface(Components.interfaces.mozIXMLTermShell);
 
833
  DEBUG_LOG("Interface xmltshell2 = " + xmltshell + "\n");
 
834
 
 
835
  if (!xmltshell) {
 
836
    WRITE_LOG("Failed to create XMLTerm shell\n");
 
837
    window.close();
 
838
    return;
 
839
  }
 
840
 
 
841
  // Store the XMLTerm shell in the window
 
842
  window.xmlterm = xmltshell;
 
843
 
 
844
  // Content window same as current window
 
845
  var contentWindow = window;
 
846
 
 
847
  // Initialize XMLTerm shell in content window with argvals
 
848
  window.xmlterm.init(contentWindow, "", "");
 
849
 
 
850
  DEBUG_LOG("LoadHandler:"+document.cookie+"\n");
 
851
 
 
852
  DEBUG_LOG("contentWindow="+contentWindow+"\n");
 
853
  DEBUG_LOG("document="+document+"\n");
 
854
  DEBUG_LOG("documentElement="+document.documentElement+"\n");
 
855
 
 
856
  // Handle resize events
 
857
  //contentWindow.addEventListener("onresize", Resize);
 
858
  contentWindow.onresize = Resize;
 
859
 
 
860
  // Set focus to appropriate frame
 
861
  contentWindow.focus();
 
862
 
 
863
  //contentWindow.xmlterm = xmlterm;
 
864
 
 
865
  DEBUG_LOG(contentWindow.xmlterm);
 
866
 
 
867
  // The following code is for testing IFRAMEs only
 
868
  DEBUG_LOG("[Main] "+window+"\n");
 
869
  DEBUG_LOG(window.screenX+", "+window.screenY+"\n");
 
870
  DEBUG_LOG(window.scrollX+", "+window.scrollY+"\n");
 
871
  DEBUG_LOG(window.pageXOffset+", "+window.pageYOffset+"\n");
 
872
 
 
873
  DEBUG_LOG("IFRAME checks\n");
 
874
  var iframe = document.getElementById('iframe1');
 
875
 
 
876
  DEBUG_LOG("iframe="+iframe+"\n");
 
877
 
 
878
  frames=document.frames;
 
879
  DEBUG_LOG("frames="+frames+"\n");
 
880
  DEBUG_LOG("frames.length="+frames.length+"\n");
 
881
 
 
882
  framewin = frames[0];
 
883
 
 
884
  DEBUG_LOG("framewin="+framewin+"\n");
 
885
  DEBUG_LOG("framewin.document="+framewin.document+"\n");
 
886
 
 
887
  DEBUG_LOG(framewin.screenX+", "+framewin.screenY+"\n");
 
888
  DEBUG_LOG(framewin.scrollX+", "+framewin.scrollY+"\n");
 
889
  DEBUG_LOG(framewin.pageXOffset+", "+framewin.pageYOffset+"\n");
 
890
 
 
891
  var body = framewin.document.getElementsByTagName("BODY")[0];
 
892
  DEBUG_LOG("body="+body+"\n");
 
893
 
 
894
  var height= body.scrollHeight;
 
895
  DEBUG_LOG("height="+height+"\n");
 
896
 
 
897
//        iframe.height = 800;
 
898
//        iframe.width = 700;
 
899
 
 
900
//        framewin.sizeToContent();
 
901
 
 
902
  framewin.xmltshell = xmltshell;
 
903
  DEBUG_LOG(framewin.xmltshell+"\n");
 
904
 
 
905
  DEBUG_LOG("xmlterm: LoadHandler completed\n");
 
906
  return false;
 
907
}
 
908