Giter VIP home page Giter VIP logo

countdown's Introduction

countdown

countdown is a jQuery plugin to render countdowns. Instead of unicorns this plugin does not have any magic, but if you like countdowns to be rendered the way you want, this plugin might become your best friend.

Uber simple setup

To use the countdown plugin you need to load the current version of jQuery (tested with 1.7.2) and the javascript file of the plugin. Just add the following lines to the head of your website:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="/path/to/jquery.countdown.js"></script>

Then you have to initialize the plugin with your desired configuration:

$(function() {
    $('.yourCountdownContainer').countdown({
        date: "June 7, 2087 15:03:26"
    });
});

Yep, it's easy like that! Enjoy the time you saved!

Options

You can pass a set of these options to set a custom behaviour and look for the plugin.

Property (Type) Default Description
date new Date("June 7, 2087 15:03:25") The end time of your fancy countdown. Pass either a date object or a string/integer that will be used to create a new Date object. Here you can find all accepted formats of this value.
refresh 1000 Refresh rate in milliseconds or false to avoid automatic updates.
render With the render option you can set a function to change the output of the plugin. This function is called in the scope of the plugin, so you can access the leadingZeros method to format numbers as well as public variables and methods. A literal object will be passed to this function as an argument, containing the remaining time parts (years, days, hours, min, sec).
onEnd Callback function that is called when the end date is reached
offset A period of time (in milliseconds) that is used as offset in time difference calculation between now and end time. Useful if countdown calculation to end time is imprecise due to user's date and time settings.

Public plugin methods

method(arguments) Description
leadingZeros(number, [length = 2]) Add leading zeros to a number.
update(newDate) Update the end time. The possible formats of the argument newDate are the same as described in the date-option above.
updateOffset(newOffset) Update the offset (time in milliseconds).
render() Call the render method. This might be usefull if you set refresh to false.
stop() Stops the refresh loop.
start([refreshRate]) Start the refresh loop. If you set a refresh rate in the options you can overwrite it with the argument refreshRate. If you don't pass an argument, the old value or the default value of 1 sec will be used.
restart(options) Update the options and restart the countdown

Changelog

Version 2.2.0 - May 6, 2016

  • added restart countdown api method (Thanks @scazzy)
  • Fixed bower dependencies and main field

