Difference between revisions of "Module:HonorChallPart"
From Pathfinder Wiki
DesignerThan (talk | contribs) (Created page with "local p = {} local honorUtils = require ( "Module:HonorUtils" ) local utilities = require ( "Module:Utilities" ) function p.getChallangingPart( frame ) local reqVariants = h...") |
DesignerThan (talk | contribs) |
||
| Line 3: | Line 3: | ||
local utilities = require ( "Module:Utilities" ) | local utilities = require ( "Module:Utilities" ) | ||
| − | function p. | + | function p.getChallengingPart( frame ) |
local reqVariants = honorUtils.getVariantsData( frame, nil, 'requirements', nil ) | local reqVariants = honorUtils.getVariantsData( frame, nil, 'requirements', nil ) | ||
| − | local | + | local landingPage = frame:expandTemplate{ title='GetHonorLandingPage' } |
| − | local | + | local langSuffix = frame:preprocess( '{{PAGELANGUAGE}}' ) |
| + | local retString = nil | ||
| + | if ( reqVariants ~= nil and reqVariants['requirements'] ~= nil ) then | ||
| + | if ( #reqVariants['requirements'] > 1 ) then | ||
| + | -- create tab's | ||
| + | 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'] | ||
| + | |||
| + | local HTMLTabContainer = mw.html.create( 'ul' ) | ||
| + | HTMLTabContainer | ||
| + | :addClass( 'nav nav-tabs' ) | ||
| + | :attr( 'id', 'challengeTab' ) | ||
| + | :attr( 'role', 'tablist' ) | ||
| + | :wikitext( createNavTab( authAbbrev, tabText, isActive) ) | ||
| + | |||
| + | local reqPageLink = landingPage..'/Requirements' | ||
| + | if ( key > 1 ) then | ||
| + | reqPageLink = reqPageLink..' '..key | ||
| + | end | ||
| + | reqPageLink = reqPageLink..'/'..langSuffix | ||
| + | |||
| + | local content = frame:callParserFunction( '#lst', reqPageLink, 'challenge' ) | ||
| + | local HTMLTabsContent = mw.html.create( 'div' ) | ||
| + | HTMLTabsContent | ||
| + | :addClass( 'tab-content' ) | ||
| + | :attr( 'challengeTabContent' ) | ||
| + | :wikitext( createContentTab( authAbbrev, content, isActive )) | ||
| + | |||
| + | retString = tostring( HTMLTabContainer )..tostring( HTMLTabsContent ) | ||
| + | end | ||
| + | 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 retString | ||
| + | end | ||
| + | |||
| + | function createNavTab( authAbbrev, tabText, isActive) | ||
-- create a single tab | -- create a single tab | ||
| − | local | + | local HTMLLink = mw.html.create( 'a' ) |
-- if first add css class 'active' | -- if first add css class 'active' | ||
| − | + | HTMLLink | |
:addClass( 'nav-link' ) | :addClass( 'nav-link' ) | ||
:attr( 'id', authAbbrev..'-tab' ) | :attr( 'id', authAbbrev..'-tab' ) | ||
| Line 18: | Line 69: | ||
:attr( 'role', 'tab' ) | :attr( 'role', 'tab' ) | ||
:attr( 'aria-controls', authAbbrev ) | :attr( 'aria-controls', authAbbrev ) | ||
| − | :attr( 'aria-selected', | + | :attr( 'aria-selected', tostring(isActive) ) |
| − | :wikitext( | + | :wikitext( tabText ) |
| − | local | + | |
| − | + | local HTMLLi = mw.html.create( 'li' ) | |
| + | HTMLLi | ||
:addClass( 'nav-item' ) | :addClass( 'nav-item' ) | ||
:attr( 'role', 'presentation' ) | :attr( 'role', 'presentation' ) | ||
| − | :wikitext( tostring( | + | :wikitext( tostring( HTMLLink ) ) |
| − | + | ||
| + | return tostring( HTMLLi ) | ||
| + | end | ||
| + | |||
| + | function createContentTab( authAbbrev, content, isActive ) | ||
--create a content tab | --create a content tab | ||
| − | HTMLContentTab = mw.html.create( 'div' ) | + | local HTMLContentTab = mw.html.create( 'div' ) |
-- if first add css class 'active & show' | -- if first add css class 'active & show' | ||
| + | local isActiveCSSClass = '' | ||
| + | if ( isActive == true ) then | ||
| + | isActiveCSSClass = ' active show' | ||
| + | end | ||
| + | |||
HTMLContentTab | HTMLContentTab | ||
| − | :addClass( 'tab-pane fade' ) | + | :addClass( 'tab-pane fade'..isActiveCSSClass ) |
:attr( 'id', authAbbrev ) | :attr( 'id', authAbbrev ) | ||
:attr( 'role', 'tabpanel' ) | :attr( 'role', 'tabpanel' ) | ||
:attr( 'aria-labelledby', authAbbrev..'-tab' ) | :attr( 'aria-labelledby', authAbbrev..'-tab' ) | ||
| − | :wikitext( | + | :wikitext( content ) |
| − | + | return tostring( HTMLContentTab ) | |
| − | |||
end | end | ||
return p | return p | ||
Revision as of 22:23, 30 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' }
local langSuffix = frame:preprocess( '{{PAGELANGUAGE}}' )
local retString = nil
if ( reqVariants ~= nil and reqVariants['requirements'] ~= nil ) then
if ( #reqVariants['requirements'] > 1 ) then
-- create tab's
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']
local HTMLTabContainer = mw.html.create( 'ul' )
HTMLTabContainer
:addClass( 'nav nav-tabs' )
:attr( 'id', 'challengeTab' )
:attr( 'role', 'tablist' )
:wikitext( createNavTab( authAbbrev, tabText, isActive) )
local reqPageLink = landingPage..'/Requirements'
if ( key > 1 ) then
reqPageLink = reqPageLink..' '..key
end
reqPageLink = reqPageLink..'/'..langSuffix
local content = frame:callParserFunction( '#lst', reqPageLink, 'challenge' )
local HTMLTabsContent = mw.html.create( 'div' )
HTMLTabsContent
:addClass( 'tab-content' )
:attr( 'challengeTabContent' )
:wikitext( createContentTab( authAbbrev, content, isActive ))
retString = tostring( HTMLTabContainer )..tostring( HTMLTabsContent )
end
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 retString
end
function createNavTab( authAbbrev, tabText, isActive)
-- create a single tab
local HTMLLink = mw.html.create( 'a' )
-- if first add css class 'active'
HTMLLink
: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 )
--create a content tab
local HTMLContentTab = mw.html.create( 'div' )
-- if first add css class 'active & show'
local isActiveCSSClass = ''
if ( isActive == true ) then
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
