Module:Portal bar/sandbox
Appearance
From Wikipedia, the free encyclopedia
This module depends on the following other modules:
This module implements the {{portal bar }} template. It displays a horizontal bar of portals.
See here and here for testcases.
Note: in order to make the test cases work, the Sandbox CSS classes have "-sand" appended to their names. If you wish to update the CSS, copy the contents of each class from Module:Portal bar/sandbox/styles.css to Module:Portal bar/styles.css, but do not alter the class names, nor just copy-paste the entire CSS file. For the current difference in CSS between Sandbox and Main, see here.
Usage
[edit ]{{#invoke:Portal bar|main|''portal 1''|''portal 2 ''|...|border=''no''}}
- Positional parameters - the names of the portals to be displayed.
border- if|border=is equal tono,n,false, or0, then the portal box will have no border.redlinks- if|redlinks=is equal toyes,y,trueorinclude, then the portal box will show redlinked portals
Examples
[edit ]{{#invoke:portal bar|main|Visual arts|Science|Literature}}
Produces:
{{#invoke:portal bar|main|Visual arts|Science|Literature|border=no}}
Produces:
For further examples, see Template:Portal bar/testcases.
Images
[edit ]This module uses Module:Portal to get portal images. To add, change, or remove images, please see the instructions at Module:Portal#Image.
The above documentation is transcluded from Module:Portal bar/doc. (edit | history)
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Add categories to the /doc subpage. Subpages of this module.
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Add categories to the /doc subpage. Subpages of this module.
-- This module implements {{portal bar}}. require('strict') -- determine whether we're being called from a sandbox localisSandbox=mw.getCurrentFrame():getTitle():find('sandbox',1,true) localsandbox=isSandboxand'/sandbox'or'' localportalModule=require('Module:Portal'..sandbox) localgetImageName=portalModule._image localcheckPortals=portalModule._checkPortals localprocessPortalArgs=portalModule._processPortalArgs localyesno=require('Module:Yesno') localgetArgs=require('Module:Arguments').getArgs localp={} localfunctionsandboxVersion(s) returnisSandboxands.."-sand"ors end -- Builds the portal bar used by {{portal bar}}. functionp._main(portals,args) -- check for sensible args args=type(args)=="table"andargsor{} -- Normalize arguments forkey,defaultinpairs({border=true,redlinks=false,tracking=true})do ifargs[key]==nilthenargs[key]=defaultend args[key]=yesno(args[key],default) end localnav=mw.html.create('div') :addClass(sandboxVersion('portal-bar')) :addClass('noprint metadata noviewer') :attr('role','navigation') :attr('aria-label','Portals') :addClass(sandboxVersion(args.borderand'portal-bar-bordered'or'portal-bar-unbordered')) localtrackingCat='' -- Allow any number of portals args.minPortals=0 args.maxPortals=-1 -- Check to see whether there are redlinks, filter out unless args.redlink is true portals,trackingCat=checkPortals(portals,args) nav:wikitext(trackingCat) if#portals==0then returntrackingCat end localrelated=yesno(args.related) ifrelatedthen nav:addClass(sandboxVersion('portal-bar-related')) else localheader=nav:tag('span') header:addClass(sandboxVersion('portal-bar-header')) header:wikitext('[[Wikipedia:Contents/Portals|Portal]]') if#portals>1then header:wikitext('s') end header:wikitext(':') end localcontainer=nav:tag('ul') container:addClass(sandboxVersion('portal-bar-content')) ifrelatedthen container:addClass(sandboxVersion('portal-bar-content-related')) end localsize=relatedand'28x24px'or'21x19px' for_,portalinipairs(portals)do container :tag('li') :addClass(sandboxVersion('portal-bar-item')) :wikitext(string.format('<span class="nowrap" aria-hidden="true">[[File:%s|%s]] </span>[[Portal:%s|%s]]', getImageName(portal,true),size,portal,portal)) end localstyleFile='Module:Portal bar'..sandbox..'/styles.css' returnmw.getCurrentFrame():extensionTag{ name='templatestyles',args={src=styleFile} }..tostring(nav) end -- Processes external arguments and sends them to the other functions. functionp.main(frame) localorigArgs=getArgs(frame) localportals,args=processPortalArgs(origArgs) returnp._main(portals,args) end returnp