Module:Listbox: Difference between revisions

Jump to navigation Jump to search
Want an adless experience? Log in or Create an account.
implement gallery mode (has a few bugs I think)
(saving WIP for gallery layout. realized this will be much easier if I first convert Tab (and maybe Gallery too))
(implement gallery mode (has a few bugs I think))
Line 1: Line 1:
local Box = require( 'Module:Box' ).Box
local Box = require( 'Module:Box' ).Box
local Lazy = require( 'Module:Lazy' ) -- may load: Tabs, Gallery


function getCategoryProps( categoryName )
function getCategoryProps( categoryName )
Line 52: Line 53:
end
end


function buildGallery( categoryProps, pageTree )
function buildGallery( pages )
   local tabGroupId = 'TODO' -- mw.getCurrentFrame():expandTemplate{ title = 'Zelda', args = { game } } .. category -- or strip whitespace from self.subject
   local Gallery = Lazy.load( 'Module:Gallery' ).Gallery
  local gallery = Gallery.new() -- TODO define appropriate args. CD/Header has: {{Gallery|size={{#ifeq:{{{size|}}}|large|95|62}}|pad=1|square={{{square|true}}}}}
  for _, page in ipairs( pages ) do
    defaultGallery:addFile( 'No Image.png', '[[' .. page.text .. '|' .. page.extra.name or page.text .. ']]', {
      link = page.text,
      alt = page.extra.name or page.text
    } )
  end
 
  return gallery:render()
end
 
 
function buildGalleries( categoryProps, pageTree )
  local Gallery = Lazy.load( 'Module:Gallery' ).Gallery
 
  local defaultGallery = nil
  if pageTree.default then
    defaultGallery = buildGallery( pageTree.default )
  end
 
  if categoryProps.groups then
    local Tabs = Lazy.load( 'Module:Tabs' ).Tabs
    local tabs = Tabs.new()


  -- from TabSettings: {{#vardefine:TabsID|{{{1|}}}}}{{#vardefine:TabsDefault|{{#if:{{{2|}}}|{{{2|}}}|1}}}} 
    if defaultGallery then
  -- from CD/Decorator: {{#vardefine:cd-dec|gallery}}{{#vardefine:cd-tabindex|0}}{{TabSettings|{{{2|{{PAGENAME}}}}}}}<div class{{=}}"tab"><ul></ul></div><div class{{=}}"tabcontent">


  local content = mw.html.create( 'div' )
      tabs:addTabTopWithContent{
  content:tag( 'div' )
        contentId = 'General',
    :addClass( 'tab' )
        content = defaultGallery
     :tag( 'ul' )
      }
  local tabcontent = content:tag( 'div' )
     end
    :addClass( 'tabcontent' )


  -- from CD/Header:
    -- coerce it to a table for easier processing
--{{#if: {{{1|}}}
    local groups = type( categoryProps.groups ) == 'table' and categoryProps.groups or { categoryProps.groups }
--  | {{Tab|{{#vardefineecho:cd-tabindex|{{#expr:{{#var:cd-tabindex}}+1}}}}|{{{1|}}}}}
    for index, group in ipairs( groups ) do
--<div class{{=}}"_toggle {{#var:TabsID}}tab{{#var:cd-tabindex}} {{#var:TabsID}}tabs" {{#ifeq:{{#var:TabsDefault}}|{{#var:cd-tabindex}}|style{{=}}"display: none;"|}}></div><div class{{=}}"_toggle {{#var:TabsID}}tab{{#var:cd-tabindex}} {{#var:TabsID}}tabs" {{#ifeq:{{#var:TabsDefault}}|{{#var:cd-tabindex}}||style{{=}}"display: none;"}}>
      if pageTree[group] then
--  | <div>
        tabs:addTabTopWithContent{
--  }}{{Gallery|size={{#ifeq:{{{size|}}}|large|95|62}}|pad=1|square={{{square|true}}}}}
          contentId = group,
          content = buildGallery( pageTree[group] )
        }
      end
    end


  -- from CD:
    return tabs:render()
--{{#if:{{{caption1|}}}
  end
--  | {{#forargs:caption|key|val
--    | {{#ifexpr:{{#var:key}}>1|{{N}}}}{{Gallery/Box
--      | file = {{{file{{#var:key}}|{{{file|}}}}}}
--      | link = {{{link{{#var:key}}|{{{link|}}}}}}
--      | tip = {{{tip{{#var:key}}|{{{tip|{{#var:val}}}}}}}}
--      | caption = [[{{{link{{#var:key}}|{{{link|}}}}}}|{{#var:val}}]]}}
--    }}
--  | {{Gallery/Box|file={{{file|}}}|link={{{link|}}}|tip={{{tip|{{{caption|{{{link|}}}}}}}}}|caption=[[{{{link|}}}|{{{caption|{{{link|}}}}}}]]}}
--  }}


  -- from CD/End: {{Gallery/Bottom}}</div>
   return defaultGallery
   return content
end
end


Line 93: Line 109:
   for _, page in ipairs( pages ) do
   for _, page in ipairs( pages ) do
     list:tag( 'li' )
     list:tag( 'li' )
       :wikitext( '[[' .. page.text .. '|' .. (page.extra.name or page.sortkey or page.text) .. ']]' )
       :wikitext( '[[' .. page.text .. '|' .. (page.extra.name or page.text) .. ']]' )
   end
   end
end
end
Line 109: Line 125:
   if categoryProps.groups then
   if categoryProps.groups then
     -- coerce it to a table for easier processing
     -- coerce it to a table for easier processing
     local groups = type(categoryProps.groups) == 'table' and categoryProps.groups or { categoryProps.groups }
     local groups = type( categoryProps.groups ) == 'table' and categoryProps.groups or { categoryProps.groups }
     for index, group in ipairs(groups) do
     for index, group in ipairs( groups ) do
       if( pageTree[group] ) then
       if pageTree[group] then
         local row = content:tag( 'tr' )
         local row = content:tag( 'tr' )
         row:tag( 'th' )
         row:tag( 'th' )

Navigation menu