Difference between revisions of "Module:HonorTabs"
From Pathfinder Wiki
DesignerThan (talk | contribs) |
DesignerThan (talk | contribs) |
||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
− | |||
local honorVariants = require ( "Module:HonorVariants" ) | local honorVariants = require ( "Module:HonorVariants" ) | ||
+ | |||
+ | function p.generateHonorTabs( frame ) | ||
+ | local parentFrame = frame:getParent() | ||
+ | return parentFrame.args[1] | ||
+ | end | ||
function p.createAnswerTab( frame ) | function p.createAnswerTab( frame ) | ||
Line 12: | Line 16: | ||
end | end | ||
− | function outputVariantsTab(frame, variants) | + | function outputVariantsTab( frame, variants ) |
local HTMLCode = "" | local HTMLCode = "" | ||
local HTMLCodeString = "" | local HTMLCodeString = "" | ||
Line 28: | Line 32: | ||
local buttonArgs = {} | local buttonArgs = {} | ||
buttonArgs['tagname'] = 'button' | buttonArgs['tagname'] = 'button' | ||
− | local explodedPageName = | + | local explodedPageName = mw.text.split( frame:expandTemplate{title='PAGENAMEwithoutLang'}, '/', true) |
buttonArgs['class'] = 'dropdown-toggle' .. ' ' .. explodedPageName[#explodedPageName] | buttonArgs['class'] = 'dropdown-toggle' .. ' ' .. explodedPageName[#explodedPageName] | ||
if (explodedPageName[#explodedPageName] == 'Answer Key') then | if (explodedPageName[#explodedPageName] == 'Answer Key') then | ||
Line 43: | Line 47: | ||
:addClass( 'honor-nav-item' ) | :addClass( 'honor-nav-item' ) | ||
:addClass( 'dropdown' ) | :addClass( 'dropdown' ) | ||
− | |||
:wikitext( dropdownButton ) | :wikitext( dropdownButton ) | ||
Revision as of 20:52, 6 July 2021
Documentation for this module may be created at Module:HonorTabs/doc
local p = {}
local honorVariants = require ( "Module:HonorVariants" )
function p.generateHonorTabs( frame )
local parentFrame = frame:getParent()
return parentFrame.args[1]
end
function p.createAnswerTab( frame )
local ansVariants = ""
if frame.args.answerVariants then ansVariants = frame.args.answerVariants end
local landingPage = frame.args.landingPage
local t_answerVariants = honorVariants.getExpandedHonorVariants(frame, ansVariants, landingPage, "Answer Key")
result_string = outputVariantsTab(frame, t_answerVariants)
return result_string
end
function outputVariantsTab( frame, variants )
local HTMLCode = ""
local HTMLCodeString = ""
if (variants == nil) then
-- should not happen!
HTMLCodeString = "no variants?! = nil"
elseif (#variants < 1) then
-- should not happen!
HTMLCodeString = "no variants?! < 1"
elseif (#variants == 1) then
HTMLCodeString = createSimpleTab( variants[1].url )
else
-- now there should be more then 1 variants
local HTMLTabParent = mw.html.create( 'li' )
local buttonArgs = {}
buttonArgs['tagname'] = 'button'
local explodedPageName = mw.text.split( frame:expandTemplate{title='PAGENAMEwithoutLang'}, '/', true)
buttonArgs['class'] = 'dropdown-toggle' .. ' ' .. explodedPageName[#explodedPageName]
if (explodedPageName[#explodedPageName] == 'Answer Key') then
buttonArgs['class'] = buttonArgs['class'] .. ' selflink'
end
buttonArgs['type'] = 'button'
buttonArgs['id'] = 'dropdownAnswerKeys'
buttonArgs['data-toggle'] = 'dropdown'
buttonArgs['aria-haspopup'] = 'true'
buttonArgs['aria-expanded'] = 'false'
buttonText = frame:expandTemplate{title = 'Localize', args = {'Answer Key'} }
local dropdownButton = frame:extensionTag('htmltag', buttonText, buttonArgs)
HTMLTabParent
:addClass( 'honor-nav-item' )
:addClass( 'dropdown' )
:wikitext( dropdownButton )
HTMLVariantsContainer = mw.html.create( 'div' )
HTMLVariantsContainer
:addClass( 'dropdown-menu' )
:attr( 'aria-labelledby', 'dropdownAnswerKeys')
for key, variant in pairs(variants) do
HTMLVariantLink = mw.html.create( 'span' )
HTMLVariantLink
:addClass( 'dropdown-item' )
:wikitext( variant.url )
:done()
HTMLVariantsContainer:node( HTMLVariantLink )
end
HTMLVariantsContainer:done()
HTMLTabParent:node( HTMLVariantsContainer )
HTMLCodeString = tostring( HTMLTabParent )
end
return HTMLCodeString
end
function createSimpleTab( wikiLink )
local HTMLCode = mw.html.create( 'li' )
HTMLCode
:addClass( 'honor-nav-item' )
:wikitext( wikiLink )
return tostring( HTMLCode )
end
return p