Module:Large category TOC/sandbox: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Line 7:
-- Implements [[Template:Large Category TOC]]
function p.scrollable(frame)
-- It should be much faster to only process these once, and just re use them as variables
return make(false,true,true,frame)
local pageurl = mw.title.getCurrentTitle():fullUrl()
end
local toc = mw.message.new('Toc'):plain()
-- Begins the "title" parameter of {{Navigation bar}} with Top of the category (no ?from) and numerals (?from=0)
local title = '<div style="width:100%;">\n<span class="plainlinks">'..toc..':\n['..pageurl..' Top]'..
'\n['..pageurl..'?from=0 0-9]'
-- Add ?from=A through Z to the title bar
for i=1,26,1 do
local letter = string.sub(azupper,i,i)
title = title..'\n['..pageurl..'?from='..letter..' '..letter..']'
end
-- Closing tags
title = title..'\n</span>\n</div>'
-- Begin the list parameter with ?from=*
local list = '<div style="overflow-x:auto; overflow-y:hidden; width:98%;"><span class="plainlinks">'..
'\n['..pageurl..'?from=* *] •'
 
-- Add ?from=0 through 9 to the list
function p.collapsible(frame)
for i=0,9,1 do
return make(true,false,true,frame)
list = list..'\n['..pageurl..'?from='..i..' '..i..']'
end
end
 
-- A-Z loop that calls the a-z function
function p.aejot(frame)
for i=1,26,1 do
return make(false,false,false,frame)
local letter = string.sub(azupper,i,i)
list = list..atoz(letter,true,true)
end
-- Close tags
list = list..'\n</span></div>'
return frame:expandTemplate{title='Navigation bar',args={color='#f9f9f9;',title=title,list=list}}
end
 
-- Implements [[Template:Collapsible large category TOC]]
function make(collapsible,scrollable,fullaz,frame)
function p.collapsible(frame)
-- It should be much faster to only process these once, and just re use them as variables
local pageurl = frame:preprocessmw.title.getCurrentTitle('{{fullurl):{{FULLPAGENAME}}}}'fullUrl()
local toc_string = '<div class="collapsible" style="background:transparent;">\n'..
'<div class="NavFrame" style="clear:both; background:WhiteSmoke;">\n'..
if collapsible then
toc_string = '<div class="collapsible plainlinksNavHead" style="background:transparentWhiteSmoke;">\n'..
'<div class="NavFrameplainlinks" id="kat_toc" style="clearbackground:bothWhiteSmoke; backgroundtext-align:WhiteSmokecenter; font-size:100%;">\n'..
'<div class="NavHead" style="background:WhiteSmoke;">\n'..
'<divid="kat_toc" style="background:WhiteSmoke; text-align:center; font-size:100%;">\n'..
'<b>Index:</b> ['..pageurl..' *] ['..pageurl..'?from=# 0-9]'
else
toc_string = '<div class="toc plainlinks" style="clear:both; background:WhiteSmoke;">\n'..
'<div style="background:WhiteSmoke;">\n'..
'<div style="background:WhiteSmoke; text-align:center; font-size:100%;">\n'..
'<b>Index:</b> ['..pageurl..' *] ['..pageurl..'?from=# 0-9]'
end
-- Add ?from=A through Z to the title bar
for i=1,26,1 do
Line 41 ⟶ 56:
end
-- Closing tags
toc_string = toc_string..'<span style="font-size: 85%;">(Click <i>Show</i> for more navigation options.)</span>'..
if collapsible then
'\n</div>\n</div>'..
toc_string = toc_string..'<span style="font-size: 85%;">(Click <i>Show</i> for more navigation options.)</span>'
'<div class="NavContent" style="background:White; display:none;">'..
end
'<div class="plainlinks" style="background:White; font-size:100%; text-align:center;">'..
toc_string = toc_string..'\n</div></div>'
if collapsible then
toc_string = toc_string..'</span><div class="NavContent" style="background:White; display:none;">'..
'<div style="background:White; font-size:100%; text-align:center;">'..
'\n----'..
'\n<code style="background:White;"> <b>#</b>'
end
if scrollable then
toc_string = toc_string..'<div style="overflow-x:auto; overflow-y:hidden; width:98%;">'
end
-- Add ?from=0 through 9 to the list
for i=0,9,1 do
Line 61 ⟶ 67:
end
toc_string = toc_string..'<br/>'
-- Function to handle all 500+ ?from=Aa-z parameters with a simple loop
 
local function atoz(letter)
-- A-Z loop that calls the a-z function
local itlen
for i=1,26,1 do
local azstring
local letter = string.sub(azupper,i,i)
toc_string = toc_string..atoz(letter,true,true)
end
-- Close tags
toc_string = toc_string..'\n</code>\n</div></div></div>'
return toc_string
end
 
function atoz(letter,bullets,fullaz)
local azlist
local letterlist
local maxind
if fullaz then
azstringletterlist = azlower
itlenmaxind = 26
else
azstringletterlist = aejot
itlenmaxind = 5
end
if bullets then
local azlist
azlist = '\n• <b>'..letter..'</b> '
if collapsible then
else
azlist = '<br>\n<b>'..letter..'</b> '
else
azlist = '\n• <b>'..letter..'</b> '
end
for i=1,itlenmaxind,1 do
local lowerletter = string.sub(azstringletterlist,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