Hey guys, i am completely useless in java script but i need to modify the one below.<\/p>\n
What i need is for it to count down to a date, rather than count down from a set value.<\/p>\n
/*\n * jQuery The Final Countdown plugin v1.0.0 beta\n * http://github.com/hilios/jquery.countdown\n *\n * Copyright (c) 2011 Edson Hilios\n *\n * Permission is hereby granted, free of charge, to any person obtaining\n * a copy of this software and associated documentation files (the\n * \"Software\"), to deal in the Software without restriction, including\n * without limitation the rights to use, copy, modify, merge, publish,\n * distribute, sublicense, and/or sell copies of the Software, and to\n * permit persons to whom the Software is furnished to do so, subject to\n * the following conditions:\n *\n * The above copyright notice and this permission notice shall be\n * included in all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\n * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\n * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\n * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n */\n(function($) {\n \n $.fn.countdown = function(toDate, callback) {\n var handlers = ['seconds', 'minutes', 'hours', 'days', 'weeks', 'daysLeft'];\n \n function delegate(scope, method) {\n return function() { return method.call(scope) }\n }\n \n return this.each(function() {\n // Convert\n if(!(toDate instanceof Date)) {\n if(String(toDate).match(/^[0-9]*$/)) {\n toDate = new Date(toDate);\n } else if( toDate.match(/([0-9]{1,2})\\/([0-9]{1,2})\\/([0-9]{2,4})\\s([0-9]{1,2})\\:([0-9]{2})\\:([0-9]{2})/) ||\n toDate.match(/([0-9]{2,4})\\/([0-9]{1,2})\\/([0-9]{1,2})\\s([0-9]{1,2})\\:([0-9]{2})\\:([0-9]{2})/)\n ) {\n toDate = new Date(toDate);\n } else if(toDate.match(/([0-9]{1,2})\\/([0-9]{1,2})\\/([0-9]{2,4})/) || \n toDate.match(/([0-9]{2,4})\\/([0-9]{1,2})\\/([0-9]{1,2})/)\n ) {\n toDate = new Date(toDate)\n } else {\n throw new Error(\"Doesn't seen to be a valid date object or string\")\n }\n }\n \n var $this = $(this),\n values = {},\n lasting = {},\n interval = $this.data('countdownInterval'),\n currentDate = new Date(),\n secondsLeft = Math.floor((toDate.valueOf() - currentDate.valueOf()) / 1000);\n \n function triggerEvents() {\n // Evaluate if this node is included in the html\n if($this.closest('html').length === 0) {\n stop(); // Release the memory\n dispatchEvent('removed');\n return;\n }\n // Calculate the time offset\n secondsLeft--;\n if(secondsLeft < 0) {\n secondsLeft = 0;\n }\n lasting = {\n seconds : secondsLeft % 60,\n minutes : Math.floor(secondsLeft / 60) % 60,\n hours : Math.floor(secondsLeft / 60 / 60) % 24,\n days : Math.floor(secondsLeft / 60 / 60 / 24),\n weeks : Math.floor(secondsLeft / 60 / 60 / 24 / 7),\n daysLeft: Math.floor(secondsLeft / 60 / 60 / 24) % 7\n }\n for(var i=0; i<handlers.length; i++) {\n var eventName = handlers[i];\n if(values[eventName] != lasting[eventName]) {\n values[eventName] = lasting[eventName];\n dispatchEvent(eventName);\n }\n }\n if(secondsLeft == 0) { \n stop();\n dispatchEvent('finished');\n }\n }\n triggerEvents();\n \n function dispatchEvent(eventName) {\n var event = $.Event(eventName);\n event.date = new Date(new Date().valueOf() + secondsLeft);\n event.value = values[eventName] || \"0\";\n event.toDate = toDate;\n event.lasting = lasting;\n switch(eventName) {\n case \"seconds\":\n case \"minutes\":\n case \"hours\":\n event.value = event.value < 10 ? '0'+event.value.toString() : event.value.toString();\n break;\n default:\n if(event.value) {\n event.value = event.value.toString();\n }\n break;\n }\n callback.call($this, event);\n }\n \n function stop() {\n clearInterval(interval);\n }\n\n function start() {\n $this.data('countdownInterval', setInterval(delegate($this, triggerEvents), 1000));\n interval = $this.data('countdownInterval');\n }\n \n if(interval) stop();\n start();\n });\n }\n})(jQuery);\n<\/code><\/pre>\n
Advertisement
I really appreciate any help!<\/p>","upvoteCount":7,"answerCount":11,"datePublished":"2014-06-17T19:43:22.000Z","author":{"@type":"Person","name":"kirkatroics","url":"https://community.spiceworks.com/u/kirkatroics"},"acceptedAnswer":{"@type":"Answer","text":"
Your countTo is always 25 days from the time the page is viewed since you are using “now.valueOf”.<\/p>\n
var countTo = 25 * 24 * 60 * 60 * 1000 + now.valueOf();\n<\/code><\/pre>\nWhen the page loads it takes the current time on the client’s PC and then adds 25 days to it. If you have a specific launch day then I would make that your countTo instead of basing it off of “now”.<\/p>","upvoteCount":0,"datePublished":"2014-06-18T16:15:58.000Z","url":"https://community.spiceworks.com/t/javascript-help/313680/7","author":{"@type":"Person","name":"adammurphy2925","url":"https://community.spiceworks.com/u/adammurphy2925"}},"suggestedAnswer":[{"@type":"Answer","text":"
Hey guys, i am completely useless in java script but i need to modify the one below.<\/p>\n
What i need is for it to count down to a date, rather than count down from a set value.<\/p>\n
/*\n * jQuery The Final Countdown plugin v1.0.0 beta\n * http://github.com/hilios/jquery.countdown\n *\n * Copyright (c) 2011 Edson Hilios\n *\n * Permission is hereby granted, free of charge, to any person obtaining\n * a copy of this software and associated documentation files (the\n * \"Software\"), to deal in the Software without restriction, including\n * without limitation the rights to use, copy, modify, merge, publish,\n * distribute, sublicense, and/or sell copies of the Software, and to\n * permit persons to whom the Software is furnished to do so, subject to\n * the following conditions:\n *\n * The above copyright notice and this permission notice shall be\n * included in all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\n * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\n * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\n * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n */\n(function($) {\n \n $.fn.countdown = function(toDate, callback) {\n var handlers = ['seconds', 'minutes', 'hours', 'days', 'weeks', 'daysLeft'];\n \n function delegate(scope, method) {\n return function() { return method.call(scope) }\n }\n \n return this.each(function() {\n // Convert\n if(!(toDate instanceof Date)) {\n if(String(toDate).match(/^[0-9]*$/)) {\n toDate = new Date(toDate);\n } else if( toDate.match(/([0-9]{1,2})\\/([0-9]{1,2})\\/([0-9]{2,4})\\s([0-9]{1,2})\\:([0-9]{2})\\:([0-9]{2})/) ||\n toDate.match(/([0-9]{2,4})\\/([0-9]{1,2})\\/([0-9]{1,2})\\s([0-9]{1,2})\\:([0-9]{2})\\:([0-9]{2})/)\n ) {\n toDate = new Date(toDate);\n } else if(toDate.match(/([0-9]{1,2})\\/([0-9]{1,2})\\/([0-9]{2,4})/) || \n toDate.match(/([0-9]{2,4})\\/([0-9]{1,2})\\/([0-9]{1,2})/)\n ) {\n toDate = new Date(toDate)\n } else {\n throw new Error(\"Doesn't seen to be a valid date object or string\")\n }\n }\n \n var $this = $(this),\n values = {},\n lasting = {},\n interval = $this.data('countdownInterval'),\n currentDate = new Date(),\n secondsLeft = Math.floor((toDate.valueOf() - currentDate.valueOf()) / 1000);\n \n function triggerEvents() {\n // Evaluate if this node is included in the html\n if($this.closest('html').length === 0) {\n stop(); // Release the memory\n dispatchEvent('removed');\n return;\n }\n // Calculate the time offset\n secondsLeft--;\n if(secondsLeft < 0) {\n secondsLeft = 0;\n }\n lasting = {\n seconds : secondsLeft % 60,\n minutes : Math.floor(secondsLeft / 60) % 60,\n hours : Math.floor(secondsLeft / 60 / 60) % 24,\n days : Math.floor(secondsLeft / 60 / 60 / 24),\n weeks : Math.floor(secondsLeft / 60 / 60 / 24 / 7),\n daysLeft: Math.floor(secondsLeft / 60 / 60 / 24) % 7\n }\n for(var i=0; i<handlers.length; i++) {\n var eventName = handlers[i];\n if(values[eventName] != lasting[eventName]) {\n values[eventName] = lasting[eventName];\n dispatchEvent(eventName);\n }\n }\n if(secondsLeft == 0) { \n stop();\n dispatchEvent('finished');\n }\n }\n triggerEvents();\n \n function dispatchEvent(eventName) {\n var event = $.Event(eventName);\n event.date = new Date(new Date().valueOf() + secondsLeft);\n event.value = values[eventName] || \"0\";\n event.toDate = toDate;\n event.lasting = lasting;\n switch(eventName) {\n case \"seconds\":\n case \"minutes\":\n case \"hours\":\n event.value = event.value < 10 ? '0'+event.value.toString() : event.value.toString();\n break;\n default:\n if(event.value) {\n event.value = event.value.toString();\n }\n break;\n }\n callback.call($this, event);\n }\n \n function stop() {\n clearInterval(interval);\n }\n\n function start() {\n $this.data('countdownInterval', setInterval(delegate($this, triggerEvents), 1000));\n interval = $this.data('countdownInterval');\n }\n \n if(interval) stop();\n start();\n });\n }\n})(jQuery);\n<\/code><\/pre>\nI really appreciate any help!<\/p>","upvoteCount":7,"datePublished":"2014-06-17T19:43:22.000Z","url":"https://community.spiceworks.com/t/javascript-help/313680/1","author":{"@type":"Person","name":"kirkatroics","url":"https://community.spiceworks.com/u/kirkatroics"}},{"@type":"Answer","text":"
Moved this IT Programming forum for better exposure.<\/p>","upvoteCount":1,"datePublished":"2014-06-17T20:34:46.000Z","url":"https://community.spiceworks.com/t/javascript-help/313680/2","author":{"@type":"Person","name":"Bud-G","url":"https://community.spiceworks.com/u/Bud-G"}},{"@type":"Answer","text":"
I’m curious what you are trying to accomplish. The github doc shows it being used to countdown to a specific date, which seems to be what you are asking for. Can you be more specific about why this doesn’t meet your need?<\/p>","upvoteCount":1,"datePublished":"2014-06-18T02:35:18.000Z","url":"https://community.spiceworks.com/t/javascript-help/313680/3","author":{"@type":"Person","name":"matthootman","url":"https://community.spiceworks.com/u/matthootman"}},{"@type":"Answer","text":"
When i launch this on my test page it always counds down from 24 days, 24 hours, 24 seconds.<\/p>\n
I assumed, due to this, that it was counting down from a set value rather than to a specific date or time.<\/p>","upvoteCount":0,"datePublished":"2014-06-18T05:27:39.000Z","url":"https://community.spiceworks.com/t/javascript-help/313680/4","author":{"@type":"Person","name":"kirkatroics","url":"https://community.spiceworks.com/u/kirkatroics"}},{"@type":"Answer","text":"
Post your test page so we can see how you are using the countdown.<\/p>","upvoteCount":0,"datePublished":"2014-06-18T15:39:05.000Z","url":"https://community.spiceworks.com/t/javascript-help/313680/5","author":{"@type":"Person","name":"adammurphy2925","url":"https://community.spiceworks.com/u/adammurphy2925"}},{"@type":"Answer","text":"