PageSourceSearch

http://www.takukyou.or.jp/js/jquery/thickbox/thickbox.js

js takukyou.or.jp collected 2026-10-05 03:28:40 UTC 19,631 bytes, 537 lines download raw bytes

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
8var $this            = null;
9var tb_pathImgFolder = FullUrl + "css/js/jquery/thickbox/image/";
10var tb_pathToImage   = tb_pathImgFolder + "loadingAnimation.gif";
11var first_top = 0;
12
13
14/*!!!!!!!!!!!!!!!!! edit below this line at your own risk !!!!!!!!!!!!!!!!!!!!!!!*/
15
16//on page load call tb_init
17$(document).ready(function(){   
18	tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
19	imgLoader = new Image();// preload image
20	imgLoader.src = tb_pathToImage;
21});
22
23//add thickbox to href & area elements that have a class of .thickbox
24function tb_init(domChunk){
25	$(domChunk).click(function(){
26	first_top = document.documentElement.scrollTop;
27    $this = $(this);
28	var t = this.title || this.name || null;
29	var a = this.href || this.alt;
30	var g = this.rel || false;
31	tb_show(t,a,g);
32    this.blur();
33    //近藤 ログ取得
34    if(typeof $jq.getClick == 'function') {
35        $jq.getClick($jq(this),true);
36    }
37	return false;
38	});
39}
40
41function tb_show(caption, url, imageGroup) {//function called when the user clicks on a thickbox link
42	try {
43		if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
44			$("body","html").css({height: "100%", width: "100%"});
45			$("html").css("overflow","hidden");
46			if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
47				$("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
48				$("#TB_overlay").click(tb_remove);
49			}
50		}else{//all others
51
52			// #1018 2013/11/11 M-Egawa
53			if ("ontouchstart" in document.documentElement){ 
54				$('html').addClass('touch'); 
55			}
56
57			if(document.getElementById("TB_overlay") === null){
58				$("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
59				$("#TB_overlay").click(tb_remove);
60			}
61		}
62		
63		if(tb_detectMacXFF()){
64			$("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
65		}else{
66			$("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
67		}
68		
69		if(caption===null){caption="";}
70		$("body").append("<div id='TB_load'><img src='"+imgLoader.src+"' /></div>");//add loader to the page
71		$('#TB_load').show();//show loader
72		
73		var baseURL;
74	   if(url.indexOf("?")!==-1){ //ff there is a query string involved
75			baseURL = url.substr(0, url.indexOf("?"));
76	   }else{ 
77	   		baseURL = url;
78	   }
79	   
80	   var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/;
81	   var urlType = baseURL.toLowerCase().match(urlString);
82
83		if(urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' || urlType == '.gif' || urlType == '.bmp'){//code to show images
84				
85			TB_PrevCaption = "";
86			TB_PrevURL = "";
87			TB_PrevHTML = "";
88			TB_NextCaption = "";
89			TB_NextURL = "";
90			TB_NextHTML = "";
91			TB_imageCount = "";
92			TB_FoundURL = false;
93			if(imageGroup){
94				TB_TempArray = $("a[rel="+imageGroup+"]").get();
95				for (TB_Counter = 0; ((TB_Counter < TB_TempArray.length) && (TB_NextHTML === "")); TB_Counter++) {
96					var urlTypeTemp = TB_TempArray[TB_Counter].href.toLowerCase().match(urlString);
97						if (!(TB_TempArray[TB_Counter].href == url)) {						
98							if (TB_FoundURL) {
99								TB_NextCaption = TB_TempArray[TB_Counter].title;
100								TB_NextURL = TB_TempArray[TB_Counter].href;
101								TB_NextHTML = "<span id='TB_next'>&nbsp;&nbsp;<a href='#'><img src='" + tb_pathImgFolder + "next.gif' /></a></span>";
102								
103								if($("a[rel="+imageGroup+"]").eq(TB_Counter).find(".thickboxCustomText").length)
104								{	
105									TB_NextCaption  = $("a[rel="+imageGroup+"]").eq(TB_Counter).find(".thickboxCustomText").html();
106								}
107							} else {
108								TB_PrevCaption = TB_TempArray[TB_Counter].title;
109								TB_PrevURL = TB_TempArray[TB_Counter].href;
110								TB_PrevHTML = "<span id='TB_prev'><a href='#'><img src='" + tb_pathImgFolder + "prev.gif' /></a></span>";
111								
112								if($("a[rel="+imageGroup+"]").eq(TB_Counter).find(".thickboxCustomText").length)
113								{
114									TB_PrevCaption  = $("a[rel="+imageGroup+"]").eq(TB_Counter).find(".thickboxCustomText").html();
115								}
116							}
117						} else {
118							TB_FoundURL = true;
119							TB_imageCount = "Image " + (TB_Counter + 1) +" of "+ (TB_TempArray.length);											
120						}
121				}
122				
123			}
124			
125
126			
127			if((!caption) && $this.find(".thickboxCustomText").length){
128				var str = $this.find(".thickboxCustomText").html();
129				str = str.replace(/(\s+)/g,'');
130				if(str){
131					caption  = $this.find(".thickboxCustomText").html();
132				}
133			}
134			
135			imgPreloader = new Image();
136			imgPreloader.onload = function(){		
137			imgPreloader.onload = null;
138				
139			// Resizing large images - orginal by Christian Montoya edited by me.
140			var pagesize = tb_getPageSize();
141			//var x = pagesize[0] - 150;
142			//var y = pagesize[1] - 150;
143			
144			var x = $(window).width()*0.8;
145			var y = 2000;
146			
147			var imageWidth = imgPreloader.width;
148			var imageHeight = imgPreloader.height;
149
150			// #1570
151			var ua = window.navigator.userAgent;
152			if(/iPhone/.test(ua)) {
153				ua.match(/iPhone OS (\w+){1,3}/g);
154				var osv=(RegExp.$1.replace(/_/g, '')+'00').slice(0,3);
155				// iPhoneのiOS8以上iOS9未満
156				if(osv >= 800 && osv < 900) {
157					var y = 800;
158					// 横向きの場合
159					if(Math.abs(window.orientation) == 90) {
160						var y = 430;
161					}
162				}
163			} else if(/iPad/.test(ua)) {
164				ua.match(/CPU OS (\w+){1,3}/g);
165				var osv=(RegExp.$1.replace(/_/g, '')+'00').slice(0,3);
166				// iPadのiOS8以上iOS9未満
167				if(osv >= 800 && osv < 900) {
168					var y = 800;
169					// 横向きの場合
170					if(Math.abs(window.orientation) == 90) {
171						var y = 430;
172					}
173				}
174			}
175
176			if (imageWidth > x) {
177				imageHeight = imageHeight * (x / imageWidth); 
178				imageWidth = x; 
179				if (imageHeight > y) { 
180					imageWidth = imageWidth * (y / imageHeight); 
181					imageHeight = y; 
182				}
183			} else if (imageHeight > y) { 
184				imageWidth = imageWidth * (y / imageHeight); 
185				imageHeight = y; 
186				if (imageWidth > x) { 
187					imageHeight = imageHeight * (x / imageWidth); 
188					imageWidth = x;
189				}
190			}
191			
192			TB_WIDTH = imageWidth + 30;
193			TB_HEIGHT = imageHeight + 60;
194			
195			//2011-11-16 matuuchi 最小でも、300pxのウィンドウになるように調整
196			if(TB_WIDTH < 300){
197				TB_WIDTH = 300;
198			}
199			
200			var $ht = $("<div>");
201			var cap_html = '';
202			if(caption){
203				cap_html = "<div id='TB_caption' style=''>"+caption+"</div>";
204			}
205			
206			//2011-11-16 matuuchi 画像が中央になるように調整
207			$ht.append("<a href='' id='TB_ImageOff' title='Close'><div style='text-align:center'><img id='TB_Image' src='"+url+"' width='"+imageWidth+"' height='"+imageHeight+"' style='margin-left:auto;margin-right:auto;' alt='Close'/></div></a>" + "<div><div style='float:left;margin-top:10px;margin-bottom:20px;padding-left:15px;'>"+cap_html+"<div id='TB_secondLine' style=''>" + TB_imageCount + TB_PrevHTML + TB_NextHTML + "</div></div><div id='TB_closeWindow' style='float:right;'><a href='#' id='TB_closeWindowButton' title='Close'><div id='TB_closeWindowButtonImg'></div></a></div></div>").hide();
208			$("#TB_window").append($ht);
209			// #1290 2014/04/14 t-ichikawa クローム対応
210			//$('html,body').scrollTop(first_top);
211			$('window').scrollTop(first_top);
212			$ht.animate({opacity:'show'},1000,"swing");
213
214			var tbcaption = $("#TB_caption");
215			
216			//2011-11-16 matuuchi 画像が小さい場合文字が縦になるのを調整
217			//tbcaption.width($("#TB_Image").width()-90);
218			tbcaption.width(TB_WIDTH - 100);
219
220			//2011-11-16 matuuchi 調整テスト(文字の幅を決めてから、高さを取得するように移動)
221			TB_HEIGHT = $ht.outerHeight();
222
223			$("#TB_closeWindowButton").click(tb_remove);
224			
225			if (!(TB_PrevHTML === "")) {
226				function goPrev(){
227                    //近藤 ログ取得
228                    if(typeof $jq.getClick == 'function') {
229                        $jq.getClick($jq('#TB_prev'),true);
230                    }
231					if($(document).unbind("click",goPrev)){$(document).unbind("click",goPrev);}
232					$("#TB_window").remove();
233					$("body").append("<div id='TB_window'></div>");
234					tb_show(TB_PrevCaption, TB_PrevURL, imageGroup);
235					return false;	
236				}
237				$("#TB_prev").click(goPrev);
238			}
239			
240			if (!(TB_NextHTML === "")) {		
241				function goNext(){
242                    //近藤 ログ取得
243                    if(typeof $jq.getClick == 'function') {
244                        $jq.getClick($jq('#TB_next'),true);
245                    }
246					$("#TB_window").remove();
247					$("body").append("<div id='TB_window'></div>");
248					tb_show(TB_NextCaption, TB_NextURL, imageGroup);				
249					return false;	
250				}
251				$("#TB_next").click(goNext);
252				
253			}
254
255			document.onkeydown = function(e){ 	
256				if (e == null) { // ie
257					keycode = event.keyCode;
258				} else { // mozilla
259					keycode = e.which;
260				}
261				if(keycode == 27){ // close
262					tb_remove();
263				} else if(keycode == 190){ // display previous image
264					if(!(TB_NextHTML == "")){
265						document.onkeydown = "";
266						goNext();
267					}
268				} else if(keycode == 188){ // display next image
269					if(!(TB_PrevHTML == "")){
270						document.onkeydown = "";
271						goPrev();
272					}
273				}	
274			};
275			
276			tb_position2();
277			$("#TB_load").remove();
278			$("#TB_ImageOff").click(tb_remove);
279			$("#TB_window").css({display:"block"}); //for safari using css instead of show
280			};
281
282			imgPreloader.src = url;
283		}else{//code to show html
284			
285			var queryString = url.replace(/^[^\?]+\??/,'');
286			var params = tb_parseQuery( queryString );
287
288			TB_PrevCaption = "";
289			TB_PrevURL = "";
290			TB_PrevHTML = "";
291			TB_NextCaption = "";
292			TB_NextURL = "";
293			TB_NextHTML = "";
294			TB_imageCount = "";
295			TB_FoundURL = false;
296			if(imageGroup){
297				TB_TempArray = $("a[rel="+imageGroup+"]").get();
298				for (TB_Counter = 0; ((TB_Counter < TB_TempArray.length) && (TB_NextHTML === "")); TB_Counter++) {
299					var urlTypeTemp = TB_TempArray[TB_Counter].href.toLowerCase().match(urlString);
300						if (!(TB_TempArray[TB_Counter].href == url)) {						
301							if (TB_FoundURL) {
302								TB_NextCaption = TB_TempArray[TB_Counter].title;
303								TB_NextURL = TB_TempArray[TB_Counter].href;
304								TB_NextHTML = "<span id='TB_next'>&nbsp;&nbsp;<a href='#'><img src='" + tb_pathImgFolder + "next.gif' /></a></span>";
305								
306								if($("a[rel="+imageGroup+"]").eq(TB_Counter).find(".thickboxCustomText").length)
307								{	
308									TB_NextCaption  = $("a[rel="+imageGroup+"]").eq(TB_Counter).find(".thickboxCustomText").html();
309								}
310							} else {
311								TB_PrevCaption = TB_TempArray[TB_Counter].title;
312								TB_PrevURL = TB_TempArray[TB_Counter].href;
313								TB_PrevHTML = "<span id='TB_prev'><a href='#'><img src='" + tb_pathImgFolder + "prev.gif' /></a></span>";
314								
315								if($("a[rel="+imageGroup+"]").eq(TB_Counter).find(".thickboxCustomText").length)
316								{
317									TB_PrevCaption  = $("a[rel="+imageGroup+"]").eq(TB_Counter).find(".thickboxCustomText").html();
318								}
319							}
320						} else {
321							TB_FoundURL = true;
322							TB_imageCount = "" + (TB_Counter + 1) +" of "+ (TB_TempArray.length);											
323						}
324				}
325				
326			}
327			
328			TB_WIDTH = (params['width']*1) + 30 || 630; //defaults to 630 if no paramaters were added to URL
329			TB_HEIGHT = (params['height']*1) + 40 || $(window).height()-100; //defaults to 440 if no paramaters were added to URL
330
331			if($(window).width() < TB_WIDTH){
332				TB_WIDTH = $(window).width() - 80;
333			}
334			if($(window).height() < TB_HEIGHT){
335				TB_HEIGHT = $(window).height() - 40;
336			}
337			
338			ajaxContentW = TB_WIDTH - 30;
339			ajaxContentH = TB_HEIGHT - 45;
340			
341			if(url.indexOf('TB_iframe') != -1){// either iframe or ajax window		
342					urlNoQuery = url.split('TB_');
343					$("#TB_iframeContent").remove();
344					if(params['modal'] != "true"){//iframe no modal
345						$("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'><div id='TB_secondLine' style='float:left;margin:0px 0px 0px 20px;'>" + TB_imageCount + TB_PrevHTML + TB_NextHTML + "</div></div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton' title='Close'><div id='TB_closeWindowButtonImg'></div></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>");
346					}else{//iframe modal
347					$("#TB_overlay").unbind();
348						$("#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>");
349					}
350			}else{// not an iframe, ajax
351					if($("#TB_window").css("display") != "block"){
352						if(params['modal'] != "true"){//ajax no modal
353						$("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'></div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton'><div id='TB_closeWindowButtonImg'></div></a></div></div><div id='TB_ajaxContent' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px'></div>");
354						}else{//ajax modal
355						$("#TB_overlay").unbind();
356						$("#TB_window").append("<div id='TB_ajaxContent' class='TB_modal' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;'></div>");	
357						}
358					}else{//this means the window is already up, we are just loading new content via ajax
359						$("#TB_ajaxContent")[0].style.width = ajaxContentW +"px";
360						$("#TB_ajaxContent")[0].style.height = ajaxContentH +"px";
361						$("#TB_ajaxContent")[0].scrollTop = 0;
362						$("#TB_ajaxWindowTitle").html(caption);
363					}
364			}
365
366			$('html,body').scrollTop(first_top);
367
368
369			$("#TB_closeWindowButton").click(tb_remove);
370				if(url.indexOf('TB_inline') != -1){	
371					$("#TB_ajaxContent").append($('#' + params['inlineId']).children());
372					$("#TB_window").unload(function () {
373						$('#' + params['inlineId']).append( $("#TB_ajaxContent").children() ); // move elements back when you're finished
374					});
375					tb_position();
376					$("#TB_load").remove();
377					$("#TB_window").css({display:"block"}); 
378				}else if(url.indexOf('TB_iframe') != -1){
379					tb_position();
380					if($.browser.safari){//safari needs help because it will not fire iframe onload
381						$("#TB_load").remove();
382						$("#TB_window").css({display:"block"});
383					}
384				}else{
385					$("#TB_ajaxContent").load(url += "&random=" + (new Date().getTime()),function(){//to do a post change this load method
386						tb_position();
387						$("#TB_load").remove();
388						tb_init("#TB_ajaxContent a.thickbox");
389						$("#TB_window").css({display:"block"});
390					});
391				}
392
393			$("#TB_closeWindowButton").click(tb_remove);
394			
395			if (!(TB_PrevHTML === "")) {
396				function goPrev(){
397                    //近藤 ログ取得
398                    if(typeof $jq.getClick == 'function') {
399                        $jq.getClick($jq('#TB_next'),true);
400                    }
401					if($(document).unbind("click",goPrev)){$(document).unbind("click",goPrev);}
402					$("#TB_window").remove();
403					$("body").append("<div id='TB_window'></div>");
404					tb_show(TB_PrevCaption, TB_PrevURL, imageGroup);
405					return false;	
406				}
407				$("#TB_prev").click(goPrev);
408			}
409			
410			if (!(TB_NextHTML === "")) {		
411				function goNext(){
412                    //近藤 ログ取得
413                    if(typeof $jq.getClick == 'function') {
414                        $jq.getClick($jq('#TB_next'),true);
415                    }
416					$("#TB_window").remove();
417					$("body").append("<div id='TB_window'></div>");
418					tb_show(TB_NextCaption, TB_NextURL, imageGroup);				
419					return false;	
420				}
421				$("#TB_next").click(goNext);
422				
423			}
424
425		}
426		
427		if(params)
428		{
429			if(!params['modal']){
430				document.onkeyup = function(e){ 	
431					if (e == null) { // ie
432						keycode = event.keyCode;
433					} else { // mozilla
434						keycode = e.which;
435					}
436					if(keycode == 27){ // close
437						tb_remove();
438						
439					}	
440				};
441			}
442		}
443		
444	} catch(e) {
445		//nothing here
446	}
447}
448
449//helper functions below
450function tb_showIframe(){
451	$("#TB_load").remove();
452	$("#TB_window").css({display:"block"});
453}
454
455function tb_remove() {
456    //近藤 ログ取得
457    if(typeof $jq.getClick == 'function') {
458        $jq.getClick($jq("#TB_closeWindowButton"),true);
459    }
460 	$("#TB_imageOff").unbind("click");
461	$("#TB_closeWindowButton").unbind("click");
462	$("#TB_window").hide();
463	$("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
464	$("#TB_load").remove();
465
466	if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
467		$("body","html").css({height: "auto", width: "auto"});
468		$("html").css("overflow","");
469	}
470	document.onkeydown = "";
471	document.onkeyup = "";
472	return false;
473}
474
475function tb_position() {
476
477$("#TB_window").css({marginLeft: '-' + parseInt((TB_WIDTH / 2),10) + 'px', width: TB_WIDTH + 'px'});
478	if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6
479		var m_top = parseInt($("#TB_window").css('top').replace("px"));
480		m_top = m_top - (($(window).height() - TB_HEIGHT)/2);
481		
482		$("#TB_window").css({marginTop: '-' + m_top + 'px'});
483	}
484}
485
486function tb_position2() {
487	if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
488		$("body","html").css({height: "auto", width: "auto"});
489		$("html").css("overflow","");
490	}else{//all others
491
492	}
493
494	// #1290 2014/04/14 t-ichikawa クローム対応
495	if($(window).height() < TB_HEIGHT){
496		//var win_top = document.documentElement.scrollTop+10;
497		var win_top = ($(window).scrollTop())+10;
498	}else{
499		//var win_top = document.documentElement.scrollTop+(($(window).height() - TB_HEIGHT)/2)-5;
500		var win_top = ($(window).scrollTop())+(($(window).height() - TB_HEIGHT)/2)-5;
501	}
502	
503	$("#TB_window").css({position:'absolute',top:win_top+"px",marginTop:"0px",marginLeft: '-' + parseInt((TB_WIDTH / 2),10) + 'px', width: TB_WIDTH + 'px'});
504}
505
506
507function tb_parseQuery ( query ) {
508   var Params = {};
509   if ( ! query ) {return Params;}// return empty object
510   var Pairs = query.split(/[;&]/);
511   for ( var i = 0; i < Pairs.length; i++ ) {
512      var KeyVal = Pairs[i].split('=');
513      if ( ! KeyVal || KeyVal.length != 2 ) {continue;}
514      var key = unescape( KeyVal[0] );
515      var val = unescape( KeyVal[1] );
516      val = val.replace(/\+/g, ' ');
517      Params[key] = val;
518   }
519   return Params;
520}
521
522function tb_getPageSize(){
523	var de = document.documentElement;
524	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
525	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
526	arrayPageSize = [w,h];
527	return arrayPageSize;
528}
529
530function tb_detectMacXFF() {
531  var userAgent = navigator.userAgent.toLowerCase();
532  if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
533    return true;
534  }
535}
536
537

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.