Module:Navbar/sandbox: Difference between revisions

Content deleted Content added
use mw.html
Jackmcbarn (talk | contribs)
inherit line height on the ul
Line 2:
 
local getArgs
local HtmlBuilder = require('Module:HtmlBuilder')
 
local function trim(s)
Line 8 ⟶ 9:
 
local function htmlError(s)
local span = mw.htmlHtmlBuilder.create('span')
 
span
:.addClass('error')
:.css('float', 'left')
:.css('white-space', 'nowrap')
:.wikitext('Error: ' .. s)
 
return tostring(span)
Line 71 ⟶ 72:
end
 
local div = mw.htmlHtmlBuilder.create():.tag('div')
div
:.addClass('plainlinks')
:.addClass('hlist')
:.addClass('navbar')
:.cssText(args.style)
 
if args.mini then div:.addClass('mini') end
 
if not (args.mini or args.plain) then
div
:.tag('span')
:.css('word-spacing', 0)
:.cssText(args.fontstyle)
:.wikitext(args.text or 'This box:')
:.wikitext(' ')
end
 
if args.brackets then
div
:.tag('span')
:.css('margin-right', '-0.125em')
:.cssText(args.fontstyle)
:.wikitext('[')
:.newline();
end
 
local ul = div:.tag('ul');
.css('line-height', 'inherit'); -- otherwise, the default ul line height makes this take up 2 lines in navboxes, and makes the second line off-center
 
ul
:.tag('li')
:.addClass('nv-view')
:.wikitext('[[' .. mainpage .. '|')
:.tag('span')
:.attr('title', 'View this template')
:.cssText(args.fontstyle or '')
:.wikitext(viewLink)
:.done()
:.wikitext(']]')
:.done()
:.tag('li')
:.addClass('nv-talk')
:.wikitext('[[' .. talkpage .. '|')
:.tag('span')
:.attr('title', 'Discuss this template')
:.cssText(args.fontstyle or '')
:.wikitext(talkLink)
:.done()
:.wikitext(']]');
 
if not args.noedit then
ul
:.tag('li')
:.addClass('nv-edit')
:.wikitext('[' .. editurl .. ' ')
:.tag('span')
:.attr('title', 'Edit this template')
:.cssText(args.fontstyle or '')
:.wikitext(editLink)
:.done()
:.wikitext(']');
end
 
if args.brackets then
div
:.tag('span')
:.css('margin-left', '-0.125em')
:.cssText( args.fontstyle or '')
:.wikitext(']')
:.newline();
end
if args.collapsible then
div
:.done()
:.tag('span')
:.css('font-size', '110%')
:.cssText(args.fontstyle or '')
:.wikitext(args[1])
end
 
return tostring(div:.allDone())
end