Jump to content

Module:Large category TOC/sandbox

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by The Mol Man (talk | contribs) at 16:47, 2 July 2014 (Create sandbox version of Module:Large category TOC). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
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