raw
mp-wp_genesis           1 /*
mp-wp_genesis 2 * Thickbox 3.1 - One Box To Rule Them All.
mp-wp_genesis 3 * By Cody Lindley (http://www.codylindley.com)
mp-wp_genesis 4 * Copyright (c) 2007 cody lindley
mp-wp_genesis 5 * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
mp-wp_genesis 6 */
mp-wp_genesis 7
mp-wp_genesis 8 var tb_pathToImage = "../wp-includes/js/thickbox/loadingAnimation.gif";
mp-wp_genesis 9 var tb_closeImage = "../wp-includes/js/thickbox/tb-close.png";
mp-wp_genesis 10
mp-wp_genesis 11 /*!!!!!!!!!!!!!!!!! edit below this line at your own risk !!!!!!!!!!!!!!!!!!!!!!!*/
mp-wp_genesis 12
mp-wp_genesis 13 //on page load call tb_init
mp-wp_genesis 14 jQuery(document).ready(function(){
mp-wp_genesis 15 tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
mp-wp_genesis 16 imgLoader = new Image();// preload image
mp-wp_genesis 17 imgLoader.src = tb_pathToImage;
mp-wp_genesis 18 });
mp-wp_genesis 19
mp-wp_genesis 20 //add thickbox to href & area elements that have a class of .thickbox
mp-wp_genesis 21 function tb_init(domChunk){
mp-wp_genesis 22 jQuery(domChunk).click(function(){
mp-wp_genesis 23 var t = this.title || this.name || null;
mp-wp_genesis 24 var a = this.href || this.alt;
mp-wp_genesis 25 var g = this.rel || false;
mp-wp_genesis 26 tb_show(t,a,g);
mp-wp_genesis 27 this.blur();
mp-wp_genesis 28 return false;
mp-wp_genesis 29 });
mp-wp_genesis 30 }
mp-wp_genesis 31
mp-wp_genesis 32 function tb_show(caption, url, imageGroup) {//function called when the user clicks on a thickbox link
mp-wp_genesis 33
mp-wp_genesis 34 try {
mp-wp_genesis 35 if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
mp-wp_genesis 36 jQuery("body","html").css({height: "100%", width: "100%"});
mp-wp_genesis 37 jQuery("html").css("overflow","hidden");
mp-wp_genesis 38 if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
mp-wp_genesis 39 jQuery("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
mp-wp_genesis 40 jQuery("#TB_overlay").click(tb_remove);
mp-wp_genesis 41 }
mp-wp_genesis 42 }else{//all others
mp-wp_genesis 43 if(document.getElementById("TB_overlay") === null){
mp-wp_genesis 44 jQuery("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
mp-wp_genesis 45 jQuery("#TB_overlay").click(tb_remove);
mp-wp_genesis 46 }
mp-wp_genesis 47 }
mp-wp_genesis 48
mp-wp_genesis 49 if(tb_detectMacXFF()){
mp-wp_genesis 50 jQuery("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
mp-wp_genesis 51 }else{
mp-wp_genesis 52 jQuery("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
mp-wp_genesis 53 }
mp-wp_genesis 54
mp-wp_genesis 55 if(caption===null){caption="";}
mp-wp_genesis 56 jQuery("body").append("<div id='TB_load'><img src='"+imgLoader.src+"' /></div>");//add loader to the page
mp-wp_genesis 57 jQuery('#TB_load').show();//show loader
mp-wp_genesis 58
mp-wp_genesis 59 var baseURL;
mp-wp_genesis 60 if(url.indexOf("?")!==-1){ //ff there is a query string involved
mp-wp_genesis 61 baseURL = url.substr(0, url.indexOf("?"));
mp-wp_genesis 62 }else{
mp-wp_genesis 63 baseURL = url;
mp-wp_genesis 64 }
mp-wp_genesis 65
mp-wp_genesis 66 var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/;
mp-wp_genesis 67 var urlType = baseURL.toLowerCase().match(urlString);
mp-wp_genesis 68
mp-wp_genesis 69 if(urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' || urlType == '.gif' || urlType == '.bmp'){//code to show images
mp-wp_genesis 70
mp-wp_genesis 71 TB_PrevCaption = "";
mp-wp_genesis 72 TB_PrevURL = "";
mp-wp_genesis 73 TB_PrevHTML = "";
mp-wp_genesis 74 TB_NextCaption = "";
mp-wp_genesis 75 TB_NextURL = "";
mp-wp_genesis 76 TB_NextHTML = "";
mp-wp_genesis 77 TB_imageCount = "";
mp-wp_genesis 78 TB_FoundURL = false;
mp-wp_genesis 79 if(imageGroup){
mp-wp_genesis 80 TB_TempArray = jQuery("a[@rel="+imageGroup+"]").get();
mp-wp_genesis 81 for (TB_Counter = 0; ((TB_Counter < TB_TempArray.length) && (TB_NextHTML === "")); TB_Counter++) {
mp-wp_genesis 82 var urlTypeTemp = TB_TempArray[TB_Counter].href.toLowerCase().match(urlString);
mp-wp_genesis 83 if (!(TB_TempArray[TB_Counter].href == url)) {
mp-wp_genesis 84 if (TB_FoundURL) {
mp-wp_genesis 85 TB_NextCaption = TB_TempArray[TB_Counter].title;
mp-wp_genesis 86 TB_NextURL = TB_TempArray[TB_Counter].href;
mp-wp_genesis 87 TB_NextHTML = "<span id='TB_next'>&nbsp;&nbsp;<a href='#'>Next &gt;</a></span>";
mp-wp_genesis 88 } else {
mp-wp_genesis 89 TB_PrevCaption = TB_TempArray[TB_Counter].title;
mp-wp_genesis 90 TB_PrevURL = TB_TempArray[TB_Counter].href;
mp-wp_genesis 91 TB_PrevHTML = "<span id='TB_prev'>&nbsp;&nbsp;<a href='#'>&lt; Prev</a></span>";
mp-wp_genesis 92 }
mp-wp_genesis 93 } else {
mp-wp_genesis 94 TB_FoundURL = true;
mp-wp_genesis 95 TB_imageCount = "Image " + (TB_Counter + 1) +" of "+ (TB_TempArray.length);
mp-wp_genesis 96 }
mp-wp_genesis 97 }
mp-wp_genesis 98 }
mp-wp_genesis 99
mp-wp_genesis 100 imgPreloader = new Image();
mp-wp_genesis 101 imgPreloader.onload = function(){
mp-wp_genesis 102 imgPreloader.onload = null;
mp-wp_genesis 103
mp-wp_genesis 104 // Resizing large images - orginal by Christian Montoya edited by me.
mp-wp_genesis 105 var pagesize = tb_getPageSize();
mp-wp_genesis 106 var x = pagesize[0] - 150;
mp-wp_genesis 107 var y = pagesize[1] - 150;
mp-wp_genesis 108 var imageWidth = imgPreloader.width;
mp-wp_genesis 109 var imageHeight = imgPreloader.height;
mp-wp_genesis 110 if (imageWidth > x) {
mp-wp_genesis 111 imageHeight = imageHeight * (x / imageWidth);
mp-wp_genesis 112 imageWidth = x;
mp-wp_genesis 113 if (imageHeight > y) {
mp-wp_genesis 114 imageWidth = imageWidth * (y / imageHeight);
mp-wp_genesis 115 imageHeight = y;
mp-wp_genesis 116 }
mp-wp_genesis 117 } else if (imageHeight > y) {
mp-wp_genesis 118 imageWidth = imageWidth * (y / imageHeight);
mp-wp_genesis 119 imageHeight = y;
mp-wp_genesis 120 if (imageWidth > x) {
mp-wp_genesis 121 imageHeight = imageHeight * (x / imageWidth);
mp-wp_genesis 122 imageWidth = x;
mp-wp_genesis 123 }
mp-wp_genesis 124 }
mp-wp_genesis 125 // End Resizing
mp-wp_genesis 126
mp-wp_genesis 127 TB_WIDTH = imageWidth + 30;
mp-wp_genesis 128 TB_HEIGHT = imageHeight + 60;
mp-wp_genesis 129 jQuery("#TB_window").append("<a href='' id='TB_ImageOff' title='Close'><img id='TB_Image' src='"+url+"' width='"+imageWidth+"' height='"+imageHeight+"' alt='"+caption+"'/></a>" + "<div id='TB_caption'>"+caption+"<div id='TB_secondLine'>" + TB_imageCount + TB_PrevHTML + TB_NextHTML + "</div></div><div id='TB_closeWindow'><a href='#' id='TB_closeWindowButton' title='Close'><img src='" + tb_closeImage + "' /></a></div>");
mp-wp_genesis 130
mp-wp_genesis 131 jQuery("#TB_closeWindowButton").click(tb_remove);
mp-wp_genesis 132
mp-wp_genesis 133 if (!(TB_PrevHTML === "")) {
mp-wp_genesis 134 function goPrev(){
mp-wp_genesis 135 if(jQuery(document).unbind("click",goPrev)){jQuery(document).unbind("click",goPrev);}
mp-wp_genesis 136 jQuery("#TB_window").remove();
mp-wp_genesis 137 jQuery("body").append("<div id='TB_window'></div>");
mp-wp_genesis 138 tb_show(TB_PrevCaption, TB_PrevURL, imageGroup);
mp-wp_genesis 139 return false;
mp-wp_genesis 140 }
mp-wp_genesis 141 jQuery("#TB_prev").click(goPrev);
mp-wp_genesis 142 }
mp-wp_genesis 143
mp-wp_genesis 144 if (!(TB_NextHTML === "")) {
mp-wp_genesis 145 function goNext(){
mp-wp_genesis 146 jQuery("#TB_window").remove();
mp-wp_genesis 147 jQuery("body").append("<div id='TB_window'></div>");
mp-wp_genesis 148 tb_show(TB_NextCaption, TB_NextURL, imageGroup);
mp-wp_genesis 149 return false;
mp-wp_genesis 150 }
mp-wp_genesis 151 jQuery("#TB_next").click(goNext);
mp-wp_genesis 152
mp-wp_genesis 153 }
mp-wp_genesis 154
mp-wp_genesis 155 document.onkeydown = function(e){
mp-wp_genesis 156 if (e == null) { // ie
mp-wp_genesis 157 keycode = event.keyCode;
mp-wp_genesis 158 } else { // mozilla
mp-wp_genesis 159 keycode = e.which;
mp-wp_genesis 160 }
mp-wp_genesis 161 if(keycode == 27){ // close
mp-wp_genesis 162 tb_remove();
mp-wp_genesis 163 } else if(keycode == 190){ // display previous image
mp-wp_genesis 164 if(!(TB_NextHTML == "")){
mp-wp_genesis 165 document.onkeydown = "";
mp-wp_genesis 166 goNext();
mp-wp_genesis 167 }
mp-wp_genesis 168 } else if(keycode == 188){ // display next image
mp-wp_genesis 169 if(!(TB_PrevHTML == "")){
mp-wp_genesis 170 document.onkeydown = "";
mp-wp_genesis 171 goPrev();
mp-wp_genesis 172 }
mp-wp_genesis 173 }
mp-wp_genesis 174 };
mp-wp_genesis 175
mp-wp_genesis 176 tb_position();
mp-wp_genesis 177 jQuery("#TB_load").remove();
mp-wp_genesis 178 jQuery("#TB_ImageOff").click(tb_remove);
mp-wp_genesis 179 jQuery("#TB_window").css({display:"block"}); //for safari using css instead of show
mp-wp_genesis 180 };
mp-wp_genesis 181
mp-wp_genesis 182 imgPreloader.src = url;
mp-wp_genesis 183 }else{//code to show html
mp-wp_genesis 184
mp-wp_genesis 185 var queryString = url.replace(/^[^\?]+\??/,'');
mp-wp_genesis 186 var params = tb_parseQuery( queryString );
mp-wp_genesis 187
mp-wp_genesis 188 TB_WIDTH = (params['width']*1) + 30 || 630; //defaults to 630 if no paramaters were added to URL
mp-wp_genesis 189 TB_HEIGHT = (params['height']*1) + 40 || 440; //defaults to 440 if no paramaters were added to URL
mp-wp_genesis 190 ajaxContentW = TB_WIDTH - 30;
mp-wp_genesis 191 ajaxContentH = TB_HEIGHT - 45;
mp-wp_genesis 192
mp-wp_genesis 193 if(url.indexOf('TB_iframe') != -1){// either iframe or ajax window
mp-wp_genesis 194 urlNoQuery = url.split('TB_');
mp-wp_genesis 195 jQuery("#TB_iframeContent").remove();
mp-wp_genesis 196 if(params['modal'] != "true"){//iframe no modal
mp-wp_genesis 197 jQuery("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton' title='Close'><img src='" + tb_closeImage + "' /></a></div></div><iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='tb_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;' > </iframe>");
mp-wp_genesis 198 }else{//iframe modal
mp-wp_genesis 199 jQuery("#TB_overlay").unbind();
mp-wp_genesis 200 jQuery("#TB_window").append("<iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='tb_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;'> </iframe>");
mp-wp_genesis 201 }
mp-wp_genesis 202 }else{// not an iframe, ajax
mp-wp_genesis 203 if(jQuery("#TB_window").css("display") != "block"){
mp-wp_genesis 204 if(params['modal'] != "true"){//ajax no modal
mp-wp_genesis 205 jQuery("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton'><img src='" + tb_closeImage + "' /></a></div></div><div id='TB_ajaxContent' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px'></div>");
mp-wp_genesis 206 }else{//ajax modal
mp-wp_genesis 207 jQuery("#TB_overlay").unbind();
mp-wp_genesis 208 jQuery("#TB_window").append("<div id='TB_ajaxContent' class='TB_modal' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;'></div>");
mp-wp_genesis 209 }
mp-wp_genesis 210 }else{//this means the window is already up, we are just loading new content via ajax
mp-wp_genesis 211 jQuery("#TB_ajaxContent")[0].style.width = ajaxContentW +"px";
mp-wp_genesis 212 jQuery("#TB_ajaxContent")[0].style.height = ajaxContentH +"px";
mp-wp_genesis 213 jQuery("#TB_ajaxContent")[0].scrollTop = 0;
mp-wp_genesis 214 jQuery("#TB_ajaxWindowTitle").html(caption);
mp-wp_genesis 215 }
mp-wp_genesis 216 }
mp-wp_genesis 217
mp-wp_genesis 218 jQuery("#TB_closeWindowButton").click(tb_remove);
mp-wp_genesis 219
mp-wp_genesis 220 if(url.indexOf('TB_inline') != -1){
mp-wp_genesis 221 jQuery("#TB_ajaxContent").append(jQuery('#' + params['inlineId']).children());
mp-wp_genesis 222 jQuery("#TB_window").unload(function () {
mp-wp_genesis 223 jQuery('#' + params['inlineId']).append( jQuery("#TB_ajaxContent").children() ); // move elements back when you're finished
mp-wp_genesis 224 });
mp-wp_genesis 225 tb_position();
mp-wp_genesis 226 jQuery("#TB_load").remove();
mp-wp_genesis 227 jQuery("#TB_window").css({display:"block"});
mp-wp_genesis 228 }else if(url.indexOf('TB_iframe') != -1){
mp-wp_genesis 229 tb_position();
mp-wp_genesis 230 if($.browser.safari){//safari needs help because it will not fire iframe onload
mp-wp_genesis 231 jQuery("#TB_load").remove();
mp-wp_genesis 232 jQuery("#TB_window").css({display:"block"});
mp-wp_genesis 233 }
mp-wp_genesis 234 }else{
mp-wp_genesis 235 jQuery("#TB_ajaxContent").load(url += "&random=" + (new Date().getTime()),function(){//to do a post change this load method
mp-wp_genesis 236 tb_position();
mp-wp_genesis 237 jQuery("#TB_load").remove();
mp-wp_genesis 238 tb_init("#TB_ajaxContent a.thickbox");
mp-wp_genesis 239 jQuery("#TB_window").css({display:"block"});
mp-wp_genesis 240 });
mp-wp_genesis 241 }
mp-wp_genesis 242
mp-wp_genesis 243 }
mp-wp_genesis 244
mp-wp_genesis 245 if(!params['modal']){
mp-wp_genesis 246 document.onkeyup = function(e){
mp-wp_genesis 247 if (e == null) { // ie
mp-wp_genesis 248 keycode = event.keyCode;
mp-wp_genesis 249 } else { // mozilla
mp-wp_genesis 250 keycode = e.which;
mp-wp_genesis 251 }
mp-wp_genesis 252 if(keycode == 27){ // close
mp-wp_genesis 253 tb_remove();
mp-wp_genesis 254 }
mp-wp_genesis 255 };
mp-wp_genesis 256 }
mp-wp_genesis 257
mp-wp_genesis 258 } catch(e) {
mp-wp_genesis 259 //nothing here
mp-wp_genesis 260 }
mp-wp_genesis 261 }
mp-wp_genesis 262
mp-wp_genesis 263 //helper functions below
mp-wp_genesis 264 function tb_showIframe(){
mp-wp_genesis 265 jQuery("#TB_load").remove();
mp-wp_genesis 266 jQuery("#TB_window").css({display:"block"});
mp-wp_genesis 267 }
mp-wp_genesis 268
mp-wp_genesis 269 function tb_remove() {
mp-wp_genesis 270 jQuery("#TB_imageOff").unbind("click");
mp-wp_genesis 271 jQuery("#TB_closeWindowButton").unbind("click");
mp-wp_genesis 272 jQuery("#TB_window").fadeOut("fast",function(){jQuery('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
mp-wp_genesis 273 jQuery("#TB_load").remove();
mp-wp_genesis 274 if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
mp-wp_genesis 275 jQuery("body","html").css({height: "auto", width: "auto"});
mp-wp_genesis 276 jQuery("html").css("overflow","");
mp-wp_genesis 277 }
mp-wp_genesis 278 document.onkeydown = "";
mp-wp_genesis 279 document.onkeyup = "";
mp-wp_genesis 280 return false;
mp-wp_genesis 281 }
mp-wp_genesis 282
mp-wp_genesis 283 function tb_position() {
mp-wp_genesis 284 jQuery("#TB_window").css({marginLeft: '-' + parseInt((TB_WIDTH / 2),10) + 'px', width: TB_WIDTH + 'px'});
mp-wp_genesis 285 if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6
mp-wp_genesis 286 jQuery("#TB_window").css({marginTop: '-' + parseInt((TB_HEIGHT / 2),10) + 'px'});
mp-wp_genesis 287 }
mp-wp_genesis 288 }
mp-wp_genesis 289
mp-wp_genesis 290 function tb_parseQuery ( query ) {
mp-wp_genesis 291 var Params = {};
mp-wp_genesis 292 if ( ! query ) {return Params;}// return empty object
mp-wp_genesis 293 var Pairs = query.split(/[;&]/);
mp-wp_genesis 294 for ( var i = 0; i < Pairs.length; i++ ) {
mp-wp_genesis 295 var KeyVal = Pairs[i].split('=');
mp-wp_genesis 296 if ( ! KeyVal || KeyVal.length != 2 ) {continue;}
mp-wp_genesis 297 var key = unescape( KeyVal[0] );
mp-wp_genesis 298 var val = unescape( KeyVal[1] );
mp-wp_genesis 299 val = val.replace(/\+/g, ' ');
mp-wp_genesis 300 Params[key] = val;
mp-wp_genesis 301 }
mp-wp_genesis 302 return Params;
mp-wp_genesis 303 }
mp-wp_genesis 304
mp-wp_genesis 305 function tb_getPageSize(){
mp-wp_genesis 306 var de = document.documentElement;
mp-wp_genesis 307 var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
mp-wp_genesis 308 var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
mp-wp_genesis 309 arrayPageSize = [w,h];
mp-wp_genesis 310 return arrayPageSize;
mp-wp_genesis 311 }
mp-wp_genesis 312
mp-wp_genesis 313 function tb_detectMacXFF() {
mp-wp_genesis 314 var userAgent = navigator.userAgent.toLowerCase();
mp-wp_genesis 315 if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
mp-wp_genesis 316 return true;
mp-wp_genesis 317 }
mp-wp_genesis 318 }
mp-wp_genesis 319
mp-wp_genesis 320