By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,664 Members | 1,669 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,664 IT Pros & Developers. It's quick & easy.

Help with "un-PHP'ing" some code...

P: n/a
Hello all.
Can someone help out ? I found this PHP code that works just fine, however,
I am trying to put it back into its original Javascript form.

I am still learning the syntax, etc. for Javascript, so I'm not really sure
what needs
to be removed and kept.

I was trying the basic search/replaces, but always ended up with Javascript
errors.
Here is the code:

Ultimately, all it does it allow me to create a "tooltip" box which I use to
float over
images (i.e. copyright information and such). Eventually, I would like to
completely
replace the JS code with either some fancy CSS or something else (since more
and
more I read I see about trying to cut back on JS code)

echo "<script language = \"javascript\">\n";
echo "<!--\n";
echo "var ie = document.all ? 1 : 0\n";
echo "var ns = document.layers ? 1 : 0\n";
echo "if(ns){doc = \"document.\"; sty = \"\"}\n";
echo "if(ie){doc = \"document.all.\"; sty = \".style\"}\n";
echo "var initialize = 0\n";
echo "var Ex, Ey, topColor, subColor, ContentInfo\n";
echo "if(ie){\n";
echo "Ex = \"event.x\"\n";
echo "Ey = \"event.y\"\n";
echo "topColor = \"#7D92A9\"\n";
echo "subColor = \"#A5B4C4\"\n";
echo "}\n";
echo "if(ns){\n";
echo "Ex = \"e.pageX\"\n";
echo "Ey = \"e.pageY\"\n";
echo "window.captureEvents(Event.MOUSEMOVE)\n";
echo "window.onmousemove=overhere\n";
echo "topColor = \"#7D92A9\"\n";
echo "subColor = \"#A5B4C4\"\n";
echo "}\n";
echo "function MoveToolTip(layerName, FromTop, FromLeft, e){\n";
echo "if(ie){eval(doc + layerName + sty + \".top = \" + (eval(FromTop) +
document.body.scrollTop))}\n";
echo "if(ns){eval(doc + layerName + sty + \".top = \" +
eval(FromTop))}\n";
echo "eval(doc + layerName + sty + \".left = \" + (eval(FromLeft) + 15))\n";
echo "}\n";
echo "function ReplaceContent(layerName){\n";
echo "if(ie){document.all[layerName].innerHTML = ContentInfo}\n";
echo "if(ns){\n";
echo "with(document.layers[layerName].document)\n";
echo "{\n";
echo " open();\n";
echo " write(ContentInfo);\n";
echo " close();\n";
echo "}\n";
echo "}\n";
echo "}\n";
echo "function Activate(){initialize=1}\n";
echo "function deActivate(){initialize=0}\n";
echo "function overhere(e){\n";
echo "if(initialize){\n";
echo "MoveToolTip(\"ToolTip\", Ey, Ex, e)\n";
echo "eval(doc + \"ToolTip\" + sty + \".visibility = 'visible'\")\n";
echo "}\n";
echo "else{\n";
echo "MoveToolTip(\"ToolTip\", 0, 0)\n";
echo "eval(doc + \"ToolTip\" + sty + \".visibility = 'hidden'\")\n";
echo "}\n";
echo "}\n";
echo "function EnterContent(layerName, TTitle, TContent){\n";
echo "ContentInfo = '<table border=\"0\" width=\"150\" cellspacing=\"0\"
cellpadding=\"0\">'+\n";
echo "'<tr><td width=\"100%\" bgcolor=\"#000000\">'+\n";
echo "'<table border=\"0\" width=\"100%\" cellspacing=\"1\"
cellpadding=\"0\">'+\n";
echo "'<tr><td width=\"100%\" bgcolor='+topColor+'>'+\n";
echo "'<table border=\"0\" width=\"90%\" cellspacing=\"0\" cellpadding=\"0\"
align=\"center\">'+\n";
echo "'<tr><td width=\"100%\">'+\n";
echo "'<center><font
class=\"tooltiptitle\">&nbsp;'+TTitle+'</font></center>'+\n";
echo "'</td></tr>'+\n";
echo "'</table>'+\n";
echo "'</td></tr>'+\n";
echo "'<tr><td width=\"100%\" bgcolor='+subColor+'>'+\n";
echo "'<table border=\"0\" width=\"90%\" cellpadding=\"0\" cellspacing=\"1\"
align=\"center\">'+\n";
echo "'<tr><td width=\"100%\">'+\n";
echo "'<center><font
class=\"tooltipcontent\">'+TContent+'</font></center>'+\n";
echo "'</td></tr>'+\n";
echo "'</table>'+\n";
echo "'</td></tr>'+\n";
echo "'</table>'+\n";
echo "'</td></tr>'+\n";
echo "'</table>';\n";
echo "ReplaceContent(layerName)\n";
echo "}\n";
echo "//-->\n";
echo "</script>";
Jul 16 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

