Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Module:Clickable button

Permanently protected module
From Wikipedia, the free encyclopedia
Module documentation[view] [edit] [history] [purge]
Clickable button/sandbox
Code sourceClickable button/sandbox
StatusUnknown

Documentation

Package items

Other items

TODO: Check knownArgs.
['action'] (member)
Arguments whose inputs are case-insensitive, and are converted to lowercase.
(variable)
Valid argument keys.
ignoreblank (variable)
Other options for unknown parameters check.
(variable)
Wrapper templates that only require reading fromparentFrame(). Positional arguments using template parameters (e.g.,{{{var|}}}) are ignored, ascurrentFrame() is not used. Improves performance by avoiding argument checks in both frames.
dummyButton (variable)
Tracking category pagenames with namespace.
(variable)
Preview warning text for unknown arguments.
(variable)
No ARIA-label preview warning text.
(variable)
"Visible label is too long" preview warning text.
(variable)
No arguments preview warning text.
weight (variable)
Default values for button options
legacyClassSets (table)
Namespace exclusions for tracking categories.
['blue'] (member)
Aliases for CSS class:. progressive.
['red'] (member)
Aliases for CSS class:. destructive.
M.yesno() (function)
Returns: any valueBoolean Boolean true if truthy, or false if falsy, or nil if nil. defaultResponse or nil if input is unrecognized.
(variable)
text (variable)
text = gsub(text,"(%-+)","%1")
M.url() (function)
Returns: string|nil displayText Display label for the URL.
(variable)
but still add any custom category passed in.
(variable)
and external links.
(variable)
and thereforearia-disabled = true.
(variable)
Also disabled to accessibility API (aria-disabled = true).

mw.html: Span tag that creates the button.

string|nil Custom CSS style attributes for parent span node (not including plainlinks span tag if URL used).

(table)
Classes, ARIArole andaria-label, andstyle attributes for button span tag.

string Wikilink that wraps around button wikitext.

(variable)
Generate error message when viewed in preview mode of an edit.

string|nil

data.icon (member)
TODO: do i need string check -- type(parsedArgs.icon) == 'string'
(variable)
@TODO Must still actually use this in the CSS file.
rawArgs.label (member)
label value priority:label >text >2 >1
(variable)
@TODO double check next five lines of code
(variable)
rawArgs. disabled = true
(variable)
@TODO refactor: decide if we want to allowor in label, and if so, how to handle it.
M._main() (function)
Returns: string data Wikitext that renders button, without CSS files.

string

M.main() (function)
Returns: string|nil wikitextOutput Wikitext for insertion on a wiki page.

Thismodule is rated asready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned onhelp pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed throughsandbox testing rather than repeated trial-and-error editing.
Page protectedThis module is currentlyprotected from editing.
See theprotection policy andprotection log for more details. Please discuss any changes on thetalk page; you maysubmit an edit request to ask anadministrator to make an edit if it isuncontroversial or supported byconsensus. You may alsorequest that this page be unprotected.
WarningThis Lua module is used in system messages, and onapproximately 1,130,000 pages, or roughly 2% of all pages.
Changes to it can cause immediate changes to the Wikipedia user interface.
To avoid major disruption and server load, any changes should be tested in the module's/sandbox or/testcases subpages, or in your ownmodule sandbox. The tested changes can be added to this page in a single edit. Please discuss changes on thetalk page before implementing them.
This module depends on the following other modules:

This module implements the{{Clickable button}} template.

Click meClick2blueClick me

Usage from wikitext

To use this module from wikitext, you should normally use the{{Clickable button}} template. However, it can also be used with the syntax{{#invoke:Clickable button|main|arguments}}. Please see the template page for a list of available parameters.

Usage from Lua modules

To use this module from other Lua modules, first load the module.

localmClickableButton=require('Module:Clickable button')

You can then generate a button using the.main function.

mClickableButton.main(args)

Theargs variable should be a table containing the arguments to pass to the module. To see the different arguments that can be specified and how they affect the module output, please refer to the{{Clickable button}} template documentation.

The abovedocumentation istranscluded fromModule:Clickable button/doc.(edit |history)
Editors can experiment in this module'ssandbox(edit |diff) and testcases(create) pages.
Subpages of this module.

-- This module implements {{clickable button 2}}.localyesno=require('Module:Yesno')localdelink=require('Module:Delink')._delinklocalp={}functionp.main(frame)localgetArgs=require('Module:Arguments').getArgslocalargs=getArgs(frame)returnp._main(args)endfunctionp._main(args)-- If first arg or a url is not provided,-- but we have a second arg, make a button.-- Otherwise, return nothing.args.originalInput=args[1]args[1]=delink({args[1]})ifargs[1]==""thenargs[1]=nilendifnotargs[1]andnotargs.urlthenifargs[2]thenp.nolink=trueelsereturn''endendlocaldata=p.makeLinkData(args)locallink=p.renderLink(args.originalInput,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]elseifargs[2]thendata.display=args[2]elsedata.display=args.urlp.urlisdisplay=trueendelsedata.isUrl=falsep.urlisdisplay=falsedata.link=args[1]ifargs[2]thendata.display=args[2]elsedata.display=args[1]endifargs[1]andargs[1]:find('http')thendata.isUrl=trueendendifyesno(args.link)==falsethenp.nolink=trueend-- Colours-- For the merge with {{clickable button}}localcolour=args.colorandargs.color:lower()-- 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')end--If class is unset,--then let color determine classifnotclassthenifcolour=='blue'thenclass='mw-ui-progressive'elseifcolour=='red'thenclass='mw-ui-destructive'elseifcolour=='green'thenclass='mw-ui-constructive'endendifclassthentable.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])elseifp.urlisdisplaythencurrentTitle=mw.title.getCurrentTitle()endifsuccessandlinkTitleandmw.title.equals(currentTitle,linkTitle)andnotp.urlisdisplaythenifclass=='ui-button-blue'orclass=='mw-ui-progressive'orclass=='mw-ui-constructive'thendata.backgroundColor='#2962CB'data.color='#fff'elseifclass=='ui-button-green'thendata.backgroundColor='#008B6D'elseifclass=='ui-button-red'orclass=='mw-ui-destructive'thendata.backgroundColor='#A6170F'elsedata.backgroundColor='#CCC'data.color='#666'endelseifp.urlisdisplaythendata.dummyLink=tostring(currentTitle)end-- Add user-specified styles.data.style=args.styleendreturndataendfunctionp.renderLink(originalInput,data)-- Render the display span tag.localdisplaydolocaldisplaySpan=mw.html.create('span')fori,classinipairs(data.classesor{})dodisplaySpan:addClass(class)enddisplaySpan:css{['background-color']=data.backgroundColor,color=data.color}ifdata.stylethendisplaySpan:cssText(data.style)enddisplaySpan:wikitext(data.display)display=tostring(displaySpan)end-- Render the linklocallinkiforiginalInputandoriginalInput:find('|')thenlink=string.format('[[%s|%s]]',delink({originalInput,wikilinks='target'}),display)elseifp.nolinkthenifp.urlisdisplaythenlink=string.format('[[%s|%s]]',data.dummyLink,display)elselink=string.format('%s',display)endelseifdata.isUrlthenlink=string.format('[%s %s]',data.link,display)elselink=string.format('[[%s |%s]]',data.link,display)endendreturnstring.format('<span class="plainlinks clickbutton">%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
Retrieved from "https://en.wikipedia.org/w/index.php?title=Module:Clickable_button&oldid=1236855992"
Category:
Hidden category:

[8]ページ先頭

©2009-2025 Movatter.jp