17,230
edits
mNo edit summary |
(I knew the logic was bad but not that bad. breaking it into two ifs for clarity) |
||
(6 intermediate revisions by the same user not shown) | |||
Line 91: | Line 91: | ||
for _, c in ipairs( self.contents ) do | for _, c in ipairs( self.contents ) do | ||
if self.tabsLeft and self.tabsLeft.defaultSelection == c.selection | if type( c.selection ) == 'string' | ||
and (self.tabsLeft and self.tabsLeft.defaultSelection == c.selection:gsub( "%s", "" ) | |||
or self.tabsTop and self.tabsTop.defaultSelection == c.selection:gsub( "%s", "" )) then | |||
and self.tabsLeft and self.tabsLeft.defaultSelection == c.selection.left | c.default = true | ||
and self.tabsTop and self.tabsTop.defaultSelection == c.selection.top then | elseif type( c.selection ) == 'table' | ||
and self.tabsLeft and self.tabsLeft.defaultSelection == c.selection.left:gsub( "%s", "" ) | |||
and self.tabsTop and self.tabsTop.defaultSelection == c.selection.top:gsub( "%s", "" ) then | |||
c.default = true | c.default = true | ||
end | end | ||
Line 176: | Line 178: | ||
local content = mw.html.create( 'div' ) | local content = mw.html.create( 'div' ) | ||
:addClass( 'zdw-tabcontent' ) | :addClass( 'zdw-tabcontent' ) | ||
:wikitext( '\n' .. self.content ) -- newline is needed for tables, lists, etc. | |||
if type( self.selection ) == 'table' then | if type( self.selection ) == 'table' then | ||
for k, v in pairs( self.selection ) do | for k, v in pairs( self.selection ) do | ||
content:attr( 'data-tab-content-' .. k, v ) | content:attr( 'data-tab-content-' .. k, v:gsub( "%s", "" ) ) | ||
end | end | ||
else | else | ||
content:attr( 'data-tab-content', self.selection ) | content:attr( 'data-tab-content', self.selection:gsub( "%s", "" ) ) | ||
end | end | ||
Line 260: | Line 245: | ||
end | end | ||
for contentSelection, contentArgs in pairs( args.content or {} ) do -- order doesn't matter here since only one is displayed at a time | -- Special case where content is transcluded from subpages rather than provided directly | ||
-- For now, assumes 2D mode (both left and top tabs) | |||
if Args.getValue( args.content or {} ) == 'transclude' then | |||
for _, leftArgs in ipairs( args.left ) do | |||
local leftSelection = Args.getValue( leftArgs ) | |||
for _, topArgs in ipairs( args.top ) do | |||
local topSelection = Args.getValue( topArgs ) | |||
local template = mw.title.getCurrentTitle().text .. '/' .. leftSelection .. '/' .. topSelection | |||
-- add edit link, aligned to transcluded table's header | |||
local editlink = mw.html.create( 'span' ) | |||
:addClass( 'edit plainlinks' ) | |||
:css( 'position', 'absolute' ) -- css to align with table header | |||
:css( 'top', '12px' ) | |||
:css( 'right', '15px' ) | |||
:wikitext( '[' .. tostring( mw.uri.fullUrl( template, { action = 'edit' } ) ) .. ' [edit]]' ) | |||
-- add the transcluded content | |||
tabs:addContent{ | |||
selection = { left = leftSelection, top = topSelection }, | |||
content = mw.getCurrentFrame():expandTemplate{ title = ':' .. template } .. tostring( editlink ) | |||
} | |||
end | |||
end | |||
else -- content is provided by the caller | |||
for contentSelection, contentArgs in pairs( args.content or {} ) do -- order doesn't matter here since only one is displayed at a time | |||
local leftSelection, topSelection = string.match( contentSelection, '(.+) (.+)' ) | |||
contentArgs = Args.getTable( contentArgs ) | |||
contentArgs.selection = leftSelection and { left = leftSelection, top = topSelection } or contentSelection | |||
contentArgs.content = Args.getValue( contentArgs ) | |||
tabs:addContent( contentArgs ) | |||
end | |||
end | end | ||