MediaWiki:PagedGallery.js

From Zelda Dungeon Wiki
Jump to navigation Jump to search
Want an adless experience? Log in or Create an account.

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 (Command+R on a Mac)
  • Google Chrome: press Ctrl+Shift+R (Command+Shift+R on a Mac)
  • Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl+F5
  • Konqueror: click Reload or press F5
  • Opera: clear the cache in Tools → Preferences
/*
Script enabling paged galleries, where one page (may be one or more images, or arbitrary content) is displayed at a time and previous/next buttons navigate the pages
*/

$( function() {
$( 'body' ).on( 'click', '.zdw-button--paging', function( e ) {
  var $button = $( this );
  var $gallery = $button.closest( '.zdw-paged-gallery' );
  var $pages = $gallery.children( '.zdw-paged-gallery__page' );

  var navType = $button.data( 'nav' );
  var currentPageNum = $pages.index( '.active' );
  var pageNumToActivate =
    navType == 'next' ? Math.max( currentPageNum + 1, $pages.length - 1 ) :
    navType == 'prev' ? Math.min( currentPageNum - 1, 0 ) :
    navType == 'last' ? $pages.length - 1 :
    0; // 'first' or any unknown type

  if ( pageNumToActivate != currentPageNum ) {
    $pages.removeClass( 'active' );
    $pages.eq( pageNumToActivate ).addClass( 'active' );
  }
} );
} );