/
document.js
713 lines (571 loc) · 14.5 KB
/
document.js
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
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
/*
* The following tag used for display in advanced file listings only:
* <title>JavaScript Routines and Objects to Create Temporary Documents</title>
*
* See document.txt file for general documentation.
*/
var documentVersion = "v1.20.2005080609";
var sAuthorCopyright = "\xA9 2000-2005 by Thomas Lahn (PES)";
var sAuthorEMail = "webmaster@PointedEars.de";
/* Script exceptions */
var sCopyright =
"document.js "
+ documentVersion
+ " "
+ sAuthorCopyright
+ "\nmailto:"
+ sAuthorEMail
+ "\n\n";
function HTMLException(Msg)
{
alert( sCopyright + Msg );
return false;
}
function ENoDocument(sFunctionName)
{
// var sFunctionName = (sFunctionName != null) ? sFunctionName + ": " : "";
/*
* Passing the name of the function which caused the exception currently not
* possible
*/
return HTMLException(
"The specified target object does not exist."
+ " Please check your assignment(s) to the HTMLdoc variable.");
}
function EInvalidArgNum(sFunctionName, iArg)
{
return HTMLException(
sFunctionName
+ ": The user script did not pass the required number of arguments ("
+ iArg
+ "). Refer documentation in script file for correct function call.");
}
/* Script features */
if (typeof jsx == "undefined") var jsx = {};
if (typeof jsx.document == "undefined")
{
jsx.document = {
write: function(s) {
return jsx.tryThis(
function() {
/*jshint -W060*/
document.write(s);
/*jshint +W060*/
/* fix circular reference */
s = null;
return true;
},
function() {
/* try without namespaces first (presumably HTML or loose XHTML) */
var scripts = document.getElementsByTagName("script");
if (!scripts || !scripts.length)
{
/* try with namespace (presumably strict XHTML) */
scripts = document.getElementsByTagNameNS(
document.documentElement.getAttribute("xmlns"),
"script");
}
/* Can we locate ourselves at all? */
if (scripts && scripts.length)
{
var thisScript = scripts[scripts.length - 1];
var node = thisScript.parentNode.insertBefore(
document.createTextNode(s),
thisScript);
}
/* fix circular reference */
s = null;
return node;
}) || false;
}
};
}
var HTMLdoc = document;
/* Version 1.05.x OOP Extension */
var HTMLinstance = new _HTMLDocument(HTMLdoc);
function docCheck(bRaiseException)
{
if (HTMLdoc)
{
return true;
}
if (arguments.length == 1 && bRaiseException)
{
ENoDocument(docCheck.caller);
}
return false;
}
/* Document Type Definitions and HTML 4.0 Tag Policy URLs */
/*jshint -W098*/
/* DTD for HTML 2.0 documents */
var dtdHTML2 = '"-//W3C//DTD HTML 2.0//EN"';
/* DTD for HTML 3.2 documents */
var dtdHTML32 = '"-//W3C//DTD HTML 3.2//EN"';
/* DTD for HTML 4.01 documents */
var dtdHTML4 = '"-//W3C//DTD HTML 4.01//EN"';
/* DTD for HTML 4.01 documents including frameset definition */
var dtdHTML4frm = '"-//W3C//DTD HTML 4.01 Frameset//EN"';
/* DTD for HTML 4.01 documents containing deprecated elements and attributes */
var dtdHTML4scr = '"-//W3C//DTD HTML 4.01 Transitional//EN"';
/* URL of DTD for HTML 4.01 documents containing deprecated elements and attribs */
var dtdURL_HTML4dep = '\n "http://www.w3.org/TR/html4/loose.dtd"';
/* URL of DTD for HTML 4.01 documents that define framesets */
var dtdURL_HTML4frm = '\n "http://www.w3.org/TR/html4/frameset.dtd"';
/* URL of DTD for documents that use strict HTML 4.01 syntax */
var dtdURL_HTML4str = '\n "http://www.w3.org/TR/html4/strict.dtd"';
/*jshint +W098*/
function HTMLdocOpen(sDTD, bReplace)
{
if (!docCheck(true)) return;
/*
* version 1.08.2000.3 bugfix, formerly: ...length = 2(!)
* and separated sections
*/
// if( HTMLdoc.location.href != "" ) HTMLdoc.close();
if (arguments.length == 2 && bReplace)
{
HTMLdoc.open("text/html", "replace");
}
else
{
HTMLdoc.open("text/html");
}
if (arguments.length < 1)
{
sDTD = "";
}
HTMLdoc.writeln("<!DOCTYPE html PUBLIC ", sDTD, ">\n<html>\n");
}
function HTMLdocClose()
{
if (!docCheck(true))
{
return;
}
HTMLdoc.writeln("</html>");
HTMLdoc.close();
}
function docWrite(s)
{
if (!docCheck(true))
{
return;
}
HTMLdoc.write(s);
}
function docWriteLn(s)
{
if (!docCheck(true))
{
return;
}
HTMLdoc.writeln(s);
}
var HTMLtagCount = 0;
function HTMLwriteTag(sTag, sAttrib, sContent)
{
var sWrite = "";
if (!docCheck(true))
{
return;
}
if (arguments.length < 1 || sTag == "")
{
EInvalidArgNum("HTMLwriteTag", 1);
return;
}
/* for better document compression rates */
sTag = sTag.toLowerCase();
if (arguments.length < 2)
{
/* use default value if argument missing */
sAttrib = "";
}
if (arguments.length < 3)
{
/* use default value if argument missing */
sContent = "";
}
sWrite = "<" + sTag;
if (sAttrib != "" )
{
sWrite += " " + sAttrib;
}
sWrite += ">";
if (sContent != "")
{
sWrite +=
sContent + "</" + sTag + ">";
for (var i = 4; i < arguments.length; i++)
{
sWrite += arguments[i];
}
}
HTMLdoc.write(sWrite);
HTMLtagCount++;
/* OOP extension */
HTMLinstance.tagCount = HTMLtagCount;
/*
* TODO Bug: Text is written twice into the document when the function
* result is used as argument. Workaround required to uncomment
* return statement.
*/
// return sWrite;
}
var HTMLmetaCount = 0;
function HTMLwriteMeta(sName, sHTTPequiv, sContent)
{
if (arguments.length != 3)
{
EInvalidArgNum("HTMLwriteMeta", 3);
return;
}
if (! docCheck(true))
{
return;
}
if (sName.toLowerCase() != "generator")
{
HTMLdoc.write("<meta ");
if (sName != "")
{
HTMLdoc.write('name="', sName, '" ');
}
if (sHTTPequiv != "")
{
HTMLdoc.write('http-equiv="', sHTTPequiv, '" ');
HTMLdoc.writeln('content="', sContent, '">');
HTMLmetaCount++;
/* OOP extension */
HTMLinstance.metaCount = HTMLmetaCount;
}
}
}
/*jshint -W098*/
function HTMLwriteLinkFavIcon(sURL)
{
/*jshint +W098*/
if (sURL.length > 0)
{
HTMLdoc.HTMLwriteTag("link", 'rel="shortcut icon" href="' + sURL + '"');
}
}
/*jshint +W098*/
var HTMLscriptCount = 0;
function HTMLwriteScript(sLang, sSrc, sType, sContent)
{
if (sSrc == "" && (arguments.length < 4 || sContent == ""))
{
EInvalidArgNum("HTMLwriteScript", 4);
return;
}
if (!docCheck(true))
{
return;
}
if (arguments.length == 0 || sLang == "")
{
sLang = "JavaScript";
}
HTMLdoc.write('<script language="', sLang, '"');
if (arguments.length < 2)
{
sSrc = "";
}
if (sSrc != "")
{
HTMLdoc.write(' src="', sSrc, '"');
}
if (arguments.length < 3 || sType == "")
{
sType = "text/javascript";
}
if (sType != "")
{
HTMLdoc.write( ' type="', sType, '"' );
}
HTMLdoc.write('>');
if (arguments.length < 4)
{
sContent = "";
}
if (sSrc == "" && sContent != "")
{
HTMLdoc.write('<!--\n', sContent, '\n//-->');
}
HTMLdoc.write('</script>\n');
HTMLscriptCount++;
/* OOP extension */
HTMLinstance.scriptCount = HTMLscriptCount;
}
var HTMLstyleCount = 0;
function HTMLwriteStyle(sType, sAttrib, sContent)
{
if (sContent == "" || arguments.length < 3)
{
EInvalidArgNum("HTMLwriteStyle", 3);
return;
}
if (!docCheck(true))
{
return;
}
if (sType == "")
{
sType = "text/css";
}
HTMLdoc.write('<style type="', sType, '"');
if (sAttrib != "")
{
HTMLdoc.write( ' ', sAttrib );
}
HTMLdoc.write('><!--\n', sContent, '\n//--></style>\n');
HTMLstyleCount++;
/* OOP extension */
HTMLinstance.styleCount = HTMLstyleCount;
}
function HTMLheadOpen(sTitle)
{
if (!docCheck(true)) return;
HTMLdoc.writeln(
"<head>\n\n<title>",
sTitle,
'</title>\n\n<meta name="generator" content="document.js ',
documentVersion,
" ",
sAuthorCopyright,
' (' + sAuthorEMail + ')">');
}
function HTMLheadClose()
{
if (!docCheck(true))
{
return;
}
HTMLdoc.writeln('\n</head>\n');
}
/** background color */
var clBodyBg = "";
/** default text color */
var clBodyText = "";
/** default color for an unvisited link */
var clBodyLink = "";
/** default color for a visited link */
var clBodyVLink = "";
/** default color for a selected link */
var clBodyALink = "";
/** URL of the background image */
var imgBody = "";
/** Defines whether the background image is a watermark */
var bBodyBgFixed = false;
function HTMLbodyOpen()
{
if (!docCheck(true))
{
return;
}
HTMLdoc.write( "<body" );
if (clBodyBg != "")
{
HTMLdoc.write(' bgcolor="', clBodyBg, '"');
}
if (clBodyText != "")
{
HTMLdoc.write(' text="', clBodyText, '"');
}
if (clBodyLink != "")
{
HTMLdoc.write(' link="', clBodyLink, '"');
}
if (clBodyVLink != "")
{
HTMLdoc.write(' vlink="', clBodyVLink, '"');
}
if (clBodyALink != "")
{
HTMLdoc.write(' alink="', clBodyALink, '"');
}
if (imgBody != "")
{
HTMLdoc.write(' background="', imgBody, '"');
}
if (bBodyBgFixed)
{
HTMLdoc.write(' bgproperties="fixed"');
}
HTMLdoc.writeln ( ">\n" );
}
function HTMLbodyClose()
{
if (!docCheck(true))
{
return;
}
HTMLdoc.writeln('\n</body>\n');
}
/* OOP Support for Multiple Document Access (MDA): Methods and prototype */
function DocumentListAdd(aItem)
{
this.items.push(aItem);
}
function DocumentListRemove()
{
this.items.pop();
}
function DocumentList()
{
/* Properties */
this.items = new Array();
/* Methods */
this.add = DocumentListAdd;
this.remove = DocumentListRemove;
}
/*jshint -W098*/
var docList = new DocumentList();
/*jshint +W098*/
/* General OOP support: Methods, global counter variable and class */
function HTMLDocumentActivate()
{
HTMLinstance = this;
HTMLdoc = this.target;
clBodyBg = this.clBodyBg;
clBodyText = this.clBodyText;
clBodyLink = this.clBodyLink;
clBodyVLink = this.clBodyVLink;
clBodyALink = this.clBodyALink;
imgBody = this.imgBody;
bBodyBgFixed = this.bBodyBgFixed;
HTMLtagCount = this.tagCount;
HTMLmetaCount = this.metaCount;
HTMLscriptCount = this.scriptCount;
HTMLstyleCount = this.styleCount;
}
function HTMLDocumentShowProperties()
{
var sCaller =
(HTMLDocumentShowProperties.caller != null
? "Caller: \n\n" + HTMLDocumentShowProperties.caller + "\n"
: "");
var sResult =
sCopyright
+ "Current properties of the HTMLDocument instance named \""
+ this.name
+ "\";\nUsed HTMLDocument.showProperties() method:\n\n";
for (var Property in this)
{
var isNotMethod =
(String(this[Property]).toLowerCase().substr(0, 9) != "function ");
var isNotNameProp =
(String(Property).toLowerCase().substr(0, 4) != "name");
if (isNotMethod && isNotNameProp)
{
var isString =
(isNaN(this[Property]) || String(this[Property]) == "");
var bDblQuote =
(isString
? '"'
: "");
var sProp = String(this[Property]);
if (sProp == "[object]") bDblQuote = "";
sResult +=
Property
+ " = "
+ bDblQuote
+ sProp
+ bDblQuote
+ "\n";
}
}
sResult += "\nCreator URL: \"" + document.URL + "\"\n\n" + sCaller;
alert(sResult);
}
/** Number of _HTMLDocument instances created by the script caller document */
var HTMLDocumentCount = 0;
/* `HTMLDocument' is a W3C DOM 2 HTML interface literally implemented in Geckos */
function _HTMLDocument(aTarget, sDTD, bReplace, sName)
{
// Properties
if (arguments.length < 1)
{
this.target = HTMLdoc;
}
else
{
if (aTarget)
{
HTMLinstance = this;
this.target = aTarget;
HTMLdoc = this.target;
HTMLtagCount = 0;
HTMLmetaCount = 0;
HTMLscriptCount = 0;
/* Open doc. automatically on more arg. */
if (arguments.length > 1)
{
HTMLdocOpen(sDTD, bReplace);
}
}
else
{
/* Error if passed object is not available */
ENoDocument("_HTMLDocument");
return;
}
}
/* "" is v1.08.2000.3 bugfix, formerly used colors of last activated object */
/** background color */
this.clBodyBg = "";
/** text color */
this.clBodyText = "";
/** color for an unvisited link */
this.clBodyLink = "";
/** color for a visited link */
this.clBodyVLink = "";
/** color for a selected link */
this.clBodyALink = "";
/** URL of the background image */
this.imgBody = "";
/** Default: background image is no watermark */
this.bBodyBgFixed = false;
/** HTML tags written by writeTag(...) method */
this.tagCount = 0;
/** <meta> tags written except "generator" */
this.metaCount = 0;
/** <script></script> sections written */
this.scriptCount = 0;
/** <style></style> sections written */
this.styleCount = 0;
/* Increase the number of created _HTMLDocument instances for auto-naming */
HTMLDocumentCount++;
if (arguments.length >= 4)
{
/* Recommended to name the object for debug purposes */
this.name = sName;
}
else
{
this.name = "_HTMLDocument_" + String(HTMLDocumentCount);
}
/* Methods */
this.activate = HTMLDocumentActivate;
/* DEBUG */
this.showProperties = HTMLDocumentShowProperties;
this.checkTarget = docCheck;
this.open = HTMLdocOpen;
this.close = HTMLdocClose;
this.write = docWrite;
this.writeLn = docWriteLn;
this.writeTag = HTMLwriteTag;
this.writeMeta = HTMLwriteMeta;
this.writeScript = HTMLwriteScript;
this.writeStyle = HTMLwriteStyle;
this.headOpen = HTMLheadOpen;
this.headClose = HTMLheadClose;
this.bodyOpen = HTMLbodyOpen;
this.bodyClose = HTMLbodyClose;
}
/* Raise exception if not processed from a web browser */
if (! document)
{
ENoBrowser();
}