Module:Navbar
From TechInfoDepot
Jump to navigationJump to search
![]() | This Lua module is used on a very large number of pages. To avoid large-scale disruption and unnecessary server load, any changes to this module should first be tested in its /sandbox or /testcases subpages. The tested changes can then be added to this page in one single edit. Please consider discussing any changes on the talk page before implementing them. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
![]() | This module's documentation is missing or does not accurately describe its functionality or the parameters in its code. Please help improve it. |
This is a Lua implementation of {{navbar}}. It is used in Module:Navbox.
The above documentation is transcluded from Module:Navbar/doc. (edit | history) Editors can experiment in this module's sandbox (create | mirror) and testcases (create) pages. Subpages of this module. |
1 local p = {}
2
3 local getArgs
4
5 function p._navbar(args)
6 local titleArg = 1
7
8 if args.collapsible then
9 titleArg = 2
10 if not args.plain then
11 args.mini = 1
12 end
13 if args.fontcolor then
14 args.fontstyle = 'color:' .. args.fontcolor .. ';'
15 end
16 args.style = 'float:left; text-align:left; width:6em;'
17 end
18
19 local titleText = args[titleArg] or (':' .. mw.getCurrentFrame():getParent():getTitle())
20 local title = mw.title.new(mw.text.trim(titleText), 'Template');
21
22 if not title then
23 error('Invalid title ' .. titleText)
24 end
25
26 local talkpage = title.talkPageTitle and title.talkPageTitle.fullText or '';
27
28 local div = mw.html.create():tag('div')
29 div
30 :addClass('plainlinks')
31 :addClass('hlist')
32 :addClass('navbar')
33 :cssText(args.style)
34
35 if args.mini then div:addClass('mini') end
36
37 if not (args.mini or args.plain) then
38 div
39 :tag('span')
40 :css('word-spacing', 0)
41 :cssText(args.fontstyle)
42 :wikitext(args.text or 'This box:')
43 :wikitext(' ')
44 end
45
46 if args.brackets then
47 div
48 :tag('span')
49 :css('margin-right', '-0.125em')
50 :cssText(args.fontstyle)
51 :wikitext('[')
52 :newline();
53 end
54
55 local ul = div:tag('ul');
56
57 ul
58 :tag('li')
59 :addClass('nv-view')
60 :wikitext('[[' .. title.fullText .. '|')
61 :tag('span')
62 :attr('title', 'View this template')
63 :cssText(args.fontstyle)
64 :wikitext(args.mini and 'v' or 'view')
65 :done()
66 :wikitext(']]')
67 :done()
68 :tag('li')
69 :addClass('nv-talk')
70 :wikitext('[[' .. talkpage .. '|')
71 :tag('span')
72 :attr('title', 'Discuss this template')
73 :cssText(args.fontstyle)
74 :wikitext(args.mini and 't' or 'talk')
75 :done()
76 :wikitext(']]');
77
78 if not args.noedit then
79 ul
80 :tag('li')
81 :addClass('nv-edit')
82 :wikitext('[' .. title:fullUrl('action=edit') .. ' ')
83 :tag('span')
84 :attr('title', 'Edit this template')
85 :cssText(args.fontstyle)
86 :wikitext(args.mini and 'e' or 'edit')
87 :done()
88 :wikitext(']');
89 end
90
91 if args.brackets then
92 div
93 :tag('span')
94 :css('margin-left', '-0.125em')
95 :cssText(args.fontstyle)
96 :wikitext(']')
97 :newline();
98 end
99
100 if args.collapsible then
101 div
102 :done()
103 :tag('span')
104 :css('font-size', '110%')
105 :cssText(args.fontstyle)
106 :wikitext(args[1])
107 end
108
109 return tostring(div:done())
110 end
111
112 function p.navbar(frame)
113 if not getArgs then
114 getArgs = require('Module:Arguments').getArgs
115 end
116 return p._navbar(getArgs(frame))
117 end
118
119 return p