source: trunk/web-app/js/lightbox.js @ 189

Last change on this file since 189 was 189, checked in by gav, 14 years ago

Set minimum lightbox width, may fix IE resize bug but also makes list navigation faster.

File size: 24.9 KB
Line 
1//
2//      Lightbox version 3.0.0
3//      by Lokesh Dhakar - http://www.huddletogether.com
4//      04/03/2008
5//
6//      For more information on this script, visit:
7//      http://huddletogether.com/projects/lightbox2/
8//
9//      Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
10//
11//      Credit also due to those who have helped, inspired, and made their code available to the public.
12//      Including: Scott Upton(uptonic.com), Peter-Paul Koch(quirksmode.org), Thomas Fuchs(mir.aculo.us), and others.
13//
14
15/*
16
17  Table of Contents
18  -----------------
19
20  Extending Built-in Objects
21  - Object.extend(Element)
22  - Array.prototype.removeDuplicates()
23
24  Lightbox Class Declaration
25  - block()
26  - onload()
27  - updateImageList()
28 
29  Miscellaneous Functions
30  - getPageScroll()
31  - getPageSize()
32  - showSelectBoxes()
33  - hideSelectBoxes()
34  - showObjects()
35  - hideObjects()
36  - pause()
37
38*/
39
40//      Additional methods for Element added by SU, Couloir
41//      - further additions by Lokesh Dhakar (huddletogether.com)
42Object.extend(Element, {
43  setWidth: function (element, width) {
44    $(element).style.width = width + "px";
45  },
46  setHeight: function (element, height) {
47    $(element).style.height = height + "px";
48  },
49  setTop: function (element, top) {
50    $(element).style.top = top + "px";
51  },
52  setLeft: function (element, left) {
53    $(element).style.left = left + "px";
54  },
55  setSrc: function (element, src) {
56    $(element).src = src;
57  },
58  setInnerHTML: function (element, content) {
59    $(element).innerHTML = content;
60  }
61});
62
63//      Extending built-in Array object
64//      - array.removeDuplicates()
65Array.prototype.removeDuplicates = function () {
66  for (i = 1; i < this.length; i++) {
67    if (this[i][0] == this[i - 1][0]) { this.splice(i, 1); }
68  }
69}
70
71//      Lightbox Class Declaration
72//      - block()
73//  - onload()
74//  - updateImageList()
75
76//      Structuring of code inspired by Scott Upton (http://www.uptonic.com/)
77
78var Lightbox = {
79
80  onload: function (event) {
81
82    // preload image.
83    loadingImage = new Image();
84    loadingImage.src =  Lightbox._imagePath + "loading.gif";
85
86    var options = { 'minWidth' : 650};
87    return Lightbox._create(options);
88  },
89
90  // Fades to overlay and runs an animated loading gif (e.g after form submit)
91  loading: function(options) {
92    if (!document.getElementsByTagName) { return true; }
93
94     Lightbox._options(options);
95
96     var buttons = document.getElementsByClassName("buttons");
97     buttons[0].style.visibility = "hidden";
98
99    var parent = document.getElementsByTagName("body").item(0);
100    var overlay = Lightbox._createElement("div", "overlay", "none", null, null, function (event) {} );
101    parent.appendChild(overlay);
102
103    var pageSize = getPageSize();
104    Element.setWidth('overlay', pageSize[0]);
105    Element.setHeight('overlay', pageSize[1]);
106
107    if (Lightbox._animate) {
108      new Effect.Appear('overlay', { duration: Lightbox._overlayBlockDuration, from: 0.0, to: Lightbox._blockOpacity });
109    }
110    else {
111      Element.setOpacity('overlay', Lightbox._opacity);
112    }
113
114    if (Lightbox._animate) {
115        var loading = Lightbox._createElement("div", 'loading');
116        parent.appendChild(loading);
117
118        // document.all should be detected in IE and Opera, workaround for IE gif freezing.
119        if(document.all) {
120            new Effect.Pulsate(loading, { pulses: 15, duration: 10 });
121        }
122        else {
123            Element.show('loading');
124        }
125    }
126
127  },
128
129
130  // Blocks the page (after form submit)
131  block: function(message, options) {
132    if (!document.getElementsByTagName) { return true; }
133
134    Lightbox._options(options);
135   
136    var parent = document.getElementsByTagName("body").item(0);
137    var overlay = Lightbox._createElement("div", "overlay", "none", null, null, function (event) {} );
138    parent.appendChild(overlay);
139       
140    // The rest of this code inserts html at the bottom of the page that looks similar to this:
141    //
142    // <div id="lightbox">
143    //   <div id="outerImageContainer">
144    //     <div id="imageContainer">
145    //       <div id="loading"></div>
146    //       <div id="imageDataContainer"> message </div>
147    //     </div>
148    //   </div>
149    // </div>
150
151    var lightbox = Lightbox._createElement("div", "lightbox", "none");
152    parent.appendChild(lightbox);
153
154    var outerImageContainer = Lightbox._createElement("div", "outerImageContainer");
155    lightbox.appendChild(outerImageContainer);
156
157    var imageContainer = Lightbox._createElement("div", 'imageContainer');
158    outerImageContainer.appendChild(imageContainer);
159
160        imageContainer.appendChild(Lightbox._createElement("div", 'loading'));
161    imageDataContainer = Lightbox._createElement("div", 'imageDataContainer');
162    imageContainer.appendChild(imageDataContainer);
163    imageDataContainer.appendChild(document.createTextNode(message));
164
165    hideSelectBoxes();
166    hideObjects();
167    var pageSize = getPageSize();
168    Element.setWidth('overlay', pageSize[0]);
169    Element.setHeight('overlay', pageSize[1]);
170    Element.setOpacity('overlay', Lightbox._blockOpacity);
171    Element.show('overlay');
172    Element.setTop('lightbox', Number(getPageScroll()[1] + (getPageSize()[3] / 15)).toFixed());
173    Element.show('lightbox');
174    Element.show('loading');
175    return true;
176  },
177 
178  // Loops through anchor tags looking for 'lightbox' references and applies onclick
179  // events to appropriate links. You can rerun after dynamically adding images w/ajax.
180  updateImageList: function () {
181    if (!document.getElementsByTagName) { return; }
182
183    // loop through all anchor tags
184    var anchors = document.getElementsByTagName('a');
185    for (var i = 0, l = anchors.length; i < l; i++) {
186      var anchor = anchors[i];
187      // use the string.match() method to catch 'lightbox' references in the rel attribute
188      var relAttribute = String(anchor.getAttribute('rel'));
189      if (anchor.getAttribute('href') && (relAttribute.toLowerCase().match('lightbox'))) {
190        anchor.onclick = function () { return Lightbox._start(this); };
191      }
192    }
193
194    // loop through all area tags
195    // todo: combine anchor & area tag loops
196    var areas = document.getElementsByTagName('area');
197    for (var i = 0, l = areas.length; i < l; i++) {
198      var area = areas[i];
199      // use the string.match() method to catch 'lightbox' references in the rel attribute
200      var relAttribute = String(area.getAttribute('rel'));
201      if (area.getAttribute('href') && (relAttribute.toLowerCase().match('lightbox'))) {
202        Area.onclick = function () { return Lightbox.start(this); }
203      }
204    }
205  },
206
207  // Loops through anchor tags looking for 'lightbox' references and applies onclick events
208  // to appropriate links. The 2nd section of the function inserts html at the bottom of the
209  // page which is used to display the shadow overlay and the image container.
210  _create: function(options) {
211    if (!document.getElementsByTagName) return;
212
213    Lightbox._options(options);
214
215    var parent = document.getElementsByTagName("body").item(0);
216    var overlay = Lightbox._createElement("div", "overlay", "none", null, null, Lightbox._overlayEnd);
217    parent.appendChild(overlay);
218
219    Lightbox.updateImageList();
220       
221    // The rest of this code inserts html at the bottom of the page that looks similar to this:
222    //
223    // <div id="lightbox">
224    //   <div id="outerImageContainer">
225    //     <div id="imageContainer">
226    //       <img id="lightboxImage" />
227    //       <div id="hoverNav">
228    //         <a href="#" id="prevLink"></a>
229    //         <a href="#" id="nextLink"></a>
230    //       </div>
231    //       <div id="loading"></div>
232    //     </div>
233    //   </div>
234    //   <div id="imageDataContainer">
235    //     <div id="imageData">
236    //       <div id="imageDetails">
237    //         <span id="caption"></span>
238    //         <span id="numberDisplay"></span>
239    //       </div>
240    //       <div id="bottomNav">
241    //         <img id="bottomNavPrev" />
242    //         <img id="bottomNavNext" />
243    //         <img id="bottomNavClose" />
244    //       </div>
245    //     </div>
246    //   </div>
247    // </div>
248
249    var lightbox = Lightbox._createElement("div", "lightbox", "none", null, null, Lightbox._overlayEnd);
250    parent.appendChild(lightbox);
251
252    var outerImageContainer = Lightbox._createElement("div", "outerImageContainer");
253    lightbox.appendChild(outerImageContainer);
254
255    // When Lightbox starts it will resize itself from 250 by 250 to the current image dimension.
256    // If animations are turned off, it will be hidden as to prevent a flicker of a
257    // white 250 by 250 box.
258    if (Lightbox._animate) {
259      Element.setWidth('outerImageContainer', 250);
260      Element.setHeight('outerImageContainer', 250);
261    }
262    else {
263      Element.setWidth('outerImageContainer', 1);
264      Element.setHeight('outerImageContainer', 1);
265    }
266
267    var imageContainer = Lightbox._createElement("div", 'imageContainer');
268    outerImageContainer.appendChild(imageContainer);
269    imageContainer.appendChild(Lightbox._createElement("img", 'lightboxImage'));
270
271    var hoverNav = Lightbox._createElement("div", 'hoverNav');
272    imageContainer.appendChild(hoverNav);
273
274    hoverNav.appendChild(Lightbox._createElement("a", 'prevLink', null, null, '#'));
275    hoverNav.appendChild(Lightbox._createElement("a", 'nextLink', null, null, '#'));
276
277    imageContainer.appendChild(Lightbox._createElement("div", 'loading', null, null, null, Lightbox._end));
278
279    imageDataContainer = Lightbox._createElement("div", 'imageDataContainer');
280    lightbox.appendChild(imageDataContainer);
281
282    imageData = Lightbox._createElement("div", 'imageData');
283    imageDataContainer.appendChild(imageData);
284
285    var imageDetails = Lightbox._createElement("div", 'imageDetails');
286    imageData.appendChild(imageDetails);
287
288    imageDetails.appendChild(Lightbox._createElement("span", 'caption'));
289    imageDetails.appendChild(Lightbox._createElement("span", 'numberDisplay'));
290
291    bottomNav = Lightbox._createElement("div", 'bottomNav');
292    imageData.appendChild(bottomNav);
293
294    bottomNav.appendChild(Lightbox._createElement("img", 'bottomNavPrev',  null, Lightbox._imagePath + "miniprev.jpg",   null, Lightbox._prevImage));
295    bottomNav.appendChild(Lightbox._createElement("img", 'bottomNavNext',  null, Lightbox._imagePath + "mininext.jpg",   null, Lightbox._nextImage));
296    bottomNav.appendChild(Lightbox._createElement("img", 'bottomNavClose', null, Lightbox._imagePath + "closelabel.gif", null, Lightbox._end));
297  },
298
299  _createElement: function (type, id, display, src, href, onclick) {
300    elem = document.createElement(type);
301    if (id)      { elem.setAttribute('id', id); }
302    if (display) { elem.style.display = display; }
303    if (src)     { elem.setAttribute('src', src); }
304    if (href)    { elem.setAttribute('href', href); }
305        if (onclick) { elem.onclick = onclick; }
306    return elem;
307  },
308
309  _options: function(options) {
310    if (options) {
311      var option = options['borderSize'];
312      if (option) { Lightbox._borderSize = option; }
313      option = options['overlayDuration'];
314      if (option) { Lightbox._overlayDuration = option; }
315      option = options['resizeDuration'];
316      if (option) { Lightbox._resizeDuration = option; }
317      option = options['minWidth'];
318      if (option) { Lightbox._minWidth = option; }
319      option = options['imagePath'];
320      if (option) { Lightbox._imagePath = option; }
321      option = options['opacity'];
322      if (option) { Lightbox._opacity = option; }
323      option = options['blockOpacity'];
324      if (option) { Lightbox._blockOpacity = option; }
325      option = options['animate'];
326      if (option) { Lightbox._animate = option; }
327      option = options['text'];
328      if (option) { Lightbox._text = option; }
329    }   
330  },
331
332  // Display overlay and lightbox. If image is part of a set, add siblings to imageArray.
333  _start: function (imageLink) {
334    hideSelectBoxes();
335    hideObjects();
336
337    // stretch overlay to fill page and fade in
338    var pageSize = getPageSize();
339    Element.setWidth('overlay', pageSize[0]);
340    Element.setHeight('overlay', pageSize[1]);
341
342    if (Lightbox._animate) {
343      new Effect.Appear('overlay', { duration: Lightbox._overlayDuration, from: 0.0, to: Lightbox._opacity });
344    }
345    else {
346      Element.setOpacity('overlay', Lightbox._opacity);
347    }
348
349    Lightbox._activeImage = 0;
350    Lightbox._imageArray = [];
351    var imageNum = 0;
352    if ((imageLink.getAttribute('rel') == 'lightbox')) { // if image is NOT part of a set..
353          Lightbox._imageArray.push(new Array(imageLink.getAttribute('href'), imageLink.getAttribute('title')));
354    }
355    else { // if image is part of a set..
356      // loop through anchors, find other images in set, and add them to imageArray
357      var rel = imageLink.getAttribute('rel');
358      var anchors = document.getElementsByTagName(imageLink.tagName);
359      for (var i = 0, l = anchors.length; i < l; i++) {
360        var anchor = anchors[i];
361        if (anchor.getAttribute('href') && (anchor.getAttribute('rel') == rel)) {
362          Lightbox._imageArray.push(new Array(anchor.getAttribute('href'), anchor.getAttribute('title')));
363        }
364      }
365      Lightbox._imageArray.removeDuplicates();
366      var href = imageLink.getAttribute('href');
367      while (Lightbox._imageArray[imageNum][0] != href) { imageNum++; }
368    }
369
370    // calculate top offset for the lightbox and display
371    var pageScroll = getPageScroll();
372    Element.setTop('lightbox', Number(pageScroll[1] + (pageSize[3] / 10)).toFixed());
373    Element.setLeft('lightbox', Number(pageScroll[0]).toFixed());
374    Element.show('lightbox');
375    Lightbox._changeImage(imageNum);
376    return false;
377  },
378
379  _overlayEnd: function (event) {
380    if (!event) { event = window.event; }
381    var id = Event.element(event).id;
382    if (id == 'overlay' || id == 'lightbox') { return Lightbox._end(); }
383    return true;
384  },
385
386  _end: function (event) {
387    Lightbox._disableKeyboardNav();
388    Element.hide('lightbox');
389    if (Lightbox._animate) {
390      new Effect.Fade('overlay', { duration: Lightbox._overlayDuration });
391    } 
392    else {
393      Element.hide('overlay');
394    }
395    showSelectBoxes();
396    showObjects();
397    return false;
398  },
399
400  _hasNext: function () {
401    return Lightbox._activeImage < (Lightbox._imageArray.length - 1);
402  },
403
404  _nextImage: function () {
405    Lightbox._changeImage(Lightbox._activeImage + 1);
406    return false;
407  },
408
409  _hasPrev: function () {
410    return Lightbox._activeImage > 0;
411  },
412
413  _prevImage: function () {
414    Lightbox._changeImage(Lightbox._activeImage - 1);
415    return false;
416  },
417
418  // Hide most elements and preload image in preparation for resizing image container.
419  _changeImage: function (imageNum) {
420    Lightbox._activeImage = imageNum;
421   
422    // hide elements during transition
423    if (Lightbox._animate) { Element.show('loading'); }
424    Element.hide('lightboxImage');
425    Element.hide('hoverNav');
426    Element.hide('prevLink');
427    Element.hide('nextLink');
428    Element.hide('bottomNavPrev');
429    Element.hide('bottomNavNext');
430    Element.hide('imageDataContainer');
431    Element.hide('caption');
432    Element.hide('numberDisplay');
433
434    // once image is preloaded, resize image container
435    Lightbox._preloader = new Image();
436    Lightbox._preloader.onload = function () {
437      Element.setSrc('lightboxImage', Lightbox._imageArray[imageNum][0]);
438      Lightbox._preloader.onload = function () { }; // clear onLoad, IE behaves irratically with animated gifs otherwise
439      Lightbox._resizeImageContainer(Lightbox._preloader.width, Lightbox._preloader.height);
440    };
441    Lightbox._preloader.src = Lightbox._imageArray[imageNum][0];
442  },
443
444  _resizeImageContainer: function (imgWidth, imgHeight) {
445    var borders = Lightbox._borderSize * 2;
446   
447    // keep to a minimum width, if specified
448    if (Lightbox._minWidth > 0 && (imgWidth + borders) < Lightbox._minWidth) {
449      imgWidth = Lightbox._minWidth - borders;
450    }
451
452    // get current height and width
453    var widthCurrent = Element.getWidth('outerImageContainer');
454    var heightCurrent = Element.getHeight('outerImageContainer');
455
456    // get new width and height
457    var widthNew = imgWidth + borders;
458    var heightNew = imgHeight + borders;
459
460    // scalars based on change from old to new
461    var xScale = (widthNew / widthCurrent) * 100;
462    var yScale = (heightNew / heightCurrent) * 100;
463   
464    // calculate size difference between new and old image, and resize if necessary
465    var widthDiff = widthCurrent - widthNew;
466        var heightDiff = heightCurrent - heightNew;
467    if (heightDiff != 0) {
468      new Effect.Scale('outerImageContainer', yScale, { scaleX: false, duration: Lightbox._resizeDuration, queue: 'front' });
469    }
470        if (widthDiff != 0) {
471          new Effect.Scale('outerImageContainer', xScale, { scaleY: false, duration: Lightbox._resizeDuration, delay: Lightbox._resizeDuration });
472        }
473
474    // if new and old image are same size and no scaling transition is necessary,
475    // do a quick pause to prevent image flicker.
476    if ((heightDiff == 0) && (widthDiff == 0)) {
477      if (navigator.appVersion.indexOf("MSIE") != -1) { pause(250); } else { pause(100); }
478    }
479
480    Element.setHeight('prevLink', imgHeight);
481    Element.setHeight('nextLink', imgHeight);
482    Element.setWidth('imageDataContainer', widthNew);
483    Lightbox._showImage();
484  },
485
486  // Display image.
487  _showImage: function () {
488    Element.hide('loading');
489    new Effect.Appear('lightboxImage', { duration: Lightbox._resizeDuration, queue: 'end', afterFinish: Lightbox._updateDetails });
490        Lightbox._preloadNeighborImages();
491  },
492
493  // Display caption, image number, and bottom nav.
494  _updateDetails: function () {
495    // if caption is not null
496        var caption = Lightbox._imageArray[Lightbox._activeImage][1];
497    if (caption) {
498      Element.show('caption');
499      Element.setInnerHTML('caption', caption);
500    }
501               
502    // if image is part of set display 'Image x of x'
503    if (Lightbox._imageArray.length > 1) {
504      Element.show('numberDisplay');
505      var text = Lightbox._text.replace("*", (Lightbox._activeImage + 1));
506      text = text.replace("*", Lightbox._imageArray.length);
507      Element.setInnerHTML('numberDisplay', text);
508    } 
509
510    if (Lightbox._hasPrev()) { Element.show('bottomNavPrev'); } 
511    if (Lightbox._hasNext()) { Element.show('bottomNavNext'); }
512
513        new Effect.Parallel(
514          [ new Effect.SlideDown('imageDataContainer', { sync: true, duration: Lightbox._resizeDuration }),
515        new Effect.Appear('imageDataContainer', { sync: true, duration: Lightbox._resizeDuration }) ],
516      { duration: Lightbox._resizeDuration, afterFinish: Lightbox._updateNav });
517  },
518
519  // Display appropriate previous and next hover navigation.
520  _updateNav: function () {
521    $('imageDataContainer').style.overflow = 'auto'; // css float fix
522
523    Element.setHeight('overlay', getPageSize()[1]);
524
525    Element.show('hoverNav');
526
527    // if not first image in set, display prev image button
528    if (Lightbox._hasPrev()) {
529      document.getElementById('prevLink').onclick = Lightbox._prevImage;
530      Element.show('prevLink');
531      }
532
533    // if not last image in set, display next image button
534    if (Lightbox._hasNext()) {
535      document.getElementById('nextLink').onclick = Lightbox._nextImage;
536      Element.show('nextLink');
537    }
538   Lightbox._enableKeyboardNav();
539  },
540
541  _enableKeyboardNav: function () {
542    document.onkeydown = Lightbox._keyboardAction;
543  },
544
545  _disableKeyboardNav: function () {
546    document.onkeydown = '';
547  },
548
549  _keyboardAction: function (evnt) {
550    var keycode = 0, escapeKey = 0, key = 0;
551    if (evnt == null) { // ie
552      keycode = event.keyCode;
553      escapeKey = 27;
554    }
555    else { // mozilla
556      keycode = evnt.keyCode;
557      escapeKey = evnt.DOM_VK_ESCAPE;
558    }
559
560    key = String.fromCharCode(keycode).toLowerCase();
561    if ((key == 'x') || (key == 'o') || (key == 'c') || (keycode == escapeKey)) { // close lightbox
562      Lightbox._end();
563      return true;
564    } 
565    else if((key == 'p') || (keycode == 37)) { // display previous image
566      if (Lightbox._hasPrev()) {
567        Lightbox._disableKeyboardNav();
568        Lightbox._prevImage();
569        return true;
570      }
571    } 
572    else if((key == 'n') || (keycode == 39)) { // display next image
573      if (Lightbox._hasNext()) {
574        Lightbox._disableKeyboardNav();
575        Lightbox._nextImage();
576        return true;
577      }
578    }
579  return false;
580  },
581
582  _preloadNeighborImages: function () {
583    if (Lightbox._hasNext()) {
584      Lightbox._preloadNextImage = new Image();
585      Lightbox._preloadNextImage.src = Lightbox._imageArray[Lightbox._activeImage + 1][0];
586    }
587    if (Lightbox._hasPrev()) {
588      Lightbox._preloadPrevImage = new Image();
589      Lightbox._preloadPrevImage.src = Lightbox._imageArray[Lightbox._activeImage - 1][0];
590    }
591  },
592
593  _borderSize: 10,
594  _overlayDuration: 0.2,
595  _overlayBlockDuration: 0.6,
596  _resizeDuration: 0.4,
597  _minWidth: 0,
598  _imagePath: "/gnuMims/images/",
599  _opacity: 0.6,
600  _blockOpacity: 0.1,
601  _animate: true,
602  _text: "Image * of *",
603  _activeImage: 0,
604  _imageArray: []
605}
606
607// Returns array with x, y page scroll values.
608// Core code from - quirksmode.org
609function getPageScroll(){
610  var xScroll = 0, yScroll = 0;
611  if (self.pageYOffset) {
612    xScroll = self.pageXOffset;
613    yScroll = self.pageYOffset;
614  }
615  else if (document.documentElement && document.documentElement.scrollTop) {    // Explorer 6 Strict
616    xScroll = document.documentElement.scrollLeft;
617    yScroll = document.documentElement.scrollTop;
618  } 
619  else if (document.body) { // all other Explorers
620    xScroll = document.body.scrollLeft; 
621    yScroll = document.body.scrollTop;
622  }
623  return new Array(xScroll, yScroll)
624}
625
626// Returns array with page width, height and window width, height
627// Core code from - quirksmode.org
628// Edit for Firefox by pHaez
629function getPageSize() {
630  var xScroll = 0, yScroll = 0;
631  var docBody = document.body;
632  var docElem = document.documentElement;
633  if (window.innerHeight && window.scrollMaxY) {
634    xScroll = window.innerWidth + window.scrollMaxX;
635    yScroll = window.innerHeight + window.scrollMaxY;
636  }
637  else if (docBody.scrollHeight > docBody.offsetHeight) { // all but Explorer Mac
638    xScroll = docBody.scrollWidth;
639    yScroll = docBody.scrollHeight;
640  } 
641  else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
642    xScroll = docBody.offsetWidth;
643    yScroll = docBody.offsetHeight;
644  }
645
646  var windowWidth = 0, windowHeight = 0, pageHeight = 0, pageWidth = 0;
647  if (self.innerHeight) {       // all except Explorer
648    if(docElem.clientWidth) {
649      windowWidth = docElem.clientWidth; 
650    }
651    else {
652      windowWidth = self.innerWidth;
653    }
654    windowHeight = self.innerHeight;
655  }
656  else if (docElem && docElem.clientHeight) { // Explorer 6 Strict Mode
657    windowWidth = docElem.clientWidth;
658    windowHeight = docElem.clientHeight;
659  }
660  else { // other Explorers
661    windowWidth = docBody.clientWidth;
662    windowHeight = docBody.clientHeight;
663  }
664
665  // for small pages with total height less then height of the viewport
666  if (yScroll < windowHeight) {
667    pageHeight = windowHeight;
668  }     
669  else {
670    pageHeight = yScroll;
671  }
672
673  // for small pages with total width less then width of the viewport
674  if (xScroll < windowWidth) {
675    pageWidth = xScroll;
676  }
677  else {
678    pageWidth = windowWidth;
679  }
680  return new Array(pageWidth, pageHeight, windowWidth, windowHeight)
681}
682
683function showSelectBoxes() {
684  var selects = document.getElementsByTagName("select");
685  for (var i = 0, l = selects.length; i < l; i++) {
686    selects[i].style.visibility = "visible";
687  }
688}
689
690function hideSelectBoxes() {
691  var selects = document.getElementsByTagName("select");
692  for (var i = 0, l = selects.length; i < l; i++) {
693    selects[i].style.visibility = "hidden";
694  }
695}
696
697function showObjects() {
698  var objects = document.getElementsByTagName("object");
699  for (var i = 0, l = objects.length; i < l; i++) {
700    objects[i].style.visibility = "visible";
701  }
702
703  var embeds = document.getElementsByTagName("embed");
704  for (var i = 0, l = embeds.length; i < l; i++) {
705    embeds[i].style.visibility = "visible";
706  }
707}
708
709function hideObjects() {
710  var objects = document.getElementsByTagName("object");
711  for (var i = 0, l = objects.length; i < l; i++) {
712    objects[i].style.visibility = "hidden";
713  }
714
715  var embeds = document.getElementsByTagName("embed");
716  for (var i = 0, l = embeds.length; i < l; i++) {
717    embeds[i].style.visibility = "hidden";
718  }
719}
720
721// pause(numberMillis)
722// Pauses code execution for specified time. Uses busy code, not good.
723// Code from http://www.faqts.com/knowledge_base/view.phtml/aid/1602
724// Help from Ran Bar-On [ran2103@gmail.com]
725function pause(ms) {
726  var date = new Date();
727  var curDate = null;
728  do {
729    curDate = new Date();
730  } while (curDate - date < ms);
731}
Note: See TracBrowser for help on using the repository browser.