Issues (4542)

config/js/thickbox.js (28 issues)

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
10
/*!!!!!!!!!!!!!!!!! edit below this line at your own risk !!!!!!!!!!!!!!!!!!!!!!!*/
11
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
0 ignored issues
show
The variable imgLoader seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.imgLoader.
Loading history...
16
	imgLoader.src = tb_pathToImage;
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
	try {
34
		if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
35
			$("body","html").css({height: "100%", width: "100%"});
36
			$("html").css("overflow","hidden");
37
			if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
38
				$("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
39
				$("#TB_overlay").click(tb_remove);
40
			}
41
		}else{//all others
42
			if(document.getElementById("TB_overlay") === null){
43
				$("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
44
				$("#TB_overlay").click(tb_remove);
45
			}
46
		}
47
		
48
		if(tb_detectMacXFF()){
49
			$("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
50
		}else{
51
			$("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
52
		}
53
		
54
		if(caption===null){caption="";}
55
		$("body").append("<div id='TB_load'><img src='"+imgLoader.src+"' /></div>");//add loader to the page
56
		$('#TB_load').show();//show loader
57
		
58
		var baseURL;
59
	   if(url.indexOf("?")!==-1){ //ff there is a query string involved
60
			baseURL = url.substr(0, url.indexOf("?"));
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
				
70
			TB_PrevCaption = "";
0 ignored issues
show
The variable TB_PrevCaption seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.TB_PrevCaption.
Loading history...
71
			TB_PrevURL = "";
0 ignored issues
show
The variable TB_PrevURL seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.TB_PrevURL.
Loading history...
72
			TB_PrevHTML = "";
0 ignored issues
show
The variable TB_PrevHTML seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.TB_PrevHTML.
Loading history...
73
			TB_NextCaption = "";
0 ignored issues
show
The variable TB_NextCaption seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.TB_NextCaption.
Loading history...
74
			TB_NextURL = "";
0 ignored issues
show
The variable TB_NextURL seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.TB_NextURL.
Loading history...
75
			TB_NextHTML = "";
0 ignored issues
show
The variable TB_NextHTML seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.TB_NextHTML.
Loading history...
76
			TB_imageCount = "";
0 ignored issues
show
The variable TB_imageCount seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.TB_imageCount.
Loading history...
77
			TB_FoundURL = false;
0 ignored issues
show
The variable TB_FoundURL seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.TB_FoundURL.
Loading history...
78
			if(imageGroup){
79
				TB_TempArray = $("a[@rel="+imageGroup+"]").get();
0 ignored issues
show
The variable TB_TempArray seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.TB_TempArray.
Loading history...
80
				for (TB_Counter = 0; ((TB_Counter < TB_TempArray.length) && (TB_NextHTML === "")); TB_Counter++) {
0 ignored issues
show
The variable TB_Counter seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.TB_Counter.
Loading history...
81
					var urlTypeTemp = TB_TempArray[TB_Counter].href.toLowerCase().match(urlString);
0 ignored issues
show
The variable urlTypeTemp seems to be never used. Consider removing it.
Loading history...
82
						if (!(TB_TempArray[TB_Counter].href == url)) {						
83
							if (TB_FoundURL) {
84
								TB_NextCaption = TB_TempArray[TB_Counter].title;
85
								TB_NextURL = TB_TempArray[TB_Counter].href;
86
								TB_NextHTML = "<span id='TB_next'>&nbsp;&nbsp;<a href='#'>Next &gt;</a></span>";
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'>&nbsp;&nbsp;<a href='#'>&lt; Prev</a></span>";
91
							}
92
						} else {
93
							TB_FoundURL = true;
94
							TB_imageCount = "Image " + (TB_Counter + 1) +" of "+ (TB_TempArray.length);											
95
						}
96
				}
97
			}
98
99
			imgPreloader = new Image();
0 ignored issues
show
The variable imgPreloader seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.imgPreloader.
Loading history...
100
			imgPreloader.onload = function(){		
101
			imgPreloader.onload = null;
102
				
103
			// Resizing large images - orginal by Christian Montoya edited by me.
104
			var pagesize = tb_getPageSize();
105
			var x = pagesize[0] - 150;
106
			var y = pagesize[1] - 150;
107
			var imageWidth = imgPreloader.width;
108
			var imageHeight = imgPreloader.height;
109
			if (imageWidth > x) {
110
				imageHeight = imageHeight * (x / imageWidth); 
111
				imageWidth = x; 
112
				if (imageHeight > y) { 
113
					imageWidth = imageWidth * (y / imageHeight); 
114
					imageHeight = y; 
115
				}
116
			} else if (imageHeight > y) { 
117
				imageWidth = imageWidth * (y / imageHeight); 
118
				imageHeight = y; 
119
				if (imageWidth > x) { 
120
					imageHeight = imageHeight * (x / imageWidth); 
121
					imageWidth = x;
122
				}
123
			}
124
			// End Resizing
125
			
126
			TB_WIDTH = imageWidth + 30;
0 ignored issues
show
The variable TB_WIDTH seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.TB_WIDTH.
Loading history...
127
			TB_HEIGHT = imageHeight + 60;
0 ignored issues
show
The variable TB_HEIGHT seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.TB_HEIGHT.
Loading history...
128
			$("#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'><span style='font-size:18px;padding:5px;'><i class='fa fa-close'></i></span></a></div>"); 		
129
			
130
			$("#TB_closeWindowButton").click(tb_remove);
131
			
132
			if (!(TB_PrevHTML === "")) {
133
				function goPrev(){
0 ignored issues
show
The function goPrev is declared conditionally. This is not supported by all runtimes. Consider moving it to root scope or using var goPrev = function() { /* ... */ }; instead.
Loading history...
134
					if($(document).unbind("click",goPrev)){$(document).unbind("click",goPrev);}
135
					$("#TB_window").remove();
136
					$("body").append("<div id='TB_window'></div>");
137
					tb_show(TB_PrevCaption, TB_PrevURL, imageGroup);
138
					return false;	
139
				}
140
				$("#TB_prev").click(goPrev);
141
			}
142
			
143
			if (!(TB_NextHTML === "")) {		
144
				function goNext(){
0 ignored issues
show
The function goNext is declared conditionally. This is not supported by all runtimes. Consider moving it to root scope or using var goNext = function() { /* ... */ }; instead.
Loading history...
145
					$("#TB_window").remove();
146
					$("body").append("<div id='TB_window'></div>");
147
					tb_show(TB_NextCaption, TB_NextURL, imageGroup);				
148
					return false;	
149
				}
150
				$("#TB_next").click(goNext);
151
				
152
			}
153
154
			document.onkeydown = function(e){ 	
155
				if (e == null) { // ie
156
					keycode = event.keyCode;
0 ignored issues
show
The variable keycode seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.keycode.
Loading history...
157
				} else { // mozilla
158
					keycode = e.which;
159
				}
160
				if(keycode == 27){ // close
161
					tb_remove();
162
				} else if(keycode == 190){ // display previous image
163
					if(!(TB_NextHTML == "")){
164
						document.onkeydown = "";
165
						goNext();
166
					}
167
				} else if(keycode == 188){ // display next image
168
					if(!(TB_PrevHTML == "")){
169
						document.onkeydown = "";
170
						goPrev();
171
					}
172
				}	
173
			};
174
			
175
			tb_position();
176
			$("#TB_load").remove();
177
			$("#TB_ImageOff").click(tb_remove);
178
			$("#TB_window").css({display:"block"}); //for safari using css instead of show
179
			};
180
			
181
			imgPreloader.src = url;
182
		}else{//code to show html
183
			
184
			var queryString = url.replace(/^[^\?]+\??/,'');
185
			var params = tb_parseQuery( queryString );
186
187
			TB_WIDTH = (params['width']*1) + 30 || 630; //defaults to 630 if no paramaters were added to URL
0 ignored issues
show
The variable TB_WIDTH seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.TB_WIDTH.
Loading history...
188
			TB_HEIGHT = (params['height']*1) + 40 || 440; //defaults to 440 if no paramaters were added to URL
0 ignored issues
show
The variable TB_HEIGHT seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.TB_HEIGHT.
Loading history...
189
			ajaxContentW = TB_WIDTH - 30;
0 ignored issues
show
The variable ajaxContentW seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.ajaxContentW.
Loading history...
190
			ajaxContentH = TB_HEIGHT - 45;
0 ignored issues
show
The variable ajaxContentH seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.ajaxContentH.
Loading history...
191
			
192
			if(url.indexOf('TB_iframe') != -1){// either iframe or ajax window		
193
					urlNoQuery = url.split('TB_');
0 ignored issues
show
The variable urlNoQuery seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.urlNoQuery.
Loading history...
194
					$("#TB_iframeContent").remove();
195
					if(params['modal'] != "true"){//iframe no modal
196
						$("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton' title='Close'><span style='font-size:18px;padding:5px;'><i class='fa fa-close'></i></span></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>");
197
					}else{//iframe modal
198
					$("#TB_overlay").unbind();
199
						$("#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>");
200
					}
201
			}else{// not an iframe, ajax
202
					if($("#TB_window").css("display") != "block"){
203
						if(params['modal'] != "true"){//ajax no modal
204
						$("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton'><span style='font-size:18px;padding:5px;'><i class='fa fa-close'></i></span></a></div></div><div id='TB_ajaxContent' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px'></div>");
205
						}else{//ajax modal
206
						$("#TB_overlay").unbind();
207
						$("#TB_window").append("<div id='TB_ajaxContent' class='TB_modal' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;'></div>");	
208
						}
209
					}else{//this means the window is already up, we are just loading new content via ajax
210
						$("#TB_ajaxContent")[0].style.width = ajaxContentW +"px";
211
						$("#TB_ajaxContent")[0].style.height = ajaxContentH +"px";
212
						$("#TB_ajaxContent")[0].scrollTop = 0;
213
						$("#TB_ajaxWindowTitle").html(caption);
214
					}
215
			}
216
					
217
			$("#TB_closeWindowButton").click(tb_remove);
218
			
219
				if(url.indexOf('TB_inline') != -1){	
220
					$("#TB_ajaxContent").append($('#' + params['inlineId']).children());
221
					$("#TB_window").unload(function () {
222
						$('#' + params['inlineId']).append( $("#TB_ajaxContent").children() ); // move elements back when you're finished
223
					});
224
					tb_position();
225
					$("#TB_load").remove();
226
					$("#TB_window").css({display:"block"}); 
227
				}else if(url.indexOf('TB_iframe') != -1){
228
					tb_position();
229
					if($.browser.safari){//safari needs help because it will not fire iframe onload
230
						$("#TB_load").remove();
231
						$("#TB_window").css({display:"block"});
232
					}
233
				}else{
234
					$("#TB_ajaxContent").load(url += "&random=" + (new Date().getTime()),function(){//to do a post change this load method
235
						tb_position();
236
						$("#TB_load").remove();
237
						tb_init("#TB_ajaxContent a.thickbox");
238
						$("#TB_window").css({display:"block"});
239
					});
240
				}
241
			
242
		}
243
244
		if(!params['modal']){
0 ignored issues
show
The variable params seems to not be initialized for all possible execution paths.
Loading history...
245
			document.onkeyup = function(e){ 	
246
				if (e == null) { // ie
247
					keycode = event.keyCode;
0 ignored issues
show
The variable keycode seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.keycode.
Loading history...
248
				} else { // mozilla
249
					keycode = e.which;
250
				}
251
				if(keycode == 27){ // close
252
					tb_remove();
253
				}	
254
			};
255
		}
256
		
257
	} catch(e) {
0 ignored issues
show
Coding Style Comprehensibility Best Practice introduced by
Empty catch clauses should be used with caution; consider adding a comment why this is needed.
Loading history...
258
		//nothing here
259
	}
260
}
261
262
//helper functions below
263
function tb_showIframe(){
264
	$("#TB_load").remove();
265
	$("#TB_window").css({display:"block"});
266
}
267
268
function tb_remove() {
269
 	$("#TB_imageOff").unbind("click");
270
	$("#TB_closeWindowButton").unbind("click");
271
	$("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
272
	$("#TB_load").remove();
273
	if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
274
		$("body","html").css({height: "auto", width: "auto"});
275
		$("html").css("overflow","");
276
	}
277
	document.onkeydown = "";
278
	document.onkeyup = "";
279
	return false;
280
}
281
282
function tb_position() {
283
$("#TB_window").css({marginLeft: '-' + parseInt((TB_WIDTH / 2),10) + 'px', width: TB_WIDTH + 'px'});
284
	if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6
285
		$("#TB_window").css({marginTop: '-' + parseInt((TB_HEIGHT / 2),10) + 'px'});
286
	}
287
}
288
289
function tb_parseQuery ( query ) {
290
   var Params = {};
291
   if ( ! query ) {return Params;}// return empty object
292
   var Pairs = query.split(/[;&]/);
293
   for ( var i = 0; i < Pairs.length; i++ ) {
294
      var KeyVal = Pairs[i].split('=');
295
      if ( ! KeyVal || KeyVal.length != 2 ) {continue;}
296
      var key = unescape( KeyVal[0] );
297
      var val = unescape( KeyVal[1] );
298
      val = val.replace(/\+/g, ' ');
299
      Params[key] = val;
300
   }
301
   return Params;
302
}
303
304
function tb_getPageSize(){
305
	var de = document.documentElement;
306
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
307
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
308
	arrayPageSize = [w,h];
0 ignored issues
show
The variable arrayPageSize seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.arrayPageSize.
Loading history...
309
	return arrayPageSize;
310
}
311
312
function tb_detectMacXFF() {
313
  var userAgent = navigator.userAgent.toLowerCase();
314
  if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if userAgent.indexOf("mac")...ndexOf("firefox") != -1 is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
315
    return true;
316
  }
317
}
318
319
320