17,230
edits
(transclude from main namespace) |
(better idea for transclude) |
||
Line 176: | Line 176: | ||
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 | ||
Line 260: | Line 243: | ||
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 = tostring( editlink ) .. mw.getCurrentFrame():expandTemplate{ title = ':' .. template } | |||
} | |||
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 | ||