MediaWiki:Chameleon.js

From EngageWiki
Revision as of 21:12, 3 December 2021 by WikiVisor (talk | contribs)

Note: After saving, 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: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
var tagline = $('<div>')
	.addClass('banner-tagline')
	.text( "" );

$('.banner').after(tagline);

var gotop = $('<button>')
	.addClass('d-print-none noprint')
	.prop('id', 'back-to-top')
	.prop('title', 'Go to top')
	.prop('onclick', 'topFunction()')
	.append( $('<i>')
		.addClass('fas fa-chevron-up')
	);
	
$('.flex-fill.container').append(gotop);

$('.page-Special_RequestAccount input, .page-Special_RequestAccount textarea').addClass('form-control');
$('.page-EngageWiki_Interactive_research_map_of_ATM .flex-fill.container').toggleClass('container container-fluid');

$(document).scroll(function() {
if($(document).scrollTop() >= 84) {
	$('#mw-navigation').css({'position':'fixed','width':'100%'});
} else {
	$('#mw-navigation').css('position','relative');
}
});

$(document).ready(function() {
	
	modifyNavbarItems();
	progButtonsPlacement();
	resizeIframe();
	menuDivider();
    makeDraggable();
    updateForm();
    accountReqTickbox();
    imapCalls();
    
	if($('.dataTable').length){
//		mw.loader.using( 'DataTables', function() {
			injectDatatables();
//		});
	}

	$(window).scroll(function () {
		if ($(this).scrollTop() > 50) {
			$('#back-to-top').fadeIn();
		} else {
			$('#back-to-top').fadeOut();
		}
	});

	$('#back-to-top').click(function () {
		$('body,html').animate({
			scrollTop: 0
		}, 400);
		return false;
	});

});

function modifyNavbarItems(){
	var uname = mw.config.get('wgUserName');
	$('a.navbar-userloggedin').addClass('text-nowrap nav-link').text(uname);
	
	var anonlinks = $('.navbar-tools:eq(1)');
	$('.pt-createaccount, .pt-login').addClass('nav-link').detach().prependTo(anonlinks);

	$('a.navbar-more-tools').text("Page").addClass('dropdown-toggle nav-link');
	$('a.ca-edit').text("Edit").addClass('text-nowrap nav-link');
	
	$('#footer-info').closest('.row').css({'align-items':'flex-end', 'line-height':'1.2rem'});
}

function injectDatatables(){
        checknode = $('table.dataTable');
        $(checknode).DataTable({
                dom: '<"top d-flex flex-column flex-md-row justify-content-between"Bif>t<"bottom"p><"clear">',
                pageLength: 50,
				buttons: [ 'excel' ],
                responsive: true,
                language: {
                        "sSearch":              "",
                },
                fnInitComplete: function() {
                	    $('.dt-buttons .buttons-excel').toggleClass('btn btn-secondary mw-ui-button mw-ui-progressive m-auto p-1 px-4');
                	    $('.dt-buttons .buttons-excel span').html('Export to Excel');
                        $('div.dataTables_filter input').addClass('rounded-0 ml-0 p-3 bg-white').css({'border':'2px solid #2f85a8','box-shadow':'none'}).prop('placeholder', 'Filter ...').focus();
                        $('a.paginate_button.current').css({"background":"#f6f6f6"}).addClass('border-0 text-primary');
                        $('.paginate_button').hover(function () {
        			        $(this).addClass('bg-light');
        		       }, function () {
        			        $(this).removeClass('bg-light');
            		   }
            	);
        }
});
}

function progButtonsPlacement(){
	var buttons = $('#programmes-buttons');
	$('.filtered').addClass('row');
    $(buttons).detach().appendTo('.filtered-filters').toggleClass('d-none d-flex');
}

$(window).on('resize', function(){
      resizeIframe();
});

function resizeIframe(){
	$('.research-mapping').css('height', $(window).height()+'px');
}
function menuDivider(){
	$('.dropdown-menu a[href="#"]').css({'height': '0','padding': '0', 'margin': '.5rem 0', 'border-top': '1px solid #f0f0f0','color':'#fff'});
}

function makeDraggable() {
var draggable = $('.draggable'); //element 

draggable.on('mousedown', function(e){
	var dr = $(this).addClass("drag").css("cursor","move");
	height = dr.outerHeight();
	width = dr.outerWidth();
	ypos = dr.offset().top + height - e.pageY,
	xpos = dr.offset().left + width - e.pageX;
	$(document.body).on('mousemove', function(e){
		var itop = e.pageY + ypos - height;
		var ileft = e.pageX + xpos - width;
		if(dr.hasClass("drag")){
			dr.offset({top: itop,left: ileft});
		}
	}).on('mouseup', function(e){
			dr.removeClass("drag");
	});
});
}

function updateForm() {
//	$('#contactpage-education .oo-ui-fieldLayout').eq(1).hide();
	$('#contactpage-education .oo-ui-fieldLayout').eq(2).hide();
	$('#contactpage-education .oo-ui-fieldLayout').eq(3).hide();
	$('#contactpage-education').css({'visibility':'visible'});
}
function accountReqTickbox() {
	$('#wpToS').closest('p').addClass('d-flex');
}
function imapCalls(){
	$('.imap-call').click(function(){
		$(this).css({'background-color':'#2f85a8','color':'white'});	
		$('.imap-call').not(this).css({'background-color':'#f7f7f7','color':'inherit'});
	});
}

This project has received funding from the SESAR Joint Undertaking under the European Union’s Horizon 2020 research and innovation programme under grant agreement No 783287.