TinyPortal

Development => Block Codes => Topic started by: Xarcell on November 17, 2005, 04:42:32 AM

Title: Countdown Block
Post by: Xarcell on November 17, 2005, 04:42:32 AM
I found a script here:

http://www.dynamicdrive.com/dynamicindex6/dhtmlcount.htm

It's javascript, but it works very well and is customizable. Just place it in a javascript/html block.
Title: Re: Countdown Block
Post by: Wizard on December 11, 2005, 01:44:31 AM
I use Dynamic Drive all the time for my site. It's a very good resource, and if you ever need a DHTML script, it should be the first place you look. Right now I'm using the countdown script for the time until Christmas day. :D
Title: Re: Countdown Block
Post by: Amay_Zing on March 22, 2006, 03:09:15 PM
Hey man ;D

I am having problems with mine it doesn't countdown correctly ie it is looking at some current time that is 8 hours ahead.  Do you have a fix on this?
Thanks
Title: Re: Countdown Block
Post by: technodragon73 on March 22, 2006, 03:19:32 PM
it is probably using your server time rather than your board time...
Title: Re: Countdown Block
Post by: Amay_Zing on March 22, 2006, 08:55:29 PM
Sorted now thank you
Title: Re: Countdown Block
Post by: qwe3 on March 31, 2006, 04:39:36 AM
I like it, counting down to summer.   :2funny:
Title: Re: Countdown Block
Post by: TwinsX2Dad on March 31, 2006, 07:21:27 AM
Quote from: qwe3 on March 31, 2006, 04:39:36 AM
I like it, counting down to summer.   :2funny:

What if your visitor is from down under?
Title: Re: Countdown Block
Post by: qwe3 on March 31, 2006, 01:49:20 PM
Funny you should bring that up.  One of my mods is from Sidney   :2funny:
Title: Re: Countdown Block
Post by: TwinsX2Dad on March 31, 2006, 06:33:15 PM
That might not be too nice - advertising your impending warm weather while theirs is getting colder.

Oh, never mind - I am in Phoenix - we like to rub it in every December, when it is freezing in Queens and broiling in Queensland.

Springlike weather for much of the year does that.......   ;D  :2funny:   ;D
Title: Re: Countdown Block
Post by: Shane84 on December 09, 2006, 09:58:23 AM
Sadly that is about the most confusing set of codes I've ever seen :(

I was hoping to install a countdown timer that would automatically reset each week.  After looking at their codes I decided I was no match for them and manually editing the dates every week would be too time consuming.  Does anyone have any ideas how to create a weekly countdown timer?  Either using these codes or perhaps using another countown timer?  If so I would be much appreciative.
Title: Re: Countdown Block
Post by: JPDeni on December 09, 2006, 04:14:27 PM
What exactly do you want to do? Something like counting down every week to Monday at 8pm? If so, I think I know of a way to do it, combining a different javascript and php.
Title: Re: Countdown Block
Post by: PowerPyx on December 09, 2006, 04:29:17 PM

I'm using the following one (scriptbox) and to update it takes 15 secs... not more.

to reset the date you just have to change the date in STEP 1


<script language="JavaScript1.2">

/*
Dynamic countdown Script- Ã...  Dynamic Drive (www.dynamicdrive.com)
For full source code, 100's more DHTML scripts, and TOS,
visit http://www.dynamicdrive.com
*/


function setcountdown(theyear,themonth,theday){
yr=theyear;mo=themonth;da=theday
}

//////////CONFIGURE THE COUNTDOWN SCRIPT HERE//////////////////

//STEP 1: Configure the countdown-to date, in the format year, month, day:
setcountdown(2006,12,24)

//STEP 2: Change the two text below to reflect the occasion, and message to display on that occasion, respectively
var occasion="Weihnachten!"
var message_on_occasion="Frohes Fest euch allen!"

//STEP 3: Configure the below 5 variables to set the width, height, background color, and text style of the countdown area
var countdownwidth='360px'
var countdownheight='20px'
var countdownbgcolor=''
var opentags='<font face="Verdana"><center>'
var closetags='</font></center>'

//////////DO NOT EDIT PASS THIS LINE//////////////////

var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
var crosscount=''

