Ok, is it just me, or has JavaScript spoiled me? It seems like almost daily I come across a web page with a long list of image thumbnails. I click on one and the entire page reloads. I click back and get a whole other large page load. I click on another image, and, well, you get the idea. I hate this. I've blogged before about the jQuery Thickbox plugin. It is a great solution to this problem, especially when you team it up with ColdFusion. Here is a great example.
I want to build a page which will make use of the Thickbox plugin, but I don't want to hard code the images. Instead, I'll let ColdFusion scan a folder and create the list for me. Since I'm using ColdFusion 8, I can also use it to create the thumbnails as well. This means I can copy images right off my camera, dump them in a folder, and leave it at that. I like easy. Let's look at the code.2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
5 <title>Untitled Document</title>
6
7 <script type="text/javascript" src="http://www.coldfusionjedi.com/js/jquery.js"></script>
8 <script type="text/javascript" src="http://www.coldfusionjedi.com/js/thickbox/thickbox.js"></script>
9 <link rel="stylesheet" href="http://www.coldfusionjedi.com/js/thickbox/thickbox.css" type="text/css" media="screen" />
10 </head>
11
12 <body>
2 <cfset imageDir = expandPath("./#imageFolder#")>
3 <cfdirectory directory="#imageDir#" name="images">
4
5 <!--- make thumbs --->
6 <cfif not directoryExists("#imageDir#/thumbs")>
7 <cfdirectory action="create" directory="#imageDir#/thumbs">
8 </cfif>
2
3 <!--- valid image? --->
4 <cfif isImageFile("#directory#/#name#")>
5 <!--- check for thumbnail --->
6 <cfif not fileExists("#directory#/thumbs/#name#")>
7 <cfimage action="read" source="#directory#/#name#" name="image">
8 <cfset imageScaleToFit(image, 125, 125)>
9 <cfset imageWrite(image, "#directory#/thumbs/#name#",true)>
10 </cfif>
11
12 <cfoutput>
13 <a href="#imageFolder#/#name#" title="#name#" class="thickbox" rel="gallery-ss"><img src="#imageFolder#/thumbs/#name#" alt="#name#" /></a>
14 </cfoutput>
15 </cfif>
16 </cfloop>
Comment 1 written by Katie Atkinson on 18 February 2009, at 4:43 AM
Comment 2 written by Curt Gratz on 18 February 2009, at 7:23 AM
If you want to use the writetobrowser action and resize each image on the fly you can with your imageUtils. <a href="http://imageutils.riaforge.org/">http://im...; using the getURL() method. Just a thought so you don't have to write all the thumbs to disk. Might be expensive depending on the application.
Comment 3 written by Eric Cobb on 18 February 2009, at 9:00 AM
The only difference is I used Lightbox (http://plugins.jquery.com/project/jquerylightbox_b...) instead of Thickbox. No particular reason why I chose one over the other, I think it was just the first one I found.
Comment 4 written by Raymond Camden on 18 February 2009, at 9:02 AM
As for getURL, that is for converting a URL into an image, ie, taking a screen shot of a web page. It is not for resizing images.
Comment 5 written by Chris on 18 February 2009, at 1:22 PM
Comment 6 written by Raymond Camden on 18 February 2009, at 3:28 PM
Comment 7 written by Chris Luksha on 19 February 2009, at 8:32 AM
So you might do
<cfparam name="url.gogogadgetreset" default="">
<cfswitch expression="url.gogogadgetreset">
<cfcase value="rebuild"> Dump the thumb folder and start over</cfcase>
<cfcase value="refresh">simply refresh the missing thumbs</cfcase>
<cfdefaultcase>do nothing</cfdefaultcase>
</cfswitch>
Just a thought
Chris
Comment 8 written by Marwan Narian on 19 February 2009, at 9:50 AM
Comment 9 written by Raymond Camden on 19 February 2009, at 9:52 AM
Comment 10 written by wade miller on 19 February 2009, at 12:05 PM
That gives me some concerns about using jquery. I guess nothing is perfect. I am just trying to convince others at my company of its benefits, and this didn't help.
Comment 11 written by Raymond Camden on 19 February 2009, at 12:08 PM
Comment 12 written by Bilgehan on 19 February 2009, at 1:12 PM
Comment 13 written by wade miller on 19 February 2009, at 1:15 PM
I know there is something I'm probably missing. I'm just going to go back to CF.
Comment 14 written by Raymond Camden on 19 February 2009, at 1:36 PM
@Wade: Again, my local server was using 1.3.1. Not sure what you mean by saying you will just go back to CF - as this IS CF, CF and JavaScript. :) I wouldn't give up yet. Can you put this online where we can look?
Comment 15 written by Bilgehan on 19 February 2009, at 2:48 PM
Comment 16 written by Raymond Camden on 19 February 2009, at 2:53 PM
Comment 17 written by wade miller on 19 February 2009, at 2:57 PM
http://www.bray.com/tboxtest/index.cfm?test=works
http://www.bray.com/tboxtest/index.cfm?test=fail
What I meant by "back to using CF" I left off and actionscript.
Comment 18 written by Raymond Camden on 19 February 2009, at 3:06 PM
http://www.bray.com/tboxtest/macFFBgHack.png
On the docs for Thickbox, they talk about the fixes you have to do in code for this.
Comment 19 written by wade miller on 19 February 2009, at 3:16 PM
I've been meaning to install Firebug, but I always put it off. Now, I will do it while it is fresh on my mind.
Comment 20 written by Hatem Jaber on 19 February 2009, at 4:25 PM
http://fancy.klade.lv/
Comment 21 written by Raymond Camden on 19 February 2009, at 4:47 PM
Comment 22 written by Raymond Camden on 20 February 2009, at 6:04 AM
Comment 23 written by Marwan Narian on 20 February 2009, at 10:40 AM
Comment 24 written by Raymond Camden on 20 February 2009, at 2:10 PM
Comment 25 written by Marwan Narian on 20 February 2009, at 2:38 PM
<cflayout type="border">
<cflayoutarea name="whatever" position="center">
<script type="text/javascript" src="http://www.coldfusionjedi.com/js/jquery.js"&g...;
<script type="text/javascript" src="http://www.coldfusionjedi.com/js/thickbox/thickbox...;
<link rel="stylesheet" href="http://www.coldfusionjedi.com/js/thickbox/thickbox...; type="text/css" media="screen" />
</head>
<body>
<cfset imageFolder = "folder2">
<cfset imageDir = expandPath("./#imageFolder#")>
<cfdirectory directory="#imageDir#" name="images">
<!--- make thumbs --->
<cfif not directoryExists("#imageDir#/thumbs")>
<cfdirectory action="create" directory="#imageDir#/thumbs">
</cfif>
<cfloop query="images">
<!--- valid image? --->
<cfif isImageFile("#directory#/#name#")>
<!--- check for thumbnail --->
<cfif not fileExists("#directory#/thumbs/#name#")>
<cfimage action="read" source="#directory#/#name#" name="image">
<cfset imageScaleToFit(image, 125, 125)>
<cfset imageWrite(image, "#directory#/thumbs/#name#",true)>
</cfif>
<cfoutput>
<a href="#imageFolder#/#name#" title="#name#" class="thickbox" rel="gallery-ss"><img src="#imageFolder#/thumbs/#name#" alt="#name#" /></a>
</cfoutput>
</cfif>
</cfloop>
</cflayoutarea>
</cflayout>
Comment 26 written by Raymond Camden on 21 February 2009, at 4:01 PM
Comment 27 written by Marwan Narian on 23 February 2009, at 9:13 AM
Comment 28 written by Raymond Camden on 23 February 2009, at 9:17 AM
Comment 29 written by Tiffany Trott on 4 March 2009, at 9:58 AM
Any help would be appreciated!
Comment 30 written by Raymond Camden on 4 March 2009, at 10:04 AM
Comment 31 written by Raymond Camden on 4 March 2009, at 10:09 AM
Comment 32 written by Raymond Camden on 4 March 2009, at 10:11 AM
http://codylindley.com/thickboxforum/comments.php?...
I replace the line mentioned and it worked for me.
Comment 33 written by Tiffany Trott on 4 March 2009, at 10:38 AM
Thanks again Jedi!!!
Comment 34 written by Wade Miller on 4 March 2009, at 5:40 PM
[Add Comment] [Subscribe to Comments]