Module:Navbar

From blackwiki
Revision as of 14:37, 22 September 2020 by Blackwikiadmin (talk | contribs) (Blackwikiadmin changed the content model of the page Module:Navbar from "wikitext" to "Scribunto")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

{{Navbar}} provides a small "view · talk · edit" navigation bar. It is primarily used for content-heavy templates and other transcluded content blocks, so that the content inside the template or block is more easily editable in situ where it was found, without having track it down through examining transclusion code. {{Navbar}}'s extremely high use rate and consequent protection level are because it is integrated as a feature into numerous navigation box and infobox templates used in millions of articles. It is also a regular feature of many internal-use templates and tables of the Wikipedia, Help, and Template namespaces.

Usage

General

When one of the following examples is placed inside a given template (or block of content used for selective transclusion), it adds basic navbar navigational functionality:

{{navbar|{{subst:PAGENAME}}|mini=y}}
{{navbar|{{subst:PAGENAME}}|plain=y}}
{{navbar|{{subst:PAGENAME}}|fontstyle=color: green; font-style: italic;}}
The {{subst:PAGENAME}} will be substituted with the page name of the real location of the content when parsed by the servers. For example, {{navbar|Navbar/doc}} gives:

When used in content that is selectively transcluded but which is also used as-is in its original location, this template should be wrapped in <includeonly>...</includeonly> markup, so that it only appears when transcluded.

Font size and weight

Font-size is 88% when used in a topical navbar template or in plain text, and 100% when nested in a navbox or infobox (because those templates' text size is already reduced; the "100%" is relative to the surrounding template's own content, not that of the entire page). The |fontstyle= parameter can be used to adjust font size as needed (e.g. to reduce font size even more when the template is used inside a block element with a large font size). Do not abuse this to make excessively small text (i.e. less than 85% of the normal page text), since that causes accessibility problems for many readers.

In a topical navbar, the weight is "normal"; when nested in a navbox or infobox, it inherits the style of the surrounding content. The middot bullets are bold for better visibility.

Examples

Required parameters

  • {{navbar|Template Name}} – the template name is required.

Optional parameters

Options Parameters Produces... "Shortcut" template
Basic {{navbar|Template Name}}
Different text {{navbar|Template Name|text=This template:}}
Without "This box:" text {{navbar|Template Name|plain=y}} {{view}}
Short version {{navbar|Template Name|mini=y}} {{v}}
With brackets {{navbar|Template Name|brackets=y}}
With font styling examples (span) {{navbar|Template Name|fontstyle=color: green; font-style: italic;}}
With whole-template styling examples (div) {{navbar|Template Name|style=float:right; background: Beige; padding: 5px; border: 1px solid;}}

Shortcut templates

The mini=y and plain=y parameters can be avoided by using the {{v}} or {{view}} templates, respectively, instead.

{{view}} and {{v}} also support changing the shown links, for example only view and edit, or only view and talk:

Code Result
{{view|template=view/doc}}
{{view|template=view/doc|talk}}
{{view|template=view/doc|talk|edit}}
{{v|template=v/doc}}
{{v|template=v/doc|t}}
{{v|template=v/doc|t|e}}

Notes

Navbar is contained within a <div>...</div> in order to accommodate a horizontal unnumbered list. This means it cannot be placed inside a <span>...</span> or other inline element, because the HTML Tidy extension will 'fix' situations where it finds block elements inside inline elements.

Prepackaged

{{Navbar-header}}
Positions on the right edge of the line, often used in non-collapsible navbox heading.
{{Navbar-navframe}}
For use in conjunction with NavFrame divs, positions opposite of the [hide]/[show] feature.
{{Navbar-collapsible}}
For use in conjunction with collapsible tables, floats opposite of the [hide]/[show] feature.

See also

[] Compare different edit templates:
  • {{Ed}} —– plain-style edit link surrounded by <small> tags, specifically for templates only
  • {{Ed right}} —– plain-style edit link surrounded by <small> tags and aligned to right of page, specifically for templates only
  • {{Edit}} —– plain-style edit link, applicable to all Wikipedia namespaces
  • {{Edit section}} —– edit link surrounded by <div> tags by default which can specify which section to edit on a page, applicable to all Wikipedia namespaces
  • {{Edit sup}} —– plain-style edit link surrounded by <sup> tags, applicable to all Wikipedia namespaces
  • {{Edit sub}} —– plain-style edit link surrounded by <sub> tags, applicable to all Wikipedia namespaces
  • {{Vedit}} —– plain-style edit link which edit with the Wikipedia:VisualEditor, applicable to all Wikipedia namespaces

