From 957beec4dee18497cb24f73ec2db035d4c71d898 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Mon, 3 Mar 2014 02:33:22 +0000 Subject: [PATCH] Editor: throttle scrolling of the main window when the editor is active and is being scrolled with the mouse wheel or a trackpad, see #27013 git-svn-id: https://develop.svn.wordpress.org/trunk@27368 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/js/post.js | 32 +++++++++++++++-- .../js/tinymce/plugins/wordpress/plugin.js | 35 ++++++++++++++++--- src/wp-includes/version.php | 4 +-- 3 files changed, 63 insertions(+), 8 deletions(-) diff --git a/src/wp-admin/js/post.js b/src/wp-admin/js/post.js index 2786cb6239..c847cd4134 100644 --- a/src/wp-admin/js/post.js +++ b/src/wp-admin/js/post.js @@ -370,7 +370,8 @@ $(document).on( 'heartbeat-send.refresh-lock', function( e, data ) { }(jQuery)); jQuery(document).ready( function($) { - var stamp, visibility, $submitButtons, updateVisibility, updateText, $content, + var stamp, visibility, $submitButtons, updateVisibility, updateText, $content, topx, reset, + deltax = 0, sticky = '', last = 0, co = $('#content'), @@ -1067,12 +1068,18 @@ jQuery(document).ready( function($) { if ( ! ( 'ontouchstart' in window ) ) { // When scrolling with mouse wheel or trackpad inside the Text editor, don't scroll the whole window $content = $('#content').on( 'onwheel' in $document[0] ? 'wheel.text-editor-scroll' : 'mousewheel.text-editor-scroll', function( event ) { - var delta, origEvent = event.originalEvent; + var delta, top, + origEvent = event.originalEvent; if ( wp.editor && wp.editor.fullscreen.settings.visible ) { return; } + // Don't modify scrolling when the Text editor is not active. + if ( document.activeElement && document.activeElement.id !== 'content' ) { + return; + } + if ( typeof origEvent.deltaY !== 'undefined' ) { delta = origEvent.deltaY; @@ -1084,6 +1091,27 @@ jQuery(document).ready( function($) { } $content.scrollTop( $content.scrollTop() + delta ); + + top = $content.scrollTop(); + + if ( topx === top ) { + deltax += delta; + + window.clearTimeout( reset ); + reset = window.setTimeout( function() { + deltax = 0; + }, 1000 ); + } else { + deltax = 0; + } + + topx = top; + + // Sensitivity: scroll the parent window when over-scrolling by more than 800px + if ( deltax > 1000 || deltax < -1000 ) { + return; + } + event.preventDefault(); }); } diff --git a/src/wp-includes/js/tinymce/plugins/wordpress/plugin.js b/src/wp-includes/js/tinymce/plugins/wordpress/plugin.js index 707656c4c4..359a46964e 100644 --- a/src/wp-includes/js/tinymce/plugins/wordpress/plugin.js +++ b/src/wp-includes/js/tinymce/plugins/wordpress/plugin.js @@ -276,7 +276,8 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { }); editor.on( 'init', function() { - var env = tinymce.Env, + var env = tinymce.Env, topx, reset, + deltax = 0, bodyClass = ['mceContentBody'], // back-compat for themes that use this in editor-style.css... doc = editor.getDoc(); @@ -318,11 +319,16 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { if ( ! ( 'ontouchstart' in window ) ) { // 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; + var delta, top, + docElement = doc.documentElement; if ( editor.settings.wp_fullscreen ) { return; } + // Don't modify scrolling when the editor is not active. + if ( typeof doc.hasFocus === 'function' && ! doc.hasFocus() ) { + return; + } if ( typeof event.deltaY !== 'undefined' ) { delta = event.deltaY; @@ -334,13 +340,34 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { delta = -event.wheelDelta; } - event.preventDefault(); - if ( env.webkit ) { doc.body.scrollTop += delta; } else { docElement.scrollTop += delta; } + + top = docElement.scrollTop || doc.body.scrollTop; + + if ( topx === top ) { + deltax += delta; + + window.clearTimeout( reset ); + // Sensitivity: delay before resetting the count of over-scroll pixels + reset = window.setTimeout( function() { + deltax = 0; + }, 1000 ); + } else { + deltax = 0; + } + + topx = top; + + // Sensitivity: scroll the parent window when over-scrolling by more than 1000px + if ( deltax > 1000 || deltax < -1000 ) { + return; + } + + event.preventDefault(); }); } }); diff --git a/src/wp-includes/version.php b/src/wp-includes/version.php index ecd10c5a8d..627cb21cc9 100644 --- a/src/wp-includes/version.php +++ b/src/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '3.9-alpha-27234-src'; +$wp_version = '3.9-alpha-27368-src'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. @@ -18,7 +18,7 @@ $wp_db_version = 26691; * * @global string $tinymce_version */ -$tinymce_version = '4016-20140211'; +$tinymce_version = '4016-20140302'; /** * Holds the required PHP version