Module:Slider
From Jules RNG Wiki
More actions
Documentation for this module may be created at Module:Slider/doc
local p = {}
function p.render(frame)
-- Handle arguments whether invoked directly or via template
local args = frame:getParent().args
if args['image1'] == nil then
args = frame.args -- Fallback if invoked directly
end
-- CONFIGURATION
local height = args['height'] or '300px'
local width = args['width'] or '100%'
local interval = args['interval'] or '4000' -- Default 4 seconds
-- CONTAINER
local slider = mw.html.create('div')
:addClass('jule-slider')
:attr('data-interval', interval) -- Pass time to JS
:css({
['width'] = width,
['height'] = height
})
-- LOOP THROUGH IMAGES
local i = 1
while args['image' .. i] do
local filename = args['image' .. i]
local slide = slider:tag('div')
:addClass('jule-slide')
-- The first slide gets the 'active' class initially
if i == 1 then
slide:addClass('active'):css('opacity', '1')
end
-- Render Image
-- We use |link= to disable clicking. You can add link1, link2 args later if you want clickable banners.
slide:wikitext(string.format('[[%s|%s|center|link=|class=slide-img]]', filename, width))
i = i + 1
end
return tostring(slider)
end
return p