Module:Sandbox/Dat Hack3r: Difference between revisions
Appearance
Dat Hack3r (talk | contribs) Accounted for namespaces. |
Dat Hack3r (talk | contribs) m Forgot to add the colon (":") after the namespace. |
||
(9 intermediate revisions by the same user not shown) | |||
Line 7: | Line 7: | ||
title_format = title_format or string.gsub(title.text, '%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' | ||
local curr_num | |||
if title_format then | if title_format then | ||
curr_num = string.match(title, string.gsub(title_format, "%%d", "(%%d+)")) | curr_num = tonumber(string.match(title.text, string.gsub(title_format, "%%d", "(%%d+)"))) | ||
else | else | ||
curr_num = string.match(title, '%d+') | curr_num = tonumber(string.match(title.text, '%d+')) | ||
end | end | ||
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 s_end and 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 | ||
table.insert(navlist, '[['..title. | table.insert(navlist, '[['..title.nsText..':'..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>') | ||
Line 25: | Line 30: | ||
end | end | ||
end | end | ||
navlist[1] = prepad..navlist[1] | |||
navlist[#navlist] = navlist[#navlist]..postpad | |||
templatestyles = mw.getCurrentFrame():extensionTag{ | local templatestyles = mw.getCurrentFrame():extensionTag{ | ||
name = "templatestyles", | name = "templatestyles", | ||
args = {src = 'Module:Series navigation/styles.css'} | args = {src = 'Module:Series navigation/styles.css'} | ||
Line 34: | Line 41: | ||
function p.main(frame) | function p.main(frame) | ||
s_start = frame:getParent().args['start'] or 1 | local s_start = tonumber(frame:getParent().args['start']) or 1 | ||
s_end = frame:getParent().args['end'] | local s_end = tonumber(frame:getParent().args['end']) | ||
increment = frame:getParent().args['increment'] or 1 | local increment = tonumber(frame:getParent().args['increment']) or 1 | ||
title = mw.title.getCurrentTitle() | local title = mw.title.getCurrentTitle() | ||
title_format = frame:getParent().args['title_format'] | local title_format = frame:getParent().args['title_format'] | ||
text_format = frame:getParent().args['text_format'] | local text_format = frame:getParent().args['text_format'] | ||
return p._main(s_start, s_end, increment, title, title_format, text_format) | return p._main(s_start, s_end, increment, title, title_format, text_format) | ||
end | end | ||
return p | return p |