MiniBB JavaScript (part two)

In the first stage of our cleanup of the JavaScript in miniBB we got rid of or fixed the parts of the code that didn't work and updated the code to get rid of obsolete calls such as document.write, alert and the noscript tag. The one debugging call that we didn't replace was the prompt calls for inserting links and images into a post. The reason we didn't bother fixing that is that amending the JavaScript to do away with those calls is somewhat more complicated than the other changes that we applied. This almost brings the JavaScript into the early years of the 21st Century.

Fixing the code to get rid of the prompt calls would be more complicated if it weren't that I recommend replacing all of the edit buttons above the textarea with a more powerful alternative that has already been written and which is also available under a GPL licence - tinyMCE. By using this we obtain a far more powerful editor for our forum posts and we get to cut down on the amount of JavaScript that our forum needs since apart from our specific customisations of tinyMCE the entire script can be pulled in from a common external site meaning that many of our visitors will already have the script downloaded. Using tinyMCE also means that all the code that was attached to the buttons we deleted can also go. It is because you may decide not to follow this path in continuing to update the JavaScript used by miniBB that I have chosen that I split this update off from the earlier one I covered in part one. Should you decide against using tinyMCE then you are most welcome to apply the part one changes and then apply your own fix to get rid of the debugging prompt calls.

Apart from deleting the buttons from the template that provides the textarea and attaching tinyMCE to it instead, we also need to update the way that the Reply and Quote links work so that they will insert the appropriate content into the textarea when under tinyMCE control. In fact this also results in a dramatic reduction in the amount of JavaScript that we need as tinyMCE has code to handle the insertion of content at the cursor already built in (using a far more modern algorithm than the one in miniBB) so our code changes to fix those links to work with tinyMCE mean that a further large chunk of the JavaScript that miniBB provides can go. Also, rather than producing an error message when there is no text selected for the quote I think it makes more sense to simply copy the entire post into the quote and let the person delete any parts they don't want after that. This gets rid of a huge chunk of the code in forms.js including all of the part that was browser specific. All browser specific processing is now handled by the tinyMCE script which uses far more modern JavaScript than miniBB did and also which we do not need to concern ourselves with all that much as it is almost entirely externally hosted.

The implementation of tinyMCE into miniBB in addition to the changes we previosly made in part one mean that the JavaScript our forum uses is now nowhere near as antiquated as it originally was plus all of the code used actually works across all modern browsers. There is still some room for further improvements to the code to make it even more modern and completely unobtrusive but those changes are less urgent than the ones we have already applied and will also be easier to apply once the HTML the script uses has been updated to get rid of all the HTML 3.2.

To update your copy of miniBB to apply this second lot of updates to the JavaScript simply download the updated file and upload it to your site in place of the current one. As almost all of these changes are to template files these changes should continue to work with future versions of miniBB but of course there are no guarantees that this will be the case.


This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow