{"id":980,"date":"2009-04-13T11:49:49","date_gmt":"2009-04-13T17:49:49","guid":{"rendered":"http:\/\/www.cyberward.net\/blog\/?p=980"},"modified":"2009-04-20T09:49:30","modified_gmt":"2009-04-20T15:49:30","slug":"how-to-use-thickbox","status":"publish","type":"post","link":"https:\/\/www.cyberward.net\/blog\/2009\/04\/how-to-use-thickbox\/","title":{"rendered":"How to use Thickbox"},"content":{"rendered":"<p>I have had a lot of hits on my <a href=\"http:\/\/www.cyberward.net\/blog\/2009\/02\/how-to-use-lytebox\/\">How to use Lytebox<\/a> post, and I thought I might continue it as a series and do something on another of the light box clones. It also looks like lytebox\u00ac\u2020has been discontinued by the author. I have started to use <a href=\"http:\/\/jquery.com\/demo\/thickbox\/\">Thickbox<\/a>.\u00ac\u2020Why you ask? It uses <a href=\"http:\/\/jquery.com\/\">jQuery<\/a>, and I am starting to really like that library. One of the things that drew me to lytebox was that it had no dependencies. But now, more sites require javascript anyway, and my library of choice is jQuery. So, if I am using jQuery, why not the Thickbox plugin?<\/p>\n<p>If you are not sure about this library, check out <a href=\"http:\/\/planetozh.com\/projects\/lightbox-clones\/\">this matrix<\/a> that lists just about every light box type javascript library around.<\/p>\n<p><!--more--><\/p>\n<h3>Setting up\u00ac\u2020Thickbox<\/h3>\n<p>The <a href=\"http:\/\/jquery.com\/demo\/thickbox\/\">thickbox site<\/a> has great examples too. It is not hard to set up. Head over to the Thickbox site and grab the files. What you need to get are the thickbox.js file, the thickbox.css file, the loadingAnimation.gif, and the macFFBgHack.png. More on the images in a minute.<\/p>\n<p>Don&#8217;t forget, this is a plugin, or aditional library that builds on jQuery, so you will need to <a href=\"http:\/\/docs.jquery.com\/Downloading_jQuery\">download\u00ac\u2020jQuery<\/a> too. You will only need one file: jQuery.js. For these\u00ac\u2020examples I am not using the compressed versions, but you could. Both jQuery and Thickbox offer compressed versions of their javascript libraries. They might be worth using in a production environment, but I will use the fully spaced files here.<\/p>\n<p>Ok, first up, I like to have a bit of structure to my web sites. I like to have js, css,\u00ac\u2020images, and pictures folders. You don&#8217;t have to, but this is what I do. I put my javascript into the js folder. I put style sheets into css, icons and graphics for the site into images, and photographs into the pictures folder. So for this example, that is where\u00ac\u2020I put the files.\u00ac\u2020<\/p>\n<pre>\/examples\/thickbox\/js\/jquery.js\r\n                 \/js\/thickbox.js\r\n                 \/css\/thickbox.js\r\n                 \/images\/loadingAnimation.gif\r\n                 \/images\/macFFBgHack.png<\/pre>\n<h3>A few little tweaks<\/h3>\n<p>If you put all of the files into \/examples\/thickbox\/, and not into the structure like we have, you wouldn&#8217;t need to do this step, but if you did, we need to edit a couple of thickbox files to let them know what we did.<\/p>\n<p>You can edit files in any number of ways. If you are on a web server running linux, you might want to try nano. It is pretty easy to use, and gives you some ctrl key combinations at the bottom for thigs like saving and searching.<\/p>\n<p>To edit the index html file in nano type:<\/p>\n<pre>nano -w index.html<\/pre>\n<p>You can move around using the cursor keys, and the terminal will scroll for you. When you want to exit and save, press ctrl-x.<\/p>\n<p>First is the \/js\/thickbox.js file. We need to modify were the loading animation is located. Change that line to:<\/p>\n<pre>var tb_pathToImage = \"images\/loadingAnimation.gif\";<\/pre>\n<p>This line is inserted into generated html, so the path is relative to the html page created.<\/p>\n<p>Then we need to look at the \/css\/thickbox.cc file. We need to navigate down through that file and find the .TB_overlayMacFFBGHack class. Change that to:<\/p>\n<pre>.TB_overlayMacFFBGHack {background: url(..\/images\/macFFBgHack.png) repeat;}<\/pre>\n<p>What are these files for? The loading animation is a little bar that shows up inbetween when you click on the image, and the larger one is ready. The overlay image is to help firefox on Mac&#8217;s provide the screen dimming over flash.<\/p>\n<h3>Including our files.<\/h3>\n<p>To get our files &#8216;included&#8217; into a html document, we need to put some lines into the head of the document, like this:<\/p>\n<pre lang=\"html\"><script src=\"js\/jquery.js\" type=\"text\/javascript\"><!--mce:0--><\/script>\r\n<script src=\"js\/thickbox.js\" type=\"text\/javascript\"><!--mce:1--><\/script><\/pre>\n<p>That&#8217;s all there is to it. The two script tags insert the javascript, and the link tag inserts the stylesheet.<\/p>\n<h3>Apply the effect<\/h3>\n<p>Thickbox uses the jQuery library. This means that it is all about selectors. That usually means that we use css class names in our javascript to identify elements on a page. Thickbox uses the &#8220;thickbox&#8221; class to identify what images to apply this effect to.<\/p>\n<p>Here is a line of html that displays a thumbnail, and when you click on it, it takes you to a different page and displays it full screen.<\/p>\n<pre lang=\"html\"><a title=\"Montana Cabin\" href=\"pictures\/Montana Cabin.jpg\">\r\n<img decoding=\"async\" src=\"pictures\/Montana Cabin thumb.jpg\" alt=\"\" \/><\/a><\/pre>\n<p>Here is a line of html that displays a thumbnail, and when you click on it, it uses the thickbox javascript to display the light box type effect.<\/p>\n<pre lang=\"html\"><a class=\"thickbox\" title=\"Montana Cabin\" href=\"pictures\/Montana Cabin.jpg\"><img decoding=\"async\" src=\"pictures\/Montana Cabin thumb.jpg\" alt=\"\" \/><\/a><\/pre>\n<p>Not much different is there? The only difference is the class=&#8221;thickbox&#8221;. I think that is pretty cool. How about linking several images together so that you can use next and previous buttons to link them? You just need to add a rel=&#8221;xxx&#8221; where xxx is the name of the gallery. As long as this text is the same for each image you want linked together, it can be anything.<\/p>\n<pre lang=\"html\"><a class=\"thickbox\" title=\"Montana Cabin\" rel=\"gallery2\" href=\"pictures\/Montana Cabin.jpg\"><img decoding=\"async\" src=\"pictures\/Montana Cabin thumb.jpg\" alt=\"\" \/><\/a>\r\n<a class=\"thickbox\" title=\"Montana Road\" rel=\"gallery2\" href=\"pictures\/Montana Road.jpg\"><img decoding=\"async\" src=\"pictures\/Montana Road thumb.jpg\" alt=\"\" \/><\/a><\/pre>\n<h3>The full example<\/h3>\n<p>What I show now is a full example of using this to create a gallery. A very simple one. Not going to win any style awards, but it will do. There are 3 versions of the index.html file here. One <a href=\"http:\/\/www.cyberward.net\/examples\/thickbox\/index.html\">without the thickbox<\/a> effect at all (index.html), one <a href=\"http:\/\/www.cyberward.net\/examples\/thickbox\/index2.html\">with the thickbox<\/a> effect (index2.html), and one with <a href=\"http:\/\/www.cyberward.net\/examples\/thickbox\/index3.html\">thickbox using gallerys<\/a>\u00ac\u2020(index3.html). To make this work I have also added another css file: \/css\/gallery.css.<\/p>\n<pre lang=\"html\">\r\n\r\n  <script src=\"js\/jquery.js\" type=\"text\/javascript\"><!--mce:2--><\/script>\r\n  <script src=\"js\/thickbox.js\" type=\"text\/javascript\"><!--mce:3--><\/script>\r\n<h1>Thickbox Example Gallery<\/h1>\r\n<h3>\r\n    <a href=\"index.html\">No Thickbox<\/a>\r\n    <a href=\"index2.html\">Using Thickbox<\/a>\r\n    <span>Thickbox with Galleries<\/span><\/h3>\r\n<a class=\"thickbox\" title=\"Erie Night\" rel=\"gallery1\" href=\"pictures\/Erie Night.jpg\"><img decoding=\"async\" src=\"pictures\/Erie Night thumb.jpg\" alt=\"\" \/><\/a>\r\n  <a class=\"thickbox\" title=\"Field of Grass\" rel=\"gallery1\" href=\"pictures\/Field of Grass.jpg\"><img decoding=\"async\" src=\"pictures\/Field of Grass thumb.jpg\" alt=\"\" \/><\/a>\r\n  <a class=\"thickbox\" title=\"Gentle Evening\" rel=\"gallery1\" href=\"pictures\/Gentle Evening.jpg\"><img decoding=\"async\" src=\"pictures\/Gentle Evening thumb.jpg\" alt=\"\" \/><\/a>\r\n  <a class=\"thickbox\" title=\"Reflected Cloud\" rel=\"gallery1\" href=\"pictures\/Reflected Cloud.jpg\"><img decoding=\"async\" src=\"pictures\/Reflected Cloud thumb.jpg\" alt=\"\" \/><\/a>\r\n\r\n  <a class=\"thickbox\" title=\"Montana Cabin\" rel=\"gallery2\" href=\"pictures\/Montana Cabin.jpg\"><img decoding=\"async\" src=\"pictures\/Montana Cabin thumb.jpg\" alt=\"\" \/><\/a>\r\n  <a class=\"thickbox\" title=\"Montana Road\" rel=\"gallery2\" href=\"pictures\/Montana Road.jpg\"><img decoding=\"async\" src=\"pictures\/Montana Road thumb.jpg\" alt=\"\" \/><\/a>\r\n  <a class=\"thickbox\" title=\"Montana Sunset\" rel=\"gallery2\" href=\"pictures\/Montana Sunset.jpg\"><img decoding=\"async\" src=\"pictures\/Montana Sunset thumb.jpg\" alt=\"\" \/><\/a>\r\n  <a class=\"thickbox\" title=\"Spoon and Cherry\" rel=\"gallery2\" href=\"pictures\/Spoon and Cherry.jpg\"><img decoding=\"async\" src=\"pictures\/Spoon and Cherry thumb.jpg\" alt=\"\" \/><\/a>\r\n<h3><a href=\"http:\/\/www.cyberward.net\/blog\/2009\/04\/how-to-use-thickbox\/\">Cyberward blog post on Thickbox<\/a><\/h3>\r\n<\/pre>\n<pre lang=\"css\">body {\r\n        background-color: black;\r\n        text-align: center;\r\n        margin:10px;\r\n}\r\nh1, h3, h3 a, span {\r\n        color: white;\r\n        font-family: sans-serif;\r\n        margin:10px;\r\n}\r\nimg {\r\n        border: solid 1px gray;\r\n}\r\nimg:hover {\r\n        border: solid 1px white;\r\n        \/* doesn't work in ie *\/\r\n}\r\na img {\r\n        text-decoration: none;\r\n}<\/pre>\n<p>There you have it. A pretty simple gallery. Fell free to copy it. You will just need to download the files from jQuery and Thickbox, and get your own images. Have fun.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have had a lot of hits on my How to use Lytebox post, and I thought I might continue it as a series and do something on another of the light box clones. It also looks like lytebox\u00ac\u2020has been &hellip; <a href=\"https:\/\/www.cyberward.net\/blog\/2009\/04\/how-to-use-thickbox\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[101,103],"tags":[108,16,115,167,168,166],"series":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pffAy-fO","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/posts\/980"}],"collection":[{"href":"https:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/comments?post=980"}],"version-history":[{"count":0,"href":"https:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/posts\/980\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/media?parent=980"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/categories?post=980"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/tags?post=980"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/www.cyberward.net\/blog\/wp-json\/wp\/v2\/series?post=980"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}