User:CaptFredricks/common.js

/***********************************************************
 * CAPTFREDRICKS' PERSONAL SCRIPTS:
 * FEEL FREE TO USE WHATEVER YOU LIKE ON YOUR OWN PERSONAL
 * JS PAGE (Special:MyPage/common.js)
 * code on this page affects all skins

/* Imports */

importScriptPage('UTCClock/code.js', 'dev'); // UTC clock

/* Add an extra CSS class to the body tag on user profiles */

setTimeout(function {	// Check whether the user profile app exists (i.e., we are viewing a user's profile)	if($('#userProfileApp').length) {		// Add the "user-profile" class to the body tag		$('body').addClass('user-profile');	} }, 1000);

/* Make the header sticky on scroll (UCX) */

// Fetch the current scroll position var current_scroll = getCurrentScroll;

// Toggle the sticky header based on the scroll position toggleStickyHeader((current_scroll > 0));

// Execute an event when the page is scrolled $(window).on('scroll', function {	// Fetch the current scroll position	current_scroll = getCurrentScroll;	// Toggle the sticky header based on the scroll position	toggleStickyHeader((current_scroll > 0)); });

// Fetch and return the current scroll position function getCurrentScroll { return window.pageYOffset || document.documentElement.scrollTop; }

// Toggle the sticky header function toggleStickyHeader(is_sticky) { // Check whether the header should be sticky if(is_sticky) { // Add the 'sticky' class to the header $('.wds-community-header').addClass('sticky'); } else { // Remove the 'sticky' class from the header $('.wds-community-header').removeClass('sticky'); } }