From Wikipedia, the free encyclopedia


require('strict')

local p = {}

local getArgs = require('Module:Arguments').getArgs

local yesno = require("Module:Yesno")



local function converttolinearrgb(c)

	c = tonumber(c, 16)

	c = c / 255.0

	if c <= 0.03928 then

		c = c/12.92321  -- Correct constant from sRGB standard

	else

		c = ((c+0.055)/1.055) ^ 2.4

	end

	

	return c

end



local function luminance(color)

	-- The text color in the header is automatically chosen based on the best contrast

	-- https://stackoverflow.com/questions/3942878/how-to-decide-font-color-in-white-or-black-depending-on-background-color

	

	local rgb = string.gsub(color, '#', '')

	rgb = mw.text.split(rgb, '')

	local r, g, b

	if #rgb == 6 then

		r = rgb1 .. rgb2

		g = rgb3 .. rgb4

		b = rgb5 .. rgb6

	elseif #rgb == 3 then

		r = rgb1 .. rgb1

		g = rgb2 .. rgb2

		b = rgb3 .. rgb3

	end

	r = converttolinearrgb(r)

	g = converttolinearrgb(g)

	b = converttolinearrgb(b)

	

	return 0.2126 * r + 0.7152 * g + 0.0722 * b

end



local function generate_header(root, args)

	local header = root:tag('div')

	header:css('font-size','1.6875em')

	header:css('border-radius','2px')

	header:css('font-weight','bold')

	header:css('padding','0.25em')

	header:css('background',args.themecolor)

	header:css('color',luminance(args.themecolor) > 0.1791 and '#000' or '#fff')

	header:cssText(args.headerstyle)

	header:wikitext(args.portalname)

	if args.portalicon then

		local span = header:tag('span')

		span:css('padding','0.3em')

		span:css('display','inline-block')

		span:css('margin-right','0.5em')

		span:wikitext(portalicon)

	end

	return header

end



local function generate_tab(body, index, args)

	local container = body:tag('li')

	container:css('display','inline-block')

	container:css('position','relative')

	container:css('vertical-align','top')

	container:css('margin','0')

			

	-- Create the tab itself

			

	local entry = container:tag('span')

	entry:css('display','inline-block')

	entry:css('margin','1em')

	entry:css('padding-bottom','0.5em')

	entry:css('font-weight','bold')

	if index == args.active then

		if not args.subtabsindex or args.hidesubnav then

			entry:css('border-bottom','0.3em solid '..args.themecolor)

		else

			entry:css('margin-bottom','0')

		end

	else

		entry:css('border-bottom','0.3em solid #c8ccd1')

	end

			

	if args.tabsiconsindex then

		local icon = entry:tag('span')

		icon:css('margin-right','0.75em')

		icon:wikitext(args.tabsiconsindex])

	end

	entry:wikitext(args.tabsindex])

	

	-- If the tab is active, show the subnav if there is any

			

	if index == args.active and args.subtabsindex and not args.hidesubnav then

		local subnav = container:tag('ul')

		subnav:css('font-size','95%')

		subnav:css('margin','0 1em')

		subnav:css('padding','1.125em 0')

		local borderColor = '0.35em solid '..args.themecolor

		subnav:css('border-top',borderColor)

		subnav:css('border-bottom',borderColor)

		subnav:css('list-style','none')

		for _, subpagelink in ipairs(args.subtabsindex]) do

			local link = subnav:tag('li')

			link:css('margin','0')

			link:wikitext(subpagelink)

		end

	end

	return container

end



