Jump to content
Wikipedia The Free Encyclopedia

Module:Collapsible list

From Wikipedia, the free encyclopedia
Module documentation[view] [edit] [history] [purge]
Warning This Lua module is used on 66,000+ pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them.
This module is rated as ready 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 on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing.
Page template-protected This module is currently protected from editing.
See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected.

This module implements {{collapsible list }}. Please see the template page for documentation.

The above documentation is transcluded from Module:Collapsible list/doc. (edit | history)
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Subpages of this module.

 localp={}

 localfunctiongetListItem(data)
 ifnottype(data)=='string'then
 return''
 end
 returnmw.ustring.format('<li style="line-height: inherit; margin: 0">%s</li>',data)
 end

 -- Returns an array containing the keys of all positional arguments
 -- that contain data (i.e. non-whitespace values).
 localfunctiongetArgNums(args)
 localnums={}
 fork,vinpairs(args)do
 iftype(k)=='number'and
 k>=1and
 math.floor(k)==kand
 type(v)=='string'and
 mw.ustring.match(v,'%S')then
 table.insert(nums,k)
 end
 end
 table.sort(nums)
 returnnums
 end

 -- Formats a list of classes, styles or other attributes.
 localfunctionformatAttributes(attrType,...)
 localattributes={...}
 localnums=getArgNums(attributes)
 localt={}
 fori,numinipairs(nums)do
 table.insert(t,attributes[num])
 end
 if#t==0then
 return''-- Return the blank string so concatenation will work.
 end
 returnmw.ustring.format(' %s="%s"',attrType,table.concat(t,' '))
 end

 -- TODO: use Module:List. Since the update for this comment is routine,
 -- this is blocked without a consensus discussion by
 -- [[MediaWiki_talk:Common.css/Archive_15#plainlist_+_hlist_indentation]]
 -- if we decide hlist in plainlist in this template isn't an issue, we can use
 -- module:list directly
 -- [https://en.wikipedia.org/w/index.php?title=Module:Collapsible_list/sandbox&oldid=1130172480]
 -- is an implementation (that will code rot slightly I expect)
 localfunctionbuildList(args)
 -- Get the list items.
 locallistItems={}
 localargNums=getArgNums(args)
 fori,numinipairs(argNums)do
 table.insert(listItems,getListItem(args[num]))
 end
 if#listItems==0then
 return''
 end
 listItems=table.concat(listItems)

 -- hack around mw-collapsible show/hide jumpiness by looking for text-alignment
 -- by setting a margin if centered
 localtextAlignmentCentered='text%-align%s*:%s*center'
 localcenteredTitle=(args.title_styleandargs.title_style:lower():match(textAlignmentCentered)
 orargs.titlestyleandargs.titlestyle:lower():match(textAlignmentCentered))
 localcenteredTitleSpacing
 ifcenteredTitlethen
 centeredTitleSpacing='margin: 0 4em'
 else
 centeredTitleSpacing=''
 end

 -- Get class, style and title data.
 localcollapsibleContainerClass=formatAttributes(
 'class',
 'collapsible-list',
 'mw-collapsible',
 notargs.expandand'mw-collapsed'
 )
 localcollapsibleContainerStyle=formatAttributes(
 'style',
 -- mostly work around .infobox-full-data defaulting to centered
 'text-align: left;',
 args.frame_style,
 args.framestyle
 )
 localcollapsibleTitleStyle=formatAttributes(
 'style',
 'line-height: 1.6em; font-weight: bold;',
 args.title_style,
 args.titlestyle
 )
 localjumpyTitleStyle=formatAttributes(
 'style',
 centeredTitleSpacing
 )
 localtitle=args.titleor'List'
 localulclass=formatAttributes('class','mw-collapsible-content',args.hlistand'hlist')
 localulstyle=formatAttributes(
 'style',
 'margin-top: 0; margin-bottom: 0; line-height: inherit;',
 notargs.bulletsand'list-style: none; margin-left: 0;',
 args.list_style,
 args.liststyle
 )

 localhlist_templatestyles=''
 ifargs.hlistthen
 hlist_templatestyles=mw.getCurrentFrame():extensionTag{
 name='templatestyles',args={src='Hlist/styles.css'}
 }
 end

 -- Build the list.
 returnmw.ustring.format(
 '%s<div%s%s>\n<div%s><div%s>%s</div></div>\n<ul%s%s>%s</ul>\n</div>',
 hlist_templatestyles,collapsibleContainerClass,collapsibleContainerStyle,
 collapsibleTitleStyle,jumpyTitleStyle,title,ulclass,ulstyle,listItems
 )
 end

 functionp.main(frame)
 localorigArgs
 ifframe==mw.getCurrentFrame()then
 origArgs=frame:getParent().args
 fork,vinpairs(frame.args)do
 origArgs=frame.args
 break
 end
 else
 origArgs=frame
 end

 localargs={}
 fork,vinpairs(origArgs)do
 iftype(k)=='number'orv~=''then
 args[k]=v
 end
 end
 returnbuildList(args)
 end

 returnp

AltStyle によって変換されたページ (->オリジナル) /