Module:Rslider

From The Satanic Wiki
Jump to navigation Jump to search

Documentation for this module may be created at Module:Rslider/doc

--<pre>
--Syntax:{{#invoke:rslider|main|<file1>|<file2>|<file3>}}
local p = {}
local u = require('Module:Utility')

function p.main(frame)
   return p.randSlider(frame, 0)
end

function p.showdef(frame)
   return p.randSlider(frame, 1)
end

function p.randSlider(frame, iDefault)
    local tArgs1 ,tArgs2 = u.getArgs(frame,"both")
    local tMedia ={}
    local sIndexes = ""
    local sFiles ='<gallery type="slider" orientation="bottom">\n'
    local iIndex = 0
    
    if not tArgs1 and not tArgs2  then 
        return 
    end
    
    if not tArgs1  and tArgs2 then 
       tArgs1= tArgs2 
    end
    math.randomseed( mw.site.stats.edits + mw.site.stats.pages + os.time() + math.floor(os.clock() * 1000000000))
    math.random()
    
    if iDefault == 1 then 
        sFiles = sFiles .. tArgs1[1]..'\n'
        tMedia[1]=tArgs1[1]
    end
    
    if #tArgs1 > 1 then
        while iIndex < 4 do
            local entry = math.random(1,#tArgs1)
            
            if tArgs1 and not(tArgs1[entry] == tMedia[entry]) and not(iDefault == entry) then
                 tMedia[entry]= tArgs1[entry]
                 sFiles = sFiles..tMedia[entry]..'\n'
                 sIndexes = sIndexes .."-".. entry
                 iIndex = iIndex +1
            end
            if #tMedia == #tArgs1 then
                break;
            end
        end
    end
    return frame:preprocess(sFiles .."</gallery>" )
end

return p
--[[Category:Utility modules]]