• 0

what does this JavaScript do?


Question

Can anyone tell me what this JavaScript does?

It belong to this website http://gowrightworks.com/

My dad (the owner of the company) wants me to redesign the site. I have been learning HTML and CSS and i am confident i can do the redesign, i am just curious what the JavaScript does.

// JavaScript Document

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;


}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

Thanks in advance.

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

It preloads the images and then does the 'hover' effect on the images used in the nav. You can ditch the swapImgRestore() and in place you can use CSS Sprites for it instead (when you do a redesign should you need to have something similar again.)

Link to comment
Share on other sites

  • 0

Thanks alot! I was quite sure that is what it do purely by looking at the code and the website but with no knowledge of JavaScript i thought i would ask.

I was planing on doing sprites for the redesign.

Thanks again! :D

Link to comment
Share on other sites

  • 0

I was mortified that they were still using it. The code itself is fine and was pretty common thanks to Dreamweaver. The graphic designers probably didn't think of optimizing their UI code like Cupcakes showed.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.