ColdFusion Support In jQuery

Posted March 15, 2007 at 10:49 AM by Ben Nadel

Tags: ColdFusion, Javascript / DHTML

I am sure I have not been the first one to point this out, but someone just pointed it out to me (and I hadn't seen it before). The good people over at CJordan.us have created a jQuery plugin that mimics many of the built in ColdFusion functions. Come on CF'ers, no reason to not dive right into Javascript now :)

Here is a list of the available functions (as taken from their site):

  • Abs( number )
  • ArrayAppend( array, value )
  • ArrayLen( array )
  • ArraySort( array, sort_type [, sort_order ] )
  • ArrayToList( array [, delimiter ] )
  • Ceiling( number )
  • Compare( string1, string2 )
  • CompareNoCase( string1, string2 )
  • DateDiff( datepart, date1, date2 )
  • DecimalFormat( number )
  • DollarFormat( number )
  • Find( substring, string )
  • FindNoCase( substring, string )
  • Insert( substring, string, position )
  • IsDate( date )
  • IsNumeric( string )
  • LCase( string )
  • Left( string, count )
  • Len( sting )
  • ListAppend( list, value, [, delimiters] )
  • ListDeleteAt( list, position [, delimiters ] )
  • ListFind( list, value [, delimiters ] ) )
  • ListFindNoCase( list, value [, delimiters ] ) )
  • ListFirst( list, [, delimiters ] )
  • ListGetAt( list, position [, delimiters ] ) )
  • ListLast( list, [, delimiters ] )
  • ListLen( list [, delimiters] )
  • ListToArray( list [, delimiters] )
  • LTrim( string )
  • Mid( string, start, count )
  • Replace( string, substring1, substring2 [, scope ] )
  • ReplaceNoCase( string, substring1, substring2 [, scope] )
  • Reverse( string )
  • Right( string, count )
  • Round( number [, number of decimal places] )
  • RTrim( string )
  • StructKeyList ( struct [, delimiter] )
  • StructKeyArray ( struct )
  • Trim( string )
  • UCase( string )
  • URLDecode( string )
  • URLEncodedFormat( string )

Nicely done guys!



Reader Comments

Mar 15, 2007 at 1:44 PM // reply »
10 Comments

Thanks for pointing this out Ben. It will help a lot.


Apr 7, 2007 at 2:53 PM // reply »
168 Comments

Very cool.

A while ago, I did a little work towards porting all of CF's list functions to JavaScript in a way that was fully compatible with CF, while at the same time offering extended, optional functionality such as multi-character delimiters, regular expression delimiters, options for whether list items should be treated as case sensitive, whether empty list items should be preserved, etc., all within very tight code which didn't depend on a JS library. I've never gotten around to finishing it, but because I'd started this before the first thing I looked at in the cjordan.us code was their list functions. I must say that I'm a little disappointed that not only are many of the key list functions missing, but the others are not even close to compatible with ColdFusion. Oh well, there's always version 2 (or I could try to motivate myself to work on my JS list library).


May 14, 2007 at 6:52 PM // reply »
4 Comments

First Ben, thanks for blogging about CFJS! :o)

Second, and I know it's been a while since the post, but CFJS does now include all of the List functions (except for ListQualify. I didn't feel like that would be a very handy function in JS).

Anyway, I invite you and your readers to check out the latest version of the code. Also, someday (hopefully soon, as it's not that hard), I'll be creating a branch of CFJS that is *not* a jQuery extension.


May 15, 2007 at 3:36 AM // reply »
168 Comments

Chris, again, very nice work! However, since you specifically noted the list functions, I've noticed that they are still not compatible with CF. E.g., empty list items are not ignored, and delimiters are handled completely differently (though your delimiters are superior to CF's since multi-character and regex delimiters can be used).


May 15, 2007 at 7:17 AM // reply »
10,640 Comments

@Chris,

Good work. I know a bunch of people who love these list functions.


May 15, 2007 at 11:04 AM // reply »
4 Comments

@Steve,

Thanks for responding. I realize that empty list items are not ignored so my list functions are different in that way. I suppose I could allow the user to pass a switch that would turn this behavior off, but how many folks would want that? I always thought that ignoring empty list items was a mistake on CFs part. In fact a good friend of mine wrote a UDF called ListFix, that puts a null character of the user's choice in place of the empty list items.

