Line 4: |
Line 4: |
| -- == Helper functions == | | -- == Helper functions == |
| --[[ libraries ]] | | --[[ libraries ]] |
− | local common = require("Module:Common") | + | local U = require("Module:Core") |
− | local style = require("Module:Styles")
| |
| | | |
− | local colors = style.main_colors | + | local colors = U.main_colors |
| | | |
| if mw.text == nil then mw.text = require("Module:MW.text") end | | if mw.text == nil then mw.text = require("Module:MW.text") end |
Line 52: |
Line 51: |
| tmp['index'] = v | | tmp['index'] = v |
| tmp['list'] = list[v] | | tmp['list'] = list[v] |
− | if common.isset(group[v]) then tmp['group'] = group[v] end | + | if U.isset(group[v]) then tmp['group'] = group[v] end |
− | if common.isset(liststyle[v]) then tmp['liststyle'] = liststyle[v] end | + | if U.isset(liststyle[v]) then tmp['liststyle'] = liststyle[v] end |
− | if common.isset(groupstyle[v]) then tmp['groupstyle'] = groupstyle[v] end | + | if U.isset(groupstyle[v]) then tmp['groupstyle'] = groupstyle[v] end |
| ret[#ret+1] = tmp | | ret[#ret+1] = tmp |
| end | | end |
Line 75: |
Line 74: |
| -- new, independent navbox - create a frame around it | | -- new, independent navbox - create a frame around it |
| ret[#ret+1] = '<table class="navbox' | | ret[#ret+1] = '<table class="navbox' |
− | if common.isset(frame.args['bodyclass']) then ret[#ret+1] = " " .. frame.args['bodyclass'] end | + | if U.isset(frame.args['bodyclass']) then ret[#ret+1] = " " .. frame.args['bodyclass'] end |
| ret[#ret+1] = '" cellspacing="0" style="' | | ret[#ret+1] = '" cellspacing="0" style="' |
− | if common.isset(colors[ttype]) then ret[#ret+1] = 'background:' .. colors[ttype]['background'] .. ';' end | + | if U.isset(colors[ttype]) then ret[#ret+1] = 'background:' .. colors[ttype]['background'] .. ';' end |
| -- ret[#ret+1] = 'border:1px solid #aaa; padding:1px;width:100%;vertical-align:middle;margin:auto;clear:both;font-size:88%;text-align:center;' | | -- ret[#ret+1] = 'border:1px solid #aaa; padding:1px;width:100%;vertical-align:middle;margin:auto;clear:both;font-size:88%;text-align:center;' |
− | style.add(ret, frame.args['bodystyle']) | + | U.addStyle(ret, frame.args['bodystyle']) |
− | style.add(ret, frame.args['style']) | + | U.addStyle(ret, frame.args['style']) |
| ret[#ret+1] = '"><tr><td style="padding: 2px;">' | | ret[#ret+1] = '"><tr><td style="padding: 2px;">' |
| end | | end |
Line 86: |
Line 85: |
| -- The actual navbox table starts here | | -- The actual navbox table starts here |
| ret[#ret+1] = '<table cellspacing="0" class="nowraplinks' | | ret[#ret+1] = '<table cellspacing="0" class="nowraplinks' |
− | if common.isset(frame.args['title']) and frame.args['state'] ~= "plain" and frame.args['state'] ~= "off" then | + | if U.isset(frame.args['title']) and frame.args['state'] ~= "plain" and frame.args['state'] ~= "off" then |
| --TODO: If there is support for collapsible and autocollapse, swap comments here | | --TODO: If there is support for collapsible and autocollapse, swap comments here |
| --ret[#ret+1] = ' collapsible ' | | --ret[#ret+1] = ' collapsible ' |
| ret[#ret+1] = ' mw-collapsible ' | | ret[#ret+1] = ' mw-collapsible ' |
− | if common.isset(frame.args['state']) then | + | if U.isset(frame.args['state']) then |
| ret[#ret+1] = frame.args['state'] | | ret[#ret+1] = frame.args['state'] |
| else | | else |
Line 99: |
Line 98: |
| if border == "subgroup" or border == "child" or border == "none" then | | if border == "subgroup" or border == "child" or border == "none" then |
| ret[#ret+1] = ' navbox-subgroup" style="' | | ret[#ret+1] = ' navbox-subgroup" style="' |
− | if common.isset(colors[ttype]) then table.insert(ret, 'background:' .. colors[ttype]['background'] .. ';') end | + | if U.isset(colors[ttype]) then table.insert(ret, 'background:' .. colors[ttype]['background'] .. ';') end |
| -- ret[#ret+1] = 'margin:auto;clear:both;font-size:88%;text-align:center;width:100%;vertical-align:middle;' | | -- ret[#ret+1] = 'margin:auto;clear:both;font-size:88%;text-align:center;width:100%;vertical-align:middle;' |
| ret[#ret+1] = 'width: 100%;' | | ret[#ret+1] = 'width: 100%;' |
− | style.add(ret, frame.args['bodystyle']) | + | U.addStyle(ret, frame.args['bodystyle']) |
− | style.add(ret, frame.args['style']) | + | U.addStyle(ret, frame.args['style']) |
| ret[#ret+1] = '">' | | ret[#ret+1] = '">' |
| else | | else |
Line 131: |
Line 130: |
| local function build_title(frame, border, ttype) | | local function build_title(frame, border, ttype) |
| local ret = {""} | | local ret = {""} |
− | if not common.isset(frame.args['title']) then return '' end | + | if not U.isset(frame.args['title']) then return '' end |
| | | |
| table.insert(ret, '<tr>') | | table.insert(ret, '<tr>') |
− | if common.isset(frame.args['titlegroup']) then | + | if U.isset(frame.args['titlegroup']) then |
| -- in case that there's a group for title | | -- in case that there's a group for title |
| ret[#ret+1] = '<td class="navbox-group" style="' | | ret[#ret+1] = '<td class="navbox-group" style="' |
− | if common.isset(colors[ttype]) then ret[#ret+1] = 'background:' .. colors[ttype]['group'] .. ';' end | + | if U.isset(colors[ttype]) then ret[#ret+1] = 'background:' .. colors[ttype]['group'] .. ';' end |
| ret[#ret+1] = 'padding-left:1em;padding-right:1em;white-space:nowrap;text-align:right;' | | ret[#ret+1] = 'padding-left:1em;padding-right:1em;white-space:nowrap;text-align:right;' |
− | style.add(ret, frame.args['basestyle']) | + | U.addStyle(ret, frame.args['basestyle']) |
− | style.add(ret, frame.args['groupstyle']) | + | U.addStyle(ret, frame.args['groupstyle']) |
− | style.add(ret, frame.args['titlegroupstyle']) | + | U.addStyle(ret, frame.args['titlegroupstyle']) |
| ret[#ret+1] = '">\n' | | ret[#ret+1] = '">\n' |
| ret[#ret+1] = frame.args['titlegroup'] | | ret[#ret+1] = frame.args['titlegroup'] |
Line 147: |
Line 146: |
| | | |
| ret[#ret+1] = '<th style="border-left:2px solid ' | | ret[#ret+1] = '<th style="border-left:2px solid ' |
− | ret[#ret+1] = common.cv(common.isset(colors[ttype]), colors[ttype]['background'], '#fdfdfd') | + | ret[#ret+1] = U.cv(U.isset(colors[ttype]), colors[ttype]['background'], '#fdfdfd') |
| ret[#ret+1] = ';width:100%;' | | ret[#ret+1] = ';width:100%;' |
| else | | else |
Line 153: |
Line 152: |
| table.insert(ret, '<th style="') | | table.insert(ret, '<th style="') |
| end | | end |
− | if common.isset(colors[ttype]) then ret[#ret+1] = 'background:' .. colors[ttype]['title'] .. ';' end | + | if U.isset(colors[ttype]) then ret[#ret+1] = 'background:' .. colors[ttype]['title'] .. ';' end |
| ret[#ret+1] = 'text-align:center;' | | ret[#ret+1] = 'text-align:center;' |
− | style.add(ret, frame.args['basestyle']) | + | U.addStyle(ret, frame.args['basestyle']) |
− | style.add(ret, frame.args['titlestyle']) | + | U.addStyle(ret, frame.args['titlestyle']) |
| ret[#ret+1] = '"' | | ret[#ret+1] = '"' |
| | | |
| -- calculate the colspan for title | | -- calculate the colspan for title |
| local cs = 2 -- 2 because each list element with group occupies 2 columns | | local cs = 2 -- 2 because each list element with group occupies 2 columns |
− | if common.isset(frame.args['imageleft']) then cs = cs + 1 end | + | if U.isset(frame.args['imageleft']) then cs = cs + 1 end |
− | if common.isset(frame.args['image']) then cs = cs + 1 end | + | if U.isset(frame.args['image']) then cs = cs + 1 end |
− | if common.isset(frame.args['titlegroup']) then cs = cs - 1 end -- if there was a titlegroup, it occupies one cell already | + | if U.isset(frame.args['titlegroup']) then cs = cs - 1 end -- if there was a titlegroup, it occupies one cell already |
| ret[#ret+1] = ' colspan = "' .. cs .. '"' | | ret[#ret+1] = ' colspan = "' .. cs .. '"' |
| ret[#ret+1] = ' class="navbox-title">' | | ret[#ret+1] = ' class="navbox-title">' |
Line 186: |
Line 185: |
| local q = {""} | | local q = {""} |
| q[#q+1] = 'text-align:left;' | | q[#q+1] = 'text-align:left;' |
− | style.add(q, frame.args['basestyle']) | + | U.addStyle(q, frame.args['basestyle']) |
− | style.add(q, frame.args['titlestyle']) | + | U.addStyle(q, frame.args['titlestyle']) |
| q[#q+1] = 'border:none;' | | q[#q+1] = 'border:none;' |
| args['fontstyle'] = table.concat(q) | | args['fontstyle'] = table.concat(q) |
Line 201: |
Line 200: |
| -- the title starts here | | -- the title starts here |
| ret[#ret+1] = '<span' | | ret[#ret+1] = '<span' |
− | if common.isset(frame.args['titleclass']) then ret[#ret+1] = ' class="' .. frame.args['titleclass'] .. '"' end | + | if U.isset(frame.args['titleclass']) then ret[#ret+1] = ' class="' .. frame.args['titleclass'] .. '"' end |
− | ret[#ret+1] = ' style="font-size:' .. common.cv((border == "subgroup" or border == "child" or border == "none"), '100%', '110%') .. ';">\n' | + | ret[#ret+1] = ' style="font-size:' .. U.cv((border == "subgroup" or border == "child" or border == "none"), '100%', '110%') .. ';">\n' |
| | | |
| ret[#ret+1] = frame.args['title'] | | ret[#ret+1] = frame.args['title'] |
Line 215: |
Line 214: |
| local function build_above_below(frame, border, ttype, text, rstyle, sep) | | local function build_above_below(frame, border, ttype, text, rstyle, sep) |
| local ret = {''} | | local ret = {''} |
− | if common.isset(text) then | + | if U.isset(text) then |
| if sep then -- if separation is needed | | if sep then -- if separation is needed |
| table.insert(ret, '<tr style="height: 2px;"><td></td></tr>') | | table.insert(ret, '<tr style="height: 2px;"><td></td></tr>') |
Line 223: |
Line 222: |
| ret[#ret+1] = '<tr>' | | ret[#ret+1] = '<tr>' |
| ret[#ret+1] = '<td class="navbox-abovebelow" style="' | | ret[#ret+1] = '<td class="navbox-abovebelow" style="' |
− | if common.isset(colors[ttype]) then | + | if U.isset(colors[ttype]) then |
| -- both above and below share same default color from 'colors' table | | -- both above and below share same default color from 'colors' table |
− | ret[#ret+1] = 'background:' .. common.cv((border ~= "subgroup" and border ~= "child"), colors[ttype]['above'], colors[ttype]['group']) .. ';' | + | ret[#ret+1] = 'background:' .. U.cv((border ~= "subgroup" and border ~= "child"), colors[ttype]['above'], colors[ttype]['group']) .. ';' |
| end | | end |
| ret[#ret+1] = 'padding-left:1em;padding-right:1em;text-align:center;' | | ret[#ret+1] = 'padding-left:1em;padding-right:1em;text-align:center;' |
− | style.add(ret, frame.args['basestyle']) | + | U.addStyle(ret, frame.args['basestyle']) |
− | style.add(ret, rstyle) | + | U.addStyle(ret, rstyle) |
| ret[#ret+1] = '"' | | ret[#ret+1] = '"' |
| | | |
| -- calculate and add the colspan (always full table width) | | -- calculate and add the colspan (always full table width) |
| local cs = 2 | | local cs = 2 |
− | if common.isset(frame.args['imageleft']) then cs = cs + 1 end | + | if U.isset(frame.args['imageleft']) then cs = cs + 1 end |
− | if common.isset(frame.args['image']) then cs = cs + 1 end | + | if U.isset(frame.args['image']) then cs = cs + 1 end |
| ret[#ret+1] = ' colspan="' .. cs .. '">\n' | | ret[#ret+1] = ' colspan="' .. cs .. '">\n' |
| | | |
Line 250: |
Line 249: |
| local function build_row(frame, border, ttype, k, group, list, groupstyle, liststyle) | | local function build_row(frame, border, ttype, k, group, list, groupstyle, liststyle) |
| local ret = {""} | | local ret = {""} |
− | if common.isset(group) then | + | if U.isset(group) then |
| -- there's a group name for current list, so add a cell for it | | -- there's a group name for current list, so add a cell for it |
| ret[#ret+1] = '<td class="navbox-group" style="' | | ret[#ret+1] = '<td class="navbox-group" style="' |
− | if common.isset(colors[ttype]) then | + | if U.isset(colors[ttype]) then |
− | ret[#ret+1] = 'background:' .. common.cv((border ~= "subgroup" and border ~= "child"), colors[ttype]['group'], colors[ttype]['subgroup']) .. ';' | + | ret[#ret+1] = 'background:' .. U.cv((border ~= "subgroup" and border ~= "child"), colors[ttype]['group'], colors[ttype]['subgroup']) .. ';' |
| end | | end |
| ret[#ret+1] = 'padding-left:1em; padding-right:1em; white-space:nowrap; text-align:right;' | | ret[#ret+1] = 'padding-left:1em; padding-right:1em; white-space:nowrap; text-align:right;' |
− | style.add(ret, frame.args['basestyle']) | + | U.addStyle(ret, frame.args['basestyle']) |
− | if common.isset(frame.args['groupwidth']) then ret[#ret+1] = 'width:' .. frame.args['groupwidth'] .. ';' end | + | if U.isset(frame.args['groupwidth']) then ret[#ret+1] = 'width:' .. frame.args['groupwidth'] .. ';' end |
− | style.add(ret, frame.args['groupstyle']) | + | U.addStyle(ret, frame.args['groupstyle']) |
− | style.add(ret, groupstyle) | + | U.addStyle(ret, groupstyle) |
| ret[#ret+1] = '">' | | ret[#ret+1] = '">' |
| ret[#ret+1] = '<div style="padding:0;">\n' | | ret[#ret+1] = '<div style="padding:0;">\n' |
Line 274: |
Line 273: |
| -- a bit tricky, but this works as XOR | | -- a bit tricky, but this works as XOR |
| if (frame.args['evenodd'] == "swap") ~= ((k % 2) == 0) then | | if (frame.args['evenodd'] == "swap") ~= ((k % 2) == 0) then |
− | if common.isset(colors[ttype]) then ret[#ret+1] = 'background:' .. colors[ttype]['dark'] .. ';' end | + | if U.isset(colors[ttype]) then ret[#ret+1] = 'background:' .. colors[ttype]['dark'] .. ';' end |
| else | | else |
| ret[#ret+1] = 'background:transparent;' | | ret[#ret+1] = 'background:transparent;' |
| end | | end |
− | if not common.isset(frame.args['groupwidth']) then ret[#ret+1] = 'width:100%;' end | + | if not U.isset(frame.args['groupwidth']) then ret[#ret+1] = 'width:100%;' end |
| ret[#ret+1] = 'padding: 0;' | | ret[#ret+1] = 'padding: 0;' |
− | style.add(ret, frame.args['liststyle']) | + | U.addStyle(ret, frame.args['liststyle']) |
− | style.add(ret, common.cv((frame.args['evenodd'] == "swap") ~= ((k % 2) == 0), frame.args['evenstyle'], frame.args['oddstyle'])) | + | U.addStyle(ret, U.cv((frame.args['evenodd'] == "swap") ~= ((k % 2) == 0), frame.args['evenstyle'], frame.args['oddstyle'])) |
− | style.add(ret, liststyle) | + | U.addStyle(ret, liststyle) |
− | ret[#ret+1] = '" class="navbox-list ' .. common.cv((frame.args['evenodd'] == "swap") ~= ((k % 2) == 0), 'navbox-even', 'navbox-odd') .. '">' | + | ret[#ret+1] = '" class="navbox-list ' .. U.cv((frame.args['evenodd'] == "swap") ~= ((k % 2) == 0), 'navbox-even', 'navbox-odd') .. '">' |
| | | |
| -- add the <div> with content (same <div> that child navbox has to close when starting table) | | -- add the <div> with content (same <div> that child navbox has to close when starting table) |
| ret[#ret+1] = '<div style="padding:' | | ret[#ret+1] = '<div style="padding:' |
− | if common.isset(frame.args['list' .. k .. 'padding']) then | + | if U.isset(frame.args['list' .. k .. 'padding']) then |
| ret[#ret+1] = frame.args['list' .. k .. 'padding'] | | ret[#ret+1] = frame.args['list' .. k .. 'padding'] |
− | elseif common.isset(frame.args['listpadding']) then | + | elseif U.isset(frame.args['listpadding']) then |
| ret[#ret+1] = frame.args['listpadding'] | | ret[#ret+1] = frame.args['listpadding'] |
| else | | else |
Line 303: |
Line 302: |
| local function build_body(frame, border, ttype, lists) | | local function build_body(frame, border, ttype, lists) |
| local ret = {} | | local ret = {} |
− | local sep = common.isset(frame.args['title']) -- if there was a title, we have to add separation for first row | + | local sep = U.isset(frame.args['title']) -- if there was a title, we have to add separation for first row |
| local imgs = true -- add images if present | | local imgs = true -- add images if present |
− | local irows = common.cv( (#lists > 0), (2 * #lists - 1), 1 ) | + | local irows = U.cv( (#lists > 0), (2 * #lists - 1), 1 ) |
| | | |
| -- aff the 'above' row | | -- aff the 'above' row |
Line 319: |
Line 318: |
| -- add left image (if wasn't added yet and is present) | | -- add left image (if wasn't added yet and is present) |
| if imgs then | | if imgs then |
− | if common.isset(frame.args['imageleft']) then | + | if U.isset(frame.args['imageleft']) then |
| ret[#ret+1] = '<td style="width:0%;padding:0px 2px 0px 0px;' | | ret[#ret+1] = '<td style="width:0%;padding:0px 2px 0px 0px;' |
− | style.add(ret, frame.args['imageleftstyle']) | + | U.addStyle(ret, frame.args['imageleftstyle']) |
| ret[#ret+1] = '" rowspan="' .. irows .. '">' .. frame.args['imageleft'] .. '</td>' | | ret[#ret+1] = '" rowspan="' .. irows .. '">' .. frame.args['imageleft'] .. '</td>' |
| end | | end |
Line 331: |
Line 330: |
| -- add right image (if wasn't added yet and is present) | | -- add right image (if wasn't added yet and is present) |
| if imgs then | | if imgs then |
− | if common.isset(frame.args['image']) then | + | if U.isset(frame.args['image']) then |
| ret[#ret+1] = '<td style="width:0%;padding:0px 0px 0px 2px;' | | ret[#ret+1] = '<td style="width:0%;padding:0px 0px 0px 2px;' |
− | style.add(ret, frame.args['imagestyle']) | + | U.addStyle(ret, frame.args['imagestyle']) |
| ret[#ret+1] = '" rowspan="' .. irows .. '">' .. frame.args['image'] .. '</td>' | | ret[#ret+1] = '" rowspan="' .. irows .. '">' .. frame.args['image'] .. '</td>' |
| end | | end |
Line 357: |
Line 356: |
| local ttype = "" | | local ttype = "" |
| | | |
− | if common.isset(frame.args['border']) then | + | if U.isset(frame.args['border']) then |
| border = frame.args['border'] | | border = frame.args['border'] |
− | elseif common.isset(frame.args[1]) then | + | elseif U.isset(frame.args[1]) then |
| border = mw.text.trim(frame.args[1]) | | border = mw.text.trim(frame.args[1]) |
| end | | end |
| | | |
− | if common.isset(frame.args['type']) then | + | if U.isset(frame.args['type']) then |
| ttype = frame.args['type'] | | ttype = frame.args['type'] |
| end | | end |
Line 383: |
Line 382: |
| -- [[ Workaround for the "Navbox subgroup" template ]] | | -- [[ Workaround for the "Navbox subgroup" template ]] |
| local function buildNavboxSubgroup(frame) | | local function buildNavboxSubgroup(frame) |
− | if not common.isset(frame.args['border']) then frame.args['border'] = 'child' end | + | if not U.isset(frame.args['border']) then frame.args['border'] = 'child' end |
| | | |
| -- TODO: add/modify/remove other params? | | -- TODO: add/modify/remove other params? |