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