Module:Sandbox/Dat Hack3r: Difference between revisions
Jump to navigation
Jump to search
Dat Hack3r (talk | contribs) (Created a prototype of Module:Series navigation.) |
Dat Hack3r (talk | contribs) (Accounted for namespaces.) |
||
Line 5: | Line 5: | ||
function p._main(s_start, s_end, increment, title, title_format, text_format) | function p._main(s_start, s_end, increment, title, title_format, text_format) | ||
title_format = title_format or string.gsub(title, '%d+', '%%d', 1) | title_format = title_format or string.gsub(title.text, '%d+', '%%d', 1) | ||
text_format = text_format or '%d' | text_format = text_format or '%d' | ||
if title_format then | if title_format then | ||
Line 18: | Line 18: | ||
table.insert(navlist, '<span style="visibility: hidden;">'..i..'</span>') | table.insert(navlist, '<span style="visibility: hidden;">'..i..'</span>') | ||
else | else | ||
if mw.title.new(string.format(title_format, i), | if mw.title.new(string.format(title_format, i), title.namespace).exists then | ||
table.insert(navlist, '[['..string.format(title_format, i)..'|'..string.format(text_format, i)..']]') | table.insert(navlist, '[['..title.namespace..string.format(title_format, i)..'|'..string.format(text_format, i)..']]') | ||
else | else | ||
table.insert(navlist, '<span class="seriesNavigation-item-inactive">'..string.format(text_format, i)..'</span>') | table.insert(navlist, '<span class="seriesNavigation-item-inactive">'..string.format(text_format, i)..'</span>') |
Revision as of 17:00, 16 December 2024
Documentation for this module may be created at Module:Sandbox/Dat Hack3r/doc
local p = {}
local horizontal = require('Module:List').horizontal
local mw_error = require('Module:Error').error
function p._main(s_start, s_end, increment, title, title_format, text_format)
title_format = title_format or string.gsub(title.text, '%d+', '%%d', 1)
text_format = text_format or '%d'
if title_format then
curr_num = string.match(title, string.gsub(title_format, "%%d", "(%%d+)"))
else
curr_num = string.match(title, '%d+')
end
local navlist = {}
for i=curr_num - 5,curr_num + 5 do
if i < s_start then
table.insert(navlist, '<span style="visibility: hidden;">'..i..'</span>')
else
if mw.title.new(string.format(title_format, i), title.namespace).exists then
table.insert(navlist, '[['..title.namespace..string.format(title_format, i)..'|'..string.format(text_format, i)..']]')
else
table.insert(navlist, '<span class="seriesNavigation-item-inactive">'..string.format(text_format, i)..'</span>')
end
end
end
templatestyles = mw.getCurrentFrame():extensionTag{
name = "templatestyles",
args = {src = 'Module:Series navigation/styles.css'}
}
return templatestyles..'<div class="toccolours seriesNavigation" role="navigation" aria-label="Range">'..horizontal(navlist)..'</div>'
end
function p.main(frame)
s_start = frame:getParent().args['start'] or 1
s_end = frame:getParent().args['end']
increment = frame:getParent().args['increment'] or 1
title = mw.title.getCurrentTitle()
title_format = frame:getParent().args['title_format']
text_format = frame:getParent().args['text_format']
return p._main(s_start, s_end, increment, title, title_format, text_format)
end
return p