پرش به محتوا

ماژول:Side box

ویکی‌پدیا، آزادِ دانشنومه، جه

توضیحات این پودمان می‌تواند در ماژول:Side box/توضیحات قرار گیرد.

-- This module implements {{side box}}.

local yesno = require('Module:Yesno')

local p = {}

function p.main(frame)
	local origArgs = frame:getParent().args
	local args = {}
	for k, v in pairs(origArgs) do
		v = v:match('%s*(.-)%s*$')
		if v ~= '' then
			args[k] = v
		end
	end
	return p._main(args)
end

function p._main(args)
	local data = p.makeData(args)
	return p.renderSidebox(data)
end

function p.makeData(args)
	local data = {}

	-- Main table classes
	data.classes = {}
	if yesno(args.metadata) ~= false then
		table.insert(data.classes, 'metadata')
	end
	if args.position and (args.position:lower() == 'right' or args.position == 'يمين') then
		table.insert(data.classes, 'mbox-small-right')
	else
		table.insert(data.classes, 'mbox-small')
	end
	table.insert(data.classes, args.class)
	
	-- Image
	if args.image and (args.image ~= 'none' or args.image ~= 'بدون') then
		data.image = args.image
	end

	-- Copy over data that does not need adjusting
	local argsToCopy = {
		-- Classes
		'textclass',

		-- Styles
		'style',
		'textstyle',

		-- Above row
		'above',
		'abovestyle',

		-- Body row
		'text',
		'imageleft',

		-- Below row
		'below',
	}
	for i, key in ipairs(argsToCopy) do
		data[key] = args[key]
	end

	return data
end

function p.renderSidebox(data)
	-- Renders the sidebox HTML.

	-- Table root
	local root = mw.html.create('table')
	root:attr('role', 'presentation')
	for i, class in ipairs(data.classes or {}) do
		root:addClass(class)
	end
	root:css{border = '1px solid #C0C0C0', ['background-color'] = '#f9f9f9', color = '#000'}
	if data.style then
		root:cssText(data.style)
	end

	-- The "above" row
	if data.above then
		local aboveCell = root:newline():tag('tr'):tag('td')
		aboveCell
			:attr('colspan', data.imageleft and 3 or 2)
			:addClass('mbox-text')
		if data.textstyle then
			aboveCell:cssText(data.textstyle)
		end
		if data.abovestyle then
			aboveCell:cssText(data.abovestyle)
		end
		aboveCell
			:newline()
			:wikitext(data.above)
	end

	-- The body row
	local bodyRow = root:newline():tag('tr'):newline()
	if data.image then
		bodyRow:tag('td')
			:addClass('mbox-image')
			:wikitext(data.image)
	else
		bodyRow:tag('td'):css('width', '1px')
	end
	local textCell = bodyRow:newline():tag('td')
	textCell:addClass('mbox-text')
	textCell:addClass(data.textclass or 'plainlist')
	if data.textstyle then
		textCell:cssText(data.textstyle)
	end
	textCell:wikitext(data.text)
	if data.imageleft then
		bodyRow:newline():tag('td')
			:addClass('mbox-imageleft')
			:wikitext(data.imageleft)
	end

	-- The below row
	if data.below then
		local belowCell = root:newline():tag('tr'):tag('td')
		belowCell
			:attr('colspan', data.imageleft and 3 or 2)
			:addClass('mbox-text')
		if data.textstyle then
			belowCell:cssText(data.textstyle)
		end
		belowCell:wikitext(data.below)
	end

	root:newline()
	return tostring(root)
end

return p
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy