Module:PagedGallery: Difference between revisions

Jump to navigation Jump to search
Want an adless experience? Log in or Create an account.
add page content
(start implementation with buttons only)
 
(add page content)
Line 1: Line 1:
local Args = require( 'Module:Args' )
local Args = require( 'Module:Args' )
local Box = require( 'Module:Box' ).Box
local Box = require( 'Module:Box' ).Box
local PAGE_NUMBER_FORMAT = "\{(#+)}"


local PagedGallery = Box.new()
local PagedGallery = Box.new()
Line 8: Line 10:
function PagedGallery.new( args )
function PagedGallery.new( args )
   args.class = 'zdw-paged-gallery'
   args.class = 'zdw-paged-gallery'
  local width = args.width or 300
  args.width = width * 2 .. 'px'
   local obj = Box.new( 'light', args )
   local obj = Box.new( 'light', args )
  obj.imageWidth = width .. 'px'
  obj.pageNumReplacementFormat = "%0" .. #string.match( args.format, PAGE_NUMBER_FORMAT ) .. "d"
   return setmetatable( obj, PagedGallery )
   return setmetatable( obj, PagedGallery )
end
end
Line 29: Line 35:
   addButton( nav, 'last', 'Last >>' )
   addButton( nav, 'last', 'Last >>' )


-- TODO pages
  -- cover
  content:tag( 'div' )
    :addClass( 'zdw-paged-gallery__page active' )
    :wikitext( self:renderImage( 0 ) )
 
  -- pages
  for i = 1, self.args.numPages - 1, 2 do
    content:tag( 'div' )
      :addClass( 'zdw-paged-gallery__page' )
      :wikitext( self:renderImage( i ) .. self:renderImage( i + 1 ) )
  end
 
  -- back
  if self.args.numPages % 2 == 1 then
    content:tag( 'div' )
      :addClass( 'zdw-paged-gallery__page' )
      :wikitext( self:renderImage( self.args.numPages ) )
  end


   return content
   return content
end
function PagedGallery:renderImage( pageNum )
  return '[[File:' .. self.args.format:gsub( PAGE_NUMBER_FORMAT, string.format( self.pageNumReplacementFormat, pageNum ) ) .. '|' .. self.imageWidth .. ']]'
end
end


Line 47: Line 74:
   getParent = function() return {
   getParent = function() return {
     args = {
     args = {
      format = 'The-Legend-of-Zelda-North-American-Instruction-Manual-Page-{##}.jpg',
      numPages = 47
     }
     }
   } end
   } end

Navigation menu