File: xmlterm2.html

package info (click to toggle)
kompozer 1%3A0.8~b3.dfsg.1-0.1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 283,956 kB
  • ctags: 314,166
  • sloc: cpp: 1,763,181; ansic: 990,028; xml: 97,969; makefile: 46,334; asm: 34,989; perl: 26,943; sh: 20,165; cs: 6,232; java: 5,513; python: 3,221; pascal: 340; lex: 306; php: 244; csh: 132; objc: 97; yacc: 79; ada: 49; awk: 14; sql: 4; sed: 4
file content (460 lines) | stat: -rw-r--r-- 15,411 bytes parent folder | download | duplicates (8)
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
<!-- xmlterm.html: XMLterm page -->
<HTML>
  <HEAD>
    <TITLE>XMLterm Page</TITLE>

  <LINK TITLE="DefaultStyle" REL="stylesheet" TYPE="text/css"
   HREF="chrome://xmlterm/skin/xmltpage.css">

    <SCRIPT language="JavaScript">

      // CONVENTION: All pre-defined XMLTerm Javascript functions
      //             begin with an upper letter. This allows
      //             an easy distinction with user defined functions,
      //             which should begin with a lower case letter.

      // Show all output
      function ShowAll() {
        return DisplayAllOutput(true);
      }

      // Hide all output
      function HideAll() {
        return DisplayAllOutput(false);
      }

      // Set history buffer size
      function SetHistory(value) {
        dump("SetHistory("+value+")\n");
        window.xmlterm.SetHistory(value, document.cookie);
        return (false);
      }

      // Set prompt
      function SetPrompt(value) {
        dump("SetPrompt("+value+")\n");
        window.xmlterm.SetPrompt(value, document.cookie);
        return (false);
      }

      // Create new XMLTerm window
      function NewXMLTerm(firstcommand) {
        newwin = window.openDialog( "chrome://xmlterm/content/xmlterm.xul",
                                    "xmlterm", "chrome,dialog=no,resizable",
                                    firstcommand);
        //newwin = window.xmlterm.NewXMLTermWindow(firstcommand);
        dump("NewXMLTerm: "+newwin+"\n")
        return (false);
      }

      // Handle resize events
      function Resize(event) {
        dump("Resize()\n");
        window.xmlterm.Resize();
        return (false);
      }

      // Scroll Home
      function ScrollHome(isShift, isControl) {
        dump("ScrollHome("+isShift+","+isControl+")\n");
        if (isShift && window.xmltbrowser) {
           window.xmltbrowser.scroll(0,0);
        } else {
           window.scroll(0,0);
        }
        return false;
      }

      // Scroll End
      function ScrollEnd(isShift, isControl) {
        dump("ScrollEnd("+isShift+","+isControl+")\n");
        if (isShift && window.xmltbrowser) {
           window.xmltbrowser.scroll(0,9999);
        } else {
           window.scroll(0,9999);
        }
        return false;
      }

      // Scroll PageUp
      function ScrollPageUp(isShift, isControl) {
        dump("ScrollPageUp("+isShift+","+isControl+")\n");

        if (isShift && window.xmltbrowser) {
           window.xmltbrowser.scrollBy(0,-300);
        } else {
           window.scrollBy(0,-300);
        }
        return false;
      }

      // Scroll PageDown
      function ScrollPageDown(isShift, isControl) {
        dump("ScrollPageDown("+isShift+","+isControl+")\n");
        if (isShift && window.xmltbrowser) {
          window.xmltbrowser.scrollBy(0,300);
        } else {
          window.scrollBy(0,300);
        }
        return false;
      }

      // Form Focus (workaround for form input being transmitted to xmlterm)
      function FormFocus() {
        dump("FormFocus()\n");
        window.xmlterm.IgnoreKeyPress(true, document.cookie);
        return false;
      }

      // Form Blur (workaround for form input being transmitted to xmlterm)
      function FormBlur() {
        dump("FormBlur()\n");
        window.xmlterm.IgnoreKeyPress(false, document.cookie);
        return false;
      }

      // Handle default meta command
      function MetaDefault(arg1) {
        return Load("http://"+arg1);
      }

      // Load URL in XMLTermBrowser window
      function Load(url) {
        var succeeded = false;
        if (window.xmltbrowser) {
           dump("Load:xmltbrowser.location.href="+window.xmltbrowser.location.href+"\n");
           if (window.xmltbrowser.location.href.length) {
              window.xmltbrowser.location.href = url;
              succeeded = true;
           }
        }
        if (!succeeded) {
           window.xmltbrowser = window.open(url, "xmltbrowser");
        }
        return (false);
      }

      // Control display of all output elements
      function DisplayAllOutput(flag) {
        var outputElements = document.getElementsByName("output");
        for (i=0; i<outputElements.length; i++) {
          var outputElement = outputElements[i];
          outputElement.style.display = (flag) ? "block" : "none";
        }

        var promptElements = document.getElementsByName("prompt");
        for (i=0; i<promptElements.length; i++) {
          promptElement = promptElements[i];
          promptElement.style.setProperty("text-decoration",
                                           (flag) ? "none" : "underline", "")
        }
        return (false);
      }

      // Centralized event handler
      // eventType values:
      //   click
      //
      // targetType: 
      //   textlink  - hyperlink
      //   prompt    - command prompt
      //   command   - command line
      //   exec      - execute command with sendln/createln
      //               (depending upon window.commandMode)
      //   send      - transmit arg to LineTerm
      //   sendln    - transmit arg+newline to LineTerm
      //   createln  - transmit arg+newline as first command to new XMLTerm
      //
      // entryNumber: >=0 means process only if current entry
      //              <0  means process anytime
      //
      // arg1:    command/pathname string (without newline)
      // arg2:    alternate command line (for use in current entry only;
      //            uses relative pathnames assuming current working directory)
      //
      function HandleEvent(eventObj, eventType, targetType, entryNumber,
                           arg1, arg2) {
        dump("HandleEvent("+eventObj+","+eventType+","+targetType+","+
                         entryNumber+","+arg1+","+arg2+")\n");

        // Entry independent targets
        if (action === "textlink") {
          dump("textlink = "+arg1+"\n");
          Load(arg1);
  
        } else if (eventType === "click") {
           if (targetType === "prompt") {
             var outputElement = document.getElementById("output"+entryNumber);
             var promptElement = document.getElementById("prompt"+entryNumber);
             //dump(promptElement.style.getPropertyValue("text-decoration"));

             if (outputElement.style.display == "none") {
               outputElement.style.display = "block";
               promptElement.style.setProperty("text-decoration","none","");
             } else {
               outputElement.style.display = "none";
               promptElement.style.setProperty("text-decoration","underline","");
             }

           } else if (targetType === "command") {
             var commandElement = document.getElementById(targetType+entryNumber);
             var command = commandElement.firstChild.data;
             dump("command = "+command+"\n\n");
             window.xmlterm.SendText("\025"+command+"\n", document.cookie);

           } else {
             // Targets which may be qualified only for current entry

             if ((entryNumber >= 0) &&
               (window.xmlterm.currentEntryNumber != entryNumber)) {
               dump("NOT CURRENT COMMAND\n");
               return (false);
             }

             var action = targetType;

             if (action === "exec") {
                if (window.commandMode === "window") {
                   action = "createln";
                } else {
                   action = "sendln";
               }
             }

             if (action === "send") {
               dump("send = "+arg1+"\n");
               window.xmlterm.SendText(arg1, document.cookie);
  
             } else if (action === "sendln") {

               if ((Math.abs(entryNumber)+1 == window.xmlterm.currentEntryNumber) &&
                (arg2 != null)) {
                  // Current command
                  dump("sendln = "+arg2+"\n\n");
                  window.xmlterm.SendText("\025"+arg2+"\n", document.cookie);
               } else {
                  // Not current command
                  dump("sendln = "+arg1+"\n\n");
                  window.xmlterm.SendText("\025"+arg1+"\n", document.cookie);
               }
  
             } else if (action === "createln") {
               dump("createln = "+arg1+"\n\n");
               newwin = NewXMLTerm(arg1+"\n");
             }
          }
        }

        return (false);
      }

      // Set history buffer count using form entry
      function SetHistoryValue() {
        var field = document.getElementById('InputValue');
        return SetHistory(field.value);
      }

      // Set prompt using form entry
      function SetPromptValue() {
        var field = document.getElementById('InputValue');
        return SetPrompt(field.value);
      }

      // Usage tips
      var tips = new Array();
      tips[0] = 'Click the SetPrompt button to use a cool Mozilla prompt from dmoz.org!';
      tips[1] = '"js:SetPrompt(HTMLstring);" sets prompt to HTML string.';
      tips[2] = 'Type "js:func(arg);" to execute inline Javascript function func.';
      tips[3] = 'Inline Javascript ("js:...") can be used to produce HTML output.';
      tips[4] = 'XMLterm supports full screen commands like "vi", "emacs -nw", and "less".';
      tips[5] = 'Use "xls -i" for iconic display of directory contents.';
      tips[6] = 'Use "xcat file" to display file.';

      // Display random usage tip
      // (should cease to operate after a few cycles;
      // need to use Prefs to keep track of that)
      function UsageTip() {
        var tipCount = tips.length;
        var ranval = Math.random();
        var tipIndex = Math.floor(ranval * tipCount);
        if (tipIndex >= tipCount) tipIndex = 0;

        dump("xmlterm: UsageTip "+tipIndex+","+ranval+"\n");

        var tiphead = document.getElementById('tiphead');
        var tipdata = document.getElementById('tipdata');
        tiphead.firstChild.data = "Tip:";
        tipdata.firstChild.data = tips[tipIndex];

        return false;
      }

      // Display more tips
      function MoreTips() {
        dump("xmlterm: MoreTips\n");

        var moreTipsElement = document.getElementById('moretips');
        var moreTipsFrame = document.getElementById('moretipsframe');

        if (moreTipsFrame) {
           // Remove more tips iframe
           document.body.removeChild(moreTipsFrame);
           moreTipsElement.firstChild.data = "More tips/news";
        } else {
           // Create more tips iframe
           moreTipsFrame = document.createElement("iframe");
           moreTipsFrame.setAttribute('ID', 'moretipsframe');
           moreTipsFrame.setAttribute('CLASS', 'moretipsframe');
           moreTipsFrame.setAttribute('WIDTH', '100%');
           moreTipsFrame.setAttribute('SRC', 'http://xmlterm.org/newstips.html');

           dump(moreTipsFrame);

           // Insert more tips iframe in body
           var sessionElement = document.getElementById('session');
           document.body.insertBefore(moreTipsFrame, sessionElement);
           moreTipsElement.firstChild.data = "Hide tips/news";
        }
        return false;
      }

      // onLoad event handler
      function LoadHandler() {
        dump("xmlterm: LoadHandler ... "+window.xmlterm+"\n");

        UsageTip();

        if (window.xmlterm) {
           // XMLTerm already initialized
           return (false);
        }

        dump("LoadHandler: WINDOW.ARGUMENTS="+window.arguments+"\n");

        dump("Trying to make an XMLTerm Shell through the component manager...\n");

        var xmltshell = Components.classes["@mozilla.org/xmlterm/xmltermshell;1"].createInstance();

        dump("Interface xmltshell1 = " + xmltshell + "\n");

        xmltshell = xmltshell.QueryInterface(Components.interfaces.mozIXMLTermShell);
        dump("Interface xmltshell2 = " + xmltshell + "\n");

        if (!xmltshell) {
          dump("Failed to create XMLTerm shell\n");
          window.close();
          return;
        }
  
        // Store the XMLTerm shell in the window
        window.xmlterm = xmltshell;

        // Content window same as current window
        var contentWindow = window;

        // Initialize XMLTerm shell in content window with argvals
        window.xmlterm.Init(contentWindow, "", "");

        //dump("LoadHandler:"+document.cookie+"\n");

        dump("contentWindow="+contentWindow+"\n");
        dump("document="+document+"\n");
        dump("documentElement="+document.documentElement+"\n");

        // Handle resize events
        //contentWindow.addEventListener("onresize", Resize);
        contentWindow.onresize = Resize;

        // Set focus to appropriate frame
        contentWindow.focus();

        //contentWindow.xmlterm = xmlterm;

        //dump(contentWindow.xmlterm);

        // The following code is for testing IFRAMEs only
        dump("[Main] "+window+"\n");
        dump(window.screenX+", "+window.screenY+"\n");
        dump(window.scrollX+", "+window.scrollY+"\n");
        dump(window.pageXOffset+", "+window.pageYOffset+"\n");

        dump("IFRAME checks\n");
        var iframe = document.getElementById('iframe1');

        dump("iframe="+iframe+"\n");

        frames=document.frames;
        dump("frames="+frames+"\n");
        dump("frames.length="+frames.length+"\n");

        framewin = frames[0];

        dump("framewin="+framewin+"\n");
        dump("framewin.document="+framewin.document+"\n");

        dump(framewin.screenX+", "+framewin.screenY+"\n");
        dump(framewin.scrollX+", "+framewin.scrollY+"\n");
        dump(framewin.pageXOffset+", "+framewin.pageYOffset+"\n");

        var body = framewin.document.getElementsByTagName("BODY")[0];
        dump("body="+body+"\n");

        var height= body.scrollHeight;
        dump("height="+height+"\n");

//        iframe.height = 800;
//        iframe.width = 700;

//        framewin.sizeToContent();

        framewin.xmltshell = xmltshell;
        dump(framewin.xmltshell+"\n");

        dump("xmlterm: LoadHandler completed\n");
        return (false);
      }

    </SCRIPT>
    
  </HEAD>

  <BODY onLoad="return LoadHandler();">

    <TABLE FRAME=none BORDER=0>
      <TBODY>
      <TR><TD ALIGN=center>
        <FORM NAME="XMLTERM form">
          <INPUT TYPE="button" VALUE="Hide all output"
               onClick="return HideAll();">
          <INPUT TYPE="button" VALUE="Show all output"
               onClick="return ShowAll();">
          <INPUT TYPE="button" VALUE="SetHistory"
                 onClick="return SetHistoryValue();">
          <INPUT TYPE="button" VALUE="SetPrompt"  onClick="return SetPromptValue();">
          <INPUT TYPE="button" VALUE="NewXMLTerm"  onClick="return NewXMLTerm('');">
          <BR>
          Input Value:
          <INPUT SIZE=50 TYPE="text" ID="InputValue"
                 VALUE="<img src='http:/dmoz.org/img/lizard2a.gif'>"
                 onFocus="return FormFocus();" onBlur="return FormBlur();">
        </FORM>
    </TABLE>

<SPAN CLASS="tiphead" ID="tiphead" STYLE="font-weight:bold"> &nbsp; </SPAN>
<SPAN CLASS="tipdata" ID="tipdata"> &nbsp; </SPAN>

<SPAN CLASS="moretips" ID="moretips" onClick="return MoreTips();">
More tips/news
</SPAN>
<P>
<!--
    <IFRAME NAME="iframet" SRC="chrome://xmlterm/content/xmltblank.html"
            FRAMEBORDER=0>
    </IFRAME>
 -->

    <DIV CLASS="session" ID="session">
    </DIV>

  </BODY>
</HTML>