Javascript question

by "Bob Unger" <rbu(at)akula.com>

 Date:  Tue, 19 Sep 2000 11:26:51 -0400
 To:  hwg-techniques(at)hwg.org
  todo: View Thread, Original
All,
I've been given the opportunity to maintain an existing web site.  I 
took a look at it and there is a piece of Javascript that I am not 
familiar with.  I understand the middle section - preload images - 
but I'm not sure what the "swapImg" functions does in the first and 
last parts of the script.  Can anybody give me a brief explanation?
Thanks,
Bob Unger



<SCRIPT language=JavaScript>

<!--
function MM_swapImgRestore() { //v2.0
  if (document.MM_swapImgData != null)
    for (var i=0; i<(document.MM_swapImgData.length-1); i+=2)
      document.MM_swapImgData[i].src = 
document.MM_swapImgData[i+1];
}

function MM_preloadImages() { //v2.0
  if (document.images) {
    var imgFiles = MM_preloadImages.arguments;
    if (document.preloadArray==null) document.preloadArray = new 
Array();
    var i = document.preloadArray.length;
    with (document) for (var j=0; j<imgFiles.length; j++) if 
(imgFiles[j].charAt(0)!="#"){
      preloadArray[i] = new Image;
      preloadArray[i++].src = imgFiles[j];
  } }
}

function MM_swapImage() { //v2.0
  var i,j=0,objStr,obj,swapArray=new 
Array,oldArray=document.MM_swapImgData;
  for (i=0; i < (MM_swapImage.arguments.length-2); i+=3) {
    objStr = MM_swapImage.arguments[(navigator.appName == 
'Netscape')?i:i+1];
    if ((objStr.indexOf('document.layers[')==0 && 
document.layers==null) ||
        (objStr.indexOf('document.all[')   ==0 && document.all   
==null))
      objStr = 
'document'+objStr.substring(objStr.lastIndexOf('.'),objStr.length);
    obj = eval(objStr);
    if (obj != null) {
      swapArray[j++] = obj;
      swapArray[j++] = (oldArray==null || oldArray[j-
1]!=obj)?obj.src:oldArray[j];
      obj.src = MM_swapImage.arguments[i+2];
  } }
  document.MM_swapImgData = swapArray; //used for restore
}
//-->


</SCRIPT>

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA

This page is part of a preserved archive of archives.hwg.org. The site is no longer active and its content is not maintained. For enquiries about this archive, write to archive(at)iwanet.org.