Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Cleaning up templates/javascript

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #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
  #2  
Old 06-06-2005, 12:20 PM
 
balinor balinor is offline
 

Veteran
  
Join Date: Oct 2003
Location: Connecticut, USA
Posts: 30,253
 

Default

That JS code looks like it is from a Dreamweaver rollover image. Is that what you used for your category images? If so, you don't want to delete that JS or your rollovers won't work
__________________
Padraic Ryan
Ryan Design Studio
Professional E-Commerce Development
Reply With Quote
  #3  
Old 06-06-2005, 12:45 PM
 
PDI PDI is offline
 

Advanced Member
  
Join Date: Sep 2004
Posts: 65
 

Default

I didn't design the template, rollovers, etc. X-cart just adapted our site's previous design to work with their templates. I have no idea what they did or how it works. I was just wondering if all the "mouseover" stuff could be dumped off to a separate file (or if there's a cleaner, simpler HTML alternative). Of course, I'll just leave it alone unless I'm sure of an alternative (which I would test before implementing live, of course).

I made a test page putting the JS from question 1 in a separate .js file. The page appears to work just fine (but I don't know if that JS does something special that isn't visibly obvious). Also, since it's commented out, I assume it has no real needed function. I assume I'm safe on this one, right?

Thanks!
__________________
x-cart 4.0.1
Reply With Quote
  #4  
Old 06-06-2005, 12:51 PM
 
balinor balinor is offline
 

Veteran
  
Join Date: Oct 2003
Location: Connecticut, USA
Posts: 30,253
 

Default

You can probably put it in a different file, but I doubt the rollovers will work (or preload the images) without that script in place. There also seems to be a seperate function in that javascript that controls some sort of zoom pop-up window?
__________________
Padraic Ryan
Ryan Design Studio
Professional E-Commerce Development
Reply With Quote
  #5  
Old 06-06-2005, 12:55 PM
 
PDI PDI is offline
 

Advanced Member
  
Join Date: Sep 2004
Posts: 65
 

Default

Which are you talking about having a popup, #1 or #2?

There is no popup on our site. If you're talking about #1, I'm guessing that's what's getting commented out (perhaps it's a holdover from our pre-Xcart design).

As for #2, I'll leave them as-is.

Thanks again!
__________________
x-cart 4.0.1
Reply With Quote
  #6  
Old 06-06-2005, 12:56 PM
 
balinor balinor is offline
 

Veteran
  
Join Date: Oct 2003
Location: Connecticut, USA
Posts: 30,253
 

Default

#1 has popup code in it. Also, I doubt the code in #2 will work without the script in #1.....
__________________
Padraic Ryan
Ryan Design Studio
Professional E-Commerce Development
Reply With Quote
  #7  
Old 06-06-2005, 01:06 PM
 
PDI PDI is offline
 

Advanced Member
  
Join Date: Sep 2004
Posts: 65
 

Default

Oh, OK. I didn't realize they were related to each other somehow.
On the test page, with #1 called from a separate .js file, the mouseovers still work, so I'll go with that.
Thank you for your help!
__________________
x-cart 4.0.1
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 03:19 PM.

   

 
X-Cart forums © 2001-2020