On 30-Jul-2003, "fartsniff" <fa**@sniff.com> wrote:
Can someone help out ? I found this PHP code that works just fine,
however,
I am trying to put it back into its original Javascript form.

I am still learning the syntax, etc. for Javascript, so I'm not really
sure
what needs
to be removed and kept.


remove the echo " and the \n"; from each line
change the \" to "

this should be it, I haven't tested it--
<script language = "javascript">
<!--
var ie = document.all ? 1 : 0
var ns = document.layers ? 1 : 0
if(ns){doc = "document."; sty = ""}
if(ie){doc = "document.all."; sty = ".style"}
var initialize = 0
var Ex, Ey, topColor, subColor, ContentInfo
if(ie){
Ex = "event.x"
Ey = "event.y"
topColor = "#7D92A9"
subColor = "#A5B4C4"
}
if(ns){
Ex = "e.pageX"
Ey = "e.pageY"
window.captureEvents(Event.MOUSEMOVE)
window.onmousemove=overhere
topColor = "#7D92A9"
subColor = "#A5B4C4"
}
function MoveToolTip(layerName, FromTop, FromLeft, e){
if(ie){eval(doc + layerName + sty + ".top = " + (eval(FromTop) +
document.body.scrollTop))}
if(ns){eval(doc + layerName + sty + ".top = " + eval(FromTop))}
eval(doc + layerName + sty + ".left = " + (eval(FromLeft) + 15))
}
function ReplaceContent(layerName){
if(ie){document.all[layerName].innerHTML = ContentInfo}
if(ns){
with(document.layers[layerName].document)
{
open();
write(ContentInfo);
close();
}
}
}
function Activate(){initialize=1}
function deActivate(){initialize=0}
function overhere(e){
if(initialize){
MoveToolTip("ToolTip", Ey, Ex, e)
eval(doc + "ToolTip" + sty + ".visibility = 'visible'")
}
else{
MoveToolTip("ToolTip", 0, 0)
eval(doc + "ToolTip" + sty + ".visibility = 'hidden'")
}
}
function EnterContent(layerName, TTitle, TContent){
ContentInfo = '<table border="0" width="150" cellspacing="0"
cellpadding="0">'+
'<tr><td width="100%" bgcolor="#000000">'+
'<table border="0" width="100%" cellspacing="1" cellpadding="0">'+
'<tr><td width="100%" bgcolor='+topColor+'>'+
'<table border="0" width="90%" cellspacing="0" cellpadding="0"
align="center">'+
'<tr><td width="100%">'+
'<center><font class="tooltiptitle">&nbsp;'+TTitle+'</font></center>'+
'</td></tr>'+
'</table>'+
'</td></tr>'+
'<tr><td width="100%" bgcolor='+subColor+'>'+
'<table border="0" width="90%" cellpadding="0" cellspacing="1"
align="center">'+
'<tr><td width="100%">'+
'<center><font class="tooltipcontent">'+TContent+'</font></center>'+
'</td></tr>'+
'</table>'+
'</td></tr>'+
'</table>'+
'</td></tr>'+
'</table>';
ReplaceContent(layerName)
}
//-->
</script>


--
Tom Thackrey
www.creative-light.com
Jul 16 '05 #2

P: n/a
i am such a boob. i cannot believe it ;) i concentrate on things so hard
some times
that i overlook the obvious.

thanks for the tip/help.

"jack" <ja**@croatiabiz.com> wrote in message
news:bg**********@ls219.htnet.hr...
fartsniff wrote:
Hello all.
Can someone help out ? I found this PHP code that works just fine,
however, I am trying to put it back into its original Javascript form.


execute it in php, then view source :))))))

--
--- --- --- --- --- --- ---
ja**@croatiabiz.com

Jul 16 '05 #3

P: n/a
thank you also. i am still playing with CSS, and was able to come up with
this so far since
my original post.

