Archive

Archive for the ‘Javascript’ Category

Be careful with the ‘local’ scope when migrating from CF8 to CF9

February 8th, 2010 Dan Skaggs 9 comments

One of the really nice “fixes” included in ColdFusion 9 from a developer’s perspective is the inclusion of an implicit “local” variable scope into which variables created within the body of a <cffunction> tag are placed by default. Previously, developers had to manually add a “var” keyword to variables that should only exist within the confines of the function.

One of the ways of simplifying this that gained some traction among various developers prior to the release of ColdFusion 9 was to “var” a single variable at the top of the function as an empty structure then store any additional variables needed in the function inside it. Many folks, myself included, named this structure “local” so that it would be readily apparent that the values inside were local to that function. This approach worked fine and dandy on ColdFusion 8 and below.
Read more…

Categories: ColdFusion, Javascript

jQuery head-scratcher and lesson learned

February 1st, 2010 Dan Skaggs No comments

As I mentioned in my last post, I’m working on a pet project in my spare time. It uses jQuery in various places including in the site design template that I purchased to use with the site. The template uses jQuery to expand and collapse menu items in the left sidebar to show sub items for that selection. Because of this, jQuery and a javascript file named custom.js was included in the template. After breaking the template apart to work inside my ModelGlue application, I started implementing some other features that used jQuery with their own associated javascript files, one of which was cfUniform.

As soon as I put the cfUniform code into the page, I started getting javascript errors in the console pane of Firebug. The error would state something similar to “$(document) not a function” or “$ not a function”. Now, I’ve not had a ton of experience with jQuery, but I have used several pre-built jQuery plugins in sites before and I had seen errors similar to this. Normally this error is caused by one of two issues. Either a) you’ve forgotten to include the script block to load the jQuery library or b) your code is loading the jQuery library twice.

I was able to use Firebug to verify that I was indeed loading it and loading it only once but couldn’t for the life of me figure out why I was getting an error. Obviously cfUniform wasn’t really at fault (the error pointed to a line in one of the cfUniform javascript files) so I knew it had to be something on my side. I did some searching on the phrase and found some discussions around jQuery’s noConflict() feature that allows you to reference jQuery with a notation other than using the familiar “$”.

After reading for a while, I opened the custom.js file that came with the site template and found the code below:

1
2
3
4
jQuery.noConflict();
jQuery(document).ready(function(){
   //contents snipped
}

Since I’m not using any other javascript libraries in this application that might conflict with using the “$” to access jQuery, I removed the noConflict() line, but that didn’t fix my problem. On a hunch I did a search/replace through the custom.js file replacing “jQuery(” with “$(” so that references to the jQuery library in this file would be accessed with the same syntax as in all the other javascript files. Lo and behold, all my errors in Firebug’s console went away and CFUniform began behaving as expected.

While I don’t understand all the underpinnings of why this worked, I’ll take it as my “lesson for the day” that in the future I need to always make sure that all the various jQuery plugins and code that is used in my applications need to reference the jQuery library with the same syntax.

Categories: Javascript, ModelGlue, jQuery

Free and easy way to play MP3 files in your web pages

April 26th, 2009 Dan Skaggs 4 comments

One of my current clients recently commissioned me to write a feature for their site that allows visitors to listen to snippets of MP3 tracks that they sell directly from within the product’s “detail” page. In my particular situation, one of the requirements was to use the design commissioned by a separate design firm. In doing some research I found a few different open source methods of accomplishing this. The one that turned out to be the best fit for our situation was an Adobe Flash-based application called NiftyPlayer.

NiftyPlayer is a free, open source Flash file that you can embed into your page and play MP3 files without worrying about what audio player is installed on the visitor’s machine. The best part for my situation is that the player is completely controllable through Javascript. That means that I could completely “hide” the UI provided by the Flash file by setting the height and width of the Flash object to zero and use custom javascript methods to craft my page to do exactly what I wanted it to do.
Read more…

Categories: Flash, Javascript