正在編輯「模組:Infobox

跳至導覽 跳至搜尋
警告:您尚未登入。 若您進行任何的編輯您的 IP 位址將會被公開。 若您 登入建立帳號,您的編輯將會以您的使用者名稱標示,並能擁有另外的益處。

此編輯可以被還原。 請檢查以下比較表,確認您是否要還原,然後發布以下變更以完成編輯還原。

最新修訂 您的文字
行 4: 行 4:
-- overimagerowclass以及header/labal/data*style參數。
-- overimagerowclass以及header/labal/data*style參數。
--
--

local p = {}
local p = {}


local navbar = require('Module:Navbar')._navbar
local HtmlBuilder = require('Module:HtmlBuilder')


local args = {}
local args = {}
行 13: 行 13:
local root
local root


local function union(t1, t2)
function union(t1, t2)
-- Returns the union of the values of two tables, as a sequence.
-- Returns the union of the values of two tables, as a sequence.
local vals = {}
local vals = {}
for k, v in pairs(t1) do
for k,v in pairs(t1) do
vals[v] = true
vals[v] = true
end
end
for k, v in pairs(t2) do
for k,v in pairs(t2) do
vals[v] = true
vals[v] = true
end
end
local ret = {}
local ret = {}
for k, v in pairs(vals) do
for k,v in pairs(vals) do
table.insert(ret, k)
table.insert(ret, k)
end
end
行 34: 行 34:
-- 'data1', 'data2', and 'data5' exist, it would return {1, 2, 5}.
-- 'data1', 'data2', and 'data5' exist, it would return {1, 2, 5}.
local nums = {}
local nums = {}
for k, v in pairs(args) do
for k,v in pairs(args) do
local num = tostring(k):match('^' .. prefix .. '([1-9]%d*)$')
local num = tostring(k):match('^' .. prefix .. '([1-9]%d*)$')
if num then table.insert(nums, tonumber(num)) end
if num then table.insert(nums, tonumber(num)) end
行 47: 行 47:
if rowArgs.header then
if rowArgs.header then
root
root
:tag('tr')
.tag('tr')
:addClass(rowArgs.rowclass)
.addClass(rowArgs.rowclass)
:cssText(rowArgs.rowstyle)
.tag('th')
:attr('id', rowArgs.rowid)
.attr('colspan', 2)
:tag('th')
.addClass(rowArgs.class)
:attr('colspan', 2)
.css('text-align', 'center')
:attr('id', rowArgs.headerid)
.cssText(rowArgs.headerstyle)
:addClass(rowArgs.class)
.wikitext(rowArgs.header)
:addClass(args.headerclass)
:css('text-align', 'center')
:cssText(rowArgs.headerstyle)
:wikitext(rowArgs.header)
elseif rowArgs.data then
elseif rowArgs.data then
local row = root:tag('tr')
local row = root.tag('tr')
row:addClass(rowArgs.rowclass)
row.addClass(rowArgs.rowclass)
row:cssText(rowArgs.rowstyle)
row:attr('id', rowArgs.rowid)
if rowArgs.label then
if rowArgs.label then
row
row
:tag('th')
.tag('th')
:attr('scope', 'row')
.attr('scope', 'row')
:css('text-align', 'left')
.css('text-align', 'left')
:attr('id', rowArgs.labelid)
.cssText(rowArgs.labelstyle)
:cssText(rowArgs.labelstyle)
.wikitext(rowArgs.label)
:wikitext(rowArgs.label)
.done()
:done()
end
end

local dataCell = row:tag('td')
local dataCell = row.tag('td')
if not rowArgs.label then
if not rowArgs.label then
dataCell
dataCell
:attr('colspan', 2)
.attr('colspan', 2)
:css('text-align', 'center')
.css('text-align', 'center')
end
end
dataCell
dataCell
:attr('id', rowArgs.dataid)
.addClass(rowArgs.class)
:addClass(rowArgs.class)
.cssText(rowArgs.datastyle)
:cssText(rowArgs.datastyle)
.newline()
:newline()
.wikitext(rowArgs.data)
:wikitext(rowArgs.data)
end
end
end
end
行 93: 行 85:
if not args.overimage then return end
if not args.overimage then return end


local row = root:tag('tr')
local row = root.tag('tr')
row:addClass(args.overimagerowclass)
row.addClass(args.overimagerowclass)
local topImage = row:tag('td')
local topImage = row.tag('td')
topImage:attr('colspan', 2)
topImage.attr('colspan', 2)
topImage:addClass(args.imageclass)
topImage.addClass(args.class)
topImage:cssText(args.imagestyle)
topImage.cssText(args.datastyle)
topImage:css('text-align', 'center')
topImage.css('text-align', 'center')
if args.overcaption and args.captionstyle then
if args.overcaption then
topImage:wikitext(args.overimage .. '<br /><span style=\"' .. args.captionstyle .. '\">' .. args.overcaption .. '</span>')
topImage.wikitext(args.overimage .. '<br><span style=\"' .. args.captionstyle .. '\">' .. args.overcaption .. '</span>')
else
else
topImage.wikitext(args.overimage)
if args.overcaption then
end
topImage:wikitext(args.overimage .. '<br />' .. args.overcaption)
else
topImage:wikitext(args.overimage)
end
end
end
end


local function renderTitle()
local function renderTitle()
if not args.title then return end
if not args.title then return end

root
root
:tag('caption')
.tag('caption')
:addClass(args.titleclass)
.addClass(args.titleclass)
:cssText(args.titlestyle)
.cssText(args.titlestyle)
:wikitext('\'\'\'' .. args.title .. '\'\'\'')
.wikitext('\'\'\'' .. args.title .. '\'\'\'')
end
end


local function renderAboveRow()
local function renderAboveRow()
if not args.above then return end
if not args.above then return end
root
root
:tag('tr')
.tag('tr')
:tag('th')
.tag('th')
:attr('colspan', 2)
.attr('colspan', 2)
:addClass(args.aboveclass)
.addClass(args.aboveclass)
:css('text-align', 'center')
.css('text-align', 'center')
:css('font-size', '125%')
.css('font-size', '125%')
:css('font-weight', 'bold')
.css('font-weight', 'bold')
:cssText(args.abovestyle)
.cssText(args.abovestyle)
:wikitext(args.above)
.wikitext(args.above)
end
end


local function renderBelowRow()
local function renderBelowRow()
if not args.below then return end
if not args.below then return end

root
root
:tag('tr')
.tag('tr')
:tag('td')
.tag('td')
:attr('colspan', '2')
.attr('colspan', '2')
:addClass(args.belowclass)
.addClass(args.belowclass)
:css('text-align', 'center')
.css('text-align', 'center')
:cssText(args.belowstyle)
.cssText(args.belowstyle)
:newline()
.newline()
:wikitext(args.below)
.wikitext(args.below)
end
end


