15 April 2011

Create a quasi-random number with Apache SSI

Recently, I had a Flash SWF carousel that was consuming XML data. However, when the admin updated the XML, the SHTML page didn't always pull the latest version. The solution was to attach a random value as a querystring to the XML file:
<param name="FlashVars" 
value="paramXMLPath=param.xml?rv=<!--#echo var="rand" -->">
Note the comment tag; that's actually telling Apache to process the information server side using SSI. In this case, I've defined a variable earlier in code:

This is using the built-in timefmt configuration option, which allows you to define how the date and time will be displayed. I'm telling Apache to display the date and time as year, day of year, day of month, hour, minute, and second, all concatenated together. This provides a unique number each time the page is loaded and can be used as a querystring value. This page provides a great list of configuration options and what the % formatting values are.

Rethinking application development in light of 'devops'


01 April 2011

Create a new window using custom jQuery function

For my current project, I needed to pop up a new window from specific anchor tags on the page. This provided the perfect opportunity to write some custom jQuery to handle this. I started with some research into creating jQuery function; Jeremy Martin's blog post got me started. Next, I got some inspiration from this popup window generator, though I could never get it working for my site.

So the jQuery function looks like this:
* Add a function to jQuery to automate popup windows.
$.fn.popWindow = function(options) {

// Declare some default values.
var defaults = {
width: 729,
height: 529,
left: 19,
top: 19,
location: 0,
directories: 0,
status: 0,
toolbar: 0,
menubar: 0,
resizable: 1,
scrollbars: 1,
url: '',
name: 'cms_win',
center: 0

// Merge the defaults with the options parameter.
var options = $.extend(defaults, options);

// For each of these objects...
return this.each(function(){
// Get a handle to this HTML object.
obj = $(this);

// Set the left and top if we're centering.
if (options.center){
options.left = (screen.width - options.width)/2;
options.top = (screen.height - options.height)/2;

// If user provided a URL, use that; otherwise use the HREF.
var url = (!jQuery(options.url).isEmpty()) ?
options.url : obj.attr("href");

// Concatenate the window.open() function's options.
var features = "width="+options.width+",height="+

// Add an onClick() handler to this object.
// On click, open a new window with these arguments.
return false;

* Add a function to jQuery to check null/undefined/blank
* status of object.
$.fn.isEmpty = function(){
return (typeof $(this) === "undefined" ||
$(this) === null ||
$(this) === "") ? true : false;
Note the helper function isEmpty() which serves to check for null, undefined, or blank variables. The folks on StackOverflow.com helped with that function. To use the popWindow() function, ensure you've included the latest jQuery library on your page; add the above code in a script tag; then set the style class on your anchor tag or add an ID so you can reference the object; finally, call it on your page like this:
// Set all the objects with pop class to open in new window.
center: 1
In this case, I'm also taking advantage of the built-in center functionality to center the new window.