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
 
(112 intermediate revisions by the same user not shown)
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'>
var Example1 = new (function() {
$.getScript( 'http://ec2-50-19-198-137.compute-1.amazonaws.com/includes/raty/jquery.timer.js',function(){
var $stopwatch, // Stopwatch element on the page
mw.loader.using('mediawiki.user',function(){
        incrementTime = 70, // Timer speed in milliseconds
if($.inArray("CMEUser", mw.config.get( 'wgUserGroups' )) != "-1"){
        currentTime = 0, // Current time in hundredths of a second
var Obj1 = new (function(){
        updateTimer = function() {
    var $timer1,
    incrementTime = 100,
            $stopwatch.html(formatTime(currentTime));
    currentTime = 0,
            currentTime += incrementTime / 10;
    updateTimer = function() {
        },
        $timer1.html(currentTime);
        init = function() {
        currentTime +=incrementTime;
        if(currentTime == 30000){
             $stopwatch = $('#stopwatch');
            var api = new mw.Api();
            Example1.Timer = $.timer(updateTimer, incrementTime, true);
             api.get( {
        };
                action: 'updatetracker',
     this.resetStopwatch = function() {
                user: mw.user.getName(),
        currentTime = 0;
                activity: window.location.pathname.substring(11,window.location.pathname.length),
        this.Timer.stop().once();
            } ).done ( function ( data ) {
                console.log( data );
            } );
            currentTime = 0;
        }
    },
     init = function(){
        $timer1 = $('#output1');
        window.Timer1 = $.timer(updateTimer, incrementTime, true);
     };
     };
     $(init);
     this.pause = function(){
        window.Timer1.pause().once();
    };
    this.play = function(){
        if(!this.Timer.isActive){
        window.Timer1.play().once();
        }
    };
$(init);
});
});
 
var Obj2 = new (function(){
var count = 0,
     var $timer2,
    timer = $.timer(function() {
    incrementTime = 100,
    currentTime = 120000,
        count++;
    updateTimer = function() {
        $('#counter').html(count);
        $timer2.html(currentTime);
     });
        currentTime -=incrementTime;
timer.set({ time : '', autostart : true });
        if(currentTime === 100){
 
            window.Timer1.pause();
 
            alert("Click OK to continue accruing CME Time");
var Example2 = new (function() {
            window.Timer2.pause().once();
var $stopwatch2, // Stopwatch element on the page
            currentTime = 5000;
        incrementTime = 70, // Timer speed in milliseconds
        }
        currentTime = 0, // Current time in hundredths of a second
    },
        updateTimer = function() {
    init = function(){
        $timer2 = $('#output2');
            $stopwatch2.html(formatTime(currentTime));
        window.Timer2 = $.timer(updateTimer, incrementTime, true);
            currentTime += incrementTime / 10;
        },
        init = function() {
            $stopwatch2 = $('#stopwatch2');
            Example1.Timer = $.timer(updateTimer, incrementTime, true);
        };
    this.resetStopwatch = function() {
        currentTime = 0;
        this.Timer.stop().once();
     };
     };
     $(init);
     this.resetTimer = function(){
        currentTime = 120000;
        if(!window.Timer2.isActive){
        window.Timer2.play().once();
        }
        window.Timer1.play();
    }
$(init);
});
});
 
$(document).keypress(function(){Obj2.resetTimer();});
var count2 = 0,
$(document).click(function(){Obj2.resetTimer();});
    timer = $.timer(function() {
$(document).mousemove(function(){Obj2.resetTimer();});
$(document).scroll(function(){Obj2.resetTimer();});
        count2++;
        $('#counter2').html(count);
    });
timer.set({ time : '', autostart : true });
 
 
// Common functions
function pad(number, length) {
 
    var str = '' + number;
    while (str.length < length) {str = '0' + str;}
    return str;
}
function formatTime(time) {
 
    var min = parseInt(time / 6000),
        sec = parseInt(time / 100) - (min * 60),
        hundredths = pad(time - (sec * 100) - (min * 6000), 2);
    return (min > 0 ? pad(min, 2) : "") + ":" + pad(sec, 2) + ":" + hundredths;
}
}
});
});
</script>
</script>
 
<span id="output1"></span><br />
<span id="stopwatch">00:00:00</span>
<span id="output2"></span>
<p>
<input type='button' value='Play/Pause' onclick='Example1.Timer.toggle();' />
<input type='button' value='Stop/Reset' onclick='Example1.resetStopwatch();' />
</p>
<span id="stopwatch2">00:00:00</span>
<p>
<input type='button' value='Play/Pause' onclick='Example2.Timer.toggle();' />
<input type='button' value='Stop/Reset' onclick='Example2.resetStopwatch();' />
</p>
</includeonly>
</includeonly>

Latest revision as of 18:26, 24 April 2014