function start_countdown(){
if (document.layers)
document.countdownnsmain.visibility="show"
else if (document.all||document.getElementById)
crosscount=document.getElementById&&!document.all?document.getElementById("countdownie") : countdownie
countdown()
}

if (document.all||document.getElementById)
document.write('<span id="countdownie" style="width:'+countdownwidth+'; background-color:'+countdownbgcolor+'"></span>')

window.onload=start_countdown


function countdown(){
var today=new Date()
var todayy=today.getYear()
if (todayy < 1000)
todayy+=1900
var todaym=today.getMonth()
var todayd=today.getDate()
var todayh=today.getHours()
var todaymin=today.getMinutes()
var todaysec=today.getSeconds()
var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
futurestring=montharray[mo-1]+" "+da+", "+yr
dd=Date.parse(futurestring)-Date.parse(todaystring)
dday=Math.floor(dd/(60*60*1000*24)*1)
dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)
//if on day of occasion
if(dday<=0&&dhour<=0&&dmin<=0&&dsec<=1&&todayd==da){
if (document.layers){
document.countdownnsmain.document.countdownnssub.document.write(opentags+message_on_occasion+closetags)
document.countdownnsmain.document.countdownnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+message_on_occasion+closetags
return
}
//if passed day of occasion
else if (dday<=-1){
if (document.layers){
document.countdownnsmain.document.countdownnssub.document.write(opentags+"Occasion already passed! "+closetags)
document.countdownnsmain.document.countdownnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+"Occasion already passed! "+closetags
return
}
//else, if not yet
else{
if (document.layers){
document.countdownnsmain.document.countdownnssub.document.write(opentags+dday+ " days, "+dhour+" hours, "+dmin+" minutes, and "+dsec+" seconds left until "+occasion+closetags)
document.countdownnsmain.document.countdownnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+dday+ " days, "+dhour+" hours, "+dmin+" minutes, and "+dsec+" seconds left until "+occasion+closetags
}
setTimeout("countdown()",1000)
}
</script>

<ilayer id="countdownnsmain" width=&{countdownwidth}; height=&{countdownheight}; bgColor=&{countdownbgcolor}; visibility=hide><layer id="countdownnssub" width=&{countdownwidth}; height=&{countdownheight}; left=0 top=0></layer></ilayer>




Demo on : http://rad.hrsv.de/forum/index.php


Pyx
Title: Re: Countdown Block
Post by: Shane84 on December 09, 2006, 07:52:37 PM
Quote from: JPDeni on December 09, 2006, 04:14:27 PM
What exactly do you want to do? Something like counting down every week to Monday at 8pm? If so, I think I know of a way to do it, combining a different javascript and php.

Yes :) that is precisely what I would love to do.

Quote from: PowerPyx on December 09, 2006, 04:29:17 PM

I'm using the following one (scriptbox) and to update it takes 15 secs... not more.

to reset the date you just have to change the date in STEP 1

If all else fails I will try this, but I'd really like to find a script because I there are times where I won't be online at the exact moment or perhaps even hours from when the timer would expire.

Background...I'm working on this for a game site that has challenges every week, the challenge times expire at 11pm Pacific USA time.  The following morning the new weeks challenges begin at 7am Pacific USA time.

In a perfect world I'd love a script that would allow for the time to expire at 11pm Pacific USA time on Tuesday and reset the countdown timer at 7am Pacific USA time on Wednesday morning.  I realize that would be much more difficult so I'm not picky or expecting miracles, even a simple reset at the expire time of 11pm Tuesday would work out great for us.
Title: Re: Countdown Block
Post by: JPDeni on December 09, 2006, 08:13:44 PM
Well, I think I can do pretty much what you want.

First, go to this site (http://www.hashemian.com/tools/javascript-countdown.htm) and download the countdown.js script. Put it in the root directory of your SMF/TP setup. You might want to bookmark that site, too, because it's got all the stuff for formatting and such.

Then, put the code below into a php block.


$dayofweek = 'Tuesday';
if (date('l') == $dayofweek)
  $targetdate = date('m/d/Y');
else
  $targetdate = date('m/d/Y',strtotime('next '. $dayofweek));
$targettime = '11:00 PM UTC-0800';
echo '
<script language="JavaScript">
TargetDate = "', $targetdate , ' ' , $targettime, '";
BackColor = "palegreen";
ForeColor = "navy";
CountActive = true;
CountStepper = -1;
LeadingZero = true;
DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
FinishMessage = "It is finally here!";
</script>
<script language="JavaScript" src="countdown.js"></script>';


The FinishMessage should display for about an hour, from 11pm to midnight on Tuesdays. You may have to do a little bit of adjustment, though, when you're determining which day it is. I'm never sure whether the time is actually server time or GMT. But we can likely work that out.

If this is in general what you want, I can share with you the alterations I've done on the javascript, so it might actually do exactly what you have in mind. I haven't tested any further than this, though. And in my tests, it's been the same day where I am and in Greenwich. I'll be interested to know how it works in a few hours. :)
Title: Re: Countdown Block
Post by: Shane84 on December 09, 2006, 08:19:16 PM
I'm glad you responded :)

I was working with that one this morning because already have a countdown timer for christmas and it appears we can't have two countdowns running at the same time.  I'm working on a solution and so it my other admin, she came up with this but I haven't used it yet.

<?
function next_week($target_week_day)
         {         
         $date = getDate();
           
         $day = $date["mday"];
         $week_day = $date["wday"];
         $month = $date["mon"];         
         $year = $date["year"];
         
         //This assumes that if today is a target week day,
         //today's date will be used and not next week's.
         //To change that, just make
         //if($week_day <= $target_week_day)
         //if($week_day < $target_week_day)
         if($week_day <= $target_week_day)
            $days_left = $target_week_day - $week_day;
         else
            $days_left = 7 - ($week_day - $target_week_day);
         
         //This script works by finding out the number of days separating
         //the current date and the next target week day.
         $next_week = getDate(mktime(0, 0, 0, $month, $day + $days_left, $year));
         
         $next_week_html = $next_week["month"] . " " . $next_week["mday"] . " , " . $next_week["year"];
                                             
         return($next_week_html);
         }
?>


EDIT:  Scratch that, it doesn't work.
Title: Re: Countdown Block
Post by: JPDeni on December 09, 2006, 08:31:28 PM
You could probably have another copy of countdown.js and rename it to countdown2.js. And then change the name of the file in the code. I just really like that countdown script. Looks like you do, too. :)

