Content added Content deleted
(added templatestyles) |
(add classes) |
||
Line 5: | Line 5: | ||
local p = {} |
local p = {} |
||
local color = |
local color = nil |
||
local colors = { |
local colors = { |
||
['easy preview'] = constants.get_difficulty_color('easy'), |
['easy preview'] = constants.get_difficulty_color('easy'), |
||
Line 32: | Line 32: | ||
local header = mw.html.create('div') |
local header = mw.html.create('div') |
||
:addClass('header') |
|||
:css({ |
:css({ |
||
['border-radius'] = '6px', |
|||
['background-color'] = color, |
['background-color'] = color, |
||
['font-weight'] = 'bold', |
|||
['text-align'] = 'center', |
|||
['margin-bottom'] = '5px', |
|||
['padding'] = '5px' |
|||
}) |
}) |
||
:wikitext(utils.editIfNil( |
:wikitext(utils.editIfNil( |
||
Line 53: | Line 49: | ||
local function makeVideo(frame, link) |
local function makeVideo(frame, link) |
||
local video = mw.html.create('div') |
local video = mw.html.create('div') |
||
:addClass('video') |
|||
:css({ |
|||
['flex'] = '1 1 320px', |
|||
['text-align'] = 'center', |
|||
['min-width'] = '320px', |
|||
['height'] = '180px' |
|||
}) |
|||
if link then |
if link then |
||
Line 84: | Line 75: | ||
local function makeInfo(release_date, illustration, animation, video) |
local function makeInfo(release_date, illustration, animation, video) |
||
local infoHeaderCss = { |
local infoHeaderCss = { |
||
[' |
['background-color'] = color |
||
['background-color'] = color, |
|||
['padding'] = '5px 10px' |
|||
} |
|||
local infoCellCss = { |
|||
['padding'] = '5px' |
|||
} |
} |
||
local info = mw.html.create('div') |
local info = mw.html.create('div') |
||
: |
:addClass('info') |
||
['display'] = 'grid', |
|||
['grid-template-columns'] = '1fr 1fr', |
|||
['grid-auto-rows'] = 'min-content', |
|||
['gap'] = '5px' |
|||
}) |
|||
info:tag('div') |
info:tag('div') |
||
:css(infoHeaderCss) |
:css(infoHeaderCss) |
||
: |
:addClass('ih') |
||
:wikitext('Release date') |
|||
:done() |
:done() |
||
:tag('div') |
:tag('div') |
||
:addClass('id') |
|||
:css(infoCellCss) |
:css(infoCellCss) |
||
:wikitext(utils.editIfNil(release_date)) |
:wikitext(utils.editIfNil(release_date)) |
||
Line 112: | Line 95: | ||
info:tag('div') |
info:tag('div') |
||
:css(infoHeaderCss) |
:css(infoHeaderCss) |
||
:addClass('ih') |
|||
:wikitext('Illustration') |
:wikitext('Illustration') |
||
:done() |
:done() |
||
:tag('div') |
:tag('div') |
||
: |
:addClass('id') |
||
:wikitext(illustration) |
:wikitext(illustration) |
||
:done() |
:done() |
||
Line 123: | Line 107: | ||
info:tag('div') |
info:tag('div') |
||
:css(infoHeaderCss) |
:css(infoHeaderCss) |
||
:addClass('ih') |
|||
:wikitext('Animation') |
:wikitext('Animation') |
||
:done() |
:done() |
||
:tag('div') |
:tag('div') |
||
: |
:addClass('id') |
||
:wikitext(animation) |
:wikitext(animation) |
||
:done() |
:done() |
||
Line 134: | Line 119: | ||
info:tag('div') |
info:tag('div') |
||
:css(infoHeaderCss) |
:css(infoHeaderCss) |
||
:addClass('ih') |
|||
:wikitext('Video') |
:wikitext('Video') |
||
:done() |
:done() |
||
:tag('div') |
:tag('div') |
||
: |
:addClass('id') |
||
:wikitext(video) |
:wikitext(video) |
||
:done() |
:done() |
||
Line 156: | Line 142: | ||
local root = mw.html.create('div') |
local root = mw.html.create('div') |
||
:addClass('song-video') |
|||
:css({ |
|||
['display'] = 'inline-grid', |
|||
['margin-right'] = '10px', |
|||
['margin-bottom'] = '10px' |
|||
}) |
|||
color = colors[video_type] or color |
color = colors[video_type] or color |
||
Line 168: | Line 150: | ||
local body = root:tag('div') |
local body = root:tag('div') |
||
:addClass('content') |
|||
:css({ |
|||
['display'] = 'flex', |
|||
['flex-wrap'] = 'wrap', |
|||
['gap'] = '5px' |
|||
}) |
|||
:node(makeVideo(frame, link)) |
:node(makeVideo(frame, link)) |
||
:node(makeInfo(release_date, illustration, animation, video)) |
:node(makeInfo(release_date, illustration, animation, video)) |
Revision as of 22:21, 22 December 2021
Documentation for this module may be created at Module:Song video/doc
local getArgs = require('Module:Arguments').getArgs
local utils = require('Module:Utilities')
local constants = require('Module:Constants')
local p = {}
local color = nil
local colors = {
['easy preview'] = constants.get_difficulty_color('easy'),
['normal preview'] = constants.get_difficulty_color('normal'),
['hard preview'] = constants.get_difficulty_color('hard'),
['expert preview'] = constants.get_difficulty_color('expert'),
['master preview'] = constants.get_difficulty_color('master'),
['original mv'] = '#66dd11',
['game 2d mv'] = '#66dd11',
['full 2d mv'] = '#00cdba',
['3d mv'] = '#66dd11'
}
local function makeHeader(video_type)
local headers = {
['easy preview'] = 'Easy Preview',
['normal preview'] = 'Normal Preview',
['hard preview'] = 'Hard Preview',
['expert preview'] = 'Expert Preview',
['master preview'] = 'Master Preview',
['original mv'] = 'Original MV',
['game 2d mv'] = '2D MV (game version)',
['full 2d mv'] = '2D MV (full version)',
['3d mv'] = '3D MV'
}
local header = mw.html.create('div')
:addClass('header')
:css({
['background-color'] = color,
})
:wikitext(utils.editIfNil(
video_type,
function()
return utils.editIfNil(headers[video_type:lower()])
end
))
:done()
return header
end
local function makeVideo(frame, link)
local video = mw.html.create('div')
:addClass('video')
if link then
local is_yt = string.find(link, '^' .. ('[a-zA-Z0-9_-]'):rep(11) .. '$') ~= nil
local is_file = string.find(link, '.+\.mp4') ~= nil
if is_yt then
video:wikitext(frame:extensionTag{
name = 'youtube',
args = { width = "320", height= "180" },
content = link
})
elseif is_file then
video:wikitext('[[File:' .. link .. '|320px]]')
else
video:wikitext(utils.editIfNil(nil))
end
else
video:wikitext(utils.editIfNil(nil))
end
return video
end
local function makeInfo(release_date, illustration, animation, video)
local infoHeaderCss = {
['background-color'] = color
}
local info = mw.html.create('div')
:addClass('info')
info:tag('div')
:css(infoHeaderCss)
:addClass('ih')
:wikitext('Release date')
:done()
:tag('div')
:addClass('id')
:css(infoCellCss)
:wikitext(utils.editIfNil(release_date))
:done()
if illustration and illustration ~= '' then
info:tag('div')
:css(infoHeaderCss)
:addClass('ih')
:wikitext('Illustration')
:done()
:tag('div')
:addClass('id')
:wikitext(illustration)
:done()
end
if animation and animation ~= '' then
info:tag('div')
:css(infoHeaderCss)
:addClass('ih')
:wikitext('Animation')
:done()
:tag('div')
:addClass('id')
:wikitext(animation)
:done()
end
if video and video ~= '' then
info:tag('div')
:css(infoHeaderCss)
:addClass('ih')
:wikitext('Video')
:done()
:tag('div')
:addClass('id')
:wikitext(video)
:done()
end
return info
end
function p.main(frame)
local args = getArgs(frame)
local video_type = args['type']
local link = args['link']
local release_date = args['date']
local illustration = args['illustration']
local animation = args['animation']
local video = args['video']
local root = mw.html.create('div')
:addClass('song-video')
color = colors[video_type] or color
local header = makeHeader(video_type)
root:node(header)
local body = root:tag('div')
:addClass('content')
:node(makeVideo(frame, link))
:node(makeInfo(release_date, illustration, animation, video))
return mw.getCurrentFrame():extensionTag{
name = 'templatestyles',
args = { src = 'Template:Song video/styles.css' }
} .. tostring(root)
end
return p