-
Notifications
You must be signed in to change notification settings - Fork 0
/
outline.js
199 lines (180 loc) · 7.71 KB
/
outline.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
// The following tag is for display in advanced filelists only:
// <TITLE>Support for Outline-styled Structure Using Dynamic HTML Statements</title>
//
// Refer outline.txt for general documentation.
// Variable definitions
var sOutline = "outline"; // Class name for outline node
var sOutlined = "outlined"; // Class name for outline content
var imgCollapsed = ""; // Image file to load when node is collapsed
var imgExpanded = ""; // Image file to load when node is expanded
var sCollapsed = "+"; // Text to display when node is collapsed
var sExpanded = "-"; // Text to display when node is expanded
/* SCRIPT EXCEPTIONS */
function EOutline(Msg) {
var msgBody = "outline.js (c) 1999-2006 Thomas Lahn (webmaster@PointedEars.de)\n\n";
msgBody += Msg;
msgBody += "\n\nClick \"OK\" to send a feedback e-mail to the author of the script or click \"Cancel\" to abort.\nAnyway, you should inform the author of the HTML document of the error you have encountered.";
if (confirm(msgBody))
{
self.location.href = "mailto:webmaster@PointedEars.de?subject=Feedback/JavaScript/outline.js";
}
return false;
}
function ENoBrowser() {
return EOutline( "This script is designed to be processed from a web browser only." );
}
function ENoJScript() {
return EOutline( "Your browser does not support Microsoft JScript. This is designed for Microsoft Internet Explorer only." );
}
function ENoTarget(Object) {
var msg = "The script could not determine the required target object (";
msg += Object;
msg += "+).\nThe possible causes are:\n\n";
msg += "a) A style-sheet is included in the HTML document that redefines the OUTLINE class for DIV tags. The additional style-sheet needs to be removed, the class needs to be renamed, or the CLASS=\"OUTLINE\" attribute is to be used for no other objects than outline nodes for the script to work properly.\n\n";
msg += "b) The HTML document did not provide the object.\nIt needs to be defined using the ID attribute of the respective HTML tag.\n\n";
msg += "c) Maybe your browser is unable to return the complete object list due to low system resources.\nThere are currently ";
msg += String(document.all.length);
msg += " accessible objects within the HTML document. The number of outline objects possibly needs to be reduced for the script to work properly.\nFor the moment you may be able to expand/collapse all nodes of the outline structure using the respective items/buttons if the author had included them in the HTML document.";
return EOutline(msg);
}
function ENoAttr(Object) {
var msg = "The clicked object (ID=\"";
msg += Object;
msg += "\") does neither support the SRC, ALT nor the innerHTML attribute.\nUse the <IMG SRC=\"...\" [ALT=\"...\"] CLASS=\"outline\"> tag or any tag with an appropriate closing tag (<...></...>) for the node symbol instead.";
return EOutline( msg );
}
function EInvalidArgument(Arg) {
var msg = "FullTree: The user script did not pass the required number of arguments or passed an invalid argument (";
msg += Arg;
msg += "). Refer documentation in script file for correct function call.";
return EOutline( msg );
}
/* SCRIPT FEATURES */
function CalcPaths() { // Calculates relative image file paths to absolute ones
var PathEnd = document.URL.lastIndexOf('\\'); // Folder path
if( PathEnd == -1 )
{
PathEnd = document.URL.lastIndexOf('/'); // URL
}
if( PathEnd == -1 ) { // Extends filename to full path
var prevImgCollapsed = imgCollapsed;
imgCollapsed = document.URL.slice(0, PathEnd);
imgCollapsed += "/";
imgCollapsed += prevImgCollapsed;
var prevImgExpanded = imgExpanded;
imgExpanded = document.URL.slice(0, PathEnd);
imgExpanded += "/";
imgExpanded += prevImgExpanded;
}
}
function clickHandler() {
var srcElement, targetId, targetElement;
if (document) { // If processed from web browser
var srcElement = window.event.srcElement;
if (srcElement && (srcElement.className.toLowerCase() == sOutline)) {
// If classified as outline node
targetId = srcElement.id;
targetId += "+";
targetElement = getElem("id", targetId);
if (targetElement) { // If the node content exists
if (targetElement.style.display == "none") { // If currently collapsed
targetElement.style.display = "";
if (srcElement.src) {
if (imgExpanded != "") srcElement.src = imgExpanded;
if (srcElement.alt) {
if (sExpanded != "") srcElement.alt = sExpanded;
}
} else if (srcElement.alt) {
if (sExpanded != "") srcElement.alt = sExpanded;
} else if (srcElement.innerHTML) {
if (sExpanded != "") srcElement.innerHTML = sExpanded;
} else
return ENoAttr( srcElement.id );
} else { // If currently expanded
targetElement.style.display = "none";
if (srcElement.src) {
if (imgCollapsed != "") srcElement.src = imgCollapsed;
if (srcElement.alt) {
if (sCollapsed != "") srcElement.alt = sCollapsed;
}
} else if (srcElement.alt) {
if (sCollapsed != "") srcElement.alt = sCollapsed;
} else if (srcElement.innerHTML) {
if (sCollapsed != "") srcElement.innerHTML = sCollapsed;
} else
return ENoAttr();
}
} else
return ENoTarget (srcElement.id);
}
} else
return ENoBrowser();
}
function FullTree(action) {
var obj;
if (document) { // If processed from web browser
if (document.all) { // If Microsoft JScript is supported
for (var i = document.all.length; i--;) {
obj = document.all[i];
if (obj.className.toLowerCase() == sOutline || obj.className.toLowerCase() == sOutlined) {
if ((obj.tagName.toLowerCase() == "div") && (obj.className.toLowerCase() != sOutline)) {
if (action == "+")
obj.style.display = "";
else if (action == "-")
obj.style.display = "none";
else
return EInvalidArgument();
if (obj.src) {
if (action == "+") {
if (imgExpanded != "") obj.src = imgExpanded;
} else if (action == "-") {
if (imgCollapsed != "") obj.src = imgCollapsed;
} else
return EInvalidArgument();
}
if (obj.alt) {
if (action == "+") {
if (sExpanded != "") obj.alt = sExpanded;
} else if (action == "-") {
if (sCollapsed != "") obj.alt = sCollapsed;
} else
return EInvalidArgument();
}
} else if ((obj.innerHTML && obj.tagName.toLowerCase() == "span") && (obj.className.toLowerCase() == sOutline)) {
// Only on SPAN
if (action == "+") {
if (sExpanded != "") obj.innerHTML = sExpanded;
} else if (action == "-") {
if (sCollapsed != "") obj.innerHTML = sCollapsed;
} else
return EInvalidArgument();
}
}
}
} else
return ENoJScript();
} else
return ENoBrowser();
}
function FullExpand() {
return FullTree("+");
}
function FullCollapse() {
return FullTree("-");
}
function FullTreeItems() {
document.write( '<p><a href="JavaScript:FullExpand()" target="_self">Alle Ebenen einblenden</a><br>',
'<a href="FullCollapse()" target="_self">Alle Ebenen ausblenden</a></p>' );
}
function FullTreeButtons() {
document.write( '<p><input type="button" width=100% value="Alle Ebenen einblenden" class="help" style="width:100%;" onClick="FullExpand();"><br>',
'<input type="button" width=100% value="Alle Ebenen ausblenden" class="help" style="width:100%" onClick="FullCollapse()"></p>' );
}
if (document) // If processed from a web browser: Defines the function above to be processed on every click on the document
{
document.onclick = clickHandler;
}
else
{
ENoBrowser();
}