MediaWiki:Common.js: 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: | ||
mw.loader.using('mediawiki.user',function(){ | mw.loader.using('mediawiki.user', function () { | ||
$('tr').css('height : 1px'); | $('tr').css('height : 1px'); | ||
if($.inArray("CMEUser", mw.config.get( 'wgUserGroups' )) != "-1"){ | if ($.inArray("CMEUser", mw.config.get('wgUserGroups')) != "-1") { | ||
$.getScript( 'http://www.wikidoc.org/includes/raty/jquery.timer.js',function(){ | $.getScript('http://www.wikidoc.org/includes/raty/jquery.timer.js', function () { | ||
var Obj1 = new (function(){ | var Obj1 = new(function () { | ||
var $timer1, | |||
incrementTime = 100, | |||
currentTime = 0, | |||
updateTimer = function () { | |||
$timer1.html(currentTime); | |||
currentTime += incrementTime; | |||
if (currentTime == 30000) { | |||
if (window.location.pathname === "/index.php") { | |||
var path = window.location.search.substring(1, window.location.search.length) | |||
} else { | |||
var path = window.location.pathname.substring(11, window.location.pathname.length) | |||
} | |||
var api = new mw.Api(); | |||
api.get({ | |||
action : 'updatetracker', | |||
user : mw.user.getName(), | |||
activity : path, | |||
}).done(function (data) { | |||
console.log(data); | |||
}); | |||
currentTime = 0; | |||
} | |||
}, | |||
init = function () { | |||
$timer1 = $('#output1'); | |||
window.Timer1 = $.timer(updateTimer, incrementTime, true); | |||
}; | |||
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(); | |||
}); | |||
$(document).click(function () { | |||
Obj2.resetTimer(); | |||
}); | |||
$(document).mousemove(function () { | |||
Obj2.resetTimer(); | |||
}); | |||
$(document).scroll(function () { | |||
Obj2.resetTimer(); | |||
}); | |||
}); | |||
} | |||
}); | |||
mw.loader.using('mediawiki.user', function () { | |||
$(document).ready(function () { | |||
var rand = Math.floor((Math.random() * 10) + 1); | |||
//if(rand > 5){ | |||
if (1) { | |||
butterbarShouldDisplay(); | |||
} | |||
function butterbarShouldDisplay() { | |||
if (mw.user.isAnon()) { | |||
if (getCookie("butterbarHide") != "1") { | |||
butterbarShow(); | |||
} | |||
} else { | |||
if ($.inArray("hideButterbar", mw.config.get('wgUserGroups')) == "-1") { | |||
butterbarShow(); | |||
} | |||
} | |||
} | |||
function butterbarShow() { | |||
$("#globalWrapper").prepend("<div id='butterbar'>You can earn CME Credit by browsing wikidoc! Click <a href='http://www.wikidoc.org/index.php/Special:CMERegister'>here</a> to register! or <div id='permaHide'>Never show again</div><div id='butterbarClose'>X</div></div>"); | |||
$("#butterbarClose").click(function () { | |||
$("#butterbar").remove(); | |||
}); | |||
$("#permaHide").click(function() { | |||
butterbarNeverAgain() | |||
}); | |||
} | |||
function butterbarNeverAgain(){ | |||
if (mw.user.isAnon()) { | |||
setCookie("butterbarHide", "1", 365); | |||
} else { | |||
var api = new mw.Api(); | |||
api.get({ | |||
action:'query', | |||
list:'users', | |||
ususers:mw.user.getName( ), | |||
}).done(function (data) { | |||
var newApi = new mw.Api(); | |||
api.get({ | |||
action:'user', | |||
token:data.query.users.userrightstoken, | |||
add:'hideButterbar' | |||
}); | |||
} | |||
} | |||
function setCookie(cname, cvalue, exdays) { | |||
var d = new Date(); | |||
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); | |||
var expires = "expires=" + d.toUTCString(); | |||
document.cookie = cname + "=" + cvalue + "; " + expires; | |||
} | |||
function getCookie(cname) { | |||
var name = cname + "="; | |||
var ca = document.cookie.split(';'); | |||
for (var i = 0; i < ca.length; i++) { | |||
var c = ca[i]; | |||
while (c.charAt(0) == ' ') | |||
c = c.substring(1); | |||
if (c.indexOf(name) != -1) | |||
return c.substring(name.length, c.length); | |||
} | |||
return ""; | |||
} | |||
} | |||
}); | |||
}); | |||
}); | }); |
Revision as of 03:33, 27 October 2014
mw.loader.using('mediawiki.user', function () { $('tr').css('height : 1px'); if ($.inArray("CMEUser", mw.config.get('wgUserGroups')) != "-1") { $.getScript('http://www.wikidoc.org/includes/raty/jquery.timer.js', function () { var Obj1 = new(function () { var $timer1, incrementTime = 100, currentTime = 0, updateTimer = function () { $timer1.html(currentTime); currentTime += incrementTime; if (currentTime == 30000) { if (window.location.pathname === "/index.php") { var path = window.location.search.substring(1, window.location.search.length) } else { var path = window.location.pathname.substring(11, window.location.pathname.length) } var api = new mw.Api(); api.get({ action : 'updatetracker', user : mw.user.getName(), activity : path, }).done(function (data) { console.log(data); }); currentTime = 0; } }, init = function () { $timer1 = $('#output1'); window.Timer1 = $.timer(updateTimer, incrementTime, true); }; 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(); }); $(document).click(function () { Obj2.resetTimer(); }); $(document).mousemove(function () { Obj2.resetTimer(); }); $(document).scroll(function () { Obj2.resetTimer(); }); }); } }); mw.loader.using('mediawiki.user', function () { $(document).ready(function () { var rand = Math.floor((Math.random() * 10) + 1); //if(rand > 5){ if (1) { butterbarShouldDisplay(); } function butterbarShouldDisplay() { if (mw.user.isAnon()) { if (getCookie("butterbarHide") != "1") { butterbarShow(); } } else { if ($.inArray("hideButterbar", mw.config.get('wgUserGroups')) == "-1") { butterbarShow(); } } } function butterbarShow() { $("#globalWrapper").prepend("<div id='butterbar'>You can earn CME Credit by browsing wikidoc! Click <a href='http://www.wikidoc.org/index.php/Special:CMERegister'>here</a> to register! or <div id='permaHide'>Never show again</div><div id='butterbarClose'>X</div></div>"); $("#butterbarClose").click(function () { $("#butterbar").remove(); }); $("#permaHide").click(function() { butterbarNeverAgain() }); } function butterbarNeverAgain(){ if (mw.user.isAnon()) { setCookie("butterbarHide", "1", 365); } else { var api = new mw.Api(); api.get({ action:'query', list:'users', ususers:mw.user.getName( ), }).done(function (data) { var newApi = new mw.Api(); api.get({ action:'user', token:data.query.users.userrightstoken, add:'hideButterbar' }); } } function setCookie(cname, cvalue, exdays) { var d = new Date(); d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); var expires = "expires=" + d.toUTCString(); document.cookie = cname + "=" + cvalue + "; " + expires; } function getCookie(cname) { var name = cname + "="; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') c = c.substring(1); if (c.indexOf(name) != -1) return c.substring(name.length, c.length); } return ""; } }); });