Module:Pagination: Difference between revisions
From Growtopia
Jump to navigationJump to search
>HashJona No edit summary |
>HashJona No edit summary |
||
| Line 81: | Line 81: | ||
function p.test(frame) | function p.test(frame) | ||
local args = frame.args | local args = frame.args | ||
local totalVal = args.total | local totalVal = tonumber(args.total or "0") or 0 | ||
return "Debug: total param is: " .. tostring(totalVal) | return "Debug: total param is: " .. tostring(totalVal) | ||
end | end | ||
return p | return p | ||
Revision as of 19:35, 8 March 2025
Documentation for this module may be created at Module:Pagination/doc
local p = {}
function p.pagination(frame)
local args = frame.args
local paramName = args.param or "offset"
local offsetVal = tonumber(args.offset or "0") or 0
local countVal = tonumber(args.count or "0") or 0
local totalVal = tonumber(args.total or "0") or 0
local debug = args.debug or "0"
local prevOffset = math.max(0, offsetVal - countVal)
local nextOffset = offsetVal + countVal
local lastOffset = 0
if countVal > 0 then
lastOffset = math.floor((totalVal - 1) / countVal) * countVal
if lastOffset < 0 then
lastOffset = 0
end
end
local out = {}
local function w(line) table.insert(out, line) end
if debug == "1" then
w('{| class="wikitable" style="margin:1em auto;"')
w('|-')
w('! colspan="2" | Debug Information')
w('|-')
w('| param')
w('| ' .. paramName .. ' <small>(default: offset)</small>')
w('|-')
w('| offset')
w('| ' .. offsetVal .. ' <small>(default: 0)</small>')
w('|-')
w('| count')
w('| ' .. countVal .. ' <small>(default: 0)</small>')
w('|-')
w('| total')
w('| ' .. totalVal .. ' <small>(default: 0)</small>')
w('|}')
end
w('<div class="category-page__pagination" style="display:flex; justify-content: space-between; width:100%">')
w('<div>')
if offsetVal > 0 then
local firstLink = frame:callParserFunction('fullurl', {
mw.title.getCurrentTitle().prefixedText,
paramName .. "=0"
})
w(string.format('[%s <span class="wds-button wds-is-text">First</span>]', firstLink))
local prevLink = frame:callParserFunction('fullurl', {
mw.title.getCurrentTitle().prefixedText,
paramName .. "=" .. prevOffset
})
w(string.format('[%s <span class="category-page__pagination-prev wds-button wds-is-secondary">< Previous</span>]', prevLink))
end
w('</div><div>')
if (offsetVal + countVal) < totalVal then
local nextLink = frame:callParserFunction('fullurl', {
mw.title.getCurrentTitle().prefixedText,
paramName .. "=" .. nextOffset
})
w(string.format('[%s <span class="category-page__pagination-prev wds-button wds-is-secondary">Next ></span>]', nextLink))
local lastLink = frame:callParserFunction('fullurl', {
mw.title.getCurrentTitle().prefixedText,
paramName .. "=" .. lastOffset
})
w(string.format('[%s <span class="wds-button wds-is-text">Last</span>]', lastLink))
end
w('</div></div>')
return table.concat(out, '\n')
end
function p.test(frame)
local args = frame.args
local totalVal = tonumber(args.total or "0") or 0
return "Debug: total param is: " .. tostring(totalVal)
end
return p