Module:TextPageTabs: Difference between revisions
From Bodhicitta
((by SublimeText.Mediawiker)) |
((by SublimeText.Mediawiker)) |
||
| Line 5: | Line 5: | ||
local qPage = pArgs.page | local qPage = pArgs.page | ||
local subPage = pArgs.queryPagename | local subPage = pArgs.queryPagename | ||
local pagesForRels = pArgs.pagesForRelationships | |||
-- Build first tab content with intro and featured vid (loads immediately) | -- Build first tab content with intro and featured vid (loads immediately) | ||
Revision as of 16:41, 13 October 2025
Documentation for this module may be created at Module:TextPageTabs/doc
local p = {}
function p.main(frame)
local pArgs = frame:getParent().args
local qPage = pArgs.page
local subPage = pArgs.queryPagename
local pagesForRels = pArgs.pagesForRelationships
-- Build first tab content with intro and featured vid (loads immediately)
local firstTab = 'Introduction = <div class="row mx-0">'
if pArgs.FeaturedYoutubeID and pArgs.FeaturedYoutubeID ~= '' then
firstTab = firstTab .. '<div class="col-md-8 pl-md-0">' .. pArgs.introduction .. '</div>'
local featureVid = '<div class="col-md-4 pr-md-0">' .. frame:expandTemplate{
title = 'YouTube',
args = {
id = pArgs.FeaturedYoutubeID,
caption = pArgs.FeaturedVidCaption
}
} .. '</div>'
firstTab = firstTab .. featureVid
else
firstTab = firstTab .. '<div class="col-12">' .. pArgs.introduction .. '</div>'
end
firstTab = firstTab .. '</div>'
-- Build tab content, starting with first tab
local tabContent = { firstTab }
-- Create placeholder tabs with loading indicators
-- Each tab gets a unique ID and data attributes for AJAX loading
local tabs = {
{name = 'Recensions', id = 'recensions'},
{name = 'Translations', id = 'translations'},
{name = 'Commentaries', id = 'commentaries'},
{name = 'Teachings', id = 'teachings'},
{name = 'Media', id = 'media'},
{name = 'Related scholarship', id = 'scholarship'}
}
for _, tab in ipairs(tabs) do
-- Tab name goes before the = sign, content after
local tabHtml = tab.name .. ' = ' ..
'<div class="ajax-tab-content" ' ..
'data-tab-type="' .. tab.id .. '" ' ..
'data-tab-name="' .. tab.name .. '" ' ..
'data-page="' .. mw.text.encode(qPage) .. '" ' ..
'data-subpage="' .. mw.text.encode(subPage) .. '" ' ..
'data-loaded="false">' ..
'<div class="text-center p-4">' ..
'<div class="spinner-border text-primary" role="status">' ..
'<span class="sr-only">Loading...</span>' ..
'</div>' ..
'<div class="mt-2">Loading ' .. tab.name:lower() .. '...</div>' ..
'</div></div>'
table.insert(tabContent, tabHtml)
end
-- Check for extra tabs added manually
local extraTabs = ''
if pArgs.ExtraTabs then
extraTabs = frame:preprocess(pArgs.ExtraTabs)
end
-- Add a marker div to trigger the lazy loading script
local lazyLoadMarker = '<div class="text-tabs-lazy-load-marker" style="display:none"></div>'
-- Return tabber with marker
if #tabContent > 0 or extraTabs then
return frame:preprocess('{{#tag:tabber|' .. table.concat(tabContent, '{{!}}-{{!}}') .. '}}') ..
extraTabs .. lazyLoadMarker
else
return 'No related content found.'
end
end
return p