MediaWiki:Common.js

From OTC Wiki

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)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */

$( '.smw-feed-furtherresults > a' ).addClass( 'feedlink' );

$(function() {
	dynamicApi();
	opinionApi();
	editMeta();
	moveDisclaimers();
	newsCount();
	moveFeatured();
	moveEditorCta();
	adjustFormedit();
	backToTop();
	hideFeaturedPrefix();
	injectDataTables();
	moveToSidepanel();
	moveToSubpages();
	moveRelatedPages();
	moveToTop();
	showForLoggedIn();
});

function dynamicApi() {
    current = mw.config.get( 'wgPageName' );
    
	$(document).on('click', '.subpage-call', function(){
        $('ul.subpages li.active').removeClass('active');
        $(this).parent().addClass('active');
        		var term = $(this).text();
        $('.add-opinion, .sub-section:not(#'+term+'Sect)').hide();
		$('#' + term + 'Sect').show();
	});
}

function opinionApi() {
    current = mw.config.get( 'wgPageName' );
	$(document).on('click', '.opinion-call', function(){
        $('ul.subpages li.active').removeClass('active');
        $(this).parent().addClass('active');
        $('.add-opinion').show();
        $('.sub-section').hide();
	});
}

function moveToTop() {
	$('.contentHeader').after($('.move-to-top'));
}

function editMeta() {
	$('.ns-0 #edit-meta').detach().insertBefore('#top-notice').toggleClass('d-none d-flex');
	$('.ns-8 #edit-meta').toggleClass('d-none d-flex'); 
}

function moveDisclaimers() {
    // if($('#article-disclaimers').length > 0) {
        $('#article-disclaimers').detach().insertBefore('#bottom-notice-ns').show();
    //}
    $('.mw-references-wrap').before('<h2>References</h2>');
}

function newsCount(){
    var newsSection;

    var numLinks = $('.stock-link').length;
    if(numLinks > 0){
        newsSection = $('<span class="icounter">(' + numLinks + ')</span>');
        $(newsSection).insertAfter('.subpage-call.Links');
    }
    var numOps = $('.opinion').length;
    if(numOps > 0){
        newsSection = $('<span class="icounter">(' + numOps + ')</span>');
        $(newsSection).insertAfter('.opinion-call');
    }
    var numFaqs = $('.qna-question').length;
    if(numFaqs > 0){
        newsSection = $('<span class="icounter">(' + numFaqs + ')</span>');
        $(newsSection).insertAfter('.subpage-call.FAQs');
    }
}

function backToTop() {
	$('#back-to-top').click(function(e) {
        e.preventDefault();
        $('html, body').animate({
                scrollTop: "0"
        });
	});
	$(window).scroll(function() {
        if ($(this).scrollTop()) {
                $('#back-to-top').css('visibility', 'visible');
        } else {
                $('#back-to-top').css('visibility', 'hidden');
        }
	});
}

function hideFeaturedPrefix(){
	$('.ns-3006 #firstHeading').text( '' + mw.config.get('wgTitle') + '').show();
}

function moveFeatured(){
	$('#featured-announce').detach().insertBefore('#p-search').toggleClass('d-none d-flex');
}

function moveEditorCta(){
	$('.editor-cta').detach().insertBefore('#firstHeading');
}

function adjustFormedit() {
	$('.ns-3002 a.ca-formedit').text('Assign editor').css({'visibility':'visible'});
}

function injectDataTables() {
    mw.loader.using( 'ext.datatables' ).then( function () {
        recentWikis();
    });
}

function recentWikis() {
    if($('table#recent-wikis').length){
        $('table#recent-wikis').DataTable({
			dom: '',
			responsive: true,
			order: [[ 1, 'desc' ]],
    		columns: [
{ "title": "Company" },
{ "title": "Date" },
{ "title": "Editor" }
			],
			aoColumns: [],
			lengthMenu: [
				[10, 25, 50], [10, 25, 50]
			],
			pageLength: 50,
			fnInitComplete: function() {    
			}
    	});
	}
}
function moveToSidepanel() {
	$('[id^="moveto-sidebar"]').detach().appendTo('.side-panel-right').show();
}
function moveToSubpages() {
	var stockp = $('#movetosubpages').html();
	$('.subpages').append(stockp);
}
function moveRelatedPages() {
	var rmc = $('.read-more-container');
	if(rmc.length > 0){
		$('#bottom-notice-ns').append(rmc);
	}
}
function showForLoggedIn(){
	if ( mw.config.get( 'wgUserId' ) !== null ) {
		$('.loggedin').show();
	}
}