Module:Side box: Difference between revisions

From NvWiki
Jump to navigation Jump to search
d'oh
we cookin with plainlist templatestyles now
Line 1: Line 1:
==Plainlinks?==
local yesno = require('Module:Yesno')
{{Side box|text=Some [http://example.com external link] (invalid example.com) using {{Tl|Side box}}}}
local p = {}
{{Listen|pos=left|help=no|filename=Accordion chords-01.ogg|title=Accordion chords (using Listen)|description=Some [http://example.com external link] (invalid example.com)}}
I noticed that external links in the parameter {{Para|description}} of the template {{Tl|Listen}} are not shown as such ([[File:External.png]]). Examining that template showed that it uses {{Tl|Side box}} where {{mono|1=class="plainlinks"}} is used. Is this behaviour deliberate or an unintended side effect? -- [[User:Michael Bednarek|Michael Bednarek]] ([[User talk:Michael Bednarek|talk]]) 05:49, 30 June 2010 (UTC)


: Definitely unintended. Can this be overridden? [[user:thumperward|Chris Cunningham (not at work)]] - [[user talk:thumperward|talk]] 12:30, 6 July 2010 (UTC)
local function makeData(args)
::I don't know; why not simply remove the {{mono|plainlinks}} class? -- [[User:Michael Bednarek|Michael Bednarek]] ([[User talk:Michael Bednarek|talk]]) 12:36, 6 July 2010 (UTC)
local data = {}


::: The sisterlinks templates all use it. Truth be told, {{tl|listen}} really shouldn't be subclassing here in the first place, as it's very different from the other templates that use it. [[user:thumperward|Chris Cunningham (not at work)]] - [[user talk:thumperward|talk]] 13:06, 6 July 2010 (UTC)
-- Main table classes
data.classes = {}
if yesno(args.metadata) ~= false then
table.insert(data.classes, 'metadata')
end
if args.position and args.position:lower() == 'left' then
table.insert(data.classes, 'side-box-left')
else
table.insert(data.classes, 'side-box-right')
end
if args.collapsible then
table.insert(data.classes, 'mw-collapsible')
if args.collapsible == "collapsed" then
table.insert(data.classes, 'mw-collapsed')
end
data.collapsible = true
end


::::That (sisterlinks) makes sense. I'm not technically savvy enough with templates to re-write {{tl|Listen}}. Maybe {{mono|plainlinks}} can be overridden with some kind of {{mono|<nowiki><div></nowiki>}} or {{mono|<nowiki><span></nowiki>}}? -- [[User:Michael Bednarek|Michael Bednarek]] ([[User talk:Michael Bednarek|talk]]) 13:45, 6 July 2010 (UTC)
table.insert(data.classes, args.class)
-- Image
if args.image and args.image ~= 'none' then
data.image = args.image
end
-- we have to check to see if a downstream use has plainlist like
-- Template:Sister_project. also it's the default. wikitext is :(
if args.textclass == 'plainlist' or not args.textclass then
data.textclass = 'plainlist'
data.plainlist_templatestyles = 'Plainlist/styles.css'
else
data.textclass = args.textclass
end


== above parameter? ==
-- Copy over data that does not need adjusting
local argsToCopy = {
-- aria qualities
'role',
'labelledby',


When I was looking at {{tl|Interwiki category}}, I wanted ''above'' parameter like ''below''. It would be useful. Here's [{{fullurl:Template:Side box/sandbox|oldid=443903740}} the sandbox]. --[[User:Fryed-peach|fryed-peach]] ([[User talk:Fryed-peach|talk]]) 17:33, 9 August 2011 (UTC)
-- Styles
'style',
'textstyle',
'templatestyles',


: I've massaged this into the current codebase, minus some additional changes that weren't present in the proposal. [[User:Thumperward|Chris Cunningham (user:thumperward)]] ([[User talk:Thumperward|talk]]) 15:26, 15 August 2012 (UTC)
-- Above row
'above',
'abovestyle',


== Edit request on 23 August 2013 ==
-- Body row
'text',
'imageright',


{{edit protected|<!-- Page to be edited -->|answered=yes}}
-- Below row
<!-- Begin request -->
'below',
Replace
}
metadata
for i, key in ipairs(argsToCopy) do
with
data[key] = args[key]
<nowiki>{{#ifeq:{{lc:{{{metadata|}}}}}|no||metadata}}</nowiki>
end
so this template can be used for content like it says on the tin.
<!-- End request -->
[[User:Lfdder|Lfdder]] ([[User talk:Lfdder|talk]]) 11:16, 23 August 2013 (UTC)


:{{done}} [[User:Happy-melon|<b style="color:forestgreen">Happy</b>]]‑[[User talk:Happy-melon|<b style="color:darkorange">melon</b>]] 11:36, 23 August 2013 (UTC)
return data
::Thanks. Can you also look at the edit request [[Template_talk:Listen#Edit_request_on_23_August_2013|here]]? — [[User:Lfdder|Lfdder]] ([[User talk:Lfdder|talk]]) 11:37, 23 August 2013 (UTC)
end


== Conversion to Lua ==
local function renderSidebox(data)
-- Renders the sidebox HTML.


I've written a Lua version of this template at [[Module:Side box]]. You can test it out using {{tl|side box/sandbox}}, and there are test cases at [[Module:Side box/testcases]] ([[Module talk:Side box/testcases|run]]) and [[Template:Side box/testcases]]. It should be a one-for-one switch, apart from the {{para|metadata}} parameter now accepting "no", "n", "false", and "0" to suppress the "metadata" class. This particular template isn't too resource-hungry, but it needs to be converted to Lua to allow some of its resource-hungry daughter templates, such as {{tl|listen}}, to be converted as well. Does anyone have any objections to be updating the template? — '''''[[User:Mr. Stradivarius|<span style="color: #194D00; font-family: Palatino, Times, serif">Mr. Stradivarius</span>]]''''' <sup>[[User talk:Mr. Stradivarius|♪ talk ♪]]</sup> 07:10, 2 June 2014 (UTC)
-- Table root
:I've gone ahead and converted it. Please let me know if you notice any odd behaviour from any side-box-related templates. — '''''[[User:Mr. Stradivarius|<span style="color: #194D00; font-family: Palatino, Times, serif">Mr. Stradivarius</span>]]''''' <sup>[[User talk:Mr. Stradivarius|♪ talk ♪]]</sup> 05:01, 3 June 2014 (UTC)
local root = mw.html.create('div')
root:attr('role', data.role)
:attr('aria-labelledby', data.labelledby)
:addClass('side-box')
for i, class in ipairs(data.classes or {}) do
root:addClass(class)
end
if data.style then
root:cssText(data.style)
end
local frame = mw.getCurrentFrame()
if data.plainlist_templatestyles then
root:wikitext(frame:extensionTag{
name = 'templatestyles', args = { src = data.plainlist_templatestyles }
})
end


* Thanks for your work, Mr. Stradivarius. I notice that the default styling produces a box that's nearly but not quite as wide as the 22.0em default set for e.g. {{tl|Sidebar}} – is this deliberate and/or due to the Firefox-based browser I use and/or worth amending..? [[User:Sardanaphalus|Sardanaphalus]] ([[User talk:Sardanaphalus|talk]]) 12:43, 19 June 2014 (UTC)
-- The "above" row
*:{{ping|Sardanaphalus}} That's set by the mbox-small class, not by the module directly. A look at [[MediaWiki:Common.css]] shows that it sets the width to 238px. — '''''[[User:Mr. Stradivarius|<span style="color: #194D00; font-family: Palatino, Times, serif">Mr. Stradivarius</span>]]''''' <sup>[[User talk:Mr. Stradivarius|♪ talk ♪]]</sup> 13:36, 19 June 2014 (UTC)
if data.above then
*:: Thanks for pointing out. I'll leave a query on the talkpage there. (Incidentally, any advice about [[MediaWiki talk:Common.css#navbox-level3 / navbox-levelN classes?|this query there]]..?) [[User:Sardanaphalus|Sardanaphalus]] ([[User talk:Sardanaphalus|talk]]) 08:58, 28 June 2014 (UTC)
local above = root:newline():tag('div')
above:addClass('side-box-abovebelow')
:newline()
:wikitext(data.above)
if data.textstyle then
above:cssText(data.textstyle)
end
if data.abovestyle then
above:cssText(data.abovestyle)
end
end


== Protected edit request on 30 November 2014 ==
-- The body row
local body = root:newline():tag('div')
body:addClass('side-box-flex')
:addClass(data.collapsible and 'mw-collapsible-content')
:newline()
if data.image then
body:tag('div')
:addClass('side-box-image')
:wikitext(data.image)
end
local text = body:newline():tag('div')
text:addClass('side-box-text')
:addClass(data.textclass)
if data.textstyle then
text:cssText(data.textstyle)
end
text:wikitext(data.text)
if data.imageright then
body:newline():tag('div')
:addClass('side-box-imageright')
:wikitext(data.imageright)
end


{{edit protected|Template:Side box|answered=yes}}
-- The below row
<!-- Begin request -->
if data.below then
This template should have its own class. Currently, it uses mbox and mbox-text classes, which blocks setting the width:auto for any use case. --[[User:Rezonansowy|Rezonansowy]] <small>([[User talk:Rezonansowy|talk]] | [[Special:Contributions/Rezonansowy|contribs]])</small> 15:50, 30 November 2014 (UTC)
local below = root:newline():tag('div')
<!-- End request -->
below
[[User:Rezonansowy|Rezonansowy]] <small>([[User talk:Rezonansowy|talk]] | [[Special:Contributions/Rezonansowy|contribs]])</small> 15:50, 30 November 2014 (UTC)
:addClass('side-box-abovebelow')
:Please make your requested changes to the template's sandbox first; see [[WP:TESTCASES]].<!-- Template:EP --> {{U|Rezonansowy}}, what do you mean it "blocks setting the width:auto"?  Something like this would need to be sandboxed before being carried out anyways, so let's work through it. — <span class="nowrap">&#123;&#123;U&#124;[[User:Technical 13|Technical 13]]&#125;&#125; <sup>([[Special:EmailUser/Technical 13|e]] • [[User talk:Technical 13|t]] • [[Special:Contribs/Technical 13|c]])</sup></span> 21:50, 30 November 2014 (UTC)
:wikitext(data.below)
::{{ping|Technical 13}} I'm not able to create a sandbox for a non-existing CSS class. Just create a separate CSS class for it and remove the width=100% property. --[[User:Rezonansowy|Rezonansowy<sub>aka</sub>''Rezy'']] <small>([[User talk:Rezonansowy|talk]] | [[Special:Contributions/Rezonansowy|contribs]])</small> 13:10, 24 January 2015 (UTC)
if data.textstyle then
:[[File:Red information icon with gradient background.svg|20px|link=]] '''Not done for now:'''<!-- Template:EP --> A class isn't needed for that.  Where is the use case for where you need to set the width to auto?  Simply add <code>|style = width: auto !important</code> and it will override the <code>width: 100%;</code> all by itself.  If I'm misunderstanding you, then please show me where you want to use this feature and tell me why it is needed and I'll try to help you make it happen (even though this is a Lua module which I'm not very good with yet, I've set up a sandbox to play with and try and make needed adjustments). — <code class="nowrap">&#123;&#123;U&#124;[[User:Technical 13|Technical 13]]&#125;&#125; <sup>([[Special:EmailUser/Technical 13|e]] • [[User talk:Technical 13|t]] • [[Special:Contribs/Technical 13|c]])</sup></code> 16:42, 24 January 2015 (UTC)
below:cssText(data.textstyle)
end
end


== belowstyle? / "text"==
root:newline()
local templatestyles = ''
if data.templatestyles then
templatestyles = frame:extensionTag{
name = 'templatestyles', args = { src = data.templatestyles }
}
end
return frame:extensionTag{
name = 'templatestyles', args = { src = 'Module:Side box/styles.css' }
} .. templatestyles .. tostring(root)
end


This template/module doesn't appear to offer a ''belowstyle'' parameter – is this correct/intentional? If so, any particular reason why..? If not intentional, may it be added..? [[User:Sardanaphalus|Sardanaphalus]] ([[User talk:Sardanaphalus|talk]]) 12:22, 15 January 2015 (UTC)
function p._main(args)
local data = makeData(args)
return renderSidebox(data)
end


PS As text isn't necessarily what might be placed in the middle of the box, could the ''text'' parameter be renamed ''content'' (or ''content'' made an alias for ''text'', or...) and ''textstyle'' renamed ''contentstyle'' (or...), please..?
function p.main(frame)
local origArgs = frame:getParent().args
local args = {}
for k, v in pairs(origArgs) do
v = v:match('%s*(.-)%s*$')
if v ~= '' then
args[k] = v
end
end
return p._main(args)
end


 
return p
== Working with tables ==
It doesn't seem to be working with tables. &nbsp;[ [[User:Derekleungtszhei|<span title="Visit my user page">Derek Leung</span>]] | [[User_talk:Derekleungtszhei|<span title="Leave a message">LM</span>]] ] 16:15, 13 May 2015 (UTC)
 
== Foreground color ==
 
{{edit fully-protected|answered=yes}}
There's an issue with [[Wikipedia:Style sheets for visually impaired users|night mode skins]] where background is overwritten without changing text color leaving white text on white background.  Please change in [[Module:Side box]]:
<pre>css{border = '1px solid #aaa', ['background-color'] = '#f9f9f9'}</pre>
to
<pre>css{border = '1px solid #aaa', ['background-color'] = '#f9f9f9', color = '#000'}</pre>
— [[User:Dispenser|Dispenser]] 22:27, 16 February 2017 (UTC)
:[[File:Yes check.svg|20px|link=|alt=]] '''Done'''<!-- Template:EP --> &mdash;&nbsp;Martin <small>([[User:MSGJ|MSGJ]]&nbsp;·&nbsp;[[User talk:MSGJ|talk]])</small> 14:37, 17 February 2017 (UTC)
 
== Fully protected edit request on 14 May 2017 ==
 
{{Editprotected|Template:Sidebox|answered=yes}}
A protected redirect, '''Template:Sidebox'''{{-r|Template:Sidebox|,}} needs redirect category ([[WP:RCAT|rcat]]) templates added.  Please modify it as follows:
 
* from this:
 
<pre>
#REDIRECT [[Template:Side box]]
</pre>
 
* to this:
 
<pre>
#REDIRECT [[Template:Side box]]
 
{{Redirect category shell|
{{R from move}}
{{R from modification}}
{{R from template shortcut}}
}}
</pre>
 
* {{color|darkred|'''<small>WHEN YOU COPY & PASTE, PLEASE LEAVE THE SKIPPED LINE BLANK FOR READABILITY.</small>'''}}
The {{tl|Redirect category shell}} template is used to sort redirects into one or more categories.  When {{tl|pp-protected}} and/or {{tl|pp-move}} suffice, the ''Redirect category shell'' template will detect the protection level(s) and categorize the redirect automatically.  (Also, the categories will be automatically removed or changed when and if protection is lifted, raised or lowered.)  Thank you in advance! &nbsp;'''''[[User:Paine Ellsworth|<span style="font-size:85%;color:darkblue;font-family:Segoe Script">Paine&nbsp;Ellsworth</span>]]'''''<small>&nbsp;&nbsp;[[User talk:Paine Ellsworth|<sup>put'r&nbsp;there</sup>]]&nbsp;</small>&nbsp;<small>09:21, 14 May 2017 (UTC)</small>
:[[File:Padlock-pink-open.svg|28px|link=|alt=]] '''Not done:''' The page's protection level has changed since this request was placed. You should now be able to [[Help:Editing|edit the page yourself]]. If you still seem to be unable to, please reopen the request with further details.<!-- Template:ETp --> [[User:Jo-Jo Eumerus|Jo-Jo Eumerus]] ([[User talk:Jo-Jo Eumerus|talk]], [[Special:CentralAuth/Jo-Jo Eumerus|contributions]]) 10:22, 14 May 2017 (UTC)
::Thank you very much, [[User:Jo-Jo Eumerus|Jo-Jo Eumerus]]! &nbsp;'''''[[User:Paine Ellsworth|<span style="font-size:85%;color:darkblue;font-family:Segoe Script">Paine&nbsp;Ellsworth</span>]]'''''<small>&nbsp;&nbsp;[[User talk:Paine Ellsworth|<sup>put'r&nbsp;there</sup>]]&nbsp;</small>&nbsp;<small>10:44, 14 May 2017 (UTC)</small>
 
== add the raw code to the documentation ==
 
Hi, I suggest adding something like this to the documentation
 
<pre>
{{Side box |metadata=No
| above = '''''above''''' content appears here, in a separate row above the main text area
| image = {{smaller|('''''image''''')}}
| text = '''''text''''' content, the box's main content, appears here
| imageright = {{longitem|font-size:90%|('''''image<br/>right'''''{{hsp}})}}
| below = '''''below''''' content appears here, in a separate row below the main text area
}}
</pre>
 
to display which code generates the example box on the right. This will also make copy-pasting the code easy. [[User:AadaamS|AadaamS]] ([[User talk:AadaamS|talk]]) 18:05, 17 March 2018 (UTC)
 
== Template-protected edit request on 25 August 2018 ==
 
copies and adaptations you may only make copies or
adaptations of the software for archival purposes or when
copying or adaptation is an essential step in the authorized
use of the software. you must you all copies or adaptations.
you may not copy the software onto any public network.  <!-- Template:Unsigned IP --><small class="autosigned">—&nbsp;Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[Special:Contributions/2604:2000:E8CC:700:D0B2:B41F:F1D7:BA99|2604:2000:E8CC:700:D0B2:B41F:F1D7:BA99]] ([[User talk:2604:2000:E8CC:700:D0B2:B41F:F1D7:BA99#top|talk]]) 08:23, 25 August 2018 (UTC)</small> <!--Autosigned by SineBot-->
 
== Width seems slightly off ==
{{moved|to=Wikipedia:Village_pump_(technical)#Side_box_width_seems_slightly_off|2=<span style="color:#AAA"><small>&#123;{u&#124;</small><span style="border-radius:9em;padding:0 5px;background:#088">[[User:Sdkb|<span style="color:#FFF">'''Sdkb'''</span>]]</span><small>}&#125;</small></span> <sup>[[User talk:Sdkb|'''talk''']]</sup> 02:14, 14 September 2020 (UTC)}}
 
== Allow disabling plainlist with a parameter ==
 
Hello,<p>At line 109 in [[Module:Side box]] there is the following code:<br /><code>textCell:addClass('mbox-text plainlist')</code></p><p>Please can a parameter be added to disable the 'plainlist' class so that lists with bullet points or numbers can appear in this template?</p><p>Thanks, [[User:DesertPipeline|DesertPipeline]] ([[User talk:DesertPipeline|talk]]) 03:52, 26 June 2021 (UTC)</p>
:@[[User:DesertPipeline|DesertPipeline]]: If nobody beats me to it, I can take a shot at this later today. –&nbsp;[[User talk:Rummskartoffel|<span style="background:linear-gradient(90deg,#e40303,#ff8c00,#ffed00,#008026,#004dff,#750787);color:transparent;background-clip:text;-webkit-background-clip:text;">Rummskartoffel</span>]] 09:19, 26 June 2021 (UTC)
::[[User:Rummskartoffel]]: Thank you very much :) [[User:DesertPipeline|DesertPipeline]] ([[User talk:DesertPipeline|talk]]) 09:27, 26 June 2021 (UTC)
{{TPER|Module:Side box|answered=y}}
:Please apply the changes made in the sandbox ([[Special:Diff/899337436/1030572793|diff]], [[Template:Side box/testcases#plainlist = no|test case]]). This will add a parameter {{para|plainlist}} which, when set to "no", will suppress the "plainlist" class on the main text cell, allowing lists to be displayed normally. The parameter will default to "yes", i.e. the behaviour of existing uses of {{t|Side box}} will not change. For background, compare [[Wikipedia:Help desk#Bullet points not working within Template:Side box?]].<br>After applying the change to the module, please also uncomment the new row for this parameter which I added to the table of parameters at [[Template:Side box/doc]] so that the documentation is up to date. –&nbsp;[[User talk:Rummskartoffel|<span style="background:linear-gradient(90deg,#e40303,#ff8c00,#ffed00,#008026,#004dff,#750787);color:transparent;background-clip:text;-webkit-background-clip:text;">Rummskartoffel</span>]] 20:25, 26 June 2021 (UTC)
::{{u|Rummskartoffel}}, do we know what the use case for this will be (i.e. why are we doing this?). Thanks! [[User:Firefly|<span style="color:#850808;">firefly</span>]] <small>( [[User talk:Firefly|t]] · [[Special:Contributions/Firefly|c]] )</small> 08:25, 28 June 2021 (UTC)
:::@[[User:Firefly|Firefly]]: Since I just made this edit request in response to a help desk post, I don't have a specific use case myself ([[User:DesertPipeline|DesertPipeline]], did you have something specific in mind?). But I don't see an obvious reason why it shouldn't be possible to have a normal-looking list in a side box – that is to say, I don't understand why this template has the "plainlist" class to begin with –, so this seems like a sensible thing to add. –&nbsp;[[User talk:Rummskartoffel|<span style="background:linear-gradient(90deg,#e40303,#ff8c00,#ffed00,#008026,#004dff,#750787);color:transparent;background-clip:text;-webkit-background-clip:text;">Rummskartoffel</span>]] 10:06, 28 June 2021 (UTC)
::::Would it be better to add a {{para|class|none}} parameter or similar which can override plainlist? Having a specific override parameter {{para|plainlist}} would be unnecessary then. This would be useful if you wanted e.g. a {{para|class|hlist}} or something and avoids any need to add a further parameter later. [[User:GKFX]]<sup>[[User talk:GKFX|talk]]</sup> 16:27, 3 July 2021 (UTC)
:::::I'm not sure I'm understanding you correctly. Do you mean that {{para|class}}, when non-empty, would set the classes of the main text cell to only the classes specified (with "none" as a special case)? Or should it always keep {{code|mbox-text}}? Or something else? –&nbsp;[[User talk:Rummskartoffel|<span style="background:linear-gradient(90deg,#e40303,#ff8c00,#ffed00,#008026,#004dff,#750787);color:transparent;background-clip:text;-webkit-background-clip:text;">Rummskartoffel</span>]] 19:22, 3 July 2021 (UTC)
:::[[User:Firefly]]: In my specific case the reason I need this is so that the article [[Trial of Socrates]] can have a box listing some Wikiquote documents with bullet points beside each one to delineate them better. Regards, [[User:DesertPipeline|DesertPipeline]] ([[User talk:DesertPipeline|talk]]) 11:21, 28 June 2021 (UTC)
:::[[User:Firefly]]: Please can you implement the edit request? Thanks, [[User:DesertPipeline|DesertPipeline]] ([[User talk:DesertPipeline|talk]]) 04:52, 12 July 2021 (UTC)
::::{{re|DesertPipeline}} I believe I have implemented effectively what you wanted. I also passed the new {{para|textclass}} parameter through {{tlx|Sister project}} and made an example by implementing it on [[Trial of Socrates]] (which seemed to be what you were trying to accomplish). —[[User:Uzume|Uzume]] ([[User talk:Uzume|talk]]) 07:51, 12 July 2021 (UTC)
:::::[[User:Uzume]]: Thank you very much! :) [[User:DesertPipeline|DesertPipeline]] ([[User talk:DesertPipeline|talk]]) 08:01, 12 July 2021 (UTC)
 
== bug: text flows on the right but not on the left ==
 
If I place the box on the right of a page, the text flows around it, but if I place in on the left, it doesn't. — [[User:Kwamikagami|kwami]] ([[User talk:Kwamikagami|talk]]) 20:56, 10 October 2021 (UTC)
 
== bug: no image on mobile ==
 
The page <code>Crime in Sweden</code> visited on mobile [https://en.m.wikipedia.org/wiki/Crime_in_Sweden] displays the box, with the <code>above</code> and <code>below</code> texts, but not the image. --[[Special:Contributions/62.98.162.83|62.98.162.83]] ([[User talk:62.98.162.83|talk]]) 07:50, 20 January 2022 (UTC)
 
:That's because this template uses mbox styling, and mbox-image is hidden on mobile. I've removed the template as totally unnecessary. [[User:Izno|Izno]] ([[User talk:Izno|talk]]) 20:24, 27 May 2022 (UTC)
 
== New edit breaks {{tl|algebraic notation}} ==
 
I'm not sure how to fix this but [[Special:diff/1096940545|this edit]] broke {{tl|algebraic notation}}. When used with {{para|pos|toc}}, it used to look like [https://web.archive.org/web/20220629114058/https://en.wikipedia.org/wiki/Chess this], in a box next to the TOC. [[Chess|Now it's just vertical text]]. But it doesn't stop there; on desktop if you zoom in enough (Ctrl + {{key|+}}), it goes back to normal. ~~&nbsp;[[User:lol1VNIO|lol1<span style="color:#D11D13">VNIO</span>]]&NoBreak;🎌&nbsp;('''[[User talk:lol1VNIO|<span style="color:#006400">talk</span>]]'''&nbsp;• [[Special:contribs/lol1VNIO|contribs]]) 16:18, 10 July 2022 (UTC)
 
:This will be a non-issue in new Vector (e.g. [https://en.wikipedia.org/wiki/Chess?useskin=vector-2022 this view]), and even in current Vector this is not unusable (in [https://en.wikipedia.org/wiki/Chess?useskin=timeless Timeless] it gets hidden behind the table of contents, isn't that nice? :).
:What's different now is that a table is a little more wrappier than a div. I will add some templatestyles for the algebraic notation template to restore the older behavior.
:Regarding "old behavior", that's a coincidence. The reason it does so is different than the older cause. [[User:Izno|Izno]] ([[User talk:Izno|talk]]) 17:51, 10 July 2022 (UTC)
::Should be fixed now, +- job queue updates. Null edit a page to see differences. [[User:Izno|Izno]] ([[User talk:Izno|talk]]) 18:07, 10 July 2022 (UTC)
:::Thanks! ~~&nbsp;[[User:lol1VNIO|lol1<span style="color:#D11D13">VNIO</span>]]&NoBreak;🎌&nbsp;('''[[User talk:lol1VNIO|<span style="color:#006400">talk</span>]]'''&nbsp;• [[Special:contribs/lol1VNIO|contribs]]) 21:03, 10 July 2022 (UTC)
 
== Bullet points don't work ==
 
Bullet points in the "text" field don't seem to work. [[User:HLHJ|HLHJ]] ([[User talk:HLHJ|talk]]) 23:53, 29 October 2022 (UTC)
:{{ping|HLHJ}} This is because the template adds the "plainlist" CSS class by default, which removes the bullet points from lists. You can work around this by specifying a dummy class to the {{para|textclass}} parameter. For example,
<pre>
{{side box|textclass=vlist|text=
Some text
* foo
* bar
}}
</pre>
:will produce the side bar below:
{{side box|textclass=vlist|text=
Some text
* foo
* bar
}}
:— '''''[[User:Mr. Stradivarius|<span style="color: #194D00; font-family: Palatino, Times, serif">Mr.&nbsp;Stradivarius</span>]]''''' <sup>[[User talk:Mr. Stradivarius|♪&nbsp;talk&nbsp;♪]]</sup> 00:49, 30 October 2022 (UTC)
 
::Thank you, [[User:Mr. Stradivarius|Mr. Stradivarius]]! I'll do that. I assume this behaviour is useful to others. {{smiley}}. [[User:HLHJ|HLHJ]] ([[User talk:HLHJ|talk]]) 00:55, 30 October 2022 (UTC)
:::The plainlist class was originally [https://en.wikipedia.org/w/index.php?title=Template:Side_box&diff=next&oldid=507545514&diffonly=1 added] back in 2012 by [[User:Thumperward|Thumperward]]. His edit summary said that the plainlist class "adds semantic value when multiple elements are used", but I'm not sure exactly why that would be. If we wanted, we could change the default, but we would need to check all of the transclusions to see which ones would need fixing, which would be a pain. — '''''[[User:Mr. Stradivarius|<span style="color: #194D00; font-family: Palatino, Times, serif">Mr.&nbsp;Stradivarius</span>]]''''' <sup>[[User talk:Mr. Stradivarius|♪&nbsp;talk&nbsp;♪]]</sup> 01:41, 30 October 2022 (UTC)
::::Thank you again. Thumperward may have useful comments; I really have none! Happy with whatever works best for others, it's not a big deal for me. [[User:HLHJ|HLHJ]] ([[User talk:HLHJ|talk]]) 02:16, 30 October 2022 (UTC)
{{side box|textclass=vlist|text=
* Some text
* foo
* bar
}}
:::::Hmm. Does not work flawlessly if the first line is bulleted. [[User:HLHJ|HLHJ]] ([[User talk:HLHJ|talk]]) 02:41, 30 October 2022 (UTC)
::::::You can work around that problem with an [[HTML encoding|HTML-encoded]] space:
<pre>
{{side box|textclass=vlist|text=&amp;#32;
* Some text
* foo
* bar
}}
</pre>
::::::This is because MediaWiki trims the whitespace at the start of the text, so the newline character disappears. By adding the HTML-encoded space, the newline character is included. (It is hardly elegant, however.) The output looks like this:
{{side box|textclass=vlist|text=&#32;
* Some text
* foo
* bar
}}
::::::— '''''[[User:Mr. Stradivarius|<span style="color: #194D00; font-family: Palatino, Times, serif">Mr.&nbsp;Stradivarius</span>]]''''' <sup>[[User talk:Mr. Stradivarius|♪&nbsp;talk&nbsp;♪]]</sup> 08:40, 30 October 2022 (UTC)
 
{{od}} I think changing the default after a decade is likely to have a ''somewhat'' deleterious effect considering that there are presently '''1038789''' transclusions of this template. Apologies if I'm a little out of the loop here as I haven't thought about this template in years, but the [[Template:Side box/testcases#plainlist_.3D_no|test cases]] page suggests that a year ago {{user|Rummskartoffel}} [https://en.wikipedia.org/w/index.php?title=Template:Side_box/testcases&diff=1030573844&oldid=771521548 introduced a test case] for a <code>plainlist=no</code> parameter. This doesn't ever seem to have actually been implemented in the code. I think that's probably the right approach if someone wants to look into it. If you need help please feel free to ping me. [[User:Thumperward|Chris Cunningham (user:thumperward)]] ([[User talk:Thumperward|talk]]) 12:25, 30 October 2022 (UTC)

Revision as of 04:33, 13 December 2022

Template:Module rating

Template:Uses TemplateStyles This module implements the {{side box}} template.

Usage from wikitext

This module cannot be used directly from wikitext. It can only be used through the {{side box}} template. Please see the template page for documentation.

Usage from Lua modules

To use this module from other Lua modules, first load the module.

local mSideBox = require('Module:Side box')

You can then generate a side box using the _main function.

mSideBox._main(args)

The args variable should be a table containing the arguments to pass to the module. To see the different arguments that can be specified and how they affect the module output, please refer to the {{side box}} template documentation.



local yesno = require('Module:Yesno')
local p = {}

local function makeData(args)
	local data = {}

	-- Main table classes
	data.classes = {}
	if yesno(args.metadata) ~= false then
		table.insert(data.classes, 'metadata')
	end
	if args.position and args.position:lower() == 'left' then
		table.insert(data.classes, 'side-box-left')
	else
		table.insert(data.classes, 'side-box-right')
	end
	
	if args.collapsible then
		table.insert(data.classes, 'mw-collapsible')
		if args.collapsible == "collapsed" then
			table.insert(data.classes, 'mw-collapsed')
		end
		data.collapsible = true
	end

	table.insert(data.classes, args.class)
	
	-- Image
	if args.image and args.image ~= 'none' then
		data.image = args.image
	end
	
	-- we have to check to see if a downstream use has plainlist like
	-- Template:Sister_project. also it's the default. wikitext is :(
	if args.textclass == 'plainlist' or not args.textclass then
		data.textclass = 'plainlist'
		data.plainlist_templatestyles = 'Plainlist/styles.css'
	else
		data.textclass = args.textclass
	end

	-- Copy over data that does not need adjusting
	local argsToCopy = {
		-- aria qualities
		'role',
		'labelledby',

		-- Styles
		'style',
		'textstyle',
		'templatestyles',

		-- Above row
		'above',
		'abovestyle',

		-- Body row
		'text',
		'imageright',

		-- Below row
		'below',
	}
	for i, key in ipairs(argsToCopy) do
		data[key] = args[key]
	end

	return data
end

local function renderSidebox(data)
	-- Renders the sidebox HTML.

	-- Table root
	local root = mw.html.create('div')
	root:attr('role', data.role)
		:attr('aria-labelledby', data.labelledby)
		:addClass('side-box')
	for i, class in ipairs(data.classes or {}) do
		root:addClass(class)
	end
	if data.style then
		root:cssText(data.style)
	end
	
	local frame = mw.getCurrentFrame()
	if data.plainlist_templatestyles then
		root:wikitext(frame:extensionTag{
			name = 'templatestyles', args = { src = data.plainlist_templatestyles }
		})
	end

	-- The "above" row
	if data.above then
		local above = root:newline():tag('div')
		above:addClass('side-box-abovebelow')
			:newline()
			:wikitext(data.above)
		if data.textstyle then
			above:cssText(data.textstyle)
		end
		if data.abovestyle then
			above:cssText(data.abovestyle)
		end
	end

	-- The body row
	local body = root:newline():tag('div')
		body:addClass('side-box-flex')
			:addClass(data.collapsible and 'mw-collapsible-content')
			:newline()
	if data.image then
		body:tag('div')
			:addClass('side-box-image')
			:wikitext(data.image)
	end
	local text = body:newline():tag('div')
	text:addClass('side-box-text')
		:addClass(data.textclass)
	if data.textstyle then
		text:cssText(data.textstyle)
	end
	text:wikitext(data.text)
	if data.imageright then
		body:newline():tag('div')
			:addClass('side-box-imageright')
			:wikitext(data.imageright)
	end

	-- The below row
	if data.below then
		local below = root:newline():tag('div')
		below
			:addClass('side-box-abovebelow')
			:wikitext(data.below)
		if data.textstyle then
			below:cssText(data.textstyle)
		end
	end

	root:newline()
	local templatestyles = ''
	if data.templatestyles then
		templatestyles = frame:extensionTag{
			name = 'templatestyles', args = { src = data.templatestyles }
		}
	end
	return frame:extensionTag{
		name = 'templatestyles', args = { src = 'Module:Side box/styles.css' }
	} .. templatestyles .. tostring(root)
end

function p._main(args)
	local data = makeData(args)
	return renderSidebox(data)
end

function p.main(frame)
	local origArgs = frame:getParent().args
	local args = {}
	for k, v in pairs(origArgs) do
		v = v:match('%s*(.-)%s*$')
		if v ~= '' then
			args[k] = v
		end
	end
	return p._main(args)
end

return p