|
|
| (No se muestran 2 ediciones intermedias de otro usuario) |
| Línea 1: |
Línea 1: |
| local p = {} | | local p = {} |
| | local getArgs = require('Module:Arguments').getArgs |
|
| |
|
| local function is_rtl(lang) | | local SKINVERT = 'skin-invert-image' |
| lang = lang or mw.getCurrentFrame():preprocess('{{int:lang}}')
| | -- possible refactor for this: collect all tabs/icons into one array you can |
| return require('Module:Is rtl')[lang] == true
| | -- iterate through. would also allow warning about unused args. |
| end
| |
|
| |
|
| function get_portalicon(portalicon) | | function p._main(args) |
| if portalicon == nil then | | local container = mw.html.create('div') |
| return ''
| | :addClass('portal-navigation') |
| else
| |
| return '<span class="portal-navigation-portalicon">' .. portalicon .. '</span>' | |
| end
| |
| end
| |
|
| |
|
| function converttolinearrgb(c)
| | local header = container |
| c = tonumber(c, 16)
| | :tag('div') |
| c = c / 255.0
| | :addClass('portal-navigation-header') |
| if c <= 0.03928 then
| | :css({ |
| c = c/12.92
| | ['color'] = args.header_text_color, |
| else | | ['background-color'] = args.header_background_color, |
| c = ((c+0.055)/1.055) ^ 2.4 | | ['border-bottom-color'] = args.header_border_color, |
| | }) |
| | if not args.noinvert then |
| | header:addClass(SKINVERT) |
| end | | end |
|
| |
| return c
| |
| end
| |
|
| |
|
| function p.render(frame)
| | header:tag('span') |
| -- Default values
| | :addClass('portal-navigation-portalicon') |
| portalname = 'Portal' | | :wikitext(args.portalicon) |
| tabs = {}
| | header:tag('span') |
| subtabs = {}
| | :addClass('portal-navigation-portalname') |
| wrc = 0
| | :wikitext(args.portalname) |
|
| |
|
| -- Default values (customizations) | | local nav = container:tag('ul') |
| themecolor = '#54595d'
| | :addClass('portal-navigation-body') |
| headerstyle = ''
| | :addClass(SKINVERT) |
| tabsicons = {}
| |
| ff = nil
| |
| lang = nil
| |
| wrcadditional = nil
| |
|
| |
| -- Populating variables
| |
| for key, value in pairs(frame:getParent().args) do
| |
| if key == 'portalname' then
| |
| portalname = value
| |
| elseif key == 'portalicon' then
| |
| portalicon = value
| |
| elseif key == 'active' then
| |
| active = tonumber(value)
| |
| elseif key == 'wrc' then | |
| wrc = value
| |
| elseif key == 'themecolor' then
| |
| themecolor = value
| |
| elseif key == 'headerstyle' then
| |
| headerstyle = value
| |
| elseif key == 'forceflip' then
| |
| ff = value
| |
| elseif key == 'lang' then
| |
| lang = value
| |
| elseif key == 'hidenav' then
| |
| hidenav = value
| |
| elseif key == 'hidesubnav' then
| |
| hidesubnav = value
| |
| elseif key == 'wrcadditional' then
| |
| wrcadditional = value
| |
| elseif string.find(key, 'tab') ~= nil
| |
| and string.find(key, 'subtab') == nil then -- matches tab1, tab2, ...
| |
| id = string.gsub(key, 'tab', '')
| |
| id = tonumber(id)
| |
| tabs[id] = value
| |
| elseif string.find(key, 'icon') ~= nil then -- matches icon1, icon2, etc.
| |
| id = string.gsub(key, 'icon', '')
| |
| id = tonumber(id)
| |
| tabsicons[id] = value
| |
| elseif string.find(key, 'subtab') ~= nil then -- matches subtab1-1, etc.
| |
| id = string.gsub(key, 'subtab', '')
| |
| -- Subtab params take the form [prime tab]-[sub tab]
| |
| id = mw.text.split(id, '-')
| |
| primetab = tonumber(id[1])
| |
| subtab = tonumber(id[2])
| |
| if subtabs[primetab] == nil then
| |
| subtabs[primetab] = {}
| |
| end
| |
| subtabs[primetab][subtab] = value
| |
| end
| |
| end
| |
|
| |
| if ff == 'yes' or ff == 'true' or ff == '1' then
| |
| ff = true
| |
| end
| |
|
| |
| if hidenav == 'yes' or hidenav == 'true' or hidenav == '1' then
| |
| hidenav = true
| |
| end
| |
|
| |
| if hidesubnav == 'yes' or hidesubnav == 'true' or hidesubnav == '1' then
| |
| hidesubnav = true
| |
| end
| |
|
| |
|
| -- Constructing header | | local i = 1 |
| -- Relevant variables: portalname, wrc, themecolor, headerstyle
| | local activetab = tonumber(args.active) |
|
| | while true do |
| -- The text color in the header is automatically chosen based on the best contrast
| | local tab = args['tab' .. i] |
| -- https://stackoverflow.com/questions/3942878/how-to-decide-font-color-in-white-or-black-depending-on-background-color
| | local icon = args['icon' .. i] |
| headertextcolor = '#fff'
| | if not tab then break end |
|
| |
| rgb = string.gsub(themecolor, '#', '') | |
| rgb = mw.text.split(rgb, '')
| |
| if #rgb == 6 then | |
| r = rgb[1] .. rgb[2] | |
| g = rgb[3] .. rgb[4] | |
| b = rgb[5] .. rgb[6]
| |
| elseif #rgb == 3 then
| |
| r = rgb[1] .. rgb[1]
| |
| g = rgb[2] .. rgb[2]
| |
| b = rgb[3] .. rgb[3] | |
| end
| |
| r = converttolinearrgb(r)
| |
| g = converttolinearrgb(g)
| |
| b = converttolinearrgb(b)
| |
|
| |
| luminance = 0.2126 * r + 0.7152 * g + 0.0722 * b
| |
|
| |
| if luminance > 0.179 then
| |
| headertextcolor = '#000'
| |
| end
| |
|
| |
|
| -- Applying customizations to headerstyle
| | local item = nav:tag('li'):addClass('portal-navigation-item') |
| headerstyle = 'background:' .. themecolor .. '; color:' .. headertextcolor .. ';'
| | if i == activetab then |
| .. headerstyle
| | item:addClass('active-tab') |
|
| | end |
| header = '<div class="portal-navigation-header" style="' .. headerstyle .. '">'
| |
| | |
| if ff ~= true or (ff == true and not is_rtl()) then
| |
| header = header .. get_portalicon(portalicon) .. portalname .. '</div>'
| |
| else
| |
| header = header .. portalname .. get_portalicon(portalicon) .. '</div>' | |
| end
| |
|
| |
|
| if wrc == '1' or wrc == 1 or wrc == 'true' or wrc == true or wrc == 'yes' then
| | if icon then |
| badgeargs = {}
| | item:tag('span') |
| if ff == true then | | :addClass('portal-navigation-tabicon') |
| badgeargs['forceflip'] = ff | | :wikitext(icon) |
| end
| |
| if wrcadditional ~= nil then
| |
| badgeargs['additional'] = wrcadditional
| |
| end | | end |
|
| |
|
| header = frame:expandTemplate{ | | item:tag('span') |
| title = 'Wikimedia Resource Center badge',
| | :addClass('portal-navigation-tabname') |
| args = badgeargs } | | :wikitext(tab) |
| .. '\n\n' .. header
| |
| end
| |
|
| |
| -- Constructing the rest
| |
| -- Relevant variables: themecolor tabs tabsicons active subtabs
| |
| | |
| body = ''
| |
|
| |
|
| if hidenav ~= true then
| | i = i + 1 |
| body = body .. '<ul class="portal-navigation-body">'
| |
| | |
| for index, pagelink in ipairs(tabs) do
| |
| -- Open TOC entry container
| |
| body = body .. '<li>'
| |
|
| |
| -- Create the tab itself
| |
| local entryclass = 'portal-navigation-entry'
| |
| local entrystyle = ''
| |
| if index == active then
| |
| if subtabs[index] == nil or hidesubnav == true then
| |
| entrystyle = ' style="border-bottom-color:' .. themecolor .. ';"'
| |
| else
| |
| entryclass = entryclass .. ' portal-navigation-entry-has-subtabs'
| |
| end
| |
| end
| |
|
| |
| icon = ''
| |
| if tabsicons[index] ~= nil then
| |
| icon = '<span class="portal-navigation-tabicon">' .. tabsicons[index] .. '</span>'
| |
| end
| |
|
| |
| body = body
| |
| .. '<span class="' .. entryclass .. '"' .. entrystyle .. '>'
| |
| .. icon .. pagelink
| |
| .. '</span>'
| |
|
| |
| -- If the tab is active, show the subnav if there is any
| |
|
| |
| if index == active and subtabs[index] ~= nil and hidesubnav ~= true then
| |
| body = body .. '<ul class="portal-navigation-subtabs" style="border-color:' .. themecolor .. ';">'
| |
|
| |
| for _, subpagelink in ipairs(subtabs[index]) do
| |
| body = body .. '<li>' .. subpagelink .. '</li>'
| |
| end
| |
|
| |
| body = body .. '</ul>'
| |
| end
| |
|
| |
| -- Close TOC entry container
| |
| body = body .. '</li>'
| |
| end
| |
|
| |
| body = body .. '</ul>' | |
| end | | end |
|
| |
|
| local templatestyles = frame:extensionTag('templatestyles', '', {src = 'Module:Portal navigation/styles.css'}) | | return container |
| | | end |
| local classes = 'portal-navigation'
| |
| local attributes = ''
| |
| if lang then
| |
| attributes = ' lang="' .. lang .. '" dir="' .. (is_rtl(lang) and 'rtl' or 'ltr') .. '"'
| |
| end
| |
| if ff == true then
| |
| classes = classes .. ' portal-navigation-force-' .. (is_rtl() and 'rtl' or 'ltr')
| |
| end
| |
|
| |
|
| return '<div class="' .. classes .. '"' .. attributes .. '>' .. templatestyles .. header .. body .. '</div>' | | function p.main(frame) |
| | return tostring(p._main(getArgs(frame))) .. frame:extensionTag('templatestyles', '', { |
| | src = 'Module:Portal navigation/styles.css', |
| | }) |
| end | | end |
|
| |
|
| return p | | return p |
La documentación para este módulo puede ser creada en Módulo:Portal navigation/doc
local p = {}
local getArgs = require('Module:Arguments').getArgs
local SKINVERT = 'skin-invert-image'
-- possible refactor for this: collect all tabs/icons into one array you can
-- iterate through. would also allow warning about unused args.
function p._main(args)
local container = mw.html.create('div')
:addClass('portal-navigation')
local header = container
:tag('div')
:addClass('portal-navigation-header')
:css({
['color'] = args.header_text_color,
['background-color'] = args.header_background_color,
['border-bottom-color'] = args.header_border_color,
})
if not args.noinvert then
header:addClass(SKINVERT)
end
header:tag('span')
:addClass('portal-navigation-portalicon')
:wikitext(args.portalicon)
header:tag('span')
:addClass('portal-navigation-portalname')
:wikitext(args.portalname)
local nav = container:tag('ul')
:addClass('portal-navigation-body')
:addClass(SKINVERT)
local i = 1
local activetab = tonumber(args.active)
while true do
local tab = args['tab' .. i]
local icon = args['icon' .. i]
if not tab then break end
local item = nav:tag('li'):addClass('portal-navigation-item')
if i == activetab then
item:addClass('active-tab')
end
if icon then
item:tag('span')
:addClass('portal-navigation-tabicon')
:wikitext(icon)
end
item:tag('span')
:addClass('portal-navigation-tabname')
:wikitext(tab)
i = i + 1
end
return container
end
function p.main(frame)
return tostring(p._main(getArgs(frame))) .. frame:extensionTag('templatestyles', '', {
src = 'Module:Portal navigation/styles.css',
})
end
return p