rupsen Posted October 11, 2008 Share Posted October 11, 2008 i have a php script that generates a javascript code for a infobar now i get a javascript syntaxiserror it says it's in this line: .prototype.setContent=function(data){ here is the actual javascript code: <script type="text/javascript"> function (){ this.displayfreq="always" this.content='<a href="javascript:.close()\"><img src="plugins/infobar/img/close.gif" style=\"width: 14px; height: 14px; float: right; border: 0; margin-right: 5px" /></a>' } .prototype.setContent=function(data){ this.content=this.content+data document.write('<div id="" style="top: -500px">'+this.content+'</div>') } .prototype.animatetoview=function(){ var barinstance=this if (parseInt(this.barref.style.top)<0){ this.barref.style.top=parseInt(this.barref.style.top)+5+"px" setTimeout(function(){barinstance.animatetoview()}, 50) } else{ if (document.all && !window.XMLHttpRequest) this.barref.style.setExpression("top", 'document.compatMode=="CSS1Compat"? document.documentElement.scrollTop+"px" : body.scrollTop+"px"') else this.barref.style.top=0 } } .close=function(){ document.getElementById("").style.display="none" if (this.displayfreq=="session") document.cookie="shown=1;path=/" } .prototype.setfrequency=function(type){ this.displayfreq=type } .prototype.initialize=function(){ if (this.displayfreq=="session" && document.cookie.indexOf("infobarshown")==-1 || this.displayfreq=="always"){ this.barref=document.getElementById("") this.barheight=parseInt(this.barref.offsetHeight) this.barref.style.top=this.barheight*(-1)+"px" this.animatetoview() } } window.onunload=function(){ this.barref=null } </script> and here is the php script: $infobox_header .= '<script type="text/javascript"> function '.$event.'(){ this.displayfreq="always" this.content=\'<a href="javascript:'.$event.'.close()\"><img src="plugins/infobar/img/close.gif" style=\"width: 14px; height: 14px; float: right; border: 0; margin-right: 5px" /></a>\' } '.$event.'.prototype.setContent=function(data){ this.content=this.content+data document.write(\'<div id="'.$event.'" style="top: -500px">\'+this.content+\'</div>\') } '.$event.'.prototype.animatetoview=function(){ var barinstance=this if (parseInt(this.barref.style.top)<0){ this.barref.style.top=parseInt(this.barref.style.top)+5+"px" setTimeout(function(){barinstance.animatetoview()}, 50) } else{ if (document.all && !window.XMLHttpRequest) this.barref.style.setExpression("top", \'document.compatMode=="CSS1Compat"? document.documentElement.scrollTop+"px" : body.scrollTop+"px"\') else this.barref.style.top=0 } } '.$event.'.close=function(){ document.getElementById("'.$event.'").style.display="none" if (this.displayfreq=="session") document.cookie="'.$event.'shown=1;path=/" } '.$event.'.prototype.setfrequency=function(type){ this.displayfreq=type } '.$event.'.prototype.initialize=function(){ if (this.displayfreq=="session" && document.cookie.indexOf("infobarshown")==-1 || this.displayfreq=="always"){ this.barref=document.getElementById("'.$event.'") this.barheight=parseInt(this.barref.offsetHeight) this.barref.style.top=this.barheight*(-1)+"px" this.animatetoview() } } window.onunload=function(){ this.barref=null } </script> '; so if anybode knows what is wrong, and how to make it correct in the php code, that would be great Link to comment https://forums.phpfreaks.com/topic/127959-infobar-help/ Share on other sites More sharing options...
JasonLewis Posted October 11, 2008 Share Posted October 11, 2008 Don't you need to specify something to have a prototype? What's the actual error? Link to comment https://forums.phpfreaks.com/topic/127959-infobar-help/#findComment-662613 Share on other sites More sharing options...
rupsen Posted October 11, 2008 Author Share Posted October 11, 2008 i get the following line: 67 char: 1 error: syntaxiserror code: 0 line 67 is the following: .prototype.setContent=function(data){ the full script is in my first post Link to comment https://forums.phpfreaks.com/topic/127959-infobar-help/#findComment-662616 Share on other sites More sharing options...
JasonLewis Posted October 11, 2008 Share Posted October 11, 2008 Your $event variable isn't working. Take a look at your code and you can see that, because your function isn't called anything and there is nothing in front of .prototype. Link to comment https://forums.phpfreaks.com/topic/127959-infobar-help/#findComment-662638 Share on other sites More sharing options...
rupsen Posted October 11, 2008 Author Share Posted October 11, 2008 but still it's working, so what should i edit in the php script? im very new to this so i dont understand the most terms btw here is the complete php code: require("plugins/infobar/lang/infobar.".$usr['lang'].".lang.php"); // Check if non-registered user if ($usr['maingrp'] <= 0){ $event = "informationbar"; $infobox_body .= '<script type="text/javascript"> var infobar=new '.$event.'() infobar.setContent(\''.$L['member'].'<a href=\"users.php?m=register\">'.$L['member_click'].'</a>\')'; if ($cfg['plugin']['infobar']['sessionregister'] == "Yes" ){ $infobox_body .= ' infobar.setFrequency("session") infobar.initialize() </script> '; } else { $infobox_body .= ' infobar.initialize() </script> '; } } // Check if user has new PM if ($usr['newpm']){ $event = "informationbarpm"; $infobox_body .= '<script type="text/javascript"> var infobar=new '.$event.'() infobar.setContent(\''.$L['pm'].'<a href=\"pm.php\">'.$L['pm_click'].'</a>\')'; if ($cfg['plugin']['infobar']['sessionpm'] == "Yes" ){ $infobox_body .= ' infobar.setFrequency("session") infobar.initialize() </script> '; } else { $infobox_body .= ' infobar.initialize() </script> '; } } // Feed out header javascript functions $infobox_header .= '<script type="text/javascript"> function '.$event.'(){ this.displayfreq="always" this.content=\'<a href="javascript:'.$event.'.close()\"><img src="plugins/infobar/img/close.gif" style=\"width: 14px; height: 14px; float: right; border: 0; margin-right: 5px" /></a>\' } '.$event.'.prototype.setContent=function(data){ this.content=this.content+data document.write(\'<div id="'.$event.'" style="top: -500px">\'+this.content+\'</div>\') } '.$event.'.prototype.animatetoview=function(){ var barinstance=this if (parseInt(this.barref.style.top)<0){ this.barref.style.top=parseInt(this.barref.style.top)+5+"px" setTimeout(function(){barinstance.animatetoview()}, 50) } else{ if (document.all && !window.XMLHttpRequest) this.barref.style.setExpression("top", \'document.compatMode=="CSS1Compat"? document.documentElement.scrollTop+"px" : body.scrollTop+"px"\') else this.barref.style.top=0 } } '.$event.'.close=function(){ document.getElementById("'.$event.'").style.display="none" if (this.displayfreq=="session") document.cookie="'.$event.'shown=1;path=/" } '.$event.'.prototype.setfrequency=function(type){ this.displayfreq=type } '.$event.'.prototype.initialize=function(){ if (this.displayfreq=="session" && document.cookie.indexOf("infobarshown")==-1 || this.displayfreq=="always"){ this.barref=document.getElementById("'.$event.'") this.barheight=parseInt(this.barref.offsetHeight) this.barref.style.top=this.barheight*(-1)+"px" this.animatetoview() } } window.onunload=function(){ this.barref=null } </script> '; // And throw the stuff out $t-> assign(array( "INFOBOX_HEADER" => $infobox_header, "INFOBOX_BODY" => $infobox_body, "HEADER_METAS" => $out['metas'].'<link rel="stylesheet" href="./plugins/infobar/infobar.css" type="text/css" title="Information Bar" />', )); ?> Link to comment https://forums.phpfreaks.com/topic/127959-infobar-help/#findComment-662643 Share on other sites More sharing options...
JasonLewis Posted October 11, 2008 Share Posted October 11, 2008 Find where your $event variable is being set, and make sure it's being set. Because throughout your whole script it is not working. Link to comment https://forums.phpfreaks.com/topic/127959-infobar-help/#findComment-662645 Share on other sites More sharing options...
rupsen Posted October 11, 2008 Author Share Posted October 11, 2008 wait i get it, the infobar only shows when u are not registerd or when u have a new pm, so when u dont have a new pm and ur registerd $event isn't set..... Link to comment https://forums.phpfreaks.com/topic/127959-infobar-help/#findComment-662775 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.