Module:Vertical header/sandbox: Difference between revisions
Appearance
Content deleted Content added
sandybox |
Sync from rev. 1232249886 of module.. |
||
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 stupidIEAlign = "" |
|||
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 |
local class = args.class or '' |
||
local vertAlign = not isEmpty( args.vertAlign ) and 'is-valign-' .. args.vertAlign or '' |
|||
local sortPadding = args.sortPadding |
|||
⚫ | |||
if sortPadding == "" then |
|||
local wikiText = string.format( 'class="nowrap ts-vertical-header %s %s %s"', vertAlign, noBold, class ) |
|||
⚫ | |||
⚫ | |||
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=\"vertical-rl=-webkit-writing-mode: vertical-rl; -o-writing-mode: vertical-rl; -ms-writing-mode: tb-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" |
|||
-- stupidIEAlign = "left" |
|||
elseif vertAlign == "middle" then |
|||
normalAlign = "center" |
|||
-- stupidIEAlign = "center" |
|||
else |
|||
normalAlign = "left" |
|||
-- stupidIEAlign = "right" |
|||
end |
|||
wikiText = wikiText .. normalAlign .. ";" -- text-align:" .. stupidIEAlign .. " \ ;" |
|||
⚫ | |||
local style = args.style:gsub("\"", """) |
local style = args.style:gsub("\"", """) |
||
wikiText = wikiText .. style .. "\">" |
wikiText = wikiText .. style .. "\">" |
||
-- Add TemplateStyles |
|||
⚫ | |||
⚫ | |||
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 21:28, 19 September 2024
![]() | This is the module sandbox page for Module:Vertical header (diff). |
![]() | 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 class = args.class or ''
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 %s"', vertAlign, noBold, class )
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