MediaWiki:PagedGallery.js

From Zelda Dungeon Wiki
Revision as of 18:44, March 27, 2021 by Locke (talk | contribs) (fix all the bugs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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 $currentPage = $pages.filter( '.active' );
  var $pageToActivate =
    navType == 'next' ? $currentPage.next( '.zdw-paged-gallery__page' ) :
    navType == 'prev' ? $currentPage.prev( '.zdw-paged-gallery__page' ) :
    navType == 'last' ? $pages.last() :
    $pages.first(); // 'first' or any unknown type

  if ( $pageToActivate.length && $pageToActivate[0] != $currentPage[0] ) {
    $currentPage.removeClass( 'active' );
    $pageToActivate.addClass( 'active' );
  }
} );
} );