Plugin Directory

Changeset 608737


Ignore:
Timestamp:
10/05/2012 11:06:14 PM (13 years ago)
Author:
attosoft
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • auto-thickbox-plus/trunk/thickbox.js

    r607313 r608737  
    501501            var params = tb_parseQuery( queryString );
    502502
    503             TB_WIDTH = (params['width']*1) || tb_options.win_width; //defaults to 600 if no paramaters were added to URL
    504             TB_HEIGHT = (params['height']*1) || tb_options.win_height; //defaults to 400 if no paramaters were added to URL
    505             ajaxContentW = TB_WIDTH;
    506             ajaxContentH = TB_HEIGHT;
    507 
    508503            if (typeof caption == "object") caption = tb_caption(caption, tb_options.ref_title);
    509504            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>";
    510505
    511506            if(url.indexOf('TB_iframe') != -1){// either iframe or ajax window
    512                 ajaxContentW += ('\v'=='v' ? 10 : 8) * 2; // add default body margin (IE or not)
    513                 ajaxContentH += ('\v'=='v' ? 15 : 8) * 2;
    514507                urlNoQuery = url.split(/[?&]TB_/);
    515508                jQuery("#TB_iframeContent").remove();
    516                 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>";
     509                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>";
    517510                if(params['modal'] != "true"){//iframe no modal
    518511                    switch (tb_options.position_title) {
     
    530523            }else{// not an iframe, ajax
    531524                if(jQuery("#TB_window").css("display") != "block"){
    532                     TB_Ajax = "<div id='TB_ajaxContent' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;'></div>";
     525                    TB_Ajax = "<div id='TB_ajaxContent'></div>";
    533526                    if(params['modal'] != "true"){//ajax no modal
    534527                        switch (tb_options.position_title) {
     
    546539                    }
    547540                }else{//this means the window is already up, we are just loading new content via ajax
    548                     jQuery("#TB_ajaxContent")[0].style.width = ajaxContentW +"px";
    549                     jQuery("#TB_ajaxContent")[0].style.height = ajaxContentH +"px";
    550541                    jQuery("#TB_ajaxContent")[0].scrollTop = 0;
    551542                    jQuery("#TB_ajaxWindowTitle").html(caption);
    552543                }
    553             }
    554 
    555             if(url.indexOf('TB_iframe') != -1) {
    556                 TB_WIDTH += ('\v'=='v' ? 10 : 8) * 2; // add default body margin (IE or not)
    557                 TB_HEIGHT += ('\v'=='v' ? 15 : 8) * 2 + tb_getSize(jQuery("#TB_title"))[1]; // add body margin and title bar height
    558             } else {
    559                 var innerSize = tb_getSize(jQuery("#TB_ajaxContent"), "padding");
    560                 var size = tb_getSize(jQuery("#TB_ajaxContent"));
    561                 TB_WIDTH += innerSize[0] - size[0]; // add content padding
    562                 TB_HEIGHT += innerSize[1] - size[1] + tb_getSize(jQuery("#TB_title"))[1];
    563544            }
    564545
     
    570551                    jQuery('#' + params['inlineId']).append( jQuery("#TB_ajaxContent").children() ); // move elements back when you're finished
    571552                });
    572                 tb_position();
     553                tb_position_html(url, params);
    573554                jQuery("#TB_load").remove();
    574555                tb_open();
    575556                tb_roundCorner("iframe");
    576557            }else if(url.indexOf('TB_iframe') != -1){
    577                 tb_position();
     558                tb_position_html(url, params);
    578559                if ((!("onload" in jQuery("#TB_iframeContent")[0]) && (typeof jQuery("#TB_iframeContent")[0]["onload"] != "function")) // not support iframe onload - http://kangax.github.com/iseventsupported/
    579560                    || urlType == '.pdf') { // XXX: Not wait for loading to complete because "onload" event won't triggered in IE and Firefox
     
    583564                var sign = (url.indexOf('?') == -1) ? '?' : '&';
    584565                jQuery("#TB_ajaxContent").load(url += sign + "random=" + (new Date().getTime()),function(){//to do a post change this load method
    585                     tb_position();
     566                    tb_position_html(url, params);
    586567                    jQuery("#TB_load").remove();
    587568                    tb_open();
     
    829810}
    830811
     812function tb_position_html(url, params) {
     813    TB_WIDTH = (params['width']*1) || tb_options.win_width; //defaults to 600 if no paramaters were added to URL
     814    TB_HEIGHT = (params['height']*1) || tb_options.win_height; //defaults to 400 if no paramaters were added to URL
     815    ajaxContentW = TB_WIDTH;
     816    ajaxContentH = TB_HEIGHT;
     817
     818    if(url.indexOf('TB_iframe') != -1){// either iframe or ajax window
     819        ajaxContentW += ('\v'=='v' ? 10 : 8) * 2; // add default body margin (IE or not)
     820        ajaxContentH += ('\v'=='v' ? 15 : 8) * 2;
     821        jQuery("#TB_iframeContent").attr("style", "width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;");
     822    }else{// not an iframe, ajax
     823        if(jQuery("#TB_window").css("display") != "block"){
     824            jQuery("#TB_ajaxContent").attr("style", "width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;");
     825        }else{//this means the window is already up, we are just loading new content via ajax
     826            jQuery("#TB_ajaxContent")[0].style.width = ajaxContentW +"px";
     827            jQuery("#TB_ajaxContent")[0].style.height = ajaxContentH +"px";
     828        }
     829    }
     830
     831    if(url.indexOf('TB_iframe') != -1) {
     832        TB_WIDTH += ('\v'=='v' ? 10 : 8) * 2; // add default body margin (IE or not)
     833        TB_HEIGHT += ('\v'=='v' ? 15 : 8) * 2 + tb_getSize(jQuery("#TB_title"))[1]; // add body margin and title bar height
     834    } else {
     835        var innerSize = tb_getSize(jQuery("#TB_ajaxContent"), "padding");
     836        var size = tb_getSize(jQuery("#TB_ajaxContent"));
     837        TB_WIDTH += innerSize[0] - size[0]; // add content padding
     838        TB_HEIGHT += innerSize[1] - size[1] + tb_getSize(jQuery("#TB_title"))[1];
     839    }
     840
     841    tb_position();
     842}
     843
    831844function tb_parseQuery ( query ) {
    832845    var Params = {};
Note: See TracChangeset for help on using the changeset viewer.