모듈:Navbox: 두 판 사이의 차이

잔글편집 요약 없음
잔글 ((포켓몬위키))
 
(같은 사용자의 중간 판 하나는 보이지 않습니다)
1번째 줄: 1번째 줄:
--
--[[
-- This module implements {{Navbox}}
Navbox Module
-- 이 모듈은 {{둘러보기 상자}}의 구현에 사용됩니다
--


local p = {}
* Fully CSS styled (inline styles possible but not default)
* Supports unlimited rows


local navbar = require('Module:Navbar')._navbar
by User:Tjcool007
local getArgs -- lazily initialized
http://layton.wikia.com/wiki/Module:Navbox


local args
Next changes are applied by User:Cafeinlove:
local border
* Parameter names are translated into Korean.
local listnums
* CSS class names reflect BEM rules
local ODD_EVEN_MARKER = '\127_ODDEVEN_\127'
* Parameters `name`, `border` are removed.
local RESTART_MARKER = '\127_ODDEVEN0_\127'
* VDE linkset no more requires Template:Vdelinks. It is generated out of
local REGEX_MARKER = '\127_ODDEVEN(%d?)_\127'
  `참조` argument, and the links color is customizable via `참조색` argument.
 
* Parameters related to alternative group/list have been removed.
local function striped(wikitext)
  Instead, parameters for individual cells such as
-- Return wikitext with markers replaced for odd/even striping.
  `제목클래스n`, `제목모양n`, `내용클래스n`, `내용모양n` are introduced.
-- Child (subgroup) navboxes are flagged with a category that is removed
* List items are separated by a middot(plain text) instead of CSS pseudo.
-- by parent navboxes. The result is that the category shows all pages
* List parameter accepts both list items and non-list items.
-- where a child navbox is not contained in a parent navbox.
* Class `navbox__title` is assigned to `th` element instead of `tr` element.
local orphanCat = '[[분류:외톨이 둘러보기 상자]]'
]]
if border == 'subgroup' and args.orphan ~= 'yes' then
-- No change; striping occurs in outermost navbox.
local p = {}
return wikitext .. orphanCat
end
-- Default config. Values will be replaced with
local first, second = 'odd', 'even'
-- proprecessed arguments passed to template
if args.evenodd then
local args = {}
if args.evenodd == 'swap' then
local navbox -- Actual navbox
first, second = second, first
else
local rownums, skiprows = {}, {}
first = args.evenodd
local alt, hasrows, hasData, isChild = false, false, false, false
second = first
local activeSection, sections, cimage, cimageleft
end
local colspan, rowspan
end
local changer
local showText, hideText = '보이기', '숨기기'
if first == second then
changer = first
------------------------------------------------
else
-- Title
local index = 0
------------------------------------------------
changer = function (code)
if code == '0' then
--- Processes the VDE links in the title
-- Current occurrence is for a group before a nested table.
--
-- Set it to first as a valid although pointless class.
-- @param titlecell The table cell of the title
-- The next occurrence will be the first row after a title
local function processVde( titlecell )
-- in a subgroup and will also be first.
    if not args['참조'] then return end
index = 0
return first
    local vde = { '보기', '토론', '편집' }
end
    local vdeLinks = {}
index = index + 1
    local link, ns, fullurl
return index % 2 == 1 and first or second
    local page = args['참조']
end
    local color = args['참조색'] or '#111'
end
local regex = orphanCat:gsub('([%[%]])', '%%%1')
    for k, v in pairs(vde) do
return (wikitext:gsub(regex, ''):gsub(REGEX_MARKER, changer)) -- () omits gsub count
        ns = '틀'
        if v ~= '편집' then
            if v == '토론' then ns = '틀토론' end
            link = '[[' .. ns .. ':'.. page .. '|<span style="color:' .. color .. ';">' .. v .. '</span>]]'
        else
            fullurl = mw.uri.fullUrl( ns .. ':' .. page, 'action=edit')
            link = '[' .. tostring(fullurl) .. ' <span style="color:' .. color .. ';">' .. v .. '</span>]'
        end
        table.insert(vdeLinks, link)
    end
    titlecell
        :tag('span')
            :addClass('navbox__vde')
            :wikitext( table.concat(vdeLinks, ' &#5867; ') )
end
end
 
local function processItem(item, nowrapitems)
--- Processes the main title row
if item:sub(1, 2) == '{|' then
local function processTitle()
-- Applying nowrap to lines in a table does not make sense.
    local titlerow = mw.html.create('tr')
-- Add newlines to compensate for trim of x in |parm=x in a template.
    local titlecell = mw.html.create('th'):addClass('navbox__title'):attr('colspan',colspan):attr('scope','col')
return '\n' .. item ..'\n'
end
    processVde( titlecell )
if nowrapitems == 'yes' then
local lines = {}
    titlecell:wikitext( args['큰제목'] or '&nbsp;' )
for line in (item .. '\n'):gmatch('([^\n]*)\n') do
local prefix, content = line:match('^([*:;#]+)%s*(.*)')
    if args['큰제목클래스'] then titlerow:addClass( args['큰제목클래스'] ) end
if prefix and not content:match('^<span class="nowrap">') then
    if args['큰제목모양'] then titlecell:cssText( args['큰제목모양'] ) end
line = prefix .. '<span class="nowrap">' .. content .. '</span>'
end
    titlerow:node( titlecell )