行 158: 行 146:
end
end
local subheadernums = getArgNums('subheader')
local subheadernums = getArgNums('subheader')
for k, num in ipairs(subheadernums) do
for k,num in ipairs(subheadernums) do
addRow({
addRow({
data = args['subheader' .. tostring(num)],
data = args['subheader' .. tostring(num)],
行 176: 行 164:
end
end
local imagenums = getArgNums('image')
local imagenums = getArgNums('image')
for k, num in ipairs(imagenums) do
for k,num in ipairs(imagenums) do
local caption = args['caption' .. tostring(num)]
local caption = args['caption' .. tostring(num)]
local data = mw.html.create():wikitext(args['image' .. tostring(num)])
local data = HtmlBuilder.create().wikitext(args['image' .. tostring(num)])
if caption then
if caption then
data
data
:tag('div')
.tag('br', {selfClosing = true})
:cssText(args.captionstyle)
.done()
:wikitext(caption)
.tag('div')
.cssText(args.captionstyle)
.wikitext(caption)
end
end
addRow({
addRow({
行 199: 行 189:
local rownums = union(getArgNums('header'), getArgNums('data'))
local rownums = union(getArgNums('header'), getArgNums('data'))
table.sort(rownums)
table.sort(rownums)
for k, num in ipairs(rownums) do
for k,num in ipairs(rownums) do
addRow({
addRow({
header = args['header' .. tostring(num)],
header = args['header' .. tostring(num)],
headerstyle = (args.headerstyle or '') .. (args.headerstyle and ';' or '') .. (args['header' .. tostring(num) .. 'style'] or ''),
headerstyle = (args.headerstyle or '') .. ';' .. (args['header' .. tostring(num) .. 'style'] or ''),
label = args['label' .. tostring(num)],
label = args['label' .. tostring(num)],
labelstyle = (args.labelstyle or '') .. (args.labelstyle and ';' or '') .. (args['label' .. tostring(num) .. 'style'] or ''),
labelstyle = (args.labelstyle or '') .. ';' .. (args['label' .. tostring(num) .. 'style'] or ''),
data = args['data' .. tostring(num)],
data = args['data' .. tostring(num)],
datastyle = (args.datastyle or '') .. (args.datastyle and ';' or '') .. (args['data' .. tostring(num) .. 'style'] or ''),
datastyle = (args.datastyle or '') .. ';' .. (args['data' .. tostring(num) .. 'style'] or ''),
class = args['class' .. tostring(num)],
class = args['class' .. tostring(num)],
rowclass = args['rowclass' .. tostring(num)],
rowclass = args['rowclass' .. tostring(num)]
rowstyle = args['rowstyle' .. tostring(num)],
dataid = args['dataid' .. tostring(num)],
labelid = args['labelid' .. tostring(num)],
headerid = args['headerid' .. tostring(num)],
rowid = args['rowid' .. tostring(num)]
})
})
end
end
行 220: 行 205:
local function renderNavBar()
local function renderNavBar()
if not args.name then return end
if not args.name then return end
root
root
:tag('tr')
.tag('tr')
:tag('td')
.tag('td')
:attr('colspan', '2')
.attr('colspan', '2')
:css('text-align', 'right')
.css('text-align', 'right')
:wikitext(navbar{
.wikitext(mw.getCurrentFrame():expandTemplate({
args.name,
title = 'navbar',
mini = 1,
args = { args.name, mini = 1 }
})
}))
end
end


行 235: 行 220:
local italicTitle = args['italic title'] and mw.ustring.lower(args['italic title'])
local italicTitle = args['italic title'] and mw.ustring.lower(args['italic title'])
if italicTitle == '' or italicTitle == 'force' or italicTitle == 'yes' then
if italicTitle == '' or italicTitle == 'force' or italicTitle == 'yes' then
root:wikitext(mw.getCurrentFrame():expandTemplate({title = 'italic title'}))
root.wikitext(mw.getCurrentFrame():expandTemplate({title = 'italic title'}))
end
end
end
end
行 242: 行 227:
if args.decat ~= 'yes' then
if args.decat ~= 'yes' then
if #(getArgNums('data')) == 0 and mw.title.getCurrentTitle().namespace == 0 then
if #(getArgNums('data')) == 0 and mw.title.getCurrentTitle().namespace == 0 then
root:wikitext('[[Category:使用無數據行信息框模板的條目]]')
root.wikitext('[[Category:使用無數據行信息框模板的條目]]')
end
end
if args.child == 'yes' and args.title then
if args.child == 'yes' and args.title then
root:wikitext('[[Category:使用帶有標題參數的嵌入式信息框模板的條目]]')
root.wikitext('[[Category:使用帶有標題參數的嵌入式信息框模板的條目]]')
end
end
end
end
行 254: 行 239:
-- if the infobox is used as a 'child' inside another infobox.
-- if the infobox is used as a 'child' inside another infobox.
if args.child ~= 'yes' then
if args.child ~= 'yes' then
root = mw.html.create('table')
root = HtmlBuilder.create('table')

root
root
:addClass('infobox')
.addClass('infobox')
:addClass(args.bodyclass)
.addClass(args.bodyclass)
:attr('cellspacing', 3)
.attr('cellspacing', 3)
:css('border-spacing', '3px')
.css('border-spacing', '3px')

if args.subbox == 'yes' then
if args.subbox == 'yes' then
root
root
:css('padding', '0')
.css('padding', '0')
:css('border', 'none')
.css('border', 'none')
:css('margin', '-3px')
.css('margin', '-3px')
:css('width', 'auto')
.css('width', 'auto')
:css('min-width', '100%')
.css('min-width', '100%')
:css('font-size', 'small')
.css('font-size', 'small')
:css('clear', 'none')
.css('clear', 'none')
:css('float', 'none')
.css('float', 'none')
:css('background-color', 'transparent')
.css('background-color', 'transparent')
else
else
root
root
:css('width', '22em')
.css('width', '22em')
:css('text-align', 'left')
.css('text-align', 'left')
:css('font-size', 'small')
.css('font-size', 'small')
:css('line-height', '1.5em')
.css('line-height', '1.5em')
end
end
root
root
:cssText(args.bodystyle)
.cssText(args.bodystyle)

renderTitle()
renderTitle()
renderAboveRow()
renderAboveRow()
else
else
root = mw.html.create()
root = HtmlBuilder.create()

root
root
:wikitext(args.title)
.wikitext(args.title)
end
end


renderOverImage()
renderOverImage()
renderSubheaders()
renderSubheaders()
renderImages()
renderImages()
行 300: 行 285:
renderItalicTitle()
renderItalicTitle()
renderTrackingCategories()
renderTrackingCategories()

return tostring(root)
return tostring(root)
end
end
行 325: 行 310:
error("Invalid step value detected", 2)
error("Invalid step value detected", 2)
end
end

-- Get arguments without a number suffix, and check for bad input.
-- Get arguments without a number suffix, and check for bad input.
for i,v in ipairs(prefixTable) do
for i,v in ipairs(prefixTable) do
行 334: 行 319:
-- Only parse the depend parameter if the prefix parameter is present and not blank.
-- Only parse the depend parameter if the prefix parameter is present and not blank.
if args[v.prefix] and v.depend then
if args[v.prefix] and v.depend then
for j, dependValue in ipairs(v.depend) do
for j,dependValue in ipairs(v.depend) do
if type(dependValue) ~= 'string' then
if type(dependValue) ~= 'string' then
error('Invalid "depend" parameter value detected in preprocessArgs')
error('Invalid "depend" parameter value detected in preprocessArgs')
行 388: 行 373:
end
end
end
end

function p.infobox(frame)
function p.infobox(frame)
-- If called via #invoke, use the args passed into the invoking template.
-- If called via #invoke, use the args passed into the invoking template.
行 397: 行 382:
origArgs = frame
origArgs = frame
end
end

-- Parse the data parameters in the same order that the old {{infobox}} did, so that
-- Parse the data parameters in the same order that the old {{infobox}} did, so that
-- references etc. will display in the expected places. Parameters that depend on
-- references etc. will display in the expected places. Parameters that depend on
行 415: 行 400:
preprocessSingleArg('aboveclass')
preprocessSingleArg('aboveclass')
preprocessSingleArg('abovestyle')
preprocessSingleArg('abovestyle')
preprocessSingleArg('aboverowclass')
preprocessArgs({
preprocessArgs({
{prefix = 'subheader', depend = {'subheaderstyle', 'subheaderrowclass'}}
{prefix = 'subheader', depend = {'subheaderstyle', 'subheaderrowclass'}}
行 430: 行 416:
{prefix = 'data', depend = {'label'}},
{prefix = 'data', depend = {'label'}},
{prefix = 'rowclass'},
{prefix = 'rowclass'},
{prefix = 'rowstyle'},
{prefix = 'class'}
{prefix = 'class'},
{prefix = 'dataid'},
{prefix = 'labelid'},
{prefix = 'headerid'},
{prefix = 'rowid'}
}, 80)
}, 80)
preprocessSpecificStyle({
preprocessSpecificStyle({
行 442: 行 423:
{arg = 'data'}
{arg = 'data'}
}, 80)
}, 80)
preprocessSingleArg('headerclass')
preprocessSingleArg('headerstyle')
preprocessSingleArg('headerstyle')
preprocessSingleArg('labelstyle')
preprocessSingleArg('labelstyle')
行 452: 行 432:
args['italic title'] = origArgs['italic title'] -- different behaviour if blank or absent
args['italic title'] = origArgs['italic title'] -- different behaviour if blank or absent
preprocessSingleArg('decat')
preprocessSingleArg('decat')

return _infobox()
return _infobox()
end
end

return p
return p
BYCC3.0SA 點擊“儲存頁面”按鈕後,表示您同意我們的使用條款。
同時您同意依據CC-BY-SA-3.0授權您的貢獻,並在CC BY-SA 3.0的條款下以超鏈接或URL的方式進行署名。
取消 編輯說明(在新視窗開啟)
使用此模板預覽頁面

· “” ‘’ 「」 『』 () —— …… 《》 〈〉 【】 〖〗 〔〕

<> [[Commons:]] [[m:]] [[n:]] [[q:]] [[s:]] [[b:]] [[Wikt:]] · <nowiki></nowiki> <noinclude></noinclude> <includeonly></includeonly> <onlyinclude></onlyinclude> -R|{}- {{{}}} · {{subst:}} {{SERVER}}{{localurl:}} {{fullurl:}} {{FULLPAGENAME}} {{PAGENAME}} {{DEFAULTSORT:}} · {{#expr:}} {{#if:}} {{#ifeq:}} {{#ifexpr:}} {{#switch:}} {{#ifexist:}} {{#time:Y年Fj日 H:i|}} {{#language:}} ~~~ ~~~~ ~~~~~

ā á ǎ à · ō ó ǒ ò · ē é ě è · ī í ǐ ì · ū ú ǔ ù · ü ǖ ǘ ǚ ǜ · ê ê̄ ế ê̌ · Ā Á Ǎ À · Ō Ó Ǒ Ò · Ē É Ě È

· ˉ ˊ ˇ ˋ ˙

° ¥ £ ¤ © ® ·

· ·
·

< > ° · × ÷ ± · ¼ ½ ¾ ¹ ² ³ ° · · · · ¬ ·

<math></math> 簡單: ^{} · _{} · \sqrt[]{} · \frac{}{} · \int_{}^{} · \lim_{\rightarrow} · \sum_{=}^{}
標準功能: \sin{} \cos{} \tan{} · \cot{} \sec{} \csc{} · \exp{} \ln{} \log{} · \sinh{} \cosh{} \tanh{} \coth{} · \arcsin{} \arccos{} \arctan{}
Diactritiques : \acute{} \breve{} \check{} \grave{} \tilde{}

· · · · · · · · · ·

· · · · · · · · · ·

此頁面使用了以下模板: