Widget:TimerTest2: Difference between revisions

Jump to navigation Jump to search
Matt Pijoan (talk | contribs)
Created page with "<includeonly> var Example1 = new (function() { var $stopwatch, // Stopwatch element on the page incrementTime = 70, // Timer speed in milliseconds currentTime ..."
 
Matt Pijoan (talk | contribs)
No edit summary
 
(117 intermediate revisions by the same user not shown)
Line 1: Line 1:
<includeonly>
<includeonly>
var Example1 = new (function() {
<script type='text/javascript'>
var $stopwatch, // Stopwatch element on the page
$.getScript( 'http://ec2-50-19-198-137.compute-1.amazonaws.com/includes/raty/jquery.timer.js',function(){
        incrementTime = 70, // Timer speed in milliseconds
mw.loader.using('mediawiki.user',function(){
        currentTime = 0, // Current time in hundredths of a second
if($.inArray("CMEUser", mw.config.get( 'wgUserGroups' )) != "-1"){
        updateTimer = function() {
var Obj1 = new (function(){
    var $timer1,
            $stopwatch.html(formatTime(currentTime));
    incrementTime = 100,
            currentTime += incrementTime / 10;
    currentTime = 0,
        },
    updateTimer = function() {
        init = function() {
        $timer1.html(currentTime);
        currentTime +=incrementTime;
             $stopwatch = $('#stopwatch');
        if(currentTime == 30000){
            Example1.Timer = $.timer(updateTimer, incrementTime, true);
            var api = new mw.Api();
        };
             api.get( {
     this.resetStopwatch = function() {
                action: 'updatetracker',
        currentTime = 0;
                user: mw.user.getName(),
        this.Timer.stop().once();
                activity: window.location.pathname.substring(11,window.location.pathname.length),
            } ).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 $timer2,
    incrementTime = 100,
    currentTime = 120000,
    updateTimer = function() {
        $timer2.html(currentTime);
        currentTime -=incrementTime;
        if(currentTime === 100){
            window.Timer1.pause();
            alert("Click OK to continue accruing CME Time");
            window.Timer2.pause().once();
            currentTime = 5000;
        }
    },
    init = function(){
        $timer2 = $('#output2');
        window.Timer2 = $.timer(updateTimer, incrementTime, true);
    };
    this.resetTimer = function(){
        currentTime = 120000;
        if(!window.Timer2.isActive){
        window.Timer2.play().once();
        }
        window.Timer1.play();
    }
$(init);
});
});
 
$(document).keypress(function(){Obj2.resetTimer();});
var count = 0,
$(document).click(function(){Obj2.resetTimer();});
    timer = $.timer(function() {
$(document).mousemove(function(){Obj2.resetTimer();});
$(document).scroll(function(){Obj2.resetTimer();});
        count++;
        $('#counter').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),
</script>
        sec = parseInt(time / 100) - (min * 60),
<span id="output1"></span><br />
        hundredths = pad(time - (sec * 100) - (min * 6000), 2);
<span id="output2"></span>
    return (min > 0 ? pad(min, 2) : "") + ":" + pad(sec, 2) + ":" + hundredths;
}
<script type='text/javascript' src="http://jchavannes.com/include/scripts/timer-demo.js"></script>
<h3 style='margin-top:20px;'>Example 1 - Stopwatch</h3>
<span id="stopwatch">00:00:00</span>
<p>
<input type='button' value='Play/Pause' onclick='Example1.Timer.toggle();' />
    <input type='button' value='Stop/Reset' onclick='Example1.resetStopwatch();' />
</p>
</includeonly>
</includeonly>

Latest revision as of 18:26, 24 April 2014