Module:Zgallery

From Uncyclopedia, the content-free encyclopedia
Jump to navigation Jump to search

Documentation for this module may be created at Module:Zgallery/doc

-- spit-polish and documentation to follow. This sucks. Ignore how bad this sucks.
local p = {}

function dimensions( width, height )
	local dimensions
	if width ~= nil then dimensions = width .. 'px' end
	if height ~= nil then dimensions = 'x' .. height .. 'px' end
	return ( dimensions or '180px' )
end

function p.build( frame )
	local gallery, a, id = {}, frame.args, ( frame.args.id or 'lg_' .. math.random( 1000, 9999 ) )
	for i, val in ipairs( a ) do
		local pic, w, h, link
		w = tonumber( a[ 'width' .. i ] or tonumber( a.width ) )
		h = tonumber( a[ 'height' .. i ] or tonumber( a.height ) )
		link = ( a[ 'link' .. i ] or a.link )
		if link == 'nolink' then link = 'link=' elseif link then link = 'link=' .. link end
		pic = '<li class="lg_item" style="display: inline-block; font-size: 85%; vertical-align: top;">'
			.. '<div class="lg_image">' .. '[[File:' .. val .. '|' .. dimensions( w, h ) .. '|'
			.. ( link or '' ) .. ']]</div>'
			.. '<div class="lg_caption" style="font-size: 90%; width: ' .. ( w or 180 ) .. 'px;">'
			.. ( a[ 'c' .. i ] or '' ) .. '</div></li>'
		table.insert( gallery, pic )
	end
	return '<ul class="lua_gallery" id="' .. id .. '">' .. table.concat( gallery ) .. '</ul>',
	-- for testing only! Remove at a later date.
		'<!--' .. mw.text.nowiki( table.concat( gallery ) ) .. '-->'
end

return p