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={}localfunctiongetListItem(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)-- Get class, style and title data.localdiv1class=formatAttributes('class','NavFrame',notargs.expandand'collapsed')localdiv1style=formatAttributes('style',args.frame_style,args.framestyle,not(args.frame_styleorargs.framestyle)and'border: none; padding: 0;')localdiv2class=formatAttributes('class','NavHead')localdiv2style=formatAttributes('style','font-size: 105%;',args.title_style,args.titlestyle,not(args.title_styleorargs.titlestyle)and'background: transparent; text-align: left;')localtitle=args.titleor'List'localulclass=formatAttributes('class','NavContent',args.hlistand'hlist')localulstyle=formatAttributes('style',notargs.bulletsand'list-style: none none; margin-left: 0;',args.list_style,args.liststyle,not(args.list_styleorargs.liststyle)and'text-align: left;','font-size: 105%; margin-top: 0; margin-bottom: 0; line-height: inherit;')-- Build the list.returnmw.ustring.format('<div%s%s>\n<div%s%s>%s</div>\n<ul%s%s>%s</ul>\n</div>',div1class,div1style,div2class,div2style,title,ulclass,ulstyle,listItems)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