Topic: Basic post editor (work in progress)

Since we ported our forum from MiniBB, some people have complained about the very simple post editor. I've seen the "post enhancer" mod, but I'm not too happy with that, so I'm writing my own.

Features: You can apply bold/italic/underline/code/quote/url to current selection - or if nothing is selected, open/close tags will be generated on first/second click. The URL button provides a prompt and generates the appropriate code.

For testing, it includes just one smiley now - the finished mod will of course generate smiley buttons according to your configuration.

It should work on IE4 or newer on Windows, but basic (dumb) functionality is provided for minority browsers, so it shouldn't cause errors on those - I only have IE6 to test with, so please specify your browser/version when posting your test results...

http://www.mindplay.dk/temp/postedit.htm

Thank You! smile

2

Re: Basic post editor (work in progress)

I can't apply features to existing text, but I can insert tags. This is under Firefox 1.0.

Re: Basic post editor (work in progress)

Good - as said, those features only work under IE ... I don't know if it's even possible to implement under Firefox?

Re: Basic post editor (work in progress)

Looking good mindplay smile.
Firefox users can make use of the BBCode extension for quicker post formatting.

Re: Basic post editor (work in progress)

mindplay: Try this JavaScript. It supports IE, Moz and has fallback support for quirky browsers such as Opera/Safari etc.

<script type="text/javascript" language="javascript">  
<!--
function insert_text(open, close)
{
    // Replace 'post' with the ID of the form
    msgfield = (document.all) ? document.all.req_message : document.forms['post']['req_message'];

    // IE support
    if (document.selection && document.selection.createRange)
    {
        msgfield.focus();
        sel = document.selection.createRange();
        sel.text = open + sel.text + close;
    }

    // Moz support
    else if (msgfield.selectionStart || msgfield.selectionStart == '0')
    {
        var startPos = msgfield.selectionStart;
        var endPos = msgfield.selectionEnd;

        msgfield.value = msgfield.value.substring(0, startPos) +    open + msgfield.value.substring(startPos, endPos) + close + msgfield.value.substring(endPos, msgfield.value.length);
        msgfield.selectionStart = msgfield.selectionEnd = endPos + open.length + close.length; /* + ((text.indexOf("[") == "0") ? text.length/2 : text.length); */
        msgfield.focus();
    }

    // Support for stupid browsers
    else
    {
        msgfield.value += open + close;
        msgfield.focus();
    }

    return;
}
-->
</script>
"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: Basic post editor (work in progress)

Thanks, that was helpful - and pretty easy smile ... Try this again:

http://www.mindplay.dk/temp/postedit.htm

I downloaded Mozilla Firefox 1.0 for testing, and the script should now fully support that.

(This makes the script about twice as long with some repeated code - I may decide to clean it up, but it's only 3500 bytes of javascript, and if it's put into an external javascript file it'll get cached on the client anyways, so...)

Re: Basic post editor (work in progress)

Just uploaded again - now has actual buttons, with state (open/close) indication on them smile ... tested in Mozilla Firebird and IE6. A small bug in IE will cause selection to disappear if you select everything and then apply a style, such as bold. No cure, as far as I can figure. But also no big, I guess. Everything else seems to work. Feedback, anyone?

Re: Basic post editor (work in progress)

Uploaded again - more style, hints are displayed when you roll over the buttons, a small bugfix for Mozilla, and focus on the control now sticks if you accidentally click next to a button. (the latter works best in Mozilla, since, apparently, IE has a small focusable area next to every button, on which you can't detect clicks)

Re: Basic post editor (work in progress)

The textarea is cleared when I click any of the smilies.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: Basic post editor (work in progress)

Fixed (?)

It's a weird little Mozilla bug - if your onClick event on Button objects don't return false, it submits the form, apparently ... only Submit objects are supposed to do that, afaik...

11

Re: Basic post editor (work in progress)

Working very well now for me smile

Re: Basic post editor (work in progress)

hmm, now it's giving me problems in IE ... doubleclicking to select some text, then applying, say, bold - works fine ... but left-drag to select some text, then apply bold, and - oops - the text is deselected. Annoying. I can't figure out why. Any ideas?

Re: Basic post editor (work in progress)

Its working fine in both IE and Firefox 1.0

God wisely designed the human body so that we can neither pat our own backs nor kick ourselves too easily

Re: Basic post editor (work in progress)

You can't reproduce the problem I mentioned under IE? ... what version of IE are you using? (mine is IE6 SP2 on Win XP SP2)

Try drag-selecting some text, then apply bold - on my machine, the selection disappears, and the textarea looses focus...

Re: Basic post editor (work in progress)

well, I assumed that it was me - that I did something to break the editor, so I shaved it down to next to nothing, the bare essentials, 15 lines of code just for testing, but the problem persisted.

I then decided to "spy" on some of the other commonly used boards on the net:

phpBB
Invision Power Board (IPB)
madtracker.org (custom)

(also looked at miniBB and two or three others, but found no others with real BBcode editing)

... they ALL suffer from this new bug, so now I'm assuming it's a bug in IE6 SP2 under WinXP SP2.

I guess there's nothing I can/should do about this, then? I guess we can only hope m$ is going to fix it? ... they introduce new bugs every time they update IE! sad

16

Re: Basic post editor (work in progress)

This is a good idea. It saves alot of trouble newbies asking how to get a smiley on their post.

Re: Basic post editor (work in progress)

yep - I need to finish the editor and make it compatible with v1.2 ... expect it'll be a while before I get there though, since my first priority at the moment is finishing PunMod; after which I will make the mod in that smile