dev
Documentation icon Module documentation
[view] [edit] [history] [purge]



-- <nowiki>
local p = {}

function p.generateMobileGallery(frame)
    local numTabs = 100
    local lines = {}

    for i = 1, numTabs do
        local tab = frame.args['tab' .. i]
        if tab and tab ~= '' then
            local title = frame.args['tab' .. i .. '_title'] or ''
            lines[#lines + 1] =
                tab .. '|alt=' .. title .. '|' .. title
        end
    end

    if #lines == 0 then
        return ''
    end

    return '\n<div class="miniwiki_element_mobile">\n'
        .. '<gallery position="center" titlealign="center">\n'
        .. table.concat(lines, '\n')
        .. '\n</gallery>\n'
        .. '</div>\n'
end

function p.generateTabItems(frame)
    local items = {}
    local i = 1
	while frame.args['tab'..i] or frame.args['tab'..i..'_title'] do
        local tab = frame.args['tab'..i]
        local tabTitle = frame.args['tab'..i..'_title'] or frame.args['tab_title'] or ''
        local tabTitleClass = frame.args['tab'..i..'_title_class'] or frame.args['tab_title_class'] or ''
        local tabCaption = frame.args['tab'..i..'_caption'] or frame.args['tab_caption'] or ''
        local tabClass = frame.args['tab'..i..'_class'] or frame.args['tab_overall_class'] or ''
        local tabSize = frame.args['tab'..i..'_size'] or frame.args['tab_overall_size'] or '135'

        if i == 1 then tabClass = tabClass .. ' wds-is-current' end
        local tabIndex = (i == 1) and '0' or '-1'

        if tab or tabTitle ~= '' then
            local tabContent = ''
            if tab and tab ~= '' then
                tabContent = '[[File:' .. tab .. '|' .. tabSize .. 'x' .. tabSize .. 'px|link=|alt=' .. tabCaption .. '|' .. tabCaption .. ']]'
            else
                tabContent = '<span class="miniwiki-tab_title ' .. tabTitleClass .. '" title="' .. tabCaption ..'">' .. tabTitle .. '</span>'
            end

            table.insert(items,
                '{{#if:{{{' .. 'tab'..i .. '|}}}{{{tab'..i..'_title|}}}|' ..
                '<li class="wds-tabs__tab miniwiki-tabs__tab ' .. tabClass .. '" data-hash="Tab_' .. i .. '" tabindex="' .. tabIndex .. '">' .. tabContent ..
                '</li>' ..
                '}}'
            )
        end
    	i = i + 1
	end

    return table.concat(items, '\n')
end

function p.generateTabSections(frame)
    local sections = {}
    local i = 1
	while frame.args['tab'..i] or frame.args['tab'..i..'_title'] do
        local content = frame.args['tab'..i..'_content']
        local contentClass = frame.args['tab'..i..'_content_class'] or ''
        local contentHeight = ''
        
        local header = frame.args['tab'..i..'_header'] or frame.args['tab_header'] or ''

        local headerClass = frame.args['tab'..i..'_header_class'] or frame.args['tab_header_class'] or ''
        
		local style = ''
		if frame.args['tab'..i..'_content_height'] then
		    style = style .. 'max-height: ' .. frame.args['tab'..i..'_content_height'] .. 'px; '
		elseif frame.args['overall_content_height'] then
		    style = style .. 'max-height: ' .. frame.args['overall_content_height'] .. 'px; '
		end
		
		if frame.args['tab'..i..'_content_width'] then
		    style = style .. 'max-width: ' .. frame.args['tab'..i..'_content_width'] .. 'px; '
		elseif frame.args['overall_content_width'] then
		    style = style .. 'max-width: ' .. frame.args['overall_content_width'] .. 'px; '
		end
        
        if i == 1 then contentClass = contentClass .. ' wds-is-current' end
        
        local headerHTML = ''

		if header ~= '' then headerHTML =
	        '<div class="miniwiki-tab_header ' .. headerClass .. '">' .. header .. '</div>'
		end

        if content and content ~= '' then
            table.insert(sections,
                '<div class="wds-tab__content miniwiki-tab__content ' .. contentClass .. '" data-hash="Tab_' .. i .. '" style="' .. style .. '">' ..
                	headerHTML .. content .. '\n' ..
                '</div>'
            )
        end
    	i = i + 1
	end

    return table.concat(sections, '\n')
end

function p.main(frame)
    local orientation = frame.args['orientation'] or 'horizontal'
    local tabs_position = frame.args['tabs_position'] or 'before'
    local height = frame.args['height'] or '748'
    local overall_content_height = frame.args['overall_content_height'] or '748'
    local vertical_tab_height = frame.args['vertical_tab_height'] or overall_content_height or '748'
    
    local return_link = frame.args['return_link']
    local topback_class = frame.args['topback_class'] or ''
	local return_link_button = ''
	
	local return_link_lower = return_link and mw.ustring.lower(mw.text.trim(return_link))
	local show_return_link = true
	
	if return_link == nil then return_link = 'Return&nbsp;to&nbsp;Top'
	elseif return_link_lower == '' or return_link_lower == 'none' or return_link_lower == 'n/a' then show_return_link = false
	end
    
    local cover = frame.args['cover'] or ''
    local coverClass = (frame.args['cover_class'] or '')
    local coverStyle = (frame.args['cover_style'] or '')

    local coverHTML = ''
    local coverId = ""  
    local miniwiki_id = frame.args['miniwiki_id'] or ''
    if cover ~= '' then
        if miniwiki_id then
            coverId = miniwiki_id .. "_cover"
            coverHTML = '<div id="' .. coverId .. '" class="wds-tabs__cover miniwiki_cover ' .. coverClass .. '" style="' .. coverStyle ..'">' .. cover .. '</div>'
        else
            coverHTML = '<div class="wds-tabs__cover miniwiki_cover ' .. coverClass .. '" style="' .. coverStyle ..'">' .. cover .. '</div>'
        end
    end

    local wrapperId = (miniwiki_id and miniwiki_id ~= '') and (miniwiki_id .. "_wrapper") or ''
	
	if show_return_link then
	    if cover ~= '' and miniwiki_id ~= '' then
	        return_link_button = '<div class="miniwiki_topback_container">[[#' .. (miniwiki_id .. "_cover") .. '|<span id="' .. (miniwiki_id .. "_topback") .. '" class="miniwiki_topback wds-button ' .. topback_class .. '">' ..  return_link .. '</span>]]</div>'
	
	    elseif miniwiki_id ~= '' then
	        return_link_button = '<div class="miniwiki_topback_container">[[#' .. wrapperId .. '|<span id="' .. (miniwiki_id .. "_topback") .. '" class="miniwiki_topback wds-button ' .. topback_class .. '">' ..  return_link .. '</span>]]</div>'
	    end
	end

    local tabs = p.generateTabItems(frame)
    local content = p.generateTabSections(frame)
    local mobileGallery = ''
    -- p.generateMobileGallery(frame)

	local tabsHTML
	if orientation == 'vertical' then
	    tabsHTML = [[
	        <div id="]] .. wrapperId .. [[" class="miniwiki-tabs__wrapper wds-tabs__wrapper">
	            <ul class="miniwiki_tabs vertical wds-tabs" style="max-height: ]] .. vertical_tab_height .. [[px;">
	                ]] .. tabs .. [[
	            </ul>
	        </div>
	    ]]
	else
	    tabsHTML = [[
	        <div id="]] .. wrapperId .. [[" class="miniwiki-tabs__wrapper wds-tabs__wrapper">
	            <ul class="miniwiki_tabs horizontal wds-tabs" style="max-height: ]] .. height .. [[px;">
	                ]] .. tabs .. [[
	            </ul>
	        </div>
	    ]]
	end
	
	local innerHTML
	if tabs_position == 'after' then
	    innerHTML = content .. tabsHTML
	else
	    innerHTML = tabsHTML .. content
	end
	
	local output
	if orientation == 'vertical' then
	    output = coverHTML .. mobileGallery .. [[
	        <div class="wds-tabber miniwiki_tabber vertical">
	            ]] .. innerHTML .. [[
	        </div>]] .. return_link_button
	else
	    output = coverHTML .. mobileGallery .. [[
	        <div class="wds-tabber miniwiki_tabber horizontal">
	            ]] .. innerHTML .. [[
	        </div>]] .. return_link_button
	end
    
    
    miniwiki_id_container = ''
	if miniwiki_id ~= '' then miniwiki_id_container = miniwiki_id .. '_container' else miniwiki_id_container = '' end
    return frame:preprocess([[<div id="]] .. miniwiki_id_container .. [[" class="miniwiki miniwiki_outer"><div class="miniwiki_inner">]] .. output .. [[</div></div>]])
end

return p
-- </nowiki>