Module:ImageStackPopup
Create an image that has a play button which popups a viewer showing a slideshow of some other images. Intended for use in viewing a series of medical images. See {{ImageStackPopup}} for more details.
This Module is a template gadget that requires the ImageStackPopup gadget to work.
local p = {}
function p.image( frame )
math.randomseed(tonumber(mw.getContentLanguage():formatDate( "U" ))*10000 + os.clock()*10000)
local args = frame:getParent().args
local popupConfig = {}
local caption = ''
popupConfig.loop = args.loop == "yes"
if tonumber( args.start ) then
popupConfig.start = tonumber( args.start )
else
popupConfig.start = 1
end
if tonumber( args.width ) then
popupConfig.width = tonumber( args.width )
end
if tonumber( args.height ) then
popupConfig.height = tonumber( args.height )
end
popupConfig.list = args.list
if args['noregisterimages'] == nil then
-- Register this as a dependency so that this page shows up as using all the images on the list page
frame:expandTemplate{ title = ':' .. args.list }
end
-- If we don't want to transclude for performance, maybe we could at least link
-- however links need to actually be output on the page to register them.
if args.caption then
popupConfig.caption = "imagestackpopup-caption-" .. math.random()
caption = tostring( mw.html.create( 'div' )
:attr( 'id', popupConfig.caption )
:attr( 'style', 'display: none' )
:wikitext( args.caption )
:done() )
end
if args.title then
popupConfig.title = args.title
end
return tostring( mw.html.create( 'div' )
:attr( 'class', 'ImageStackPopup' )
:attr( 'data-imagestackpopup-config', mw.text.jsonEncode( { popupConfig } ) )
:wikitext( args.file ) )
.. caption
end
function p.gallery( frame )
-- Seems like math.random is always seeded with 0 :(
math.randomseed(tonumber(mw.getContentLanguage():formatDate( "U" ))*10000 + os.clock()*10000)
local args = frame:getParent().args
local reuseImageCaption = args.reuse_image_caption ~= nil
local title = args["popup-title"]
local captionId = nil
local captionText = ''
local galleryContents = ''
local optionsArray = {}
local galleryArgs = {}
local galleryAttr = { "mode", "widths", "heights", "perrow", "caption", "showfilename", "showthumbnail", "id", "title", "class", "lang", "dir" }
for i, j in ipairs( galleryAttr ) do
galleryArgs[j] = args[j]
end
if args['popup-caption'] then
captionId = 'imagestackpopup-caption-' .. math.random()
captionText = tostring(
mw.html.create( 'div' )
:attr( 'style', 'display:none' )
:attr( 'id', captionId )
:wikitext( args['popup-caption'] )
)
end
for row in mw.text.gsplit( args.gallery, "\n", true ) do
local galleryRow = ''
local popupOptions = { title = title, caption = captionId }
for part in mw.text.gsplit( row, "!", true ) do
equalSplit = mw.text.split( part, '=', true )
if #equalSplit <= 1 then
-- be sure this really is a caption.
if galleryRow ~= '' and
reuseImageCaption and
#part > 8 and
string.find( part, " ", 1, true )
then
local captionId = 'imagestackpopup-caption-' .. math.random()
local wrappedPart = tostring( mw.html.create( 'span' )
:attr( 'id', captionId )
:wikitext( part )
)
popupOptions.caption = captionId
galleryRow = galleryRow .. wrappedPart .. '|'
else
galleryRow = galleryRow .. part .. '|'
end
else
if equalSplit[1] == 'popup-width' then
popupOptions.width = tonumber(equalSplit[2])
elseif equalSplit[1] == 'popup-height' then
popupOptions.height = tonumber(equalSplit[2])
elseif equalSplit[1] == 'popup-loop' then
popupOptions.loop = equalSplit[2] ~= ''
elseif equalSplit[1] == 'popup-start' then
popupOptions.start = tonumber(equalSplit[2])
elseif equalSplit[1] == 'popup-caption' then
local captionIdForImg = 'imagestackpopup-caption-' .. math.random()
captionText = captionText .. tostring( mw.html.create( 'div' )
:attr( 'id', captionIdForImg )
:css( 'display', 'none' )
:wikitext( table.concat( equalSplit, '=', 2 ) )
)
popupOptions.caption = captionIdForImg
elseif equalSplit[1] == 'popup-title' then
popupOptions.title = table.concat( equalSplit, '=', 2 )
elseif equalSplit[1] == 'popup-list' then
popupOptions.list = table.concat( equalSplit, '=', 2 )
if args['noregisterimages'] == nil then
-- Register this as a dependency so that this page shows up as using all the images on the list page
frame:expandTemplate{ title = ':' .. table.concat( equalSplit, '=', 2 ) }
end
else
galleryRow = galleryRow .. part .. '|'
end
end
end
if string.sub( galleryRow, -1 ) == '|' then
galleryRow = string.sub( galleryRow, 1, -2 )
end
galleryContents = galleryContents .. galleryRow .. "\n"
optionsArray[#optionsArray+1] = popupOptions
end
return tostring( mw.html.create( 'div' )
:attr( 'class', 'ImageStackPopup' )
:attr( 'data-imagestackpopup-config', mw.text.jsonEncode( optionsArray ) )
:wikitext( frame:extensionTag( 'gallery', galleryContents, galleryArgs ) )
) .. captionText
end
return p
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.