Saltar para o conteúdo

Módulo:Collapsible list

Permanently protected module
Origem: Wikipédia, a enciclopédia livre.

-- This module implements {{collapsible list}}.

localp={}

localfunctiongettitlestyletracking(ts)
ifnottsthenreturn''end
ts=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:')then
return'[[Categoria:!Páginas usando lista minimizável com cor de fundo e posição do texto no estilo do título|'..skey..' ]]'
end
return'[[Categoria:!Páginas usando lista minimizável sem cor de fundo e posição do texto no estilo do título|'..skey..' ]]'
end

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

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)

-- 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'Lista'
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
)..gettitlestyletracking(args.title_styleorargs.titlestyle)
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