Page 1 of 1

Java Script Error

Posted: Fri Feb 01, 2008 1:21 am
by tiffany
So I'm making myself crazy trying to figure this one out. I embedded Serendipity by modifying the index.tpl file. I used to have a flash banner which worked fine, but I wanted to change to html/java. This is the code I'm having problems with:

Code: Select all

<script src="DWConfiguration/ActiveContent/IncludeFiles/AC_RunActiveContent.js" type="text/javascript"></script>
<link href="style.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
<!--
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];}
}
//-->
</script>
<style type="text/css">
<!--
.style2 {font-size: 10px}
-->
</style>
</head>



<body bgcolor="black" text="black" link="black" vlink="purple" alink="red" topmargin="0" marginheight="0" onLoad="MM_preloadImages('elements/home_glow.png','elements/gallery_glow.png','elements/links_glow.png','elements/sign_glow.png','elements/contact_glow.png');">

<table cellpadding="0" cellspacing="0" width="900" align="center" bgcolor="white">

    <tr>

        <td width="900" height="156" align="right" valign="bottom" nowrap background="elements/title.png"><table width="900" border="0">
          <tr>
            <td width="449"> </td>
            <td width="85"><a href="http://www.mysite.com/serendipity" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('home','','elements/home_glow.png',1)"><img src="elements/home_button.png" name="home" width="80" height="30" border="0"></a></td>
            <td width="85"><a href="http://www.mysite.com/gallery" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('gallery','','elements/gallery_glow.png',1)"><img src="elements/gallery_button.png" name="gallery" width="80" height="30" border="0"></a></td>
            <td width="85"><a href="http://www.mysite.com/links.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('links','','elements/links_glow.png',1)"><img src="elements/links_button.png" name="links" width="80" height="30" border="0"></a></td>
            <td width="85"><a href="http://www.mysite.com/guestbook_/fpg.cgi" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('sign','','elements/sign_glow.png',1)"><img src="elements/sign_button.png" name="sign" width="80" height="30" border="0"></a></td>
            <td width="85"><a href="http://www.mysite.com/contact.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('contact','','elements/contact_glow.png',1)"><img src="elements/contact_button.png" name="contact" width="80" height="30" border="0"></a></td>
          </tr>
        </table></td>
    </tr>
In response, I'm getting the following error:
Fatal error: Smarty error: [in /home/user/public_html/mysite/serendipity/templates/plain-vanilla/index.tpl line 28]: syntax error: unrecognized tag: //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/home/user/public_html/mysite/serendipity/bundled-libs/Smarty/libs/Smarty.class.php on line 1095
Any ideas?? Thanks!

Re: Java Script Error

Posted: Fri Feb 01, 2008 1:25 am
by garvinhicking
Hi!

In Smarty, the characters { and } are reserved for its Syntax.

Thus, you need to either replace all { with {ldelim} and all } with {rdelim}, or you need to enclose your raw code that contains { and } with {literal}...{/literal}.

Best regards,
Garvin

Posted: Fri Feb 01, 2008 4:43 am
by tiffany
Thanks for your reply. Unfortunately, I couldn't get that to work. I did manage to fix the issue by splitting the script. I put the script for the java function in the HTML-Head Nugget, then placed the banner in the index.tpl. It looks better, but it has some compatibility issues.

I put the title bar in a table with two rows, the second row split into 6 to hold each button / menu option. When I hover over the button...

* In Firefox, the image changes back and forth depending on the mouse movement (good), but the new image bumps up a cm.
* In IE there is no movement (good), but the button stays lit up after you pass it. By reloading the page, it resets itself.

Bizarre. The same code works fine embedded with menalto's gallery or on its own.

Here's the code again:

In the nugget:

Code: Select all

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script 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];}
}
//-->
</script>
In the index:

Code: Select all

<body bgcolor="black" text="black" link="black" vlink="purple" alink="red" topmargin="0" marginheight="0" <body onload="MM_preloadImages('http://www.mysite.com/elementshome_glow.png','http://www.mysite.com/elementsgallery_glow.png','http://www.mysite.com/elementslinks_glow.png','http://www.mysite.com/elementssign_glow.png','http://www.mysite.com/elementscontact_glow.png')">
<table width="900" height="156" align="center" cellpadding="0" cellspacing="0" background="http://www.mysite.com/elements/title.png" bgcolor="white">
  <tr>
    <td height="78" colspan="6" align="left" valign="bottom" nowrap="nowrap"> </td>
  </tr>
  <tr>
    <td width="448" height="78" align="" valign="bottom" nowrap="nowrap"> </td>
    <td width="90" height="30" align="left" valign="bottom" nowrap="nowrap"><a href="http://www.mysite.com/serendipity" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('home','','http://www.mysite.com/elements/home_glow.png',1)"><img src="http://www.mysite.com/elements/home_button.png" alt="news" name="home" width="80" height="30" border="0" id="home" /><br />
    </a></td>
    <td width="90" height="30" align="left" valign="bottom" nowrap="nowrap"><a href="http://www.mysite.com/gallery" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('gallery','','http://www.mysite.com/elements/gallery_glow.png',1)"><img src="http://www.mysite.com/elements/gallery_button.png" alt="gallery" name="gallery" width="80" height="30" border="0" id="gallery" /></a></td>
    <td width="90" height="30" align="left" valign="bottom" nowrap="nowrap"><a href="http://www.mysite.com/links.htm" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('links','','http://www.mysite.com/elements/links_glow.png',1)"><img src="http://www.mysite.com/elements/links_button.png" alt="links" name="links" width="80" height="30" border="0" id="links" /></a></td>
    <td width="90" height="30" align="left" valign="bottom" nowrap="nowrap"><a href="http://www.mysite.com/guestbook_/fpg.cgi" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('sign','','http://www.mysite.com/elements/sign_glow.png',1)"><img src="http://www.mysite.com/elements/sign_button.png" alt="sign" name="sign" width="80" height="30" border="0" id="sign" /></a></td>
    <td width="90" align="left" valign="bottom" nowrap="nowrap"><a href="http://www.mysite.com/contact.htm" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('contact','','http://www.mysite.com/elements/contact_glow.png',1)"><img src="http://www.mysite.com/elements/contact_button.png" alt="contact" name="contact" width="80" height="30" border="0" id="contact" /></a></td>
  </tr>
</table>
Any thoughts? I'm sorry that's it's so much code, to read through, but I really appreciate all your help.

Posted: Fri Feb 01, 2008 4:53 am
by tiffany
Oops. I don't see how to edit my prior post. In the file path, I had excluded a slash. I fixed it, but the problems still exist.

i.e http://www.mysite.com/elementshome_glow.png FIXED TO
http://www.mysite.com/elements/home_glow.png

Posted: Fri Feb 01, 2008 12:41 pm
by garvinhicking
Hi!

Hm, I don't understand why using {literal} should not work. How was the complete code you tried, what was your result?

Your actual URL would also help us to debug this. :)

Regards,
Garvin