1// $Id: thickbox.js,v 1.8.2.19 2010/03/09 07:10:48 frjo Exp $ 2 3/* 4 * Thickbox 3.1 - One Box To Rule Them All. 5 * By Cody Lindley (http://www.codylindley.com) 6 * Copyright (c) 2007 cody lindley 7 * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php 8*/ 9 10 11// Initialize Thickbox. 12Drupal.behaviors.initThickbox = function (context) { 13 $('a,area,input', context).filter('.thickbox:not(.initThickbox-processed)').addClass('initThickbox-processed').click(function() { 14 var t = this.title || this.name || null; 15 var a = this.href || this.alt; 16 var g = this.rel || false; 17 tb_show(t,a,g); 18 this.blur(); 19 return false; 20 }); 21}; 22 23function tb_show(caption, url, imageGroup) { //function called when the user clicks on a thickbox link 24 25 var settings = Drupal.settings.thickbox; 26 tb_setBrowserExtra(); 27 28 try { 29 if (typeof document.body.style.maxHeight === 'undefined') { //if IE 6 30 $('body','html').css({height: '100%', width: '100%'}); 31 $('html').css('overflow','hidden'); 32 if (document.getElementById('TB_HideSelect') === null) { //iframe to hide select elements in ie6 33 $('body').append('<iframe id="TB_HideSelect"></iframe><div id="TB_overlay"></div><div id="TB_window"></div>'); 34 $('#TB_overlay').click(tb_remove); 35 } 36 } 37 else { //all others 38 if (document.getElementById('TB_overlay') === null) { 39 $('body').append('<div id="TB_overlay"></div><div id="TB_window"></div>'); 40 $('#TB_overlay').click(tb_remove); 41 } 42 } 43 44 if ($.browserextra.macfirefox) { 45 $('#TB_overlay').addClass('TB_overlayMacFFBGHack'); //use png overlay so hide flash 46 } 47 else { 48 $('#TB_overlay').addClass('TB_overlayBG'); //use background and opacity 49 } 50 51 if (caption === null) { 52 caption = ''; 53 } 54 $('body').append('<div id="TB_load"></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 } 61 else { 62 baseURL = url; 63 } 64 65 var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/; 66 var urlType = baseURL.toLowerCase().match(urlString); 67 68 if (urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' || urlType == '.gif' || urlType == '.bmp') { //code to show images 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="#">' + settings.next + '</a></span>'; 86 } 87 else { 88 TB_PrevCaption = TB_TempArray[TB_Counter].title; 89 TB_PrevURL = TB_TempArray[TB_Counter].href; 90 TB_PrevHTML = '<span id="TB_prev"> <a href="#">' + settings.prev + '</a></span>'; 91 } 92 } 93 else { 94 TB_FoundURL = true; 95 if (TB_TempArray.length > 1) { // Don't show "Image 1 of 1". 96 TB_imageCount = settings.image_count.replace(/\!current/, (TB_Counter + 1)).replace(/\!total/, TB_TempArray.length); 97 } 98 } 99 } 100 } 101 102 // Modified to preload previous and next image. 103 imgPreloader = new Image(); 104 prevImg = new Image(); 105 nextImg = new Image(); 106 imgPreloader.onload = function() { 107 imgPreloader.onload = null; 108 109 var TB_Links = $('a[class*="thickbox"]'); 110 var i = -1; 111 TB_Links.each(function(n) { if (this.href == imgPreloader.src) { i = n; } }); 112 if (i != -1) { 113 if (i > 0) { prevImg.src = TB_Links[i - 1].href; } 114 if (i + 1 < TB_Links.length) { nextImg.src = TB_Links[i + 1].href; } 115 } 116 117 // Resizing large images - orginal by Christian Montoya edited by me. 118 var pagesize = tb_getPageSize(); 119 var x = pagesize[0] - 100; 120 var y = pagesize[1] - 100; 121 var imageWidth = imgPreloader.width; 122 var imageHeight = imgPreloader.height; 123 if (imageWidth > x) { 124 imageHeight = imageHeight * (x / imageWidth); 125 imageWidth = x; 126 if (imageHeight > y) { 127 imageWidth = imageWidth * (y / imageHeight); 128 imageHeight = y; 129 } 130 } 131 else if (imageHeight > y) { 132 imageWidth = imageWidth * (y / imageHeight); 133 imageHeight = y; 134 if (imageWidth > x) { 135 imageHeight = imageHeight * (x / imageWidth); 136 imageWidth = x; 137 } 138 } 139 // End Resizing 140 141 TB_WIDTH = imageWidth < 320 ? 350 : imageWidth + 30; 142 TB_HEIGHT = imageHeight + 60; 143 $('#TB_window').append('<a href="" id="TB_ImageOff" title="' + settings.next_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="' + settings.close + '">' + settings.close + '</a> ' + settings.esc_key + '</div>'); 144 $('#TB_closeWindowButton').click(tb_remove); 145 146 if (!(TB_PrevHTML === '')) { 147 function goPrev() { 148 if ($(document).unbind('click',goPrev)) {$(document).unbind('click',goPrev);} 149 $('#TB_window').remove(); 150 $('body').append('<div id="TB_window"></div>'); 151 tb_show(TB_PrevCaption, TB_PrevURL, imageGroup); 152 return false;
153 } 154 $('#TB_prev').click(goPrev); 155 } 156 157 if (!(TB_NextHTML === '')) { 158 function goNext() { 159 $('#TB_window').remove(); 160 $('body').append('<div id="TB_window"></div>'); 161 tb_show(TB_NextCaption, TB_NextURL, imageGroup); 162 return false; 163 } 164 $('#TB_next').click(goNext); 165 $('#TB_ImageOff').click(goNext); 166 } 167 else { 168 $('#TB_ImageOff').click(tb_remove); 169 } 170 171 document.onkeydown = function(e) { 172 if (e == null) { // ie 173 keycode = event.keyCode; 174 escapeKey = 27; 175 } 176 else if ($.browser.safari || $.browser.opera) { // safari or opera 177 keycode = e.which; 178 escapeKey = 27; 179 } 180 else { // mozilla 181 keycode = e.keyCode; 182 escapeKey = e.DOM_VK_ESCAPE; 183 } 184 key = String.fromCharCode(keycode).toLowerCase(); 185 if (key == 'x' || key == 'c' || keycode == escapeKey) { // close 186 tb_remove(); 187 } 188 else if (key == 'n' || keycode == 39) { // display previous image 189 if (!(TB_NextHTML == '')) { 190 document.onkeydown = ''; 191 goNext(); 192 } 193 } 194 else if (key == 'p' || keycode == 37) { // display next image 195 if (!(TB_PrevHTML == '')) { 196 document.onkeydown = ''; 197 goPrev(); 198 } 199 } 200 }; 201 202 tb_position(); 203 $('#TB_load').remove(); 204 $('#TB_window').css({display:'block', opacity: 0}).animate({opacity: 1}, 400); //for safari using css instead of show 205 }; 206 207 imgPreloader.src = url; 208 } 209 else { //code to show html 210 211 var queryString = url.replace(/^[^\?]+\??/,''); 212 var params = tb_parseQuery( queryString ); 213 214 TB_WIDTH = (params['width']*1) + 30 || 630; //defaults to 630 if no paramaters were added to URL 215 TB_HEIGHT = (params['height']*1) + 40 || 440; //defaults to 440 if no paramaters were added to URL 216 ajaxContentW = TB_WIDTH - 30; 217 ajaxContentH = TB_HEIGHT - 45; 218 219 if (url.indexOf('TB_iframe') != -1) { // either iframe or ajax window 220 urlNoQuery = url.split('TB_'); 221 $('#TB_iframeContent').remove(); 222 if (params['modal'] != 'true') { //iframe no modal 223 $('#TB_window').append('<div id="TB_title"><div id="TB_ajaxWindowTitle">' + caption + '</div><div id="TB_closeAjaxWindow"><a href="#" id="TB_closeWindowButton" title="' + settings.close + '">' + settings.close + '</a> ' + settings.esc_key + '</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>'); 224 } 225 else { //iframe modal 226 $('#TB_overlay').unbind(); 227 $('#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>'); 228 } 229 } 230 else { // not an iframe, ajax 231 if ($('#TB_window').css('display') != 'block') { 232 if (params['modal'] != 'true') { //ajax no modal 233 $('#TB_window').append('<div id="TB_title"><div id="TB_ajaxWindowTitle">' + caption + '</div><div id="TB_closeAjaxWindow"><a href="#" id="TB_closeWindowButton" title="' + settings.close + '">' + settings.close + '</a> ' + settings.esc_key + '</div></div><div id="TB_ajaxContent" style="width:' + ajaxContentW + 'px;height:' + ajaxContentH + 'px"></div>'); 234 window.setTimeout("tb_focusFirstFormElement()", 1000); 235 } 236 else { //ajax modal 237 $('#TB_overlay').unbind(); 238 $('#TB_window').append('<div id="TB_ajaxContent" class="TB_modal" style="width:' + ajaxContentW + 'px;height:' + ajaxContentH + 'px;"></div>'); 239 } 240 } 241 else { //this means the window is already up, we are just loading new content via ajax 242 $('#TB_ajaxContent')[0].style.width = ajaxContentW + 'px'; 243 $('#TB_ajaxContent')[0].style.height = ajaxContentH + 'px'; 244 $('#TB_ajaxContent')[0].scrollTop = 0; 245 $('#TB_ajaxWindowTitle').html(caption); 246 } 247 } 248 249 $('#TB_closeWindowButton').click(tb_remove); 250 251 if (url.indexOf('TB_inline') != -1) { 252 $('#TB_ajaxContent').append($('#' + params['inlineId']).children()); 253 $('#TB_window').unload(function () { 254 $('#' + params['inlineId']).append($('#TB_ajaxContent').children()); // move elements back when you're finished 255 }); 256 tb_position(); 257 $('#TB_load').remove(); 258 $('#TB_window').css({display:'block', opacity: 0}).animate({opacity: 1}, 400); 259 } 260 else if (url.indexOf('TB_iframe') != -1) { 261 tb_position(); 262 if ($.browser.safari || $.browserextra.iphone) { //safari needs help because it will not fire iframe onload 263 $('#TB_load').remove(); 264 $('#TB_window').css({display:'block', opacity: 0}).animate({opacity: 1}, 400); 265 } 266 } 267 else { 268 $('#TB_ajaxContent').load(url += '&random=' + (new Date().getTime()),function() { //to do a post change this load method 269 tb_position(); 270 $('#TB_load').remove(); 271 Drupal.attachBehaviors('#TB_ajaxContent'); 272 $('#TB_window').css({display:'block', opacity: 0}).animate({opacity: 1}, 400); 273 }); 274 } 275 } 276 277 if (!params['modal']) { 278 document.onkeyup = function(e) { 279 if (e == null) { // ie 280 keycode = event.keyCode; 281 escapeKey = 27; 282 } 283 else if ($.browser.safari || $.browser.opera) { // safari or opera 284 keycode = e.which; 285 escapeKey = 27; 286 } 287 else { // mozilla 288 keycode = e.keyCode; 289 escapeKey = e.DOM_VK_ESCAPE; 290 } 291 key = String.fromCharCode(keycode).toLowerCase(); 292 if (keycode == escapeKey) { // close 293 tb_remove(); 294 } 295 }; 296 } 297 298 }
299 catch(e) { 300 //nothing here 301 } 302} 303 304//helper functions below 305function tb_showIframe() { 306 $('#TB_load').remove(); 307 $('#TB_window').css({display:'block', opacity: 0}).animate({opacity: 1}, 400); 308} 309 310function tb_remove() { 311 $('#TB_imageOff').unbind('click'); 312 $('#TB_overlay').unbind('click'); 313 $('#TB_closeWindowButton').unbind('click'); 314 $('#TB_window').fadeOut(400,function() {$('#TB_window,#TB_overlay,#TB_HideSelect').trigger('unload').unbind().remove();}); 315 $('#TB_load').remove(); 316 if (typeof document.body.style.maxHeight == 'undefined') { //if IE 6 317 $('body','html').css({height: 'auto', width: 'auto'}); 318 $('html').css('overflow',''); 319 } 320 document.onkeydown = ''; 321 document.onkeyup = ''; 322 return false; 323} 324 325function tb_position() { 326 $('#TB_window').css({marginLeft: '-' + parseInt((TB_WIDTH / 2),10) + 'px', width: TB_WIDTH + 'px'}); 327 if (!($.browserextra.msie6)) { // take away IE6 328 $('#TB_window').css({marginTop: '-' + parseInt((TB_HEIGHT / 2),10) + 'px'}); 329 } 330} 331 332function tb_parseQuery( query ) { 333 var Params = {}; 334 if ( ! query ) {return Params;}// return empty object 335 var Pairs = query.split(/[;&]/); 336 for ( var i = 0; i < Pairs.length; i++ ) { 337 var KeyVal = Pairs[i].split('='); 338 if ( ! KeyVal || KeyVal.length != 2 ) {continue;} 339 var key = unescape( KeyVal[0] ); 340 var val = unescape( KeyVal[1] ); 341 val = val.replace(/\+/g, ' '); 342 Params[key] = val; 343 } 344 return Params; 345} 346 347function tb_getPageSize() { 348 var de = document.documentElement; 349 var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth; 350 var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight; 351 arrayPageSize = [w,h]; 352 return arrayPageSize; 353} 354 355function tb_setBrowserExtra() { 356 // Return if already set. 357 if ($.browserextra) { 358 return; 359 } 360 361 // Add iPhone, IE 6 and Mac Firefox browser detection. 362 // msie6 fixes the fact that IE 7 now reports itself as MSIE 6.0 compatible 363 var userAgent = navigator.userAgent.toLowerCase(); 364 $.browserextra = { 365 iphone: /iphone/.test( userAgent ), 366 msie6: /msie/.test( userAgent ) && !/opera/.test( userAgent ) && /msie 6\.0/.test( userAgent ) && !/msie 7\.0/.test( userAgent ) && !/msie 8\.0/.test( userAgent ), 367 macfirefox: /mac/.test( userAgent ) && /firefox/.test( userAgent ) 368 }; 369} 370 371function tb_focusFirstFormElement() { 372 $('#TB_window form input[type=text]:first').focus(); 373}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.