CFJS 1.1.12
This release contains a small change to the DateFormat() function.
This release contains a small change to the DateFormat() function.
I have updated the CFJS function listing page. There is a link to it in the sidebar on the right -- or just click here.
My goal will be to update that page as often as necessary and then post a quick blog note (like this one) alerting folks to the update. Overkill? Maybe... but I'm havin' fun. :)
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'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 |
Okay. It's late. Really late. But, I'm back -- I know you're thinkin' who the heck are you? -- and part two of my jQuery + AjaxCFC tutorial is finally here. I've been stressing over not having finished this sooner, but I hope some folks will still find it useful.
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.
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. |
Thanks to my good friend and co-worker, Steven Van Gemert, two new string functions have been added to both the jQuery and non-jQuery branches of the CFJS library!
Functions Added:
Pad(String [, Number] [, PadCharacter] [, PadDirection])
RepeatString(String, Number)
Since Pad() isn't a usual ColdFusion function, I'll update this blog post with some instructions and an example later this evening.
EDIT: So, here's the edit I promised for last night. I'll show here an example of how the Pad() function works.
>>>>>>>>>CFJS ROCKS!
Changing the direction of the pad would put the fill characters on the other side of the starting string. If the given string is longer than the length passed in (arg. 2), then the function just returns the original string.
The function will also accept R or L as directions in stead of Right or Left.
The addition of these two string functions brings the total number of functions in the library to 69!
CFJS Downloads (jQuery):
Download CFJS for jQuery (compressed) 9.5KB
Download CFJS for jQuery (uncompressed) 22.7KB
Download The CFJS ChangeLog 5.7KB
Downloads (non-jQuery):
Download CFSJ (compressed)
Download CFSJ (uncompressed)
Cheers, everyone!
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!
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