Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Join the Playtest on Steam Now: SpiritVale

Module:Definitions: Difference between revisions

From SpiritVale Wiki
No edit summary
Tags: Mobile edit Mobile web edit
No edit summary
Tags: Mobile edit Mobile web edit
 
(5 intermediate revisions by the same user not shown)
Line 9: Line 9:
-- - CSS namespace: ONLY "sv-def" (plus sv-def--* modifiers).
-- - CSS namespace: ONLY "sv-def" (plus sv-def--* modifiers).
-- - Output classes: sv-def, sv-def-icon, sv-def-icon-img, sv-def-text.
-- - Output classes: sv-def, sv-def-icon, sv-def-icon-img, sv-def-text.
-- - Tooltip/link behavior is handled by Universal Popups (Common.js).


local p = {}
local p = {}
Line 117: Line 118:
-- =============================================================================
-- =============================================================================
-- Icon rendering
-- Icon rendering
-- - Blank icon: render nothing (no generic dot/circle)
-- - Blank icon: render nothing
-- - Missing file: render "?" badge (no redlink image)
-- - Missing file: render "?" badge (no redlink image)
-- =============================================================================
-- =============================================================================
Line 138: Line 139:
end
end


return '<span class="sv-def-icon-img">[[' .. fileTitle .. '|16px|link=]]</span>'
return '<span class="sv-def-icon-img">[[' .. fileTitle .. '|14px|link=]]</span>'
end
end


Line 148: Line 149:
opts = opts or {}
opts = opts or {}
local noicon = truthy(opts.noicon)
local noicon = truthy(opts.noicon)
local pill  = truthy(opts.pill)
local fill  = truthy(opts.fill)


local db = load_db()
local db = load_db()
Line 173: Line 176:
local d_lc = lc(domain)
local d_lc = lc(domain)


-- Missing record: show a visible hint but NO tooltip/link data.
-- Missing record: visible hint, no tooltip/link attributes.
if rec == nil then
if rec == nil then
local miss_icon = noicon and "" or '<span class="sv-def-icon sv-def-icon--missing" aria-hidden="true">?</span>'
local miss_icon = noicon and "" or '<span class="sv-def-icon sv-def-icon--missing" aria-hidden="true">?</span>'
return
return
'<span class="sv-def sv-def--missing sv-def--' .. enc_attr(d_lc) .. '"' ..
'<span class="sv-def sv-def--missing' ..
(pill and ' sv-def--pill' or '') ..
(fill and ' sv-def--fill' or '') ..
' sv-def--' .. enc_attr(d_lc) .. '"' ..
' data-sv-def-domain="' .. enc_attr(domain) .. '"' ..
' data-sv-def-domain="' .. enc_attr(domain) .. '"' ..
' data-sv-def-key="' .. enc_attr(key) .. '"' ..
' data-sv-def-key="' .. enc_attr(key) .. '"' ..
(pill and ' data-sv-def-pill="1"' or '') ..
(fill and ' data-sv-def-fill="1"' or '') ..
'>' ..
'>' ..
miss_icon ..
miss_icon ..
Line 187: Line 195:


local classes = 'sv-def sv-def--' .. enc_attr(d_lc)
local classes = 'sv-def sv-def--' .. enc_attr(d_lc)
if noicon then
if noicon then classes = classes .. ' sv-def--noicon' end
classes = classes .. ' sv-def--noicon'
if pill then classes = classes .. ' sv-def--pill' end
end
if fill then classes = classes .. ' sv-def--fill' end


local attrs = {
local attrs = {
Line 196: Line 204:
'data-sv-def-key="' .. enc_attr(key) .. '"',
'data-sv-def-key="' .. enc_attr(key) .. '"',
}
}
if pill then attrs[#attrs + 1] = 'data-sv-def-pill="1"' end
if fill then attrs[#attrs + 1] = 'data-sv-def-fill="1"' end


-- Only include tooltip/link attributes when populated.
-- Only include tooltip/link attributes when populated.
if defn ~= "" then
if defn ~= "" then
attrs[#attrs + 1] = 'data-sv-def-tip="' .. enc_attr(defn) .. '"'
attrs[#attrs + 1] = 'data-sv-def-tip="' .. enc_attr(defn) .. '"'
-- Interactive definitions are focusable for consistent UX.
attrs[#attrs + 1] = 'tabindex="0"'
end
end
if link ~= "" then
if link ~= "" then
attrs[#attrs + 1] = 'data-sv-def-link="' .. enc_attr(link) .. '"'
attrs[#attrs + 1] = 'data-sv-def-link="' .. enc_attr(link) .. '"'
end
end
local title_attr = (defn ~= "") and (' title="' .. enc_attr(defn) .. '"') or ""


local ico = noicon and "" or icon_html(icon)
local ico = noicon and "" or icon_html(icon)


return
return
'<span ' .. table.concat(attrs, " ") .. title_attr .. '>' ..
'<span ' .. table.concat(attrs, " ") .. '>' ..
ico ..
ico ..
'<span class="sv-def-text">' .. mw.text.nowiki(name) .. '</span>' ..
'<span class="sv-def-text">' .. mw.text.nowiki(name) .. '</span>' ..
Line 225: Line 236:
local key    = a[2] or a.Key or a.key
local key    = a[2] or a.Key or a.key
local noicon = a.noicon or a.NoIcon or a[3]
local noicon = a.noicon or a.NoIcon or a[3]
return render(domain, key, { noicon = noicon })
local pill  = a.pill or a.Pill
local fill  = a.fill or a.Fill
return render(domain, key, { noicon = noicon, pill = pill, fill = fill })
end
end