Module:Bounce

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

local p = {}

function p.main(frame)
	local args = frame:getParent() and frame:getParent().args or frame.args
	local text = args[1] or "Bounce"
	local color = args[2] or "inherit"
	
	color = color or "inherit"
	if color:match("^[0-9a-fA-F]+$") and #color == 6 then
        color = "#" .. color
    end

	local styles = frame:extensionTag{ 
        name = 'templatestyles', 
        args = { src = 'Template:Bounce/styles.css' } 
	}

	local root = mw.html.create('span')
	root:addClass('bounce-container')
	if args.class and args.class ~= '' then
    	root:addClass(args.class)
	end
	root:css('color', color)

	local inner = root:tag('span')
	inner:addClass('noop-bounce')
	inner:attr('aria-label', text)

	local delay_step = 0.2
	local current_delay = 0
 
	for char in mw.ustring.gmatch(text, ".") do
        local content = char
        if content == " " then content = " " end

        inner:tag('span')
            :addClass('bnc')
            :css('animation-delay', current_delay .. 's')
            :wikitext(content)
            
        current_delay = current_delay + delay_step
	end

	return styles .. tostring(root)
end

return p