"ഘടകം:Multiple gallery" എന്ന താളിന്റെ പതിപ്പുകൾ തമ്മിലുള്ള വ്യത്യാസം
No edit summary |
No edit summary |
||
| വരി 9: | വരി 9: | ||
end | end | ||
-- Helper function to | -- Helper function to sanitize text for HTML output | ||
local function | local function sanitize(text) | ||
if not text then return '' end | |||
return mw.text.encode(text) | |||
if not | |||
end | end | ||
| വരി 51: | വരി 20: | ||
-- Get configuration parameters | -- Get configuration parameters | ||
local align = args.align or 'right' -- right | local mode = args.mode or 'horizontal' -- horizontal, vertical, or box | ||
local | local align = args.align or 'right' -- right, left, center, none | ||
local width = args.width or '100%' | |||
local height = args.height or '180px' -- default height for horizontal | |||
local boxWidth = args.boxwidth or '150px' -- width for box mode | |||
local boxHeight = args.boxheight or '150px' -- height for box mode | |||
local bgColor = parseColor(args['background color']) | local bgColor = parseColor(args['background color']) | ||
local headerBg = parseColor(args.header_background) | local headerBg = parseColor(args.header_background) | ||
local headerAlign = args.header_align or 'center' | local headerAlign = args.header_align or 'center' | ||
local header = args.header or '' | local header = args.header or '' | ||
local captionAlign = args.caption_align or 'left' | local captionAlign = args.caption_align or 'left' | ||
local footerBg = parseColor(args.footer_background) | local footerBg = parseColor(args.footer_background) | ||
| വരി 66: | വരി 37: | ||
-- Collect all images and their properties | -- Collect all images and their properties | ||
local images = {} | local images = {} | ||
for i = 1, | for i = 1, 50 do -- Extended to 50 images | ||
if args['image' .. i] then | if args['image' .. i] or args['file' .. i] then | ||
table.insert(images, { | table.insert(images, { | ||
file = args['image' .. i], | file = args['image' .. i] or args['file' .. i], | ||
width = | width = args['width' .. i], | ||
height = | height = args['height' .. i], | ||
alt = args['alt' .. i] or '', | alt = args['alt' .. i] or '', | ||
link = args['link' .. i], | link = args['link' .. i], | ||
| വരി 81: | വരി 52: | ||
if #images == 0 then | if #images == 0 then | ||
return '<div class="error">No images provided | return '<div class="error">No images provided for gallery</div>' | ||
end | end | ||
-- | -- Build the HTML structure | ||
if | local html = mw.html.create('div') | ||
html:addClass('responsive-gallery-container') | |||
html:addClass('gallery-' .. mode) | |||
-- Set alignment | |||
if align ~= 'none' then | |||
if align == 'left' then | |||
html:css('float', 'left') | |||
html:css('margin-right', '1em') | |||
elseif align == 'right' then | |||
html:css('float', 'right') | |||
html:css('margin-left', '1em') | |||
elseif align == 'center' then | |||
html:css('margin-left', 'auto') | |||
html:css('margin-right', 'auto') | |||
end | |||
end | end | ||
-- Set container width | |||
if width ~= '100%' then | |||
html:css('width', width) | |||
-- Set container | |||
if | |||
end | end | ||
-- Create gallery box | -- Create gallery box | ||
local box = | local box = html:tag('div') | ||
box:addClass('responsive-gallery-box') | |||
if bgColor then | if bgColor then | ||
box:css('background-color', bgColor) | box:css('background-color', bgColor) | ||
end | end | ||
-- Add header if provided | -- Add header if provided | ||
if header ~= '' then | if header ~= '' then | ||
local headerDiv = box:tag('div') | local headerDiv = box:tag('div') | ||
headerDiv:addClass('gallery-header') | |||
headerDiv:css('text-align', headerAlign) | |||
if headerBg then | if headerBg then | ||
headerDiv:css('background-color', headerBg) | headerDiv:css('background-color', headerBg) | ||
end | end | ||
headerDiv:wikitext(header) | headerDiv:wikitext(header) | ||
end | end | ||
-- Create images container | -- Create images container with flexbox | ||
local imagesContainer = box:tag('div') | local imagesContainer = box:tag('div') | ||
imagesContainer:addClass('gallery-images') | |||
if | -- Set flexbox direction based on mode | ||
imagesContainer: | if mode == 'vertical' then | ||
imagesContainer:addClass('gallery-vertical') | |||
elseif mode == 'box' then | |||
imagesContainer:addClass('gallery-box') | |||
else | else | ||
imagesContainer: | imagesContainer:addClass('gallery-horizontal') | ||
end | end | ||
-- | -- Add each image | ||
for | for i, img in ipairs(images) do | ||
local item = imagesContainer:tag('div') | local item = imagesContainer:tag('div') | ||
item:addClass('gallery-item') | |||
if | -- Set item sizing based on mode | ||
item:css('width', ' | if mode == 'box' then | ||
item:css('width', boxWidth) | |||
item:css('height', boxHeight) | |||
elseif mode == 'horizontal' then | |||
item:css('height', height) | |||
elseif mode == 'vertical' then | |||
if img.width then | |||
item:css('width', img.width .. 'px') | |||
end | |||
end | end | ||
-- Create image wrapper | -- Create image wrapper | ||
local | local wrapper = item:tag('div') | ||
wrapper:addClass('gallery-image-wrapper') | |||
-- Build image | -- Build image markup | ||
local | local imageMarkup = '[[File:' .. img.file | ||
-- | -- Add image parameters | ||
if mode == 'box' then | |||
if | imageMarkup = imageMarkup .. '|' .. boxWidth .. 'x' .. boxHeight | ||
elseif mode == 'horizontal' then | |||
elseif | imageMarkup = imageMarkup .. '|x' .. height | ||
elseif mode == 'vertical' then | |||
elseif img.width then | if img.width then | ||
imageMarkup = imageMarkup .. '|' .. img.width .. 'px' | |||
end | |||
end | end | ||
-- Add link if specified | |||
if img.link then | |||
-- Add | imageMarkup = imageMarkup .. '|link=' .. img.link | ||
if img. | |||
end | end | ||
-- Add alt text | -- Add alt text | ||
if img.alt ~= '' then | if img.alt ~= '' then | ||
imageMarkup = imageMarkup .. '|alt=' .. img.alt | |||
end | end | ||
-- Add | -- Add thumbtime for videos | ||
if img. | if img.thumbtime then | ||
imageMarkup = imageMarkup .. '|thumbtime=' .. img.thumbtime | |||
end | end | ||
imageMarkup = imageMarkup .. ']]' | |||
wrapper:wikitext(imageMarkup) | |||
-- Add caption if provided | |||
-- Add caption if | |||
if img.caption ~= '' then | if img.caption ~= '' then | ||
item:tag('div') | local caption = item:tag('div') | ||
caption:addClass('gallery-caption') | |||
caption:css('text-align', captionAlign) | |||
caption:wikitext(img.caption) | |||
end | end | ||
end | end | ||
| വരി 227: | വരി 175: | ||
if footer ~= '' then | if footer ~= '' then | ||
local footerDiv = box:tag('div') | local footerDiv = box:tag('div') | ||
footerDiv:addClass('gallery-footer') | |||
footerDiv:css('text-align', footerAlign) | |||
if footerBg then | if footerBg then | ||
footerDiv:css('background-color', footerBg) | footerDiv:css('background-color', footerBg) | ||
end | end | ||
footerDiv:wikitext(footer) | footerDiv:wikitext(footer) | ||
end | end | ||
return tostring( | return tostring(html) | ||
end | end | ||
return p | return p | ||
20:13, 27 ഒക്ടോബർ 2025-നു നിലവിലുള്ള രൂപം
ഈ ഘടകത്തിന്റെ വിവരണം ഘടകം:Multiple gallery/വിവരണം എന്ന താളിൽ നിർമ്മിക്കാവുന്നതാണ്
local p = {}
-- Helper function to parse color values
local function parseColor(color)
if not color or color == '' then
return nil
end
return color
end
-- Helper function to sanitize text for HTML output
local function sanitize(text)
if not text then return '' end
return mw.text.encode(text)
end
-- Main function to generate the gallery
function p.gallery(frame)
local args = frame:getParent().args
-- Get configuration parameters
local mode = args.mode or 'horizontal' -- horizontal, vertical, or box
local align = args.align or 'right' -- right, left, center, none
local width = args.width or '100%'
local height = args.height or '180px' -- default height for horizontal
local boxWidth = args.boxwidth or '150px' -- width for box mode
local boxHeight = args.boxheight or '150px' -- height for box mode
local bgColor = parseColor(args['background color'])
local headerBg = parseColor(args.header_background)
local headerAlign = args.header_align or 'center'
local header = args.header or ''
local captionAlign = args.caption_align or 'left'
local footerBg = parseColor(args.footer_background)
local footerAlign = args.footer_align or 'left'
local footer = args.footer or ''
-- Collect all images and their properties
local images = {}
for i = 1, 50 do -- Extended to 50 images
if args['image' .. i] or args['file' .. i] then
table.insert(images, {
file = args['image' .. i] or args['file' .. i],
width = args['width' .. i],
height = args['height' .. i],
alt = args['alt' .. i] or '',
link = args['link' .. i],
thumbtime = args['thumbtime' .. i],
caption = args['caption' .. i] or ''
})
end
end
if #images == 0 then
return '<div class="error">No images provided for gallery</div>'
end
-- Build the HTML structure
local html = mw.html.create('div')
html:addClass('responsive-gallery-container')
html:addClass('gallery-' .. mode)
-- Set alignment
if align ~= 'none' then
if align == 'left' then
html:css('float', 'left')
html:css('margin-right', '1em')
elseif align == 'right' then
html:css('float', 'right')
html:css('margin-left', '1em')
elseif align == 'center' then
html:css('margin-left', 'auto')
html:css('margin-right', 'auto')
end
end
-- Set container width
if width ~= '100%' then
html:css('width', width)
end
-- Create gallery box
local box = html:tag('div')
box:addClass('responsive-gallery-box')
if bgColor then
box:css('background-color', bgColor)
end
-- Add header if provided
if header ~= '' then
local headerDiv = box:tag('div')
headerDiv:addClass('gallery-header')
headerDiv:css('text-align', headerAlign)
if headerBg then
headerDiv:css('background-color', headerBg)
end
headerDiv:wikitext(header)
end
-- Create images container with flexbox
local imagesContainer = box:tag('div')
imagesContainer:addClass('gallery-images')
-- Set flexbox direction based on mode
if mode == 'vertical' then
imagesContainer:addClass('gallery-vertical')
elseif mode == 'box' then
imagesContainer:addClass('gallery-box')
else
imagesContainer:addClass('gallery-horizontal')
end
-- Add each image
for i, img in ipairs(images) do
local item = imagesContainer:tag('div')
item:addClass('gallery-item')
-- Set item sizing based on mode
if mode == 'box' then
item:css('width', boxWidth)
item:css('height', boxHeight)
elseif mode == 'horizontal' then
item:css('height', height)
elseif mode == 'vertical' then
if img.width then
item:css('width', img.width .. 'px')
end
end
-- Create image wrapper
local wrapper = item:tag('div')
wrapper:addClass('gallery-image-wrapper')
-- Build image markup
local imageMarkup = '[[File:' .. img.file
-- Add image parameters
if mode == 'box' then
imageMarkup = imageMarkup .. '|' .. boxWidth .. 'x' .. boxHeight
elseif mode == 'horizontal' then
imageMarkup = imageMarkup .. '|x' .. height
elseif mode == 'vertical' then
if img.width then
imageMarkup = imageMarkup .. '|' .. img.width .. 'px'
end
end
-- Add link if specified
if img.link then
imageMarkup = imageMarkup .. '|link=' .. img.link
end
-- Add alt text
if img.alt ~= '' then
imageMarkup = imageMarkup .. '|alt=' .. img.alt
end
-- Add thumbtime for videos
if img.thumbtime then
imageMarkup = imageMarkup .. '|thumbtime=' .. img.thumbtime
end
imageMarkup = imageMarkup .. ']]'
wrapper:wikitext(imageMarkup)
-- Add caption if provided
if img.caption ~= '' then
local caption = item:tag('div')
caption:addClass('gallery-caption')
caption:css('text-align', captionAlign)
caption:wikitext(img.caption)
end
end
-- Add footer if provided
if footer ~= '' then
local footerDiv = box:tag('div')
footerDiv:addClass('gallery-footer')
footerDiv:css('text-align', footerAlign)
if footerBg then
footerDiv:css('background-color', footerBg)
end
footerDiv:wikitext(footer)
end
return tostring(html)
end
return p