[wp-trac] [WordPress Trac] #33365: Plugins admin: plugin-install.js prevents custom thickbox implementations

WordPress Trac noreply at wordpress.org
Tue Aug 9 07:11:03 UTC 2016


#33365: Plugins admin: plugin-install.js prevents custom thickbox implementations
--------------------------+-----------------------------------------
 Reporter:  Offereins     |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Plugins       |     Version:  4.2
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:  javascript, administration
--------------------------+-----------------------------------------

Comment (by alanstorm):

 I ran into this, and other issue this week as well.  The Wordpress core
 code's redefinition of `tb_position` and style changes can interfere with
 a plugin developer who wants to add a thickbox to certain admin pages.
 I've outline the problem in a Wordpress Stack Exchange Questions
 (http://wordpress.stackexchange.com/questions/235327/custom-thickbox-
 broken-on-dashboard-page), and also have a temp workaround in a self-
 answer (http://wordpress.stackexchange.com/a/235399/33566).

 The workaround involves opening the thickboxes yourself with `tb_show`,
 and then using the following javascript function to un-do the Wordpress
 customizations that interfere with third party thickboxes.  This code also
 tries to set Wordpress's customizations back after the thickboxes close.
 Not widely tested, but hope it helps point folks towards a soution

 {{{
     var resetWordpressChangesToThickbox = function(){
         //remove these styles from body if they exist
         var classes = ['about-php','plugin-install-php','import-php',
             'plugins-php','update-core-php','index-php'];
         var removed = [];
         $.each(classes, function(k,v){
             if(!$('body').hasClass(v)) { return; }
             removed.push(v);
             $('body').removeClass(v);
         });

         var tb_position_original = window.tb_position;

         //some wordpress pages redefine this function which breaks
         //the thickbox, so we need to reset it here.
         window.tb_position = function() {
             var isIE6 = typeof document.body.style.maxHeight ===
 "undefined";
             jQuery("#TB_window").css({marginLeft: '-' + parseInt((TB_WIDTH
 / 2),10) + 'px', width: TB_WIDTH + 'px'});
             if ( ! isIE6 ) { // take away IE6
                 jQuery("#TB_window").css({marginTop: '-' +
 parseInt((TB_HEIGHT / 2),10) + 'px'});
             }
         }

         var tb_remove_original = window.tb_remove;
         window.tb_remove = function()
         {
             $.each(removed, function(k,v){
                 $('body').addClass(v);
                 window.tb_position = tb_position_original;
             });
             tb_remove_original();
         }
     }
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/33365#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list