Module:OOO/Variants: Difference between revisions

No edit summary
No edit summary
Line 1: Line 1:
-- Module:OOO/Variants
-- Module:OOO/Variants
-- Renders a right-aligned TabberNeue block of OOOInfoBox variants.
-- Renders a TabberNeue block of OOOInfoBox variants, wrapped so it aligns with the infobox.
-- Usage examples:
-- Usage:
--  {{OOOVariants|400162|400163|400113|400169|400170}}
--  {{OOOVariants|400162|400163|400113|400169|400170}}
--  {{OOOVariants | label1=2 m | art1=400162 | label2=3 m | art2=400163 | width=300 | align=left }}
--  {{OOOVariants | label1=2 m | art1=400162 | label2=3 m | art2=400163 | width=300 | align=left | mode=scroll }}
--
--
-- Optional params (global):
-- Global params:
--  |domain=Buildings   -- which data bucket to use; defaults to Buildings
--  |domain=Buildings       -- bucket to read from (default: Buildings)
--  |align=right       -- right (default), left, none, center
--  |align=right|left|none|center
--  |width=300         -- pixels; applies to wrapper and each infobox
--  |width=300             -- px; applies to wrapper + OOOInfoBox (240–600)
--  |mode=wrap|scroll      -- wrap (default) or horizontal scroll (adds class used by gadget)
--
--
-- Optional per-tab overrides (append tab index N):
-- Per-tab overrides (append N):
--  |labelN=..., |imageN=..., |descriptionN=..., |dimensionsN=..., |classN=...
--  |labelN=... |imageN=... |descriptionN=... |dimensionsN=... |classN=...


local DATA = require('Module:OOO/Data')
local DATA = require('Module:OOO/Data')
local p = {}
local p = {}


-- keys we allow forwarding to OOOInfoBox per tab (suffix with index)
local PASSTHROUGH = { 'image', 'description', 'dimensions', 'class' }
local PASSTHROUGH = { 'image', 'description', 'dimensions', 'class' }


Line 24: Line 25:
end
end


-- Sanitize label for tab header (avoid raw '|' or '=' breaking tabber syntax)
local function safe_label(s)
local function safe_label(s)
   s = tostring(s or '')
   s = tostring(s or '')
Line 31: Line 31:
end
end


-- Resolve a nice label: explicit labelN > data.displayName > art id
local function label_for(domain, art, given)
local function label_for(domain, art, given)
   if given and given ~= '' then return given end
   if given and given ~= '' then return given end
Line 44: Line 43:
   local domain = tostring_or_nil(args.domain or args.type) or 'Buildings'
   local domain = tostring_or_nil(args.domain or args.type) or 'Buildings'
   local align  = tostring_or_nil(args.align) or 'right'
   local align  = tostring_or_nil(args.align) or 'right'
   local width  = tonumber(args.width) -- optional shared width for wrapper + infoboxes
  local mode  = tostring_or_nil(args.mode)  or 'wrap'    -- 'wrap' (default) or 'scroll'
   local width  = tonumber(args.width)


   -- Build each tab
   -- Build each tab entry
   local entries = {}
   local entries = {}
   local i = 1
   local i = 1
Line 55: Line 55:
     local label = label_for(domain, art, args['label'..i] or args['name'..i])
     local label = label_for(domain, art, args['label'..i] or args['name'..i])


     -- Args passed to the underlying OOOInfoBox template
     -- Args forwarded to OOOInfoBox
     local ibx = {
     local ibx = {
       art = art,
       art   = art,
       type = domain,
       type = domain,
       align = align,
       align = align,
     }
     }
Line 79: Line 79:
   end
   end


  -- Build the TabberNeue tag (ensures the extension parses it, not raw text)
   local inner  = table.concat(entries, '|-|\n')
   local inner  = table.concat(entries, '|-|\n')
   local tabber = frame:extensionTag('tabber', inner)
   local tabber = frame:extensionTag('tabber', inner)


   -- Wrap so tabs float with the infobox; mirror align/width
   -- Wrapper around tabber so it floats with the infobox and gets our styles
   local wrap = mw.html.create('div'):addClass('ooo-infobox-tabwrap')
   local wrap = mw.html.create('div'):addClass('ooo-infobox-tabwrap')
   if align == 'left' then
   if align == 'left' then
Line 91: Line 90:
   elseif align == 'center' then
   elseif align == 'center' then
     wrap:addClass('ooo-infobox-tabwrap--center')
     wrap:addClass('ooo-infobox-tabwrap--center')
  end
  if mode == 'scroll' then
    -- enables horizontal-scroll mode + arrow gadget hook
    wrap:addClass('ooo-infobox-tabwrap--scroll')
   end
   end
   if width and width >= 240 and width <= 600 then
   if width and width >= 240 and width <= 600 then
     wrap:css('width', tostring(width) .. 'px')
     wrap:css('width', tostring(width) .. 'px')
   end
   end
   wrap:wikitext(tabber)
   wrap:wikitext(tabber)


Line 101: Line 105:
   html = html .. frame:extensionTag('templatestyles', '', { src = 'Template:OOOInfoBoxTabber/styles.css' })
   html = html .. frame:extensionTag('templatestyles', '', { src = 'Template:OOOInfoBoxTabber/styles.css' })


   -- Optional debug comment (viewable in page source)
   -- Optional debug comment
   if tostring(args.debug) == '1' then
   if tostring(args.debug) == '1' then
     html = html .. string.format('<!-- OOOVariants: domain=%s, align=%s, width=%s, tabs=%d -->',
     html = html .. string.format('<!-- OOOVariants: domain=%s, align=%s, mode=%s, width=%s, tabs=%d -->',
       domain, align, width or 'default', #entries)
       domain, align, mode, width or 'default', #entries)
   end
   end