Difference between revisions of "Module:Airport destination list"
Jump to navigation
Jump to search
blackwiki>Magioladitis m (Protected Module:Airport destination list: To match Template:Airport destination list ([Edit=Allow only template editors and admins] (indefinite) [Move=Allow only template editors and admins] (indefinite))) |
blackwiki>Andy M. Wang (allow param 4thcoltitle for fourth column when specified (per edit request(s))) |
||
| Line 7: | Line 7: | ||
function p.table(frame) | function p.table(frame) | ||
local args = (frame.args[1] ~= nil) and frame.args or frame:getParent().args | local args = (frame.args[1] ~= nil) and frame.args or frame:getParent().args | ||
| − | local cols = isnotempty(args['3rdcoltitle']) | + | local cols |
| + | if isnotempty(args['4thcoltitle']) and isnotempty(args['3rdcoltitle']) then | ||
| + | cols = 4 | ||
| + | elseif isnotempty(args['3rdcoltitle']) then cols = 3 | ||
| + | else cols = 2 | ||
| + | end | ||
-- compute the maximum cell index | -- compute the maximum cell index | ||
| Line 37: | Line 42: | ||
cell:css('width','10%') | cell:css('width','10%') | ||
cell:wikitext(args['3rdcoltitle']) | cell:wikitext(args['3rdcoltitle']) | ||
| + | end | ||
| + | if (isnotempty(args['4thcoltitle'])) then | ||
| + | cell= row:tag('th') | ||
| + | cell:wikitext(args['4thcoltitle']) | ||
end | end | ||
-- loop over rows | -- loop over rows | ||
Revision as of 19:36, 25 July 2016
| This module is subject to page protection. It is a highly visible module in use by a very large number of pages, 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. |
Implements {{Airport destination list}}.
Usage
{{#invoke:Airport destination list|table}}
local p = {}
local function isnotempty(s)
return s and s:match( '^%s*(.-)%s*$' ) ~= ''
end
function p.table(frame)
local args = (frame.args[1] ~= nil) and frame.args or frame:getParent().args
local cols
if isnotempty(args['4thcoltitle']) and isnotempty(args['3rdcoltitle']) then
cols = 4
elseif isnotempty(args['3rdcoltitle']) then cols = 3
else cols = 2
end
-- compute the maximum cell index
local cellcount = 0
for k, v in pairs( args ) do
if type( k ) == 'number' and isnotempty(v) then
cellcount = math.max(cellcount, k)
end
end
-- compute the number of rows
local rows = math.ceil(cellcount / cols)
-- create the root table
local root = mw.html.create('table')
root
:addClass('wikitable')
:addClass('sortable')
:css('font-size', '95%')
-- add the header row
local row = root:tag('tr')
local cell= row:tag('th')
cell:wikitext('Airlines')
cell= row:tag('th')
cell:addClass('unsortable')
cell:wikitext('Destinations')
if (isnotempty(args['3rdcoltitle'])) then
cell= row:tag('th')
cell:css('width','10%')
cell:wikitext(args['3rdcoltitle'])
end
if (isnotempty(args['4thcoltitle'])) then
cell= row:tag('th')
cell:wikitext(args['4thcoltitle'])
end
-- loop over rows
for j=1,rows do
row = root:tag('tr')
for i=1,cols do
cell= row:tag('td')
if (i > 2) then cell:css('text-align','center') end
cell:wikitext(args[cols*(j - 1) + i] or '')
end
end
-- return the root table
return tostring(root)
end
return p