模块:LineList:修订间差异

来自临东市服务器Wiki
无编辑摘要
无编辑摘要
第2行: 第2行:


function p.infobox(frame)
function p.infobox(frame)
     local args = frame.args
     local args = frame:getParent().args
     local lineName = args.Name or ""
     local lineName = args.Name or ""
     local lineColor = args.Color or "gray"
     local lineColor = args.Color or "gray"
     local company = args.Company or ""
     local company = args.Company or ""
    local ticket = args.Ticket or ""
     local firstTrain = args.FirstTrain or ""
     local firstTrain = args.FirstTrain or ""
     local lastTrain = args.LastTrain or ""
     local lastTrain = args.LastTrain or ""
第21行: 第22行:
     time:tag("div"):addClass("first-train"):wikitext(firstTrain)
     time:tag("div"):addClass("first-train"):wikitext(firstTrain)
     time:tag("div"):addClass("last-train"):wikitext(lastTrain)
     time:tag("div"):addClass("last-train"):wikitext(lastTrain)
    time:tag("div"):addClass("ticket"):wikitext(ticket)


     local stationList = output:tag("ul"):addClass("station-list")
     local stationList = output:tag("ul"):addClass("station-list")
第31行: 第33行:
          
          
         if staName then
         if staName then
            local li = stationList:tag("li")
            local stationDiv = li:tag("div"):addClass("name"):wikitext(staName)
           
            local transferInfo = mw.ustring.match(stationInfo, "|(.+)")
            if transferInfo then
                local transferDiv = stationDiv:tag("div"):addClass("transfer")
                for transfer in mw.ustring.gmatch(transferInfo, "([^/]+)") do
                    local line, color = mw.ustring.match(transfer, "(.+)%+(%w+)")
                    if line and color then
                        local transferLineDiv = transferDiv:tag("div")
                        transferLineDiv:tag("div"):wikitext(line)
                        transferLineDiv:tag("div"):css("background-color", color)
                    end
                end
            end
            -- 在站点列表的每个<li>后面添加带有线路颜色的<div class='line'>
             if not insertedLine then
             if not insertedLine then
                 insertedLine = true
                 insertedLine = true
第53行: 第38行:
                 stationList:wikitext("<div class='line' style='background-color:" .. lineColor .. ";'></div>")
                 stationList:wikitext("<div class='line' style='background-color:" .. lineColor .. ";'></div>")
             end
             end
           
            local li = stationList:tag("li")
            local stationDiv = li:tag("div"):addClass("name"):wikitext(staName)
           
            -- local transferInfo = mw.ustring.match(stationInfo, "|(.+)")
            -- if transferInfo then
            --    local transferDiv = stationDiv:tag("div"):addClass("transfer")
            --    for transfer in mw.ustring.gmatch(transferInfo, "([^/]+)") do
            --        local line, color = mw.ustring.match(transfer, "(.+)%+(%w+)")
            --        if line and color then
            --            local transferLineDiv = transferDiv:tag("div")
            --            transferLineDiv:tag("div"):wikitext(line)
            --            transferLineDiv:tag("div"):css("background-color", color)
            --        end
            --    end
            -- end
         end
         end



2023年9月9日 (六) 23:21的版本


local p = {}

function p.infobox(frame)
    local args = frame:getParent().args
    local lineName = args.Name or ""
    local lineColor = args.Color or "gray"
    local company = args.Company or ""
    local ticket = args.Ticket or ""
    local firstTrain = args.FirstTrain or ""
    local lastTrain = args.LastTrain or ""

    local output = mw.html.create("div")
    output:addClass("infobox-card")

    local header = output:tag("div"):addClass("header")
    header:tag("div"):addClass("line-name"):wikitext(lineName)

    local detail = header:tag("div"):addClass("detail")
    detail:tag("div"):addClass("company"):wikitext(company)

    local time = header:tag("div"):addClass("time")
    time:tag("div"):addClass("first-train"):wikitext(firstTrain)
    time:tag("div"):addClass("last-train"):wikitext(lastTrain)
    time:tag("div"):addClass("ticket"):wikitext(ticket)

    local stationList = output:tag("ul"):addClass("station-list")

    local stationIndex = 1
    local insertedLine = false
    while args["Sta" .. stationIndex] do
        local stationInfo = args["Sta" .. stationIndex]
        local staName = mw.ustring.match(stationInfo, "([^|]+)")
        
        if staName then
            if not insertedLine then
                insertedLine = true
                li:done()
                stationList:wikitext("<div class='line' style='background-color:" .. lineColor .. ";'></div>")
            end
            
            local li = stationList:tag("li")
            local stationDiv = li:tag("div"):addClass("name"):wikitext(staName)
            
            -- local transferInfo = mw.ustring.match(stationInfo, "|(.+)")
            -- if transferInfo then
            --     local transferDiv = stationDiv:tag("div"):addClass("transfer")
            --     for transfer in mw.ustring.gmatch(transferInfo, "([^/]+)") do
            --         local line, color = mw.ustring.match(transfer, "(.+)%+(%w+)")
            --         if line and color then
            --             local transferLineDiv = transferDiv:tag("div")
            --             transferLineDiv:tag("div"):wikitext(line)
            --             transferLineDiv:tag("div"):css("background-color", color)
            --         end
            --     end
            -- end
        end

        stationIndex = stationIndex + 1
    end

    return tostring(output)
end

return p