FANDOM


m
m
 
Line 6: Line 6:
   
 
function p.main(frame)
 
function p.main(frame)
local args = frame:getParent().args
+
local args = frame:getParent().args
local colourPrefix = 'colour'
+
local colourPrefix = 'colour'
local namePrefix = 'name'
+
local namePrefix = 'name'
local tbl = mw.html.create('table')
+
local limit = tonumber(args.limit) or 16
:addClass('recolour-table')
+
local tbl = mw.html.create('table')
local row
+
:addClass('recolour-table')
local curArg
+
local row
+
local curArg
for i=1, 16 do
+
curColour = args[colourPrefix .. tostring(i)] or '#fff'
+
for i=1, limit do
curName = args[namePrefix .. tostring(i)] or 'White'
+
curColour = args[colourPrefix .. tostring(i)] or '#fff'
  +
curName = args[namePrefix .. tostring(i)] or 'White'
   
if i % 4 == 1 then
+
if i % 4 == 1 then
if row then
+
if row then
tbl = row:done()
+
tbl = row:done()
:tag('tr')
+
:tag('tr')
:addClass('rec-empty-row')
+
:addClass('rec-empty-row')
:tag('td')
+
:tag('td')
:addClass('rec-empty-cell')
+
:addClass('rec-empty-cell')
:done()
+
:done()
:done()
+
:done()
end
+
end
+
row = tbl:tag('tr')
+
row = tbl:tag('tr')
end
+
end
+
row:tag('td')
+
row:tag('td')
:addClass('rec-cell')
+
:addClass('rec-cell')
:css('background', curColour)
+
:css('background', curColour)
:attr('title', curName)
+
:attr('title', curName)
:done()
+
:done()
+
if i % 4 ~= 0 then
+
if i % 4 ~= 0 then
row:tag('td')
+
row:tag('td')
:addClass('rec-empty-cell')
+
:addClass('rec-empty-cell')
:done()
+
:done()
end
+
end
+
end
+
end
+
return tostring(tbl:allDone())
+
return tostring(tbl:allDone())
 
end
 
end
   

Latest revision as of 20:09, August 21, 2017

-- <nowiki>
-- Implements {{Recolours}}
--
 
local p = {}
 
function p.main(frame)
    local args = frame:getParent().args
    local colourPrefix = 'colour'
    local namePrefix = 'name'
    local limit = tonumber(args.limit) or 16
    local tbl = mw.html.create('table')
            :addClass('recolour-table')
    local row
    local curArg
 
    for i=1, limit do
        curColour = args[colourPrefix .. tostring(i)] or '#fff'
        curName = args[namePrefix .. tostring(i)] or 'White'
 
        if i % 4 == 1 then
            if row then
                tbl = row:done()
                        :tag('tr')
                            :addClass('rec-empty-row')
                            :tag('td')
                                :addClass('rec-empty-cell')
                                :done()
                            :done()
            end
 
            row = tbl:tag('tr')
        end
 
        row:tag('td')
            :addClass('rec-cell')
            :css('background', curColour)
            :attr('title', curName)
            :done()
 
        if i % 4 ~= 0 then
            row:tag('td')
                :addClass('rec-empty-cell')
                :done()
        end
 
    end
 
    return tostring(tbl:allDone())
end
 
return p
Community content is available under CC-BY-SA unless otherwise noted.