Module:Large category TOC/sandbox
Appearance
![]() | This is the module sandbox page for Module:Large category TOC (diff). |
![]() | 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 Lua module is used on approximately 11,000 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. |
Usage
This module implements Template:Large category TOC and similar templates. It is used on categories with many members to provide a means of indexing them by first letter and first two letters
For full lists (Template:Large category TOC):
{{#invoke:Large category TOC|aejot}}
For collapsible lists (Template:Collapsible large category TOC):
{{#invoke:Large category TOC|collapsible}}
local p = {}
local azupper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
local azlower = 'abcdefghijklmnopqrstuvwxyz'
local aejot = 'aejot'
-- Implements [[Template:Large Category TOC]]
function p.scrollable(frame)
end
function p.make(collapsible,fullaz)
-- It should be much faster to only process these once, and just re use them as variables
local pageurl = frame:preprocess('{{fullurl:{{FULLPAGENAME}}}}')
local toc_string
if collapsible then
toc_string = '<div class="collapsible" style="background:transparent;">\n'
else
toc_string = ''
end
toc_string = toc_string..'<div class="NavFrame" style="clear:both; background:WhiteSmoke;">\n'..
'<div class="NavHead" style="background:WhiteSmoke;">\n'..
'<div class="plainlinks" id="kat_toc" style="background:WhiteSmoke; text-align:center; font-size:100%;">\n'..
'<b>Index:</b> ['..pageurl..' *] ['..pageurl..'?from=# 0-9]'
-- Add ?from=A through Z to the title bar
for i=1,26,1 do
local letter = string.sub(azupper,i,i)
toc_string = toc_string..' ['..pageurl..'?from='..letter..' '..letter..']'
end
-- Closing tags
if collapsible then
toc_string = toc_string..'<span style="font-size: 85%;">(Click <i>Show</i> for more navigation options.)</span>'
end
toc_string = toc_string..'\n</div>\n</div>'
if collapsible then
toc_string = toc_string..'<div class="NavContent" style="background:White; display:none;">'..
'<div class="plainlinks" style="background:White; font-size:100%; text-align:center;">'..
'\n----'..
'\n<code style="background:White;"> <b>#</b>'
end
-- Add ?from=0 through 9 to the list
for i=0,9,1 do
toc_string = toc_string..'\n['..pageurl..'?from='..i..' '..i..']'
end
-- Function to handle all 500+ ?from=Aa-z parameters with a simple loop
local function atoz(letter)
local itlen
local azstring
if fullaz then
azstring = azlower
itlen = 26
else
azstring = aejot
itlen = 5
end
local azlist
if collapsible then
azlist = '<br>\n<b>'..letter..'</b> '
else
azlist = '\n• <b>'..letter..'</b> '
end
for i=1,itlen,1 do
local lowerletter = string.sub(azstring,i,i)
azlist = azlist..' ['..pageurl..'?from='..letter..lowerletter..' '..letter..lowerletter..'] '
end
return azlist
end
-- A-Z loop that calls the a-z function
for i=1,26,1 do
local letter = string.sub(azupper,i,i)
toc_string = toc_string..atoz(letter)
end
-- Close tags
if collapsible then
toc_string = toc_string..'\n</code>\n</div></div></div>'
else
toc_string = toc_string..'\n</span></div></div>'
end
return toc_string
end
return p