Difference between revisions of "Module:Navbar/sandbox"

From blackwiki
Jump to navigation Jump to search
test>Jackmcbarn
(rm 2 unnecessary functions)
test>Jackmcbarn
(various simplifications)
Line 29: Line 29:
 
local editurl = title:fullUrl('action=edit');
 
local editurl = title:fullUrl('action=edit');
  
local viewLink, talkLink, editLink = 'view', 'talk', 'edit'
+
local viewLink, talkLink, editLink
 
if args.mini then
 
if args.mini then
 
viewLink, talkLink, editLink = 'v', 't', 'e'
 
viewLink, talkLink, editLink = 'v', 't', 'e'
 +
else
 +
viewLink, talkLink, editLink = 'view', 'talk', 'edit'
 
end
 
end
  
Line 69: Line 71:
 
:tag('span')
 
:tag('span')
 
:attr('title', 'View this template')
 
:attr('title', 'View this template')
:cssText(args.fontstyle or '')
+
:cssText(args.fontstyle)
 
:wikitext(viewLink)
 
:wikitext(viewLink)
 
:done()
 
:done()
Line 79: Line 81:
 
:tag('span')
 
:tag('span')
 
:attr('title', 'Discuss this template')
 
:attr('title', 'Discuss this template')
:cssText(args.fontstyle or '')
+
:cssText(args.fontstyle)
 
:wikitext(talkLink)
 
:wikitext(talkLink)
 
:done()
 
:done()
Line 91: Line 93:
 
:tag('span')
 
:tag('span')
 
:attr('title', 'Edit this template')
 
:attr('title', 'Edit this template')
:cssText(args.fontstyle or '')
+
:cssText(args.fontstyle)
 
:wikitext(editLink)
 
:wikitext(editLink)
 
:done()
 
:done()
Line 101: Line 103:
 
:tag('span')
 
:tag('span')
 
:css('margin-left', '-0.125em')
 
:css('margin-left', '-0.125em')
:cssText( args.fontstyle or '')
+
:cssText(args.fontstyle)
 
:wikitext(']')
 
:wikitext(']')
 
:newline();
 
:newline();
Line 111: Line 113:
 
:tag('span')
 
:tag('span')
 
:css('font-size', '110%')
 
:css('font-size', '110%')
:cssText(args.fontstyle or '')
+
:cssText(args.fontstyle)
 
:wikitext(args[1])
 
:wikitext(args[1])
 
end
 
end
  
return tostring(div:allDone())
+
return tostring(div:done())
 
end
 
end
  

Revision as of 20:40, 30 November 2014

Documentation for this module may be created at Module:Navbar/sandbox/doc

local p = {}

local getArgs

function p._navbar(args)
	local titleArg = 1
	
	if args.collapsible then
		titleArg = 2
		if not args.plain then
			args.mini = 1
		end
		if args.fontcolor then
			args.fontstyle = 'color:' .. args.fontcolor .. ';'
		end
		args.style = 'float:left; text-align:left; width:6em;'
	end
	
	local titleText = args[titleArg] or (':' .. mw.getCurrentFrame():getParent():getTitle())
	local title = mw.title.new(mw.text.trim(titleText), 'Template');

	if not title then
		error('Invalid title ' .. titleText)
	end

	local talk_title = title.talkPageTitle;
	local mainpage = title.fullText;
	local talkpage = talk_title and talk_title.fullText or ''
	local editurl = title:fullUrl('action=edit');

	local viewLink, talkLink, editLink
	if args.mini then
		viewLink, talkLink, editLink = 'v', 't', 'e'
	else
		viewLink, talkLink, editLink = 'view', 'talk', 'edit'
	end

	local div = mw.html.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');

	ul
		:tag('li')
			:addClass('nv-view')
			:wikitext('[[' .. mainpage .. '|')
			:tag('span')
				:attr('title', 'View this template')
				:cssText(args.fontstyle)
				:wikitext(viewLink)
				:done()
			:wikitext(']]')
			:done()
		:tag('li')
			:addClass('nv-talk')
			:wikitext('[[' .. talkpage .. '|')
			:tag('span')
				:attr('title', 'Discuss this template')
				:cssText(args.fontstyle)
				: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)
					:wikitext(editLink)
					:done()
				:wikitext(']');
	end

	if args.brackets then
		div
			:tag('span')
				:css('margin-left', '-0.125em')
				:cssText(args.fontstyle)
				:wikitext(']')
				:newline();
	end
	
	if args.collapsible then
		div
			:done()
		:tag('span')
			:css('font-size', '110%')
			:cssText(args.fontstyle)
			:wikitext(args[1])
	end

	return tostring(div:done())
end

function p.navbar(frame)
	if not getArgs then
		getArgs = require('Module:Arguments').getArgs
	end
	return p._navbar(getArgs(frame))
end

return p