Skip to content

Instantly share code, notes, and snippets.

@djKianoosh
Created February 20, 2012 02:34
Show Gist options
  • Save djKianoosh/1867375 to your computer and use it in GitHub Desktop.
Save djKianoosh/1867375 to your computer and use it in GitHub Desktop.
javascript timer for ngml online draft
var JQ = document.createElement('script');
JQ.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js';
JQ.type= 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(JQ);
jQuery.noConflict();
var ngml = {};
ngml.msgBox = jQuery('div[id^="[ngml]"] form textarea');
ngml.maxTime=45;
ngml.timer=0;
ngml.team = "TEST";
ngml.intervalId=0;
ngml.ontheclock = function(name) {
clearInterval(ngml.intervalId);
ngml.timer=ngml.maxTime;
ngml.team = name;
ngml.sendMsg(ngml.team + " on the clock: " + ngml.timer + " seconds");
ngml.intervalId = setInterval("ngml.reminder()", 10000);
return ngml.msgBox;
};
ngml.reminder = function() {
ngml.decrementTimer();
if (ngml.timer < 1) {
clearInterval(ngml.intervalId);
ngml.timesup();
} else {
ngml.sendMsg(ngml.timer + " seconds left for " + ngml.team);
}
};
ngml.decrementTimer = function() {
ngml.timer = ngml.timer - 10;
};
ngml.timesup = function() {
ngml.sendMsg("Time is up for " + ngml.team);
};
ngml.sendMsg = function(msg) {
jQuery(ngml.msgBox).val(msg).trigger('submit');
};
@djKianoosh
Copy link
Author

Once that's on the page.. use::

ngml.ontheclock("49ers");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment