Module:Quotes/pl

From JoJo's Bizarre Encyclopedia - JoJo Wiki
< Module:Quotes
Revision as of 14:55, 12 August 2024 by Damianito (talk | contribs) (Created page with "local p = {} function p.render(frame) local args = frame:getParent().args local title = args.Title or "Cytaty" local icon = args.Icon or "Quote.png" local bg = args.bg or "#b06767" local bg2 = args.bg2 or "#9199a6" bg = frame:expandTemplate{title = "Color", args = {bg}} bg2 = frame:expandTemplate{title = "Color", args = {bg2}} local rows = {} local i = 1 local nihongoJapaneseFound = false -- Iterating over the arguments to...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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

local p = {}

function p.render(frame)
    local args = frame:getParent().args
    local title = args.Title or "Cytaty"
    local icon = args.Icon or "Quote.png"
    local bg = args.bg or "#b06767"
    local bg2 = args.bg2 or "#9199a6"

    bg = frame:expandTemplate{title = "Color", args = {bg}}
    bg2 = frame:expandTemplate{title = "Color", args = {bg2}}

    local rows = {}
    local i = 1
    local nihongoJapaneseFound = false

    -- Iterating over the arguments to collect rows and check for nihongo-japanese class
    while args[i] do
        local row = args[i]
        table.insert(rows, row)
        if string.find(row, 'class="[^"]*nihongo%-japanese[^"]*"') then
            nihongoJapaneseFound = true
        end
        i = i + 1
    end

    local boxArgs = {
        Title = title,
        Icon = icon,
        bg = bg,
        bg2 = bg2,
        height = '400px'
    }

    for i, row in ipairs(rows) do
        boxArgs["r"..i] = row
    end

    -- Only add buttonsHtml if nihongoJapaneseFound is true
    local buttonsHtml = ''
    if nihongoJapaneseFound then
        buttonsHtml = '<div class="quote-buttons" style="text-align:center; background-color:' .. bg2 .. ';">'
        buttonsHtml = buttonsHtml .. '<span class="quote-button mw-ui-button" id="showAllButton">Pokaż wszystko</span>'
        buttonsHtml = buttonsHtml .. '<span class="quote-button mw-ui-button" id="showEnglishButton">Polski</span>'
        buttonsHtml = buttonsHtml .. '<span class="quote-button mw-ui-button" id="showJapaneseButton">Japoński</span>'
        buttonsHtml = buttonsHtml .. '<span class="quote-button mw-ui-button" id="showRomajiButton">Romaji</span>'
        buttonsHtml = buttonsHtml .. '</div>'
    end

    local boxHtml = frame:expandTemplate{title = "Box", args = boxArgs}

    local finalHtml = '<div class="quoteBox boxTemplate">'
    finalHtml = finalHtml .. boxHtml
    finalHtml = finalHtml:gsub('(<div class="boxTemplate2 volume".->)', '%1' .. frame:preprocess(buttonsHtml))
    finalHtml = finalHtml .. '</div>'

    return finalHtml
end

return p