Darryl Lyons’ Blog

AJAX, ColdFusion and Web technology…

Entries Comments



Month: June, 2006

Internet Explorer 7 Beta 3 released

30 June, 2006 (06:26) | Uncategorized | By: Darryl Lyons

Microsoft released IE7 Beta 3 yesterday. The new beta contains the following enhancements:

  • Reordering of tabs
  • Improved user interface icons
  • New image magnifying tool
  • Email icon back on the toolbar (via customise dialog)
  • Update all RSS feeds on-demand, as well as mark all as read.

The reordering of tabs has of course been in Firefox for some time, but it is interesting that this feature has come about in IE7 because of feedback from beta users. Another one of the small but worthy improvements is the changes to image zooming. I think Max Stevens puts it best:

IE6 featured auto scaling of large images to fit the browser window, and it had this weird button that would show up over the top of the image after some indeterminate amount of time. It felt a little odd to use, and was somewhat unpredictable. In IE7, thanks to Michael, we’ve replaced this with a simple magnification cursor. Now, you can click to zoom the image to full size, and the image will be centered on where you clicked.

This is the last beta for IE7, with Release Candidates to follow. It looks as though Microsoft are scheduling a release for the second half of the year.

Google Checkout released

29 June, 2006 (21:03) | Google | By: Darryl Lyons

Google have released their online payment service Google Checkout. Google are pushing three main areas:

Stop creating multiple accounts and passwords.
With Google Checkoutâ„¢ you can quickly and easily buy from stores across the web and track all your orders and shipping in one place.

Shop with confidence.
Our fraud protection policy covers you against unauthorized purchases made through Google Checkout, and we don’t share your purchase history or full credit card number with sellers.

Control commercial spam.
You can keep your email address confidential, and easily turn off unwanted emails from stores where you use Google Checkout.

As expected, Google have integrated the service into AdWords. This means that merchants who support Google Checkout are shown with a green shopping trolley next to their URL in advertising. Google are also adding incentives for those who pay for advertising with Google. That certainly is a major point-of-difference with Paypal.

Process sales for free.
For every $1 you spend on AdWords, you can process $10 in sales for free. For sales that exceed this amount or if you don’t use AdWords, you can process them at a low 2% and $0.20 per transaction.

The previously reported free period during beta was obviously untrue. For people who do not spend money on AdWords, the fees are 2% and $0.20 USD per transaction. That certainly beats Paypal’s fees of 2.9% and $0.30 USD per transaction.

There are already a number of well-known online stores using Google Checkout.

AJAX (On-Demand JavaScript) with ToScript()

24 June, 2006 (22:54) | AJAX, ColdFusion, JavaScript | By: Darryl Lyons

I recently discovered the neat little method toScript() had been added to ColdFusion 7.0. I immediately thought that this would have to be quicker at serialising ColdFusion variables into their JavaScript equivilent than any existing JSON serialisers.

It also occurred to me that ToScript() could be used as an alternative data delivery mechanism to XML or JSON for "AJAX-enabled" web applications.

Using ToScript() for AJAX

The easiest way to use ToScript() in an "AJAX" sense is to use the On-Demand JavaScript pattern.

I've posted about the On-Demand JavaScript pattern before, so I thought I would re-use that same code, but improve it a little so that it is cross-browser (tested in Mozilla 1.5.x, IE6) compatible, and a little less verbose.

There are a number of parts to this example:

  1. index.html: Contains an empty table, ready to populate, and the trigger to call the JavaScript.
  2. getData.cfm: Serialises a query as a JavaScript array of objects (structs).
  3. getData.js: Creates a SCRIPT tag on the fly that points to the getData.cfm template as its SRC.

You can also download this example.

index.html

This code simply includes the getData.js JavaScript file, and defines an empty table, awaiting population. I've put a link above the table to trigger the population based upon data returned from ColdFusion.