Version 2.1.0 - Oct 13, 2014

  • Added time offset option to fix time differences between server and client time (#8)

Version 2.0.0 - Oct 13, 2014

  • removed coffee-script dependency
  • added vanilla version
  • add UMD wrapper (commonJS, require.js, global)
  • added support to define the end date with the data-date attribute (#14)

Version 1.0.1 - May 01, 2013

  • Added callback function when the end date is reached

Version 1.0.0 - Aug 05, 2012

  • Initial release

License

countdown is dual licensed under the MIT and GPL-3.0 licenses.

countdown's People

Contributors

ain avatar alyssais avatar geoffharcourt avatar rendro avatar scazzy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

countdown's Issues

[enhancement] Support data attributes

It would be nice to have the facility to set options by using data attributes.

example:

<div class="countdown" data-date="June 7, 2087 15:03:26"></div>
<div class="countdown" data-date="July 9, 2034 13:13:02"></div>

$(".countdown").countdown();

Change language countdown

I want to change the language of the countdown (days, hours, minutes, seconds). How can I do that?
Thank you

The countdown display issue on iphone

As stated above I have a display issue when viewing in iPhone.
Attached is the iphone view of the countdown. However on android phone, it has no issue at all.

Is there anyway I can resolve this issue on phone? Thanks.

countdown

Time format for decimal like

Thanks for the plugin!

Time format for decimal like leadingZeroes method.

Example
15000 will be format as 15.00

I tried this, but it didn't work

$('.counter').countdown({
date: +(new Date) + 15000,
render: function(data) {
var ti= this.leadingZeros(data.sec, 2);
var ts= ti.toFixed(2);
$(this.el).text(ts + " sec");
}
});

Failure on jQuery installation

Stack:

bower FlexSlider#version/2.2.2       not-cached git://github.com/woothemes/FlexSlider.git#version/2.2.2
bower FlexSlider#version/2.2.2          resolve git://github.com/woothemes/FlexSlider.git#version/2.2.2
bower bower-skrollr-menu#0.1.14      not-cached git://github.com/Prinzhorn/skrollr-menu.git#0.1.14
bower bower-skrollr-menu#0.1.14         resolve git://github.com/Prinzhorn/skrollr-menu.git#0.1.14
bower bower-skrollr-menu#0.1.14        download https://github.com/Prinzhorn/skrollr-menu/archive/0.1.14.tar.gz
bower magnific-popup#~0.9.9          not-cached git://github.com/dimsemenov/Magnific-Popup.git#~0.9.9
bower magnific-popup#~0.9.9             resolve git://github.com/dimsemenov/Magnific-Popup.git#~0.9.9
bower jquery#~1.11.1                 not-cached git://github.com/jquery/jquery.git#~1.11.1
bower jquery#~1.11.1                    resolve git://github.com/jquery/jquery.git#~1.11.1
bower modernizr#~2.8.2               not-cached git://github.com/Modernizr/Modernizr.git#~2.8.2
bower modernizr#~2.8.2                  resolve git://github.com/Modernizr/Modernizr.git#~2.8.2
bower bower-skrollr#~0.6.26          not-cached git://github.com/egorkhmelev/bower-skrollr.git#~0.6.26
bower bower-skrollr#~0.6.26             resolve git://github.com/egorkhmelev/bower-skrollr.git#~0.6.26
bower countdown#~2.1.0               not-cached git://github.com/rendro/countdown.git#~2.1.0
bower countdown#~2.1.0                  resolve git://github.com/rendro/countdown.git#~2.1.0
bower FlexSlider#version/2.2.2         download https://github.com/woothemes/FlexSlider/archive/version/2.2.2.tar.gz
bower countdown#~2.1.0                 download https://github.com/rendro/countdown/archive/2.1.0.tar.gz
bower bower-skrollr#~0.6.26            download https://github.com/egorkhmelev/bower-skrollr/archive/v0.6.26.tar.gz
bower magnific-popup#~0.9.9            download https://github.com/dimsemenov/Magnific-Popup/archive/0.9.9.tar.gz
bower modernizr#~2.8.2                 download https://github.com/Modernizr/Modernizr/archive/v2.8.3.tar.gz
bower bower-skrollr-menu#0.1.14         extract archive.tar.gz
bower bower-skrollr-menu#0.1.14    invalid-meta bower-skrollr-menu is missing "main" entry in bower.json
bower bower-skrollr-menu#0.1.14    invalid-meta bower-skrollr-menu is missing "ignore" entry in bower.json
bower bower-skrollr-menu#0.1.14        resolved git://github.com/Prinzhorn/skrollr-menu.git#0.1.14
bower countdown#~2.1.0                  extract archive.tar.gz
bower countdown#~2.1.0             invalid-meta countdown is missing "main" entry in bower.json
bower countdown#~2.1.0                 resolved git://github.com/rendro/countdown.git#2.1.0
bower bower-skrollr#~0.6.26             extract archive.tar.gz
bower bower-skrollr#~0.6.26            resolved git://github.com/egorkhmelev/bower-skrollr.git#0.6.26
bower jQuery#>=1.7.2                 not-cached git://github.com/jquery/jquery.git#>=1.7.2
bower jQuery#>=1.7.2                    resolve git://github.com/jquery/jquery.git#>=1.7.2
bower magnific-popup#~0.9.9             extract archive.tar.gz
bower magnific-popup#~0.9.9            resolved git://github.com/dimsemenov/Magnific-Popup.git#0.9.9
bower jquery#>=1.8.0                 not-cached git://github.com/jquery/jquery.git#>=1.8.0
bower jquery#>=1.8.0                    resolve git://github.com/jquery/jquery.git#>=1.8.0
bower jquery#~1.11.1                   download https://github.com/jquery/jquery/archive/1.11.1.tar.gz
bower jQuery#>=1.7.2                   download https://github.com/jquery/jquery/archive/2.1.1.tar.gz
bower jquery#>=1.8.0                   download https://github.com/jquery/jquery/archive/2.1.1.tar.gz
bower modernizr#~2.8.2                  extract archive.tar.gz
bower modernizr#~2.8.2             invalid-meta modernizr is missing "main" entry in bower.json
bower modernizr#~2.8.2             invalid-meta modernizr is missing "ignore" entry in bower.json
bower modernizr#~2.8.2                 resolved git://github.com/Modernizr/Modernizr.git#2.8.3
bower FlexSlider#version/2.2.2          extract archive.tar.gz
bower FlexSlider#version/2.2.2     invalid-meta FlexSlider is missing "main" entry in bower.json
bower FlexSlider#version/2.2.2     invalid-meta FlexSlider is missing "ignore" entry in bower.json
bower FlexSlider#version/2.2.2         resolved git://github.com/woothemes/FlexSlider.git#version/2.2.2
bower jquery#>=1.8.0                    extract archive.tar.gz
bower jquery#~1.11.1                    extract archive.tar.gz
bower jquery#>=1.8.0                   resolved git://github.com/jquery/jquery.git#2.1.1
bower jquery#~1.11.1                   resolved git://github.com/jquery/jquery.git#1.11.1
bower jQuery#>=1.7.2                    extract archive.tar.gz
bower jQuery#>=1.7.2                   resolved git://github.com/jquery/jquery.git#2.1.1
bower bower-skrollr-menu#0.1.14         install bower-skrollr-menu#0.1.14
bower countdown#~2.1.0                  install countdown#2.1.0
bower bower-skrollr#~0.6.26             install bower-skrollr#0.6.26
bower magnific-popup#~0.9.9             install magnific-popup#0.9.9
bower modernizr#~2.8.2                  install modernizr#2.8.3
bower FlexSlider#version/2.2.2          install FlexSlider#version/2.2.2
bower jquery#~1.11.1                    install jquery#1.11.1
bower jQuery#>=1.7.2                    install jQuery#2.1.1
bower                                     error Unexpected string

Stack trace:
SyntaxError: Unexpected string
    at Object.parse (native)
    at /Users/ain/.nvm/v0.10.31/lib/node_modules/bower/lib/core/Manager.js:185:37
    at _fulfilled (/Users/ain/.nvm/v0.10.31/lib/node_modules/bower/node_modules/q/q.js:787:54)
    at self.promiseDispatch.done (/Users/ain/.nvm/v0.10.31/lib/node_modules/bower/node_modules/q/q.js:816:30)
    at Promise.promise.promiseDispatch (/Users/ain/.nvm/v0.10.31/lib/node_modules/bower/node_modules/q/q.js:749:13)
    at /Users/ain/.nvm/v0.10.31/lib/node_modules/bower/node_modules/q/q.js:557:44
    at flush (/Users/ain/.nvm/v0.10.31/lib/node_modules/bower/node_modules/q/q.js:108:17)
    at process._tickCallback (node.js:419:13)

Console trace:
Trace
    at StandardRenderer.error (/Users/ain/.nvm/v0.10.31/lib/node_modules/bower/lib/renderers/StandardRenderer.js:82:17)
    at Logger.<anonymous> (/Users/ain/.nvm/v0.10.31/lib/node_modules/bower/bin/bower:110:22)
    at Logger.emit (events.js:95:17)
    at Logger.emit (/Users/ain/.nvm/v0.10.31/lib/node_modules/bower/node_modules/bower-logger/lib/Logger.js:29:39)
    at /Users/ain/.nvm/v0.10.31/lib/node_modules/bower/lib/commands/index.js:40:20
    at _rejected (/Users/ain/.nvm/v0.10.31/lib/node_modules/bower/node_modules/q/q.js:797:24)
    at /Users/ain/.nvm/v0.10.31/lib/node_modules/bower/node_modules/q/q.js:823:30
    at Promise.when (/Users/ain/.nvm/v0.10.31/lib/node_modules/bower/node_modules/q/q.js:1035:31)
    at Promise.promise.promiseDispatch (/Users/ain/.nvm/v0.10.31/lib/node_modules/bower/node_modules/q/q.js:741:41)
    at /Users/ain/.nvm/v0.10.31/lib/node_modules/bower/node_modules/q/q.js:557:44

System info:
Bower version: 1.3.12
Node version: 0.10.31
OS: Darwin 14.0.0 x64

shell returned 1

Hide days if 0...

Hi,

I wanted to see if there's a way to hide left-most element, if its 0.
For example, if remaining time is only 5 mins and 10 sec, is there a way to hide days and hours?

BTW: This is great and much appreciated.
I'm going to be using this...

Thanks,
Jatin

Not working on firefox and IE

Not working on firefox and IE.
This is my script:
https://www.mediafire.com/?vbu56612bevf3wb
and added time server zone:

// End time for diff purposes
var endTimeDiff = new Date().getTime() + 15000;
// This is server's time
var timeThere = new Date();
// This is client's time (delayed)
var timeHere = new Date(timeThere.getTime() - 5434);
// Get the difference between client time and server time
var diff_ms = timeHere.getTime() - timeThere.getTime();
// Get the rounded difference in seconds
var diff_s = diff_ms / 1000 | 0;

    var notice = [];
    notice.push('Server time: ' + timeThere.toDateString() + ' ' + timeThere.toTimeString());
    notice.push('Your time: ' + timeHere.toDateString() + ' ' + timeHere.toTimeString());
    notice.push('Time difference: ' + diff_s + ' seconds (' + diff_ms + ' milliseconds to be precise). Your time is a bit behind.');


    $('.offset-server .countdown').countdown({
      date: endTimeDiff,
      offset: diff_s * 1000,
      onEnd: function() {
        $(this.el).addClass('ended');
      }
    });
help pls.

jQuery wrapper missing from minified version

First of all, thank you for this script.
When jquery.countdown.min.js file in the package is included in a page where jQuery is loaded in no-conflict mode the script fails due to the $ variable used in the script. The solution was to wrap the entire thing in a self executing anonymous function:
(function( $ ){ // the script. })( jQuery );

Time Zone

Better if it had an option for different time zone...

NaN under Safari

Countdown not displaying numbers under Safari.

When I log args under render method, Safari send this :

Object
    days: 0
    hours: 0
    millisec: 0
    min: 0
    sec: NaN
    years: 0

countdown not work with flotcharts.

Hello, great plugin i want to use it in combination with flotcharts but if i inlcude the chart file , plugin stop work without error in console, just time is aways 0

Any ideas ?

Cant get it to re-render

Hey

I have the countdown linked to a select change event and want to re-render it based upon the time passed in by the change.

I have a function where is pass in the 'datetime' from the select box

it works fine on page load using the initial date, but upon changing the dropdown, the new date is being passed. debugged and checked. but the output doesnt change. Stays as initial datetime that was passed in. Any ideas.

Thanks

dates being passed in as strings
initial date: "March 19, 2014 15:00:00"
on change: "March 19, 2014 17:00:00"
on change2: "March 20, 2014 15:00:00"

output always shows countdown to initial date.

function GetCountDown(dateTime) {

        $('#cd').countdown({
            date: dateTime,
            render: function (data) {
                $(this.el).html("<div>" + this.leadingZeros(data.days, 3) + " <span>days</span></div><div>" + this.leadingZeros(data.hours, 2) + " <span>hrs</span></div><div>" + this.leadingZeros(data.min, 2) + " <span>min</span></div><div>" + this.leadingZeros(data.sec, 2) + " <span>sec</span></div>");
            },

        });
}

Provide callback upon countdown expiration

It would be nice if you could specify a callback function which is executed when the countdown expires. This would enable applications to respond to an expired callback with some sort of 'intelligent' behavior.

Prettier styled output

Would it be possible to add style/code for your plugin to look like this one: https://github.com/martinaglv/jQuery-Countdown

The reason I ask is that I think the martinaglv plugin is just about the best looking one I know but your plugin offers more/better functionality and most importantly is works without problems on multiple instances on a page which is important for my usage pattern.

I would completely understand if you just said "No, do it yourself" but I suck at JavaScript and it would take me a lot of putzing around to get this done, if I succeeded at all. So just consider this a kind request from a happy user.

Vielen Dank!

about dest folder

recently, we want to add your lib on https://cdnjs.com
cdnjs/cdnjs#5942
and we usually use git auto-update to add new version
we usually add all files under dist
so, if dest in your repo is same as dist, please let me know.
thank you very much!

Does not work on iPad and iPhone

Does not work on iPad and iPhone if you use it like this:

$(function() {
$('#counter').countdown({
date: "15.05.2014 15:03:26"
});
});

timezones

is there any way to use UTC dates all over the plugin?

Licensing

Hi,

I love this countdown and will be using it.
Anything I need to do from licensing perspective other than not modify source files?
I'm only using it for the website that will sell small events-tickets.
Not modyfing jquery source...

Thanks,
Jatin

[enhancement] Add missing bower.json.

Hey, maintainer(s) of rendro/countdown!

We at VersionEye are working hard to keep up the quality of the bower's registry.

We just finished our initial analysis of the quality of the Bower.io registry:

7530 - registered packages, 224 of them doesnt exists anymore;

We analysed 7306 existing packages and 1070 of them don't have bower.json on the master branch ( that's where a Bower client pulls a data ).

Sadly, your library rendro/countdown is one of them.

Can you spare 15 minutes to help us to make Bower better?

Just add a new file bower.json and change attributes.

{
  "name": "rendro/countdown",
  "version": "1.0.0",
  "main": "path/to/main.css",
  "description": "please add it",
  "license": "Eclipse",
  "ignore": [
    ".jshintrc",
    "**/*.txt"
  ],
  "dependencies": {
    "<dependency_name>": "<semantic_version>",
    "<dependency_name>": "<Local_folder>",
    "<dependency_name>": "<package>"
  },
  "devDependencies": {
    "<test-framework-name>": "<version>"
  }
}

Read more about bower.json on the official spefication and nodejs semver library has great examples of proper versioning.

NB! Please validate your bower.json with jsonlint before commiting your updates.

Thank you!

Timo,
twitter: @versioneye
email: [email protected]
VersionEye - no more legacy software!

Destroy the plugin instance?

Hello!

Thank you for this module!

However, what is the recommended way to destroy the plugin and remove it from a page dynamically?

Also, is it ok to initialize plugin on the same elements multiple times or it will create duplicate instances?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.