Module:Vertical header: Difference between revisions
Appearance
Content deleted Content added
removed CSS for unsupported browsers |
changes from ru:Module:Vertical header by me to add TemplateStyles support and remove code that can be done using CSS |
||
Line 1: | Line 1: | ||
require( 'strict' ) |
|||
local p = {} |
local p = {} |
||
local templatestylesPage = 'Module:Vertical header/styles.css' |
|||
local function isEmpty(s) |
|||
return s == nil or s == '' |
|||
⚫ | |||
function p._vertical_header(args) |
function p._vertical_header(args) |
||
⚫ | |||
local text = args.text |
local text = args.text |
||
local maxWidth = args.maxWidth |
local maxWidth = args.maxWidth |
||
local rows = 1 |
local rows = 1 |
||
local width = 0 |
local width = 0 |
||
if maxWidth ~= |
if maxWidth ~= '' then |
||
width = maxWidth |
width = maxWidth |
||
else |
else |
||
for eachMatch in text:gmatch( |
for eachMatch in text:gmatch('<[bB][rR] */? *>') do |
||
rows = rows + 1 |
rows = rows + 1 |
||
end |
end |
||
⚫ | |||
width = |
width = rows |
||
⚫ | |||
end |
end |
||
local vertAlign = not isEmpty( args.vertAlign ) and 'is-valign-' .. args.vertAlign or '' |
|||
local wikiText = "class = \"nowrap" |
|||
local |
local noBold = isEmpty( args.noBold ) and '' or 'is-normal' |
||
local wikiText = string.format( 'class="nowrap ts-vertical-header %s %s"', vertAlign, noBold ) |
|||
if sortPadding == "" then |
|||
⚫ | |||
⚫ | |||
local |
local cellStyle = ( args.cellstyle or '' ):gsub("\"", """) |
||
if width and width ~= '1em' then |
|||
wikiText = wikiText .. "\" style=\"line-height:99%;vertical-align:" .. vertAlign .. ";padding:" |
|||
⚫ | |||
if sortPadding == "" then |
|||
elseif cellStyle then |
|||
⚫ | |||
wikiText = wikiText .. string.format( ' style="%s"', cellStyle ) |
|||
else |
|||
wikiText = wikiText .. "21px" |
|||
end |
end |
||
wikiText = wikiText .. " .4em .2em;background-position:50% .4em !important;" |
|||
local cellStyle = args.cellstyle:gsub("\"", """) |
|||
⚫ | |||
wikiText = wikiText .. " | <div style=\"-webkit-writing-mode: vertical-rl; writing-mode: tb-rl; writing-mode: vertical-rl; layout-flow: vertical-ideographic;transform:rotate(180deg);display:inline-block;padding-left:1px;text-align:" |
|||
local normalAlign = "" |
|||
if vertAlign == "top" then |
|||
normalAlign = "right" |
|||
elseif vertAlign == "middle" then |
|||
normalAlign = "center" |
|||
else |
|||
normalAlign = "left" |
|||
end |
|||
wikiText = wikiText .. normalAlign .. ";" |
|||
⚫ | |||
local style = args.style:gsub("\"", """) |
local style = args.style:gsub("\"", """) |
||
wikiText = wikiText .. style .. "\">" |
wikiText = wikiText .. style .. "\">" |
||
-- Add TemplateStyles |
|||
local noBold = args.noBold |
|||
⚫ | |||
if noBold == "" then |
|||
name = 'templatestyles', |
|||
wikiText = wikiText .. text |
|||
args = { src = templatestylesPage } |
|||
else |
|||
⚫ | |||
wikiText = wikiText .. mw.getCurrentFrame():preprocess("{{nobold|1=" .. text .. "}}") |
|||
wikiText = wikiText .. |
wikiText = wikiText .. text .. '</div>' |
||
return wikiText |
return wikiText |
||
end |
end |
Revision as of 11:10, 28 April 2024
![]() | This module uses TemplateStyles: |
Implements {{Vertical header}}
require( 'strict' )
local p = {}
local templatestylesPage = 'Module:Vertical header/styles.css'
local function isEmpty(s)
return s == nil or s == ''
end
function p._vertical_header(args)
local text = args.text
local maxWidth = args.maxWidth
local rows = 1
local width = 0
if maxWidth ~= '' then
width = maxWidth
else
for eachMatch in text:gmatch('<[bB][rR] */? *>') do
rows = rows + 1
end
width = rows
width = width .. 'em'
end
local vertAlign = not isEmpty( args.vertAlign ) and 'is-valign-' .. args.vertAlign or ''
local noBold = isEmpty( args.noBold ) and '' or 'is-normal'
local wikiText = string.format( 'class="nowrap ts-vertical-header %s %s"', vertAlign, noBold )
local cellStyle = ( args.cellstyle or '' ):gsub("\"", """)
if width and width ~= '1em' then
wikiText = wikiText .. string.format( ' style="max-width:%s; width:%s; %s"', width, width, cellStyle )
elseif cellStyle then
wikiText = wikiText .. string.format( ' style="%s"', cellStyle )
end
wikiText = wikiText .. ' | <div style="'
local style = args.style:gsub("\"", """)
wikiText = wikiText .. style .. "\">"
-- Add TemplateStyles
wikiText = wikiText .. mw.getCurrentFrame():extensionTag{
name = 'templatestyles',
args = { src = templatestylesPage }
}
wikiText = wikiText .. text .. '</div>'
return wikiText
end
function p.cell(frame)
local args = frame.args
return p._vertical_header(args)
end
return p