View Single Post
  #1  
Old 06-06-2005, 12:06 PM
 
PDI PDI is offline
 

Advanced Member
  
Join Date: Sep 2004
Posts: 65
 

Default Cleaning up templates/javascript

Hi Everyone,

I want to try to clear up our templates a bit. I want to reduce the amount of code to make pages smaller/faster, less complex, and easier on search engines (so they have less code to wade through to get to the actual text).

This will look like a long post, but please don't be scared away! The answers should be pretty simple.

1) The following Javascript code is included in all our pages:
Code:
<SCRIPT language=JavaScript type=text/JavaScript> <!-- 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_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_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];} } function MM_reloadPage(init) { //reloads the window if Nav4 resized if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) { document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }} else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload(); } MM_reloadPage(true); var hwnd_Zoom; function popup(page_url, page_title) { if (hwnd_Zoom) hwnd_Zoom.close(); window.open(page_url, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no, width=650, height=550,screenX=150,screenY=150,top=150,left=150'); } //--> </SCRIPT>
Now, I assume the <!-- arrows are commenting this code out. So, it really serves no function on my site, right? Can I just delete this code outright? Or should I offload it (including the <!-- tags) into a .js file, and call it via <script> tags just to keep it in existence, but still with no actual function?

2) We have a vertical menu on the left side of the site that uses images instead of text for the category names, static pages, etc. We had our site set up so that each image has a dark (standard) version, and a highlighted version for when you mouse over the image. As a result, we have a bit like:
Code:
<BODY leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0" , '/skin1/images/custom/categoryX-light.gif' ,onload="MM_preloadImages('/skin1/images/custom/categoryX-light.gif',);">
Listing each of the categories/images, followed by:

...listed for EACH of the categories. Is there any way to clean this up? Can this all be dumped into a .js file or something?

Thank you for your help!
__________________
x-cart 4.0.1
Reply With Quote