<style type="text/css">
p.link a:hover {background-color: #2B2E21;;color:#fff;}
p.link a:link span{display: none;}
p.link a:visited span{display: none;}
p.link a:hover span {
position: absolute;
margin:5px 0px 0px 10px;
background-color: beige;
max-width:220;
padding: 2px 10px 2px 10px;
border: 1px solid #C0C0C0;
font-family: Verdana;
font-size: 12px;
color: #336699;
text-align:left;
display: block;
}
</style>
<p class="link"><a
href="#">sample<span>line1<br>line2<br>line3</span></a></p>

not sure which is better, but just in case JS isnt enabled i think the CSS
would still work.
thanks again.

"Tom Thackrey" <to***@creative-light.com> wrote in message
news:o7****************@newssvr24.news.prodigy.com ...

On 30-Jul-2003, "fartsniff" <fa**@sniff.com> wrote:
Can someone help out ? I found this PHP code that works just fine,
however,
I am trying to put it back into its original Javascript form.

I am still learning the syntax, etc. for Javascript, so I'm not really
sure
what needs
to be removed and kept.


remove the echo " and the \n"; from each line
change the \" to "

this should be it, I haven't tested it--
<script language = "javascript">
<!--
var ie = document.all ? 1 : 0
var ns = document.layers ? 1 : 0
if(ns){doc = "document."; sty = ""}
if(ie){doc = "document.all."; sty = ".style"}
var initialize = 0
var Ex, Ey, topColor, subColor, ContentInfo
if(ie){
Ex = "event.x"
Ey = "event.y"
topColor = "#7D92A9"
subColor = "#A5B4C4"
}
if(ns){
Ex = "e.pageX"
Ey = "e.pageY"
window.captureEvents(Event.MOUSEMOVE)
window.onmousemove=overhere
topColor = "#7D92A9"
subColor = "#A5B4C4"
}
function MoveToolTip(layerName, FromTop, FromLeft, e){
if(ie){eval(doc + layerName + sty + ".top = " + (eval(FromTop) +
document.body.scrollTop))}
if(ns){eval(doc + layerName + sty + ".top = " + eval(FromTop))}
eval(doc + layerName + sty + ".left = " + (eval(FromLeft) + 15))
}
function ReplaceContent(layerName){
if(ie){document.all[layerName].innerHTML = ContentInfo}
if(ns){
with(document.layers[layerName].document)
{
open();
write(ContentInfo);
close();
}
}
}
function Activate(){initialize=1}
function deActivate(){initialize=0}
function overhere(e){
if(initialize){
MoveToolTip("ToolTip", Ey, Ex, e)
eval(doc + "ToolTip" + sty + ".visibility = 'visible'")
}
else{
MoveToolTip("ToolTip", 0, 0)
eval(doc + "ToolTip" + sty + ".visibility = 'hidden'")
}
}
function EnterContent(layerName, TTitle, TContent){
ContentInfo = '<table border="0" width="150" cellspacing="0"
cellpadding="0">'+
'<tr><td width="100%" bgcolor="#000000">'+
'<table border="0" width="100%" cellspacing="1" cellpadding="0">'+
'<tr><td width="100%" bgcolor='+topColor+'>'+
'<table border="0" width="90%" cellspacing="0" cellpadding="0"
align="center">'+
'<tr><td width="100%">'+
'<center><font class="tooltiptitle">&nbsp;'+TTitle+'</font></center>'+
'</td></tr>'+
'</table>'+
'</td></tr>'+
'<tr><td width="100%" bgcolor='+subColor+'>'+
'<table border="0" width="90%" cellpadding="0" cellspacing="1"
align="center">'+
'<tr><td width="100%">'+
'<center><font class="tooltipcontent">'+TContent+'</font></center>'+
'</td></tr>'+
'</table>'+
'</td></tr>'+
'</table>'+
'</td></tr>'+
'</table>';
ReplaceContent(layerName)
}
//-->
</script>


--
Tom Thackrey
www.creative-light.com

Jul 16 '05 #4

P: n/a
On Wed, 30 Jul 2003 22:44:44 -0800, "fartsniff" <fa**@sniff.com>
wrote:
Ultimately, all it does it allow me to create a "tooltip" box which I use to
float over
images (i.e. copyright information and such). Eventually, I would like to
completely
replace the JS code with either some fancy CSS or something else (since more
and
more I read I see about trying to cut back on JS code)


You can use the title attriute to create a tooltip, e.g.

<img src='image.gif' alt='appropriate alt text' title='This image is
copyright, and not to be used without permission'>

--
David (please modify address to david@ before replying!)
Jul 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.