Refactoring: Moved sizing code of html (iframe/inline/ajax content) from tb_show() to new tb_position_html() (cf. [605624])

This commit is contained in:
attosoft committed 2012-10-05 23:06:14 +00:00
1 parent 5d23cf08e3
commit 55ad3dc08d
1 file changed
+37 -24
+37 -24
View File
@@ -500,20 +500,13 @@ function tb_show(caption, url, imageGroup) {//function called when the user clic
var queryString = url.replace(/^[^\?]+\??/,'');
var params = tb_parseQuery( queryString );
TB_WIDTH = (params['width']*1) || tb_options.win_width; //defaults to 600 if no paramaters were added to URL
TB_HEIGHT = (params['height']*1) || tb_options.win_height; //defaults to 400 if no paramaters were added to URL
ajaxContentW = TB_WIDTH;
ajaxContentH = TB_HEIGHT;
if (typeof caption == "object") caption = tb_caption(caption, tb_options.ref_title);
TB_Title = "<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton' title='"+thickboxL10n.close+"'><img src='" + tb_closeImage + "' /></a></div></div>";
if(url.indexOf('TB_iframe') != -1){// either iframe or ajax window
ajaxContentW += ('\v'=='v' ? 10 : 8) * 2; // add default body margin (IE or not)
ajaxContentH += ('\v'=='v' ? 15 : 8) * 2;
urlNoQuery = url.split(/[?&]TB_/);
jQuery("#TB_iframeContent").remove();
TB_Iframe = "<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+"px;height:"+ajaxContentH+"px;'>"+thickboxL10n.noiframes+"</iframe>";
TB_Iframe = "<iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='tb_showIframe()'>"+thickboxL10n.noiframes+"</iframe>";
if(params['modal'] != "true"){//iframe no modal
switch (tb_options.position_title) {
case "top":
@@ -529,7 +522,7 @@ function tb_show(caption, url, imageGroup) {//function called when the user clic
}
}else{// not an iframe, ajax
if(jQuery("#TB_window").css("display") != "block"){
TB_Ajax = "<div id='TB_ajaxContent' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;'></div>";
TB_Ajax = "<div id='TB_ajaxContent'></div>";
if(params['modal'] != "true"){//ajax no modal
switch (tb_options.position_title) {
case "top":
@@ -545,23 +538,11 @@ function tb_show(caption, url, imageGroup) {//function called when the user clic
jQuery("#TB_ajaxContent").addClass("TB_modal");
}
}else{//this means the window is already up, we are just loading new content via ajax
jQuery("#TB_ajaxContent")[0].style.width = ajaxContentW +"px";
jQuery("#TB_ajaxContent")[0].style.height = ajaxContentH +"px";
jQuery("#TB_ajaxContent")[0].scrollTop = 0;
jQuery("#TB_ajaxWindowTitle").html(caption);
}
}
if(url.indexOf('TB_iframe') != -1) {
TB_WIDTH += ('\v'=='v' ? 10 : 8) * 2; // add default body margin (IE or not)
TB_HEIGHT += ('\v'=='v' ? 15 : 8) * 2 + tb_getSize(jQuery("#TB_title"))[1]; // add body margin and title bar height
} else {
var innerSize = tb_getSize(jQuery("#TB_ajaxContent"), "padding");
var size = tb_getSize(jQuery("#TB_ajaxContent"));
TB_WIDTH += innerSize[0] - size[0]; // add content padding
TB_HEIGHT += innerSize[1] - size[1] + tb_getSize(jQuery("#TB_title"))[1];
}
jQuery("#TB_closeWindowButton").click(tb_remove);
if(url.indexOf('TB_inline') != -1){
@@ -569,12 +550,12 @@ function tb_show(caption, url, imageGroup) {//function called when the user clic
jQuery("#TB_window").bind('tb_unload', function () {
jQuery('#' + params['inlineId']).append( jQuery("#TB_ajaxContent").children() ); // move elements back when you're finished
});
tb_position();
tb_position_html(url, params);
jQuery("#TB_load").remove();
tb_open();
tb_roundCorner("iframe");
}else if(url.indexOf('TB_iframe') != -1){
tb_position();
tb_position_html(url, params);
if ((!("onload" in jQuery("#TB_iframeContent")[0]) && (typeof jQuery("#TB_iframeContent")[0]["onload"] != "function")) // not support iframe onload - http://kangax.github.com/iseventsupported/
|| urlType == '.pdf') { // XXX: Not wait for loading to complete because "onload" event won't triggered in IE and Firefox
tb_showIframe();
@@ -582,7 +563,7 @@ function tb_show(caption, url, imageGroup) {//function called when the user clic
}else{
var sign = (url.indexOf('?') == -1) ? '?' : '&';
jQuery("#TB_ajaxContent").load(url += sign + "random=" + (new Date().getTime()),function(){//to do a post change this load method
tb_position();
tb_position_html(url, params);
jQuery("#TB_load").remove();
tb_open();
tb_roundCorner("ajax")
@@ -828,6 +809,38 @@ function tb_reposition(params) {
tb_position();
}
function tb_position_html(url, params) {
TB_WIDTH = (params['width']*1) || tb_options.win_width; //defaults to 600 if no paramaters were added to URL
TB_HEIGHT = (params['height']*1) || tb_options.win_height; //defaults to 400 if no paramaters were added to URL
ajaxContentW = TB_WIDTH;
ajaxContentH = TB_HEIGHT;
if(url.indexOf('TB_iframe') != -1){// either iframe or ajax window
ajaxContentW += ('\v'=='v' ? 10 : 8) * 2; // add default body margin (IE or not)
ajaxContentH += ('\v'=='v' ? 15 : 8) * 2;
jQuery("#TB_iframeContent").attr("style", "width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;");
}else{// not an iframe, ajax
if(jQuery("#TB_window").css("display") != "block"){
jQuery("#TB_ajaxContent").attr("style", "width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;");
}else{//this means the window is already up, we are just loading new content via ajax
jQuery("#TB_ajaxContent")[0].style.width = ajaxContentW +"px";
jQuery("#TB_ajaxContent")[0].style.height = ajaxContentH +"px";
}
}
if(url.indexOf('TB_iframe') != -1) {
TB_WIDTH += ('\v'=='v' ? 10 : 8) * 2; // add default body margin (IE or not)
TB_HEIGHT += ('\v'=='v' ? 15 : 8) * 2 + tb_getSize(jQuery("#TB_title"))[1]; // add body margin and title bar height
} else {
var innerSize = tb_getSize(jQuery("#TB_ajaxContent"), "padding");
var size = tb_getSize(jQuery("#TB_ajaxContent"));
TB_WIDTH += innerSize[0] - size[0]; // add content padding
TB_HEIGHT += innerSize[1] - size[1] + tb_getSize(jQuery("#TB_title"))[1];
}
tb_position();
}
function tb_parseQuery ( query ) {
var Params = {};
if ( ! query ) {return Params;}// return empty object