モジュール:Navbar
このモジュールについての説明文ページを モジュール:Navbar/doc に作成できます
1 local p = {}
2
3 local getArgs
4 local ul
5
6 function p.addItem (mini, full, link, descrip, args, url)
7 local l
8 if url then
9 l = {'[', '', ']'}
10 else
11 l = {'[[', '|', ']]'}
12 end
13 ul:tag('li')
14 :addClass('nv-'..full)
15 :wikitext(l[1] .. link .. l[2])
16 :tag(args.mini and 'abbr' or 'span')
17 :attr('title', descrip..' this template')
18 :cssText(args.fontstyle)
19 :wikitext(args.mini and mini or full)
20 :done()
21 :wikitext(l[3])
22 end
23
24 function p.brackets (position, c, args, div)
25 if args.brackets then
26 div
27 :tag('span')
28 :css('margin-'..position, '-0.125em')
29 :cssText(args.fontstyle)
30 :wikitext(c)
31 end
32 end
33
34 function p._navbar(args)
35 local show = {true, true, true, false, false, false}
36 local titleArg = 1
37
38 if args.collapsible then
39 titleArg = 2
40 if not args.plain then args.mini = 1 end
41 if args.fontcolor then
42 args.fontstyle = 'color:' .. args.fontcolor .. ';'
43 end
44 args.style = 'float:left; text-align:left'
45 end
46
47 if args.template then
48 titleArg = 'template'
49 show = {true, false, false, false, false, false}
50 local index = {t = 2, d = 2, e = 3, h = 4, m = 5, w = 6, talk = 2, edit = 3, hist = 4, move = 5, watch = 6}
51 for k,v in ipairs(require ('Module:TableTools').compressSparseArray(args)) do
52 local num = index[v]
53 if num then show[num] = true end
54 end
55 end
56
57 if args.noedit then show[3] = false end
58
59 local titleText = args[titleArg] or (':' .. mw.getCurrentFrame():getParent():getTitle())
60 local title = mw.title.new(mw.text.trim(titleText), 'Template')
61 if not title then
62 error('Invalid title ' .. titleText)
63 end
64 local talkpage = title.talkPageTitle and title.talkPageTitle.fullText or ''
65
66 local div = mw.html.create():tag('div')
67 div
68 :addClass('plainlinks')
69 :addClass('hlist')
70 :addClass('navbar')
71 :cssText(args.style)
72
73 if args.mini then div:addClass('mini') end
74
75 if not (args.mini or args.plain) then
76 div
77 :tag('span')
78 :css('word-spacing', 0)
79 :cssText(args.fontstyle)
80 :wikitext(args.text or 'This box:')
81 :wikitext(' ')
82 end
83
84 p.brackets('right', '[ ', args, div)
85
86 ul = div:tag('ul')
87 if show[1] then p.addItem('v', 'view', title.fullText, 'View', args) end
88 if show[2] then p.addItem('t', 'talk', talkpage, 'Discuss', args) end
89 if show[3] then p.addItem('e', 'edit', title:fullUrl('action=edit'), 'Edit', args, true) end
90 if show[4] then p.addItem('h', 'hist', title:fullUrl('action=history'), 'History of', args, true) end
91 if show[5] then
92 local move = mw.title.new ('Special:Movepage')
93 p.addItem('m', 'move', move:fullUrl('target='..title.fullText), 'Move', args, true) end
94 if show[6] then p.addItem('w', 'watch', title:fullUrl('action=watch'), 'Watch', args, true) end
95
96 p.brackets('left', ' ]', args, div)
97
98 if args.collapsible then
99 div
100 :done()
101 :tag('div')
102 :css('font-size', '114%')
103 :css('margin', args.mini and '0 4em' or '0 7em')
104 :cssText(args.fontstyle)
105 :wikitext(args[1])
106 end
107
108 -- DELIBERATE DELTA FROM EN.WP THAT INTEGRATES HLIST TSTYLES
109 -- CARE WHEN SYNCING
110 local frame = mw.getCurrentFrame()
111 return frame:extensionTag{
112 name = 'templatestyles', args = { src = 'Flatlist/styles.css' }
113 } .. frame:extensionTag{
114 name = 'templatestyles', args = { src = 'Module:Navbar/styles.css' }
115 } .. tostring(div:done())
116 end
117
118 function p.navbar(frame)
119 if not getArgs then
120 getArgs = require('Module:Arguments').getArgs
121 end
122 return p._navbar(getArgs(frame))
123 end
124
125 return p