More actions
No edit summary |
modified script to make quick-link-cards clickable, instead of just the anchor Tag: Reverted |
||
Line 110: | Line 110: | ||
local description = args.description or '' | local description = args.description or '' | ||
-- If there's no link, create the card as before (non-clickable) | |||
if link == '' then | |||
local html = mw.html.create('div') | |||
:addClass('vh-quick-link-card') | |||
if icon ~= '' then | |||
html:tag('div') | |||
:addClass('vh-quick-link-icon') | |||
:wikitext(icon) | |||
end | |||
if title ~= '' then | |||
html:tag('div') | |||
:addClass('vh-quick-link-title') | |||
:wikitext(title) | |||
end | |||
if description ~= '' then | |||
html:tag('div') | |||
:addClass('vh-quick-link-desc') | |||
:wikitext(description) | |||
end | |||
return tostring(html) | |||
end | |||
-- If there's a link, wrap the entire card in an anchor tag | |||
local html = mw.html.create('div') | local html = mw.html.create('div') | ||
:addClass('vh-quick-link-card') | :addClass('vh-quick-link-card') | ||
-- Convert MediaWiki link to proper URL | |||
local href = mw.uri.encode(link, 'PATH') | |||
if not string.match(link, '^https?://') then | |||
-- Internal wiki link | |||
href = mw.title.new(link):fullUrl() | |||
end | |||
-- Create the anchor wrapper that covers the entire card content | |||
local linkWrapper = html:tag('a') | |||
:attr('href', href) | |||
:attr('style', 'text-decoration: none; color: inherit; display: block;') | |||
-- Add content inside the link | |||
if icon ~= '' then | if icon ~= '' then | ||
linkWrapper:tag('div') | |||
:addClass('vh-quick-link-icon') | :addClass('vh-quick-link-icon') | ||
:wikitext(icon) | :wikitext(icon) | ||
Line 120: | Line 160: | ||
if title ~= '' then | if title ~= '' then | ||
linkWrapper:tag('div') | |||
:addClass('vh-quick-link-title') | :addClass('vh-quick-link-title') | ||
:wikitext(title) | |||
end | end | ||
if description ~= '' then | if description ~= '' then | ||
linkWrapper:tag('div') | |||
:addClass('vh-quick-link-desc') | :addClass('vh-quick-link-desc') | ||
:wikitext(description) | :wikitext(description) |
Revision as of 03:43, 23 July 2025
Documentation for this module may be created at Module:Card/doc
local p = {}
local validTypes = {
default = true,
primary = true,
success = true,
warning = true,
destructive = true,
spacer = true,
}
function p.main(frame)
local args = frame:getParent().args
return p._main(args)
end
function p._main(args)
local cardType = args.type or 'default'
local icon = args.icon or ''
local title = args.title or ''
local content = args.content or ''
local footer = args.footer or ''
local link = args.link or ''
if not validTypes[cardType] then
cardType = 'default'
end
if cardType == 'spacer' then
-- Spacers should be completely empty elements. The grid will handle the rest.
local div = mw.html.create('div')
:addClass('vh-card--spacer')
return tostring(div)
end
-- Build the card HTML
local html = mw.html.create('div')
:addClass('vh-card')
:addClass('vh-card--' .. cardType)
-- Add header if title or icon exists
if title ~= '' or icon ~= '' then
local header = html:tag('div')
:addClass('vh-card-header')
if icon ~= '' then
header:tag('span')
:addClass('vh-card-icon')
:wikitext(icon)
end
if title ~= '' then
local titleElement = header:tag('h3')
:addClass('vh-card-title')
if link ~= '' then
titleElement:wikitext('[[' .. link .. '|' .. title .. ']]')
else
titleElement:wikitext(title)
end
end
end
-- Add content
if content ~= '' then
html:tag('div')
:addClass('vh-card-content')
:wikitext(content)
end
-- Add footer if exists
if footer ~= '' then
html:tag('div')
:addClass('vh-card-footer')
:wikitext(footer)
end
return tostring(html)
end
--[[
MODIFIED FUNCTION
This function is changed to prevent MediaWiki from wrapping cards in <p> tags.
It now preprocesses the content to expand the templates (e.g., {{Card}})
and then builds the final HTML as a raw string. This bypasses the parser
issue and ensures the .vh-card divs are direct children of the .vh-card-group.
]]
function p.group(frame)
local args = frame:getParent().args
local content = args.content or args[1] or ''
-- Preprocess the content to expand the templates into HTML
local processedContent = frame:preprocess(content)
-- Return the container div with the processed content as a raw string
return frame:extensionTag{
name = 'div',
content = processedContent,
args = { class = 'vh-card-group' }
}
end
function p.quickLink(frame)
local args = frame:getParent().args
local icon = args.icon or ''
local title = args.title or ''
local link = args.link or ''
local description = args.description or ''
-- If there's no link, create the card as before (non-clickable)
if link == '' then
local html = mw.html.create('div')
:addClass('vh-quick-link-card')
if icon ~= '' then
html:tag('div')
:addClass('vh-quick-link-icon')
:wikitext(icon)
end
if title ~= '' then
html:tag('div')
:addClass('vh-quick-link-title')
:wikitext(title)
end
if description ~= '' then
html:tag('div')
:addClass('vh-quick-link-desc')
:wikitext(description)
end
return tostring(html)
end
-- If there's a link, wrap the entire card in an anchor tag
local html = mw.html.create('div')
:addClass('vh-quick-link-card')
-- Convert MediaWiki link to proper URL
local href = mw.uri.encode(link, 'PATH')
if not string.match(link, '^https?://') then
-- Internal wiki link
href = mw.title.new(link):fullUrl()
end
-- Create the anchor wrapper that covers the entire card content
local linkWrapper = html:tag('a')
:attr('href', href)
:attr('style', 'text-decoration: none; color: inherit; display: block;')
-- Add content inside the link
if icon ~= '' then
linkWrapper:tag('div')
:addClass('vh-quick-link-icon')
:wikitext(icon)
end
if title ~= '' then
linkWrapper:tag('div')
:addClass('vh-quick-link-title')
:wikitext(title)
end
if description ~= '' then
linkWrapper:tag('div')
:addClass('vh-quick-link-desc')
:wikitext(description)
end
return tostring(html)
end
return p