Модуль:Карточка: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки Метки: с мобильного устройства из мобильной версии через расширенный мобильный режим |
||
| (не показаны 4 промежуточные версии этого же участника) | |||
| Строка 1: | Строка 1: | ||
-- DRUID Infobox. | -- DRUID Infobox. | ||
-- source: https://support.wiki.gg/wiki/Module:Infobox | -- source: https://support.wiki.gg/wiki/Module:Infobox | ||
-- license: | -- license: CC BY-SA 4.0 | ||
-- version 0.1.7 | -- version 0.1.7 | ||
| Строка 17: | Строка 17: | ||
-- set to `nil` (not in quotes) to remove such rows altogether in the tabs where they're missing | -- set to `nil` (not in quotes) to remove such rows altogether in the tabs where they're missing | ||
local TABBED_NONEXIST = nil -- `''` or `nil` or `'N/A'` etc. Don't put nil in quotes. | local TABBED_NONEXIST = nil -- `''` or `nil` or `'N/A'` etc. Don't put nil in quotes. | ||
local SKIP_SECTIONS_DEFAULT = 2 | |||
--------------------------------------------------------------------------- | --------------------------------------------------------------------------- | ||
| Строка 47: | Строка 48: | ||
local sep = args.sep or ',' | local sep = args.sep or ',' | ||
h.castArgs(args, sep) | h.castArgs(args, sep) | ||
local skip = tonumber(args.skipSections) or SKIP_SECTIONS_DEFAULT | |||
h.skipSections = skip | |||
h.printCount = 0 | |||
if h.castBool(args.setmainimage or 'yes') then | if h.castBool(args.setmainimage or 'yes') then | ||
--h.setMainImage(args.images[1]) | |||
end | end | ||
-- suggest to use HIDDENCAT here; will be used for maintenance & gadget imports | |||
local output = h.makeInfobox(args, sep) | |||
local finalOutput = tostring(output) | |||
return frame:preprocess(finalOutput) | |||
end | end | ||
| Строка 134: | Строка 138: | ||
function h.setMainImage(file) | function h.setMainImage(file) | ||
if h.counter > 1 then return end | if h.counter > 1 then return end | ||
if not file then return end | |||
local fileText = file:gsub('.-:', '') | |||
fileText = fileText:gsub('^([^|%]]+).*', '%1') | fileText = fileText:gsub('^([^|%]]+).*', '%1') | ||
-- setmainimage is guaranteed to exist on wiki.gg but may not exist on other wikis | -- setmainimage is guaranteed to exist on wiki.gg but may not exist on other wikis | ||
| Строка 152: | Строка 156: | ||
:addClass(args.class) -- warning: class can be nil, don't concat anything | :addClass(args.class) -- warning: class can be nil, don't concat anything | ||
:attr('id', args.id or ('druid-container-' .. h.counter)) | :attr('id', args.id or ('druid-container-' .. h.counter)) | ||
if args.style then | |||
out:cssText(args.style) | |||
end | |||
h.runHook('onMakeOutputStart', out, args) | h.runHook('onMakeOutputStart', out, args) | ||
if args.kind then out:addClass('druid-container-' .. h.escape(args.kind)) end | if args.kind then out:addClass('druid-container-' .. h.escape(args.kind)) end | ||
| Строка 157: | Строка 166: | ||
h.printImages(out, args.images, args) | h.printImages(out, args.images, args) | ||
for _, section in ipairs(args.sections) do | for _, section in ipairs(args.sections) do | ||
local cols = args[section .. '_columns'] | local cols = args[section .. '_columns'] | ||
local makeSection = cols and h.makeGridSection or h.makeSection | local makeSection = cols and h.makeGridSection or h.makeSection | ||
local secNode = makeSection(section, args[section], args, tonumber(cols)) | |||
if secNode then | |||
out:node(secNode) | |||
end | |||
end | end | ||
h.runHook('onMakeOutputEnd', out, args) | h.runHook('onMakeOutputEnd', out, args) | ||
| Строка 378: | Строка 389: | ||
local shouldPrintItem = h.printData(node, item, section, args) | local shouldPrintItem = h.printData(node, item, section, args) | ||
if shouldPrintItem then | if shouldPrintItem then | ||
h.printCount = h.printCount + 1 | |||
shouldPrint = true | shouldPrint = true | ||
local tr = container:tag(h.getTag('row')) | local tr = container:tag(h.getTag('row')) | ||
| Строка 421: | Строка 433: | ||
local a, b = sizeOfLastRow, numCols | local a, b = sizeOfLastRow, numCols | ||
while b ~= 0 do | while b ~= 0 do | ||
a, b = b, a % b | |||
end | end | ||
local lcm = sizeOfLastRow * numCols / a | local lcm = sizeOfLastRow * numCols / a | ||
| Строка 481: | Строка 493: | ||
function h.printSectionHeader(node, section, args) | function h.printSectionHeader(node, section, args) | ||
local fields = args[section] or {} | |||
local hasContent = args[section .. '_columns'] | |||
and (h.countItems(fields, section, args) > 0) | |||
or (function() | |||
for _, item in ipairs(fields) do | |||
if h.printData(mw.html.create(), item, section, args) then | |||
return true | |||
end | |||
end | |||
return false | |||
end)() | |||
if not hasContent then return end | |||
if h.castBool(args[section .. '_nolabel']) then return end | if h.castBool(args[section .. '_nolabel']) then return end | ||
h.printCount = h.printCount + 1 | |||
if h.printCount <= h.skipSections then | |||
return | |||
end | |||
local tr = node:tag(h.getTag('row')) | local tr = node:tag(h.getTag('row')) | ||
:attr('data-druid-section', h.escape(section)) | :attr('data-druid-section', h.escape(section)) | ||
| Строка 495: | Строка 527: | ||
end | end | ||
end | end | ||
local emptySections = {} | local emptySections = {} | ||
for _, label in ipairs(args.tabs) do | for _, label in ipairs(args.tabs) do | ||