Difference between revisions of "Module:Gallery items"

From blackwiki
Jump to navigation Jump to search
blackwiki>Great Brightstar
(Revert)
blackwiki>Great Brightstar
(Make the gallery layout more likes the native output in MediaWiki, the width parameter must use integral only.)
Line 6: Line 6:
 
local args = getArgs(frame)
 
local args = getArgs(frame)
  
local width = args.width or '150px'
+
local width = args.width or '150'
  
 
local items = {}
 
local items = {}
Line 14: Line 14:
 
     local item = mw.html.create('li')
 
     local item = mw.html.create('li')
 
     :addClass('gallerybox')
 
     :addClass('gallerybox')
     :css('width', args['width' .. k] or width)
+
     :css('width', ((args['width' .. k] or width)+5) .. 'px')
 
     item:tag('div')
 
     item:tag('div')
     :css('width', args['width' .. k] or width)
+
    :addClass('thumb')
 +
     :css('width', (args['width' .. k] or width) .. 'px')
 
     :css('text-align', args['itemalign'] or 'center')
 
     :css('text-align', args['itemalign'] or 'center')
     :css('margin', '0 auto')
+
     :wikitext('<div style="margin:0px auto">' .. args[k] .. '</div>')
    :wikitext(args[k])
 
 
     if args[tonumber(k)+1] then
 
     if args[tonumber(k)+1] then
 
     item
 
     item
 
     :tag('div')
 
     :tag('div')
 
     :addClass('gallerytext')
 
     :addClass('gallerytext')
     :css('width', args['width' .. k] or width)
+
     :css('width', (args['width' .. k] or width) .. 'px')
 
     :css('text-align', args['captionalign'] or 'center')
 
     :css('text-align', args['captionalign'] or 'center')
 
     :wikitext('<p>' .. args[tonumber(k)+1] .. '</p>')
 
     :wikitext('<p>' .. args[tonumber(k)+1] .. '</p>')

Revision as of 15:39, 1 September 2019

Implements {{gallery items}}


-- this module implements [[template:gallery items]]
local p = {}

function p.main(frame)
	local getArgs = require('Module:Arguments').getArgs
	local args = getArgs(frame)

	local width = args.width or '150'

	local items = {}
	for k, v in pairs(args) do
    	if k ~= nil and tonumber(k) and math.fmod(k,2) == 1 then
    		local i = math.floor(k/2) + 1
    		local item = mw.html.create('li')
    			:addClass('gallerybox')
    			:css('width', ((args['width' .. k] or width)+5) .. 'px')
    		item:tag('div')
    				:addClass('thumb')
    				:css('width', (args['width' .. k] or width) .. 'px')
    				:css('text-align', args['itemalign'] or 'center')
    				:wikitext('<div style="margin:0px auto">' .. args[k] .. '</div>')
    		if args[tonumber(k)+1] then
    			item
    				:tag('div')
    				:addClass('gallerytext')
    				:css('width', (args['width' .. k] or width) .. 'px')
    				:css('text-align', args['captionalign'] or 'center')
    				:wikitext('<p>' .. args[tonumber(k)+1] .. '</p>')
    		end
    		items[i] = tostring(item) .. '&#32;'
    	end
	end
	local root = mw.html.create('ul')
		:addClass('gallery mw-gallery-nolines nochecker')
		:addClass(args.class)
		:cssText(args.style)
		:wikitext(table.concat(items))
	
	return frame:extensionTag{ name = 'gallery' } .. tostring(root)
end

return p