table.insert(lines, line)
    navbox:node( titlerow )
end
item = table.concat(lines, '\n')
end
if item:match('^[*:;#]') then
return '\n' .. item ..'\n'
end
return item
end
end
 
local function renderNavBar(titleCell)
local function _addGutter( parent, incRowspan )
 
    parent:tag('tr'):addClass('navbox__gutter'):tag('td'):attr('colspan',2)
if args.navbar ~= 'off' and args.navbar ~= 'plain' and not (not args.name and mw.getCurrentFrame():getParent():getTitle():gsub('/연습장$', '') == '틀:둘러보기 상자') then
titleCell:wikitext(navbar{
    if incRowspan then
args.name,
        rowspan = rowspan + 1
mini = 1,
    end
fontstyle = (args.basestyle or '') .. ';' .. (args.titlestyle or '') .. ';background:none transparent;border:none;-moz-box-shadow:none;-webkit-box-shadow:none;box-shadow:none; padding:0;'
})
end
 
end
end
 
--
------------------------------------------------
--   Title row
-- Above/Below
------------------------------------------------
--- Processes the above and below rows
--
--
local function renderTitleRow(tbl)
-- @param rowtype Either 'above' or 'below'
if not args.title then return end
local function processAboveBelow( rowtype, prefix )
 
    if not args[rowtype .. '글'] then return end
local titleRow = tbl:tag('tr')
 
    local abrow = mw.html.create('tr'):addClass('navbox__'..rowtype)
if args.titlegroup then
    local abcell = mw.html.create('td'):attr('colspan',colspan):wikitext( args[rowtype .. ''] )
titleRow
:tag('th')
    if args[rowtype .. '클래스'] then abrow:addClass( args[rowtype .. '클래스'] ) end
:attr('scope', 'row')
    if args[rowtype .. '모양'] then abcell:cssText( args[rowtype .. '모양'] ) end
:addClass('navbox-group')
:addClass(args.titlegroupclass)
    abrow:node( abcell )
:cssText(args.basestyle)
    _addGutter( navbox )
:cssText(args.groupstyle)
    navbox:node( abrow )
:cssText(args.titlegroupstyle)
:wikitext(args.titlegroup)
end
 
local titleCell = titleRow:tag('th'):attr('scope', 'col')
 
if args.titlegroup then
titleCell
:css('border-left', '2px solid #fdfdfd')
:css('width', '100%')
end
 
local titleColspan = 2
if args.imageleft then titleColspan = titleColspan + 1 end
if args.image then titleColspan = titleColspan + 1 end
if args.titlegroup then titleColspan = titleColspan - 1 end
 
titleCell
:cssText(args.basestyle)
:cssText(args.titlestyle)
:addClass('navbox-title')
:attr('colspan', titleColspan)
 
renderNavBar(titleCell)
 
titleCell
:tag('div')
-- id for aria-labelledby attribute
:attr('id', mw.uri.anchorEncode(args.title))
:addClass(args.titleclass)
:css('font-size', '114%')
:css('margin', '0 4em')
:wikitext(processItem(args.title))
end
end
 
--
------------------------------------------------
--   Above/Below rows
-- Main Rows
--
------------------------------------------------
 
local function getAboveBelowColspan()
--- Processes the images
local ret = 2
local function _processImage(row, imgtype)
if args.imageleft then ret = ret + 1 end
    if not args[imgtype] then return end
if args.image then ret = ret + 1 end
return ret
    local iclass = imgtype == '그림' and 'navbox__image--right' or 'navbox__image--left'
    local imagecell = mw.html.create('td'):addClass('navbox__image'):addClass(iclass)
    local image = args[imgtype]
    if image:sub(1,1) ~= '[' then
        local width = args[imgtype .. '너비'] or '100px'
        imagecell:css('width',width):wikitext('[[' .. image  .. '|' .. width .. '|link=' .. (args[imgtype .. '링크'] or '') .. ']]')
    else
        imagecell:css('width','0%'):wikitext(image)
    end
    if args[imgtype .. '클래스'] then imagecell:addClass( args[imgtype .. '클래스'] ) end
    if args[imgtype .. '모양'] then imagecell:cssText( args[imgtype .. '모양'] ) end
    row:node( imagecell )
    if imgtype == '그림' then
        cimage = imagecell
    else
        cimageleft = imagecell
    end
end
end
 
local function renderAboveRow(tbl)
--- Closes the currently active section (if any)
if not args.above then return end
local function _closeCurrentSection()
 
    if not activeSection then return end
tbl:tag('tr')
:tag('td')
    local row = mw.html.create('tr'):addClass('navbox__section-row')
:addClass('navbox-abovebelow')
    local cell = mw.html.create('td'):attr('colspan',2)
:addClass(args.aboveclass)
:cssText(args.basestyle)
    if not hasrows then
:cssText(args.abovestyle)
        _processImage(row,'왼쪽그림')
:attr('colspan', getAboveBelowColspan())
    end
:tag('div')
-- id for aria-labelledby attribute, if no title
    cell:node(sections[activeSection])
:attr('id', args.title and nil or mw.uri.anchorEncode(args.above))
    row:node(cell)
:wikitext(processItem(args.above, args.nowrapitems))
    local firstRow = false
    if not hasrows then
        firstRow = true
        hasrows = true
        _processImage(row,'그림')
    end
    _addGutter(navbox,not firstRow)
    navbox:node(row)  
    rowspan = rowspan + 1
    activeSection = false
    hasData = false
end
end
 
local function renderBelowRow(tbl)
--- Handles alternating rows
if not args.below then return end
--
 
-- @return Alternatingly returns true or false. Always returns false if alternating rows
tbl:tag('tr')
--        are disabled with "alternaterows = no"
:tag('td')
local function _alternateRow()
:addClass('navbox-abovebelow')
    if args['색교차'] == 'no' then return false end
:addClass(args.belowclass)
:cssText(args.basestyle)
    if alt then
:cssText(args.belowstyle)
        alt = false
:attr('colspan', getAboveBelowColspan())
        return true
:tag('div')
    else
:wikitext(processItem(args.below, args.nowrapitems))
        alt = true
        return false
    end
end
end
 
--- Process a single Header "row"
--
--
--   List rows
-- @param num Number of the row to be processed
--
local function processHeader(num)
local function renderListRow(tbl, index, listnum)
    if not args['작은제목'..num] then return end
local row = tbl:tag('tr')
 
    _closeCurrentSection()
if index == 1 and args.imageleft then
row
    local subtable = mw.html.create('table'):addClass('navbox__section')
:tag('td')
    local headerrow = mw.html.create('tr')
:addClass('navbox-image')
    local header = mw.html.create('th'):addClass('navbox__header'):attr('colspan',2):attr('scope','col'):wikitext( args['작은제목'..num] )
:addClass(args.imageclass)
:css('width', '1px')              -- Minimize width
    local collapseme = args['작은제목상태'..num] or false
:css('padding', '0px 2px 0px 0px')
    local state = false
