Difference between revisions of "Module:Large category TOC/sandbox"

From blackwiki
Jump to navigation Jump to search
blackwiki>The Mol Man
(i need to start from scratch later anyways...)
blackwiki>The Mol Man
Line 6: Line 6:
  
 
-- Implements [[Template:Large Category TOC]]
 
-- Implements [[Template:Large Category TOC]]
function p.scrollable(frame)
+
function p.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
 
local pageurl = mw.title.getCurrentTitle():fullUrl()
 
local pageurl = mw.title.getCurrentTitle():fullUrl()
Line 12: Line 12:
 
 
 
-- Begins the "title" parameter of {{Navigation bar}} with Top of the category (no ?from) and numerals (?from=0)
 
-- 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]'..
+
local toc_frame = mw.html.create('div')
'\n['..pageurl..'?from=0 0-9]'
+
:addClass('plainlinks')
-- Add ?from=A through Z to the title bar
+
:addClass('hlist')
for i=1,26,1 do
+
:attr('id', 'toc')
local letter = string.sub(azupper,i,i)
+
:css('background', 'WhiteSmoke')
title = title..'\n['..pageurl..'?from='..letter..' '..letter..']'
+
:css('clear', 'both')
end
+
:css('width', '98%')
-- Closing tags
+
 
title = title..'\n</span>\n</div>'
+
local header = mw.html.create('div')
-- Begin the list parameter with ?from=*
+
:attr('id', 'toctitle')
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
+
local body = mw.html.create('div')
for i=0,9,1 do
+
:css('text-align', 'center')
list = list..'\n['..pageurl..'?from='..i..' '..i..']'
+
 +
if toc_type == 'collapsible' then
 +
toc_frame:addClass('NavFrame')
 +
header:addClass('NavHeader')
 +
body:addClass('NavContent')
 +
:css('background','white')
 +
:css('display','none')
 +
elseif toc_type == 'scrollable' then
 +
body:css('overflow-x','scroll')
 +
:css('overflow-y','hidden')
 
end
 
end
-- A-Z loop that calls the a-z function
+
 +
local header_content = '<strong>'..toc..':</strong>' ..
 +
' ['..pageurl..' Top]' ..
 +
' ['..pageurl..'?from=0 0&endash;9]'
 +
 
for i=1,26,1 do
 
for i=1,26,1 do
 
local letter = string.sub(azupper,i,i)
 
local letter = string.sub(azupper,i,i)
list = list..atoz(letter,true,true,pageurl)
+
header_content = header_content..' ['..pageurl..'?from='..letter..' '..letter..']'
 
end
 
end
-- Close tags
 
list = list..'\n</span></div>'
 
 
 
return frame:expandTemplate{title='Navigation bar',args={color='#f9f9f9;',title=title,list=list}}
+
header:wikitext(header_content)
end
+
 
+
local body_content
-- 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'..
+
if toc_type == 'collapsible' then
'<div class="NavFrame" style="clear:both; background:WhiteSmoke;">\n'..
+
body_content = '<b>#</b> '
'<div class="NavHead" style="background:WhiteSmoke;">\n'..
+
else
'<div class="plainlinks" id="kat_toc" style="background:WhiteSmoke; text-align:center; font-size:100%;">\n'..
+
body_content = '['..pageurl..'?from=* <b>*</b>] <b>#</b> '
'<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
 
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
 
for i=0,9,1 do
toc_string = toc_string..'\n['..pageurl..'?from='..i..' '..i..']'
+
body_content = body_content..' ['..pageurl..'?from='..i..' '..i..']'
 
end
 
end
 
+
-- A-Z loop that calls the a-z function
 
 
for i=1,26,1 do
 
for i=1,26,1 do
 
local letter = string.sub(azupper,i,i)
 
local letter = string.sub(azupper,i,i)
toc_string = toc_string..atoz(letter,false,true,pageurl)
+
body_content = body_content..atoz(letter)
 
end
 
end
-- Close tags
 
toc_string = toc_string..'\n</code>\n</div></div></div>'
 
 
 
return toc_string
+
local function atoz(letter)
end
+
local azlist
 
+
local letterlist
function atoz(letter,bullets,fullaz,url)
+
local maxind
local azlist
+
if toc_type == 'aejot' then
local letterlist
+
letterlist = aejot
local maxind
+
maxind = 5
if fullaz then
+
else
letterlist = azlower
+
letterlist = azlower
maxind = 26
+
maxind = 26
else
+
end
letterlist = aejot
+
maxind = 5
+
if toc_type == 'aejot' or toc_type == 'scrollable' then
end
+
azlist = '\n• <b>'..letter..'</b> '
+
else
if bullets then
+
azlist = '\n<br /><b>'..letter..'</b> '
azlist = '\n• <b>'..letter..'</b> '
+
end
else
+
azlist = '\n<br /><b>'..letter..'</b> '
+
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
 
end
 
 
for i=1,maxind,1 do
+
body:wikitext(body_content)
local lowerletter = string.sub(letterlist,i,i)
+
header:node(body)
azlist = azlist..' ['..url..'?from='..letter..lowerletter..' '..letter..lowerletter..'] '
+
toc_frame:node(header)
end
+
return azlist
+
return tostring(toc_frame)
 
end
 
end
  
 
return p
 
return p

Revision as of 23:16, 6 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.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()
	
	-- Begins the "title" parameter of {{Navigation bar}} with Top of the category (no ?from) and numerals (?from=0)
	local toc_frame = mw.html.create('div')
				:addClass('plainlinks')
				:addClass('hlist')
				:attr('id', 'toc')
				:css('background', 'WhiteSmoke')
				:css('clear', 'both')
				:css('width', '98%')

	local header = mw.html.create('div')
				:attr('id', 'toctitle')

	local body = mw.html.create('div')
				:css('text-align', 'center')
	
	if toc_type == 'collapsible' then
		toc_frame:addClass('NavFrame')
		header:addClass('NavHeader')
		body:addClass('NavContent')
			:css('background','white')
			:css('display','none')
	elseif toc_type == 'scrollable' then
		body:css('overflow-x','scroll')
			:css('overflow-y','hidden')
	end
	
	local header_content = '<strong>'..toc..':</strong>' ..
						' ['..pageurl..' Top]' ..
						' ['..pageurl..'?from=0 0&endash;9]'
	
	for i=1,26,1 do
		local letter = string.sub(azupper,i,i)
		header_content = header_content..' ['..pageurl..'?from='..letter..' '..letter..']'
	end
	
	header:wikitext(header_content)
	
	local body_content
	
	if toc_type == 'collapsible' then
		body_content = '<b>#</b> '
	else
		body_content = '['..pageurl..'?from=* <b>*</b>] <b>#</b> '
	end
	
	for i=0,9,1 do
		body_content = body_content..' ['..pageurl..'?from='..i..' '..i..']'
	end
	
	for i=1,26,1 do
		local letter = string.sub(azupper,i,i)
		body_content = body_content..atoz(letter)
	end
	
	local function atoz(letter)
		local azlist
		local letterlist
		local maxind
		if toc_type == 'aejot' then
			letterlist = aejot
			maxind = 5
		else
			letterlist = azlower
			maxind = 26
		end
				
		if toc_type == 'aejot' or toc_type == 'scrollable' then
			azlist = '\n• <b>'..letter..'</b> '
		else
			azlist = '\n<br /><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
	
	body:wikitext(body_content)
	header:node(body)
	toc_frame:node(header)
	
	return tostring(toc_frame)
end

return p