MediaWiki:Common.js

From FFXI Wiki
Revision as of 07:58, 2 May 2021 by Darvamos (talk | contribs) (Fish Caught Counter)

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.
/* Any JavaScript here will be loaded for all users on every page load. */

/** Rotate Table Row Colors ***************************************/
var ts_alternate_row_colors = true;

/* Show All Button */
$('#button-expand-all').click(function() {
    if ($('#button-expand-all').hasClass("button-expand-all-hide")) {
        $('.collapseButton a:contains("hide")').each(function() {
            this.click();
        });
    } else if ($('#button-expand-all').hasClass("button-expand-all-show")) {
        $('.collapseButton a:contains("show")').each(function() {
            this.click();
        });
    }
    $(this).text(function(i, v) {
        return v === 'Show All Tables' ? 'Hide All Tables' : 'Show All Tables';
    });
    $('#button-expand-all').toggleClass('button-expand-all-show button-expand-all-hide');
});

/** Green Tabs **/
$( document ).ready( function() {
  $( 'ul.tabs li' ).click( function() {
    var tab_id = $( this ).attr( 'data-tab-number' );
    var tab_group_number = $( this ).attr( 'data-tab-group' );
    $( ".group" + tab_group_number ).removeClass( 'current' );
    $( this ).addClass( 'current' );
    $( "#" + tab_id ).addClass( 'current' );
  } )
} )

/** Blue Tabs **/
$( document ).ready( function() {
  $( 'ul.tabsb li' ).click( function() {
    var tab_id = $( this ).attr( 'data-tab-number' );
    var tab_group_number = $( this ).attr( 'data-tab-group' );
    $( ".group" + tab_group_number ).removeClass( 'current' );
    $( this ).addClass( 'current' );
    $( "#" + tab_id ).addClass( 'current' );
  } )
} )

/** Trust Counter **/

$( document ).ready(function() {
    var trustNumTrue = $('.trusttrue').length;
    var trustNumFalse = $('.trustfalse').length;
    $( "#TrustCounter" ).text("Trust Obtained: " + trustNumTrue + " / " + (trustNumTrue + trustNumFalse) );
})

/** Blue Magic Counter **/

$( document ).ready(function() {
    var blueMagicNumTrue = $('.bluemagictrue').length;
    var blueMagicNumFalse = $('.bluemagicfalse').length;
    $( "#BlueMagicCounter" ).text("Blue Magic Obtained: " + blueMagicNumTrue + " / " + (blueMagicNumTrue + blueMagicNumFalse) );
})

/** Fish Caught Counter **/

$( document ).ready(function() {
    var fishNumTrue = $('.fishcaughttrue').length;
    var fishNumFalse = $('.fishcaughtfalse').length;
    $( "#FishCaughtCounter" ).text("Fish Caught: " + fishNumTrue + " / " + (fishNumTrue + fishNumFalse) );
})

/** Tooltips **/
 
(function() {
  var containerSelector = '#content, article'; 
  var inlineSelector = '.tooltip-source'; 
 
  var mouseOffset = {
    top: 10,
    bottom: 0,
    left: 10,
    right: 0
  };
  var tooltipCSS = {
    position: 'fixed',
    'z-index': 1000
  };
 
  function getTooltip(element) {
    var inlineElement = $(element).closest(inlineSelector);
    if (inlineElement.length > 0) {
      var tooltipID = inlineElement.attr('id') + '-tooltip';
      return $(document.getElementById(tooltipID)); 
    } else {
      return $();
    }
  }
 
  function showTooltip(element) {
    var tooltip = getTooltip(element);
    tooltip.find('img.lzyPlcHld:not(.lzyLoaded)').trigger('onload'); 
    tooltip.css(tooltipCSS);
    tooltip.show();
  }
 
  function hideTooltip(element) {
    var tooltip = getTooltip(element);
    tooltip.hide();
  }
 
  function positionTooltip(element, tooltip, mouseX, mouseY) {
    var contentArea = getContentArea();
 
    var tooltipHeight = tooltip.outerHeight();
    var tooltipWidth = tooltip.outerWidth();
 
    var positionY = mouseY + mouseOffset.top;
    var positionX = mouseX + mouseOffset.left;
 
    if ((positionY + tooltipHeight) > contentArea.bottom) {
      var spaceAbove = mouseY;
      var spaceBelow = (contentArea.bottom - mouseY);
      if (spaceAbove > spaceBelow) {
        positionY = mouseY - tooltipHeight - mouseOffset.bottom;
      }
    }
    if ((positionX + tooltipWidth) > contentArea.right) {
      var spaceLeft = mouseX;
      var spaceRight = (contentArea.right - mouseX);
      if (spaceLeft > spaceRight) {
        positionX = mouseX - tooltipWidth - mouseOffset.right;
      }
    }
 
    tooltip.css({
      left: positionX + 'px',
      top: positionY + 'px'
    });
  }
 
  function getContentArea() {
    var container = $(containerSelector);
    var containerPosition = container.offset();
    var containerMargins = {
      top: parseFloat(container.css('margin-top')),
      left: parseFloat(container.css('margin-left'))
    };
    return {
      top: containerPosition.top - containerMargins.top,
      left: containerPosition.left - containerMargins.left,
      bottom: Math.max(container.height(), $(window).height()),
      right: containerPosition.left + container.width()
    };
  }
 
  $(document).ready(function() {
    var inlineElements = $(inlineSelector);
    inlineElements.each(function() {
      $(this).mouseenter(function(event) {
        showTooltip(this);
      });
      $(this).mouseleave(function(event) {
        hideTooltip(this);
      });
      $(this).mousemove(function(event) {
        positionTooltip(this, getTooltip(this), event.clientX, event.clientY);
      });
    });
  });
})();


