CFJS 1.1.12
This release contains a small change to the DateFormat() function.
This release contains a small change to the DateFormat() function.
Just a quick note to let folks know that all branches of CFJS (both jQuery and non-jQuery) have been updated with a bug fix for two of the list functions, namely ListContains() and ListContainsNoCase().
I've successfully added HTMLCodeFormat() and HTMLEditFormat() functions to CFJS and have checked the new code into the repository as version 1.1.10.
But I've got more to do. Looking through some old notes, I found that I still needed to add the following:
I will of course, still be working on a demo page as well.
It could happen. The jQuery team is trying to gauge the interest of the community at large in attending a fee based online training class on jQuery delivered live by John Resig himself.
To quote the post to the jQuery general mailing list:
"Nobody knows jQuery better than John and in terms of JavaScript, he's considered one of the best in the world. So a training class delivered by him would surely help anyone become more proficient in JavaScript and jQuery."
Realize now that they're just trying to gauge interest. No details have been hammered out. Some concerns that have been raised so far on the mailing list are:
All are valid questions, but don't really have anything to do with the poll in which the jQuery team is asking that we participate. They're merely trying to ask the question: If John were to deliver a live, online class on the subject of jQuery (and by association JavaScript) would you pay to attend?
Do the community a favor and answer the poll. Answering the poll is not the same as making a commitment to attend or to pay any sum of money. It's a simple yes or no question. So head on over to the poll and give your yea or ney.
And in case you've missed it the three or so times above... here the link to the poll. :o)
It's been a long while since I've made any mention of CFJS in any of my blog posts. I had a look at the function listing linked to on the right hand side of the page under Projects, and noticed that the function listing wasn't quite up-to-date.
So, I decided that I'd post a fresh one. I'll replace the old link on the side with a new one to this post.
I've not gotten any requests for new functionality to be added to the library, and quite frankly, I've been too busy to devote too much time to it recently. I hope that will change later, but I think the library gets a good workout by everyone who uses it, and if something were wrong with it I'm sure I'd hear about it. ;o)
So without further ado, here's the most recent function listing. I may play around with the format of the listing, but the content shouldn't change. :o)
| ArrayAppend |
| ArrayPrepend |
| ArraySort |
| ArrayToList |
| ArrayLen |
| CreateDate |
| CreateDateTime |
| CreateTime |
| CreateODBCDate |
| CreateODBCDateTime |
| CreateODBCTime |
| DateDiff |
| DatePart |
I've been stupid busy at work recently writing code for two client's both of which have deadlines that need to be met, changes to be made, bugs that need fixing... you probably know the drill.
On top of that I've recently been diagnosed with high blood pressure, high cholesterol, and diabetes! Sucks to be me, huh? Anyway, the upshot is that I've really not had a lot of time to do all the things that I want to do for the CFJS project. I'm also writing a tutorial about using Rob Gonda's AjaxCFC with jQuery that I promised a few folks I'd get published soon.
So today I received an email from Trent Richardson not only offering to help with the CFJS project, but he put his money where his mouth was... or his code where his mouth was... or something, and wrote the IsValid() function that he was suggesting be added to the library! How cool is that!
This is my first open source project, so it's super cool to me that a) people are using it and b) that someone is willing to help the cause! I'm stoked. Thanks Trent!
Anyway (@Neil), I'm going to try to finish the tutorial and my goal is to get it up tonight. Things have finally calmed down a little with my clients, so hopefully I'll be able to get some work done on these projects (as well as fit in a movie or two ;o).
BTW: I just saw the Transformers movie tonight. It was awesome! And (as the folks in Hollywood are apt to do) they totally left it open for an other movie.
Just a quick note to say that jQuery 1.1.3 is now available for download using the following links.
This release is supposed to be more than 800% faster than the previous release! I personally, cannot wait to give this final release a test drive in my current production code!
The blog entry over at jquery.com has loads more information and I won't try to repeat it here.
The jQuery team has also released information about a secret project that has been in the works: jQuery UI.
I'm super excited about this and about the future of jQuery which is also discussed in the blog post over at jQuery.com.
If your a fan of jQuery and have a few bucks lyin' around, think about donating to the cause. It's a good one.
Hi folks.
I've received a new feature request for the CFJS library via riaforge.org.
John Farrar writes:
First I'm not fully sure I understand what John's talking about or how it would work, but here's what I *think* he's driving at:
CF and JS each use a different starting value for indexing arrays. CF starts at one (quite logical) while JavaScript starts counting at zero (a la C, C++, heck Fortran 77 I think(!) and probably others). So typically, when looping in these different languages one starts the loop count at 1 or 0 depending on what's called for.
So, if I'm understanding John correctly, he'd like a function that makes JS behave like CF in this regard. My opinion in the past has been that this isn't really a good idea. I don't really want to spend clock cycles fiddling with the shifting array element indexes and such around so that someone can start a loop at one instead of zero. Also, when JavaScript evals a JSON serialized string it automatically starts indexing at zero.
I don't think I want to mess around with the way in which JavaScript handles indexing. I just want to provide JavaScript functions that replicate CF functions as close as I can in syntax and ability.
Anyway, it just seems like a lot of work for little profit, and I'm not sure how I'd do it in the first place.
John, have I understood your request correctly or am I way off the mark?
I'd like to hear peoples opinions on this topic. So, by all means use that comment button and toss in your two cents.
While I'm still struggling to find the time to work on new features for the CFJS libraries (IsValid, ArrayAverage, ArrayClear, ArrayDeleteAt, ArrayInsertAt, ArrayPrepend, and ArraySum), a bug in the DateFormat function had been brought to my attention by user Boyan Kostadinov. He then later pointed me to another DateFormat function written by Steve Levithan.
Steve's DateFormat function is very nice, and since Steve does some ColdFusion programming the syntax is very similar. Steve implemented his function as an extension of the JavaScript date object, but since I've incorporated his function into both branches of the CFJS library this is no longer the case. So the CFJS syntax of the function follows more closely to the syntax of CF's native function.
In Steve's implementation you could write a line of code like this:
Which should return something like, "Today is Thursday". But when using the CFJS implementation to get the same result you'd need to write it like this:
Following is a table of the different metacharacters available to the DateFormat function. (This table is almost a direct rip from Steve's blog post which discusses his function)
| Mask | Description |
|---|---|
| d | Day of the month as digits; no leading zero for single-digit days. |
| dd | Day of the month as digits; leading zero for single-digit days. |
| ddd | Day of the week as a three-letter abbreviation. |
| dddd | Day of the week as its full name. |
| m | Month as digits; no leading zero for single-digit months. |
| mm | Month as digits; leading zero for single-digit months. |
| mmm | Month as a three-letter abbreviation. |
| mmmm | Month as its full name. |
| yy | Year as last two digits; leading zero for years less than 10. |
| yyyy | Year represented by four digits. |
| h | Hours; no leading zero for single-digit hours (12-hour clock). |
| hh | Hours; leading zero for single-digit hours (12-hour clock). |
| H | Hours; no leading zero for single-digit hours (24-hour clock). |
| HH | Hours; leading zero for single-digit hours (24-hour clock). |
| M | Minutes; no leading zero for single-digit minutes. Unlike CF we use an uppercase M to avoid conflict with months. |
| MM | Minutes; leading zero for single-digit minutes. Unlike CF we use an uppercase MM to avoid conflict with months. |
| s | Seconds; no leading zero for single-digit seconds. |
| ss | Seconds; leading zero for single-digit seconds. |
| l or L | Milliseconds. l gives 3 digits. L gives 2 digits. |
| t | Lowercase time marker string: a or p. No equivalent metasequence in CF. |
| tt | Lowercase time marker string: am or pm. No equivalent metasequence in CF. |
| T | Uppercase time marker string: A or P. This is equivlant to CF's t metacharacter. |
| TT | Uppercase time marker string: AM or PM. This is equivlant to CF's tt metacharacter. |
| Z | Timezone abbreviation; e.g., EST, MDT … No eqivalent metacharacter in CF. |
| '…' or "…" | Literal character sequence. Surrounding quotes are removed. Not necessary when using mask characters as part of larger words. CF only supports single quotes for literal spans. |
The most notable differences are that I've added the 't' and 'T' metacharacters to the function. While, Steve's function allowed for 'AM' or 'am' with TT and tt respectively, he did not allow for 'A' or 'a' which is what 'T' and 't' are used for.
The other major thing to note (if you haven't already) is that this new DateFormat function also handles the formatting of time. This means that there really isn't a reason to have a TimeFormat function. However, since this breaks with CF's dogma, I've written TimeFormat such that it's really just an alias of DateFormat. Someone might use DateFormat() for all their date formatting needs and TimeFormat() for all their time formatting needs, but in reality the two functions work interchangeably.
The nice thing about having one function that handles both date and time formatting is that it replaces two other functions that were quite long, and so the overall size of CFJS just went down by a bit. :o)
| Type | Description |
|---|---|
| any | any simple value. Returns false for complex values, such as query objects;; equivalent to the IsSimpleValue function. |
| array | an ColdFusion array; equivalent to the IsArray function. |
| binary | a binary value;; equivalent to the IsBinary function. |
| boolean | a Boolean value: yes, no, true, false, or a number; equivalent to the IsBoolean function. |
| component | a ColdFusion component (CFC). |
| creditcard | a 13-16 digit number conforming to the mod10 algorithm. |
| date or time | any date-time value, including dates or times;; equivalent to the IsDate function. |
| a valid email address. | |
| eurodate | any date-time value, including US date formats and time values. |
| float or numeric | a numeric value; equivalent to the IsNumeric function. |
| guid | a Universally Unique Identifier of the form "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" where 'X' is a hexadecimal number. |
| integer | an integer. |
| query | a query object; equivalent to the IsQuery function. |
| range | a numeric range, specified by the min and max attributes. |
| regex or regular_expression | matches input against pattern attribute. |
| ssn or social_security_number | A U.S. social security number. |
| string | a string value, including single characters and numbers. |
| struct | a structure; equivalent to the IsStruct function. |
| telephone | a standard US telephone number. |
| URL | an http, https, ftp, file, mailto, or news URL. |
| UUID | a ColdFusion Universally Unique Identifier, formatted 'XXXXXXXX-XXXX-XXXX-XXXXXXXXXXXXXXX', where 'X' is a hexadecimal number. See CreateUUID. |
| USdate | a U.S. date of the format mm/dd/yy, with 1-2 digit days and months, 1-4 digit years. |
| variableName | a string formatted according to ColdFusion variable naming conventions. |
| zipcode | U.S., 5- or 9-digit format ZIP codes. |
The CFJS (ColdFusion JavaScript) jQuery extension is now available as a regular JavaScript object. So if for some reason you don't or can't use jQuery that won't keep you from using CFJS.
Both this version and the jQuery extension have been expanded to include sixty-seven useful ColdFusion functions! All of the List functions have been duplicated (except for ListQualify). However there is a slight difference in the way delimiters are handled. Empty list elements are *not* ignored as they are in ColdFusion, and multi-character delimiters are allowed.
Both versions will be kept in sync so that they maintain the same functionality. When one gets updated the other will receive the same update.
View all posts about the CFJS project
Downloads:
Download CFSJ (compressed)
Download CFSJ (uncompressed)
Downloads for CFJS for jQuery can be found here.
Cheers!
Recently, I was having trouble getting a CFJS for jQuery to compress without breaking the resulting packed code. When running the compressed code I'd get some error like, "missing ; at end of statement" or something similar. A quick search of the jQuery Google Group archives turned up a suggestion: run your code through JSLint over at jslint.com.
Why not?
I visited the site and found that it was written by Douglas Crockford, so immediately I knew I was going to be getting something of quality out of my visit to the site. The interface seemed simple enough: copy your code into the top section, click the 'JSLint' button, and watch the magic happen. So, I grabbed my code and did just that.
I was humbled. The thing found numerous problems with the code - some of it mine, some of it borrowed, but that doesn't matter - sloppiness abounded. It was kinda cool though, I learned a few things I'd not known before, mostly about best practices. After I cleaned up the slop in my code, I ran it through Dean Edwards' JavaScript compressor one more time, and like magic the compressed code worked like a champ!
I'm constantly trying to learn more about JavaScript and to make my code cleaner and more efficient. JSLint is just one more way that I can check to see that I'm on track with that goal.
JSLint also has a barrage of options that the user can turn on or off to meet their level of strictness. These are:
And if you don't understand any of those, documentation is provided.
Okay, I admit it. It was entirely my fault.
A couple of weeks ago I was writing some code for a client of mine, making the app all Web 2.0-y-ish. I'm using AjaxCFC for jQuery and it keeps telling me that a critical error has occurred and that I can click OK to see what's the matter.
So, I click. And all I see is my data in the resulting popup; Not an error, but the actual data that I was expecting back! Um... is this a bug in AjaxCFC? I'm not sure, so I check and re-check my code. I try several things, but I'm just grasping at straws. So, I ask Rob Gonda what the heck I'm doin' wrong.
Well, he helped me as best he could, but in the end it wasn't AjaxCFC at all! Finally I figure out what the problem is: in the success parameter of the AjaxCFC call, I was immediately trying to dump the resulting data using $.dump(data);. Well, there's nothing wrong with that... unless you've forgotten to include the plug-in that makes the $.dump() function work.
oops... color me embarrassed.
So, today it happens again! I check and re-check my code again, and whereas last time I was using a $.dump(); this time I was just using a plain ol' alert();
Well, long story short (what's that you say? too late?) it turns out that the line of code I'd put in was:
instead of:
So, the moral of the story is: If AjaxCFC tells you there's an error, but it only shows you the data you expected... you've probably made some other mistake elsewhere in your JavaScript. Most likely in the success parameter of the ajax call. So triple-check your code. It could just be a boneheaded mistake. :o)
Thanks for all your patience Rob. And thanks for a wonderful plug-in!
Cheers
Simply put: CFJS for jQuery is a set of ColdFusion functions written for JavaScript.
The CFJS for jQuery library is ment for ColdFusion programmers who might not be as accustomed to writing in JavaScript, or for anyone who just wants a set of nifty functions at their disposal! :o)
For a while now I've been keeping the latest version of the code for CFJS over at RIAForge.org. This project does not directly use an Adobe technology, but it emulates one and so I guess they thought it would be okay for me to host the project there. (Thanks Ray!)
The download links below now point to the code in the SVN repository. Also, if anyone finds a bug or would like a function added, please use the Issue Tracker on RIAForge or contact me via the jQuery google group. You could also leave a comment to this post.
The complete list of functions provided by CFJS is contained in the changelog which is in the root of the SVN repository.
EDIT:
A list of the the available functions, now totaling 67, is available outside of the ChangeLog.
As the list of functions grows, I think I may start to offer them in smaller packages like, jquery.cfjs.strings.js, and jquery.cfjs.lists.js but for now the packed version of the whole thing is around 9.5K, and that doesn't seem too big to me.
If there's more interest in a distribution method like I mentioned above, then I may just do it anyway.
CFJS Downloads:
Download CFJS for jQuery (compressed) 9.5KB
Download CFJS for jQuery (uncompressed) 22.7KB
Download The CFJS ChangeLog 5.7KB