Module:Sandbox/Dat Hack3r: Difference between revisions
Jump to navigation
Jump to search
Dat Hack3r (talk | contribs) (Fixed overly-limited scope of "curr_num".) |
Dat Hack3r (talk | contribs) m (Integrated "prepad" and "postpad" for seamless hidden spacing in navigation.) |
||
Line 15: | Line 15: | ||
local navlist = {} | local navlist = {} | ||
local prepad = '' | |||
local postpad = '' | |||
for i=curr_num - 5,curr_num + 5 do | for i=curr_num - 5,curr_num + 5 do | ||
if i < s_start then | if i < s_start then | ||
prepad = prepad..'<span style="visibility: hidden;"> • '..string.format(text_format, i)..'</span>' | |||
elseif i > s_end then | |||
postpad = postpad..'<span style="visibility: hidden;"> • '..string.format(text_format, i)..'</span>' | |||
else | else | ||
if mw.title.new(string.format(title_format, i), title.namespace).exists then | if mw.title.new(string.format(title_format, i), title.namespace).exists then | ||
Line 31: | Line 35: | ||
args = {src = 'Module:Series navigation/styles.css'} | args = {src = 'Module:Series navigation/styles.css'} | ||
} | } | ||
return templatestyles..'<div class="toccolours seriesNavigation" role="navigation" aria-label="Range">'..horizontal(navlist)..'</div>' | return templatestyles..'<div class="toccolours seriesNavigation" role="navigation" aria-label="Range">'..prepad..horizontal(navlist)..postpad..'</div>' | ||
end | end | ||
Revision as of 17:29, 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'
local curr_num
if title_format then
curr_num = tonumber(string.match(title.text, string.gsub(title_format, "%%d", "(%%d+)")))
else
curr_num = tonumber(string.match(title.text, '%d+'))
end
local navlist = {}
local prepad = ''
local postpad = ''
for i=curr_num - 5,curr_num + 5 do
if i < s_start then
prepad = prepad..'<span style="visibility: hidden;"> • '..string.format(text_format, i)..'</span>'
elseif i > s_end then
postpad = postpad..'<span style="visibility: hidden;"> • '..string.format(text_format, 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
local templatestyles = mw.getCurrentFrame():extensionTag{
name = "templatestyles",
args = {src = 'Module:Series navigation/styles.css'}
}
return templatestyles..'<div class="toccolours seriesNavigation" role="navigation" aria-label="Range">'..prepad..horizontal(navlist)..postpad..'</div>'
end
function p.main(frame)
local s_start = frame:getParent().args['start'] or 1
local s_end = frame:getParent().args['end']
local increment = frame:getParent().args['increment'] or 1
local title = mw.title.getCurrentTitle()
local title_format = frame:getParent().args['title_format']
local text_format = frame:getParent().args['text_format']
return p._main(s_start, s_end, increment, title, title_format, text_format)
end
return p