Modul:TemplUtl: Unterschied zwischen den Versionen
2017-04-28
(2017-04-24) |
(2017-04-28) |
||
Zeile 1: | Zeile 1: | ||
local TemplUtl = { suite = "TemplUtl", | local TemplUtl = { suite = "TemplUtl", | ||
serial = "2017-04- | serial = "2017-04-28" }; | ||
Zeile 33: | Zeile 33: | ||
local framing = function ( frame ) | local framing = function ( frame ) | ||
if not TemplUtl.frame then | if not TemplUtl.frame then | ||
if frame then | if type( frame ) == "table" then | ||
TemplUtl.frame = frame; | TemplUtl.frame = frame; | ||
else | else | ||
Zeile 43: | Zeile 43: | ||
TemplUtl.faculty = function ( analyze, another | TemplUtl.faculty = function ( analyze, another ) | ||
-- Test template arg for boolean | -- Test template arg for boolean | ||
-- analyze -- string, boolean, number or nil | -- analyze -- string, boolean, number or nil | ||
-- another -- fallback: string, boolean, or nil | -- another -- fallback: string, boolean, or nil | ||
-- Returns boolean | -- Returns boolean | ||
local s = type( analyze ); | local s = type( analyze ); | ||
Zeile 54: | Zeile 53: | ||
r = mw.text.trim( analyze ); | r = mw.text.trim( analyze ); | ||
if r == "" then | if r == "" then | ||
r = TemplUtl.faculty( another, nil | r = TemplUtl.faculty( another, nil ); | ||
elseif r == "1" then | elseif r == "1" then | ||
r = true; | r = true; | ||
Zeile 110: | Zeile 109: | ||
TemplUtl.failure = function ( alert, always ) | TemplUtl.failure = function ( alert, always, addClass, frame ) | ||
-- Format error message, mostly hidden | -- Format error message, mostly hidden | ||
-- alert | -- alert -- string: message | ||
-- always | -- always -- boolean, or nil: do not hide | ||
-- addClass -- string, or nil: add classes to element | |||
-- frame -- object, or nil | |||
-- Returns string | -- Returns string | ||
local err = mw.html.create( "span" ) | local err = mw.html.create( "span" ) | ||
:addClass( "error" ) | :addClass( "error" ) | ||
:wikitext( alert ); | :wikitext( alert ); | ||
local btn = mw.html.create( "span" ); | local live; | ||
framing( frame ); | |||
live = ( TemplUtl.frame:preprocess( "{{REVISIONID}}" ) == "" ); | |||
if type( addClass ) == "string" then | |||
err:addClass( addClass ) | |||
end | |||
if live then | |||
local max = 1000000000; | |||
local id = math.floor( os.clock() * max ); | |||
local sign = string.format( "error_%d", id ); | |||
local btn = mw.html.create( "span" ); | |||
local top = mw.html.create( "div" ); | |||
err:css( { ["display"] = "inline-block", | err:attr( "id", sign ); | ||
-- TODO: LTR | |||
btn:css( { ["background"] = "#FFFF00", | |||
["border"] = "#FF0000 3px solid", | |||
["font-weight"] = "bold", | |||
["padding"] = "2px", | |||
["text-decoration"] = "none" } ) | |||
:wikitext( ">>>" ); | |||
sign = string.format( "[[#%s|%s]]", sign, tostring( btn ) ); | |||
top:wikitext( sign, " ", alert ); | |||
mw.addWarning( tostring( top ) ); | |||
elseif not always then | |||
err:css( { ["display"] = "none" } ); | |||
-- err:css( { ["display"] = "inline-block", | |||
-- ["line-height"] = "0", | |||
-- ["max-height"] = "0", | |||
-- ["max-width"] = "0", | |||
-- ["visibility"] = "hidden" } ); | |||
end | end | ||
return tostring( err ); | return tostring( err ); | ||
end -- TemplUtl.failure() | end -- TemplUtl.failure() | ||
Zeile 562: | Zeile 571: | ||
function p.faculty( frame ) | function p.faculty( frame ) | ||
return TemplUtl.faculty( frame.args[ 1 ], | return TemplUtl.faculty( frame.args[ 1 ], | ||
frame.args[ 2 ] | frame.args[ 2 ] ) and "1" | ||
or ""; | or ""; | ||
end -- p.faculty() | end -- p.faculty() | ||
Zeile 570: | Zeile 578: | ||
local scream = mw.text.trim( frame.args[ 1 ] or "" ); | local scream = mw.text.trim( frame.args[ 1 ] or "" ); | ||
local loud = frame.args[ 2 ]; | local loud = frame.args[ 2 ]; | ||
if scream == "????????? | local select = frame.args.class; | ||
if scream == "" then | |||
scream = "?????????"; | |||
end | end | ||
if loud then | if loud then | ||
loud = TemplUtl.faculty( loud, nil | loud = TemplUtl.faculty( loud, nil ); | ||
end | end | ||
return TemplUtl.failure( scream, loud ); | return TemplUtl.failure( scream, loud, select, frame ); | ||
end -- p.failure() | end -- p.failure() | ||