Commit 1ff1a86a by Masaru Abe

Thickbox.jsのリファクタリング

parent 8ad58f1a
......@@ -23,7 +23,7 @@
*
*/
//グローバルの名前空間用のオブジェクトを用意する
//グローバルの名前空間用のオブジェクトを用意する
var SCREENLOCK = {};
SCREENLOCK.screenLock = function(options) {
......
......@@ -5,23 +5,26 @@
* Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
*/
var tb_pathToImage = "";// "/common/images/loadingAnimation.gif";
var tmpPage;
var linkPage;
var TB_WIDTH;
var TB_HEIGHT;
//グローバルの名前空間用のオブジェクトを用意する
var THICKBOX = {};
THICKBOX.tb_pathToImage = "";// "/common/images/loadingAnimation.gif";
THICKBOX.tmpPage;
THICKBOX.linkPage;
THICKBOX.TB_WIDTH;
THICKBOX.TB_HEIGHT;
// ページ上部からの位置
var pageTop = 10;
THICKBOX.pageTop = 10;
/*!!!!!!!!!!!!!!!!! edit below this line at your own risk !!!!!!!!!!!!!!!!!!!!!!!*/
//on page load call tb_init
$(document).ready(function(){
if (window == window.parent){
tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
THICKBOX.tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
imgLoader = new Image();// preload image
imgLoader.src = tb_pathToImage;
imgLoader.src = THICKBOX.tb_pathToImage;
}else {
//2009/09/28 add h.kobayashi
$(".thickbox_link").click(function () {
......@@ -30,7 +33,7 @@ $(document).ready(function(){
doc = parent.document;
}
if ($("#TB_iframeContent",doc).size() > 0){
showLoading();
THICKBOX.showLoading();
$('#TB_window',doc).hide();
}
return true;
......@@ -50,21 +53,21 @@ $(document).ready(function(){
var tmpImage = $("#tmpDesign > p > img:eq(0)");
var preImg = new Image();
preImg.src = tmpImage.attr("src");
preImg.onload = _imageLoaded;
preImg.onload = THICKBOX._imageLoaded;
if (preImg.width > preImg.height){
TB_WIDTH = 820;
TB_HEIGHT = 725;
THICKBOX.TB_WIDTH = 820;
THICKBOX.TB_HEIGHT = 725;
}else{
TB_WIDTH = 820;
TB_HEIGHT = 725;
THICKBOX.TB_WIDTH = 820;
THICKBOX.TB_HEIGHT = 725;
}
TB_WIDTH = TB_WIDTH + 15;
TB_HEIGHT = TB_HEIGHT + 30;
THICKBOX.TB_WIDTH = THICKBOX.TB_WIDTH + 15;
THICKBOX.TB_HEIGHT = THICKBOX.TB_HEIGHT + 30;
var ajaxContentW = TB_WIDTH - 29;
var ajaxContentH = TB_HEIGHT - 80;
var ajaxContentW = THICKBOX.TB_WIDTH - 29;
var ajaxContentH = THICKBOX.TB_HEIGHT - 80;
$("#TB_title",doc).width(ajaxContentW);
//$("#TB_ajaxWindowTitle",doc).text(caption);
......@@ -79,9 +82,9 @@ $(document).ready(function(){
// 画面中央に位置を調整
if (jQuery.browser.msie && jQuery.browser.version < 7) {
offsetTop = (doc.documentElement.clientHeight - TB_HEIGHT)/2;
offsetTop = (doc.documentElement.clientHeight - THICKBOX.TB_HEIGHT)/2;
}else{
offsetTop = ($("body",doc).height() - TB_HEIGHT)/2;
offsetTop = ($("body",doc).height() - THICKBOX.TB_HEIGHT)/2;
}
if ($(document).scrollTop() + offsetTop >= 0){
......@@ -91,7 +94,7 @@ $(document).ready(function(){
}
docwidth = $("body",doc).width();
marginsize = ((docwidth - TB_WIDTH)/2);
marginsize = ((docwidth - THICKBOX.TB_WIDTH)/2);
$("#TB_window",doc).css("left","0px");
$("#TB_window",doc).css("margin-left",marginsize + "px");
......@@ -105,7 +108,7 @@ $(document).ready(function(){
});
//2009.09.28 add kobayashi
function _imageLoaded(){
THICKBOX._imageLoaded = function(){
var url = this.href || this.alt;
var caption = this.title || this.name || null;
......@@ -115,18 +118,18 @@ function _imageLoaded(){
}
if (this.width > this.height){
TB_WIDTH = 800;
TB_HEIGHT = 570;
THICKBOX.TB_WIDTH = 800;
THICKBOX.TB_HEIGHT = 570;
}else{
TB_WIDTH = 620;
TB_HEIGHT = 650;
THICKBOX.TB_WIDTH = 620;
THICKBOX.TB_HEIGHT = 650;
}
TB_WIDTH = TB_WIDTH + 15;
TB_HEIGHT = TB_HEIGHT + 30;
THICKBOX.TB_WIDTH = THICKBOX.TB_WIDTH + 15;
THICKBOX.TB_HEIGHT = THICKBOX.TB_HEIGHT + 30;
var ajaxContentW = TB_WIDTH - 29;
var ajaxContentH = TB_HEIGHT - 80;
var ajaxContentW = THICKBOX.TB_WIDTH - 29;
var ajaxContentH = THICKBOX.TB_HEIGHT - 80;
$("#TB_title",doc).width(ajaxContentW);
//$("#TB_ajaxWindowTitle",doc).text(caption);
......@@ -141,9 +144,9 @@ function _imageLoaded(){
// 画面中央に位置を調整
if (jQuery.browser.msie && jQuery.browser.version < 7) {
offsetTop = (doc.documentElement.clientHeight - TB_HEIGHT)/2;
offsetTop = (doc.documentElement.clientHeight - THICKBOX.TB_HEIGHT)/2;
}else{
offsetTop = ($("body",doc).height() - TB_HEIGHT)/2;
offsetTop = ($("body",doc).height() - THICKBOX.TB_HEIGHT)/2;
}
if ($(document).scrollTop() + offsetTop >= 0){
......@@ -153,7 +156,7 @@ function _imageLoaded(){
}
docwidth = $("body",doc).width();
marginsize = ((docwidth - TB_WIDTH)/2);
marginsize = ((docwidth - THICKBOX.TB_WIDTH)/2);
$("#TB_window",doc).css("left","0px");
$("#TB_window",doc).css("margin-left",marginsize + "px");
......@@ -162,24 +165,24 @@ function _imageLoaded(){
$('#TB_load',doc).hide();
$('#TB_window',doc).show();
//$("#TB_iframeContent",doc).attr("src",linkPage);
//$("#TB_iframeContent",doc).attr("src",THICKBOX.linkPage);
}
//add thickbox to href & area elements that have a class of .thickbox
function tb_init(domChunk){
THICKBOX.tb_init = function(domChunk){
$(domChunk).click(function(){
var t = this.title || this.name || null;
var a = this.href || this.alt;
var g = this.rel || false;
tb_show(t,a,g);
THICKBOX.tb_show(t,a,g);
this.blur();
return false;
});
}
function tb_show(caption, url, imageGroup) {//function called when the user clicks on a thickbox link
THICKBOX.tb_show = function(caption, url, imageGroup) {//function called when the user clicks on a thickbox link
try {
if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
......@@ -187,17 +190,17 @@ function tb_show(caption, url, imageGroup) {//function called when the user clic
//$("html").css("overflow","hidden");
if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
$("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
$("#TB_overlay").click(tb_remove);
$("#TB_overlay").click(THICKBOX.tb_remove);
}
$("#TB_HideSelect").css("overflow","hidden");
}else{//all others
if(document.getElementById("TB_overlay") === null){
$("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
$("#TB_overlay").click(tb_remove);
$("#TB_overlay").click(THICKBOX.tb_remove);
}
}
if(tb_detectMacXFF()){
if(THICKBOX.tb_detectMacXFF()){
$("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
}else{
$("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
......@@ -209,7 +212,7 @@ function tb_show(caption, url, imageGroup) {//function called when the user clic
$("body").append("<div id='TB_load'><img src='"+imgLoader.src+"' /></div>");//add loader to the page
}
showLoading();
THICKBOX.showLoading();
var baseURL;
if(url.indexOf("?")!==-1){ //ff there is a query string involved
......@@ -259,7 +262,7 @@ function tb_show(caption, url, imageGroup) {//function called when the user clic
imgPreloader.onload = null;
// Resizing large images - orginal by Christian Montoya edited by me.
var pagesize = tb_getPageSize();
var pagesize = THICKBOX.tb_getPageSize();
var x = pagesize[0] - 150;
var y = pagesize[1] - 150;
var imageWidth = imgPreloader.width;
......@@ -281,21 +284,21 @@ function tb_show(caption, url, imageGroup) {//function called when the user clic
}
// End Resizing
TB_WIDTH = imageWidth + 30;
TB_HEIGHT = imageHeight + 60;
THICKBOX.TB_WIDTH = imageWidth + 30;
THICKBOX.TB_HEIGHT = imageHeight + 60;
image_height = TB_HEIGHT;
image_height = THICKBOX.TB_HEIGHT;
$("#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' style='padding:10px 5px;'><a href='#' id='TB_closeWindowButton' title='閉じる'><img src='../common/images/bt_close.gif' alt='閉じる' width='31' height='31' /></a></div>");
$("#TB_closeWindowButton").click(tb_remove);
$("#TB_closeWindowButton").click(THICKBOX.tb_remove);
if (!(TB_PrevHTML === "")) {
function goPrev(){
if($(document).unbind("click",goPrev)){$(document).unbind("click",goPrev);}
$("#TB_window").remove();
$("body").append("<div id='TB_window'></div>");
tb_show(TB_PrevCaption, TB_PrevURL, imageGroup);
THICKBOX.tb_show(TB_PrevCaption, TB_PrevURL, imageGroup);
return false;
}
$("#TB_prev").click(goPrev);
......@@ -305,7 +308,7 @@ function tb_show(caption, url, imageGroup) {//function called when the user clic
function goNext(){
$("#TB_window").remove();
$("body").append("<div id='TB_window'></div>");
tb_show(TB_NextCaption, TB_NextURL, imageGroup);
THICKBOX.tb_show(TB_NextCaption, TB_NextURL, imageGroup);
return false;
}
$("#TB_next").click(goNext);
......@@ -319,7 +322,7 @@ function tb_show(caption, url, imageGroup) {//function called when the user clic
keycode = e.which;
}
if(keycode == 27){ // close
tb_remove();
THICKBOX.tb_remove();
} else if(keycode == 190){ // display previous image
if(!(TB_NextHTML == "")){
document.onkeydown = "";
......@@ -333,10 +336,10 @@ function tb_show(caption, url, imageGroup) {//function called when the user clic
}
};
tb_position();
THICKBOX.tb_position();
//$("#TB_load").remove();
$("#TB_load").hide();
$("#TB_ImageOff").click(tb_remove);
$("#TB_ImageOff").click(THICKBOX.tb_remove);
$("#TB_window").css({display:"block"}); //for safari using css instead of show
};
......@@ -346,12 +349,12 @@ function tb_show(caption, url, imageGroup) {//function called when the user clic
}else{//code to show html
var queryString = url.replace(/^[^\?]+\??/,'');
var params = tb_parseQuery( queryString );
var params = THICKBOX.tb_parseQuery( queryString );
TB_WIDTH = (params['width']*1) + 15 || 630; //defaults to 630 if no paramaters were added to URL
TB_HEIGHT = (params['height']*1) + 30 || 440; //defaults to 440 if no paramaters were added to URL
ajaxContentW = TB_WIDTH - 29;
ajaxContentH = TB_HEIGHT - 80;
THICKBOX.TB_WIDTH = (params['width']*1) + 15 || 630; //defaults to 630 if no paramaters were added to URL
THICKBOX.TB_HEIGHT = (params['height']*1) + 30 || 440; //defaults to 440 if no paramaters were added to URL
ajaxContentW = THICKBOX.TB_WIDTH - 29;
ajaxContentH = THICKBOX.TB_HEIGHT - 80;
if(url.indexOf('TB_iframe') != -1){// either iframe or ajax window
......@@ -361,10 +364,10 @@ function tb_show(caption, url, imageGroup) {//function called when the user clic
$("#TB_window").css({visibility:"hidden",display:"block"});
$("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton' title='閉じる'><img src='../common/images/bt_close.gif' alt='閉じる' width='31' height='31' /></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>");
$("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton' title='閉じる'><img src='../common/images/bt_close.gif' alt='閉じる' width='31' height='31' /></a></div></div><iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='THICKBOX.tb_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;' > </iframe>");
}else{//iframe modal
$("#TB_overlay").unbind();
$("#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>");
$("#TB_window").append("<iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='THICKBOX.tb_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;'> </iframe>");
}
}else{// not an iframe, ajax
if($("#TB_window").css("display") != "block"){
......@@ -382,19 +385,19 @@ function tb_show(caption, url, imageGroup) {//function called when the user clic
}
}
$("#TB_closeWindowButton").click(tb_remove);
$("#TB_closeWindowButton").click(THICKBOX.tb_remove);
if(url.indexOf('TB_inline') != -1){
$("#TB_ajaxContent").append($('#' + params['inlineId']).children());
$("#TB_window").unload(function () {
$('#' + params['inlineId']).append( $("#TB_ajaxContent").children() ); // move elements back when you're finished
});
tb_position();
THICKBOX.tb_position();
//$("#TB_load").remove();
$("#TB_load").hide();
$("#TB_window").css({display:"block"});
}else if(url.indexOf('TB_iframe') != -1){
tb_position();
THICKBOX.tb_position();
if($.browser.safari){//safari needs help because it will not fire iframe onload
//$("#TB_load").remove();
......@@ -403,23 +406,23 @@ function tb_show(caption, url, imageGroup) {//function called when the user clic
}
}else{
$("#TB_ajaxContent").load(url += "&random=" + (new Date().getTime()),function(){//to do a post change this load method
tb_position();
THICKBOX.tb_position();
//$("#TB_load").remove();
$("#TB_load").hide();
tb_init("#TB_ajaxContent a.thickbox");
THICKBOX.tb_init("#TB_ajaxContent a.thickbox");
$("#TB_window").css({display:"block"});
});
}
image_height = TB_HEIGHT;
image_height = THICKBOX.TB_HEIGHT;
}
// customize 2009/0914
$("#TB_overlay").height($(document).height());
// 画面中央に位置を調整
//var offsetTop = ($(window).height() - TB_HEIGHT)/2;
//var offsetTop = ($(window).height() - THICKBOX.TB_HEIGHT)/2;
//if ($(document).scrollTop() + offsetTop >= 0){
// $("#TB_window").css("top",$(document).scrollTop() + offsetTop + "px");
......@@ -461,7 +464,7 @@ function tb_show(caption, url, imageGroup) {//function called when the user clic
keycode = e.which;
}
if(keycode == 27){ // close
tb_remove();
THICKBOX.tb_remove();
}
};
}
......@@ -472,14 +475,14 @@ function tb_show(caption, url, imageGroup) {//function called when the user clic
}
//helper functions below
function tb_showIframe(){
THICKBOX.tb_showIframe = function(){
//$("#TB_load").remove();
$("#TB_load").hide();
$("#TB_window").css({visibility:"visible",display:"block"});
}
function tb_remove() {
THICKBOX.tb_remove = function() {
$("#TB_imageOff").unbind("click");
$("#TB_closeWindowButton").unbind("click");
$("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
......@@ -495,14 +498,14 @@ function tb_remove() {
return false;
}
function tb_position() {
$("#TB_window").css({marginLeft: '-' + parseInt((TB_WIDTH / 2),10) + 'px', width: TB_WIDTH + 'px'});
THICKBOX.tb_position = function() {
$("#TB_window").css({marginLeft: '-' + parseInt((THICKBOX.TB_WIDTH / 2),10) + 'px', width: THICKBOX.TB_WIDTH + 'px'});
//if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6
// $("#TB_window").css({marginTop: '-' + parseInt((TB_HEIGHT / 2),10) + 'px'});
// $("#TB_window").css({marginTop: '-' + parseInt((THICKBOX.TB_HEIGHT / 2),10) + 'px'});
//}
}
function tb_parseQuery ( query ) {
THICKBOX.tb_parseQuery = function( query ) {
var Params = {};
if ( ! query ) {return Params;}// return empty object
var Pairs = query.split(/[;&]/);
......@@ -517,7 +520,7 @@ function tb_parseQuery ( query ) {
return Params;
}
function tb_getPageSize(){
THICKBOX.tb_getPageSize = function(){
var de = document.documentElement;
var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
......@@ -525,14 +528,14 @@ function tb_getPageSize(){
return arrayPageSize;
}
function tb_detectMacXFF() {
THICKBOX.tb_detectMacXFF = function() {
var userAgent = navigator.userAgent.toLowerCase();
if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
return true;
}
}
function showLoading(){
THICKBOX.showLoading = function(){
var doc = window.document;
if(window != window.parent){
doc = parent.document;
......@@ -548,7 +551,7 @@ function showLoading(){
offsetTop = $("body",doc).height()/2;
}*/
offsetTop = TB_HEIGHT/2;
offsetTop = THICKBOX.TB_HEIGHT/2;
//offsetTop = pageTop;
$("#TB_load",doc).css("top",offsetTop + doctop + "px");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment