ThickBox 3.1-mf

developed by Cody Lindley and then modified by Matt Farmer, using jQuery, last updated on 02/17/2009
ThickBox is a webpage UI dialog widget written in JavaScript on top of the jQuery library. Its function is to show a single image, multiple images, inline content, iframed content, or content served through AJAX in a hybrid modal.

What's been changed? And why another 'lightbox'?

 

I've always prefered the looks of lightbox2 over Thickbox 3.1, but am usually using jquery over prototype and need some of the additional features of Thickbox (like being able to embed html in the lightbox). So I took it upon myself to edit the css, to move the menu bar from the top to the bottom, borrowed the close image from Lightbox2, and edited the javascript a little bit to support albums of html files.

The Lightbox image was licensed under the Creative Commons Attribution 2.5 License where as Thickbox 3.1 is under the MIT and GPL, so I don't know what that means to your legal experts, but there it is.

Overview-

 

Download thickbox.js , ThickBox.css, the loading graphic (loadingAnimation.gif), the close button (close.gif), and the Mac Background Hack (macFFBgHack.png) to your local machine (or cut and paste the code from the tabs). Along with these three files, a copy of the jQuery JavaScript library is needed. For this site, and ThickBox, I am using the compressed version of jQuery.

Loading...
Loading...
Right Click and Download:

Loading Animation Image

 

How to Implement ThickBox:

Before you can implement ThickBox make sure the page that invokes ThickBox has a valid DTD. This is required for ThickBox to look and function correctly.

1. ThickBox requires the jQuery JavaScript library; because of this, you will need to include the jquery.js file in the head element of your web page, followed by the thickbox.js file (NOTE: jquery.js must come first in the source order). Example below:

<script type="text/javascript" src="path-to-file/jquery.js"></script>
<script type="text/javascript" src="path-to-file/thickbox.js"></script>

Once you have included the .js files, open thickbox.js and locate the tb_pathToImage and tb_pathToCloseImage variables at the top of the page. Once you have found it, make sure to change the values of tb_pathToImage and tb_pathToCloseImage to the paths where the loadingAnimation.gif and close.gif files are located on your own server.

2. Include the ThickBox CSS file in your web page. As of version 3.1-mf you will also need to update the path to the macFFBgHack.png in the thickbox.css file. Example options below:

<link rel="stylesheet" href="path-to-file/thickbox.css" type="text/css" media="screen" />

Or

<style type="text/css" media="all">@import "path-to-file/thickbox.css";</style>

Or, open the thickbox.css file and copy and paste the styles into an existing style sheet. Be aware that the ThickBox CSS file will remove the browsers default padding and margin for all elements.

3. View the examples to learn the many different ways to use and invoke ThickBox functionality.

Supported & Tested Browsers

Windows IE 6.0, Windows IE 7+, Windows FF 2.0.0.6+, Windows Opera 9.0+, Macintosh Safari 2.0.4+, Macintosh FF 2.0.0.6+, Macintosh Opera 9.10+

MIT License/GNU License

http://www.opensource.org/licenses/mit-license.php

http://www.gnu.org/licenses/gpl.html

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so.

Change Log

As of 08/01/2007

  • Added modal functionality to ThickBox iframes
  • Fixed Flash transparency issue with Firefox on OSX
  • Updated to jQuery 1.1.3.1
  • Changed how inline content is handled in Thickbox. Instead of duplicating the inline content thickbox will now move it accordingly inside of the DOM
  • Safari iframe source issue solved

As of 05/02/2007

  • If sizes are not set for width and/or height (inline, iframe, and ajax content), ThickBox will default to a width of 630px and a height of 440px
  • iframe hack to hide &select" elements now only runs in IE 6
  • Scrollbars are removed in IE 6 when a ThickBox is opened (to counter IE 6's errant width and height calculations)
  • Cleaned code using JSLint
  • A new compressed thickbox.js using Packer
  • Updated ThickBox to use jQuery 1.1.2
  • Major updates to JavaScript and CSS to address scrolling and overlay issues
  • Replaced pre-loader image, and Pre-loader image is now being pre-loaded
  • ThickBox now works with image maps ("area" elements) and form buttons ("input" elements), just like links ("a" elements)
  • If you use Ajax content, ThickBox will now open new content in the current ThickBox. That is, after the content is loaded into a ThickBox (via Ajax), it will be parsed for any area, link, or input elements with a class of "thickbox". This will allow you to load new content into the current ThickBox
  • Added the ability to create a real modal window when using inline or Ajax content

As of 1/24/2007

  • Updated ThickBox to work with jQuery release 1.1.1

As of 10/11/2006

  • Updated jQuery code to release 1.0.2

As of 10/09/2006

  • Fixed scrolling issues with FireFox

As of 09/23/2006

  • Updated jQuery code to release 1.0.1
  • The escape key will now close ThickBox
  • Removed the necessity to have an extension to use the iframe content and ajax content (image content still requires an extension)
  • When opening iframe content with ThickBox the window will only appear after the window has loaded its content (This will not work in Safari)
  • Moved the next and previous keyboard functionality for the gallery images to the left < key (previous) and right > key (next). By doing this it fixes a known issue with safari and the arrow keys. This also allows sites design to be scrolled horizontally to use the arrow keys accordingly.
  • ThickBox will now work with sites that scroll horizontally. So, a ThickBox, not matter if you scroll a website horizontally or vertically will always show up centered in the window.

As of 08/07/2006

  • Fixed height issue of transparent iframe to hide select elements in IE

As of 08/03/2006

  • Added greybox functionality (iframed content)
  • Added titles to ThickBox for iframed, inline, and ajax content
  • Added image gallery functions (with keyboard navigation by using the left and right arrow keys)
  • New (separate) CSS file specifically for ThickBox
  • Fixed Firefox caching issue when loading a ThickBox image for the first time
  • Cleaned up and optimized the thickbox.js file
  • Add the new file extension .bmp for ThickBox images
  • Removed set height on ThickBox so two lines of caption will stretch the window vertically

As of 07/06/2006

  • Added the ability to use inline div elements to populate a ThickBox
  • Added the ability to use uppercase and lowercase extensions
  • Loading animation centers on the screen regardless of vertical scroll
  • In IE, select boxes are now hidden when ThickBox is open
  • Fixed a bug that occurs when no title is used on anchor elements
  • Fixed overlay so that it covers the screen during the loading animation (occurred in FF and Opera)
  • Uses the new jQuery 1.0 – Alpha Release
back to top

Examples-

 
Description:

This is the simplest example of ThickBox functionality. This example places a single image in a ThickBox (see demo tab).

Instructions:
  • Create a link element (<a href>)
  • Give the link a class attribute with a value of thickbox (class="thickbox")
  • Provide a path in the href attribute to an image file (.jpg .jpeg .png .gif .bmp)
Click On The Image:

Image 2

<a href="images/single.jpg" title="add a caption to title attribute / or leave blank" class="thickbox"><img src="images/single_t.jpg" alt="Single Image"/></a>
Description:

This example is exactly like the single image functionality except that it allows use of the rel attribute to group images together so they can be navigated in a ThickBox. The ideal usage would be for images galleries.

Instructions:
  • Create a link element (<a href>)
  • Give the link a class attribute with a value of "thickbox" (class="thickbox")
  • Provide a path in the href attribute to an image file (.jpg .jpeg .png .gif .bmp)
  • Give each link element the same rel element and value. (Example: rel="gallery-plants")
Important to Remember:

While you have a ThickBox gallery image open, you can navigate forward and backward through the images by using the left < key (previous) and right > key (next) on the keyboard (Next and Previous links are also provided in the ThickBox). The images will appear in the gallery from first to last as they appear in the HTML document flow.

Click An Image:

Plant 1   Plant 2   Plant 3   Plant 4

<a href="images/plant1.jpg" title="add a caption to title attribute / or leave blank" class="thickbox" rel="gallery-plants"><img src="images/plant1_t.jpg" alt="Plant 1" /></a> 
<a href="images/plant2.jpg" title="add a caption to title attribute / or leave blank" class="thickbox" rel="gallery-plants"><img src="images/plant2_t.jpg" alt="Plant 2" /></a> 
<a href="images/plant3.jpg" title="add a caption to title attribute / or leave blank" class="thickbox" rel="gallery-plants"><img src="images/plant3_t.jpg" alt="Plant 3" /></a> 
<a href="images/plant4.jpg" title="add a caption to title attribute / or leave blank" class="thickbox" rel="gallery-plants"><img src="images/plant4_t.jpg" alt="Plant 4" /></a>
Description:

Inline content on the page, either hidden or showing, can be placed in a ThickBox.

Instructions:
  • Create a link element (<a href>)
  • Give the link a class attribute with a value of thickbox (class="thickbox")
  • In the href attribute of the link add the following anchor: #TB_inline
  • In the href attribute after the #TB_inline add the following query string on to the anchor:
    ?height=300&width=300&inlineId=myOnPageContent
  • Change the values of height, width, and inlineId in the query accordingly (inlineID is the ID value of the element that contains the content you would like to show in a ThickBox.
  • Optionally you may add modal=true to the query string (e.g. #TB_inline?height=155&width=300&inlineId=hiddenModalContent&modal=true) so that closing a ThickBox will require calling the tb_remove() function from within the ThickBox. See the hidden modal content example, where you must click yes or no to close the ThickBox.
Important to Remember:

If the inline content in the ThickBox contains more content than the ThickBox dimensions will show, a vertical scroll bar will appear so that the content can be scrolled. You can avoid having the scroll by making sure the ThickBox has the appropriate dimensions in order to show all of the inline content without having to scroll. In other words, if you don't want scroll bars, increase the height and width of the ThickBox until the content does not require scrolling.

the paragraph and input below in a ThickBox, or Show hidden modal content.

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.

<input alt="#TB_inline?height=300&width=400&inlineId=myOnPageContent" title="add a caption to title attribute / or leave blank" class="thickbox" type="button" value="Show" />  
<a href="#TB_inline?height=155&width=300&inlineId=hiddenModalContent&modal=true" class="thickbox">Show hidden modal content.</a>
Description:

Opens URL's in an iframe inside of ThickBox. Yes, this is Greybox functionality.

Instructions:
  • Create a link element (<a href>)
  • Give the link a class attribute with a value of thickbox (class="thickbox")
  • In the href attribute of the link provide the URL you would like to display in a ThickBox
  • In the href attribute, after the URL, add the following query on to the end of the URL & any parameters you might add:
    ?KeepThis=true&TB_iframe=true&height=400&width=600
  • Change the values of height and width in the query accordingly
  • Optionally you may add modal=true to the query string (e.g. ?KeepThis=true&TB_iframe=true&height=400&width=600&modal=true) so that closing a ThickBox will require calling the tb_remove() function from within the ThickBox iframe (self.parent.tb_remove()). See the iframe demo for an example, where you must click "ok" to close the ThickBox.
Important to Remember:

Add all other query parameters before the TB_iframe parameters. Everything after the "TB" is removed from the URL.

<a href="ajax.PHP?keepThis=true&TB_iframe=true&height=250&width=400" title="add a caption to title attribute / or leave blank" class="thickbox">Example 1</a>  
<a href="ajaxOverFlow.htm?keepThis=true&TB_iframe=true&height=300&width=500" title="add a caption to title attribute / or leave blank" class="thickbox">Example 2</a>
<a href="iframeModal.html?placeValuesBeforeTB_=savedValues&TB_iframe=true&height=200&width=300&modal=true" title="add a caption to title attribute / or leave blank" class="thickbox">Open iFrame Modal</a>
Description:

This example is exactly like the single iFramed Content except that it allows use of the rel attribute to group the html together so they can be navigated in a ThickBox.

Instructions:
  • Create a link element (<a href>)
  • Give the link a class attribute with a value of thickbox (class="thickbox")
  • Give each link element the same rel element and value. (Example: rel="gallery-plants")
  • In the href attribute of the link provide the URL you would like to display in a ThickBox
  • In the href attribute, after the URL, add the following query on to the end of the URL & any parameters you might add:
    ?KeepThis=true&TB_iframe=true&height=400&width=600
  • Change the values of height and width in the query accordingly
  • Optionally you may add modal=true to the query string (e.g. ?KeepThis=true&TB_iframe=true&height=400&width=600&modal=true) so that closing a ThickBox will require calling the tb_remove() function from within the ThickBox iframe (self.parent.tb_remove()). See the iframe demo for an example, where you must click "ok" to close the ThickBox.
Important to Remember:

Add all other query parameters before the TB_iframe parameters. Everything after the "TB" is removed from the URL.

<a href="ajax.PHP?keepThis=true&TB_iframe=true&height=250&width=400" title="add a caption to title attribute / or leave blank" class="thickbox">Example 1</a>  
<a href="ajaxOverFlow.htm?keepThis=true&TB_iframe=true&height=300&width=500" title="add a caption to title attribute / or leave blank" class="thickbox">Example 2</a>
<a href="iframeModal.html?placeValuesBeforeTB_=savedValues&TB_iframe=true&height=200&width=300&modal=true" title="add a caption to title attribute / or leave blank" class="thickbox">Open iFrame Modal</a>
Description:

Use a hidden HTTP request (AJAX) to fetch files from the same server and have ThickBox display the contents of the files.

Instructions:
  • Create a link element (<a href>)
  • Give the link a class attribute with a value of thickbox (class="thickbox")
  • Provide a path in the href to the file/directory on the server. (href="ajaxLogin.htm")
  • In the href attribute, after the URL path to the file, add the following query on to the end of the URL:
    ?height=300&width=300
  • Change the values of height and width in the query accordingly
  • Optionally you may add modal=true to the query string (e.g. ?height=300&width=300&modal=true) so that closing a ThickBox will require calling the tb_remove() function from within the ThickBox. See the login example, where you must click cancel to close the ThickBox.
Important to Remember:

In order to open new Ajax content in an open Ajax ThickBox, its code must also contain the appropriate HTML (class=""thickbox) to launch an Ajax ThickBox (see demo for example). The only catch is, the ThickBox calls must include both the width and height of the original ThickBox. If you leave it blank the window will resize to the default size(630x440).

<a href="ajaxOverFlow.html?height=300&width=300" title="add a caption to title attribute / or leave blank" class="thickbox">Scrolling content</a>  
<a href="ajax.PHP?height=220&width=400" class="thickbox" title="add a caption to title attribute / or leave blank">No-scroll content</a>  
<a href="ajaxLogin.html?height=85&width=250&modal=true" class="thickbox" title="Please Sign In">login (modal)</a>  
<a href="ajaxTBcontent.html?height=200&width=300" class="thickbox" title="">Update ThickBox content</a>
back to top
 

This site was designed & built by Cody Lindley with jQuery (and then later modified by Matt Farmer, Resolution dependent layout, Accessible, unobtrusive JavaScript tabs with jQuery, JQuery Corner Styler, Interface elements for jQuery, Dan Webb - CodeHighlighter 0.2, Dynamic Code Viewing with jQuery, and plenty of patience. Before you cut and paste any of the JavaScript found on this site, you should know that I altered/optimized the previously mentioned scripts specifically for this site. Also, no images were killed used during the development of this site (except for the images in the examples).