Module:Tabs: Difference between revisions

Want an adless experience? Log in or Create an account.
130 bytes removed ,  June 27, 2020
use the right variables...
No edit summary
(use the right variables...)
Line 117: Line 117:
   return setmetatable( {
   return setmetatable( {
     target = args.target,
     target = args.target,
     selector = args.selector and (tonumber(args.selector) or error('invalid arg: selector must be a number')) or 0,
     selector = args.selector or '0',
     activation = args.activation or 'click',
     activation = args.activation or 'click',
     defaultTab = args.default and (tonumber(args.default) or error('invalid arg: default must be a number')) or 1,
     defaultTab = args.default and (tonumber(args.default) or error('invalid arg: default must be a number')) or 1,
Line 180: Line 180:
     :addClass( 'zdw-tabcontent' )
     :addClass( 'zdw-tabcontent' )
     :attr( 'data-tab-content', self.contentId )
     :attr( 'data-tab-content', self.contentId )
     :wikitext( '\n' .. self.content )
     :wikitext( '\n' .. self.content ) -- newline is needed for tables, lists, etc.


   for k, v in ipairs( mw.text.split( self.contentId, ' ' ) ) do
   for k, v in ipairs( mw.text.split( self.contentId, ' ' ) ) do
Line 205: Line 205:
   local tabs = TabContainer.new( args )
   local tabs = TabContainer.new( args )


   -- fix default tabs if left and top share the same selector
   -- set selectors
   if args.left and args.top and (args.left.selector or '0') == (args.top.selector or '0') then
   if args.left then args.left.selector = '0' end
     if args.left.selector and args.left.selector ~= '0' then args.top.selector = 0 end
  if args.top then args.top.selector = args.combine and '0' or '1' end
     if not args.left.selector then
 
       if args.top.selector and args.top.selector ~= '0' then
  -- fix default tabs if combined
         args.left.selector = 0
  -- l\t  nil    0     #
  -- nil  nil\0  nil\0  0\#
  -- 0    0\nil  0\0    0\#
  -- #    #\0    #\0    #\0
  if args.left and args.top and args.combine then
     if args.left.default and args.left.default ~= '0' then args.top.default = '0' end
     if not args.left.default then
       if args.top.default and args.top.default ~= '0' then
         args.left.default = 0
       else
       else
         args.top.selector = 0
         args.top.default = 0
       end
       end
     end
     end
Line 227: Line 235:


   if args.top then
   if args.top then
    local topArgs = args.top
     local top = tabs:topTabs( args.top )
    if args.left and not topArgs.selector then topArgs.selector = 1 end -- default to 2D behavior if both sets are present
    if args.left and args.left.selector == topArgs.selector and args.left.default ~= 0 then topArgs.default = 0 end
     local top = tabs:topTabs( topArgs )
     for _, tabArgs in ipairs( args.top ) do
     for _, tabArgs in ipairs( args.top ) do
       tabArgs = Args.getTable( tabArgs )
       tabArgs = Args.getTable( tabArgs )