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