Diferencia entre revisiones de «Módulo:3D viewer advanced»
De Inkipedia
m (modules moved) |
(Revisiones deshechas) Etiqueta: Reversión manual |
||
(No se muestran 17 ediciones intermedias de 2 usuarios) | |||
Línea 10: | Línea 10: | ||
function common_string(arg, opt_arg) | function common_string(arg, opt_arg) | ||
return frame:expandTemplate{title='Common string', args={arg, opt_arg}} | return frame:expandTemplate{title='Common string', args={arg, opt_arg}} | ||
end | end | ||
Línea 56: | Línea 47: | ||
.tag('div') | .tag('div') | ||
.addClass('viewer-3d-frame') | .addClass('viewer-3d-frame') | ||
.css('display', 'none') | |||
local switch_to_2d = output_view | local switch_to_2d = output_view | ||
.tag('div') | .tag('div') | ||
.attr(' | .attr('class', 'switch-to-2d') | ||
return tostring(output_view) | return tostring(output_view) | ||
Línea 70: | Línea 62: | ||
-- button classes mapping | -- button classes mapping | ||
local button_classes = { | local button_classes = { | ||
default_half = 'view-selector-default-', | default_half = 'view-selector-default-', | ||
default_full = 'view-selector-default-full', | default_full = 'view-selector-default-full', | ||
Línea 86: | Línea 73: | ||
-- create container for viewer | -- create container for viewer | ||
local startimage = utils.processArg(args['3d-image-1']) | local startimage = utils.processArg(args['3d-image-1']) | ||
local startframe = args['3d-startframe'] or utils.expandWikitext('{{File:' .. startimage .. ' 3D.png|startframe}}') | |||
local startframe = args['3d-startframe'] or utils.expandWikitext('{{File:' .. startimage .. ' 3D. | |||
local viewer_container = output_view | local viewer_container = output_view | ||
.tag('div') | .tag('div') | ||
.addClass('viewer-3d') | .addClass('viewer-3d') | ||
.addClass('startframe-' .. startframe) | .addClass('startframe-' .. startframe) | ||
.css('display', 'none') | |||
-- add 3D and 2D selectors | -- add 3D and 2D selectors | ||
Línea 103: | Línea 87: | ||
local switch_to_2d = viewer_container | local switch_to_2d = viewer_container | ||
.tag('div') | .tag('div') | ||
.attr(' | .attr('class', 'switch-to-2d') | ||
-- create container for model selector buttons | -- create container for model selector buttons | ||
Línea 109: | Línea 93: | ||
.tag('ul') | .tag('ul') | ||
.addClass('buttons-container-3d') | .addClass('buttons-container-3d') | ||
.css('display', 'none') | |||
-- create container for 2D image | -- create container for 2D image | ||
Línea 114: | Línea 99: | ||
if args['image'] then | if args['image'] then | ||
image_2d = args['image'] | image_2d = args['image'] | ||
else | else | ||
image_2d = mw.title.getCurrentTitle().baseText .. '.png' | image_2d = mw.title.getCurrentTitle().baseText .. '.png' | ||
Línea 121: | Línea 104: | ||
local viewer_2d_frame = output_view | local viewer_2d_frame = output_view | ||
.tag('div') | .tag('div') | ||
.wikitext(utils.expandWikitext('{{ | .wikitext(utils.expandWikitext('{{2D viewer|' .. image_2d .. '|' .. (args['size'] or '') .. '}}')) | ||
-- row button counter for half width buttons | -- row button counter for half width buttons | ||
local current_row_count = 0 | local current_row_count = 0 | ||
local i = 1 | local i = 1 | ||
while utils.processArg(args['3d-image-' .. i]) ~= '' | while utils.processArg(args['3d-image-' .. i]) ~= '' do | ||
local image_postfix = ' 3D.png' | |||
local image_postfix = ' 3D. | |||
local viewname_postfix = '' | local viewname_postfix = '' | ||
local image_n = utils.processArg(args['3d-image-' .. i]) | local image_n = utils.processArg(args['3d-image-' .. i]) | ||
local button_n = utils.processArg(args['3d-button-' .. i]) | local button_n = utils.processArg(args['3d-button-' .. i]) | ||
local button_class = button_classes[button_n] | local button_class = button_classes[button_n] | ||
local viewname_n = utils.processArg(args['3d-viewname-' .. i]) | local viewname_n = utils.processArg(args['3d-viewname-' .. i]) | ||
if image_n ~= '' then | if image_n ~= '' then | ||
span_image_url_n = viewer_container | span_image_url_n = viewer_container | ||
Línea 167: | Línea 132: | ||
end | end | ||
-- add selector button for this model | -- add selector button for this model | ||
if button_n == 'default_half | if button_n == 'default_half' then | ||
if current_row_count == 0 then | if current_row_count == 0 then | ||
button_class = button_class .. 'left' | button_class = button_class .. 'left' |
Revisión actual - 16:35 13 mar 2023
La documentación para este módulo puede ser creada en Módulo:3D viewer advanced/doc
-- Module:3D viewer advanced, extracted from TF2Wiki. local p = {} local utils = require('Module:Utils') local HtmlBuilder = require('Module:HtmlBuilder') local frame = nil -- Expands the template Common string for a given value. Note that some common string values include an additional parameter, here called opt_arg. function common_string(arg, opt_arg) return frame:expandTemplate{title='Common string', args={arg, opt_arg}} end function p.viewer(f) local args = utils.get_args(f) local startframe = utils.processArg(args['startframe']) local image = utils.processArg(args['image']) local image_0 = utils.processArg(args['image-0']) local fallback = utils.processArg(args['fallback']) local startframe_class if startframe ~= '' then startframe_class = mw.text.trim(startframe) else startframe_class = utils.expandWikitext('{{File:' .. (image_0 or image) .. '|startframe}}') end local output_view = HtmlBuilder.create('div') .addClass('viewer-3d') .addClass('startframe-' .. startframe_class) .wikitext(fallback) for i = 0,10 do local image_n = utils.processArg(args['image-' .. i], '') if image_n ~= '' then span_image_url_n = output_view .tag('span') .addClass('viewer-3d-url-' .. i) .wikitext(utils.expandWikitext('{{File:' .. image_n .. '|url}}')) span_image_map_n = output_view .tag('span') .addClass('viewer-3d-map-' .. i) .wikitext(utils.expandWikitext('{{File:' .. image_n .. '|map}}')) end end local viewer_3d_frame = output_view .tag('div') .addClass('viewer-3d-frame') .css('display', 'none') local switch_to_2d = output_view .tag('div') .attr('class', 'switch-to-2d') return tostring(output_view) end function p.viewer_new(f) frame = f local args = utils.get_args(f) -- button classes mapping local button_classes = { default_half = 'view-selector-default-', default_full = 'view-selector-default-full', default = 'view-selector-default-full' } -- create output container local output_view = HtmlBuilder.create('div') .addClass('viewer-3d-container') -- create container for viewer local startimage = utils.processArg(args['3d-image-1']) local startframe = args['3d-startframe'] or utils.expandWikitext('{{File:' .. startimage .. ' 3D.png|startframe}}') local viewer_container = output_view .tag('div') .addClass('viewer-3d') .addClass('startframe-' .. startframe) .css('display', 'none') -- add 3D and 2D selectors local viewer_3d_frame = viewer_container .tag('div') .addClass('viewer-3d-frame') local switch_to_2d = viewer_container .tag('div') .attr('class', 'switch-to-2d') -- create container for model selector buttons local buttons_container = output_view .tag('ul') .addClass('buttons-container-3d') .css('display', 'none') -- create container for 2D image local image_2d if args['image'] then image_2d = args['image'] else image_2d = mw.title.getCurrentTitle().baseText .. '.png' end local viewer_2d_frame = output_view .tag('div') .wikitext(utils.expandWikitext('{{2D viewer|' .. image_2d .. '|' .. (args['size'] or '') .. '}}')) -- row button counter for half width buttons local current_row_count = 0 local i = 1 while utils.processArg(args['3d-image-' .. i]) ~= '' do local image_postfix = ' 3D.png' local viewname_postfix = '' local image_n = utils.processArg(args['3d-image-' .. i]) local button_n = utils.processArg(args['3d-button-' .. i]) local button_class = button_classes[button_n] local viewname_n = utils.processArg(args['3d-viewname-' .. i]) if image_n ~= '' then span_image_url_n = viewer_container .tag('span') .addClass('viewer-3d-url-' .. (i-1)) .wikitext(utils.expandWikitext('{{File:' .. image_n .. image_postfix .. '|url}}')) span_image_map_n = viewer_container .tag('span') .addClass('viewer-3d-map-' .. (i-1)) .wikitext(utils.expandWikitext('{{File:' .. image_n .. image_postfix .. '|map}}')) -- if there is only one 3d image then don't attach selector if i == 1 and args['3d-image-2'] == nil and args['3d-image-3'] == nil then break end -- add selector button for this model if button_n == 'default_half' then if current_row_count == 0 then button_class = button_class .. 'left' current_row_count = 1 else button_class = button_class .. 'right' current_row_count = 0 end end -- selector is 0-indexed button_class = button_class .. ' selector-' .. (i-1) li_button_n = buttons_container .tag('li') .addClass(button_class) .wikitext(utils.expandWikitext('[[:File:' .. image_n .. image_postfix .. '|' .. viewname_n .. viewname_postfix .. ']]')) end i = i + 1 end return tostring(output_view) end return p