function p._render(args)

	local tabs = {}

	local subtabs = {}

	local tabsicons = {}

    -- Default values

	args.portalname = args.portalname or 'Portal'

	args.themecolor = args.themecolor or '#54595d'

	for _, key in ipairs({'wrc','hidenav','hidesubnav'}) do

		argskey = yesno(argskey])

	end

	args.active = tonumber(args.active)

	for key, value in pairs(args) do

		local id = tonumber(mw.ustring.match(key,'^tab(%d+)$'))

		if id then

			tabsid = value

		else

			id = tonumber(mw.ustring.match(key,'^icon(%d+)$'))

			if id then

				tabsiconsid = value

			else

				local primetab, subtab = mw.ustring.match(key,'^subtab(%d+)-(%d+)$')

				if primetab and subtab then

					primetab = tonumber(primetab)

					subtab = tonumber(subtab)

					if not subtabsprimetab then

						subtabsprimetab = {}

					end

					subtabsprimetab][subtab = value

				end

			end

		end

	end

	args.tabs = tabs

	args.subtabs = subtabs

	args.tabsicons = tabsicons

		

	-- Constructing header

	

	local root = mw.html.create('div')

	if args.wrc then

		local badgeargs = {}

		if wrcadditional then

			badgeargs'additional' = args.wrcadditional

		end



		root:wikitext(frame:expandTemplate{

			title = 'Wikimedia Resource Center badge',

			args = badgeargs })

	end

	generate_header(root, args)

	

	-- Constructing the rest

	

	if not args.hidenav then

		local body = root:tag('ul')

		body:css('font-size','1.125em')

		body:css('list-style','none')

		body:css('margin','0 0 1.125em 0')

		

		local tabindex = {}

		for index, _ in pairs(tabs) do

			table.insert(tabindex,index)

		end

		table.sort(tabindex)

		

		for _, index in ipairs(tabindex) do

			generate_tab(body, index, args)

		end

	end

	local clear = root:tag('div')

	clear:css('clear','both')

	return tostring(root)

end



function p.render(frame)

	local args = getArgs(frame)

	return p._render(args)

end



return p
From Wikipedia, the free encyclopedia


require('strict')

local p = {}

local getArgs = require('Module:Arguments').getArgs

local yesno = require("Module:Yesno")



local function converttolinearrgb(c)

	c = tonumber(c, 16)

	c = c / 255.0

	if c <= 0.03928 then

		c = c/12.92321  -- Correct constant from sRGB standard

	else

		c = ((c+0.055)/1.055) ^ 2.4

	end

	

	return c

end



local function luminance(color)

	-- The text color in the header is automatically chosen based on the best contrast

	-- https://stackoverflow.com/questions/3942878/how-to-decide-font-color-in-white-or-black-depending-on-background-color

	

	local rgb = string.gsub(color, '#', '')

	rgb = mw.text.split(rgb, '')

	local r, g, b

	if #rgb == 6 then

		r = rgb1 .. rgb2

		g = rgb3 .. rgb4

		b = rgb5 .. rgb6

	elseif #rgb == 3 then

		r = rgb1 .. rgb1

		g = rgb2 .. rgb2

		b = rgb3 .. rgb3

	end

	r = converttolinearrgb(r)

	g = converttolinearrgb(g)

	b = converttolinearrgb(b)

	

	return 0.2126 * r + 0.7152 * g + 0.0722 * b

end



local function generate_header(root, args)

	local header = root:tag('div')

	header:css('font-size','1.6875em')

	header:css('border-radius','2px')

	header:css('font-weight','bold')

	header:css('padding','0.25em')

	header:css('background',args.themecolor)

	header:css('color',luminance(args.themecolor) > 0.1791 and '#000' or '#fff')

	header:cssText(args.headerstyle)

	header:wikitext(args.portalname)

	if args.portalicon then

		local span = header:tag('span')

		span:css('padding','0.3em')

		span:css('display','inline-block')

		span:css('margin-right','0.5em')

		span:wikitext(portalicon)

	end

	return header

end



local function generate_tab(body, index, args)

	local container = body:tag('li')

	container:css('display','inline-block')

	container:css('position','relative')

	container:css('vertical-align','top')

	container:css('margin','0')

			

	-- Create the tab itself

			

	local entry = container:tag('span')

	entry:css('display','inline-block')

	entry:css('margin','1em')

	entry:css('padding-bottom','0.5em')

	entry:css('font-weight','bold')

	if index == args.active then

		if not args.subtabsindex or args.hidesubnav then

			entry:css('border-bottom','0.3em solid '..args.themecolor)

		else

			entry:css('margin-bottom','0')

		end

	else

		entry:css('border-bottom','0.3em solid #c8ccd1')

	end

			

	if args.tabsiconsindex then

		local icon = entry:tag('span')

		icon:css('margin-right','0.75em')

		icon:wikitext(args.tabsiconsindex])

	end

	entry:wikitext(args.tabsindex])

	

	-- If the tab is active, show the subnav if there is any

			

	if index == args.active and args.subtabsindex and not args.hidesubnav then

		local subnav = container:tag('ul')

		subnav:css('font-size','95%')

		subnav:css('margin','0 1em')

		subnav:css('padding','1.125em 0')

		local borderColor = '0.35em solid '..args.themecolor

		subnav:css('border-top',borderColor)

		subnav:css('border-bottom',borderColor)

		subnav:css('list-style','none')

		for _, subpagelink in ipairs(args.subtabsindex]) do

			local link = subnav:tag('li')

			link:css('margin','0')

			link:wikitext(subpagelink)

		end

	end

	return container

end



function p._render(args)

	local tabs = {}

	local subtabs = {}

	local tabsicons = {}

    -- Default values

	args.portalname = args.portalname or 'Portal'

	args.themecolor = args.themecolor or '#54595d'

	for _, key in ipairs({'wrc','hidenav','hidesubnav'}) do

		argskey = yesno(argskey])

	end

	args.active = tonumber(args.active)

	for key, value in pairs(args) do

		local id = tonumber(mw.ustring.match(key,'^tab(%d+)$'))

		if id then

			tabsid = value

		else

			id = tonumber(mw.ustring.match(key,'^icon(%d+)$'))

			if id then

				tabsiconsid = value

			else

				local primetab, subtab = mw.ustring.match(key,'^subtab(%d+)-(%d+)$')

				if primetab and subtab then

					primetab = tonumber(primetab)

					subtab = tonumber(subtab)

					if not subtabsprimetab then

						subtabsprimetab = {}

					end

					subtabsprimetab][subtab = value

				end

			end

		end

	end

	args.tabs = tabs

	args.subtabs = subtabs

	args.tabsicons = tabsicons

		

	-- Constructing header

	

	local root = mw.html.create('div')

	if args.wrc then

		local badgeargs = {}

		if wrcadditional then

			badgeargs'additional' = args.wrcadditional

		end



		root:wikitext(frame:expandTemplate{

			title = 'Wikimedia Resource Center badge',

			args = badgeargs })

	end

	generate_header(root, args)

	

	-- Constructing the rest

	

	if not args.hidenav then

		local body = root:tag('ul')

		body:css('font-size','1.125em')

		body:css('list-style','none')

		body:css('margin','0 0 1.125em 0')

		

		local tabindex = {}

		for index, _ in pairs(tabs) do

			table.insert(tabindex,index)

		end

		table.sort(tabindex)

		

		for _, index in ipairs(tabindex) do

			generate_tab(body, index, args)

		end

	end

	local clear = root:tag('div')

	clear:css('clear','both')

	return tostring(root)

end



function p.render(frame)

	local args = getArgs(frame)

	return p._render(args)

end



return p

Videos

Youtube | Vimeo | Bing

Websites

Google | Yahoo | Bing

Encyclopedia

Google | Yahoo | Bing

Facebook