HTML:
  1. <title>AJAX with ToScript()</title>
  2.  
  3. <script src="getData.js"></script>
  4. *
  5. {
  6.         font-family: sans-serif;
  7.         font-size: 10pt;
  8. }
  9.  
  10. caption
  11. {
  12.         background-color: #333333;
  13.         font-weight: bold;
  14.         text-align: left;
  15.         color: white;
  16.                
  17. }
  18.  
  19. thead tr
  20. {
  21.         background-color: #CCCCCC;
  22.         font-weight: bold;
  23.         text-align: left;
  24.                
  25. }
  26.  
  27. tr
  28. {
  29.         background-color: whitesmoke;
  30. }
  31.  
  32. td, caption
  33. {
  34.         padding: 4px;
  35. }
  36. </style>
  37. </head>
  38.  
  39.  
  40. <a href="javascript:getArtists()">Call getArtists() method</a>
  41.  
  42. <br/><br/>
  43. <table id="artistTable">
  44.         <caption>Artists</caption>
  45.         <thead>
  46.                 <tr>
  47.                         <td>ID</td>
  48.                         <td>Last Name</td>
  49.                         <td>First Name</td>
  50.                         <td>City</td>
  51.                 </tr>
  52.         </thead>
  53.         <tbody>
  54.         </tbody>
  55. </table>
  56.  
  57. </body>
  58.  
  59. </html>

getData.js

The getDataFromServer(id, url, callback) method dynamically creates a SCRIPT tag., where the source is set to a combination of the url and callback arguments. When the SCRIPT tag has loaded, whatever inside it is evaluated, including the specified callback method reference. The callback is placed there by getData.cfm.

The getArtists() method simply calls getDataFromServer with specified parameters. Notice that the callback is set to populateArtists.

The populateArtists(data) method is called when the SCRIPT tag has finished loading. getData.cfm contains the qArtists JavaScript variable, and a call to populateArtists, with qArtists being passed as a parameter. The table on the page is then populated.

JavaScript:
  1. function getDataFromServer(id, url, callback)
  2. {
  3.         var oScript = document.getElementById(id);
  4.         var head = document.getElementsByTagName("head").item(0);
  5.        
  6.         if (oScript)
  7.         {
  8.                 // Destory object
  9.                 head.removeChild(oScript);
  10.         }
  11.        
  12.         // Create object
  13.         oScript = document.createElement("script");
  14.        
  15.         var dtRf = new Date();
  16.  
  17.         oScript.setAttribute("src",url + "?callback=" + callback + "&rf=" +dtRf.getTime());
  18.         oScript.setAttribute("id",id);
  19.  
  20.         head.appendChild(oScript);
  21.  
  22. }
  23.  
  24. function getArtists()
  25. {
  26.         getDataFromServer("artistData","getData.cfm","populateArtists");
  27. }
  28.  
  29. function populateArtists(data)
  30. {
  31.         var oTBody = document.getElementById("artistTable").tBodies[0];
  32.  
  33.         // Loop over the data in the JS array, and add to table
  34.         for (var i=0; i <data.length; i++)
  35.         {
  36.                 // Create a new TR element
  37.                 var oTR = document.createElement("TR");
  38.                 oTBody.appendChild(oTR);
  39.  
  40.                 // Create a call for each element in struct
  41.                 var oTD = document.createElement("TD");
  42.                 oTD.innerHTML = data[i].artistid;
  43.                 oTR.appendChild(oTD);
  44.  
  45.                 var oTD = document.createElement("TD");
  46.                 oTD.innerHTML = data[i].lastname;
  47.                 oTR.appendChild(oTD);
  48.                                
  49.                 var oTD = document.createElement("TD");
  50.                 oTD.innerHTML = data[i].firstname;
  51.                 oTR.appendChild(oTD);
  52.                
  53.                 var oTD = document.createElement("TD");
  54.                 oTD.innerHTML = data[i].city;   
  55.                 oTR.appendChild(oTD);
  56.                
  57.         }
  58. }

getData.cfm

This ColdFusion code queries the art gallery example database to return all of the artists. It then uses the new ColdFusion built-in function ToScript() to serialise the query into a JavaScript array of objects (structs).

You will also notice that I am placing #url.callback(qArtists)# directly after ToScript(). When this JavaScript is loaded (when the SCRIPT tag is added to the DOM), the JavaScript method specified as url.callback will be called. The method will be passed the the parameter qArtists, which is the JavaScript variable just created by ToScript().

CFM:
  1. <cfsetting enablecfoutputonly="true">
  2.  
  3. <cfquery datasource="cfartgallery" name="qData">
  4. SELECT *
  5. FROM artists
  6. ORDER BY lastname, firstname
  7. </cfquery>
  8.  
  9. <cfoutput>var #toScript(qData, "qArtists", false, true)# #url.callback#(qArtists);</cfoutput>

