Make WordPress Core

Changeset 30560


Ignore:
Timestamp:
11/25/2014 04:30:31 AM (11 years ago)
Author:
azaozz
Message:

TinyMCE: don't hide the image toolbar when the iframe window fires onresize. There is a bug in several browsers that triggers onresize when a tooltip is shown, only in RTL mode. Also use better variable name. Fixes #30147.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/tinymce/plugins/wpeditimage/plugin.js

    r30558 r30560  
    11/* global tinymce */
    22tinymce.PluginManager.add( 'wpeditimage', function( editor ) {
    3     var tb, serializer,
     3    var floatingToolbar, serializer,
    44        DOM = tinymce.DOM,
    55        settings = editor.settings,
     
    156156    }
    157157
    158     tb = Factory.create( toolbarConfig() ).renderTo( document.body ).hide();
    159 
    160     tb.reposition = function() {
     158    floatingToolbar = Factory.create( toolbarConfig() ).renderTo( document.body ).hide();
     159
     160    floatingToolbar.reposition = function() {
    161161        var top, left, minTop, className,
     162            windowPos, adminbar, mceToolbar, boundary,
     163            boundaryMiddle, boundaryVerticalMiddle, spaceTop,
     164            spaceBottom, windowWidth, toolbarWidth, toolbarHalf,
     165            iframe, iframePos, iframeWidth, iframeHeigth,
     166            toolbarNodeHeight, verticalSpaceNeeded,
    162167            toolbarNode = this.getEl(),
    163168            buffer = 5,
    164169            margin = 8,
    165             windowPos = window.pageYOffset || document.documentElement.scrollTop,
    166             adminbar = tinymce.$( '#wpadminbar' )[0],
    167             mceToolbar = tinymce.$( '.mce-tinymce .mce-toolbar-grp' )[0],
    168170            adminbarHeight = 0,
    169             boundary = editor.selection.getNode().getBoundingClientRect(),
    170             boundaryMiddle = ( boundary.left + boundary.right ) / 2,
    171             boundaryVerticalMiddle = ( boundary.top + boundary.bottom ) / 2,
    172             spaceTop = boundary.top,
    173             spaceBottom = iframeHeigth - boundary.bottom,
    174             windowWidth = window.innerWidth,
    175             toolbarWidth = toolbarNode.offsetWidth,
    176             toolbarHalf = toolbarWidth / 2,
    177             iframe = editor.getContentAreaContainer().firstChild,
    178             iframePos = DOM.getPos( iframe ),
    179             iframeWidth = iframe.offsetWidth,
    180             iframeHeigth = iframe.offsetHeight,
    181             toolbarNodeHeight = toolbarNode.offsetHeight,
    182             verticalSpaceNeeded = toolbarNodeHeight + margin + buffer;
     171            imageNode = editor.selection.getNode();
     172
     173        if ( ! imageNode || imageNode.nodeName !== 'IMG' ) {
     174            return this;
     175        }
     176
     177        windowPos = window.pageYOffset || document.documentElement.scrollTop;
     178        adminbar = tinymce.$( '#wpadminbar' )[0];
     179        mceToolbar = tinymce.$( '.mce-tinymce .mce-toolbar-grp' )[0];
     180        boundary = imageNode.getBoundingClientRect();
     181        boundaryMiddle = ( boundary.left + boundary.right ) / 2;
     182        boundaryVerticalMiddle = ( boundary.top + boundary.bottom ) / 2;
     183        spaceTop = boundary.top;
     184        spaceBottom = iframeHeigth - boundary.bottom;
     185        windowWidth = window.innerWidth;
     186        toolbarWidth = toolbarNode.offsetWidth;
     187        toolbarHalf = toolbarWidth / 2;
     188        iframe = editor.getContentAreaContainer().firstChild;
     189        iframePos = DOM.getPos( iframe );
     190        iframeWidth = iframe.offsetWidth;
     191        iframeHeigth = iframe.offsetHeight;
     192        toolbarNodeHeight = toolbarNode.offsetHeight;
     193        verticalSpaceNeeded = toolbarNodeHeight + margin + buffer;
    183194
    184195        if ( iOS ) {
     
    264275                }, 200 );
    265276            } else {
    266                 tb.hide();
     277                floatingToolbar.hide();
    267278            }
    268279        });
     
    273284
    274285        if ( event.element.nodeName !== 'IMG' || isPlaceholder( event.element ) ) {
    275             tb.hide();
     286            floatingToolbar.hide();
    276287            return;
    277288        }
     
    281292
    282293            if ( element.nodeName === 'IMG' && ! isPlaceholder( element ) ) {
    283                 if ( tb._visible ) {
    284                     tb.reposition();
     294                if ( floatingToolbar._visible ) {
     295                    floatingToolbar.reposition();
    285296                } else {
    286                     tb.show();
     297                    floatingToolbar.show();
    287298                }
    288299            } else {
    289                 tb.hide();
     300                floatingToolbar.hide();
    290301            }
    291302        }, delay );
    292303    } );
    293304
    294     tb.on( 'show', function() {
     305    floatingToolbar.on( 'show', function() {
    295306        var self = this;
    296307
     
    305316    } );
    306317
    307     tb.on( 'hide', function() {
     318    floatingToolbar.on( 'hide', function() {
    308319        toolbarIsHidden = true;
    309320        DOM.removeClass( this.getEl(), 'mce-inline-toolbar-grp-active' );
     
    312323    function hide() {
    313324        if ( ! toolbarIsHidden ) {
    314             tb.hide();
     325            floatingToolbar.hide();
    315326        }
    316327    }
     
    323334
    324335    editor.on( 'init', function() {
    325         DOM.bind( editor.getWin(), 'resize scroll', hide );
    326     } );
    327 
     336        editor.dom.bind( editor.getWin(), 'scroll', hide );
     337    });
     338   
    328339    editor.on( 'blur hide', hide );
    329340
    330341    // 119 = F8
    331342    editor.shortcuts.add( 'Alt+119', '', function() {
    332         var node = tb.find( 'toolbar' )[0];
     343        var node = floatingToolbar.find( 'toolbar' )[0];
    333344
    334345        if ( node ) {
    335346            node.focus( true );
    336347        }
    337     } );
     348    });
    338349
    339350    function parseShortcode( content ) {
     
    11111122            event.preventDefault();
    11121123
    1113             if ( tb ) {
    1114                 tb.reposition();
     1124            if ( floatingToolbar ) {
     1125                floatingToolbar.reposition();
    11151126            }
    11161127        }
Note: See TracChangeset for help on using the changeset viewer.