ColdFusioning.com
Pronunciation \kold-fy-zhn-ing\ Noun: The actions of one that writes ColdFusion.

Please check out my new site: http://ja.mesbrown.com/

Backbone.js 0.9.0 Released

Yesterday, Backbone.js 0.9.0 was released. If you'd like to know what changed, you can view the Changelog.

NOTE: You must use Underscore.js > 1.3.1 with this Backbone.js update

I just dropped the new library into my favorite video website and ran our client-side unit tests. It did not go well. It looks like there will be some work done before implementing this release. Around half of the tests failed.

This new version looks like a great update and it is exciting that Backbone.js is nearing a 1.0 release. However, this isn't a minor upgrade and it is not backwards compatible.

Building Lightning Fast Mobile & Desktop Web Applications Presentation

I gave a presentation at NCDevCon 2011 on "Building Lightning Fast Mobile & Desktop Web Applications". If you missed the presentation, they have posted the presentation online! You can view it anytime but it does require Microsoft Silverlight: View Online

Though the slides are in the video, if you don't have Silverlight installed, I'm including the slides in a PDF. Also, the presentation description is:

In this session we are going to explore different techniques and methods to speed up your mobile and desktop web applications and websites. Consumers and end-users have come to expect pages to load quickly and be responsive. Research shows that our brains can perceive time around 100 millisecond intervals and those intervals can add up if you have bottlenecks in your page load times or the responsiveness of the pages is poor once they are loaded. We are going to look at techniques you will be able to implement immediately to speed up both the actual and perceived experience of your site. This session will cover both server and client-side technologies. We will explore desktop and mobile use-cases and demonstrate various tools you can use today. This session will utilize ColdFusion and Backbone.js but concepts will apply to all web applications.

I'm speaking at NCDevCon 2011!

I am very honored to have been selected to speak at NCDevCon 2011! The event is September 17-18th, 2011. If you'd like to come hear me (or these other great speakers ) be sure not to miss this event. My topic is "Building lightning fast mobile & desktop web applications". We'll be exploring different techniques to build extremely fast and responsive web applications. We'll also look at Backbone.js and using it to build Single Page Web Applications (SPWA).

If there is anything specific you'd like me to address or specifically speak on, either related to 'lightning fast mobile & desktop web applications" or Backbone.js specifically, let me know in the comments below.

See you in Raleigh, NC on September 17 - 18, 2011!

spwa-backbone Update for Backbone.js and Underscore.js

Tonight, I updated the spwa-backbone library to work with the latest Underscore.js. If you'd like to learn how to use the library, you can view the Backbone.js spwa-backbone post. In the comments, "Jeremy" discovered a bug that caused the spwa-backbone to not work with the latest Underscore.js library. The latest Underscore.js library (version 1.1.6) caused an error because: "_.bind now errors when trying to bind an undefined value."

You can view the updated source on Github:
http://github.com/ibjhb/spwa-backbone

I've also added the annotated source online:
http://ibjhb.github.com/spwa-backbone/

Lastly, you can view a sample application, using the spwa-backbone for Backbone.js library online:
http://ibjhb.github.com/spwa-backbone/

Also, rather than link to the public library URLs, I now include the libraries (jQuery, Backbone.js & Underscore.js) in the repo so the code will continue to work if those libraries are updated.

Using spwa-backbone To Build A Single Page Website Application

Today we're going to look at building a single page website application using Backbone.js and spwa-backbone libraries.

You can view the source code on Github.  You can also view the single page web application example in the /example/ folder.  For a more complete example, visit: Single Web Page Example

What is an spwa?

Specifically, an spwa is a single page web application.  More generally, it's a website or application where all (or most) of the content is in a single page.  You can have links to other pages but the URL stays the same, except for possibly anything after the hash tag (the pound sign - #).

Why would I want to build an spwa?

There are many reasons to build an spwa.  The most obvious advantage is pure speed.  Since most of the content is loaded in a single, first request, the subsequent calls are extremely fast. 

When you load the example application, you can see that switching from page to page is almost instant.  Also, if you open Firebug, you'll see that there are not additional http requests to the server for each page.

Another major reason is bandwidth considerations for mobile devices.  Since all the pages are loaded with the first request, we don't need to make subsequent calls to the server.  Additionally, all of our JavaScript libraries and CSS files don't need to be re-requested, downloaded or processed.  This can save a considerable amount of time and bandwidth.

Will I be able to deep link to a specific page?

Of course!  Your application would be pretty worthless if you couldn't allow your visitors to link to a specific page on your site.  The beauty of using this code is that the spwa-backbone and Backbone.js libraries both automatically handle the deep linking.

Will the browser's 'back button' work?

Of course it works!  Just like the deep linking, Backbone.js and spwa-backbone handle everything necessary for the back button to work.

How do I get started?

It doesn't take much to get started with spwa-backbone. 

1) The first step is to include the required libraries:  jQuery, Underscore.js and Backbone.js.  You can use the minified or un-minified versions of each library.  It does not matter.

2) The second step is to include the spwa-backbone library. 

3) The third step is to create and your content.  Each page is enclosed in a script tag, similar to:

view plain print about
1<script type='text/template' id='home-template'>
2Content here
3</script>

Each 'page' should have a different id attribute but you must include the '-template' suffix (note the hyphen).  Another example of an id attribute would be 'about-template'.  The 'home' page is shown by default if there is no page specified in the URL by hash tag.