Maybe I should note these differences in the ChangeLog or on my site somewhere (since there is no real documentation). What would you suggest? :o)

Cheers,
Chris


May 15, 2007 at 11:07 AM // reply »
4 Comments

@Ben,

It might be worth mentioning that the function list has grown. The library contains about 67 functions including some date/time functions. I've got plans for about four or five more functions, that I'll be coding soon.

Cheers!
Chris


May 15, 2007 at 12:29 PM // reply »
168 Comments

@Chris,

Yeah, IMO the most useful piece of documentation would be a list of how your functions differ from CF (even, or especially, when your versions are more useful), since I imagine most people who use your library would already be familiar with how the CF versions work (or at least they could look them up in the livedocs).

Whenever you think the library is at a good point (e.g., now), you should submit it to Ajaxian (from there it will easily spread further). Ajaxian is a great blog but they very rarely post anything CF-related. They would almost certainly link to your library.


May 15, 2007 at 12:57 PM // reply »
4 Comments

@Steve,

Thanks heaps for the suggestions!

I had a user suggest that I host it with RIAForge.org. I took a chance and did just that. The library got more exposure than I imagined it ever would. I'll see about listing it on Ajaxian, too! :o)

Also, I think you're absolutely right about the needed documentation. I just posted a note to my local CFUG that a new non-jQuery version was now available, and the head honcho guy wanted me to post the differences between my library and LeftCorner.js (LeftCorner.com) since it was that library I started out with. I've since added more than thirty functions and made numerous bug fixes.

Maybe later today, I'll post those differences along with some needed documentation.

Feel free to make more suggestions or criticisms. I love getting feedback.

Cheers!


Nov 15, 2007 at 10:41 AM // reply »
1 Comments

Hello,

It would be better if you put a quick download for the jquery plugin. I lost at site :o


Post A Comment

Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.

Please review the following issues:

Author Name:


Author Email:

Author Website:

Comment:

Supported HTML tags for formatting: <strong>bold</strong>   <em>italic</em>   <code>code</code>







  • Help Wanted - Find Your Next ColdFusion Job
InVision App - Prototyping Made Beautiful With Prototyping Tools Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
Feb 12, 2012 at 3:37 AM
Learning ColdFusion 8: CFImage Part III - Watermarks And Transparency
Hi Ben, Just to ask currently it is placed bottom right corner, if i need to replace the same rendered image on the bottom left side or in the bottom center, how that can be calculated. bottom ce ... read »
Feb 11, 2012 at 9:29 PM
Use jQuery's SlideDown() With Fixed-Width Elements To Prevent Jumping
I can't say how glad I am that I found your post. Thank you very much. ... read »
Feb 10, 2012 at 7:21 PM
jQuery AJAX Strips Script Tags And Inserts Them After Parent-Most Elements
Update! Instead of $(eval(options.insertAfter)).after(data['insertData']); I now use: var ajaxNode = document.createElement('span'); var parent = $(eval(options.insertAfter))[0].parentNode; ... read »
Feb 10, 2012 at 6:18 PM
jQuery AJAX Strips Script Tags And Inserts Them After Parent-Most Elements
encountered this same, what I consider, jQuery bug last week. I'm building a site in which I load some content via AJAX. This content contains Linkedin share button placeholders which Linkedin API ne ... read »
Feb 10, 2012 at 11:30 AM
Cross-Origin Resource Sharing (CORS) AJAX Requests Between jQuery And Node.js
After you understand the concepts here, this is an awesome cheatsheet for enabling CORS in just about anything http://enable-cors.org/ ... read »
JM
Feb 10, 2012 at 9:10 AM
My Safari Browser SQLite Database Hello World Example
@Amy, Here is a very good tutorial on how to use JOIN: http://www.sqltutorial.org/sqljoin-innerjoin.aspx ... read »
Feb 10, 2012 at 4:42 AM
Building A Twitter-Inspired RESTful API Architecture In ColdFusion
This is great, very useful Ben. I spotted a small typo in the api.cgm listing: <cfthrow type="Unauthroized" /> Cheers Stefan ... read »
Feb 9, 2012 at 10:35 PM
CFDirectory Filtering Uses Pipe Character For Multiple Filters (Thanks Steve Withington)
I was wondering if there would be a filter you could apply so that you got everything but what you included in the filter. As in show me all docs that are not a .pdf. ... read »