Jump to content

add a script in javascript?


vit320

Recommended Posts

look this page and look header menu with image www.ga-ga-garage.com

i want take the source code of the script that realize the image menu.

Looking at source code i see this :

 

<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)&&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.indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a;}}
}

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[n];
for(i=0;!x&&d.layers&&i
<d.layers.length;i++) x=MM_findObj(n,d.layers.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))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->

</script>

 

after this (but i don't understood why previous script is inside a REM)

 

i see this part of html...(see functions declared in javascript?)

<td width="92" height="125" align="left"><img src="menu_up/grey_sx_down_1024.jpg" width="92" height="126"></td>
<td width="145" align="right"><img src="menu_up/home_1024.jpg" width="142" height="126"></td>
<td width="131"><a href="storia/storia.htm" target="_self" onMouseOver="MM_swapImage('Storia','','menu_up/storia02_1024.jpg',1)" onMouseOut="MM_swapImgRestore()"><img src="menu_up/storia01_1024.jpg" alt="Storia" name="Storia" width="131" height="126" border="0"></a></td>
<td width="156"><a href="personaggi/beppe.htm" target="_self" onMouseOver="MM_swapImage('Personaggi','','menu_up/personaggi02_1024.jpg',1)" onMouseOut="MM_swapImgRestore()"><img src="menu_up/personaggi01_1024.jpg" alt="Personaggi" name="Personaggi" width="156" height="126" border="0"></a></td>
<td width="140"><a href="progetti/progetti.htm" target="_self" onMouseOver="MM_swapImage('Progetti','','menu_up/progetti02_1024.jpg',1)" onMouseOut="MM_swapImgRestore()"><img src="menu_up/progetti01_1024.jpg" alt="Progetti" name="Progetti" width="140" height="126" border="0"></a></td>
<td width="137"><a href="comics/comics.htm" target="_self" onMouseOver="MM_swapImage('Comics','','menu_up/comics02_1024.jpg',1)" onMouseOut="MM_swapImgRestore()"><img src="menu_up/comics01_1024.jpg" alt="Comics" name="Comics" width="137" height="126" border="0"></a></td>
<td width="140"><a href="news/news.htm" target="_top" onMouseOver="MM_swapImage('News','','menu_up/news02_1024.jpg',1)" onMouseOut="MM_swapImgRestore()"><img src="menu_up/news01_1024.jpg" alt="News" name="News" width="139" height="126" border="0"></a></td>
<td width="89"><img src="menu_up/grey_dx_down_1024.jpg" width="89" height="126"></td>

 

So i think i can reuse this script i copy it in main.php but page result broken. what i lost?

 

 

 

Link to comment
Share on other sites

"(but i don't understood why previous script is inside a REM)"

 

Having HTML comment tags <!-- --> surround javascript is a from a very old necessity to keep very old browsers that did not know javascript from having problems. The javascript MM functions are a very standard, very old, but still very valuable functions that do what you need.

 

Today, there are CSS :hover tricks.

 

The templates use a method of changing {PLACEHOLDERS} with actual data. The program that does this is called Smarty. Smarty requires that its {PLACEHOLDERS}, and only its place holders, have braces ({}) to show them.

 

Javascript and CSS also uses braces to group functions. So, Smarty has special commands to allow for a block of code to be ignored. Therefore, in your template, do this:

{literal}

<script>Place your javascript here.</script>

{/literal}

 

You can also tell Smarty that something is not a {PLACEHOLDER} by making sure there is a space between the brace and the letters:

{PLACEHOLDER} <- Belongs to Smarty

{ CSS RULE } <- Not for Smarty - note the spaces.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...