ToScript() vs. CFJSON

I decided to run a few tests comparing ToScript() to CFJSON. Not surprisingly, ToScript() came out on top. But can the output be used in place of JSON? No, it cannot. The key difference is that JSON is represented as a single statement, whereas ToScript() generates multiple statements. Therefore, you cannot simply run eval() on the ToScript() generated string to create a JavaScript object.

I will be really happy when the boys at Adobe create a ToJSON() method native to ColdFusion...

Drag & Drop sortable lists

23 June, 2006 (23:02) | JavaScript | By: Darryl Lyons

Found this some time ago, and recently a colleague of mine also came across it. This script allows you to decorate normal LI tags so that they become draggable, and also sortable. There is even an example that someone else put together to drag and drop between two lists.

I am going to use this script to allow people to configure the visibility and order of columns on a datagrid. All I have to do is put a checkbox inside the LI for the visibility toggle. Nice.

Apache release Extensible AJAX Platform (XAP)

23 June, 2006 (21:39) | AJAX, Java, JavaScript | By: Darryl Lyons

Apache have released an AJAX framework caled Extensible AJAX Platform (or XAP for short).

XAP is an XML-based declarative framework for building, deploying and maintaining rich, interactive Ajax powered web applications. It aims to reduce the need for scripting and help solve the development and maintenance challenges associated with large scale JavaScript programming.

Not too much content on the site yet. There are a few demonstrations available, along with the source. Will be interesting to see where this heads, given that XML-driven frameworks like Laszlo already exist.

Terry Tate Office Linebacker

20 June, 2006 (21:36) | Distractions | By: Darryl Lyons

A couple of years ago the Terry Tate ads were all the rage on the net. A friend of mine just sent me this again, and it still makes me laugh.

Opera 9 released

20 June, 2006 (20:17) | Browsers | By: Darryl Lyons

Opera 9Opera have released version 9.0 of their browser.

The new version has features such as:

  • Integrated BitTorrent
  • Add your favorite search engines
  • Site preferences
  • Improved rich text editing
  • Content blocker
  • Thumbnail (tab) preview
  • Widgets

The widgets feature has me interested.

Opera Widgets are small web applications run directly on a user’s desktop. With Opera Widgets you can quickly write small, focused applications that perform useful tasks. They can interact with online services such as news feeds, dictionaries or search engines.

Widgets look like a pretty cool idea to me. Haven't looked to much into their desktop integration, but it does appear as though you can use permanent storage other than cookies. Interesting all the same.

Liquid Armor

19 June, 2006 (06:23) | Distractions | By: Darryl Lyons

Researchers have figured out a way of creating "liquid armor". This from ScienCentral:

The liquid - called shear thickening fluid is actually a mixture of hard nanoparticles and nonevaporating liquid. It flows normally under low-energy conditions, but when agitated or hit with an impact it stiffens and behaves like a solid. This temporary stiffening occurs less than a millisecond after impact, and is caused by the nanoparticles forming tiny clusters inside the fluid.

Of course has its primary applications in the military, but certainly could be used in all sorts of protective clothing. ScienCentral has a video demonstrating the amazing stuff.

SkylineGlobe takes aim at Google Earth

19 June, 2006 (05:58) | Mapping | By: Darryl Lyons

SkylineGlobe looks like it is a serious contender to challenge Google Earth's dominance of the 3D mapping space. Originally developed for millitary applications, the software is going to be made publically available. The coolest feature has got to be the live video feeds that can be integrated into the maps. CNET has also got some video from the Where 2.0 conference.

Only the stupid fall for phishing?

18 June, 2006 (09:53) | Phishing | By: Darryl Lyons

At least I used to think so. The old phishing attacks we used to get were pretty easy to spot. The spelling was bad and the presentation was aweful. However, the perpetrators have been getting more sophisticated, and employing sneakier methods.

Take this email I just received. It warns me that my Commonwealth Bank account is about to expire. Now, I'm not a Commonwealth Bank customer, but a lot of Australians are. I would be surprised if some of those customers didn't fall for this one. The email looks geniune enough.

Phishing Email

If I follow the link, the Web site itself actually looks exactly the same as the Internet banking login page (minus a few minor differences) for the bank.

Phishing Web site

I wonder how many of their customers will fall for this one? I think a few will, and that's all they are banking on.