FANDOM


-- Module: Media
-- Author: "The JoTS"
-- Allows the creation of embedded media objects solely by url, and sizing params.
 
-- <pre>
 
--[==[Modules]==]--
local getArgs = require("Dev:Arguments").getArgs;
local utils = require "Module:Utils";
 
local protocols = {
    ["^File:"] = function(url)
        -- Wiki File
        return mw.html.create "div"
            :wikitext("[[" .. url .. "|180px|link=]]")
            :css({
                ["overflow-x"] = "auto",
                ["overflow-y"] = "hidden",
                width = "100%"})
    end,
 
    ["soundcloud.com/"] = function(url, args)
        -- Soundcloud
        return mw.html.create "soundcloud"
            :attr("url", url)
            :attr("height", args.height or 75)
            :attr("width", args.width or 200)
            :attr("auto_play", args.auto_play or 0);
    end,
 
    ["youtube.com/"] = function(url, args)
        -- YouTube
        local vidId = url:match("?v=([%w_-]+)");
 
        return mw.html.create "youtube"
            :wikitext(vidId)
            :attr({
                width  = args.width or 150,
                height = args.height or 25});
    end
}
 
return {
    url_to_widget = utils.create_wrapper(function(args)
        local url = args.url; -- cannot be the first positional argument as youtube has a "v=", getting interpreted as an param name
        local widget_markup;
        local div_wrapper = mw.html.create "div"
            :css({
                ["width"]      = "100%",
                ["text-align"] = "center" })
 
        for pr,func in pairs(protocols) do
            if url:match(pr) then
                widget_markup = tostring( func(url, args) );
                break;
            end
        end
 
        return tostring(div_wrapper:wikitext(widget_markup or url));
    end)
}

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.