Moduł:Lepsze główne: Różnice pomiędzy wersjami
Z Nonsensopedii, polskiej encyklopedii humoru
Polskacafe (dyskusja • edycje) M (optymalizacja wyjścia część 2 (BŁAGAM NIECH TO SIĘ NIE ROZWALI)) |
Polskacafe (dyskusja • edycje) |
||
(Nie pokazano 4 pośrednich wersji utworzonych przez tego samego użytkownika) | |||
Linia 23: | Linia 23: | ||
local final = allowOnly(value, {"desktoponly", "mobileonly"}, '') |
local final = allowOnly(value, {"desktoponly", "mobileonly"}, '') |
||
if final == "desktoponly" then |
if final == "desktoponly" then |
||
return {desktoponly=true, mobileonly=false} |
return {desktoponly=true, mobileonly=false, duplicateDesktoponly=false, duplicateMobileonly=false} |
||
elseif final == "mobileonly" then |
elseif final == "mobileonly" then |
||
return {desktoponly=false, mobileonly=true} |
return {desktoponly=false, mobileonly=true, duplicateDesktoponly=false, duplicateMobileonly=false} |
||
else |
else |
||
return {desktoponly=false, mobileonly=false} |
return {desktoponly=false, mobileonly=false, duplicateDesktoponly=false, duplicateMobileonly=false} |
||
end |
end |
||
end |
end |
||
Linia 33: | Linia 33: | ||
function showStatusToString(stat) |
function showStatusToString(stat) |
||
local val = "" |
local val = "" |
||
if stat["desktoponly"] then |
if stat["desktoponly"] or stat["duplicateDesktoponly"] then |
||
val = val .. "desktoponly " |
val = val .. "desktoponly " |
||
end |
end |
||
if stat["mobileonly"] then |
if stat["mobileonly"] or stat["duplicateMobileonly"] then |
||
val = val .. "mobileonly" |
val = val .. "mobileonly" |
||
end |
end |
||
return mw.text.trim(val) |
return mw.text.trim(val) |
||
end |
|||
function getShowStatusForPlatform(stat, platform) |
|||
if platform == "desktop" then |
|||
return stat.desktoponly or stat.duplicateDesktoponly |
|||
elseif platform == "mobile" then |
|||
return stat.mobileonly or stat.duplicateMobileonly |
|||
end |
|||
end |
|||
function willEverBeUsed(cur) |
|||
return not ((getShowStatusForPlatform(cur.showstatus, "desktop") == getShowStatusForPlatform(cur.showstatus, "mobile")) and (getShowStatusForPlatform(cur.showstatus, "desktop") == true)) |
|||
end |
end |
||
function makeElementTable(args, num) |
function makeElementTable(args, num) |
||
local cur = {} |
local cur = {} |
||
if args['ptytułszablon' .. num] ~= nil then |
|||
cur['title'] = '{{' .. mw.text.nowiki(args['ptytułszablon' .. num]) .. '}}' |
|||
else |
|||
cur['title'] = sanitizeOrElse(args['ptytuł' .. num], 'Nie podano tytułu') |
|||
end |
|||
cur['text'] = sanitizeOrElse(args['panel' .. num], '') |
cur['text'] = sanitizeOrElse(args['panel' .. num], '') |
||
cur['num'] = num |
cur['num'] = num |
||
Linia 50: | Linia 66: | ||
cur['icon'] = sanitizeOrElse(args['pikona' .. num], '') |
cur['icon'] = sanitizeOrElse(args['pikona' .. num], '') |
||
cur['iconlink'] = sanitizeOrElse(args["pikonalink" .. num], '') |
cur['iconlink'] = sanitizeOrElse(args["pikonalink" .. num], '') |
||
cur['titlelink'] = sanitizeOrElse(args["plink" .. num], '') |
|||
return cur |
return cur |
||
end |
end |
||
Linia 58: | Linia 75: | ||
local first = {} |
local first = {} |
||
local second = {} |
local second = {} |
||
local curRight = 0 |
local curLeft, curRight = 0, 0 |
||
for i = 1, 50 do |
for i = 1, 50 do |
||
if args['panel' .. i] ~= nil then |
if args['panel' .. i] ~= nil then |
||
Linia 65: | Linia 82: | ||
if i % 2 == 1 then |
if i % 2 == 1 then |
||
table.insert(first, cur) |
table.insert(first, cur) |
||
curRight = 0 |
curLeft, curRight = 0, 0 |
||
else |
else |
||
cur.showstatus. |
cur.showstatus.duplicateDesktoponly = true |
||
if willEverBeUsed(cur) then |
|||
if not ((cur.showstatus.desktoponly == cur.showstatus.mobileonly) and (cur.showstatus.desktoponly == true)) then |
|||
table.insert(second, cur) |
table.insert(second, cur) |
||
curRight = curRight + 1 |
|||
end |
end |
||
local cur2 = makeElementTable(args, i) |
local cur2 = makeElementTable(args, i) |
||
cur2.showstatus. |
cur2.showstatus.duplicateMobileonly = true |
||
if willEverBeUsed(cur2) then |
|||
if not ((cur2.showstatus.desktoponly == cur2.showstatus.mobileonly) and (cur2.showstatus.desktoponly == true)) then |
|||
table.insert(first, cur2) |
table.insert(first, cur2) |
||
curLeft = curLeft + 1 |
|||
end |
end |
||
end |
end |
||
Linia 82: | Linia 100: | ||
end |
end |
||
if curRight > 0 then |
if curRight > 0 then |
||
⚫ | |||
local maxSecond = table.maxn(second) |
local maxSecond = table.maxn(second) |
||
for i = 0, (curRight - 1) do |
for i = 0, (curRight - 1) do |
||
⚫ | |||
end |
|||
end |
|||
if curLeft > 0 then |
|||
⚫ | |||
for i = 0, (curLeft - 1) do |
|||
table.remove(first, maxFirst-i) |
table.remove(first, maxFirst-i) |
||
⚫ | |||
end |
end |
||
end |
end |
||
Linia 95: | Linia 117: | ||
function makePanel(tab) |
function makePanel(tab) |
||
local panelname = tab["title"] |
local panelname = tab["title"] |
||
local titlelink = tab["titlelink"] |
|||
local template = tab["text"] |
local template = tab["text"] |
||
local mobiledesktop = showStatusToString(tab["showstatus"]) |
local mobiledesktop = showStatusToString(tab["showstatus"]) |
||
Linia 100: | Linia 123: | ||
local iconlink = tab["iconlink"] |
local iconlink = tab["iconlink"] |
||
local id = "panel-" .. tab["num"] .. "-" .. mw.text.encode(panelname) |
local id = "panel-" .. tab["num"] .. "-" .. mw.text.encode(panelname) |
||
local wikitext = "{{User:Polskacafe/panel|" .. panelname .. "|{{" .. template .. "}}|ikona=" .. icon .. "|link=" .. iconlink .. "}}" |
local wikitext = "{{User:Polskacafe/panel|" .. panelname .. "|{{" .. template .. "}}|ikona=" .. icon .. "|link=" .. iconlink .. "|tytuł link=" .. titlelink .. "}}" |
||
local panel = mw.html.create("div") |
local panel = mw.html.create("div") |
||
:addClass("glowna-panel") |
:addClass("glowna-panel") |
Aktualna wersja na dzień 03:00, 2 kwi 2022
Moduł automatycznie generujący semi-responsywny kolumnowy układ stron głównych. Zobacz też: Szablon:Generator głównych
local tools = require('Moduł:Narzędzia')
local p = {}
function sanitizeOrElse(text, alt)
if text ~= nil then
return mw.text.nowiki(text)
else
return alt
end
end
function allowOnly(value, allowed, alt)
local sanitized = mw.text.trim(sanitizeOrElse(value, alt))
for k, v in ipairs(allowed) do
if v == sanitized then
return sanitized
end
end
return alt
end
function makeShowStatus(value)
local final = allowOnly(value, {"desktoponly", "mobileonly"}, '')
if final == "desktoponly" then
return {desktoponly=true, mobileonly=false, duplicateDesktoponly=false, duplicateMobileonly=false}
elseif final == "mobileonly" then
return {desktoponly=false, mobileonly=true, duplicateDesktoponly=false, duplicateMobileonly=false}
else
return {desktoponly=false, mobileonly=false, duplicateDesktoponly=false, duplicateMobileonly=false}
end
end
function showStatusToString(stat)
local val = ""
if stat["desktoponly"] or stat["duplicateDesktoponly"] then
val = val .. "desktoponly "
end
if stat["mobileonly"] or stat["duplicateMobileonly"] then
val = val .. "mobileonly"
end
return mw.text.trim(val)
end
function getShowStatusForPlatform(stat, platform)
if platform == "desktop" then
return stat.desktoponly or stat.duplicateDesktoponly
elseif platform == "mobile" then
return stat.mobileonly or stat.duplicateMobileonly
end
end
function willEverBeUsed(cur)
return not ((getShowStatusForPlatform(cur.showstatus, "desktop") == getShowStatusForPlatform(cur.showstatus, "mobile")) and (getShowStatusForPlatform(cur.showstatus, "desktop") == true))
end
function makeElementTable(args, num)
local cur = {}
if args['ptytułszablon' .. num] ~= nil then
cur['title'] = '{{' .. mw.text.nowiki(args['ptytułszablon' .. num]) .. '}}'
else
cur['title'] = sanitizeOrElse(args['ptytuł' .. num], 'Nie podano tytułu')
end
cur['text'] = sanitizeOrElse(args['panel' .. num], '')
cur['num'] = num
cur['showstatus'] = makeShowStatus(args["pwarunki" .. num])
cur['icon'] = sanitizeOrElse(args['pikona' .. num], '')
cur['iconlink'] = sanitizeOrElse(args["pikonalink" .. num], '')
cur['titlelink'] = sanitizeOrElse(args["plink" .. num], '')
return cur
end
-- robi listę elementów wg kolumn, ignoruje - i puste
function makeElementList(args)
-- kolumny
local first = {}
local second = {}
local curLeft, curRight = 0, 0
for i = 1, 50 do
if args['panel' .. i] ~= nil then
if args['panel' .. i] == '-' or args['panel' .. i] == '' then else
local cur = makeElementTable(args, i)
if i % 2 == 1 then
table.insert(first, cur)
curLeft, curRight = 0, 0
else
cur.showstatus.duplicateDesktoponly = true
if willEverBeUsed(cur) then
table.insert(second, cur)
curRight = curRight + 1
end
local cur2 = makeElementTable(args, i)
cur2.showstatus.duplicateMobileonly = true
if willEverBeUsed(cur2) then
table.insert(first, cur2)
curLeft = curLeft + 1
end
end
end
else break end
end
if curRight > 0 then
local maxSecond = table.maxn(second)
for i = 0, (curRight - 1) do
second[maxSecond-i].showstatus.duplicateDesktoponly = false
end
end
if curLeft > 0 then
local maxFirst = table.maxn(first)
for i = 0, (curLeft - 1) do
table.remove(first, maxFirst-i)
end
end
return first, second
end
function makePanel(tab)
local panelname = tab["title"]
local titlelink = tab["titlelink"]
local template = tab["text"]
local mobiledesktop = showStatusToString(tab["showstatus"])
local icon = tab["icon"]
local iconlink = tab["iconlink"]
local id = "panel-" .. tab["num"] .. "-" .. mw.text.encode(panelname)
local wikitext = "{{User:Polskacafe/panel|" .. panelname .. "|{{" .. template .. "}}|ikona=" .. icon .. "|link=" .. iconlink .. "|tytuł link=" .. titlelink .. "}}"
local panel = mw.html.create("div")
:addClass("glowna-panel")
:attr("id", id)
:wikitext(wikitext)
if (mobiledesktop ~= nil) then
panel = panel:addClass(mobiledesktop)
end
return panel:done()
end
function makeColumn(elements)
column = mw.html.create("div")
:addClass("glowna-kolumna")
for k,v in ipairs(elements) do
local elem = makePanel(v)
column = column:node(elem)
end
return column:done()
end
function makeAll(args)
local first, second = makeElementList(args)
local mainList = mw.html.create("div")
:addClass("glowna-lista")
:node(makeColumn(first))
:node(makeColumn(second))
:done()
return mainList
end
function p.kolumny(frame)
local args = tools.getArgs(frame) -- argumenty szablonu to jest
local mainList = makeAll(args)
return frame:preprocess(tostring(mainList))
end
return p