Difference between revisions of "Module:HonorChallPart"
From Pathfinder Wiki
DesignerThan (talk | contribs) |
DesignerThan (talk | contribs) |
||
Line 14: | Line 14: | ||
if ( #reqVariants['requirements'] > 1 ) then | if ( #reqVariants['requirements'] > 1 ) then | ||
-- create tab's | -- create tab's | ||
+ | local tabString = '' | ||
+ | local tabContentString = '' | ||
for key, variant in pairs(reqVariants['requirements']) do | for key, variant in pairs(reqVariants['requirements']) do | ||
tabText = '' | tabText = '' | ||
Line 28: | Line 30: | ||
end | end | ||
authAbbrev = variant['authorities'][1]['orig'] | authAbbrev = variant['authorities'][1]['orig'] | ||
− | + | tabString = tabString..createNavTab( authAbbrev, tabText, isActive) | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
local reqPageLink = landingPage..'/Requirements' | local reqPageLink = landingPage..'/Requirements' | ||
Line 43: | Line 39: | ||
mw.log('HonorChallPart.getChallengingPart (reqPageLink): '..reqPageLink) | mw.log('HonorChallPart.getChallengingPart (reqPageLink): '..reqPageLink) | ||
local content = frame:callParserFunction( '#lst', reqPageLink, 'challenge' ) | local content = frame:callParserFunction( '#lst', reqPageLink, 'challenge' ) | ||
− | local | + | tabContentString = tabContentString..createContentTab( authAbbrev, content, isActive ) |
− | + | end | |
− | + | ||
− | + | local HTMLTabContainer = mw.html.create( 'ul' ) | |
− | + | HTMLTabContainer | |
+ | :addClass( 'nav nav-tabs' ) | ||
+ | :attr( 'id', 'challengeTab' ) | ||
+ | :attr( 'role', 'tablist' ) | ||
+ | :wikitext( tabString ) | ||
− | retString = tostring( HTMLTabContainer )..tostring( HTMLTabsContent ) | + | local HTMLTabsContent = mw.html.create( 'div' ) |
− | + | HTMLTabsContent | |
+ | :addClass( 'tab-content' ) | ||
+ | :attr( 'challengeTabContent' ) | ||
+ | :wikitext( tabContentString ) | ||
+ | |||
+ | retString = tostring( HTMLTabContainer )..tostring( HTMLTabsContent ) | ||
else | else | ||
-- no or only 1 reqVariant's just use the default | -- no or only 1 reqVariant's just use the default |
Revision as of 21:24, 31 July 2021
Documentation for this module may be created at Module:HonorChallPart/doc
local p = {}
local honorUtils = require ( "Module:HonorUtils" )
local utilities = require ( "Module:Utilities" )
function p.getChallengingPart( frame )
local reqVariants = honorUtils.getVariantsData( frame, nil, 'requirements', nil )
local landingPage = frame:expandTemplate{ title='GetHonorLandingPage' }
landingPage = string.gsub(landingPage, "[\n\r]", '')
mw.log('HonorChallPart.getChallengingPart (landingPage): "'..landingPage..'"')
local langSuffix = frame:preprocess( '{{PAGELANGUAGE}}' )
local retString = nil
if ( reqVariants ~= nil and reqVariants['requirements'] ~= nil ) then
if ( #reqVariants['requirements'] > 1 ) then
-- create tab's
local tabString = ''
local tabContentString = ''
for key, variant in pairs(reqVariants['requirements']) do
tabText = ''
for authorityKey, authority in pairs(variant['authorities']) do
if ( #tabText > 0 ) then
tabText = tabText..' & '..authority['translated']
else
tabText = authority['translated']
end
end
local isActive = false
if ( key == 1 ) then
isActive = true
end
authAbbrev = variant['authorities'][1]['orig']
tabString = tabString..createNavTab( authAbbrev, tabText, isActive)
local reqPageLink = landingPage..'/Requirements'
if ( key > 1 ) then
reqPageLink = reqPageLink..' '..key
end
reqPageLink = reqPageLink..'/'..langSuffix
mw.log('HonorChallPart.getChallengingPart (reqPageLink): '..reqPageLink)
local content = frame:callParserFunction( '#lst', reqPageLink, 'challenge' )
tabContentString = tabContentString..createContentTab( authAbbrev, content, isActive )
end
local HTMLTabContainer = mw.html.create( 'ul' )
HTMLTabContainer
:addClass( 'nav nav-tabs' )
:attr( 'id', 'challengeTab' )
:attr( 'role', 'tablist' )
:wikitext( tabString )
local HTMLTabsContent = mw.html.create( 'div' )
HTMLTabsContent
:addClass( 'tab-content' )
:attr( 'challengeTabContent' )
:wikitext( tabContentString )
retString = tostring( HTMLTabContainer )..tostring( HTMLTabsContent )
else
-- no or only 1 reqVariant's just use the default
local reqPageLink = landingPage..'/Requirements/'..langSuffix
retString = frame:callParserFunction( '#lst', reqPageLink, 'challenge' )
end
end
return frame:preprocess(retString)
end
function createNavTab( authAbbrev, tabText, isActive)
-- create a single tab
local HTMLLink = mw.html.create( 'htmltag' )
-- if first add css class 'active'
HTMLLink
:attr( 'tagname', 'a')
:addClass( 'nav-link' )
:attr( 'id', authAbbrev..'-tab' )
:attr( 'data-toggle', 'tab' )
:attr( 'href', '#'..authAbbrev )
:attr( 'role', 'tab' )
:attr( 'aria-controls', authAbbrev )
:attr( 'aria-selected', tostring(isActive) )
:wikitext( tabText )
local HTMLLi = mw.html.create( 'li' )
HTMLLi
:addClass( 'nav-item' )
:attr( 'role', 'presentation' )
:wikitext( tostring( HTMLLink ) )
return tostring( HTMLLi )
end
function createContentTab( authAbbrev, content, isActive )
mw.log('HonorChallPart.createContentTab (authAbbrev, content, isActive): '..authAbbrev..', '..content..', '..tostring(isActive))
--create a content tab
local HTMLContentTab = mw.html.create( 'div' )
-- if first add css class 'active & show'
local isActiveCSSClass = ''
if ( isActive == true ) then
mw.log('HonorChallPart.createContentTab: Tab is active')
isActiveCSSClass = ' active show'
end
HTMLContentTab
:addClass( 'tab-pane fade'..isActiveCSSClass )
:attr( 'id', authAbbrev )
:attr( 'role', 'tabpanel' )
:attr( 'aria-labelledby', authAbbrev..'-tab' )
:wikitext( content )
return tostring( HTMLContentTab )
end
return p