WordPress.org

Make WordPress Core

Changeset 29050


Ignore:
Timestamp:
07/09/2014 10:42:28 PM (4 years ago)
Author:
azaozz
Message:

Fix whitespace, quotes and double patch content in wpautoresize plugin, see #28328

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/editor-expand.js

    r29049 r29050  
     1/* global tinymce */
    12
    23window.wp = window.wp || {};
     
    1617        $statusBar,
    1718        buffer = 200,
    18         adjust,
    1919        fullscreen = window.wp.editor && window.wp.editor.fullscreen,
    2020        editorInstance,
     
    2323
    2424    $textEditorClone.insertAfter( $textEditor );
    25    
     25
    2626    // use to enable/disable
    2727    $contentWrap.addClass( 'wp-editor-expand' );
     
    307307                    width: $editor.parent().width() - ( $top.outerWidth() - $top.width() )
    308308                } );
    309                
     309
    310310                $tools.css( {
    311311                    position: 'absolute',
     
    323323                    borderTop: 'none'
    324324                } );
    325                
     325
    326326                $tools.css( {
    327327                    position: 'absolute',
     
    330330                    width: $contentWrap.width()
    331331                } );
    332             }               
     332            }
    333333        }
    334334
  • trunk/src/wp-includes/js/tinymce/plugins/wpautoresize/plugin.js

    r29049 r29050  
    2121 * it's initialized.
    2222 */
    23 tinymce.PluginManager.add('wpautoresize', function(editor) {
     23tinymce.PluginManager.add( 'wpautoresize', function( editor ) {
    2424    var settings = editor.settings, oldSize = 0;
    2525
     
    2828    }
    2929
    30     if (editor.settings.inline) {
     30    if ( editor.settings.inline ) {
    3131        return;
    3232    }
     
    3535     * This method gets executed each time the editor needs to resize.
    3636     */
    37     function resize(e) {
     37    function resize( e ) {
    3838        var deltaSize, doc, body, docElm, DOM = tinymce.DOM, resizeHeight, myHeight, marginTop, marginBottom;
    3939
     
    4747        resizeHeight = settings.autoresize_min_height;
    4848
    49         if (!body || (e && e.type === "setcontent" && e.initial) || isFullscreen()) {
    50             if (body && docElm) {
    51                 body.style.overflowY = "auto";
    52                 docElm.style.overflowY = "auto"; // Old IE
     49        if ( ! body || ( e && e.type === 'setcontent' && e.initial ) || isFullscreen() ) {
     50            if ( body && docElm ) {
     51                body.style.overflowY = 'auto';
     52                docElm.style.overflowY = 'auto'; // Old IE
    5353            }
    5454
     
    5757
    5858        // Calculate outer height of the body element using CSS styles
    59         marginTop = editor.dom.getStyle(body, 'margin-top', true);
    60         marginBottom = editor.dom.getStyle(body, 'margin-bottom', true);
    61         myHeight = body.offsetHeight + parseInt(marginTop, 10) + parseInt(marginBottom, 10);
     59        marginTop = editor.dom.getStyle( body, 'margin-top', true );
     60        marginBottom = editor.dom.getStyle( body, 'margin-bottom', true );
     61        myHeight = body.offsetHeight + parseInt( marginTop, 10 ) + parseInt( marginBottom, 10 );
    6262
    6363        // Make sure we have a valid height
    64         if (isNaN(myHeight) || myHeight <= 0) {
     64        if ( isNaN( myHeight ) || myHeight <= 0 ) {
    6565            // Get height differently depending on the browser used
    66             myHeight = tinymce.Env.ie ? body.scrollHeight : (tinymce.Env.webkit && body.clientHeight === 0 ? 0 : body.offsetHeight);
     66            myHeight = tinymce.Env.ie ? body.scrollHeight : ( tinymce.Env.webkit && body.clientHeight === 0 ? 0 : body.offsetHeight );
    6767        }
    6868
    6969        // Don't make it smaller than the minimum height
    70         if (myHeight > settings.autoresize_min_height) {
     70        if ( myHeight > settings.autoresize_min_height ) {
    7171            resizeHeight = myHeight;
    7272        }
    7373
    7474        // If a maximum height has been defined don't exceed this height
    75         if (settings.autoresize_max_height && myHeight > settings.autoresize_max_height) {
     75        if ( settings.autoresize_max_height && myHeight > settings.autoresize_max_height ) {
    7676            resizeHeight = settings.autoresize_max_height;
    77             body.style.overflowY = "auto";
    78             docElm.style.overflowY = "auto"; // Old IE
     77            body.style.overflowY = 'auto';
     78            docElm.style.overflowY = 'auto'; // Old IE
    7979        } else {
    80             body.style.overflowY = "hidden";
    81             docElm.style.overflowY = "hidden"; // Old IE
     80            body.style.overflowY = 'hidden';
     81            docElm.style.overflowY = 'hidden'; // Old IE
    8282            body.scrollTop = 0;
    8383        }
     
    8686        if (resizeHeight !== oldSize) {
    8787            deltaSize = resizeHeight - oldSize;
    88             DOM.setStyle(DOM.get(editor.id + '_ifr'), 'height', resizeHeight + 'px');
     88            DOM.setStyle( DOM.get( editor.id + '_ifr'), 'height', resizeHeight + 'px' );
    8989            oldSize = resizeHeight;
    9090
    9191            // WebKit doesn't decrease the size of the body element until the iframe gets resized
    9292            // So we need to continue to resize the iframe down until the size gets fixed
    93             if (tinymce.isWebKit && deltaSize < 0) {
    94                 resize(e);
     93            if ( tinymce.isWebKit && deltaSize < 0 ) {
     94                resize( e );
    9595            }
    9696        }
     
    114114
    115115    // Define minimum height
    116     settings.autoresize_min_height = parseInt(editor.getParam('autoresize_min_height', editor.getElement().offsetHeight), 10);
     116    settings.autoresize_min_height = parseInt(editor.getParam( 'autoresize_min_height', editor.getElement().offsetHeight), 10 );
    117117
    118118    // Define maximum height
    119     settings.autoresize_max_height = parseInt(editor.getParam('autoresize_max_height', 0), 10);
     119    settings.autoresize_max_height = parseInt(editor.getParam( 'autoresize_max_height', 0), 10 );
    120120
    121121    function on() {
     
    162162    editor.addCommand( 'wpAutoResizeOff', off );
    163163});
    164 /**
    165  * plugin.js
    166  *
    167  * Copyright, Moxiecode Systems AB
    168  * Released under LGPL License.
    169  *
    170  * License: http://www.tinymce.com/license
    171  * Contributing: http://www.tinymce.com/contributing
    172  */
    173 
    174 // Forked for WordPress so it can be turned on/off after loading.
    175 
    176 /*global tinymce:true */
    177 /*eslint no-nested-ternary:0 */
    178 
    179 /**
    180  * Auto Resize
    181  *
    182  * This plugin automatically resizes the content area to fit its content height.
    183  * It will retain a minimum height, which is the height of the content area when
    184  * it's initialized.
    185  */
    186 tinymce.PluginManager.add('wpautoresize', function(editor) {
    187     var settings = editor.settings, oldSize = 0;
    188 
    189     function isFullscreen() {
    190         return editor.plugins.fullscreen && editor.plugins.fullscreen.isFullscreen();
    191     }
    192 
    193     if (editor.settings.inline) {
    194         return;
    195     }
    196 
    197     /**
    198      * This method gets executed each time the editor needs to resize.
    199      */
    200     function resize(e) {
    201         var deltaSize, doc, body, docElm, DOM = tinymce.DOM, resizeHeight, myHeight, marginTop, marginBottom;
    202 
    203         doc = editor.getDoc();
    204         if (!doc) {
    205             return;
    206         }
    207 
    208         body = doc.body;
    209         docElm = doc.documentElement;
    210         resizeHeight = settings.autoresize_min_height;
    211 
    212         if (!body || (e && e.type === "setcontent" && e.initial) || isFullscreen()) {
    213             if (body && docElm) {
    214                 body.style.overflowY = "auto";
    215                 docElm.style.overflowY = "auto"; // Old IE
    216             }
    217 
    218             return;
    219         }
    220 
    221         // Calculate outer height of the body element using CSS styles
    222         marginTop = editor.dom.getStyle(body, 'margin-top', true);
    223         marginBottom = editor.dom.getStyle(body, 'margin-bottom', true);
    224         myHeight = body.offsetHeight + parseInt(marginTop, 10) + parseInt(marginBottom, 10);
    225 
    226         // Make sure we have a valid height
    227         if (isNaN(myHeight) || myHeight <= 0) {
    228             // Get height differently depending on the browser used
    229             myHeight = tinymce.Env.ie ? body.scrollHeight : (tinymce.Env.webkit && body.clientHeight === 0 ? 0 : body.offsetHeight);
    230         }
    231 
    232         // Don't make it smaller than the minimum height
    233         if (myHeight > settings.autoresize_min_height) {
    234             resizeHeight = myHeight;
    235         }
    236 
    237         // If a maximum height has been defined don't exceed this height
    238         if (settings.autoresize_max_height && myHeight > settings.autoresize_max_height) {
    239             resizeHeight = settings.autoresize_max_height;
    240             body.style.overflowY = "auto";
    241             docElm.style.overflowY = "auto"; // Old IE
    242         } else {
    243             body.style.overflowY = "hidden";
    244             docElm.style.overflowY = "hidden"; // Old IE
    245             body.scrollTop = 0;
    246         }
    247 
    248         // Resize content element
    249         if (resizeHeight !== oldSize) {
    250             deltaSize = resizeHeight - oldSize;
    251             DOM.setStyle(DOM.get(editor.id + '_ifr'), 'height', resizeHeight + 'px');
    252             oldSize = resizeHeight;
    253 
    254             // WebKit doesn't decrease the size of the body element until the iframe gets resized
    255             // So we need to continue to resize the iframe down until the size gets fixed
    256             if (tinymce.isWebKit && deltaSize < 0) {
    257                 resize(e);
    258             }
    259         }
    260     }
    261 
    262     /**
    263      * Calls the resize x times in 100ms intervals. We can't wait for load events since
    264      * the CSS files might load async.
    265      */
    266     function wait( times, interval, callback ) {
    267         setTimeout( function() {
    268             resize({});
    269 
    270             if ( times-- ) {
    271                 wait( times, interval, callback );
    272             } else if ( callback ) {
    273                 callback();
    274             }
    275         }, interval );
    276     }
    277 
    278     // Define minimum height
    279     settings.autoresize_min_height = parseInt(editor.getParam('autoresize_min_height', editor.getElement().offsetHeight), 10);
    280 
    281     // Define maximum height
    282     settings.autoresize_max_height = parseInt(editor.getParam('autoresize_max_height', 0), 10);
    283 
    284     function on() {
    285         if ( ! editor.dom.hasClass( editor.getBody(), 'wp-autoresize' ) ) {
    286             editor.dom.addClass( editor.getBody(), 'wp-autoresize' );
    287             // Add appropriate listeners for resizing the content area
    288             editor.on( 'nodechange setcontent keyup FullscreenStateChanged', resize );
    289         }
    290     }
    291 
    292     function off() {
    293         // Don't turn off if the setting is 'on'
    294         if ( ! settings.wp_autoresize_on ) {
    295             editor.dom.removeClass( editor.getBody(), 'wp-autoresize' );
    296             editor.off( 'nodechange setcontent keyup FullscreenStateChanged', resize );
    297             oldSize = 0;
    298         }
    299     }
    300 
    301     if ( settings.wp_autoresize_on ) {
    302         // Turn resizing on when the editor loads
    303         editor.on( 'init', function() {
    304             editor.dom.addClass( editor.getBody(), 'wp-autoresize' );
    305         });
    306        
    307         editor.on( 'nodechange setcontent keyup FullscreenStateChanged', resize );
    308    
    309         if ( editor.getParam( 'autoresize_on_init', true ) ) {
    310             editor.on( 'init', function() {
    311                 // Hit it 20 times in 100 ms intervals
    312                 wait( 10, 200, function() {
    313                     // Hit it 5 times in 1 sec intervals
    314                     wait( 5, 1000 );
    315                 });
    316             });
    317         }
    318     }
    319 
    320     // Register the command
    321     editor.addCommand( 'wpAutoResize', resize );
    322 
    323     // On/off
    324     editor.addCommand( 'wpAutoResizeOn', on );
    325     editor.addCommand( 'wpAutoResizeOff', off );
    326 });
Note: See TracChangeset for help on using the changeset viewer.