Module:Clickable button
Tools
Actions
General
Print/export
Documentation for this module may be created atModule:Clickable button/doc
-- This module implements {{clickable button 2}}.localyesno=require('Module:Yesno')localp={}functionp.main(frame)localargs=require('Module:Arguments').getArgs(frame,{wrappers='Template:Clickable button'})returnp.luaMain(args)endfunctionp.luaMain(args)ifnotargs[1]andnotargs.urlthenreturn''endlocaldata=p.makeLinkData(args)locallink=p.renderLink(data)localtrackingCategories=p.renderTrackingCategories(args)returnlink..trackingCategoriesendfunctionp.makeLinkData(args)localdata={}-- Get the link and display values, and find whether we are outputting a-- wikilink or a URL.ifargs.urlthendata.isUrl=truedata.link=args.urlifargs[1]thendata.display=args[1]elsedata.display=args.textorargs.urlendelsedata.isUrl=falsedata.link=args[1]ifargs[2]thendata.display=args[2]elsedata.display=args[1]endend-- Classeslocalclass=args.classandargs.class:lower()data.classes={}ifclass=='ui-button-green'orclass=='ui-button-blue'orclass=='ui-button-red'thentable.insert(data.classes,'submit ui-button ui-widget ui-state-default ui-corner-all'..' ui-button-text-only ui-button-text')elsetable.insert(data.classes,'mw-ui-button')endifclassthentable.insert(data.classes,class)end-- Stylesdo--[[-- Check whether we are on the same page as we have specified in-- args[1], but not if we are using a URL link, as then args[1] is only-- a display value. If we are currently on the page specified in-- args[1] make the button colour darker so that it stands out from-- other buttons on the page.--]]localsuccess,linkTitle,currentTitleifnotdata.isUrlthencurrentTitle=mw.title.getCurrentTitle()success,linkTitle=pcall(mw.title.new,args[1])endifsuccessandlinkTitleandmw.title.equals(currentTitle,linkTitle)thenifclass=='ui-button-blue'orclass=='mw-ui-progressive'thendata.backgroundColor='#2962CB'elseifclass=='ui-button-green'orclass=='mw-ui-constructive'thendata.backgroundColor='#008B6D'elseifclass=='ui-button-red'orclass=='mw-ui-destructive'thendata.backgroundColor='#A6170F'elsedata.backgroundColor='#CCC'data.color='#666'endend-- Add user-specified styles.data.style=args.styleendreturndataendfunctionp.renderLink(data)-- Render the display span tag.localdisplaydolocaldisplaySpan=mw.html.create('span')fori,classinipairs(data.classesor{})dodisplaySpan:addClass(class)enddisplaySpan:attr('role','button'):attr('aria-disabled','false'):css{['background-color']=data.backgroundColor,color=data.color}ifdata.stylethendisplaySpan:cssText(data.style)enddisplaySpan:wikitext(data.display)display=tostring(displaySpan)end-- Render the linklocallinkifdata.isUrlthenlink=string.format('[%s %s]',data.link,display)elselink=string.format('[[%s|%s]]',data.link,display)endreturnstring.format('<span class="plainlinks">%s</span>',link)endfunctionp.renderTrackingCategories(args)ifyesno(args.category)==falsethenreturn''endlocalclass=args.classandargs.class:lower()ifclass=='ui-button-green'orclass=='ui-button-blue'orclass=='ui-button-red'thenreturn'[[Category:Pages using old style ui-button-color]]'elsereturn''endendreturnp