Module:Button

local p = {}

local SIDE_WIDTH = 17 local SIDE_HEIGHT = 45 local DEFAULT_HEIGHT = 45

-- Module call from Template:Button function p.getButton( frame ) local args = require("Module:Args").getCleanArgs

local subclass if (args.subclass == nil) then subclass = "blue" else subclass = assert(args.subclass == "blue" or args.subclass == "yellow", "Invalid value of parameter 'subclass'") end local content = args.content or "" local width = args.width local height = args.height local div = mw.html.create("div") :addClass("button-" .. subclass) :tag("div") :addClass("button-" .. subclass .. "-left") :css({				["width"] = getWidth(width, height, "left"),				["height"] = getHeight(width, height, "left")			}) :done :tag("div") :addClass("button-" .. subclass .. "-middle") :css({				["width"] = getWidth(width, height, "middle"),				["height"] = getHeight(width, height, "middle")			}) :wikitext(content) :done :tag("div") :addClass("button-" .. subclass .. "-right") :css({				["width"] = getWidth(width, height, "right"),				["height"] = getHeight(width, height, "right")			}) :done :done return tostring(div) end

function getWidth(width, height, pos) if (width == nil) then if (pos == "middle") then return "auto" else return string.format("%dpx", SIDE_WIDTH) end else width = tonumber((mw.text.trim(width):gsub(",", ""))) if (pos == "middle") then return string.format("%dpx", width - 2 * SIDE_WIDTH * (height or DEFAULT_HEIGHT) / SIDE_HEIGHT) else return string.format("%dpx", 2 * SIDE_WIDTH * (height or DEFAULT_HEIGHT) / SIDE_HEIGHT) end end end

function getHeight(width, height, pos) if (height == nil) then if (width == nil) then return string.format("%dpx", DEFAULT_HEIGHT) else return "auto" end else height = tonumber((mw.text.trim(height):gsub(",", ""))) return string.format("%dpx", height) end end

return p