/[drupal]/contributions/modules/thickbox/thickbox.js
ViewVC logotype

Contents of /contributions/modules/thickbox/thickbox.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


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

  ViewVC Help
Powered by ViewVC 1.1.2