Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
Prev Previous Post   Next Post Next
  #1  
Old 11-03-2005, 09:55 PM
smsmasters smsmasters is offline
 
Join Date: Apr 2004
Posts: 117
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Help with JS Coding Countdown Script

Code:
<!-- START EXAMPLE CODE -->

<span id="textCountdown">~d~ days, ~h~ hours, ~m~ minutes and ~s~ seconds left till Christmas 2005!</span>

<script type="text/javascript" src="countdown.js"></script>
<script type="text/javascript">
//<![CDATA[
var textCountdown = new Countdown('textCountdown', 77);
textCountdown.setEndDate(2005, 12, 25);
textCountdown.start();
//]]>
</script>

<br />
<span id="textCountdown2">~d~ days, ~h~ hours, ~m~ minutes and ~s~ seconds left till New Year 2006!</span>
<script type="text/javascript" src="countdown.js"></script>
<script type="text/javascript">
//<![CDATA[
var textCountdown2 = new Countdown('textCountdown2', 77);
textCountdown2.setEndDate(2006, 01, 01);
textCountdown2.start();
//]]>
</script>

<!-- END EXAMPLE CODE -->

Can someone please modify this code so that when it is the actual event it says "Today is Christmas" and "Today is New Year".

Thanks

EDIT:

Here is countdown.js:

Code:
function Countdown(name, updateFrequency) {
   this.name = name;
   this.updateFrequency = updateFrequency;
   this.images = null;
   this.endDate = new Date();
   this.format = (document.getElementById && document.getElementById(this.name)) ? document.getElementById(this.name).innerHTML : '';
}

Countdown.prototype.setImages = function(num0, num1, num2, num3, num4, num5, num6, num7, num8, num9) {
   this.images = new Array(num0, num1, num2, num3, num4, num5, num6, num7, num8, num9);
   preloadImages(num0, num1, num2, num3, num4, num5, num6, num7, num8, num9);
};

Countdown.prototype.setEndDate = function(year, month, day, hour, minute, second, milliseconds) {
   this.endDate = new Date(year, month - 1, day, ( (hour) ? hour : 0), ( (minute) ? minute : 0), ( (second) ? second : 0), ( (milliseconds) ? milliseconds : 0));
};

Countdown.prototype.start = function() {
   this.update();
   setInterval(this.name + '.update()', (this.updateFrequency ? this.updateFrequency : 1000) );
};

Countdown.prototype.update = function() {
   
   // calculate the time until countdown end date
   var now = new Date();
   var difference = this.endDate - now;
   
   // decompose difference into days, hours, minutes and seconds parts
   var days    = parseInt(difference / 86400000) + '';
   var hours   = parseInt((difference % 86400000) / 3600000) + '';
   var minutes = parseInt((difference % 3600000) / 60000) + '';
   var seconds = parseInt((difference % 60000) / 1000) + '';
   var milliseconds = parseInt(difference % 1000) + '';
   
   // negative values should be set to 0
   if (isNaN(days) || days.charAt(0) == '-') days = '0';
   if (isNaN(hours) || hours.charAt(0) == '-') hours = '0';
   if (isNaN(minutes) || minutes.charAt(0) == '-') minutes = '0';
   if (isNaN(seconds) || seconds.charAt(0) == '-') seconds = '0';
   if (isNaN(milliseconds) || milliseconds.charAt(0) == '-') milliseconds = '0';
   
   // display changes differently for images and text countdowns
   if (this.images != null) {
      
      // single digit values should have a '0' prepended to them
      if (days.length == 1) days = '000' + days;
      else if (days.length == 2) days = '00' + days;
      else if (days.length == 3) days = '0' + days;
      if (hours.length == 1) hours = '0' + hours;
      if (minutes.length == 1) minutes = '0' + minutes;
      if (seconds.length == 1) seconds = '0' + seconds;
      if (milliseconds.length == 1) milliseconds = '00' + milliseconds;
      else if (milliseconds.length == 2) milliseconds = '0' + milliseconds;
      
      // update images
      if (document.images[this.name + '_d1000']) document.images[this.name + '_d1000'].src = this.images[parseInt(days.charAt(0))];
      if (document.images[this.name + '_d100']) document.images[this.name + '_d100'].src = this.images[parseInt(days.charAt(1))];
      if (document.images[this.name + '_d10']) document.images[this.name + '_d10'].src = this.images[parseInt(days.charAt(2))];
      if (document.images[this.name + '_d1']) document.images[this.name + '_d1'].src = this.images[parseInt(days.charAt(3))];
      if (document.images[this.name + '_h10']) document.images[this.name + '_h10'].src = this.images[parseInt(hours.charAt(0))];
      if (document.images[this.name + '_h1']) document.images[this.name + '_h1'].src = this.images[parseInt(hours.charAt(1))];
      if (document.images[this.name + '_m10']) document.images[this.name + '_m10'].src = this.images[parseInt(minutes.charAt(0))];
      if (document.images[this.name + '_m1']) document.images[this.name + '_m1'].src = this.images[parseInt(minutes.charAt(1))];
      if (document.images[this.name + '_s10']) document.images[this.name + '_s10'].src = this.images[parseInt(seconds.charAt(0))];
      if (document.images[this.name + '_s1']) document.images[this.name + '_s1'].src = this.images[parseInt(seconds.charAt(1))];
      if (document.images[this.name + '_ms100']) document.images[this.name + '_ms100'].src = this.images[parseInt(milliseconds.charAt(0))];
      if (document.images[this.name + '_ms10']) document.images[this.name + '_ms10'].src = this.images[parseInt(milliseconds.charAt(1))];
      if (document.images[this.name + '_ms1']) document.images[this.name + '_ms1'].src = this.images[parseInt(milliseconds.charAt(2))];
   }
   else if (this.format != '') {
      if (document.getElementById && document.getElementById(this.name)) {
         var html = this.format;
         html = html.replace(/~d~/, days);
         html = html.replace(/~h~/, hours);
         html = html.replace(/~m~/, minutes);
         html = html.replace(/~s~/, seconds);
         html = html.replace(/~ms~/, milliseconds);
         
         document.getElementById(this.name).innerHTML = html;
      }
   }
};


// Image preloader
function preloadImages() {
        if (document.images) {
                for (var i = 0; i < preloadImages.arguments.length; i++) {
                        (new Image()).src = preloadImages.arguments[i];
                }
        }
}
Reply With Quote
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:42 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04326 seconds
  • Memory Usage 2,313KB
  • Queries Executed 12 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (3)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (3)post_thanks_box
  • (3)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (3)post_thanks_postbit_info
  • (3)postbit
  • (3)postbit_onlinestatus
  • (3)postbit_wrapper
  • (1)showthread_list
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_threadedmode.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids_threaded
  • showthread_threaded_construct_link
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete