MediaWiki:Gadget-stickyHeader.js

From Official Gamemode 4 Wiki
Revision as of 06:17, 3 March 2024 by Epyon (talk | contribs) (Created page with "→‎* * @see Based on https://minecraft.wiki/w/MediaWiki:Gadget-stickyHeader.js: $(function() { $('#left-navigation, #right-navigation').wrapAll('<div id="stickyTop"></div>').wrapAll('<div id="stickyTopFlex"></div>'); $('<div id="stickyTopBack"></div>').appendTo('#stickyTop'); var stickyTop = $('#stickyTop'); if ('ext.gadget.fixedWidth' in mw.loader.moduleRegistry && mw.loader.moduleRegistry['ext.gadget.fixedWidth'].state === 'ready') { stickyTo...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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.
/*
 * 
 * @see Based on https://minecraft.wiki/w/MediaWiki:Gadget-stickyHeader.js
 */
$(function() {
    $('#left-navigation, #right-navigation').wrapAll('<div id="stickyTop"></div>').wrapAll('<div id="stickyTopFlex"></div>');
    $('<div id="stickyTopBack"></div>').appendTo('#stickyTop');
    var stickyTop = $('#stickyTop');
    if ('ext.gadget.fixedWidth' in mw.loader.moduleRegistry && mw.loader.moduleRegistry['ext.gadget.fixedWidth'].state === 'ready') {
    	stickyTop.addClass('fixedWidth');
    }
    var nsTop = $('#p-namespaces').offset().top;

    function sticky() {
	    var scrollTop = $(window).scrollTop();
	
	    if (scrollTop > nsTop) { 
	        stickyTop.addClass('stick');
	    } else {
	        stickyTop.removeClass('stick'); 
	    }
    };

    sticky();

    $(window).scroll(sticky);
});