Jump to content

Module:Location map and Module:Location map/sandbox: Difference between pages

(Difference between pages)
Page 1
Page 2
Content deleted Content added
Per edit request
 
Added parameter to opt-out of noresize
 
Line 173: Line 173:
end
end
end
end
local retval = frame:extensionTag{name = 'templatestyles', args = {src = 'Module:Location map/styles.css'}}
local retval = frame:extensionTag{name = 'templatestyles', args = {src = 'Module:Location map/sandbox/styles.css'}}
if args.float == 'center' then
if args.float == 'center' then
retval = retval .. '<div class="center">'
retval = retval .. '<div class="center">'
end
end
if args.caption and args.caption ~= '' and args.border ~= 'infobox' then
if args.caption and args.caption ~= '' and args.border ~= 'infobox' then
retval = retval .. '<div class="locmap noviewer noresize thumb '
retval = retval .. '<div class="locmap noviewer' .. (args.noresize ~= false and ' noresize' or '') .. ' thumb '
if args.float == '"left"' or args.float == 'left' then
if args.float == '"left"' or args.float == 'left' then
retval = retval .. 'tleft'
retval = retval .. 'tleft'
Line 291: Line 291:
end
end


local function markOuterDiv(x, y, imageDiv, labelDiv, label_size)
local function markOuterDiv(x, y, imageDiv, labelDiv)
return mw.html.create('div')
return mw.html.create('div')
:addClass('od')
:addClass('od')
:addClass('notheme') -- T236137
:addClass('notheme') -- T236137
:cssText('top:' .. round(y, 3) .. '%;left:' .. round(x, 3) .. '%;font-size:' .. label_size .. '%')
:cssText('top:' .. round(y, 3) .. '%;left:' .. round(x, 3) .. '%')
:node(imageDiv)
:node(imageDiv)
:node(labelDiv)
:node(labelDiv)
Line 319: Line 319:
end
end


local function markLabelDiv(label, label_size, label_width, position, background, x, marksize)
local function markLabelDiv(label, label_size, label_width, position, background, x, marksize, top, compact)
if tonumber(label_size) == 0 then
if tonumber(label_size) == 0 then
return mw.html.create('div'):addClass('l0'):wikitext(label)
return mw.html.create('div'):addClass('l0'):wikitext(label)
end
end
local builder = mw.html.create('div')
local builder = mw.html.create('div')
:cssText('width:' .. label_width .. 'em')
:cssText('font-size:' .. label_size .. '%;width:' .. label_width .. 'em')
local distance = round(marksize / 2 + 1)
local distance = round(marksize / 2 + 1)
if position == 'top' then -- specified top
if position == 'top' then -- specified top
builder:addClass('pv'):cssText('bottom:' .. distance .. 'px;left:' .. (-label_width / 2) .. 'em')
builder:addClass(compact and 'pvc' or 'pv'):cssText('bottom:' .. distance .. 'px;left:' .. (-label_width / 2) .. 'em')
elseif position == 'bottom' then -- specified bottom
elseif position == 'bottom' then -- specified bottom
builder:addClass('pv'):cssText('top:' .. distance .. 'px;left:' .. (-label_width / 2) .. 'em')
builder:addClass(compact and 'pvc' or 'pv'):cssText('top:' .. distance .. 'px;left:' .. (-label_width / 2) .. 'em')
else
elseif position == 'left' or (tonumber(x) > 70 and position ~= 'right') then -- specified left or autodetected to left
if position == 'left' or (tonumber(x) > 70 and position ~= 'right') then -- specified left or autodetected to left
builder:addClass('pl'):cssText('right:' .. distance .. 'px')
builder:addClass(compact and 'plc' or 'pl'):cssText('right:' .. distance .. 'px')
else -- specified right or autodetected to right
else -- specified right or autodetected to right
builder:addClass('pr'):cssText('left:' .. distance .. 'px')
builder:addClass(compact and 'prc' or 'pr'):cssText('left:' .. distance .. 'px')
end
if top then
builder:cssText('top:' .. top .. 'em')
end
end
end
builder = builder:tag('div')
builder = builder:tag('div') -- not 'span' to avoid Linter errors if the label contains block content
:wikitext(label)
:wikitext(label)
if background then
if background then
Line 360: Line 365:
end
end


function p.mark(frame, args, map)
function p.mark(frame, args, map, ...)
if not args then
if not args then
args = getArgs(frame, {wrappers = 'Template:Location map~'})
args = getArgs(frame, {wrappers = 'Template:Location map~'})
Line 388: Line 393:
return table.concat(outputs, '#PlaceList#') .. '#PlaceList#'
return table.concat(outputs, '#PlaceList#') .. '#PlaceList#'
end
end
local containerArgs = ...
local x, y, longitude, latitude
local x, y, longitude, latitude
longitude = decdeg(args.lon_deg, args.lon_min, args.lon_sec, args.lon_dir, args.long, 'longitude')
longitude = decdeg(args.lon_deg, args.lon_min, args.lon_sec, args.lon_dir, args.long, 'longitude')
Line 494: Line 500:
local marksize = tonumber(args.marksize) or tonumber(map('marksize')) or 8
local marksize = tonumber(args.marksize) or tonumber(map('marksize')) or 8
local imageDiv = markImageDiv(mark, marksize, args.label or mw.title.getCurrentTitle().text, args.link or '', args.alt, args[2])
local imageDiv = markImageDiv(mark, marksize, args.label or mw.title.getCurrentTitle().text, args.link or '', args.alt, args[2])
local label_size = args.label_size or 91
local labelDiv
local labelDiv
if args.label and args.position ~= 'none' then
if args.label and args.position ~= 'none' then
labelDiv = markLabelDiv(args.label, label_size, args.label_width or 6, args.position, args.background, x, marksize)
labelDiv = markLabelDiv(args.label, args.label_size or 91, args.label_width or 6, args.position, args.background, x, marksize, args.label_top, containerArgs and containerArgs.CompactLabels)
end
end
return builder:node(markOuterDiv(x, y, imageDiv, labelDiv, label_size))
return builder:node(markOuterDiv(x, y, imageDiv, labelDiv))
end
end