-
-
Save chrisdarroch/970100 to your computer and use it in GitHub Desktop.
Laksa time without jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
var options = { | |
yesMessage: "YES!", | |
noMessage: "No", | |
target: document.getElementById("isitlaksatime"), | |
wrapper: document.body, | |
day: 5, // 5 for friday | |
hour: 12 // 12 for noon! | |
}; | |
function getMessage(now) { | |
var targetDay = options.day, | |
targetHour = options.hour, | |
yesMessage = options.yesMessage || "Yes", | |
noMessage = options.noMessage || "No", | |
theDay = now.getDay(), | |
theHour = now.getHours(), | |
theMinute = now.getMinutes(); | |
if ( theDay === targetDay ) { | |
if ( theHour === targetHour ) { | |
return yesMessage; | |
} | |
if ( (theHour + 2) === targetHour ) return "Not yet"; | |
if ( (theHour + 1) === targetHour ) { | |
if ( theMinute >= 58) return "Get ready"; | |
if ( theMinute >= 55) return "Nearly"; | |
if ( theMinute >= 45) return "Really soon"; | |
return "Soon"; | |
} | |
return noMessage; | |
} | |
if ( theDay === (targetDay - 1)) return "Come back tomorrow"; | |
return noMessage; | |
} | |
function countDown() { | |
var now = new Date(), | |
message = getMessage(now); | |
options.target.innerText = message; | |
options.wrapper.className = (message.length > 10) ? "long" : ""; | |
//console.log("minute: " + theMinute + " message: " + message); | |
} | |
countDown(); | |
timer = setInterval(countDown, 10000); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
BAM! And the jQuery is gone!