Collapsible [code] boxes
Moderator: Forum Moderators
Collapsible [code] boxes
Hi there,
I have just deployed a minor improvement to the forums adding collapsible [code] boxes to all three supported forum templates, as well as limiting the default [code] box height on subsilver2 and acidtech just like it’s done on prosilver upstream. This means that you no longer need to wrap large [code] blocks in tacky [spoiler] tags.
If you have been around for a while and you have any problems with this new feature on prosilver, make sure to press F5 once so your browser fetches the updated main javascript file. If that doesn’t solve it, state your web browser version below and I’ll see what I can do (unless it’s some obsolete garbage like IE 6).
And yes, you need javascript, just like with [spoiler] or [section] tags. I promise I won’t spam you with pop-up ads or steal your credit card information while browsing these forums with javascript enabled.
Regards
I have just deployed a minor improvement to the forums adding collapsible [code] boxes to all three supported forum templates, as well as limiting the default [code] box height on subsilver2 and acidtech just like it’s done on prosilver upstream. This means that you no longer need to wrap large [code] blocks in tacky [spoiler] tags.
If you have been around for a while and you have any problems with this new feature on prosilver, make sure to press F5 once so your browser fetches the updated main javascript file. If that doesn’t solve it, state your web browser version below and I’ll see what I can do (unless it’s some obsolete garbage like IE 6).
And yes, you need javascript, just like with [spoiler] or [section] tags. I promise I won’t spam you with pop-up ads or steal your credit card information while browsing these forums with javascript enabled.
Regards
Author of the unofficial UtBS sequels Invasion from the Unknown and After the Storm.
Re: Collapsible [code] boxes
Perhaps the expand/collapse text-button should be displayed only when there’s enough code in the tag to exceed the height limit? Its current appearance on small code boxes where it does nothing may induce the belief that it is nonfunctional in general.
shadowmaster wrote:This means that you no longer need to wrap largeCode: Select all
blocks in tacky [spoiler] tags.[/quote]Is such wrapping discouraged? I’ve been wrapping code boxes thus, when I remember to do so, and would continue the practice, unless you’re discouraging it. To me at least, even a height-limited code box occupies sufficiently significant space to warrant spoiler-wrapping.
Re: Collapsible [code] boxes
It looks ugly. Everyone is free to choose whichever formatting they prefer as long as they comply with the forum rules (e.g. [code] being the minimum requirement).8680 wrote:Is such wrapping discouraged?
As soon as I figure out an elegant method to achieve this, yes. For the time being, no.8680 wrote:Perhaps the expand/collapse text-button should be displayed only when there’s enough code in the tag to exceed the height limit?
Author of the unofficial UtBS sequels Invasion from the Unknown and After the Storm.
Re: Collapsible [code] boxes
shadowmaster wrote:Hi there,
I promise I won’t spam you with pop-up ads or steal your credit card information while browsing these forums with javascript enabled.
Regards
What if we don't trust you? Why is your promise so special sm?
By the way; I don't really get what the improvement is; Could you please elaborate and demonstrate before I decide to enable javascript and risk my security? I do a lot of net banking...
Bye says the cookie.
Re: Collapsible [code] boxes
You may read the page's source code to see if the javascript is evil or not (I haven't found anything wrong there). But you might be afraid to browse other sites while you have it enabled because wesnoth forums need it.
More paranoid version of the reply:
Re: Collapsible [code] boxes
Don't worry; I have no doubt that shadowmaster is trustworthy as I've surely known him long enough. The things you should watch out for are his spies...they're ever so quiet and skillfully stationary.Dugi wrote:More paranoid version of the reply:
I will allow the javascript to work on this domain, thanks for the heads up shadowmaster and constant effort in development.
Bye says the cookie.
Re: Collapsible [code] boxes
It's actually a bit less than that, as you can still see the contents of the code block without javascript; you just cannot expand the block to show the whole thing without a scrollbar. (Spoiler and section tags completely hide their contents when javascript is disabled.)shadowmaster wrote:And yes, you need javascript, just like withSpoiler:
But however you want to view the javascript requirement, I think it's an improvement. Thanks.
-
- Inactive Developer
- Posts: 2461
- Joined: August 15th, 2008, 8:46 pm
- Location: Germany
Re: Collapsible [code] boxes
A perfect usecase for noscript.Dugi wrote:But you might be afraid to browse other sites while you have it enabled because wesnoth forums need it.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
Re: Collapsible [code] boxes
Would this work to apply expanders only to expandable code boxes?
Code: Select all
function getCodeBoxes() {
// May return a NodeList, a HTMLCollection, or an Array; only safe to use
// getCodeBoxes().length and getCodeBoxes()[i].
if (document.getElementsByClassName) // For modern browsers.
return document.getElementsByClassName("codebox");
if (document.querySelectorAll) // For IE8.
return document.querySelectorAll(".codebox");
var e, i, r = [], dls = document.getElementsByTagName("dl"); // For IE7.
for (i = 0; i !== dls.length; ++i)
if ((e = dls[i]).className === "codebox")
r.push(e);
return r;
}
function applyCodeBoxExpanders() {
var c, i, cb, df, codeBoxes = getCodeBoxes();
for (i = 0; i !== codeBoxes.length; ++i) {
cb = codeBoxes[i];
c = cb.lastChild.firstChild; // The <code> element.
if (c.clientWidth !== c.scrollWidth) { // Has scrollbar.
df = document.createDocumentFragment();
(df.textContent || df.innerText) = " • ";
c = document.createElement("a");
(c.textContent || c.innerText) = "Expand";
c.href = "#";
c.onclick = function() {
toggleCodeExpand(this, "Expand", "Collapse");
// Why specify the label strings at the call site and not in
// the function?
};
df.appendChild(c);
cb.firstChild.appendChild(df);
}
}
}
onload_functions.push("applyCodeBoxExpanders()");
// on[un]load_functions: Currently you’re pushing strings representing function
// calls into these arrays, then eval()ing the strings. Why not push the
// functions, then call them from the arrays?
Re: Collapsible [code] boxes
I’ll try that out later, but a few things stand out:8680 wrote:Would this work to apply expanders only to expandable code boxes?
This has the potential to be a more costly operation than it should be, since prosilver uses8660 wrote:Code: Select all
var e, i, r = [], dls = document.getElementsByTagName("dl"); // For IE7.
<dl>
a lot for other things.Because that’s the only way to make them work with the phpBB language packs mechanism unless I move the relevant code to an actual template file. This would not normally matter, but I may or may not revisit the forum language support issue at a later point depending on certain community trends. It also ensures some degree of consistency with mainline phpBB practice.8660 wrote:Code: Select all
// Why specify the label strings at the call site and not in // the function?
This is really a question for the phpBB developers, and more specifically, the prosilver template maintainer(s).8660 wrote:Code: Select all
// on[un]load_functions: Currently you’re pushing strings representing function // calls into these arrays, then eval()ing the strings. Why not push the // functions, then call them from the arrays?
Author of the unofficial UtBS sequels Invasion from the Unknown and After the Storm.
Re: Collapsible [code] boxes
Do you have a narrower filter that works in IE7?shadowmaster wrote:This has the potential to be a more costly operation than it should be, since prosilver uses<dl>
a lot for other things.
What about emitting them as global variables in the inlineshadowmaster wrote:Because that’s the only way to make them work with the phpBB language packs mechanism unless I move the relevant code to an actual template file.
<script>
, after on[un]load_functions
, then referencing the variables in toggleCodeExpand
?
How should I contact them? (I’ll look around on phpBB.com, but you might have more specific advice.) (Edit: Googling “contact prosilver maintainers” yielded both this forum and your blog on the first page.)shadowmaster wrote:This is really a question for the ... prosilver template maintainer(s).
Also, I recommend using
(a.textContent || a.innerText)
rather than a.innerHTML
in toggleCodeExpand
, for security.Re: Collapsible [code] boxes
Probably not. I don’t really know much Javascript, to be honest.8680 wrote:Do you have a narrower filter that works in IE7?
That is a possibility I considered if I ever need to pass even more such constants to Javascript code. Which might not necessarily be never, seeing as how I want to ship a certain feature for Gambit eventually.8680 wrote:What about emitting them as global variables in the inline<script>
, afteron[un]load_functions
, then referencing the variables intoggleCodeExpand
?
Unfortunately, I can’t think of anything other than filing a bug to the phpBB bug tracker explaining the issue and (optionally) providing a pull request for a patch or set thereof.8680 wrote:How should I contact them? (I’ll look around on phpBB.com, but you might have more specific advice.)
Hard to see how this could be an issue unless there is extraneous Javascript running in the same context and calling the function in question, or the server-side template and/or language constants were compromised — which would raise a myriad different security concerns.8680 wrote:Also, I recommend using(a.textContent || a.innerText)
rather thana.innerHTML
intoggleCodeExpand
, for security.
Author of the unofficial UtBS sequels Invasion from the Unknown and After the Storm.
- Captain_Wrathbow
- Posts: 1664
- Joined: June 30th, 2009, 2:03 pm
- Location: Guardia
Re: Collapsible [code] boxes
After having this for a few weeks and seeing the new
Code: Select all
boxes around the forums, I just thought I'd pop in and say that I really like this feature. Thanks shadowm! :)
Re: Collapsible [code] boxes
For the record, I inquired regarding
on[un]load_functions
, and haven’t received a response.Re: Collapsible [code] boxes
I have submitted a pull request to weldyn for a commit implementing a somewhat modified version of my above proposed changes to show the expand/collapse buttons only for
Update: This pull request, after some further work, was merged by shadowmaster at 02013-06-13 02:27:19 UTC, who then adapted my changes for prosilver to the subsilver2 and acidtech themes at 02013-06-13 07:54:52 UTC and 02013-06-13 08:03:35 UTC respectively.
[code]
boxes with scrollbars (albeit only in the default prosilver theme).Update: This pull request, after some further work, was merged by shadowmaster at 02013-06-13 02:27:19 UTC, who then adapted my changes for prosilver to the subsilver2 and acidtech themes at 02013-06-13 07:54:52 UTC and 02013-06-13 08:03:35 UTC respectively.