モジュールの解説[作成]

local p = {}--[[Template:Tnavbar]]function p.tnavbar(frame)local r = mw.html.create()--出力用local args = frame.argsif not args[1] then return '&nbsp;' endlocal function tf(x)return x == '1' and true or falseendargs.plain = tf(args.plain)args.div = tf(args.div)args.nodiv = tf(args.nodiv)args.mini = tf(args.mini)args.viewplain = tf(args.viewplain)args.fontstyle = args.fontcolor ~= '' and ((args.fontstyle or '') .. ';color:' .. args.fontcolor .. ';') or args.fontstyle or ''local divTag = r:tag('div'):addClass('noprint'):addClass('plainlinks'):addClass('navbar'):addClass('hlist'):css('white-space', 'nowrap'):css('font-size', '60%'):css('font-weight', 'normal')if args.nodiv thendivTag:css('display', 'inline'):css('padding', '0 0.5em')elsedivTag:css('background-color', 'transparent'):css('padding', '0'):css('color', '#000')enddivTag:cssText(args.fontstyle):cssText(args.style)if not (args.plain or args.mini or args.viewplain) thendivTag:tag('span'):css('font-size', '125%'):node('このテンプレートを:&nbsp;')endlocal disp = args.mini and {'表', '話', '編', '歴'} or {'表示', 'ノート', '編集', '履歴'}local ns = {'Template:', 'Template_talk:', 'Template:', 'Template:'}local query = {nil, nil, 'action=edit', 'action=history'}local title = {'このテンプレートを表示します', 'このテンプレートのトークを表示します', 'このテンプレートを編集します。保存の前にプレビューを忘れずに。', 'このテンプレートの過去の版を表示します'}local color = {'', 'color:#002bb8;', 'color:#002bb8;', 'color:#002bb8;'}local i = 0local i_end = args.viewplain and 1 or 4local ulTag = divTag:tag('ul'):css('display', 'inline')for i = 1, i_end dolocal liTag = ulTag:tag('li')local l = {open = '', link = '', close = ''}if query[i] thenl.open = '['l.link = tostring(mw.uri.canonicalUrl(ns[i] .. args[1], query[i])) .. ' 'l.close = ']'elsel.open = '[['l.link = ns[i] .. args[1] .. '|'l.close = ']]'endliTag:wikitext(l.open .. l.link):tag('span'):attr('title', title[i]):css('font-size', '125%'):cssText(color[i]):cssText(args.fontstyle):node(disp[i]):done():wikitext(l.close)endreturn tostring(r)end--[[Define Arguments]]local getArgslocal args = {}local borderlocal child, none = false, falselocal rowspan = 0local basestyle = ''local odd, even = 'odd', 'even'local list, liststyle = {}, {}local group, groupstyle = {}, {}local colheader, colheadercolspan, colheaderstyle = {}, {}, {}local col, colstyle, colwidth = {}, {}, {}local colfooter, colfootercolspan, colfooterstyle = {}, {}, {}local abbr, state = {}, {}local sect, section = {}, {}local secttitlestyle = {}local content, contentstyle = {}local image, imageleft = {}, {}local function defArgs(frame)if not getArgs thengetArgs = require('Module:Arguments').getArgsendargs = getArgs(frame, {parentOnly = true})border = args.border or args[1]child, none = (border == 'subgroup' or border == 'child'), (border == 'none')collapsible = (args.state == 'plain' or args.state == 'off') and '' or 'mw-collapsible 'if args.basestyle then basestyle = args.basestyle .. ';' endlocal sortable_mt = {__lt = function(a, b) return a.index < b.index end,__concat = function(a, b)local strA = (type(a) == 'table') and a.content or a or ''local strB = (type(b) == 'table') and b.content or b or ''return strA .. strBend}local function sortable_args(tbl, index, content)table.insert(tbl, {index = index, content = content})setmetatable(tbl[#tbl], sortable_mt)endlocal switch = {--commonlist = function(num, v) sortable_args(list, num, '\n' .. v) end,liststyle = function(num, v) liststyle[num] = v end,group = function(num, v) group[num] = v end,groupstyle = function(num, v) groupstyle[num] = v end,--for with_columnscolheader = function(num,v) colheader[num] = v end,colheadercolspan = function(num,v) colheadercolspan[num] = v end,colheaderstyle = function(num,v) colheaderstyle[num] = v end,col = function(num, v) sortable_args(col, num, '\n' .. v) end,colstyle = function(num,v) colstyle[num] = v end,colwidth = function(num,v) colwidth[num] = v end,colfooter = function(num,v) colfooter[num] = v end,colfootercolspan = function(num,v) colfootercolspan[num] = v end,colfooterstyle = function(num,v) colfooterstyle[num] = v end,--for with_collapsible_groupsabbr = function(num, v) abbr[num] = v end,state = function(num, v) state[num] = v end,sect = function(num, v) group[num] = v end,section = function(num, v) group[num] = v end,secttitlestyle = function(num, v) groupstyle[num] = v end,content = function(num, v) sortable_args(content, num, '\n' .. v) end,contentstyle = function(num, v) liststyle[num] = v end,image = function(num, v) image[num] = v end,imageleft = function(num, v) imageleft[num] = v end,}for k, v in pairs(args) dolocal str1, num, str2 = string.match(k, '(%D+)(%d+)(%D*)')str1, num, str2 = str1 or '', tonumber(num), str2 or ''if switch[str1 .. str2] and num then switch[str1 .. str2](num, v) endendtable.sort(list)rowspan = #listend--[[top]]local function top(baseTag)local navlocal bodyTableif baseTag == nil or baseTag == '' thenbaseTag = mw.html.create()endif child thenbaseTag:wikitext('</div>')nav = baseTagelseif not none thennav = baseTag:tag('div'):addClass('navbox'):addClass(args.navboxclass):css('border-collapse', 'collapse'):cssText(args.bodystyle):cssText(args.style):css('padding', '3px')if args.title or args.above thennav:attr('aria-labelledby', mw.uri.anchorEncode(args.title or args.above))elsenav:attr('aria-label', 'Navbox')endelsenav = baseTagendbodyTable = nav:tag('table'):addClass('nowraplinks'):addClass(args.bodyclass)if args.title and (args.state ~= 'plain' and args.state ~= 'off') thenif args.state == 'collapsed' then args.state = 'mw-collapsed' endbodyTable:addClass('mw-collapsible'):addClass(args.state or 'autocollapse')endif child or border == 'none' thenbodyTable:addClass('navbox-subgroup'):cssText(args.bodystyle):cssText(args.style)else  -- regular navbox - bodystyle and style will be applied to the wrapper tablebodyTable:addClass('navbox-inner'):css('background', 'transparent'):css('color', 'inherit')endbodyTable:css('min-width', '100%'):css('border-spacing', '0px'):css('border-collapse', 'separate'):cssText(args.innerstyle)return baseTag, bodyTableend--[[title and navbar]]local function title(tbl)if not args.title then return tbl endlocal titleRow = tbl:tag('tr')if args.titlegroup thentitleRow:tag('th'):attr('scope', 'row'):addClass('navbox-group'):addClass(args.titlegroupclass):cssText(args.basestyle):cssText(args.groupstyle):cssText(args.titlegroupstyle):wikitext(args.titlegroup)endlocal titleCell = titleRow:tag('th'):attr('scope', 'col')if args.titlegroup thentitleCell:css('width', '100%')endlocal titleColspan = 2if args.imageleft then titleColspan = titleColspan + 1 endif args.image then titleColspan = titleColspan + 1 endif args.titlegroup then titleColspan = titleColspan - 1 endtitleCell:cssText(args.basestyle):cssText(args.titlestyle):addClass('navbox-title'):attr('colspan', titleColspan)if (args.navbar == 'plain') or (not args.name and (child or none)) thentitleCell:tag('div'):css('float', 'left'):css('width', '6em'):node('&nbsp;')elseif args.navbar ~= 'off' thenlocal tbl = {args = {args.name, mini = '1', fontstyle = basestyle .. (args.titlestyle or '') .. ';border:none;', fontcolor = ''}}titleCell:tag('div'):css('float', 'left'):css('width', '6em'):css('text-align', 'left'):node(p.tnavbar(tbl))endif child or border == 'none' thentitleCell:tag('div'):attr('id', mw.uri.anchorEncode(args.title)):addClass(args.titleclass):css('font-size', '100%'):css('margin', '0 6em'):node(args.title)elsetitleCell:tag('div'):attr('id', mw.uri.anchorEncode(args.title)):addClass(args.titleclass):css('font-size', '110%'):css('margin', '0 6em'):node(args.title)endreturn tblendlocal function getAboveBelowColspan()local ret = 2if args.imageleft then ret = ret + 1 endif args.image then ret = ret + 1 endreturn retend--[[above]]local function above(tbl)if not args.above then return tbl endtbl:tag('tr'):tag('td'):addClass('navbox-abovebelow'):addClass(args.aboveclass):cssText(args.basestyle):cssText(args.abovestyle):attr('colspan', getAboveBelowColspan()):newline():node(args.above)return tblend--[[body]]--first group/list and imageslocal function body1(tbl)local row = tbl:tag('tr')if args.imageleft thenrow:tag('td'):addClass('navbox-image'):addClass(args.imageclass):css('width', '1px'):css('padding', '0px 2px 0px 0px'):cssText(args.imageleftstyle):attr('rowspan', rowspan):tag('div'):node(args.imageleft)endlocal j = list[1].indexif group[j] thenlocal groupCell = row:tag('th')groupCell:attr('scope', 'row'):addClass('navbox-group'):addClass(args.groupclass):cssText(args.basestyle):css('width', args.groupwidth or '1%')groupCell:cssText(args.groupstyle):cssText(groupstyle[j]):wikitext(group[j])endlocal listCell = row:tag('td')if group[j] thenlistCell:css('text-align', 'left'):css('border-left-width', '2px'):css('border-left-style', 'solid')elselistCell:attr('colspan', 2)endif not args.groupwidth thenlistCell:css('width', '100%')endlocal rowstyleif odd == 'odd' thenrowstyle = args.oddstyleelserowstyle = args.evenstyleendlistCell:css('padding', '0px'):cssText(args.liststyle):cssText(rowstyle):cssText(liststyle[j]):addClass('navbox-list'):addClass('navbox-' .. (args.evenodd == 'swap' and even or args.evenodd or odd)):addClass(args.listclass):tag('div'):css('padding', (args.list1padding or args.listpadding or '0em 0.25em')):node(list[1].content):newline()if args.image thenrow:tag('td'):addClass('navbox-image'):addClass(args.imageclass):css('width', '1px'):css('padding', '0px 0px 0px 2px'):cssText(args.imagestyle):attr('rowspan', rowspan):tag('div'):node(args.image)endreturn tblend--remaining groups/listslocal function body2(tbl)for i = 2, #list doodd, even = even, oddlocal j = list[i].indexlocal row = tbl:tag('tr')if group[j] thenlocal groupCell = row:tag('th')groupCell:attr('scope', 'row'):addClass('navbox-group'):addClass(args.groupclass):cssText(args.basestyle):css('width', args.groupwidth or '1%')groupCell:cssText(args.groupstyle):cssText(groupstyle[j]):node(group[j])endlocal listCell = row:tag('td')if group[j] thenlistCell:css('text-align', 'left'):css('border-left-width', '2px'):css('border-left-style', 'solid')elselistCell:attr('colspan', 2)endif not args.groupwidth thenlistCell:css('width', '100%')endlocal rowstyleif odd == 'odd' thenrowstyle = args.oddstyleelserowstyle = args.evenstyleendlistCell:css('padding', '0px'):cssText(args.liststyle):cssText(rowstyle):cssText(liststyle[j]):addClass('navbox-list'):addClass('navbox-' .. (args.evenodd == 'swap' and even or args.evenodd or odd)):addClass(args.listclass):tag('div'):css('padding', (args.listpadding or '0em 0.25em')):node(list[i].content):newline()endreturn tblend--[[below]]local function below(tbl)if not args.below then return tbl endtbl:tag('tr'):tag('td'):addClass('navbox-abovebelow'):addClass(args.belowclass):cssText(args.basestyle):cssText(args.belowstyle):attr('colspan', getAboveBelowColspan()):newline():node(args.below)return tblend--[[Template:Navbox]]function p.navbox(frame)defArgs(frame)local reslocal firstTableTagres, firstTableTag = top()firstTableTag = title(firstTableTag)firstTableTag = above(firstTableTag)if list[1] thenfirstTableTag = body1(firstTableTag)endfirstTableTag = body2(firstTableTag)firstTableTag = below(firstTableTag)if child thenres:wikitext('<div>')endreturn tostring(res)end--[[Template:Navbox subgroup]]function p.subgroup(frame)defArgs(frame)if not border then child = true endargs.groupstyle = 'padding:' .. (args.grouppadding or '0 0.75em') .. ';' .. (args.groupstyle or '')local reslocal firstTableTagres, firstTableTag = top()firstTableTag = title(firstTableTag)firstTableTag = above(firstTableTag)if list[1] thenfirstTableTag = body1(firstTableTag)endfirstTableTag = body2(firstTableTag)firstTableTag = below(firstTableTag)if not border then res:wikitext('<div>') endreturn tostring(res)end--[[Template:Navbox with columns]]function p.with_columns(frame)defArgs(frame)table.sort(col)local reslocal firstTableTagres, firstTableTag = top()firstTableTag = title(firstTableTag)firstTableTag = above(firstTableTag)if col[1] thenlocal j = col[1].indexlocal cols = mw.html.create('table'):addClass('navbox-columns-table'):css('border-spacing', '0px'):css('border-collapse', 'separate'):css('text-align', 'left'):cssText((colheader[j] or args.fullwidth) and 'width:100%;' or 'margin:0 auto;'):cssText(args.coltablestyle)--Header rowif colheader[j] thenlocal headerRow = cols:tag('tr'):addClass('navbox-abovebelow'):css('font-weight', 'bold'):cssText(args.colheaderstyle)for i = 1, #col dolocal j = col[i].indexif colheader[j] thenheaderRow:tag('td'):attr('colspan', colheadercolspan[j] or '1'):cssText(colheaderstyle[j]):node(colheader[j])endendend--Main columnslocal row = cols:tag('tr'):css('vertical-align', 'top'):cssText(args.colstyle)if not (colheader[j] or colfooter[j] or args.fullwidth) thenlocal paddingoff = args.padding and string.find(args.padding, '^0[ep]?[mx]?%?;?')if not paddingoff thenrow:tag('td'):css('width', args.padding or '5em'):wikitext('&nbsp;&nbsp;&nbsp;')endendfor i = 1, #col dolocal j = col[i].indexrow:tag('td'):css('padding', '0'):cssText(args.oddcolstyle):cssText(colstyle[j]):css('width', colwidth[j] or args.colwidth or '10em'):node(col[i].content)args.oddcolstyle, args.evencolstyle = args.evencolstyle, args.oddcolstyleend--Footer rowif colfooter[j] thenrow = cols:tag('tr'):addClass('navbox-abovebelow'):css('font-weight', 'bold'):cssText(args.colfooterstyle)for i = 1, #col dolocal j = col[i].indexif colfooter[j] thenrow:tag('td'):attr('colspan', colfootercolspan[j] or '1'):cssText(colfooterstyle[j]):node(colfooter[j])endendendcols = mw.html.create():wikitext('</div>'):wikitext(tostring(cols)):wikitext('<div>')table.insert(list, {index=1, content=cols})rowspan = rowspan + 1endfirstTableTag = body1(firstTableTag)firstTableTag = body2(firstTableTag)firstTableTag = below(firstTableTag)return tostring(res)end--[[Template:Navbox with collapsible groups]]function p.with_collapsible_groups(frame)local reslocal firstTableTagdefArgs(frame)table.sort(content)res, firstTableTag = top()firstTableTag = title(firstTableTag)firstTableTag = above(firstTableTag)local i = 1local function funcList(rowTag)list[i] = list[i] or content[i]local j = list[i].indexargs.state = state[j] or args.selected and (args.selected == abbr[j] or args.selected == group[j]) and '' or 'mw-collapsed'args.name = nilargs.titlestyle = basestyle .. (args.groupstyle or '') .. ';' .. (args.secttitlestyle or '') .. ';' .. (groupstyle[j] or '')args.liststyle = (args.liststyle or '') .. ';' .. (args.contentstyle or '') .. ';' .. (liststyle[j] or '')args.title, group[j] = group[j], nilargs.image = image[j]args.imageleft = imageleft[j]rowspan = 1local baseTag = rowTag:tag('td'):cssText(args.groupwidth and '' or 'width:100%;'):css('padding', '0px'):cssText(args.liststyle):cssText(odd == 'odd' and (args.oddstyle or '') or (args.evenstyle or '')):cssText(liststyle[j]):addClass('navbox-list'):addClass('navbox-' .. (args.evenodd == 'swap' and even or args.evenodd or odd)):addClass(args.listclass):tag('div')if args.title thenlocal tableTagnone = truebaseTag, tableTag = top(baseTag)tableTag = title(tableTag)tableTag = body1(tableTag)      if child then        baseTag:wikitext('<div>')      endelsebaseTag:node(list[i].content)endend--i = 1local row = firstTableTag:tag('tr')if args.imageleft thenrow:tag('td'):addClass('navbox-image'):addClass(args.imageclass):css('width', '0'):css('padding', '0 2px 0 0'):cssText(args.imageleftstyle):attr('rowspan', rowspan):node(args.imageleft)endfuncList(row)if args.image thenrow:tag('td'):css('width', '0%'):css('padding', '0 0 0 2px'):cssText(args.imagestyle):attr('rowspan', rowspan):node(args.image)end--i > 2for i = 2, #list dorow = firstTableTag:tag('tr')list[1] = list[i]funcList(row)endfirstTableTag = below(firstTableTag)  if child thenres:wikitext('<div>')endchild, none = (border == 'subgroup' or border == 'child'), (border == 'none') --再定義return tostring(res)end--[[Template:NavboxYearsTemplate:NavboxYears2]]local function calc_years(args, fmtLink)local numtab = tonumber(args.tab) or 0local numstart = tonumber(args.start)local numend = tonumber(args['end'])local numstep = tonumber(args.step) or 1if numstart and numend thenif numtab > 0 thenfor i = 2, numtab + 1 doargs[i] = nilendendlocal numD = numend - numstart + 1for i = 1, numD, numstep doargs[i + numtab + 1] = numstart + i - 1endendlocal res = mw.html.create('table')res:css('width', '100%'):css('border-spacing', '0px'):css('border-collapse', 'separate'):css('text-align', 'center')local h = 1repeath = h + 1local row = res:tag('tr')for i = 2, 11 dolocal tdTag = row:tag('td'):css('width', '10%')if (tonumber(args[i]) or -1) > 0 thentdTag:wikitext('[[' .. fmtLink(args[1], args[i]) .. '|' .. args[i] .. ']]')elsetdTag:wikitext(args[i])endargs[i], args[i + 10] = args[i + 10], args[i + h * 10]enduntil not args[2]return tostring(res)endlocal function years(frame, fmtLink)defArgs(frame)if args.var then fmtLink = function(str, num) return str:gsub(args.var, num) end endif args.name thenargs.style = 'width:' .. (args.width or '38em') .. ';' .. (args.style or '')local reslocal firstTableTagres, firstTableTag = top()if args.title then firstTableTag = title(firstTableTag)endif args.above thenfirstTableTag = above(firstTableTag)endif not list[1] and args[1] then list[1] = {index = 1, content = calc_years(args, fmtLink)} endif list[1] thenfirstTableTag = body1(firstTableTag)endfirstTableTag = body2(firstTableTag)if args.below thenfirstTableTag = below(firstTableTag)endreturn tostring(res)elsereturn calc_years(args, fmtLink)endendfunction p.years(frame)local fmtLink = function(str, num) return str .. num endreturn years(frame, fmtLink)endfunction p.years2(frame)local fmtLink = function(str, num) return num .. str endreturn years(frame, fmtLink)endreturn p
🔥 Popular: メインページ特別:最近の更新特別:検索ニャチャンWiki Travel:サンドボックスアルプ=マリティーム県Wiki Travel:水茶屋カトヴィツェ利用者:水戸特快北京チュイルノート:ディズニーランド静岡市ヘルプ:目次オーストラリアテンプレート:同一地名横浜 (曖昧さ回避)アジア東京ディズニーシーモジュール:VCard/Subtypes利用者:ChqazWiki Travel:管理者伝言板バルカン半島インドネシア語会話集中央アジア太田市利用者:Chqaz/common.jsモジュール:Marker utilities/i18n/docWiki Travel:お知らせノート:聖地巡礼利用者:Chqaz/Script/DisamAssist.jsモジュール:Marker utilities/Types北アメリカ南アメリカ利用者・ノート:Araisyohei大子町Wiki Travel:免責事項ホーチミン市東南アジアインドネシアモジュール:Marker utilities/i18nアイヌ語会話集聖地巡礼/ゆるキャン△Wiki Travel:コミュニティ・ポータルアメリカWiki Travel:管理者東京都イギリスモジュール:Hours/i18nバルト三国利用者:Tmv/メインページ地図中部地方会話集新潟市テンプレート:利用者 ain-1香港ヘルプ:アカウントの作り方北極圏ディズニーランドテンプレート:サンドボックススターラヤ・ルーサ日本の鉄道旅行ドネツク人民共和国原爆ドームイタリア半島Wiki Travel:おすすめの旅行先Wiki Travel:ウィキボヤージュとは姫路城イリノイ州東アジアニューヨーク州ヘルプ:脚注利用者・ノート:職員室モジュール:VCard/i18n南牧村サヘル地域利用者・ノート:2023年に作成したアカウントバヌアツ