Author |
Message |
mrix
Client

Joined: Dec 04, 2004
Posts: 757
|
Posted:
Sat Jun 18, 2005 7:40 am |
|
Hi all, I have this peice of java script and would like to add it to a block, I have added it to a block as it is and it works but outside of the block which can been seen here if you scroll down the page you will see a dice that shows random numbers etc http://www.horse-racing-league.com , what code do I need to add to get it working inside the block?
many thanks for any help
Cheers
mrix |
|
|
|
 |
Manuel
Regular


Joined: May 28, 2005
Posts: 90
|
Posted:
Sat Jun 18, 2005 8:08 am |
|
you need to put the javascript code in blocks/yourblock.php
at the end of file, before ?> add this:
Code:
$content .= '
PASTE CODE HERE
';
|
|
_________________ Only registered users can see links on this board! Get registered or login! |
|
|
 |
Raven
Site Admin/Owner

Joined: Aug 27, 2002
Posts: 17088
|
Posted:
Sat Jun 18, 2005 8:52 am |
|
|
|
 |
mrix

|
Posted:
Sat Jun 18, 2005 1:33 pm |
|
Many thanks all is working fin with that extra code
Cheers
mrix |
|
|
|
 |
mrix

|
Posted:
Sun Jun 19, 2005 6:42 am |
|
Hi again, can i change it so only the admin can press the dice button but for all members and visitors to see it on the front page?
would this be complex to do or straight forward?
Thanks for any help
Cheers
mrix I did post the code or try to but the site banned me for some reason? |
|
|
|
 |
montego
Site Admin

Joined: Aug 29, 2004
Posts: 9457
Location: Arizona
|
Posted:
Sun Jun 19, 2005 8:04 am |
|
the site banned you because you tried to post J avascript. If you change each of your J avascript statements to have a space between one of more letters (like what I did here), it would have posted.
To answer your question, it IS rather straight forward. You make the block visible to all via the nuke admin tool, but within your block, you have to add code to check to see if an admin is logged on. If the admin is the one logged on, then you build the necessary link around the graphic. If the admin is NOT the one logged on, then leave off the link.
Regards,
montego |
_________________ Only registered users can see links on this board! Get registered or login!
Only registered users can see links on this board! Get registered or login! |
|
|
 |
mrix

|
Posted:
Sun Jun 19, 2005 8:28 am |
|
I understand the first bit but the second "If the admin is the one logged on, then you build the necessary link around the graphic. If the admin is NOT the one logged on, then leave off the link" is behond me to be honest , is it possible if you good explain the edits in my code below ?
many thanks for your time
Cheers
mrix
this is my codeCode:<?php
if (eregi("block-Dice.php",$PHP_SELF)) {
Header("Location: index.php");
die();
}
$content .= '
scripttagwashere
/*
*/
//preload the three images first
var face0=new Image()
face0.src="d1.gif"
var face1=new Image()
face1.src="d2.gif"
var face2=new Image()
face2.src="d3.gif"
var face3=new Image()
face3.src="d4.gif"
var face4=new Image()
face4.src="d5.gif"
var face5=new Image()
face5.src="d6.gif"
scripttagwashere
<img src="d1.gif" name="mydice">
<form>
<input type="button" value="Throw dice!" onClick="throwdice()">
</form>
scripttagwashere
function throwdice(){
//create a random integer between 0 and 1
var randomdice=Math.round(Math.random()*2)
document.images["mydice"].src=eval("face"+randomdice+".src")
}
scripttagwashere
';
?>
|
|
|
|
|
 |
montego

|
Posted:
Sun Jun 19, 2005 10:22 am |
|
Personally, I do not like the way you have coded the $content variable build, but I don't have time to recode it for you. Here is one suggestion (others here with more experience might suggest a more robust solution):
Code:
if (is_admin($admin)) {
$content .= "<form>
<input type=\"button\" value=\"Throw dice!\" onClick=\"throwdice()\">
</form>";
}
|
You need to figure out the proper syntax based on your own preference. you will also need to add the following code after your eregi if statement:
global $admin
the if statement identified above will show the Throw Dice button only if you are logged in as the site's admin (i.e., through admin.php). I don't have time right now to find and give you the code to work for all site admins/authors.
Regards,
montego |
|
|
|
 |
mrix

|
Posted:
Sun Jun 19, 2005 11:49 am |
|
Great montego, I appriciate your time on this to help
Cheers
mrix |
|
|
|
 |
Manuel

|
Posted:
Sun Jun 19, 2005 10:21 pm |
|
cause you have only one definition of $content i suggest to you to replace $content .= with $content = |
|
|
|
 |
|