bgneal@1: /* bgneal@1: * Thickbox 3.1 - One Box To Rule Them All. bgneal@1: * By Cody Lindley (http://www.codylindley.com) bgneal@1: * Copyright (c) 2007 cody lindley bgneal@1: * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php bgneal@1: */ bgneal@1: bgneal@1: var tb_pathToImage = "/media/images/loadingAnimation.gif"; bgneal@1: bgneal@1: /*!!!!!!!!!!!!!!!!! edit below this line at your own risk !!!!!!!!!!!!!!!!!!!!!!!*/ bgneal@1: bgneal@1: //on page load call tb_init bgneal@1: $(document).ready(function(){ bgneal@1: tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox bgneal@1: imgLoader = new Image();// preload image bgneal@1: imgLoader.src = tb_pathToImage; bgneal@1: }); bgneal@1: bgneal@1: //add thickbox to href & area elements that have a class of .thickbox bgneal@1: function tb_init(domChunk){ bgneal@1: $(domChunk).click(function(){ bgneal@1: var t = this.title || this.name || null; bgneal@1: var a = this.href || this.alt; bgneal@1: var g = this.rel || false; bgneal@1: tb_show(t,a,g); bgneal@1: this.blur(); bgneal@1: return false; bgneal@1: }); bgneal@1: } bgneal@1: bgneal@1: function tb_show(caption, url, imageGroup) {//function called when the user clicks on a thickbox link bgneal@1: bgneal@1: try { bgneal@1: if (typeof document.body.style.maxHeight === "undefined") {//if IE 6 bgneal@1: $("body","html").css({height: "100%", width: "100%"}); bgneal@1: $("html").css("overflow","hidden"); bgneal@1: if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6 bgneal@1: $("body").append("
"); bgneal@1: $("#TB_overlay").click(tb_remove); bgneal@1: } bgneal@1: }else{//all others bgneal@1: if(document.getElementById("TB_overlay") === null){ bgneal@1: $("body").append("
"); bgneal@1: $("#TB_overlay").click(tb_remove); bgneal@1: } bgneal@1: } bgneal@1: bgneal@1: if(tb_detectMacXFF()){ bgneal@1: $("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash bgneal@1: }else{ bgneal@1: $("#TB_overlay").addClass("TB_overlayBG");//use background and opacity bgneal@1: } bgneal@1: bgneal@1: if(caption===null){caption="";} bgneal@1: $("body").append("
");//add loader to the page bgneal@1: $('#TB_load').show();//show loader bgneal@1: bgneal@1: var baseURL; bgneal@1: if(url.indexOf("?")!==-1){ //ff there is a query string involved bgneal@1: baseURL = url.substr(0, url.indexOf("?")); bgneal@1: }else{ bgneal@1: baseURL = url; bgneal@1: } bgneal@1: bgneal@1: var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/; bgneal@1: var urlType = baseURL.toLowerCase().match(urlString); bgneal@1: bgneal@1: if(urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' || urlType == '.gif' || urlType == '.bmp'){//code to show images bgneal@1: bgneal@1: TB_PrevCaption = ""; bgneal@1: TB_PrevURL = ""; bgneal@1: TB_PrevHTML = ""; bgneal@1: TB_NextCaption = ""; bgneal@1: TB_NextURL = ""; bgneal@1: TB_NextHTML = ""; bgneal@1: TB_imageCount = ""; bgneal@1: TB_FoundURL = false; bgneal@1: if(imageGroup){ bgneal@1: TB_TempArray = $("a[@rel="+imageGroup+"]").get(); bgneal@1: for (TB_Counter = 0; ((TB_Counter < TB_TempArray.length) && (TB_NextHTML === "")); TB_Counter++) { bgneal@1: var urlTypeTemp = TB_TempArray[TB_Counter].href.toLowerCase().match(urlString); bgneal@1: if (!(TB_TempArray[TB_Counter].href == url)) { bgneal@1: if (TB_FoundURL) { bgneal@1: TB_NextCaption = TB_TempArray[TB_Counter].title; bgneal@1: TB_NextURL = TB_TempArray[TB_Counter].href; bgneal@1: TB_NextHTML = "  Next >"; bgneal@1: } else { bgneal@1: TB_PrevCaption = TB_TempArray[TB_Counter].title; bgneal@1: TB_PrevURL = TB_TempArray[TB_Counter].href; bgneal@1: TB_PrevHTML = "  < Prev"; bgneal@1: } bgneal@1: } else { bgneal@1: TB_FoundURL = true; bgneal@1: TB_imageCount = "Image " + (TB_Counter + 1) +" of "+ (TB_TempArray.length); bgneal@1: } bgneal@1: } bgneal@1: } bgneal@1: bgneal@1: imgPreloader = new Image(); bgneal@1: imgPreloader.onload = function(){ bgneal@1: imgPreloader.onload = null; bgneal@1: bgneal@1: // Resizing large images - orginal by Christian Montoya edited by me. bgneal@1: var pagesize = tb_getPageSize(); bgneal@1: var x = pagesize[0] - 150; bgneal@1: var y = pagesize[1] - 150; bgneal@1: var imageWidth = imgPreloader.width; bgneal@1: var imageHeight = imgPreloader.height; bgneal@1: if (imageWidth > x) { bgneal@1: imageHeight = imageHeight * (x / imageWidth); bgneal@1: imageWidth = x; bgneal@1: if (imageHeight > y) { bgneal@1: imageWidth = imageWidth * (y / imageHeight); bgneal@1: imageHeight = y; bgneal@1: } bgneal@1: } else if (imageHeight > y) { bgneal@1: imageWidth = imageWidth * (y / imageHeight); bgneal@1: imageHeight = y; bgneal@1: if (imageWidth > x) { bgneal@1: imageHeight = imageHeight * (x / imageWidth); bgneal@1: imageWidth = x; bgneal@1: } bgneal@1: } bgneal@1: // End Resizing bgneal@1: bgneal@1: TB_WIDTH = imageWidth + 30; bgneal@1: TB_HEIGHT = imageHeight + 60; bgneal@1: $("#TB_window").append(""+caption+"" + "
"+caption+"
" + TB_imageCount + TB_PrevHTML + TB_NextHTML + "
close or Esc Key
"); bgneal@1: bgneal@1: $("#TB_closeWindowButton").click(tb_remove); bgneal@1: bgneal@1: if (!(TB_PrevHTML === "")) { bgneal@1: function goPrev(){ bgneal@1: if($(document).unbind("click",goPrev)){$(document).unbind("click",goPrev);} bgneal@1: $("#TB_window").remove(); bgneal@1: $("body").append("
"); bgneal@1: tb_show(TB_PrevCaption, TB_PrevURL, imageGroup); bgneal@1: return false; bgneal@1: } bgneal@1: $("#TB_prev").click(goPrev); bgneal@1: } bgneal@1: bgneal@1: if (!(TB_NextHTML === "")) { bgneal@1: function goNext(){ bgneal@1: $("#TB_window").remove(); bgneal@1: $("body").append("
"); bgneal@1: tb_show(TB_NextCaption, TB_NextURL, imageGroup); bgneal@1: return false; bgneal@1: } bgneal@1: $("#TB_next").click(goNext); bgneal@1: bgneal@1: } bgneal@1: bgneal@1: document.onkeydown = function(e){ bgneal@1: if (e == null) { // ie bgneal@1: keycode = event.keyCode; bgneal@1: } else { // mozilla bgneal@1: keycode = e.which; bgneal@1: } bgneal@1: if(keycode == 27){ // close bgneal@1: tb_remove(); bgneal@1: } else if(keycode == 190){ // display previous image bgneal@1: if(!(TB_NextHTML == "")){ bgneal@1: document.onkeydown = ""; bgneal@1: goNext(); bgneal@1: } bgneal@1: } else if(keycode == 188){ // display next image bgneal@1: if(!(TB_PrevHTML == "")){ bgneal@1: document.onkeydown = ""; bgneal@1: goPrev(); bgneal@1: } bgneal@1: } bgneal@1: }; bgneal@1: bgneal@1: tb_position(); bgneal@1: $("#TB_load").remove(); bgneal@1: $("#TB_ImageOff").click(tb_remove); bgneal@1: $("#TB_window").css({display:"block"}); //for safari using css instead of show bgneal@1: }; bgneal@1: bgneal@1: imgPreloader.src = url; bgneal@1: }else{//code to show html bgneal@1: bgneal@1: var queryString = url.replace(/^[^\?]+\??/,''); bgneal@1: var params = tb_parseQuery( queryString ); bgneal@1: bgneal@1: TB_WIDTH = (params['width']*1) + 30 || 630; //defaults to 630 if no paramaters were added to URL bgneal@1: TB_HEIGHT = (params['height']*1) + 40 || 440; //defaults to 440 if no paramaters were added to URL bgneal@1: ajaxContentW = TB_WIDTH - 30; bgneal@1: ajaxContentH = TB_HEIGHT - 45; bgneal@1: bgneal@1: if(url.indexOf('TB_iframe') != -1){// either iframe or ajax window bgneal@1: urlNoQuery = url.split('TB_'); bgneal@1: $("#TB_iframeContent").remove(); bgneal@1: if(params['modal'] != "true"){//iframe no modal bgneal@1: $("#TB_window").append("
"+caption+"
close or Esc Key
"); bgneal@1: }else{//iframe modal bgneal@1: $("#TB_overlay").unbind(); bgneal@1: $("#TB_window").append(""); bgneal@1: } bgneal@1: }else{// not an iframe, ajax bgneal@1: if($("#TB_window").css("display") != "block"){ bgneal@1: if(params['modal'] != "true"){//ajax no modal bgneal@1: $("#TB_window").append("
"+caption+"
close or Esc Key
"); bgneal@1: }else{//ajax modal bgneal@1: $("#TB_overlay").unbind(); bgneal@1: $("#TB_window").append("
"); bgneal@1: } bgneal@1: }else{//this means the window is already up, we are just loading new content via ajax bgneal@1: $("#TB_ajaxContent")[0].style.width = ajaxContentW +"px"; bgneal@1: $("#TB_ajaxContent")[0].style.height = ajaxContentH +"px"; bgneal@1: $("#TB_ajaxContent")[0].scrollTop = 0; bgneal@1: $("#TB_ajaxWindowTitle").html(caption); bgneal@1: } bgneal@1: } bgneal@1: bgneal@1: $("#TB_closeWindowButton").click(tb_remove); bgneal@1: bgneal@1: if(url.indexOf('TB_inline') != -1){ bgneal@1: $("#TB_ajaxContent").append($('#' + params['inlineId']).children()); bgneal@1: $("#TB_window").unload(function () { bgneal@1: $('#' + params['inlineId']).append( $("#TB_ajaxContent").children() ); // move elements back when you're finished bgneal@1: }); bgneal@1: tb_position(); bgneal@1: $("#TB_load").remove(); bgneal@1: $("#TB_window").css({display:"block"}); bgneal@1: }else if(url.indexOf('TB_iframe') != -1){ bgneal@1: tb_position(); bgneal@1: if($.browser.safari){//safari needs help because it will not fire iframe onload bgneal@1: $("#TB_load").remove(); bgneal@1: $("#TB_window").css({display:"block"}); bgneal@1: } bgneal@1: }else{ bgneal@1: $("#TB_ajaxContent").load(url += "&random=" + (new Date().getTime()),function(){//to do a post change this load method bgneal@1: tb_position(); bgneal@1: $("#TB_load").remove(); bgneal@1: tb_init("#TB_ajaxContent a.thickbox"); bgneal@1: $("#TB_window").css({display:"block"}); bgneal@1: }); bgneal@1: } bgneal@1: bgneal@1: } bgneal@1: bgneal@1: if(!params['modal']){ bgneal@1: document.onkeyup = function(e){ bgneal@1: if (e == null) { // ie bgneal@1: keycode = event.keyCode; bgneal@1: } else { // mozilla bgneal@1: keycode = e.which; bgneal@1: } bgneal@1: if(keycode == 27){ // close bgneal@1: tb_remove(); bgneal@1: } bgneal@1: }; bgneal@1: } bgneal@1: bgneal@1: } catch(e) { bgneal@1: //nothing here bgneal@1: } bgneal@1: } bgneal@1: bgneal@1: //helper functions below bgneal@1: function tb_showIframe(){ bgneal@1: $("#TB_load").remove(); bgneal@1: $("#TB_window").css({display:"block"}); bgneal@1: } bgneal@1: bgneal@1: function tb_remove() { bgneal@1: $("#TB_imageOff").unbind("click"); bgneal@1: $("#TB_closeWindowButton").unbind("click"); bgneal@1: $("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();}); bgneal@1: $("#TB_load").remove(); bgneal@1: if (typeof document.body.style.maxHeight == "undefined") {//if IE 6 bgneal@1: $("body","html").css({height: "auto", width: "auto"}); bgneal@1: $("html").css("overflow",""); bgneal@1: } bgneal@1: document.onkeydown = ""; bgneal@1: document.onkeyup = ""; bgneal@1: return false; bgneal@1: } bgneal@1: bgneal@1: function tb_position() { bgneal@1: $("#TB_window").css({marginLeft: '-' + parseInt((TB_WIDTH / 2),10) + 'px', width: TB_WIDTH + 'px'}); bgneal@1: if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6 bgneal@1: $("#TB_window").css({marginTop: '-' + parseInt((TB_HEIGHT / 2),10) + 'px'}); bgneal@1: } bgneal@1: } bgneal@1: bgneal@1: function tb_parseQuery ( query ) { bgneal@1: var Params = {}; bgneal@1: if ( ! query ) {return Params;}// return empty object bgneal@1: var Pairs = query.split(/[;&]/); bgneal@1: for ( var i = 0; i < Pairs.length; i++ ) { bgneal@1: var KeyVal = Pairs[i].split('='); bgneal@1: if ( ! KeyVal || KeyVal.length != 2 ) {continue;} bgneal@1: var key = unescape( KeyVal[0] ); bgneal@1: var val = unescape( KeyVal[1] ); bgneal@1: val = val.replace(/\+/g, ' '); bgneal@1: Params[key] = val; bgneal@1: } bgneal@1: return Params; bgneal@1: } bgneal@1: bgneal@1: function tb_getPageSize(){ bgneal@1: var de = document.documentElement; bgneal@1: var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth; bgneal@1: var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight; bgneal@1: arrayPageSize = [w,h]; bgneal@1: return arrayPageSize; bgneal@1: } bgneal@1: bgneal@1: function tb_detectMacXFF() { bgneal@1: var userAgent = navigator.userAgent.toLowerCase(); bgneal@1: if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) { bgneal@1: return true; bgneal@1: } bgneal@1: } bgneal@1: bgneal@1: