Widget:TimerTest2: Difference between revisions
Jump to navigation
Jump to search
Matt Pijoan (talk | contribs) No edit summary |
Matt Pijoan (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
<includeonly> | <includeonly> | ||
<script type='text/javascript' src="http://www.wikidoc.org/includes/raty/jquery.timer.js"></script> | |||
<script type='text/javascript'> | <script type='text/javascript'> | ||
mw.loader.using('mediawiki.user',function(){ | mw.loader.using('mediawiki.user',function(){ | ||
if($.inArray("CMEUser", mw.config.get( 'wgUserGroups' )) != "-1"){ | if($.inArray("CMEUser", mw.config.get( 'wgUserGroups' )) != "-1"){ | ||
var Obj1 = new (function(){ | |||
var $timer1, | |||
incrementTime = 100, | |||
currentTime = 0, | |||
updateTimer = function() { | |||
$timer1.html(currentTime); | |||
currentTime +=incrementTime; | |||
if(currentTime == 30000){ | |||
var api = new mw.Api(); | var api = new mw.Api(); | ||
api.get( { | api.get( { | ||
Line 10: | Line 17: | ||
user: mw.user.getName(), | user: mw.user.getName(), | ||
activity: window.location.pathname.substring(11,window.location.pathname.length), | activity: window.location.pathname.substring(11,window.location.pathname.length), | ||
} ) | } ).done ( function ( data ) { | ||
console.log( data ); | |||
} ); | |||
currentTime = 0; | |||
} | |||
}, | |||
}); | init = function(){ | ||
$timer1 = $('#output1'); | |||
Obj1.Timer = $.timer(updateTimer, incrementTime, true); | |||
$(document).keypress(function(){ | }; | ||
$(document).click(function(){ | this.pause = function(){ | ||
$(document).mousemove(function(){ | this.Timer.pause().once(); | ||
$(document).scroll(function(){ | }; | ||
this.play = function(){ | |||
if(!this.Timer.isActive){ | |||
this.Timer.play().once(); | |||
} | |||
}; | |||
$(init); | |||
}); | |||
var Obj2 = new (function(){ | |||
var $timer2, | |||
incrementTime = 100, | |||
currentTime = 120000, | |||
updateTimer = function() { | |||
$timer2.html(currentTime); | |||
currentTime -=incrementTime; | |||
if(currentTime === 100){ | |||
Obj1.pause(); | |||
alert("Click OK to continue accruing CME Time"); | |||
Obj2.Timer.pause().once(); | |||
currentTime = 5000; | |||
} | |||
}, | |||
init = function(){ | |||
$timer2 = $('#output2'); | |||
Obj2.Timer = $.timer(updateTimer, incrementTime, true); | |||
}; | |||
this.resetTimer = function(){ | |||
currentTime = 120000; | |||
if(!this.Timer.isActive){ | |||
this.Timer.play().once(); | |||
} | |||
Obj1.play(); | |||
} | |||
$(init); | |||
}); | |||
$(document).keypress(function(){Obj2.resetTimer();}); | |||
$(document).click(function(){Obj2.resetTimer();}); | |||
$(document).mousemove(function(){Obj2.resetTimer();}); | |||
$(document).scroll(function(){Obj2.resetTimer();}); | |||
} | } | ||
}); | }); | ||
</script> | </script> | ||
<span id="output1"></span><br /> | <span id="output1"></span><br /> | ||
<span id="output2"></span> | <span id="output2"></span> | ||
</includeonly> | </includeonly> |