This Lua module is used on 52,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 subject to page protection. It is a highly visible module in use by a very large number of pages, and/or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing.
This module implements {{collapsible list}}. Please see the template page for documentation.
-- This module implements {{collapsible list}}.localp={}localfunctiongettitlestyletracking(ts)ifnottsthenreturn''endts=mw.ustring.gsub(mw.ustring.lower(ts),'%s','')localtsvals=mw.text.split(ts,';')table.sort(tsvals)localskey=table.concat(tsvals,';')skey=mw.ustring.gsub(skey,'^;','')skey=mw.text.encode(mw.text.encode(skey),'%c%[%]=')if(mw.ustring.match(';'..ts,';background:')ormw.ustring.match(';'..ts,';background%-color:'))andmw.ustring.match(';'..ts,';text%-align:')thenreturn'[[Category:Pages using collapsible list with both background and text-align in titlestyle|'..skey..' ]]'endreturn'[[Category:Pages using collapsible list without both background and text-align in titlestyle|'..skey..' ]]'endlocalfunctiongetListItem(data)ifnottype(data)=='string'thenreturn''endreturnmw.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)doiftype(k)=='number'andk>=1andmath.floor(k)==kandtype(v)=='string'andmw.ustring.match(v,'%S')thentable.insert(nums,k)endendtable.sort(nums)returnnumsend-- Formats a list of classes, styles or other attributes.localfunctionformatAttributes(attrType,...)localattributes={...}localnums=getArgNums(attributes)localt={}fori,numinipairs(nums)dotable.insert(t,attributes[num])endif#t==0thenreturn''-- Return the blank string so concatenation will work.endreturnmw.ustring.format(' %s="%s"',attrType,table.concat(t,' '))endlocalfunctionbuildList(args)-- Get the list items.locallistItems={}localargNums=getArgNums(args)fori,numinipairs(argNums)dotable.insert(listItems,getListItem(args[num]))endif#listItems==0thenreturn''endlistItems=table.concat(listItems)-- hack around mw-collapsible show/hide jumpiness by looking for text-alignment-- by setting a margin if centeredlocaltextAlignmentCentered='text%-align%s*:%s*center'localcenteredTitle=(args.title_styleandargs.title_style:lower():match(textAlignmentCentered)orargs.titlestyleandargs.titlestyle:lower():match(textAlignmentCentered))localcenteredTitleSpacingifcenteredTitlethencenteredTitleSpacing='margin: 0 4em'elsecenteredTitleSpacing=''end-- Get class, style and title data.localcollapsibleContainerClass=formatAttributes('class','mw-collapsible',notargs.expandand'mw-collapsed')localcollapsibleContainerStyle=formatAttributes('style','text-align: center; font-size: 95%;',args.frame_style,args.framestyle)localcollapsibleTitleStyle=formatAttributes('style','line-height: 1.6em; font-weight: bold; font-size: 100%; text-align: left;',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','font-size: 105%; margin-top: 0; margin-bottom: 0; line-height: inherit; text-align: left;',notargs.bulletsand'list-style: none none; margin-left: 0;',args.list_style,args.liststyle)-- Build the list.returnmw.ustring.format('<div%s%s>\n<div%s><div%s>%s</div></div>\n<ul%s%s>%s</ul>\n</div>',collapsibleContainerClass,collapsibleContainerStyle,collapsibleTitleStyle,jumpyTitleStyle,title,ulclass,ulstyle,listItems)..gettitlestyletracking(args.title_styleorargs.titlestyle)endfunctionp.main(frame)localorigArgsifframe==mw.getCurrentFrame()thenorigArgs=frame:getParent().argsfork,vinpairs(frame.args)doorigArgs=frame.argsbreakendelseorigArgs=frameendlocalargs={}fork,vinpairs(origArgs)doiftype(k)=='number'orv~=''thenargs[k]=vendendreturnbuildList(args)endreturnp