Module:Page tabs: Difference between revisions
Appearance
Content deleted Content added
MusikBot II (talk | contribs) m Changed protection settings for "Module:Page tabs": High-risk template or module: 2666 transclusions (more info) ([Edit=Require extended confirmed access] (indefinite) [Move=Require extended confirmed access] (indefinite)) |
make "class1", "class2", etc. add styling to each individual tab, as well as "style1", "style2", etc. and "class" and "style" control overall styling of the tabs |
||
Line 17: | Line 17: | ||
local row = root:tag('div') |
local row = root:tag('div') |
||
:css('background', args.Background or '#f8fcff') |
:css('background', args.Background or '#f8fcff') |
||
:cssText(args.style or nil) |
|||
:addClass('template-page-tabs') |
:addClass('template-page-tabs') |
||
:addClass(args.class or nil) |
|||
if not args[1] then |
if not args[1] then |
||
args[1] = '{{{1}}}' |
args[1] = '{{{1}}}' |
||
end |
end |
||
for i, link in ipairs(args) do |
for i, link in ipairs(args) do |
||
makeTab(row, link, args, i) |
makeTab(row, link, args, i, args["class" .. i] or nil, args["style" .. i] or nil) |
||
end |
end |
||
Line 28: | Line 30: | ||
end |
end |
||
function p.makeTab(root, link, args, i) |
function p.makeTab(root, link, args, i, class, css) |
||
local thisPage = (args.This == 'auto' and link:find('[[' .. mw.title.getCurrentTitle().prefixedText .. '|', 1, true)) or tonumber(args.This) == i |
local thisPage = (args.This == 'auto' and link:find('[[' .. mw.title.getCurrentTitle().prefixedText .. '|', 1, true)) or tonumber(args.This) == i |
||
root:tag('span') |
root:tag('span') |
||
:addClass(class) |
|||
:css('background-color', thisPage and (args['tab-bg'] or 'white') or (args['tab1-bg'] or '#cee0f2')) |
:css('background-color', thisPage and (args['tab-bg'] or 'white') or (args['tab1-bg'] or '#cee0f2')) |
||
:cssText(thisPage and 'border-bottom:0;font-weight:bold' or 'font-size:95%') |
:cssText(thisPage and 'border-bottom:0;font-weight:bold' or 'font-size:95%') |
||
:cssText(css) |
|||
:wikitext(link) |
:wikitext(link) |
||
:done() |
:done() |
||
:wikitext('<span class="spacer"> </span>') |
:wikitext('<span class="spacer ' .. (class or "") .. '"> </span>') |
||
end |
end |
||
Revision as of 03:31, 12 April 2024
![]() | This Lua module is used on approximately 3,800 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
![]() | This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
![]() | This module depends on the following other modules: |
This module implements {{page tabs}}. Please see the template page for documentation.
-- This module implements {{Page tabs}}.
local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')
local p = {}
function p.main(frame)
local args = getArgs(frame)
return p._main(args)
end
function p._main(args)
local makeTab = p.makeTab
local root = mw.html.create()
root:wikitext(yesno(args.NOTOC) and '__NOTOC__' or nil)
local row = root:tag('div')
:css('background', args.Background or '#f8fcff')
:cssText(args.style or nil)
:addClass('template-page-tabs')
:addClass(args.class or nil)
if not args[1] then
args[1] = '{{{1}}}'
end
for i, link in ipairs(args) do
makeTab(row, link, args, i, args["class" .. i] or nil, args["style" .. i] or nil)
end
return tostring(root)
end
function p.makeTab(root, link, args, i, class, css)
local thisPage = (args.This == 'auto' and link:find('[[' .. mw.title.getCurrentTitle().prefixedText .. '|', 1, true)) or tonumber(args.This) == i
root:tag('span')
:addClass(class)
:css('background-color', thisPage and (args['tab-bg'] or 'white') or (args['tab1-bg'] or '#cee0f2'))
:cssText(thisPage and 'border-bottom:0;font-weight:bold' or 'font-size:95%')
:cssText(css)
:wikitext(link)
:done()
:wikitext('<span class="spacer ' .. (class or "") .. '"> </span>')
end
return p