I set up mine to have a start and stop. We have events that last a weekend or more, so I wanted to be able to count down to the start of the event, have a message for when the event was happening and then a message for when the event was over. It was really easy to alter the code, and I'd never done any javascript before.
Title: Re: Countdown Block
Post by: Shane84 on December 09, 2006, 08:34:27 PM
Quote from: JPDeni on December 09, 2006, 08:31:28 PM
You could probably have another copy of countdown.js and rename it to countdown2.js. And then change the name of the file in the code.

We tried that :( in Firefox it stalls one of the counters and in IE it doesn't even show one of the counters.  Both are in seperate folders on the server and named differently, one is countdown.js and the other is countdown1.js.  I do like this code also, it's great and I hope we can get it to work but it won't be the end of the world if we don't :)
Title: Re: Countdown Block
Post by: JPDeni on December 09, 2006, 08:40:43 PM
I see. I hadn't tried, it so, I wasn't sure.

So you don't really need a countdown, right? Would it be enough for the counter to update when the person reloads the page? We could do that completely in php.
Title: Re: Countdown Block
Post by: sburke930 on December 09, 2006, 08:58:45 PM
Quote from: Shane84 on December 09, 2006, 08:19:16 PM
I'm glad you responded :)

I was working with that one this morning because already have a countdown timer for christmas and it appears we can't have two countdowns running at the same time.  I'm working on a solution and so it my other admin, she came up with this but I haven't used it yet.

