diff --git a/src/wp-includes/js/tinymce/plugins/wordpress/plugin.js b/src/wp-includes/js/tinymce/plugins/wordpress/plugin.js index 743ad86c88..f4f7178478 100644 --- a/src/wp-includes/js/tinymce/plugins/wordpress/plugin.js +++ b/src/wp-includes/js/tinymce/plugins/wordpress/plugin.js @@ -278,7 +278,7 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { editor.on( 'init', function() { var env = tinymce.Env, bodyClass = ['mceContentBody'], // back-compat for themes that use this in editor-style.css... - body = editor.getBody(); + doc = editor.getDoc(); if ( editor.getParam( 'directionality' ) === 'rtl' ) { bodyClass.push('rtl'); @@ -298,7 +298,7 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { tinymce.each( bodyClass, function( cls ) { if ( cls ) { - editor.dom.addClass( body, cls ); + editor.dom.addClass( doc.body, cls ); } }); @@ -314,6 +314,44 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { if ( typeof window.jQuery !== 'undefined' ) { window.jQuery( document ).triggerHandler( 'tinymce-editor-init', [editor] ); } + + // When scrolling with mouse wheel or trackpad inside the editor, don't scroll the parent window + editor.dom.bind( doc, 'onwheel' in doc ? 'wheel' : 'mousewheel', function( event ) { + var delta, docElement = doc.documentElement; + + if ( editor.settings.wp_fullscreen || 'ontouchstart' in window ) { + return; + } + + if ( typeof event.deltaY !== 'undefined' ) { + delta = event.deltaY; + + if ( typeof event.deltaMode !== 'undefined' && event.deltaMode === event.DOM_DELTA_LINE ) { + delta *= 20; + } + } else { + delta = -event.wheelDelta; + } + + // Reverse direction for MacOS + if ( env.mac ) { + delta *= -1; + } + + event.preventDefault(); + + if ( ( docElement.scrollTop === 0 && delta < 0 ) || + ( docElement.clientHeight + docElement.scrollTop === docElement.scrollHeight && delta > 0 ) ) { + + return; + } + + if ( env.webkit ) { + doc.body.scrollTop += delta; + } else { + docElement.scrollTop += delta; + } + }); }); // Word count