FANDOM


local HF = mw.InfoboxBuilderHF
HF.getArgs = require('Dev:Arguments').getArgs
 
local ContributorNames = mw.loadData( 'Module:ComicsHF/dataContributors' ).ContributorNames
 
function invokeInt(funcName)
  -- This wrapper allows invocation of an internal function from a frame.
	return function (frame)
		local args = HF.getArgs(frame, { trim = true, removeBlanks = true })
		return HF[funcName](args, vars)
	end
end
 
function HF.trim(s)
  if type(s) == 'string' then
    return (s:gsub("^%s*(.-)%s*$", '%1'))
  else
    return false
  end
end
 
function HF.AddZeros( s, len )
  local output = ""
 
  local sLength = string.len( tostring( s ) )
  local diff = tonumber( len ) - tonumber( sLength )
 
  if diff > 0 then
    for i = 1, diff do
      output = output .. "0"
    end
  end
 
  output = output .. s
 
  return output
end
 
function HF.ExternalLink( link, text, plain )
  local output = string.format('[%s %s]', link, text)
 
  if plain == true then
    output = string.format('<span class="plainlinks">%s</span>', output)
  end  
 
  return output
end
 
function HF.CategoryLink( category, sort, text )
  local output = ""
  if not HF.isempty( text ) then
    output = string.format('[[:Category:%s|%s]][[Category:%s|%s]]',
        category, text, category, sort
    )
  else 
    output = string.format('[[Category:%s|%s]]', category, sort)
  end
  return output
end
 
function HF.Link( link, text )
    if not HF.isempty( text ) then
        return string.format('[[%s|%s]]', link, text)
    else
        return string.format('[[%s]]', link)
    end
end
 
function HF.HelpButton( frame )
	local args = HF.getArgs( frame )
	return HF._HelpButton( args )
end
 
function HF._HelpButton( args )
  if HF.isempty( args.buttonsize ) then args.buttonsize = "10px" end
  local target = args.ArticleTarget or "Click here for help with this field"
	local link = string.format(
		"[[File:Information-silk.png|%s|link=Click here for help with this field#%s]] %s",
		args.buttonsize,
		args.Section or args.Label or '',
		args.Label or ''
	)
  return link
end
 
function HF.ContributorNameCorrection( name )
  if type( ContributorNames[ string.lower( name ) ] ) == "string" then
    return ContributorNames[ string.lower( name ) ]
  else
    return name
  end
end
 
HF.TrimOverflow = invokeInt('_TrimOverflow')
 
function HF._TrimOverflow( args )
    local input = args[1]
    local breakat = args['TrimBreak'] or ' '
    local limit = args['TrimLimit'] or 500
    local morelabel = args['TrimMoreLabel'] or 'more...'
    local lesslabel = args['TrimLessLabel'] or 'less...'
    if not input then return nil end
    if mw.ustring.len( input ) > limit then
        local primary   = mw.ustring.sub( input, 1, limit )
        local secondary = mw.ustring.sub( input, limit )
        local shiftatbreak = ''
        if not args['TrimBreak'] and string.find(primary, '·') then breakat = '·'
        elseif not args['TrimBreak'] and string.find(primary, ';') then breakat = ';'
        elseif not args['TrimBreak'] and string.find(primary, ' ') then breakat = ' '
        end
 
        primary, shiftatbreak = mw.ustring.match( primary, '(.*)'..breakat..'(.*)$')
        secondary = shiftatbreak .. secondary
        local morebox = mw.html.create('div')
            :addClass('expansion-tag')
            :addClass('mw-collapsible')
            :addClass('mw-collapsed')
            :attr('data-expandtext',morelabel)
            :attr('data-collapsetext',lesslabel)
            :wikitext(secondary):allDone()
        return primary .. tostring(morebox)
    else
        return input
    end
end
 
return HF

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.