/** Tooltip for Imgpop used on pages like HTBF **/
/*
 * jQuery viewportOffset - v0.3 - 2/3/2010
 * http://benalman.com/projects/jquery-misc-plugins/
 * 
 * Copyright (c) 2010 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */
(function($){var a=$(window);$.fn.viewportOffset=function(){var b=$(this).offset();return{left:b.left-a.scrollLeft(),top:b.top-a.scrollTop()}}})(jQuery);

$( function() {

        var targets = $('.mbt-hover'),
            target  = false,
            tooltip = false,
            title   = false;
     
        targets.bind( 'mouseenter', function()
        {
            target  = $( this );
            tip     = target.children('.mbt-tooltip');
            tooltip = $( '<div id="tooltip"></div>' );
     
            if( !tip || tip == '' )
                return false;
            
            //target.remove('.mbt-tooltip');
            //target.removeAttr( 'title' );
            tooltip.css( 'opacity', 0 )
                   
                   .html( tip.clone().show() )

                   .appendTo( target );
     
            var init_tooltip = function()
            {
                if( $( window ).width() < tooltip.outerWidth() * 1.5 )
                    tooltip.css( 'max-width', $( window ).width() / 2 );
                else
                    tooltip.css( 'max-width', 420 );
     
                var pos_left = target.position().left + ( target.outerWidth() / 2 ) - ( tooltip.outerWidth() / 2 ),
                    pos_top  = target.position().top - tooltip.outerHeight() - 20;
                    pos_topvw  = target.viewportOffset().top - tooltip.outerHeight() - 20;
                    pos_leftvw  = target.offset().left + ( target.outerWidth() / 2 ) - ( tooltip.outerWidth() / 2 );
     
                if( pos_leftvw < 0 )
                {
                    pos_left = target.position().left - target.outerWidth() / 2 - 20;
                    tooltip.addClass( 'left' );
                }
                else
                    tooltip.removeClass( 'left' );
     
                if( pos_leftvw + tooltip.outerWidth() > $( window ).width() )
                {
                    pos_left = target.position().left - tooltip.outerWidth() + target.outerWidth() / 2 + 20;
                    tooltip.addClass( 'right' );
                }
                else
                    tooltip.removeClass( 'right' );
     
                if( pos_topvw < 0 )
                {
                    var pos_top  = target.position().top + target.outerHeight();
                    tooltip.addClass( 'top' );
                }
                else
                    tooltip.removeClass( 'top' );
     
                tooltip.css( { left: pos_left, top: pos_top } )
                       .animate( { top: '+=10', opacity: 1 }, 50 );
            };
     
            init_tooltip();
            $( window ).resize( init_tooltip );

     
           var remove_tooltip = function()
            {
                tooltip.animate( { top: '-=10', opacity: 0 }, 300, function()
                {
                    $( this ).remove();
                });

                target.children('.mbt-tooltip', tip);
    
            };

            target.bind( 'mouseleave', remove_tooltip );
            tooltip.bind( 'click', remove_tooltip );
        });
    });