Module:Clickable button: Difference between revisions
Content deleted Content added
from English Wikipedia |
per Template talk:Clickable button 2#Category:Pages using old style ui-button-color is no longer useful, always return string from renderTrackingCategories; also refactor to local functions |
||
Line 5:
local p = {}
local function
if yesno(args.category) == false then▼
local args = require('Module:Arguments').getArgs(frame, {▼
wrappers = 'Template:Clickable button 2'▼
})▼
return p.luaMain(args)▼
end▼
function p.luaMain(args)▼
return ''
end
local data = p.makeLinkData(args)▼
-- we have no tracking categories currently but args.category should be
local link = p.renderLink(data)▼
-- supported into the future, so just return a string here for now
local trackingCategories = p.renderTrackingCategories(args)▼
return
end
local function
local data = {}
-- Get the link and display values,
-- and find whether we are outputting
-- a wikilink or a URL.
if args.url then
data.isUrl = true
Line 32 ⟶ 26:
if args[1] then
data.display = args[1]
else if args[2] then
data.display = args[2]
else
data.display = args.url
p.urlisdisplay = true
end
end
else
data.isUrl = false
p.urlisdisplay = false
data.link = args[1]
if args[2] then
Line 44 ⟶ 43:
end
end
if yesno(args.link) == false then
p.nolink = true
end▼
-- Colours
-- For the merge with {{clickable button}}
local colour = args.color and args.color:lower()
-- Classes
Line 60 ⟶ 67:
table.insert(data.classes, 'mw-ui-button')
end
--If class is unset,
--then let color determine class
if not class then
if colour == 'blue' then
else if colour == 'red' then
else if colour == 'green' then
class = 'mw-ui-constructive'
end
end
end
end
if class then
table.insert(data.classes, class)
Line 77 ⟶ 99:
currentTitle = mw.title.getCurrentTitle()
success, linkTitle = pcall(mw.title.new, args[1])
elseif p.urlisdisplay then
currentTitle = mw.title.getCurrentTitle()
end
if success
and linkTitle
and mw.title.equals(currentTitle, linkTitle)
and not p.urlisdisplay
then
if class == 'ui-button-blue'
Line 87 ⟶ 112:
then
data.backgroundColor = '#2962CB'
data.color = '#fff'
elseif class == 'ui-button-green' then
data.backgroundColor = '#008B6D'
Line 94 ⟶ 120:
data.backgroundColor = '#CCC'
data.color = '#666'
end
if p.urlisdisplay
data.dummyLink = tostring(currentTitle)
end
end
Line 103 ⟶ 134:
end
local function
-- Render the display span tag.
local display
Line 124 ⟶ 155:
-- Render the link
local link
if
if p.urlisdisplay then
link = string.format('[%s %s]', data.link, display)▼
▲ else
▲ link = string.format('[[%s|%s]]', data.link, display)
link = string.format('%s', display)
end
else if data.isUrl then
▲ link = string.format('[%s %s]', data.link, display)
else
link = string.format('[[%s|%s]]', data.link, display)
end
end
return string.format('<span class="plainlinks clickbutton">%s</span>', link)
end
function p.
-- If first arg or a url is not provided,
▲ if yesno(args.category) == false then
-- but we have a second arg, make a button.
return ''▼
-- Otherwise, return nothing.
▲ end
if args[2] then
p.nolink = true
▲ or class == 'ui-button-blue'
else
▲ or class == 'ui-button-red'
▲ return ''
▲ then
end
▲ else
end
return link .. trackingCategories
▲end
▲ local args = require('Module:Arguments').getArgs(frame, {
▲ wrappers = 'Template:Clickable button 2'
▲ })
▲ return p.luaMain(args)
end
|