4) Lastly, create your links.  You'll naturally want to create links between your pages.  You link to them using the following convention:

view plain print about
1<a href="#!about">About</a>

This would link us to the 'about-template' page.  Notice that there is a hash tag and an exclamation point in the href.  This let's us use the hash tag to change the page and the exclamation point to tell Google to index the page. 

That's it!

It's very easy.  You can create multiple pages and links very quickly.  The library will do all the work and routing.  Take a look at the example html file for a full example. 

Lastly, the un-minified version of the spwa-backbone library is fully commented.  If you are curious how the library works, take a look and if you read through the whole file, it should make sense.  If something doesn't make sense or needs a better explanation, please don't hesitate to let me know.

If you have any questions, comments or requests, please leave a comment below.

Backbone.js + jQuery = Best OO Friends Example

Backbone.js + jQuery = Best OO Friends Example

Today we are going to dive deep into OO JavaScript programming using Backbone.js and jQuery.

This is going to be a detailed example. If you want to dive directly into the code, you can check out the repository on Github.

Before we dive into the code, check out the working example of the code: Backbone.js Example

Each of the files is heavily commented and should provide insight into what each major section of code is doing.

(Open the Backbone.js Sample to view the full text)

[More]

Detecting Java Browser Support Using jQuery

Today we're going to quickly look at detecting Java (not JavaScript) using jQuery. It is actually very simple using the jQuery Browser Plugin. Once you have the plugin loaded, it extends the $.browser object to give you the following:

view plain print about
1$.browser.flash     //Flash
2$.browser.sl         //Silverlight
3$.browser.pdf         //PDF format
4$.browser.java     //Java
5$.browser.qtime     //Quicktime
6$.browser.wmp         //Windows Media Player
7$.browser.shk         //Shockwave
8$.browser.rp         //Realplayer

As you can see, we gain more than just Java detection, but Java detection is the one we're looking for in this example.

You can view a working example on this Java Detection Using jQuery page and the source code is naturally on github.

jQuery Dynamic Modal Window

Ever needed to display a jQueryUI modal window but you didn't want to (or couldn't) edit the HTML on the page? I was developing a "third-party" JavaScript file where I didn't have control over the HTML page that my library was being included on. However, I wanted to popup a modal window when there was an error.

Well, using the below code, possibly coupled with code from loading jQuery dynamically, you can append code to the and pop-up your window:

view plain print about
1$('<div id="error" title="No Address Matches Found">We could not match the address to any known addresses. Please correct the address and try again.</div>')
2    .appendTo('body')
3    .dialog({
4        modal: true,
5        width: 425,
6        height: 275,
7        buttons: {
8            OK: function(){
9     $(this).dialog('close');
10         }
11     }
12    });

jQuery: $("#elementID") != document.getElementById("elementId")

Just a quick reminder that in jQuery:

$("#elementID") != document.getElementById("elementId")

They are not the same thing.

If you use $("#elementID") you will return an array. If you want the real DOM element you need to use: $("#elementID").get(0)

ColdFusion and jQuery - Using AJAX to Call a CFC and Return JSON

I recently had a friend ask me about using jQuery to call a ColdFusion CFC via AJAX and return a value. It is actually quite easy and fun to do. It requires two files to be created. The two filenames I'm using for this example are: index.cfm and myCFC.cfc but you could easily use your own filenames.

The first file we're going to start out with is index.cfm:

view plain print about
1<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>
2<script type="text/javascript">
3chkUsernameUnique = function(theUsername){
4    $.getJSON("/assets/cfc/myCFC.cfc", {
5        method: 'chkUsername',
6        Username: theUsername,
7        returnformat: 'json'
8    }, function(isUsernameUnique){
9    
10        if (isUsernameUnique == true) {
11            $("#theErrorDivID").html('Username is unique');
12        }
13        else {
14            $("#theErrorDivID").html('Please select a new username');
15        }
16    });
17};
18</script>
19
20<div id="theErrorDivID"></div>
21<input type="text" name="username" id="username" onchange="chkUsernameUnique(this.value);" />

If you read through the code, it is self explanatory. We first include the jQuery library from the Google CDN (you could always point this at your web server if you are going to host the file instead). In the next set of lines, we create a function, setup our AJAX, specify the CFC (you can change the cfc path to match your web server), method and some variables. We then specify the return function to run once the data is returned from our cfc. Based on the data returned, we display a message to the user. The final lines outside the script tag are the DIV for displaying the message and the input.

The next set of code is the cfc we call (myCFC.cfc):

view plain print about
1<cfcomponent>
2<cffunction name="chkUsername" access="remote" returnformat="json" output="false">
3        <cfargument name="Username" required="true">
4            
5        <cfquery name="chkUsername" datasource="YOURDATASOURCEHERE">
6        SELECT ID FROM tb_user WHERE user_login = <cfqueryparam value="#arguments.Username#" cfsqltype="cf_sql_varchar" />
7        </cfquery>
8        
9        <cfreturn yesNoFormat(chkUsername.recordCount) / />
10    </cffunction>
11</cfcomponent>

This set of code queries the database to check if the username is unique and returns true or false based on that result. This example could quickly be expanded to check for other variables or perform additional functions. If you are new to jQuery, I highly recommend you check it out and dive right into it. If you are looking for a book to learn jQuery, I recommend: Learning jQuery 1.3. It is a great book and walks you through step-by-step to teach you the library.

More Entries

Recent Comments

RSS

Subscribe