Difference between revisions of "Module:Large category TOC/sandbox"
Jump to navigation
Jump to search
blackwiki>The Mol Man |
m (51 revisions imported) |
||
| (7 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
| − | local azupper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' | + | local azupper = mw.text.split('ABCDEFGHIJKLMNOPQRSTUVWXYZ','') |
| − | local azlower = 'abcdefghijklmnopqrstuvwxyz' | + | local azlower = mw.text.split('abcdefghijklmnopqrstuvwxyz','') |
| − | local aejot = 'aejot' | + | local aejot = mw.text.split('aejot','') |
function p.scrollable(frame) | function p.scrollable(frame) | ||
| Line 17: | Line 17: | ||
end | end | ||
| − | |||
| − | |||
function main(toc_type) | function main(toc_type) | ||
-- 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 | ||
| Line 30: | Line 28: | ||
:addClass('toc') | :addClass('toc') | ||
-- :attr('id','toc') | -- :attr('id','toc') | ||
| − | :css( | + | :css({ display = 'block !important', |
| − | + | background = 'WhiteSmoke', | |
| − | + | clear = 'both', | |
| − | + | width = '98%' }) | |
-- Contains "Content: Top 0-9 A - Z" | -- Contains "Content: Top 0-9 A - Z" | ||
| − | local header = | + | local header = toc_frame:tag('div') |
:attr('id','toctitle') | :attr('id','toctitle') | ||
| + | :attr('class','toctitle') | ||
:css('background','WhiteSmoke') | :css('background','WhiteSmoke') | ||
-- Contains all the rest | -- Contains all the rest | ||
local body_wrapper | local body_wrapper | ||
| − | local body = | + | local body = toc_frame:tag('div') |
| − | + | :css('text-align', 'center') | |
if toc_type == 'collapsible' then | if toc_type == 'collapsible' then | ||
| Line 49: | Line 48: | ||
header:addClass('NavHead') | header:addClass('NavHead') | ||
body:addClass('NavContent') | body:addClass('NavContent') | ||
| − | :css( | + | :css({ background = 'white', |
| − | + | display = 'none' }) | |
elseif toc_type == 'scrollable' then | elseif toc_type == 'scrollable' then | ||
| − | body:css('overflow-x' | + | body:css({ ['overflow-x'] = 'scroll', |
| − | + | ['overflow-y']= 'hidden', | |
| − | + | ['white-space'] = 'nowrap' }) | |
end | end | ||
| − | local header_content = | + | local header_content = {toc,':', |
| − | ' [' | + | ' [',pageurl,' Top]', |
| − | ' [' | + | ' [',pageurl,'?from=0 0–9]' } |
| − | for | + | for _, v in ipairs(azupper) do |
| − | + | table.insert(header_content,string.format(' [%s?from=%s %s]',pageurl,v,v)) | |
| − | |||
end | end | ||
| + | header:wikitext(table.concat(header_content)) | ||
| − | + | local body_content = {} | |
| − | |||
| − | local body_content | ||
if toc_type == 'collapsible' then | if toc_type == 'collapsible' then | ||
| − | body_content | + | table.insert(body_content,'<b>#</b> ') |
| − | body_wrapper = | + | body_wrapper = body:tag('code') |
| − | + | :css('background','White') | |
else | else | ||
| − | body_content | + | table.insert(body_content,'['..pageurl..'?from=* <b>*</b>] <b>#</b> ') |
| − | body_wrapper = | + | body_wrapper = body:tag('span') |
end | end | ||
| − | for i=0,9 | + | for i=0,9 do |
| − | body_content | + | table.insert(body_content,string.format(' [%s?from=%s %s]',pageurl,i,i)) |
end | end | ||
local function atoz(letter) | local function atoz(letter) | ||
| − | local azlist | + | local azlist = {} |
local letterlist | local letterlist | ||
| − | |||
if toc_type == 'aejot' then | if toc_type == 'aejot' then | ||
letterlist = aejot | letterlist = aejot | ||
| − | |||
else | else | ||
letterlist = azlower | letterlist = azlower | ||
| − | |||
end | end | ||
if toc_type == 'aejot' or toc_type == 'scrollable' then | if toc_type == 'aejot' or toc_type == 'scrollable' then | ||
| − | azlist | + | table.insert(azlist,' • <b>'..letter..'</b> ') |
else | else | ||
| − | azlist | + | table.insert(azlist,'<br /><b>'..letter..'</b> ') |
end | end | ||
| − | for | + | for _, v in ipairs(letterlist) do |
| − | + | table.insert(azlist,string.format(' [%s?from=%s%s %s%s] ',pageurl,letter,v,letter,v)) | |
| − | |||
end | end | ||
| − | return azlist | + | return table.concat(azlist) |
end | end | ||
| − | for | + | for _, v in ipairs(azupper) do |
| − | + | table.insert(body_content,atoz(v)) | |
| − | |||
end | end | ||
| − | body_wrapper:wikitext(body_content) | + | body_wrapper:wikitext(table.concat(body_content)) |
| − | |||
| − | |||
| − | |||
return '__NOTOC__\n'..tostring(toc_frame) | return '__NOTOC__\n'..tostring(toc_frame) | ||
Latest revision as of 06:11, 27 September 2020
Documentation for this module may be created at Module:Large category TOC/sandbox/doc
local p = {}
local azupper = mw.text.split('ABCDEFGHIJKLMNOPQRSTUVWXYZ','')
local azlower = mw.text.split('abcdefghijklmnopqrstuvwxyz','')
local aejot = mw.text.split('aejot','')
function p.scrollable(frame)
return main('scrollable')
end
function p.collapsible(frame)
return main('collapsible')
end
function p.aejot(frame)
return main('aejot')
end
function main(toc_type)
-- 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()
-- Highest level div
local toc_frame = mw.html.create('div')
:addClass('plainlinks')
:addClass('hlist')
:addClass('toc')
-- :attr('id','toc')
:css({ display = 'block !important',
background = 'WhiteSmoke',
clear = 'both',
width = '98%' })
-- Contains "Content: Top 0-9 A - Z"
local header = toc_frame:tag('div')
:attr('id','toctitle')
:attr('class','toctitle')
:css('background','WhiteSmoke')
-- Contains all the rest
local body_wrapper
local body = toc_frame:tag('div')
:css('text-align', 'center')
if toc_type == 'collapsible' then
toc_frame:addClass('NavFrame')
header:addClass('NavHead')
body:addClass('NavContent')
:css({ background = 'white',
display = 'none' })
elseif toc_type == 'scrollable' then
body:css({ ['overflow-x'] = 'scroll',
['overflow-y']= 'hidden',
['white-space'] = 'nowrap' })
end
local header_content = {toc,':',
' [',pageurl,' Top]',
' [',pageurl,'?from=0 0–9]' }
for _, v in ipairs(azupper) do
table.insert(header_content,string.format(' [%s?from=%s %s]',pageurl,v,v))
end
header:wikitext(table.concat(header_content))
local body_content = {}
if toc_type == 'collapsible' then
table.insert(body_content,'<b>#</b> ')
body_wrapper = body:tag('code')
:css('background','White')
else
table.insert(body_content,'['..pageurl..'?from=* <b>*</b>] <b>#</b> ')
body_wrapper = body:tag('span')
end
for i=0,9 do
table.insert(body_content,string.format(' [%s?from=%s %s]',pageurl,i,i))
end
local function atoz(letter)
local azlist = {}
local letterlist
if toc_type == 'aejot' then
letterlist = aejot
else
letterlist = azlower
end
if toc_type == 'aejot' or toc_type == 'scrollable' then
table.insert(azlist,' • <b>'..letter..'</b> ')
else
table.insert(azlist,'<br /><b>'..letter..'</b> ')
end
for _, v in ipairs(letterlist) do
table.insert(azlist,string.format(' [%s?from=%s%s %s%s] ',pageurl,letter,v,letter,v))
end
return table.concat(azlist)
end
for _, v in ipairs(azupper) do
table.insert(body_content,atoz(v))
end
body_wrapper:wikitext(table.concat(body_content))
return '__NOTOC__\n'..tostring(toc_frame)
end
return p