[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: use a gambas web cgi in a phpBB forum


On Sun, 30 Nov 2025 at 04:59, Lee <t.lee.davidson@xxxxxxxxx> wrote:

> On 11/29/25 7:57 PM, Bruce Steers wrote:
> > Doh!
> > I hadn't thought of that either.
> > Good result though. Your js is way better than mine was.
> > Maybe something like a timestamp...
> >
> > var id = "bbcode_" + Date.now()
>
> So you're suggesting creating a unique id for the SPAN element of the
> bbcode's HTML replacement? That might work if doable.
>
> There are two problems I see with using JavaScript: timing, and finding
> the appropriate location in the DOM tree.
>
> If the SPAN element is given an initial id statically and the bbcode
> attempts to change it, timing could cause collisions with
> other id's with the same value.
>
> On the other hand, if the SPAN element is created dynamically, how is it
> placed correctly in the DOM? The parent of the current
> post content (the DIV) must be determined as that has a unique id. But,
> Element.parentElement is not available unless a listener
> is triggered, usually in an onClick event. For example, "<span
> id="code">{TEXT}<script>this.innerText=this.ParentNode.nodeName;</script></span>",
> does not work.
>
>
> --
> Lee
>

I figured it out (in case you were still interested or curious Lee i'll
spill the beans :)
I found the way by seeking out and examining the selectCode(this) function
from the "Select All" link in the normal codebox.

if found this little beauty...
var e = a.parentNode.parentNode.getElementsByTagName('CODE')[0];
a is passed in the onclick handler as "this" like so...
<a href="#" style="color:green" onclick="runCode(this); return
false;">&#128187; Run code</a>

That gets the correct code box then e.innerText has the code with line
breaks and no html.

i used the same method to get a TextArea output element.
i can now run gambas code and display the result on my forum :)
(check it out here: https://bruceybonus.uk/phpBB/viewtopic.php?p=69#p69

Now i'm starting to get the idea of how things work i should be able to use
gambas highlighting too :)

Follow-Ups:
Re: use a gambas web cgi in a phpBB forumLee <t.lee.davidson@xxxxxxxxx>