:cssText(args.imageleftstyle)
:attr('rowspan', #listnums)
    if collapseme then
:tag('div')
        -- Look at this one
:wikitext(processItem(args.imageleft))
        if collapseme ~= 'plain' then
end
            state = collapseme == 'expanded' and 'expanded' or 'collapsed'
 
        end
if args['group' .. listnum] then
    else
local groupCell = row:tag('th')
        -- Look at default
 
        local collapseall = args['작은제목기본상태'] or false
-- id for aria-labelledby attribute, if lone group with no title or above
        if collapseall then
if listnum == 1 and not (args.title or args.above or args.group2) then
            state = collapseall == 'expanded' and 'expanded' or 'collapsed'  
groupCell
        end
:attr('id', mw.uri.anchorEncode(args.group1))
    end
end
 
    if state then
groupCell
        subtable:addClass('mw-collapsible'):attr('data-expandtext',showText):attr('data-collapsetext',hideText)
:attr('scope', 'row')
        if state == 'collapsed' then
:addClass('navbox-group')
            subtable:addClass('mw-collapsed')  
:addClass(args.groupclass)
        end
:cssText(args.basestyle)
    end
:css('width', args.groupwidth or '1%') -- If groupwidth not specified, minimize width
 
    if args['작은제목클래스'] then headerrow:addClass( args['작은제목클래스'] ) end
groupCell
    if args['작은제목모양'] then header:cssText( args['작은제목모양'] ) end
:cssText(args.groupstyle)
:cssText(args['group' .. listnum .. 'style'])
    headerrow:node(header)
:wikitext(args['group' .. listnum])
    subtable:node(headerrow)
end
 
    sections[num] = subtable
local listCell = row:tag('td')
    activeSection = num
 
if args['group' .. listnum] then
listCell
:css('text-align', 'left')
:css('border-left-width', '2px')
:css('border-left-style', 'solid')
else
listCell:attr('colspan', 2)
end
 
if not args.groupwidth then
listCell:css('width', '100%')
end
 
local rowstyle  -- usually nil so cssText(rowstyle) usually adds nothing
if index % 2 == 1 then
rowstyle = args.oddstyle
else
rowstyle = args.evenstyle
end
 
local listText = args['list' .. listnum]
local oddEven = ODD_EVEN_MARKER
if listText:sub(1, 12) == '</div><table' then
-- Assume list text is for a subgroup navbox so no automatic striping for this row.
oddEven = listText:find('<th[^>]*"navbox%-title"') and RESTART_MARKER or 'odd'
end
listCell
:css('padding', '0px')
:cssText(args.liststyle)
:cssText(rowstyle)
:cssText(args['list' .. listnum .. 'style'])
:addClass('navbox-list')
:addClass('navbox-' .. oddEven)
:addClass(args.listclass)
:addClass(args['list' .. listnum .. 'class'])
:tag('div')
:css('padding', (index == 1 and args.list1padding) or args.listpadding or '0em 0.25em')
:wikitext(processItem(listText, args.nowrapitems))
 
if index == 1 and args.image then
row
:tag('td')
:addClass('navbox-image')
:addClass(args.imageclass)
:css('width', '1px')              -- Minimize width
:css('padding', '0px 0px 0px 2px')
:cssText(args.imagestyle)
:attr('rowspan', #listnums)
:tag('div')
:wikitext(processItem(args.image))
end
end
end
 
 
--- Processes a single list row
--
--   Tracking categories
--
--
-- @param num Number of the row to be processed
local function processList(num)
    if not args['내용'..num] then return end
    local row = mw.html.create('tr'):addClass('navbox__row')
    if not hasrows and not activeSection then
        _processImage(row, '왼쪽그림')
    end
    local listcell = mw.html.create('td'):addClass('navbox__list')


local function needsHorizontalLists()
    local data = args['내용'..num]
if border == 'subgroup' or args.tracking == 'no' then
    local listTable = {}
return false
    local list = ''
end
    local separator = ' '
local listClasses = {
['plainlist'] = true, ['hlist'] = true, ['hlist hnum'] = true,
['hlist hwrap'] = true, ['hlist vcard'] = true, ['vcard hlist'] = true,
['hlist vevent'] = true,
}
return not (listClasses[args.listclass] or listClasses[args.bodyclass])
end


local function hasBackgroundColors()
    local function forwardJoined(str, tbl, sep)
for _, key in ipairs({'titlestyle', 'groupstyle', 'basestyle', 'abovestyle', 'belowstyle'}) do
        local joined = table.concat(tbl, sep)
if tostring(args[key]):find('background', 1, true) then
        for i = 0, #tbl do tbl[i] = nil end -- empty tbl
return true
        return str .. joined
end
    end
end
end


local function hasBorders()
    local function appendWrapped(str, item, patt)
for _, key in ipairs({'groupstyle', 'basestyle', 'abovestyle', 'belowstyle'}) do
        return str .. string.format(patt, item)
if tostring(args[key]):find('border', 1, true) then
    end
return true
end
end
end


local function isIllegible()
    for line in data:gmatch('[^\r\n]+') do -- get line by line
local styleratio = require('Module:Color contrast')._styleratio
        if string.len(line) == 0 then break end


for key, style in pairs(args) do
        if line:sub(1, 2) == '* ' then -- line starting with '* '
if tostring(key):match("style$") then
            table.insert(listTable, line:sub(3))
if styleratio{mw.text.unstripNoWiki(style)} < 4.5 then
        else -- other lines
return true
            if #listTable ~= 0 then
end
                list = forwardJoined(list, listTable, separator)
end
            end
end
            list = appendWrapped(list, line, '<div>%s</div>')
return false
        end
    end
    list = forwardJoined(list, listTable, separator)
    listcell:wikitext( list )
    local altRow = _alternateRow()
    if altRow then row:addClass( 'alt' ) end -- 홀수 행
    if args['모든내용클래스'] then listcell:addClass( args['모든내용클래스'] ) end
    if args['모든내용모양'] then listcell:cssText( args['모든내용모양'] ) end
    local listclass = args['내용클래스'..num] or false
    if listclass then listcell:addClass( listclass ) end
    local liststyle = args['내용모양'..num] or false
    if liststyle then listcell:cssText( liststyle ) end
    if args['제목'..num] then
        local groupcell = mw.html.create('th'):addClass('navbox__group'):attr('scope','row'):wikitext( args['제목'..num] )
        if args['모든제목클래스'] then groupcell:addClass( args['모든제목클래스'] ) end
        if args['모든제목모양'] then groupcell:cssText( args['모든제목모양'] ) end
        local groupclass = args['제목클래스'..num] or false
        if groupclass then groupcell:addClass( groupclass ) end
        local groupstyle = args['제목모양'..num] or false
        if groupstyle then groupcell:cssText( groupstyle ) end
        row:node( groupcell )
    else
        listcell:attr('colspan',2):addClass('no-group')
    end
    row:node( listcell )
    local firstRow = false
    if not hasrows and not activeSection then
        firstRow = true
        hasrows = true
        _processImage(row, '그림')
    end
    if activeSection then
        local parent = sections[activeSection]
        if not isChild or not firstRow then
            _addGutter(parent)
        end
        parent:node(row)
        hasData = true
    else
        if not isChild or not firstRow then
            _addGutter(navbox,not firstRow)
        end
        navbox:node( row )
        rowspan = rowspan + 1
    end
end
end
 
local function getTrackingCategories()
--- Processes all rows
local cats = {}
local function processRows()
if needsHorizontalLists() then table.insert(cats, '가로 목록을 지원하지 않는 둘러보기 상자') end
    sections = {}
if hasBackgroundColors() then table.insert(cats, '배경색을 이용하는 둘러보기 상자') end
    for i=1,#rownums do
if isIllegible() then table.insert(cats, '잠재적 문제가 있는 둘러보기 상자') end
        local num = rownums[i]
if hasBorders() then table.insert(cats, '테두리를 사용하는 둘러보기 상자') end
        if not skiprows[num] then
return cats
            processHeader(num)
            processList(num)
        end
    end
    _closeCurrentSection()
    if cimageleft then
        cimageleft:attr('rowspan',rowspan)    
    end
    if cimage then
        cimage:attr('rowspan',rowspan)
    end
end
end
 
local function renderTrackingCategories(builder)
------------------------------------------------
local title = mw.title.getCurrentTitle()
-- ARGUMENTS PREPROCESSOR
if title.namespace ~= 10 then return end -- not in template space
-- * Extracts arguments from frame and stores them in args table
local subpage = title.subpageText
-- * At the same time, checks for valid row numbers
if subpage == '설명문서' or subpage == '연습장' or subpage == '시험장' then return end
------------------------------------------------
 
for _, cat in ipairs(getTrackingCategories()) do
--- Preprocessor for the arguments.
builder:wikitext('[[분류:' .. cat .. ']]')
-- Will fill up the args table with the parameters from the frame grouped by their type.
end
--
-- @param frame The frame passed to the Module.
local function preProcessArgs(frame)
    local tmp = {}
    if frame == mw.getCurrentFrame() then
        tmp = frame:getParent().args
    else
        tmp = frame
    end
    -- Storage tables
    local nums = {}
    -- Loop over all the args
    for k,v in pairs(tmp) do
        -- Skip empty args, which are useless
        if v ~= '' then
            local cat,num = tostring(k):match('^(.-)([1-9]%d*)$')
            if cat == '제목' or cat == '내용' then
                nums[num] = true
            end
            args[k] = v -- Simple copy
        end
    end
    colspan = args['그림'] and 3 or 2
    if args['왼쪽그림'] then colspan = colspan + 1 end
    rowspan = 0
    if args['색교차'] == '반전' then alt = true end
    for k, v in pairs(nums) do
        table.insert(rownums, tonumber(k))
    end
    table.sort(rownums)
    -- Calculate skip rows
    local cSection, cSkip
    local showall = args['상태']
    for i = 1, #rownums do
        local num = rownums[i]
        if args['작은제목'..num] then
            cSection = true
            cSkip = false
            local showme = args['작은제목상태'..num]
            if showme == hideText then
                cSkip = true
            elseif showme == '자동' or (showme ~= showText and showall ~= showText) then
                if not args['내용'..num] then
                    local nextNum = rownums[i+1]
                    cSkip = not nextNum or args['작은제목'..nextNum] -- If next has a header -> skip
                end
            end
        end
        if cSection and cSkip then
            skiprows[num] = true
        end
    end
end
end
 
------------------------------------------------
-- MAIN FUNCTIONS
------------------------------------------------
--- Processes the arguments to create the navbox.
--
--
--   Main navbox tables
-- @return A string with HTML that is the navbox.
--
local function _navbox()
local function renderMainTable()
    -- Create the root HTML element
local tbl = mw.html.create('table')
    local trim = function(s)
:addClass('nowraplinks')
        return s and mw.ustring.gsub(s, "^%s*(.-)%s*$", "%1") or ''
:addClass(args.bodyclass)
    end
 
    isChild = (trim(args[1]) == '하위')
if args.title and (args.state ~= 'plain' and args.state ~= 'off') then
if args.state == 'collapsed' then args.state = 'mw-collapsed' end
    if isChild then
tbl
        navbox = mw.html.create('table'):addClass('navbox__subgroup')
:addClass('mw-collapsible')
    else
:addClass(args.state or 'autocollapse')
        navbox = mw.html.create('table'):addClass('navbox')
end
 
        if args['상태'] ~= 'plain' then
tbl:css('border-spacing', 0)
            navbox:addClass('mw-collapsible'):attr('data-expandtext',showText):attr('data-collapsetext',hideText)
if border == 'subgroup' or border == 'none' then
            if args['상태'] == 'collapsed' then
tbl
                navbox:addClass('mw-collapsed')
:addClass('navbox-subgroup')
            end
:cssText(args.bodystyle)
:cssText(args.style)
else  -- regular navbox - bodystyle and style will be applied to the wrapper table
tbl
:addClass('navbox-inner')
:css('background', 'transparent')
:css('color', 'inherit')
end
tbl:cssText(args.innerstyle)
 
renderTitleRow(tbl)
renderAboveRow(tbl)
for i, listnum in ipairs(listnums) do
renderListRow(tbl, i, listnum)
end
renderBelowRow(tbl)
 
return tbl
end
 
function p._navbox(navboxArgs)
args = navboxArgs
listnums = {}
 
for k, _ in pairs(args) do
if type(k) == 'string' then
local listnum = k:match('^list(%d+)$')
if listnum then table.insert(listnums, tonumber(listnum)) end
end
end
table.sort(listnums)
 
border = mw.text.trim(args.border or args[1] or '')
if border == '자식' then
border = 'child'
end
if border == '중첩' then
border = 'subgroup'
end
if border == 'child' then
border = 'subgroup'
end
 
-- render the main body of the navbox
local tbl = renderMainTable()
 
-- render the appropriate wrapper around the navbox, depending on the border param
local res = mw.html.create()
if border == 'none' then
local nav = res:tag('div')
:attr('role', 'navigation')
:node(tbl)
-- aria-labelledby title, otherwise above, otherwise lone group
if args.title or args.above or (args.group1 and not args.group2) then
nav:attr('aria-labelledby', mw.uri.anchorEncode(args.title or args.above or args.group1))
else
nav:attr('aria-label', 'Navbox')
end
elseif border == 'subgroup' then
-- We assume that this navbox is being rendered in a list cell of a parent navbox, and is
-- therefore inside a div with padding:0em 0.25em. We start with a </div> to avoid the
-- padding being applied, and at the end add a <div> to balance out the parent's </div>
res
:wikitext('</div>')
:node(tbl)
:wikitext('<div>')
else
local nav = res:tag('div')
:attr('role', 'navigation')
:addClass('navbox')
:addClass(args.navboxclass)
:cssText(args.bodystyle)
:cssText(args.style)
:css('padding', '3px')
:node(tbl)
-- aria-labelledby title, otherwise above, otherwise lone group
if args.title or args.above or (args.group1 and not args.group2) then
nav:attr('aria-labelledby', mw.uri.anchorEncode(args.title or args.above or args.group1))
else
nav:attr('aria-label', 'Navbox')
end
end
 
if (args.nocat or 'false'):lower() == 'false' then
renderTrackingCategories(res)
end
 
return striped(tostring(res))
end
 
local param_ko = {
    ['이름'] = 'name',
    ['제목'] = 'title',
    ['상태'] = 'state',
    ['그림'] = 'image',
    ['왼쪽그림'] = 'imageleft',
    ['윗글'] = 'above',
    ['아랫글'] = 'below',
    ['안내바'] = 'navbar',
    ['테두리'] = 'border',
   
    ['모양'] = 'style',
    ['기본모양'] = 'basestyle',
    ['전체모양'] = 'bodystyle',
    ['제목모양'] = 'titlestyle',
    ['내용모양'] = 'liststyle',
    ['묶음모양'] = 'groupstyle',
    ['묶음너비'] = 'groupwidth',
    ['내용여백'] = 'listpadding',
    ['홀수모양'] = 'oddstyle',
    ['짝수모양'] = 'evenstyle',
    ['홀짝'] = 'evenodd',
    ['윗글모양'] = 'abovestyle',
    ['아랫글모양'] = 'belowstyle',
    ['그림모양'] = 'imagestyle',
    ['왼쪽그림모양'] = 'imageleftstyle',
   
    ['전체속성'] = 'bodyclass',
    ['제목속성'] = 'titleclass',
    ['윗글속성'] = 'aboveclass',
    ['묶음속성'] = 'groupclass',
    ['내용속성'] = 'listclass',
    ['아랫글속성'] = 'belowclass',
 
    ['제목묶음'] = 'titlegroup',
    ['제목묶음속성'] = 'titlegroupclass',
    ['제목묶음모양'] = 'titlegroupstyle',
   
    ['내부모양'] = 'innerstyle',
}
 
for i = 1, 100 do
    param_ko['묶음' .. i] = 'group' .. i
    param_ko['묶음' .. i .. '모양'] = 'group' .. i .. 'title'
    param_ko['내용' .. i] = 'list' .. i
    param_ko['내용' .. i .. '모양'] = 'list' .. i .. 'title'
end
 
local function localname(parameter)
    return param_ko[parameter] or parameter
end
 
function p.navbox(frame)
if not getArgs then
getArgs = require('Module:Arguments').getArgs
end
local args = {}
parent_args = getArgs(frame, {wrappers = {'틀:둘러보기 상자', '틀:둘러보기 상자/중첩'}})
if frame.args.border then
-- This allows Template:Navbox_subgroup to use {{#invoke:Navbox|navbox|border=...}}.
parent_args.border = frame.args.border
end
 
-- Read the arguments in the order they'll be output in, to make references number in the right order.
local _
_ = parent_args.title or parent_args['제목'];
_ = parent_args.above or parent_args['윗글'];
for i = 1, 60 do
_ = parent_args["group" .. tostring(i)] or parent_args["묶음" .. tostring(i)];
_ = parent_args["list" .. tostring(i)] or parent_args["내용" .. tostring(i)];
end
_ = parent_args.below or parent_args["아랫글"];
 
    for k, v in pairs(parent_args) do
        if v ~= '' then
            args[localname(k)] = v
         end
         end
     end
     end
 
return p._navbox(args)
    if args['클래스'] then navbox:addClass(args['클래스']) end
    if args['모양'] then navbox:cssText(args['모양']) end
    -- Process...
    if not isChild then
        processTitle()
        processAboveBelow('above', '윗')
        processRows()
        processAboveBelow('below', '아랫')
        return tostring(navbox)
    else
        processRows()
        return tostring(navbox)
    end
end
--- Main module entry point.
-- To be called with {{#invoke:navbox|main}} or directly from another module.
--
-- @param frame The frame passed to the module via the #invoke. If called from another
--              module directly, this should be a table with the parameter definition.
function p.main(frame)
    -- Save the arguments in a local variable so other functions can use them.
    preProcessArgs(frame)
    return _navbox()
end
end
 
return p
return p

2019년 12월 26일 (목) 17:54 기준 최신판

--[[ Navbox Module

  • Fully CSS styled (inline styles possible but not default)
  • Supports unlimited rows

by User:Tjcool007 http://layton.wikia.com/wiki/Module:Navbox

Next changes are applied by User:Cafeinlove:

  • Parameter names are translated into Korean.
  • CSS class names reflect BEM rules
  • Parameters `name`, `border` are removed.
  • VDE linkset no more requires Template:Vdelinks. It is generated out of

`참조` argument, and the links color is customizable via `참조색` argument.

  • Parameters related to alternative group/list have been removed.

Instead, parameters for individual cells such as`제목클래스n`, `제목모양n`, `내용클래스n`, `내용모양n` are introduced.

  • List items are separated by a middot(plain text) instead of CSS pseudo.
  • List parameter accepts both list items and non-list items.
  • Class `navbox__title` is assigned to `th` element instead of `tr` element.

]]

local p = {}

-- Default config. Values will be replaced with -- proprecessed arguments passed to template local args = {} local navbox -- Actual navbox

local rownums, skiprows = {}, {} local alt, hasrows, hasData, isChild = false, false, false, false local activeSection, sections, cimage, cimageleft local colspan, rowspan

local showText, hideText = '보이기', '숨기기'


-- Title


--- Processes the VDE links in the title -- -- @param titlecell The table cell of the title local function processVde( titlecell ) if not args['참조'] then return endlocal vde = { '보기', '토론', '편집' }local vdeLinks = {}local link, ns, fullurllocal page = args['참조']local color = args['참조색'] or '#111'for k, v in pairs(vde) dons = '틀' if v ~= '편집' thenif v == '토론' then ns = '틀토론' endlink = '' .. v .. '' elsefullurl = mw.uri.fullUrl( ns .. ':' .. page, 'action=edit')link = '[' .. tostring(fullurl) .. ' ' .. v .. ']' endtable.insert(vdeLinks, link) endtitlecell:tag('span'):addClass('navbox__vde'):wikitext( table.concat(vdeLinks, ' ᛫ ') )


end

--- Processes the main title row local function processTitle() local titlerow = mw.html.create('tr')local titlecell = mw.html.create('th'):addClass('navbox__title'):attr('colspan',colspan):attr('scope','col')processVde( titlecell )titlecell:wikitext( args['큰제목'] or ' ' )if args['큰제목클래스'] then titlerow:addClass( args['큰제목클래스'] ) endif args['큰제목모양'] then titlecell:cssText( args['큰제목모양'] ) endtitlerow:node( titlecell )navbox:node( titlerow ) end

local function _addGutter( parent, incRowspan ) parent:tag('tr'):addClass('navbox__gutter'):tag('td'):attr('colspan',2)if incRowspan thenrowspan = rowspan + 1 end end


-- Above/Below


--- Processes the above and below rows -- -- @param rowtype Either 'above' or 'below' local function processAboveBelow( rowtype, prefix ) if not args[rowtype .. '글'] then return endlocal abrow = mw.html.create('tr'):addClass('navbox__'..rowtype)local abcell = mw.html.create('td'):attr('colspan',colspan):wikitext( args[rowtype .. '글'] )if args[rowtype .. '클래스'] then abrow:addClass( args[rowtype .. '클래스'] ) endif args[rowtype .. '모양'] then abcell:cssText( args[rowtype .. '모양'] ) endabrow:node( abcell )_addGutter( navbox )navbox:node( abrow ) end


-- Main Rows


--- Processes the images local function _processImage(row, imgtype) if not args[imgtype] then return endlocal iclass = imgtype == '그림' and 'navboximage--right' or 'navboximage--left'local imagecell = mw.html.create('td'):addClass('navbox__image'):addClass(iclass)local image = args[imgtype]if image:sub(1,1) ~= '[' thenlocal width = args[imgtype .. '너비'] or '100px'imagecell:css('width',width):wikitext('' .. width .. '|link=' .. (args[imgtype .. '링크'] or ) .. '') elseimagecell:css('width','0%'):wikitext(image) endif args[imgtype .. '클래스'] then imagecell:addClass( args[imgtype .. '클래스'] ) endif args[imgtype .. '모양'] then imagecell:cssText( args[imgtype .. '모양'] ) endrow:node( imagecell )if imgtype == '그림' thencimage = imagecell elsecimageleft = imagecell end end

--- Closes the currently active section (if any) local function _closeCurrentSection() if not activeSection then return endlocal row = mw.html.create('tr'):addClass('navbox__section-row')local cell = mw.html.create('td'):attr('colspan',2)if not hasrows then_processImage(row,'왼쪽그림') endcell:node(sections[activeSection])row:node(cell)local firstRow = falseif not hasrows thenfirstRow = truehasrows = true_processImage(row,'그림') end_addGutter(navbox,not firstRow)navbox:node(row) rowspan = rowspan + 1activeSection = falsehasData = false end

--- Handles alternating rows -- -- @return Alternatingly returns true or false. Always returns false if alternating rows -- are disabled with "alternaterows = no" local function _alternateRow() if args['색교차'] == 'no' then return false endif alt thenalt = falsereturn true elsealt = truereturn false end end

--- Process a single Header "row" -- -- @param num Number of the row to be processed local function processHeader(num) if not args['작은제목'..num] then return end_closeCurrentSection()local subtable = mw.html.create('table'):addClass('navbox__section')local headerrow = mw.html.create('tr')local header = mw.html.create('th'):addClass('navbox__header'):attr('colspan',2):attr('scope','col'):wikitext( args['작은제목'..num] )local collapseme = args['작은제목상태'..num] or falselocal state = falseif collapseme then-- Look at this oneif collapseme ~= 'plain' thenstate = collapseme == 'expanded' and 'expanded' or 'collapsed' end else-- Look at default local collapseall = args['작은제목기본상태'] or falseif collapseall thenstate = collapseall == 'expanded' and 'expanded' or 'collapsed' end endif state thensubtable:addClass('mw-collapsible'):attr('data-expandtext',showText):attr('data-collapsetext',hideText)if state == 'collapsed' thensubtable:addClass('mw-collapsed') end endif args['작은제목클래스'] then headerrow:addClass( args['작은제목클래스'] ) endif args['작은제목모양'] then header:cssText( args['작은제목모양'] ) endheaderrow:node(header) subtable:node(headerrow)sections[num] = subtableactiveSection = num end

--- Processes a single list row -- -- @param num Number of the row to be processed local function processList(num) if not args['내용'..num] then return endlocal row = mw.html.create('tr'):addClass('navbox__row')if not hasrows and not activeSection then_processImage(row, '왼쪽그림') endlocal listcell = mw.html.create('td'):addClass('navbox__list')

local data = args['내용'..num]local listTable = {}local list = local separator = ' ᛫ '

local function forwardJoined(str, tbl, sep)local joined = table.concat(tbl, sep)for i = 0, #tbl do tbl[i] = nil end -- empty tblreturn str .. joined end

local function appendWrapped(str, item, patt)return str .. string.format(patt, item) end

for line in data:gmatch('[^\r\n]+') do -- get line by lineif string.len(line) == 0 then break end


if line:sub(1, 2) == '* ' then -- line starting with '* 'table.insert(listTable, line:sub(3)) else -- other linesif #listTable ~= 0 thenlist = forwardJoined(list, listTable, separator)

endlist = appendWrapped(list, line, '

%s

')

endendlist = forwardJoined(list, listTable, separator)listcell:wikitext( list )local altRow = _alternateRow()if altRow then row:addClass( 'alt' ) end -- 홀수 행if args['모든내용클래스'] then listcell:addClass( args['모든내용클래스'] ) endif args['모든내용모양'] then listcell:cssText( args['모든내용모양'] ) endlocal listclass = args['내용클래스'..num] or falseif listclass then listcell:addClass( listclass ) endlocal liststyle = args['내용모양'..num] or falseif liststyle then listcell:cssText( liststyle ) endif args['제목'..num] thenlocal groupcell = mw.html.create('th'):addClass('navbox__group'):attr('scope','row'):wikitext( args['제목'..num] )if args['모든제목클래스'] then groupcell:addClass( args['모든제목클래스'] ) endif args['모든제목모양'] then groupcell:cssText( args['모든제목모양'] ) endlocal groupclass = args['제목클래스'..num] or falseif groupclass then groupcell:addClass( groupclass ) endlocal groupstyle = args['제목모양'..num] or falseif groupstyle then groupcell:cssText( groupstyle ) endrow:node( groupcell )elselistcell:attr('colspan',2):addClass('no-group')endrow:node( listcell )local firstRow = falseif not hasrows and not activeSection thenfirstRow = truehasrows = true_processImage(row, '그림')endif activeSection thenlocal parent = sections[activeSection]if not isChild or not firstRow then_addGutter(parent) endparent:node(row)hasData = trueelseif not isChild or not firstRow then_addGutter(navbox,not firstRow) endnavbox:node( row )rowspan = rowspan + 1end end

--- Processes all rows local function processRows() sections = {}for i=1,#rownums dolocal num = rownums[i]if not skiprows[num] thenprocessHeader(num)processList(num) end end_closeCurrentSection()if cimageleft thencimageleft:attr('rowspan',rowspan) endif cimage thencimage:attr('rowspan',rowspan) end end


-- ARGUMENTS PREPROCESSOR -- * Extracts arguments from frame and stores them in args table -- * At the same time, checks for valid row numbers


--- Preprocessor for the arguments. -- Will fill up the args table with the parameters from the frame grouped by their type. -- -- @param frame The frame passed to the Module. local function preProcessArgs(frame) local tmp = {}if frame == mw.getCurrentFrame() thentmp = frame:getParent().args elsetmp = frame end-- Storage tableslocal nums = {}-- Loop over all the argsfor k,v in pairs(tmp) do-- Skip empty args, which are uselessif v ~= thenlocal cat,num = tostring(k):match('^(.-)([1-9]%d*)$')

if cat == '제목' or cat == '내용' thennums[num] = true end args[k] = v -- Simple copyend endcolspan = args['그림'] and 3 or 2if args['왼쪽그림'] then colspan = colspan + 1 endrowspan = 0if args['색교차'] == '반전' then alt = true endfor k, v in pairs(nums) dotable.insert(rownums, tonumber(k)) endtable.sort(rownums)-- Calculate skip rowslocal cSection, cSkiplocal showall = args['상태']for i = 1, #rownums dolocal num = rownums[i]if args['작은제목'..num] thencSection = truecSkip = falselocal showme = args['작은제목상태'..num]if showme == hideText thencSkip = true elseif showme == '자동' or (showme ~= showText and showall ~= showText) thenif not args['내용'..num] thenlocal nextNum = rownums[i+1]cSkip = not nextNum or args['작은제목'..nextNum] -- If next has a header -> skip end end endif cSection and cSkip thenskiprows[num] = true end end end


-- MAIN FUNCTIONS


--- Processes the arguments to create the navbox. -- -- @return A string with HTML that is the navbox. local function _navbox() -- Create the root HTML elementlocal trim = function(s)return s and mw.ustring.gsub(s, "^%s*(.-)%s*$", "%1") or endisChild = (trim(args[1]) == '하위')if isChild thennavbox = mw.html.create('table'):addClass('navbox__subgroup') elsenavbox = mw.html.create('table'):addClass('navbox') if args['상태'] ~= 'plain' thennavbox:addClass('mw-collapsible'):attr('data-expandtext',showText):attr('data-collapsetext',hideText)if args['상태'] == 'collapsed' thennavbox:addClass('mw-collapsed') end end endif args['클래스'] then navbox:addClass(args['클래스']) endif args['모양'] then navbox:cssText(args['모양']) end-- Process...if not isChild thenprocessTitle()processAboveBelow('above', '윗')processRows()processAboveBelow('below', '아랫') return tostring(navbox) elseprocessRows() return tostring(navbox) end end

--- Main module entry point.

-- To be called with

or directly from another module.

-- -- @param frame The frame passed to the module via the #invoke. If called from another -- module directly, this should be a table with the parameter definition. function p.main(frame) -- Save the arguments in a local variable so other functions can use them.preProcessArgs(frame)return _navbox() end

return p