PageSourceSearch

https://www.speedcore.ca/wp-content/plugins/wp-e-commerce/wpsc-core/js/thickbox.js?ver=Instinct_e-commerce

js speedcore.ca collected 2026-10-07 19:42:47 UTC 14,444 bytes, 420 lines download raw bytes

1/*
2 * Thickbox 2.1 - jQuery plugin for displaying content in a box above the page
3 * 
4 * Copyright (c) 2006, 2007 Cody Lindley (http://www.codylindley.com)
5 *
6 * Licensed under the MIT License:
7 *   http://www.opensource.org/licenses/mit-license.php
8 */
9
10// on page load call TB_init
11jQuery(document).ready(TB_init);
12
13// add thickbox to href elements that have a class of .thickbox
14function TB_init(){
15	jQuery("a.thickbox").click(function(event){
16		// stop default behaviour
17		event.preventDefault();
18		// remove click border
19		this.blur();
20	
21		// get caption: either title or name attribute
22		var caption = this.title || this.name || "";
23		
24		// get rel attribute for image groups
25		var group = this.rel || false;
26		
27		// display the box for the elements href
28		TB_show(caption, this.href, group);
29	});
30}
31
32// called when the user clicks on a thickbox link
33function TB_show(caption, url, rel) {
34	// create iframe, overlay and box if non-existent
35	if ( !jQuery("#TB_HideSelect").length ) {
36		jQuery("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
37		jQuery("#TB_overlay").click(TB_remove);
38	}
39	// TODO replace or check if event is already assigned
40	jQuery(window).scroll(TB_position);
41	
42	// TODO replace
43	TB_overlaySize();
44	
45	// TODO create loader only once, hide and show on demand
46	jQuery("body").append("<div id='TB_load'><img src='"+fileThickboxLoadingImage+"' /></div>");
47	TB_load_position();
48	
49	// check if a query string is involved
50	var baseURL = url.match(/(.+)?/)[1] || url;
51
52	// regex to check if a href refers to an image
53	var imageURL = /\.(jpe?g|png|gif|bmp)/gi;
54
55	// check for images
56	if ( baseURL.match(imageURL) ) {
57		var dummy = { caption: "", url: "", html: "" };
58		
59		var prev = dummy,
60			next = dummy,
61			imageCount = "";
62			
63		// if an image group is given
64		if ( rel ) {
65			function getInfo(image, id, label) {
66				return {
67					caption: image.title,
68					url: image.href,
69					html: "<span id='TB_" + id + "'>&nbsp;&nbsp;<a href='#'>" + label + "</a></span>"
70				}
71			}
72		
73			// find the anchors that point to the group
74			var imageGroup = jQuery("a[rel='"+rel+"']").get();
75			var foundSelf = false;
76			var imageTitle = 'Gallery'; //default to something sane
77			// loop through the anchors, looking for ourself, saving information about previous and next image
78			for (var i = 0; i < imageGroup.length; i++) {
79				var image = imageGroup[i];
80				var urlTypeTemp = image.href.match(imageURL);
81				
82				// look for ourself
83				if ( image.href == url ) {
84					foundSelf = true;
85					imageCount = "Image " + (i + 1) + " of "+ (imageGroup.length);
86          if(image.rel != null) {
87            imageTitle = image.rel.replace(/_/, " ");
88					}
89				} else {
90					// when we found ourself, the current is the next image
91					if ( foundSelf ) {
92						next = getInfo(image, "next", "Next &gt;");
93						// stop searching
94						break;
95					} else {
96						// didn't find ourself yet, so this may be the one before ourself
97						prev = getInfo(image, "prev", "&lt; Prev");
98					}
99				}
100			}
101		}
102		
103		imgPreloader = new Image();
104		imgPreloader.onload = function() {
105			imgPreloader.onload = null;
106
107			// Resizing large images
108			var pagesize = TB_getPageSize();
109			var x = pagesize[0] - 150;
110			var y = pagesize[1] - 150;
111			var imageWidth = imgPreloader.width;
112			var imageHeight = imgPreloader.height;
113			if (imageWidth > x) {
114				imageHeight = imageHeight * (x / imageWidth); 
115				imageWidth = x; 
116				if (imageHeight > y) { 
117					imageWidth = imageWidth * (y / imageHeight); 
118					imageHeight = y; 
119				}
120			} else if (imageHeight > y) { 
121				imageWidth = imageWidth * (y / imageHeight); 
122				imageHeight = y; 
123				if (imageWidth > x) { 
124					imageHeight = imageHeight * (x / imageWidth); 
125					imageWidth = x;
126				}
127			}
128			// End Resizing
129			
130			// TODO don't use globals
131      if(imageGroup.length > 1) { 
132        TB_WIDTH = imageWidth + 30 + 76 + 18;
133        TB_HEIGHT = imageHeight + 60; 
134        // Browser detection is bad and all, but hey, its better than things not working
135        if(jQuery.browser.msie) {
136          TB_HEIGHT += 30; 
137          if(navigator.appVersion.match(/MSIE\s6\.0/) == "MSIE 6.0") {
138            TB_WIDTH += 20;
139					}
140				}
141        
142        // make additional image links and containing div
143        thumbPreloader = Array();
144        additional_links = "<div id='TB_additional_images'>";
145        var thumb_x = 76;
146        var thumb_y = imageHeight;
147        
148        for (var i = 0; i < imageGroup.length; i++) {
149          var image = imageGroup[i];
150          // look for ourself
151          var image_selected = "";
152          if ( image.href == url ) {
153            image_selected = "class='TB_Selected'";
154            }
155            
156          thumbPreloader[i] = new Image();
157          thumbPreloader[i].onload = function() {
158            //thumbPreloader[i].onload = null;    
159					}  
160        thumbPreloader[i].src = image.href;
161        var thumbImgWidth = thumbPreloader[i].width;
162        var thumbImgHeight = thumbPreloader[i].height;
163        if (thumbImgWidth > thumb_x) {
164          thumbImgHeight = Math.floor(thumbImgHeight * (thumb_x / thumbImgWidth)); 
165          thumbImgWidth = Math.floor(thumb_x); 
166          if (thumbImgHeight > thumb_y) { 
167            thumbImgWidth = Math.floor(thumbImgWidth * (thumb_y / thumbImgHeight)); 
168            thumbImgHeight = Math.floor(thumb_y); 
169					}
170				}
171				if(thumbImgWidth < 1) {
172          thumbImgWidth = thumb_x;				
173				}
174				
175				if(thumbImgHeight < 1) {
176          thumbImgHeight = 60				
177				}
178				
179				if(jQuery('img',image).attr('src') == null) {
180					image_src = jQuery(image).attr('rev');
181				} else {
182					image_src = jQuery('img',image).attr('src');
183				}
184				
185				image_src = image_src.replace(/width=(\d)*/, "width="+thumbImgWidth);
186				image_src = image_src.replace(/height=(\d)*/, "height="+thumbImgHeight);
187        additional_links += "<a href='#' "+image_selected+" id='TB_ThumbnailLink_"+i+"' ><img class='TB_Thumbnail_Image' src='"+image_src+"' width='"+thumbImgWidth+"' height='"+thumbImgHeight+"' alt=''/></a>";
188        }
189        
190        additional_links += "</div>";
191       jQuery("#TB_window").append("<div id='TB_Header'><div id='TB_TopCloseAjaxWindow'><a href='#' id='TB_TopCloseWindowButton' title='Close'>close</a></div>"+imageTitle+"</div>");
192        
193        jQuery("#TB_window").append(additional_links);
194        jQuery("#TB_TopCloseWindowButton").click(TB_remove);
195        }
196        else
197          {
198          TB_WIDTH = imageWidth + 30;
199          TB_HEIGHT = imageHeight + 60;
200          }
201			// TODO empty window content instead
202			jQuery("#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'>" + imageCount + prev.html + next.html + "</div></div><div id='TB_closeWindow'><a href='#' id='TB_closeWindowButton' title='Close'>close</a></div>");
203			
204			jQuery("#TB_closeWindowButton").click(TB_remove);
205   
206      function buildClickHandler(image) {
207         return function() {
208            jQuery("#TB_window").remove();
209            jQuery("body").append("<div id='TB_window'></div>");
210            TB_show(image.caption, image.url, rel);
211            return false;
212          };
213       }   
214      
215      if(imageGroup.length > 1)
216        {  
217        goImage = Array();
218        for (var i = 0; i < imageGroup.length; i++) {      
219          goImage[i] = buildClickHandler(getInfo(imageGroup[i], "image_"+i+"", ""));
220          jQuery("#TB_ThumbnailLink_"+i+"").click(goImage[i]);
221          }
222        }
223			var goPrev = buildClickHandler(prev);
224			var goNext = buildClickHandler(next);
225			if ( prev.html ) {
226				jQuery("#TB_prev").click(goPrev);
227			}
228			
229			if ( next.html ) {		
230				jQuery("#TB_next").click(goNext);
231			}
232			
233			// TODO use jQuery, maybe with event fix plugin, or just get the necessary parts of it
234			document.onkeydown = function(e) {
235				if (e == null) { // ie
236					keycode = event.keyCode;
237				} else { // mozilla
238					keycode = e.which;
239				}
240				switch(keycode) {
241				case 27:
242					TB_remove();
243					break;
244				case 190:
245					if( next.html ) {
246						document.onkeydown = null;
247						goNext();
248					}
249					break;
250				case 188:
251					if( prev.html ) {
252						document.onkeydown = null;
253						goPrev();
254					}
255					break;
256				}
257			}
258			
259			// TODO don't remove loader etc., just hide and show later
260			TB_position();
261			jQuery("#TB_load").remove();
262			jQuery("#TB_ImageOff").click(TB_remove);
263			
264			// for safari using css instead of show
265			// TODO is that necessary? can't test safari
266			jQuery("#TB_window").css({display:"block"});
267		}
268		imgPreloader.src = url;
269		
270	} else { //code to show html pages
271		//alert(url);
272		var queryString = url.match(/\?(.+)/)[1];
273		var params = TB_parseQuery( queryString );
274		
275		TB_WIDTH = (params['width']*1) + 30;
276		TB_HEIGHT = (params['height']*1) + 40;
277
278		var ajaxContentW = TB_WIDTH - 30,
279			ajaxContentH = TB_HEIGHT - 45;
280		
281		if(url.indexOf('TB_iframe') != -1){				
282			urlNoQuery = url.split('TB_');		
283			jQuery("#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></div></div><iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;' onload='TB_showIframe()'> </iframe>");
284		} else {
285			jQuery("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton'>close</a></div></div><div id='TB_ajaxContent' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;'></div>");
286		}
287				
288		jQuery("#TB_closeWindowButton").click(TB_remove);
289		
290			if(url.indexOf('TB_inline') != -1){	
291				jQuery("#TB_ajaxContent").html(jQuery('#' + params['inlineId']).html());
292				TB_position();
293				jQuery("#TB_load").remove();
294				jQuery("#TB_window").css({display:"block"}); 
295			}else if(url.indexOf('TB_iframe') != -1){
296				TB_position();
297				if(frames['TB_iframeContent'] == undefined){//be nice to safari
298					jQuery("#TB_load").remove();
299					jQuery("#TB_window").css({display:"block"});
300					jQuery(document).keyup( function(e){ var key = e.keyCode; if(key == 27){TB_remove()} });
301				}
302			}else{
303				jQuery("#TB_ajaxContent").load(url, function(){
304					TB_position();
305					jQuery("#TB_load").remove();
306					jQuery("#TB_window").css({display:"block"}); 
307				});
308			}	
309	}
310	
311	jQuery(window).resize(TB_position);
312	
313	document.onkeyup = function(e){ 	
314		if (e == null) { // ie
315			keycode = event.keyCode;
316		} else { // mozilla
317			keycode = e.which;
318		}
319		if(keycode == 27){ // close
320			TB_remove();
321		}	
322	}
323		
324}
325
326//helper functions below
327
328function TB_showIframe(){
329	jQuery("#TB_load").remove();
330	jQuery("#TB_window").css({display:"block"});
331}
332
333function TB_remove() {
334 	jQuery("#TB_imageOff").unbind("click");
335	jQuery("#TB_overlay").unbind("click");
336	jQuery("#TB_closeWindowButton").unbind("click");
337  jQuery("#TB_TopCloseWindowButton").unbind("click");
338	jQuery("#TB_window").fadeOut("fast",function(){jQuery('#TB_window,#TB_overlay,#TB_HideSelect').remove();});
339	jQuery("#TB_load").remove();
340	return false;
341}
342
343function TB_position() {
344	var pagesize = TB_getPageSize();	
345	var arrayPageScroll = TB_getPageScrollTop();
346	var style = {width: TB_WIDTH, left: (arrayPageScroll[0] + (pagesize[0] - TB_WIDTH)/2), top: (arrayPageScroll[1] + (pagesize[1]-TB_HEIGHT)/2)};
347	jQuery("#TB_window").css(style);
348	jQuery("#TB_window").css("margin-top", 0);
349}
350
351function TB_overlaySize(){
352	if (window.innerHeight && window.scrollMaxY || window.innerWidth && window.scrollMaxX) {	
353		yScroll = window.innerHeight + window.scrollMaxY;
354		xScroll = window.innerWidth + window.scrollMaxX;
355		var deff = document.documentElement;
356		var wff = (deff&&deff.clientWidth) || document.body.clientWidth || window.innerWidth || self.innerWidth;
357		var hff = (deff&&deff.clientHeight) || document.body.clientHeight || window.innerHeight || self.innerHeight;
358		xScroll -= (window.innerWidth - wff);
359		yScroll -= (window.innerHeight - hff);
360	} else if (document.body.scrollHeight > document.body.offsetHeight || document.body.scrollWidth > document.body.offsetWidth){ // all but Explorer Mac
361		yScroll = document.body.scrollHeight;
362		xScroll = document.body.scrollWidth;
363	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
364		yScroll = document.body.offsetHeight;
365		xScroll = document.body.offsetWidth;
366  	}
367	jQuery("#TB_overlay").css({"height": yScroll, "width": xScroll});
368	jQuery("#TB_HideSelect").css({"height": yScroll,"width": xScroll});
369}
370
371function TB_load_position() {
372	var pagesize = TB_getPageSize();
373	var arrayPageScroll = TB_getPageScrollTop();
374	jQuery("#TB_load")
375		.css({left: (arrayPageScroll[0] + (pagesize[0] - 100)/2), top: (arrayPageScroll[1] + ((pagesize[1]-100)/2)) })
376		.css({display:"block"});
377}
378
379function TB_parseQuery ( query ) {
380	// return empty object
381	if( !query )
382		return {};
383	var params = {};
384	
385	// parse query
386	var pairs = query.split(/[;&]/);
387	for ( var i = 0; i < pairs.length; i++ ) {
388		var pair = pairs[i].split('=');
389		if ( !pair || pair.length != 2 )
390			continue;
391		// unescape both key and value, replace "+" with spaces in value
392		params[unescape(pair[0])] = unescape(pair[1]).replace(/\+/g, ' ');
393   }
394   return params;
395}
396
397function TB_getPageScrollTop(){
398	var yScrolltop;
399	var xScrollleft;
400	if (self.pageYOffset || self.pageXOffset) {
401		yScrolltop = self.pageYOffset;
402		xScrollleft = self.pageXOffset;
403	} else if (document.documentElement && document.documentElement.scrollTop || document.documentElement.scrollLeft ){	 // Explorer 6 Strict
404		yScrolltop = document.documentElement.scrollTop;
405		xScrollleft = document.documentElement.scrollLeft;
406	} else if (document.body) {// all other Explorers
407		yScrolltop = document.body.scrollTop;
408		xScrollleft = document.body.scrollLeft;
409	}
410	arrayPageScroll = new Array(xScrollleft,yScrolltop) 
411	return arrayPageScroll;
412}
413
414function TB_getPageSize(){
415	var de = document.documentElement;
416	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
417	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight
418	arrayPageSize = new Array(w,h) 
419	return arrayPageSize;
420}

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.