]> git.stg.codes - stg.git/blob - doc/xslt/slides/browser/xbDOM.js
Set output encoding to utf-8.
[stg.git] / doc / xslt / slides / browser / xbDOM.js
1 /*
2  * xbDOM.js
3  * $Revision: 1.2 $ $Date: 2003/02/07 16:04:18 $
4  */
5
6 /* ***** BEGIN LICENSE BLOCK *****
7  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
8  *
9  * The contents of this file are subject to the Mozilla Public License Version
10  * 1.1 (the "License"); you may not use this file except in compliance with
11  * the License. You may obtain a copy of the License at
12  * http://www.mozilla.org/MPL/
13  *
14  * Software distributed under the License is distributed on an "AS IS" basis,
15  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
16  * for the specific language governing rights and limitations under the
17  * License.
18  *
19  * The Original Code is Netscape code.
20  *
21  * The Initial Developer of the Original Code is
22  * Netscape Corporation.
23  * Portions created by the Initial Developer are Copyright (C) 2001
24  * the Initial Developer. All Rights Reserved.
25  *
26  * Contributor(s): Bob Clary <bclary@netscape.com>
27  *
28  * ***** END LICENSE BLOCK ***** */
29
30 function xbToInt(s)
31 {
32   var i = parseInt(s, 10);
33   if (isNaN(i))
34     i = 0;
35
36   return i;
37 }
38
39 function xbGetWindowWidth(windowRef)
40 {
41   var width = 0;
42
43   if (!windowRef)
44   {
45     windowRef = window;
46   }
47   
48   if (typeof(windowRef.innerWidth) == 'number')
49   {
50     width = windowRef.innerWidth;
51   }
52   else if (windowRef.document.body && typeof(windowRef.document.body.clientWidth) == 'number')
53   {
54     width = windowRef.document.body.clientWidth;  
55   }
56     
57   return width;
58 }
59
60 function xbGetWindowHeight(windowRef)
61 {
62   var height = 0;
63   
64   if (!windowRef)
65   {
66     windowRef = window;
67   }
68
69   if (typeof(windowRef.innerWidth) == 'number')
70   {
71     height = windowRef.innerHeight;
72   }
73   else if (windowRef.document.body && typeof(windowRef.document.body.clientWidth) == 'number')
74   {
75     height = windowRef.document.body.clientHeight;    
76   }
77   return height;
78 }
79
80 function xbGetElementsByNameAndType(name, type, windowRef)
81 {
82   if (!windowRef)
83     windowRef = window;
84
85   var elmlist = new Array();
86
87   xbFindElementsByNameAndType(windowRef.document, name, type, elmlist);
88
89   return elmlist;
90 }
91
92 function xbFindElementsByNameAndType(doc, name, type, elmlist)
93 {
94   var i;
95   var subdoc;
96   
97   for (i = 0; i < doc[type].length; ++i)
98   {
99     if (doc[type][i].name && name == doc[type][i].name)
100     {
101       elmlist[elmlist.length] = doc[type][i];
102     }
103   }
104
105   if (doc.layers)
106   {
107     for (i = 0; i < doc.layers.length; ++i)
108     {
109       subdoc = doc.layers[i].document;
110       xbFindElementsByNameAndType(subdoc, name, type, elmlist);
111     }
112   }
113 }
114
115 if (document.layers)
116 {
117   nav4FindLayer =
118   function (doc, id)
119   {
120     var i;
121     var subdoc;
122     var obj;
123     
124     for (i = 0; i < doc.layers.length; ++i)
125     {
126       if (doc.layers[i].id && id == doc.layers[i].id)
127         return doc.layers[i];
128         
129       subdoc = doc.layers[i].document;
130       obj    = nav4FindLayer(subdoc, id);
131       if (obj != null)
132         return obj;
133     }
134     return null;
135   }
136
137   nav4FindElementsByName = 
138   function (doc, name, elmlist)
139   {
140     var i;
141     var j;
142     var subdoc;
143     
144     for (i = 0; i < doc.images.length; ++i)
145     {
146       if (doc.images[i].name && name == doc.images[i].name)
147       {
148         elmlist[elmlist.length] = doc.images[i];
149       }
150     }
151
152     for (i = 0; i < doc.forms.length; ++i)
153     {
154       for (j = 0; j < doc.forms[i].elements.length; j++)
155       {
156         if (doc.forms[i].elements[j].name && name == doc.forms[i].elements[j].name)
157         {
158           elmlist[elmlist.length] = doc.forms[i].elements[j];
159         }
160       }
161
162       if (doc.forms[i].name && name == doc.forms[i].name)
163       {
164         elmlist[elmlist.length] = doc.forms[i];
165       }
166     }
167
168     for (i = 0; i < doc.anchors.length; ++i)
169     {
170       if (doc.anchors[i].name && name == doc.anchors[i].name)
171       {
172         elmlist[elmlist.length] = doc.anchors[i];
173       }
174     }
175
176     for (i = 0; i < doc.links.length; ++i)
177     {
178       if (doc.links[i].name && name == doc.links[i].name)
179       {
180         elmlist[elmlist.length] = doc.links[i];
181       }
182     }
183
184     for (i = 0; i < doc.applets.length; ++i)
185     {
186       if (doc.applets[i].name && name == doc.applets[i].name)
187       {
188         elmlist[elmlist.length] = doc.applets[i];
189       }
190     }
191
192     for (i = 0; i < doc.embeds.length; ++i)
193     {
194       if (doc.embeds[i].name && name == doc.embeds[i].name)
195       {
196         elmlist[elmlist.length] = doc.embeds[i];
197       }
198     }
199
200     for (i = 0; i < doc.layers.length; ++i)
201     {
202       if (doc.layers[i].name && name == doc.layers[i].name)
203       {
204         elmlist[elmlist.length] = doc.layers[i];
205       }
206         
207       subdoc = doc.layers[i].document;
208       nav4FindElementsByName(subdoc, name, elmlist);
209     }
210   }
211
212   xbGetElementById = function (id, windowRef)
213   {
214     if (!windowRef)
215       windowRef = window;
216
217     return nav4FindLayer(windowRef.document, id);
218   };
219
220   xbGetElementsByName = function (name, windowRef)
221   {
222     if (!windowRef)
223       windowRef = window;
224
225     var elmlist = new Array();
226
227     nav4FindElementsByName(windowRef.document, name, elmlist);
228
229     return elmlist;
230   };
231
232 }
233 else if (document.all)
234 {
235   xbGetElementById = 
236   function (id, windowRef) 
237   { 
238     if (!windowRef) 
239     {
240       windowRef = window; 
241     }
242     var elm = windowRef.document.all[id]; 
243     if (!elm) 
244     {
245       elm = null; 
246     }
247     return elm; 
248   };
249
250   xbGetElementsByName = function (name, windowRef)
251   {
252     if (!windowRef)
253       windowRef = window;
254
255     var i;
256     var idnamelist = windowRef.document.all[name];
257     var elmlist = new Array();
258
259     if (!idnamelist.length || idnamelist.name == name)
260     {
261       if (idnamelist)
262         elmlist[elmlist.length] = idnamelist;
263     }
264     else
265     {
266       for (i = 0; i < idnamelist.length; i++)
267       {
268         if (idnamelist[i].name == name)
269           elmlist[elmlist.length] = idnamelist[i];
270       }
271     }
272
273     return elmlist;
274   }
275
276 }
277 else if (document.getElementById)
278 {
279   xbGetElementById = 
280   function (id, windowRef) 
281   { 
282     if (!windowRef) 
283     {
284       windowRef = window; 
285     }
286     return windowRef.document.getElementById(id); 
287   };
288
289   xbGetElementsByName = 
290   function (name, windowRef) 
291   { 
292     if (!windowRef) 
293     {
294       windowRef = window; 
295     }
296     return windowRef.document.getElementsByName(name); 
297   };
298 }
299 else 
300 {
301   xbGetElementById = 
302   function (id, windowRef) 
303   { 
304     return null; 
305   };
306
307   xbGetElementsByName = 
308   function (name, windowRef) 
309   { 
310     return new Array(); 
311   };
312 }
313
314 function xbGetPageScrollX(windowRef)
315 {
316   if (!windowRef) 
317   {
318     windowRef = window; 
319   }
320
321   if (typeof(windowRef.pageXOffset) == 'number')
322   {
323     return windowRef.pageXOffset;
324   }
325
326   if (typeof(windowRef.document.body && windowRef.document.body.scrollLeft) == 'number')
327   {
328     return windowRef.document.body.scrollLeft;
329   }
330
331   return 0;
332 }
333
334 function xbGetPageScrollY(windowRef)
335 {
336   if (!windowRef) 
337   {
338     windowRef = window; 
339   }
340
341   if (typeof(windowRef.pageYOffset) == 'number')
342   {
343     return windowRef.pageYOffset;
344   }
345
346   if (typeof(windowRef.document.body && windowRef.document.body.scrollTop) == 'number')
347   {
348     return windowRef.document.body.scrollTop;
349   }
350
351   return 0;
352 }
353
354 if (document.layers)
355 {
356   xbSetInnerHTML = 
357   function (element, str) 
358   { 
359     element.document.write(str); 
360     element.document.close(); 
361   };
362 }
363 else 
364 {
365   xbSetInnerHTML = function (element, str) 
366   { 
367     if (typeof(element.innerHTML) != 'undefined') 
368     {
369       element.innerHTML = str; 
370     }
371   };
372 }
373
374 // eof: xbDOM.js