No edit summary |
No edit summary Tag: Visual edit |
||
Line 3: | Line 3: | ||
/* Originally from: http://tardis.wikia.com/wiki/MediaWiki:Common.js/displayTimer.js */ |
/* Originally from: http://tardis.wikia.com/wiki/MediaWiki:Common.js/displayTimer.js */ |
||
(function(){ |
(function(){ |
||
− | var refreshDate; // Timeout |
||
var CLOCK_ID = "#ca-time"; |
var CLOCK_ID = "#ca-time"; |
||
+ | var isPurging = false; |
||
function showTime() { |
function showTime() { |
||
+ | if(isPurging) { return; } |
||
var now = new Date(), |
var now = new Date(), |
||
dd = now.getUTCDate(), |
dd = now.getUTCDate(), |
||
Line 13: | Line 14: | ||
ss = now.getUTCSeconds(), |
ss = now.getUTCSeconds(), |
||
time = "<small style='font-size:70%;'>(" + dd + ")</small>" + ( hh < 10 ? '0' + hh : hh ) + ':' + ( mm < 10 ? '0' + mm : mm ) + ':' + ( ss < 10 ? '0' + ss : ss ); |
time = "<small style='font-size:70%;'>(" + dd + ")</small>" + ( hh < 10 ? '0' + hh : hh ) + ':' + ( mm < 10 ? '0' + mm : mm ) + ':' + ( ss < 10 ? '0' + ss : ss ); |
||
− | $(CLOCK_ID).empty().append('<span>' + time + '</span>'); |
+ | $(CLOCK_ID).empty().append('<span style="pointer-events: none;">' + time + '</span>'); |
+ | } |
||
− | window.clearTimeout(refreshDate); |
||
+ | |||
⚫ | |||
+ | function doPurge() { |
||
+ | return $.post(mw.util.wikiScript('api'), { action: 'purge', titles: mw.config.get('wgPageName') }); |
||
} |
} |
||
Line 27: | Line 30: | ||
$(CLOCK_ID).attr("title", 'Purge the server cache and update the contents of this page.'); |
$(CLOCK_ID).attr("title", 'Purge the server cache and update the contents of this page.'); |
||
− | $(CLOCK_ID).attr("href", wgArticlePath.replace('$1', wgPageName.replace(/ /g, '_')) + '?action=purge'); |
+ | $(CLOCK_ID).attr("href", window.location.href);//wgArticlePath.replace('$1', wgPageName.replace(/ /g, '_')) + '?action=purge'); |
+ | $(CLOCK_ID).attr("target", '_blank'); |
||
if (skin == 'oasis') { |
if (skin == 'oasis') { |
||
$(CLOCK_ID).css({ "font-family":"\'Futura\', \'Gill Sans\', \'Helvetica Neue\',\'Trebuchet MS\', sans-serif", "font-size":"12px" }); |
$(CLOCK_ID).css({ "font-family":"\'Futura\', \'Gill Sans\', \'Helvetica Neue\',\'Trebuchet MS\', sans-serif", "font-size":"12px" }); |
||
} |
} |
||
+ | |||
+ | // Purge functionality |
||
+ | $(CLOCK_ID).on("click", function(e){ |
||
+ | var useNewTab = e.ctrlKey; |
||
+ | if(!useNewTab) { |
||
+ | e.preventDefault(); |
||
+ | } |
||
+ | isPurging = true; |
||
+ | $(this).html($('<img>', { src: 'https://images.wikia.nocookie.net/dev/images/4/42/Loading.gif' })); |
||
+ | doPurge().done(function(){ |
||
+ | isPurging = false; |
||
+ | // Open new window to same link if ctrl is held, otherwise refresh page |
||
+ | if(e.ctrlKey) { |
||
+ | // window.open(window.location.href, "_blank"); |
||
+ | // $(CLOCK_ID).click(); |
||
+ | } else { |
||
+ | window.location.reload(); |
||
+ | } |
||
+ | }); |
||
+ | return useNewTab; |
||
+ | }); |
||
+ | // Start clock |
||
− | showTime(); |
||
⚫ | |||
}); |
}); |
||
})(); |
})(); |
Revision as of 02:01, 9 December 2020
//
/* This Javascript inputs a clock next to the user navigation at the top of the page. */
/* Originally from: http://tardis.wikia.com/wiki/MediaWiki:Common.js/displayTimer.js */
(function(){
var CLOCK_ID = "#ca-time";
var isPurging = false;
function showTime() {
if(isPurging) { return; }
var now = new Date(),
dd = now.getUTCDate(),
hh = now.getUTCHours(),
mm = now.getUTCMinutes(),
ss = now.getUTCSeconds(),
time = "<small style='font-size:70%;'>(" + dd + ")</small>" + ( hh < 10 ? '0' + hh : hh ) + ':' + ( mm < 10 ? '0' + mm : mm ) + ':' + ( ss < 10 ? '0' + ss : ss );
$(CLOCK_ID).empty().append('<span style="pointer-events: none;">' + time + '</span>');
}
function doPurge() {
return $.post(mw.util.wikiScript('api'), { action: 'purge', titles: mw.config.get('wgPageName') });
}
$(document).ready(function() {
// Add timer container as needed.
if (skin != 'oasis') {
$( '<li><a id="ca-time" href="#"></a></li>').appendTo('#p-cactions > .pBody > ul' );
} else {
$( '<div class="wds-global-navigation__start-a-wiki custom-fewfre"><a id="ca-time" class="wds-button wds-is-squished wds-is-secondary custom-fewfre"></a></div>').appendTo(".wds-global-navigation__dropdown-controls");
}
$(CLOCK_ID).attr("title", 'Purge the server cache and update the contents of this page.');
$(CLOCK_ID).attr("href", window.location.href);//wgArticlePath.replace('$1', wgPageName.replace(/ /g, '_')) + '?action=purge');
$(CLOCK_ID).attr("target", '_blank');
if (skin == 'oasis') {
$(CLOCK_ID).css({ "font-family":"\'Futura\', \'Gill Sans\', \'Helvetica Neue\',\'Trebuchet MS\', sans-serif", "font-size":"12px" });
}
// Purge functionality
$(CLOCK_ID).on("click", function(e){
var useNewTab = e.ctrlKey;
if(!useNewTab) {
e.preventDefault();
}
isPurging = true;
$(this).html($('<img>', { src: 'https://images.wikia.nocookie.net/dev/images/4/42/Loading.gif' }));
doPurge().done(function(){
isPurging = false;
// Open new window to same link if ctrl is held, otherwise refresh page
if(e.ctrlKey) {
// window.open(window.location.href, "_blank");
// $(CLOCK_ID).click();
} else {
window.location.reload();
}
});
return useNewTab;
});
// Start clock
window.setInterval(showTime, 1000);
});
})();
//