Module:Hatnote: Difference between revisions
From Amaranth Legacy, available at amaranth-legacy.community
More actions
Content deleted Content added
Tesinormed (talk | contribs) No edit summary |
Tesinormed (talk | contribs) m Removed protection from "Module:Hatnote" |
||
| (42 intermediate revisions by 3 users not shown) | |||
| Line 6: | Line 6: | ||
local args = getArgs(frame) |
local args = getArgs(frame) |
||
local wrapper = mw.html.create('div') |
local wrapper = mw.html.create('div') |
||
: |
:addClass('hatnote-wrapper') |
||
| ⚫ | |||
if args['class'] then wrapper:addClass(args['class']) end |
|||
-- backwards compatibility |
|||
| ⚫ | |||
if args['file_class'] then args['file1_class'] = args['file_class'] end |
|||
if args['file_link'] then args['file1_link'] = args['file_link'] end |
|||
-- input validation |
-- input validation |
||
if not args['file1'] and args['file2'] then |
if not args['file1'] and args['file2'] then |
||
error(' |
error('file1 is required when file2 is specified') |
||
| ⚫ | |||
| ⚫ | |||
error('file_size is forbidden when file1 is specified') |
|||
end |
end |
||
if not args['primary'] then |
if not args['primary'] then |
||
| Line 22: | Line 25: | ||
-- set the color so the look stays consistent even outside of the scope |
-- set the color so the look stays consistent even outside of the scope |
||
if args['color'] then |
if args['color'] then |
||
wrapper:css('-- |
wrapper:css('--template-arg-color--light', args['color']) |
||
wrapper:css('--template-arg-color--dark', args['color']) |
|||
if yesno(args['color_applies_to_links'] or true) then |
if yesno(args['color_applies_to_links'] or true) then |
||
wrapper:css('--color-link', args['color']) |
wrapper:css('--template-arg-color-link--light', args['color']) |
||
wrapper:css('--template-arg-color-link--dark', args['color']) |
|||
end |
|||
elseif args['color_light'] and args['color_dark'] then |
|||
wrapper:css('--template-arg-color--light', args['color_light']) |
|||
wrapper:css('--template-arg-color--dark', args['color_dark']) |
|||
if yesno(args['color_applies_to_links'] or true) then |
|||
wrapper:css('--template-arg-color-link--light', args['color_light']) |
|||
wrapper:css('--template-arg-color-link--dark', args['color_dark']) |
|||
end |
end |
||
end |
end |
||
| Line 35: | Line 47: | ||
-- content wrapper |
-- content wrapper |
||
local content = wrapper:tag('div') |
local content = wrapper:tag('div') |
||
| ⚫ | |||
:addClass('noexcerpt') |
|||
:addClass('hatnote') |
|||
if args['file1'] and args['file2'] then |
if args['file1'] and args['file2'] then |
||
content: |
content:addClass('hatnote2') |
||
elseif args['file1'] then |
elseif args['file1'] then |
||
content: |
content:addClass('hatnote1') |
||
else |
else |
||
content: |
content:addClass('hatnote0') |
||
end |
end |
||
-- left file |
-- left file |
||
if args['file1'] then |
if args['file1'] then |
||
local class = 'notpageimage hatnote-image1 attribute-loading-unset' |
|||
| ⚫ | |||
if args['file1_class'] then |
|||
class = class .. ' ' .. args['file1_class'] |
|||
end |
|||
| ⚫ | |||
.. 'File:' .. args['file1'] |
.. 'File:' .. args['file1'] |
||
.. '|' .. (args['file_size'] or '80px') |
.. '|' .. (args['file_size'] or '80px') |
||
.. '|class= |
.. '|class=' .. class |
||
.. '|link=' |
.. '|link=' .. (args['file1_link'] or '') |
||
.. '|alt=' |
.. '|alt=' |
||
.. ']]') |
.. ']]') |
||
| Line 55: | Line 74: | ||
-- center text |
-- center text |
||
local text = content:tag('div') |
local text = content:tag('div'):addClass('hatnote-text') |
||
-- primary text wrapper |
-- primary text wrapper |
||
local primary_text = text:tag(' |
local primary_text = text:tag('div'):addClass('hatnote-primary') |
||
| ⚫ | |||
-- primary text linear-gradient |
-- primary text linear-gradient |
||
if args['primary_gradient'] then |
if args['primary_gradient'] then |
||
primary_text |
primary_text |
||
| ⚫ | |||
:css('background-image', 'linear-gradient(' .. args['primary_gradient'] .. ')') |
:css('background-image', 'linear-gradient(' .. args['primary_gradient'] .. ')') |
||
:css('-webkit-background-clip', 'text') |
|||
:css('background-clip', 'text') |
:css('background-clip', 'text') |
||
else |
|||
primary_text:css('color', 'var(--color-amaranth-legacy-scope)') |
|||
end |
end |
||
-- primary text font-size |
-- primary text font-size |
||
if args['primary_font_size'] then |
|||
primary_text:css('font-size', 'var(--font-size-' .. args['primary_font_size'] .. ')') |
|||
| ⚫ | |||
-- primary text font-family |
-- primary text font-family |
||
if args['font'] then |
|||
primary_text:css('font-family', args['font']) |
|||
end |
|||
-- primary text text-transform |
-- primary text text-transform |
||
if args['primary_transform'] then |
|||
primary_text:css('text-transform', args['primary_transform']) |
|||
end |
|||
-- primary text |
-- primary text |
||
primary_text:wikitext(args['primary']) |
primary_text:wikitext(args['primary']) |
||
| Line 81: | Line 103: | ||
if args['secondary'] then |
if args['secondary'] then |
||
-- italic secondary text |
-- italic secondary text |
||
if yesno(args['italic_secondary'] or true) then |
if yesno(args['secondary_italic'] or true) and yesno(args['italic_secondary'] or true) then |
||
args['secondary'] = '\'\'' .. args['secondary'] .. '\'\'' |
args['secondary'] = '\'\'' .. args['secondary'] .. '\'\'' |
||
end |
end |
||
text:wikitext( |
text:wikitext(args['secondary']) |
||
end |
end |
||
-- right file |
-- right file |
||
if args['file2'] then |
if args['file2'] then |
||
local class = 'notpageimage hatnote-image2 attribute-loading-unset' |
|||
| ⚫ | |||
if args['file2_class'] then |
|||
class = class .. ' ' .. args['file2_class'] |
|||
end |
|||
| ⚫ | |||
.. 'File:' .. args['file2'] |
.. 'File:' .. args['file2'] |
||
.. '|' .. (args['file_size'] or '80px') |
.. '|' .. (args['file_size'] or '80px') |
||
.. '|class= |
.. '|class=' .. class |
||
.. '|link=' |
.. '|link=' .. (args['file2_link'] or '') |
||
.. '|alt=' |
.. '|alt=' |
||
.. ']]') |
.. ']]') |
||
Latest revision as of 10:43, September 11, 2025
This module is used for Template:Hatnote. See the template's page for more information.
local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')
local p = {}
function p.main(frame)
local args = getArgs(frame)
local wrapper = mw.html.create('div')
:addClass('hatnote-wrapper')
if args['class'] then wrapper:addClass(args['class']) end
-- backwards compatibility
if args['file'] then args['file1'] = args['file'] end
if args['file_class'] then args['file1_class'] = args['file_class'] end
if args['file_link'] then args['file1_link'] = args['file_link'] end
-- input validation
if not args['file1'] and args['file2'] then
error('file1 is required when file2 is specified')
end
if not args['primary'] then
error('primary is required')
end
-- set the color so the look stays consistent even outside of the scope
if args['color'] then
wrapper:css('--template-arg-color--light', args['color'])
wrapper:css('--template-arg-color--dark', args['color'])
if yesno(args['color_applies_to_links'] or true) then
wrapper:css('--template-arg-color-link--light', args['color'])
wrapper:css('--template-arg-color-link--dark', args['color'])
end
elseif args['color_light'] and args['color_dark'] then
wrapper:css('--template-arg-color--light', args['color_light'])
wrapper:css('--template-arg-color--dark', args['color_dark'])
if yesno(args['color_applies_to_links'] or true) then
wrapper:css('--template-arg-color-link--light', args['color_light'])
wrapper:css('--template-arg-color-link--dark', args['color_dark'])
end
end
-- top <hr>
if not yesno(args['remove_hr'] or false) and not yesno(args['remove_hr_top'] or false) then
wrapper:wikitext('<hr>')
end
-- content wrapper
local content = wrapper:tag('div')
:attr('role', 'note')
:addClass('noexcerpt')
:addClass('hatnote')
if args['file1'] and args['file2'] then
content:addClass('hatnote2')
elseif args['file1'] then
content:addClass('hatnote1')
else
content:addClass('hatnote0')
end
-- left file
if args['file1'] then
local class = 'notpageimage hatnote-image1 attribute-loading-unset'
if args['file1_class'] then
class = class .. ' ' .. args['file1_class']
end
content:wikitext('[['
.. 'File:' .. args['file1']
.. '|' .. (args['file_size'] or '80px')
.. '|class=' .. class
.. '|link=' .. (args['file1_link'] or '')
.. '|alt='
.. ']]')
end
-- center text
local text = content:tag('div'):addClass('hatnote-text')
-- primary text wrapper
local primary_text = text:tag('div'):addClass('hatnote-primary')
-- primary text linear-gradient
if args['primary_gradient'] then
primary_text
:css('color', 'transparent')
:css('background-image', 'linear-gradient(' .. args['primary_gradient'] .. ')')
:css('background-clip', 'text')
end
-- primary text font-size
if args['primary_font_size'] then
primary_text:css('font-size', 'var(--font-size-' .. args['primary_font_size'] .. ')')
end
-- primary text font-family
if args['font'] then
primary_text:css('font-family', args['font'])
end
-- primary text text-transform
if args['primary_transform'] then
primary_text:css('text-transform', args['primary_transform'])
end
-- primary text
primary_text:wikitext(args['primary'])
-- secondary text
if args['secondary'] then
-- italic secondary text
if yesno(args['secondary_italic'] or true) and yesno(args['italic_secondary'] or true) then
args['secondary'] = '\'\'' .. args['secondary'] .. '\'\''
end
text:wikitext(args['secondary'])
end
-- right file
if args['file2'] then
local class = 'notpageimage hatnote-image2 attribute-loading-unset'
if args['file2_class'] then
class = class .. ' ' .. args['file2_class']
end
content:wikitext('[['
.. 'File:' .. args['file2']
.. '|' .. (args['file_size'] or '80px')
.. '|class=' .. class
.. '|link=' .. (args['file2_link'] or '')
.. '|alt='
.. ']]')
end
-- bottom <hr>
if not yesno(args['remove_hr'] or false) and not yesno(args['remove_hr_bottom'] or false) then
wrapper:wikitext('<hr>')
end
return frame:extensionTag { name = 'templatestyles', args = { src = 'Module:Hatnote/styles.css' } }
.. tostring(wrapper)
end
return p