Spellify for Coldfusion V1.0 Released

Spellify is an awesome textarea spell checker which uses a smooth and effective Ajax based interface. It's written by Nikola Kocic and can be downloaded here: http://www.spellify.com/

I was immediately impressed by the look and feel of this project which uses the Google spelling API but was dissapointed to see that it only supported PHP and .NET.

Well, I couldn't have this so set to work on a Coldfusion version. As CF makes these kinds of thing simple, within 30 minutes I had knocked together a Coldfusion version of Spellify.php which makes the call to the Google API and returns the XML to the Spellify Javascript.

I haven't tested this massively but it's a simple piece of code and seems to work nicely so I thought I'd get it released so you can get integrating Spellify if you need a spellchecker for textareas on your site.

Let me know if you find any issues with it.

This *should* work with all versions of CF - at least back to CF6 anyway.

Download Spellify.cfm V1.0

Here are the instructions - taken from the included READ ME.txt:

======================================================================
Spellify - Spellify.cfm v1.0 (based on Spellify.php by Nikola Kocic - http://www.spellify.com/)
Copyright (c) 2009 James Allen. (jamesallen.name, www.jwadevelopments.com)

E-Mail: james@jamesallen.name
======================================================================

Spellify.cfm is a Coldfusion version of Spellify.php for use with the superb Spellify text area spellchecker.

INSTALLATION (the following is based on the default spellify.php install and using demo.html to test):

1. Download and unpack the Spellify PHP package: http://www.spellify.com/download.html

2. Place it somewhere in your webroot, e.g /wwwroot/spell/

3. Copy Spellify.cfm to the same location as Spellify.php in the Spellify sub-folder (e.g wwwroot/spell/spellify/spellify.cfm).

4. Edit 'spellify/src/spellify.js', line 47. Change:

var defUrl  = 'spellify/spellify.php';

to

var defUrl  = 'spellify/spellify.cfm';

That's it!

Spellify should now be working with Coldfusion. You will probably have to change the defURL when you implement the code on your site (e.g /functions/spellify/spellify.cfm etc).

CFAjaxProxy - setCallBackHandler is global - remember that

Just a quick gotcha that caught me out for hours while using CFAjaxProxy in a messaging application I'm currently building.

When using CFAjaxProxy in asyncronous mode and setting a callback handler (setCallBackHandler(function)), be aware that this then becomes the callback handler for ALL subsequent calls. This is very important when building a complex Ajax application.

Basically when the user sends a message, I set a callback handler which then dynamically reloads the lists of past messages in the thread without leaving the message page.

Outside of this I have a global 30 second poll function which also uses CJAjaxProxy to obtain various user data (to alert of new messages etc). What I couldnt understand was that every 30 seconds the message list on this page would reload all by itself.. Spooky.. I searched my code looking for a call to my reloadThreadMessage() function but couldn't find one, outside of the send message function..

After much head scratching and shouting I finally realised that what was happening is every 30 seconds when the global poll was run, the CFAjaxProxy call to get the global data was still using the callback handler that was set when I sent the earlier message!

To fix this I simply place a call to setSyncMode() before the global data call and this removes the callback handler routine.

Something to bear in mind if your seeing weirdness while making multiple CFAjaxProxy calls in asyncronous mode..

How to fix CFWINDOW so the contents of the window layer are not visible on page load

Right, well I've been having lots of fun playing with the new super-duper CFWINDOW tag in CF8. What this lovely tag does is it allows you to quickly create impressive lookng web 2.0 style windows. The coolest feature of the tag is the ability to set a window as 'modal'. This makes the window one of those where the background of the page is greyed out with only the window being usable.. Very neat for login panel's etc. I'm making extensive use of this technology on the big project I'm currently working on.

Anyway, I became aware of an annoying problem today where the actual contents of the CFWINDOW was appearing at the top of the page while it was loading. Once loading was complete the content would dissapear as the Ajax goodness kicked in to hide it.. Well obviously on a production site this is simply not workable - we can't have our vistors seeing ugly text at the top of the design only to watch it vanish when the page is fully rendered.

Well anyway after an inspired moment about 10 minutes ago I realised that the key was to make sure the generated <div>'s tags that CFWINDOW creates to hold the window contents are set to render off screen. The fix is the incredibly complex piece of CSS ( :) ) that you need to add to your stylesheet:

.yuiextdlg {
    position:absolute;
    left:-200px;
}

You may need to play with the left offset if your CFWINDOW dimensions are quite wide.

This works a treat and ensures that all your CFWINDOW pages are loaded properly.

CF8 and json for Ajax - remember the UPPERCASE rule

Just a quick CF8 gotcha that can cause annoying problems if you aren't aware of it.

Basically, if your doing any AJAX in CF8 and using the returnFormat="json" functionality to get a CFC (with access="remote") to return data to Javascript on the frontend, remember this:

ColdFusion internally represents structure key names using all-uppercase characters

So what this basically means is that no matter how you specify your structure data in Coldfusion (e.g params.userName = "james"), when it arrives on the frontend via Javascript you MUST use UPPERCASE variable names.

E.G alert(proxy.USERNAME);

Just something to watch out for as it can catch you out..

Bug in calling CFC's remotely via the URL when using application.cfc

I've just been playing with the incredible <cfajaxproxy> tag in CF8 and have come across what appears to be a bug in Coldfusion when using application.cfc and calling CFC's via the URL method.

The URL method allows you to call CFC's via a URL and access any method in the CFC which has access="remote" set. Coldfusion will take care of returning the data as WDDX encoded or in JSON if using Coldfusion 8.


Anyway, I was testing this earlier today and found that no matter what I did, when calling a method in a CFC using the URL method a blank page was returned. It was incredibly frustrating!

A quick trip to the excellent #coldfusion IRC channel on Dalnet gave me the answer though (thanks Hapex) - application.cfc.

Well more specifically the onRequest method in application.cfc! For some reason if this method is defined in the file, remote CFC calls will simply display a blank page.

The solution? Comment out onRequest if you aren't making use of it. If you are, simply create an application.cfm and place it in the folder with your remotely accessed CFC's.

I believe this has been submitted to Adobe as a bug.. Hopefully it'll get fixed in the next release.

© 2010 James Allen | Contact Me
This blog runs on the awesome power of BlogCFC - created by Raymond Camden. This blog is running version 5.9.