Module:Portal image banner and Module:Portal image banner/sandbox: Difference between pages
Appearance
(Difference between pages)
Content deleted Content added
m Simplified code by clearing out redundancy, using "elseif" instead of "else if", and improving formatting |
test |
||
Line 27: | Line 27: | ||
p._main = function(args) |
p._main = function(args) |
||
if not args[1] then |
if not args[1] then |
||
return error('No page specified', 0) |
return error(linked and 'No page specified' or 'No page specified', 0) |
||
end |
end |
||
local lines=makeGalleryLinesTable(args) |
local lines=makeGalleryLinesTable(args) |
||
Line 33: | Line 33: | ||
end |
end |
||
function makeGalleryLine(file, caption, link) |
function makeGalleryLine(file, caption, link, height) |
||
local title = mw.title.new(file, "File" ) |
local title = mw.title.new(file, "File" ) |
||
local linktext = ( link and '{{!}}link=' .. link or '' ) |
local linktext = ( link and '{{!}}link=' .. link or '' ) |
||
local |
local imageSize = '{{!}}x' .. (height or '200px') |
||
return '[[' .. title.prefixedText ..(caption and'{{!}}'..caption or '').. |
return '[[' .. title.prefixedText ..(caption and'{{!}}'..caption or '').. imageSize .. linktext ..']]' .. (caption and '\n<div style="text-align:center;">' .. caption ..'</div>' or '\n') |
||
end |
end |
||
Line 45: | Line 45: | ||
return title.prefixedText .. '{{!}}' .. captiontext |
return title.prefixedText .. '{{!}}' .. captiontext |
||
end |
end |
||
function makeGalleryLinesTable(args) |
function makeGalleryLinesTable(args) |
||
Line 51: | Line 52: | ||
while args[i] do |
while args[i] do |
||
if not args.mode then |
if not args.mode then |
||
table.insert(galleryLinesTable, makeGalleryLine(args[i], args[i+1],args.link)) |
table.insert(galleryLinesTable, makeGalleryLine(args[i], args[i+1], args.link, args.height)) |
||
else if args.mode=='slideshow' then |
|||
table.insert(galleryLinesTable, makeGalleryLineSlideshow(args[i], args[i+1], args.link)) |
table.insert(galleryLinesTable, makeGalleryLineSlideshow(args[i], args[i+1], args.link)) |
||
else |
else |
||
error('Mode not supported') |
error('Mode not supported') |
||
end |
end |
||
end |
|||
i = i + 2 |
i = i + 2 |
||
end |
end |
||
return galleryLinesTable |
return galleryLinesTable |
||
end |
end |
||
function makeOutput(imageLines, overflow, maxHeight, mode, croptop) |
function makeOutput(imageLines, overflow, maxHeight, mode, croptop) |
||
local randomiseArgs = { ['t'] = imageLines } |
local randomiseArgs = { ['t'] = imageLines } |
||
Line 72: | Line 72: | ||
output = '<div class="portal-banner-image" style="max-height:' .. (maxHeight or 'initial') .. '; overflow:'..(overflow or 'auto').. |
output = '<div class="portal-banner-image" style="max-height:' .. (maxHeight or 'initial') .. '; overflow:'..(overflow or 'auto').. |
||
';"><div class="portal-banner-image-crop" style="position:relative; margin-top:-'..(croptop or '0')..'%;">'..seperate[1]..'</div></div>'..seperate[2] |
';"><div class="portal-banner-image-crop" style="position:relative; margin-top:-'..(croptop or '0')..'%;">'..seperate[1]..'</div></div>'..seperate[2] |
||
else if mode=='slideshow' then |
|||
galleryContent = table.concat(randomisedLines, '\n') |
galleryContent = table.concat(randomisedLines, '\n') |
||
output='<div class="portal-banner-image-slideshow nomobile" style="max-height:' .. (maxHeight or 'initial') .. '; overflow:'..(overflow or 'auto').. |
output='<div class="portal-banner-image-slideshow nomobile" style="max-height:' .. (maxHeight or 'initial') .. '; overflow:'..(overflow or 'auto').. |
||
Line 78: | Line 78: | ||
else |
else |
||
error('Mode not supported') |
error('Mode not supported') |
||
end |
|||
end |
end |
||
return output |
|||
end |
end |
||
return p |
return p |