MediaWiki:Common.js
Jump to navigation
Jump to search
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */
// AJAX tables (for Template:Ajax)
function addAjaxDisplayLink() {
$("table.ajax").each(function (i) {
var table = $(this).attr("id", "ajaxTable" + i);
table.find(".nojs-message").remove();
var headerLinks = $('<span style="float: right;">').appendTo(table.find('th').first());
var cell = table.find("td").first(), needLink = true;
cell.parent().show();
if (cell.hasClass("showLinkHere")) {
var old = cell.html(), rep = old.replace(/\[link\](.*?)\[\/link\]/, '<a href="javascript:;" class="ajax-load-link">$1</a>');
if (rep != old) {
cell.html(rep);
needLink = false;
}
}
if (needLink) headerLinks.html('[<a href="javascript:;" class="ajax-load-link">show data</a>]');
table.find(".ajax-load-link").parent().addBack().filter('a').click(function(event) {
event.preventDefault();
var sourceTitle = table.data('ajax-source-page'), baseLink = mw.config.get('wgScript') + '?';
cell.text('Please wait, the content is being loaded...');
$.get(baseLink + $.param({ action: 'render', title: sourceTitle }), function (data) {
if (data) {
cell.html(data);
cell.find('.ajaxHide').remove();
cell.find('.terraria').removeClass('terraria');
if (cell.find("table.sortable").length) {
mw.loader.using('jquery.tablesorter', function() {
cell.find("table.sortable").tablesorter();
});
}
headerLinks.text('[');
headerLinks.append($('<a>edit</a>').attr('href', baseLink + $.param({ action: 'edit', title: sourceTitle })));
headerLinks.append(document.createTextNode(']\u00A0['));
var shown = true;
$("<a href='javascript:;'>hide</a>").click(function() {
shown = !shown;
shown ? cell.show() : cell.hide();
$(this).text(shown ? "hide" : "show");
}).appendTo(headerLinks);
headerLinks.append(document.createTextNode(']'));
}
}).error(function() {
cell.text('Unable to load table; the source article for it might not exist.');
});
});
});
}
$(addAjaxDisplayLink);
/////////////TEMPLATE
$(function(){
/* mode tabs switch for [[Template:npcinfobox]] and [[Template:npcinfobtable]] and so on */
$('.modesbox .modetabs .tab').on('click', function(){
var $this = $(this);
if($this.hasClass('current')){
return;
}
$this.parent().children().removeClass('current');
$this.addClass('current');
$this.closest('.modesbox').removeClass('c-expert c-master c-normal').addClass($this.hasClass('normal')?'c-normal':($this.hasClass('expert')?'c-expert':'c-master'));
});
/* extra mode tabs switch for souls mod difficulty */
$('.modesbox .emodetabs .tab').on('click', function(){
var $this = $(this);
if($this.hasClass('current')){
return;
}
$this.parent().children().removeClass('current');
$this.addClass('current');
$this.closest('.modesbox').removeClass('c-eternity c-masochist c-vanilla').addClass($this.hasClass('vanilla')?'c-vanilla':($this.hasClass('eternity')?'c-eternity':'c-masochist'));
});
});