From 89b8edf8f1cf45e501e2747690ab1c0ba06c3e43 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Wed, 5 Feb 2014 01:09:42 +0000 Subject: [PATCH] TinyMCE: don't scroll the main window when scrolling the editor content with a mouse wheel or trackpad and reaching the end. Fixes #27013. git-svn-id: https://develop.svn.wordpress.org/trunk@27095 602fd350-edb4-49c9-b593-d223f7449a82 --- .../js/tinymce/plugins/wordpress/plugin.js | 42 ++++++++++++++++++- 1 file changed, 40 insertions(+), 2 deletions(-) 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