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

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

Add support for inventory item Pictures and Images.
Add new PersonService, refactor CreateDataService and TaskService to suite.

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