Templates with view, talk and edit links:

  • {{Navbar}} —– navigation bar with configurable caption and view·talk·edit links, specifically for templates only
  • {{View}} —– navbar-style view·talk·edit links, specifically for templates only
  • {{VTE}} & {{V}} —– navbar-style V·T·E links (i.e. view·talk·edit links in short forms), specifically for templates only

Other internal link templates, including:

Navigation templates comparison
Collapsible Header color Image Groups Style (body)
parameter/s
Examples
{{Navbox}} collapsible navbox Left/right of body Yes Yes
{{Navbox with collapsible groups}} collapsible navbox Left/right of body and/or in each list Yes Yes
{{Navbox with columns}} collapsible navbox Left/right of columns No Yes
Collapsible attributes
Type CSS classes JavaScript Collapses when Custom
initial state
Nesting
Collapsible tables collapsible Defined in Common.js 2 or more autocollapse on page Yes Yes

TemplateData

This is the TemplateData documentation for this template used by VisualEditor and other tools; see the monthly parameter usage report for this template.

TemplateData for Navbar

When placed inside a given template, it adds navbar navigational functionality

Template parameters

ParameterDescriptionTypeStatus
Template Name

The name of the template, so links work correctly

Default
Stringrequired
Different texttext

Allows custom text to replace the default 'this box'

Default
This box
Stringoptional
Without 'This box:' textplain

Removes 'This box'

Default
0
Numberoptional
Short Versionmini

Shortens text to V T E

Default
0
Numberoptional
with bracketsbrackets

adds brackets before and after the links

Default
0
Numberoptional
Font colorfontstyle

Allows you to change the color of the font (in the format color:green)

Default
Stringoptional
To float to the sidestyle

Allows the template to float to the side (format=float:right)

Default
float:left
Stringoptional

local p = {}

local getArgs
local ul

function p.addItem (mini, full, link, descrip, args, url)
	local l
	if url then
		l = {'[', '', ']'}
	else
		l = {'[[', '|', ']]'}
	end
	ul:tag('li')
		:addClass('nv-'..full)
		:wikitext(l[1] .. link .. l[2])
		:tag(args.mini and 'abbr' or 'span')
			:attr('title', descrip..' this template')
			:cssText(args.fontstyle)
			:wikitext(args.mini and mini or full)
			:done()
		:wikitext(l[3])
end

function p.brackets (position, c, args, div)
	if args.brackets then
		div
			:tag('span')
				:css('margin-'..position, '-0.125em')
				:cssText(args.fontstyle)
				:wikitext(c)
	end
end

function p._navbar(args)
	local show = {true, true, true, false, false, false}
	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'
	end
	
	if args.template then
		titleArg = 'template'
		show = {true, false, false, false, false, false}
		local index = {t = 2, d = 2, e = 3, h = 4, m = 5, w = 6, talk = 2, edit = 3, hist = 4, move = 5, watch = 6}
		for k,v in ipairs(require ('Module:TableTools').compressSparseArray(args)) do
			local num = index[v]
			if num then show[num] = true end
		end
	end
	
	if args.noedit then show[3] = false 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 talkpage = title.talkPageTitle and title.talkPageTitle.fullText or ''
	
	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
	
	p.brackets('right', '&#91; ', args, div)
	
	ul = div:tag('ul')
	if show[1] then p.addItem('v', 'view', title.fullText, 'View', args) end
	if show[2] then p.addItem('t', 'talk', talkpage, 'Discuss', args) end
	if show[3] then p.addItem('e', 'edit', title:fullUrl('action=edit'), 'Edit', args, true) end
	if show[4] then p.addItem('h', 'hist', title:fullUrl('action=history'), 'History of', args, true) end
	if show[5] then
		local move = mw.title.new ('Special:Movepage')
		p.addItem('m', 'move', move:fullUrl('target='..title.fullText), 'Move', args, true) end
	if show[6] then p.addItem('w', 'watch', title:fullUrl('action=watch'), 'Watch', args, true) end
	
	p.brackets('left', ' &#93;', args, div)
	
	if args.collapsible then
		div
			:done()
		:tag('div')
			:css('font-size', '114%')
			:css('margin', args.mini and '0 4em' or '0 7em')
			: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