PlaycityMap installer (토론 | 기여)님의 2025년 12월 19일 (금) 16:49 판 (Install PlaycityMap module)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)
분류:

이 모듈에 대한 설명문서는 모듈:PlaycityMap/설명문서에서 만들 수 있습니다

local p = {}

local function normalizeArg(value)
  if value == nil then
    return nil
  end
  local text = tostring(value)
  if text == "" then
    return nil
  end
  return text
end

local function buildEmbedUrl(args)
  local base = normalizeArg(args.base) or "https://maps.playcity.kr/embed"
  local query = {}
  if normalizeArg(args.mode) then
    query.mode = args.mode
  end
  if normalizeArg(args.x) then
    query.x = args.x
  end
  if normalizeArg(args.z) then
    query.z = args.z
  end
  if normalizeArg(args.center) then
    query.center = args.center
  end
  if normalizeArg(args.zoom) then
    query.zoom = args.zoom
  end
  local controlValue = normalizeArg(args.control) or normalizeArg(args.controls) or normalizeArg(args.interactive)
  if controlValue then
    query.control = controlValue
  end
  if normalizeArg(args.marker) then
    query.marker = args.marker
  end
  if normalizeArg(args.hash) then
    query.hash = args.hash
  end

  local qs = mw.uri.buildQueryString(query)
  if qs == "" then
    return base
  end
  return base .. "?" .. qs
end

function p.embed(frame)
  local args = (frame.getParent and frame:getParent() or frame).args or {}
  local width = normalizeArg(args.width) or "100%"
  local height = normalizeArg(args.height) or "420"
  local loading = normalizeArg(args.loading) or "lazy"
  local referrerpolicy = normalizeArg(args.referrerpolicy) or "no-referrer-when-downgrade"

  local iframe = mw.html.create("iframe")
    :attr("src", buildEmbedUrl(args))
    :attr("width", width)
    :attr("height", height)
    :attr("loading", loading)
    :attr("referrerpolicy", referrerpolicy)
    :attr("allowfullscreen", "true")
    :css("border", "0")

  return tostring(iframe)
end

return p

분류