Topic: AJAX post preview 1.0.2

##
##
##        Mod title:  AJAX post preview
##
##      Mod version:  1.0.2
##   Works on PunBB:  1.2, 1.2.10
##     Release date:  2005-12-22
##           Author:  bedroom
##
##      Description:  This mod uses the xajax library to quickly display the
##                    preview of a post (or errors in the post)
##
##                    (see: http://xajax.sourceforge.net)
##
##                    Nothing fancy, it does what the "Preview" button does,
##                    only without posting the form and reloading the page.
##
##                    Note that if javascript is disabled, the "Preview"
##                    button will still work the usual way (This is called 
##                    graceful degradation, folks :) )
##
##   Affected files:  header.php
##                    post.php
##                    edit.php
##
##       Affects DB:  No
##
##            Notes:  Tested with Firefox 1.5, Internet Explorer 6.0,
##                    Opera 8.51
##
##       DISCLAIMER:  Please note that "mods" are not officially supported by
##                    PunBB. Installation of this modification is done at your
##                    own risk. Backup your forum database and any and all
##                    applicable files before proceeding.
##
##

This release (finally) fixes problems with Unicode characters displayed incorrectly. All languages will now display just fine in the preview box !

(pun_trim() was a bit too aggressive with the french "à", replaced by trim() )

Download here

1.0.1 users : just grab the post.server.php from this release, that's all you need to update.

Re: AJAX post preview 1.0.2

where can I see it running?

Re: AJAX post preview 1.0.2

Why don't you do that whitout AJAX, with just pure JavaScript ?

JavaScript can do that without using xmlhttprequest, without contacting the server, it's faster (the most difficult to do is to create JavaScript functions that convert BBCode and smileys).

[img]http://www.famfamfam.com/lab/icons/silk/icons/error.png[/img] /me speaks French and bad English [img]http://www.famfamfam.com/lab/icons/silk/icons/error.png[/img]

Re: AJAX post preview 1.0.2

because its alot harder to do the bbcode parsing in javascript, sure stuff like [b] is easy but [ code] is hard.

Re: AJAX post preview 1.0.2

@Connorhd : exactly !

And here's a demo !

Re: AJAX post preview 1.0.2

If using the innerHTML property is an option, JavaScript can parse bbcode just as easily as PHP can?and maybe in fewer lines of code than PunBB's parser.php file. Of course innerHTML isn't a W3C standard property and if bedroom is a standards purist, this may not be an option.

On the other hand, it is a de facto standard, its faster than DOM methods and enjoys wide browser support. Gmail makes good use of it.

Latest Open Source project: [img=Templar PHP]http://code.google.com/p/templarphp/logo?logo_id=1251758459[/img]

TemplarPHP - A cascading template framework for PHP.

Re: AJAX post preview 1.0.2

Actually, in this mod, the result of the parsing is assigned to a div's innerHTML. So it's not really a matter of standards (I hadn't even noticed that innerHTML isn't a W3C standard, thanks for pointing that out !)

Apart from JS not really being my cup of tea, another reason for choosing AJAX is that I don't like reinventing the wheel. My forum uses custom BB tags and smileys and this ensures I have just one file to edit if I want to add/modify/delete one of them. I made this mod mostly for my personnal needs, you see smile

Re: AJAX post preview 1.0.2

I was thinking about this and decided to write a demo: As-you-type Preview

As is, the script isn't ready to use in a live forum--it would need to be part of a mod package. If someone (bedroom?) wants to use this code in a future mod, go right ahead.

Latest Open Source project: [img=Templar PHP]http://code.google.com/p/templarphp/logo?logo_id=1251758459[/img]

TemplarPHP - A cascading template framework for PHP.

Re: AJAX post preview 1.0.2

Very cool as usual Shawn.

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

Re: AJAX post preview 1.0.2

i wrote something similar before when i was playing with javascript, but try for example
[ code][ quote=abc][ /quote]
[ /code]

11

Re: AJAX post preview 1.0.2

ShawnBrown wrote:

I was thinking about this and decided to write a demo: As-you-type Preview

As is, the script isn't ready to use in a live forum--it would need to be part of a mod package. If someone (bedroom?) wants to use this code in a future mod, go right ahead.

How can I get this into my forum?

Re: AJAX post preview 1.0.2

excellent plugin many thanks.

One question: how do i integrate it into the Quick Post in viewtopic.php?

i had a quick go following the steps in post.php, but it didnt work sad

Many thanks again.