<?
function next_week($target_week_day)
         {         
         $date = getDate();
           
         $day = $date["mday"];
         $week_day = $date["wday"];
         $month = $date["mon"];         
         $year = $date["year"];
         
         //This assumes that if today is a target week day,
         //today's date will be used and not next week's.
         //To change that, just make
         //if($week_day <= $target_week_day)
         //if($week_day < $target_week_day)
         if($week_day <= $target_week_day)
            $days_left = $target_week_day - $week_day;
         else
            $days_left = 7 - ($week_day - $target_week_day);
         
         //This script works by finding out the number of days separating
         //the current date and the next target week day.
         $next_week = getDate(mktime(0, 0, 0, $month, $day + $days_left, $year));
         
         $next_week_html = $next_week["month"] . " " . $next_week["mday"] . " , " . $next_week["year"];
                                             
         return($next_week_html);
         }
?>


EDIT:  Scratch that, it doesn't work.
It only had an error because you left the <? ?> on it.  HAd you removed those the parsing error would have disappeared.

I think it still needs an echo statement in order for it to give the proper feedback in the block though.  Maybe JPDeni can help with that?
Title: Re: Countdown Block
Post by: JPDeni on December 09, 2006, 11:22:39 PM
I'm happy to help. I just need to know what exactly you want it to do. Do you need a second-by-second countdown? Or do you need something that refreshes when the user reloads the page? Or...?
Title: Re: Countdown Block
Post by: sburke930 on December 09, 2006, 11:56:18 PM
No we do not need a second by second countdown.  Just a simple countdown when a visitor initially comes to the site or each time they refresh would be sufficient.
Title: Re: Countdown Block
Post by: JPDeni on December 10, 2006, 02:25:18 AM
Okay. This should do what you want.

--code deleted. Look down a couple more posts--

This should give you the days, hours and minutes between the time the page is refreshed and the next Tuesday at 11pm. Between Tuesday at 11pm and Wednesday at 7am it should give a different message -- that "Whatever you want to say..." message. I wasn't able to test that fully, so let me know if it doesn't work like you expect it to.
Title: Re: Countdown Block
Post by: sburke930 on December 10, 2006, 03:00:59 AM
It gives me the "whatever you want to say..." message now.  Oh I am so confused.

NM I fixed it...I had to move the echo statement to the bottom...it works now!

Thank you!
Title: Re: Countdown Block
Post by: sburke930 on December 10, 2006, 03:13:16 AM
Small problem though, it says there are 10 days til next Tuesday....now as far I can remember there are only 7 days of the week...right?  :o ;D
Title: Re: Countdown Block
Post by: JPDeni on December 10, 2006, 03:14:33 AM
Post the code you're using, please. It looks like you may have changed it.
Title: Re: Countdown Block
Post by: sburke930 on December 10, 2006, 03:17:38 AM
$dayofweek = 'Tuesday';
if (date('l') <> $dayofweek )
{
  $mon = date('n',strtotime('next '.$dayofweek));
  $day = date('j',strtotime('next '.$dayofweek));
  $year = date('Y',strtotime('next '.$dayofweek));
}
else
{
  $mon = date('n');
  $day = date('j');
  $year = date('Y');
}
$target = mktime(23,0,0,$mon,$day,$year);
$difference = $target - time();
if ($difference > 572000 or $difference < 0) 
{
  $days = floor($difference/(24*60*60));
  $difference -= $days * 24 * 60 * 60;
  $hours = floor($difference / (60 * 60));
  $difference -= $hours * 60 * 60;
  $minutes = floor($difference / 60);
  echo $days . ' days ' . $hours . ' hours ' . $minutes . ' minutes left for the current challenge';
}

else

{
  echo 'Whatever you want to say between the closing of one challenge and the beginning of the next';
}


All I did was move the "else" and echo statement to the bottom
Title: Re: Countdown Block
Post by: JPDeni on December 10, 2006, 03:25:50 AM
Well, moving that code will change everything and make it not work. :) I did have the number wrong, which I'll fix in a second. (Arithmetic was never my strong suit. ;) )

There may be something strange with your system that doesn't know what "next Tuesday" means. It looks like it is making it "a week from next Tuesday."

Try this --


echo '<br />', (date('j',strtotime('next Tuesday'));


Just add it to the bottom of the code. You should get 12 on a line, but I'm thinking you're going to end up with 19. If so, we'll have to subtract a week's worth of seconds from the $difference variable.
Title: Re: Countdown Block
Post by: sburke930 on December 10, 2006, 03:34:00 AM
I am now getting a parse error on line 31.
Title: Re: Countdown Block
Post by: JPDeni on December 10, 2006, 03:40:22 AM
Try this:

$dayofweek = 'Tuesday';
if (date('l') <> $dayofweek )
{
  $mon = date('n',strtotime('next '.$dayofweek));
  $day = date('j',strtotime('next '.$dayofweek));
  $year = date('Y',strtotime('next '.$dayofweek));
}
else
{
  $mon = date('n');
  $day = date('j');
  $year = date('Y');
}
$target = mktime(23,0,0,$mon,$day,$year);
$difference = $target - time();
if ($difference > 604800)
  $difference -= 604800;
if ($difference > 576000 or $difference < 0) 
{
  echo 'Whatever you want to say between the closing of one challenge and the beginning of the next';
}
else
{
  $days = floor($difference/(24*60*60));
  $difference -= $days * 24 * 60 * 60;
  $hours = floor($difference / (60 * 60));
  $difference -= $hours * 60 * 60;
  $minutes = floor($difference / 60);
  echo $days . ' days ' . $hours . ' hours ' . $minutes . ' minutes left for the current challenge';
}
Title: Re: Countdown Block
Post by: sburke930 on December 10, 2006, 03:45:27 AM
Perfecto!

Thank you, thank you, thank you!
Title: Re: Countdown Block
Post by: JPDeni on December 10, 2006, 03:49:07 AM
Let me know what happens on Wednesday morning before 7am, if anybody's awake then. :)
Title: Re: Countdown Block
Post by: sburke930 on December 10, 2006, 04:24:01 AM
I was just looking at it and it seems to be an hour fast.  Is there a quick fix for that?

(My server is located in the one state that does not observe daylight savings time.)
Title: Re: Countdown Block
Post by: JPDeni on December 10, 2006, 04:43:47 AM
Work with the line


$target = mktime(23,0,0,$mon,$day,$year);


Try changing the 23 to 22. If you're suddenly two hours off, go the other way and try 24.
Title: Re: Countdown Block
Post by: sburke930 on December 10, 2006, 04:50:41 AM
okay thank you!
Title: Re: Countdown Block
Post by: insanemustang on May 04, 2007, 09:31:56 PM
Quote from: PowerPyx on December 09, 2006, 04:29:17 PM

I'm using the following one (scriptbox) and to update it takes 15 secs... not more.

to reset the date you just have to change the date in STEP 1


<script language="JavaScript1.2">

/*
Dynamic countdown Script- Ã,Å  Dynamic Drive (www.dynamicdrive.com)
For full source code, 100's more DHTML scripts, and TOS,
visit http://www.dynamicdrive.com
*/


function setcountdown(theyear,themonth,theday){
yr=theyear;mo=themonth;da=theday
}

//////////CONFIGURE THE COUNTDOWN SCRIPT HERE//////////////////

//STEP 1: Configure the countdown-to date, in the format year, month, day:
setcountdown(2006,12,24)

//STEP 2: Change the two text below to reflect the occasion, and message to display on that occasion, respectively
var occasion="Weihnachten!"
var message_on_occasion="Frohes Fest euch allen!"

//STEP 3: Configure the below 5 variables to set the width, height, background color, and text style of the countdown area
var countdownwidth='360px'
var countdownheight='20px'
var countdownbgcolor=''
var opentags='<font face="Verdana"><center>'
var closetags='</font></center>'

//////////DO NOT EDIT PASS THIS LINE//////////////////

var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
var crosscount=''

function start_countdown(){
if (document.layers)
document.countdownnsmain.visibility="show"
else if (document.all||document.getElementById)
crosscount=document.getElementById&&!document.all?document.getElementById("countdownie") : countdownie
countdown()
}

if (document.all||document.getElementById)
document.write('<span id="countdownie" style="width:'+countdownwidth+'; background-color:'+countdownbgcolor+'"></span>')

window.onload=start_countdown


function countdown(){
var today=new Date()
var todayy=today.getYear()
if (todayy < 1000)
todayy+=1900
var todaym=today.getMonth()
var todayd=today.getDate()
var todayh=today.getHours()
var todaymin=today.getMinutes()
var todaysec=today.getSeconds()
var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
futurestring=montharray[mo-1]+" "+da+", "+yr
dd=Date.parse(futurestring)-Date.parse(todaystring)
dday=Math.floor(dd/(60*60*1000*24)*1)
dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)
//if on day of occasion
if(dday<=0&&dhour<=0&&dmin<=0&&dsec<=1&&todayd==da){
if (document.layers){
document.countdownnsmain.document.countdownnssub.document.write(opentags+message_on_occasion+closetags)
document.countdownnsmain.document.countdownnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+message_on_occasion+closetags
return
}
//if passed day of occasion
else if (dday<=-1){
if (document.layers){
document.countdownnsmain.document.countdownnssub.document.write(opentags+"Occasion already passed! "+closetags)
document.countdownnsmain.document.countdownnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+"Occasion already passed! "+closetags
return
}
//else, if not yet
else{
if (document.layers){
document.countdownnsmain.document.countdownnssub.document.write(opentags+dday+ " days, "+dhour+" hours, "+dmin+" minutes, and "+dsec+" seconds left until "+occasion+closetags)
document.countdownnsmain.document.countdownnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+dday+ " days, "+dhour+" hours, "+dmin+" minutes, and "+dsec+" seconds left until "+occasion+closetags
}
setTimeout("countdown()",1000)
}
</script>

<ilayer id="countdownnsmain" width=&{countdownwidth}; height=&{countdownheight}; bgColor=&{countdownbgcolor}; visibility=hide><layer id="countdownnssub" width=&{countdownwidth}; height=&{countdownheight}; left=0 top=0></layer></ilayer>




Demo on : http://rad.hrsv.de/forum/index.php


Pyx

I can only get this code to show up if it's a rightside block.  As soon as I move it to the middle, or the left side, it will not show the countdown.
Title: Re: Countdown Block
Post by: tick on May 05, 2007, 04:27:47 AM
Quote from: JPDeni on December 10, 2006, 03:40:22 AM
Try this:

$dayofweek = 'Tuesday';
if (date('l') <> $dayofweek )
{
  $mon = date('n',strtotime('next '.$dayofweek));
  $day = date('j',strtotime('next '.$dayofweek));
  $year = date('Y',strtotime('next '.$dayofweek));
}
else
{
  $mon = date('n');
  $day = date('j');
  $year = date('Y');
}
$target = mktime(23,0,0,$mon,$day,$year);
$difference = $target - time();
if ($difference > 604800)
  $difference -= 604800;
if ($difference > 576000 or $difference < 0) 
{
  echo 'Whatever you want to say between the closing of one challenge and the beginning of the next';
}
else
{
  $days = floor($difference/(24*60*60));
  $difference -= $days * 24 * 60 * 60;
  $hours = floor($difference / (60 * 60));
  $difference -= $hours * 60 * 60;
  $minutes = floor($difference / 60);
  echo $days . ' days ' . $hours . ' hours ' . $minutes . ' minutes left for the current challenge';
}


Where at  in this code do I edit for the start time and finish time. 
Title: Re: Countdown Block
Post by: tick on May 05, 2007, 04:34:07 PM
Quote from: PowerPyx on December 09, 2006, 04:29:17 PM

I'm using the following one (scriptbox) and to update it takes 15 secs... not more.

to reset the date you just have to change the date in STEP 1


<script language="JavaScript1.2">

/*
Dynamic countdown Script- Ã...  Dynamic Drive (www.dynamicdrive.com)
For full source code, 100's more DHTML scripts, and TOS,
visit http://www.dynamicdrive.com
*/


function setcountdown(theyear,themonth,theday){
yr=theyear;mo=themonth;da=theday
}

//////////CONFIGURE THE COUNTDOWN SCRIPT HERE//////////////////

//STEP 1: Configure the countdown-to date, in the format year, month, day:
setcountdown(2006,12,24)

//STEP 2: Change the two text below to reflect the occasion, and message to display on that occasion, respectively
var occasion="Weihnachten!"
var message_on_occasion="Frohes Fest euch allen!"

//STEP 3: Configure the below 5 variables to set the width, height, background color, and text style of the countdown area


//////////DO NOT EDIT PASS THIS LINE//////////////////

var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
var crosscount=''

function start_countdown(){
if (document.layers)
document.countdownnsmain.visibility="show"
else if (document.all||document.getElementById)
crosscount=document.getElementById&&!document.all?document.getElementById("countdownie") : countdownie
countdown()
}

if (document.all||document.getElementById)
document.write('<span id="countdownie" style="width:'+countdownwidth+'; background-color:'+countdownbgcolor+'"></span>')

window.onload=start_countdown


function countdown(){
var today=new Date()
var todayy=today.getYear()
if (todayy < 1000)
todayy+=1900
var todaym=today.getMonth()
var todayd=today.getDate()
var todayh=today.getHours()
var todaymin=today.getMinutes()
var todaysec=today.getSeconds()
var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
futurestring=montharray[mo-1]+" "+da+", "+yr
dd=Date.parse(futurestring)-Date.parse(todaystring)
dday=Math.floor(dd/(60*60*1000*24)*1)
dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)
//if on day of occasion
if(dday<=0&&dhour<=0&&dmin<=0&&dsec<=1&&todayd==da){
if (document.layers){
document.countdownnsmain.document.countdownnssub.document.write(opentags+message_on_occasion+closetags)
document.countdownnsmain.document.countdownnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+message_on_occasion+closetags
return
}
//if passed day of occasion
else if (dday<=-1){
if (document.layers){
document.countdownnsmain.document.countdownnssub.document.write(opentags+"Occasion already passed! "+closetags)
document.countdownnsmain.document.countdownnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+"Occasion already passed! "+closetags
return
}
//else, if not yet
else{
if (document.layers){
document.countdownnsmain.document.countdownnssub.document.write(opentags+dday+ " days, "+dhour+" hours, "+dmin+" minutes, and "+dsec+" seconds left until "+occasion+closetags)
document.countdownnsmain.document.countdownnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+dday+ " days, "+dhour+" hours, "+dmin+" minutes, and "+dsec+" seconds left until "+occasion+closetags
}
setTimeout("countdown()",1000)
}
</script>

<ilayer id="countdownnsmain" width=&{countdownwidth}; height=&{countdownheight}; bgColor=&{countdownbgcolor}; visibility=hide><layer id="countdownnssub" width=&{countdownwidth}; height=&{countdownheight}; left=0 top=0></layer></ilayer>




Demo on : http://rad.hrsv.de/forum/index.php


Pyx

So I decided to go with this script.  I seemed to do  more what I wanted.  I see where you can edit the font type and color .  Is this where I would add tags to change the font size to something larger?

var countdownwidth='360px'
var countdownheight='20px'
var countdownbgcolor=''
var opentags='<font face="Verdana"><center>'
var closetags='</font></center>'
Title: Re: Countdown Block
Post by: GhostRider2110 on February 27, 2009, 04:55:35 PM
I know this is an old thread, but I tried using the script PowerPyx posted from scriptbox but I have having issues with it working.

SMF 1.1.8
TP 1.0 B3
MOdified Blueskies theme

I place it in any block it does not show up.  I do have it set to show up anywhere. I can turn on the Title and/or frame and they will show up.  I have change the text color in the script as well.  No dice. Any assistance would be greatly appreciated.  I have it as a Type HTML & Javascript block.

www.usscalemasters.org (http://www.usscalemasters.org)


See-ya
Mitch
Title: Re: Countdown Block
Post by: GhostRider2110 on February 27, 2009, 07:40:23 PM
One other note, this script does work under TP 0.9.8.  As can be seen on www.scalemasters.org (http://www.scalemasters.org)

--Mitch
Title: Re: Countdown Block
Post by: GhostRider2110 on February 27, 2009, 09:28:37 PM
OK, I have currently given up on trying to use a javascript block.  I guess I am not understanding how it is suppose to work since it switched from scriptbox in 0.9 to HTML & Javascript in 1.x.  If someone can point me to some tutorial or documentation that would be nice.  I did check How do I create a Javascript Block (http://docs.tinyportal.co.uk/index.php/topic,77.html) but that is not accurate... 

In the mean time I found a php script which, although is not real time, works for now...

--Mitch