Difference between revisions of "Module:Large category TOC/sandbox"
Jump to navigation
Jump to search
blackwiki>The Mol Man |
blackwiki>The Mol Man |
||
| Line 7: | Line 7: | ||
-- Implements [[Template:Large Category TOC]] | -- Implements [[Template:Large Category TOC]] | ||
function p.scrollable(frame) | function p.scrollable(frame) | ||
| − | + | -- It should be much faster to only process these once, and just re use them as variables | |
| + | local pageurl = mw.title.getCurrentTitle():fullUrl() | ||
| + | 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 | ||
| + | for i=0,9,1 do | ||
| + | list = list..'\n['..pageurl..'?from='..i..' '..i..']' | ||
| + | end | ||
| + | -- A-Z loop that calls the a-z function | ||
| + | for i=1,26,1 do | ||
| + | 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 | end | ||
| + | -- Implements [[Template:Collapsible large category TOC]] | ||
function p.collapsible(frame) | function p.collapsible(frame) | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
-- It should be much faster to only process these once, and just re use them as variables | -- It should be much faster to only process these once, and just re use them as variables | ||
| − | local pageurl = | + | local pageurl = mw.title.getCurrentTitle():fullUrl() |
| − | local | + | local toc_string = '<div class="collapsible" style="background:transparent;">\n'.. |
| − | + | '<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]' | '<b>Index:</b> ['..pageurl..' *] ['..pageurl..'?from=# 0-9]' | ||
| − | |||
-- Add ?from=A through Z to the title bar | -- Add ?from=A through Z to the title bar | ||
for i=1,26,1 do | for i=1,26,1 do | ||
| Line 41: | Line 56: | ||
end | end | ||
-- Closing tags | -- Closing tags | ||
| − | + | toc_string = toc_string..'<span style="font-size: 85%;">(Click <i>Show</i> for more navigation options.)</span>'.. | |
| − | + | '\n</div>\n</div>'.. | |
| − | + | '<div class="NavContent" style="background:White; display:none;">'.. | |
| − | + | '<div class="plainlinks" style="background:White; font-size:100%; text-align:center;">'.. | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | '<div style="background:White; font-size:100%; text-align:center;">'.. | ||
'\n----'.. | '\n----'.. | ||
'\n<code style="background:White;"> <b>#</b>' | '\n<code style="background:White;"> <b>#</b>' | ||
| − | |||
| − | |||
| − | |||
| − | |||
-- Add ?from=0 through 9 to the list | -- Add ?from=0 through 9 to the list | ||
for i=0,9,1 do | for i=0,9,1 do | ||
| Line 61: | Line 67: | ||
end | end | ||
| − | -- | + | toc_string = toc_string..'<br/>' |
| − | local function atoz(letter) | + | |
| − | local | + | -- A-Z loop that calls the a-z function |
| − | local | + | for i=1,26,1 do |
| + | 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 | if fullaz then | ||
| − | + | letterlist = azlower | |
| − | + | maxind = 26 | |
else | else | ||
| − | + | letterlist = aejot | |
| − | + | maxind = 5 | |
end | end | ||
| − | + | if bullets then | |
| − | + | azlist = '\n• <b>'..letter..'</b> ' | |
| + | else | ||
azlist = '<br>\n<b>'..letter..'</b> ' | azlist = '<br>\n<b>'..letter..'</b> ' | ||
| − | |||
| − | |||
end | end | ||
| − | for i=1, | + | for i=1,maxind,1 do |
| − | local lowerletter = string.sub( | + | local lowerletter = string.sub(letterlist,i,i) |
azlist = azlist..' ['..pageurl..'?from='..letter..lowerletter..' '..letter..lowerletter..'] ' | azlist = azlist..' ['..pageurl..'?from='..letter..lowerletter..' '..letter..lowerletter..'] ' | ||
end | end | ||
return azlist | return azlist | ||
end | end | ||
| − | + | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
return p | return p | ||
Revision as of 17:38, 2 July 2014
Documentation for this module may be created at Module:Large category TOC/sandbox/doc
local p = {}
local azupper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
local azlower = 'abcdefghijklmnopqrstuvwxyz'
local aejot = 'aejot'
-- 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
local pageurl = mw.title.getCurrentTitle():fullUrl()
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
for i=0,9,1 do
list = list..'\n['..pageurl..'?from='..i..' '..i..']'
end
-- A-Z loop that calls the a-z function
for i=1,26,1 do
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 p.collapsible(frame)
-- It should be much faster to only process these once, and just re use them as variables
local pageurl = mw.title.getCurrentTitle():fullUrl()
local toc_string = '<div class="collapsible" style="background:transparent;">\n'..
'<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
toc_string = toc_string..'<span style="font-size: 85%;">(Click <i>Show</i> for more navigation options.)</span>'..
'\n</div>\n</div>'..
'<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>'
-- Add ?from=0 through 9 to the list
for i=0,9,1 do
toc_string = toc_string..'\n['..pageurl..'?from='..i..' '..i..']'
end
toc_string = toc_string..'<br/>'
-- 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,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
letterlist = azlower
maxind = 26
else
letterlist = aejot
maxind = 5
end
if bullets then
azlist = '\n• <b>'..letter..'</b> '
else
azlist = '<br>\n<b>'..letter..'</b> '
end
for i=1,maxind,1 do
local lowerletter = string.sub(letterlist,i,i)
azlist = azlist..' ['..pageurl..'?from='..letter..lowerletter..' '..letter..lowerletter..'] '
end
return azlist
end
return p