MediaWiki:Common.js: Difference between revisions

MediaWiki interface page
(Created page with "→‎Any JavaScript here will be loaded for all users on every page load.: $(document).ready(function() { var getMax = function(){ return $(document).height() - $(...")
 
No edit summary
Tag: Manual revert
 
(25 intermediate revisions by the same user not shown)
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */


$(document).ready(function() {
/* https://github.com/prtksxna/persistent-toc */
   
/* mw.loader.load( 'https://cdn.rawgit.com/prtksxna/persistent-toc/master/ptoc.css', 'text/css' ); */
  var getMax = function(){
/* mw.loader.load( 'https://cdn.rawgit.com/prtksxna/persistent-toc/master/ptoc.js', 'text/javascript' ); */
    return $(document).height() - $(window).height();
  }
   
  var getValue = function(){
    return $(window).scrollTop();
  }
   
  if ('max' in document.createElement('progress')) {
    // Browser supports progress element
    var progressBar = $('progress');
       
    // Set the Max attr for the first time
    progressBar.attr({ max: getMax() });


    $(document).on('scroll', function(){
/* Persistent Table of Contents */
      // On scroll only Value attr needs to be calculated
/* mw.loader.load( 'https://zd10.net/new_wiki/skins/pivot/assets/stylesheets/ptoc.css', 'text/css' ); */
      progressBar.attr({ value: getValue() });
/* mw.loader.load( 'https://zd10.net/new_wiki/skins/pivot/assets/scripts/ptoc.js', 'text/javascript' ); */
    });
     
    $(window).resize(function(){
      // On resize, both Max/Value attr needs to be calculated
      progressBar.attr({ max: getMax(), value: getValue() });
    });
 
  } else {


    var progressBar = $('.progress-bar'),
/* Tooltipster */
        max = getMax(),
/* $(document).ready(function() { */
        value, width;
/*            $('.tooltip').tooltipster(); */
       
/*        }); */
    var getWidth = function() {
      // Calculate width in percentage
      value = getValue();           
      width = (value/max) * 100;
      width = width + '%';
      return width;
    }
       
    var setWidth = function(){
      progressBar.css({ width: getWidth() });
    }
       
    $(document).on('scroll', setWidth);
    $(window).on('resize', function(){
      // Need to reset the Max attr
      max = getMax();
      setWidth();
    });
  }
});

Latest revision as of 19:54, 6 September 2022

/* Any JavaScript here will be loaded for all users on every page load. */

/* https://github.com/prtksxna/persistent-toc */
/* mw.loader.load( 'https://cdn.rawgit.com/prtksxna/persistent-toc/master/ptoc.css', 'text/css' ); */
/* mw.loader.load( 'https://cdn.rawgit.com/prtksxna/persistent-toc/master/ptoc.js', 'text/javascript' ); */

/* Persistent Table of Contents */
/* mw.loader.load( 'https://zd10.net/new_wiki/skins/pivot/assets/stylesheets/ptoc.css', 'text/css' ); */
/* mw.loader.load( 'https://zd10.net/new_wiki/skins/pivot/assets/scripts/ptoc.js', 'text/javascript' ); */

/* Tooltipster */
/* $(document).ready(function() { */
/*            $('.tooltip').tooltipster(); */
/*        }); */
We collect cookies to analyze our website traffic and performance; we never collect any personal data.