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

Built from https://develop.svn.wordpress.org/trunk@27368


git-svn-id: http://core.svn.wordpress.org/trunk@27218 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz 2014-03-03 02:34:14 +00:00
parent 83a0b00489
commit cab6362f2b
6 changed files with 65 additions and 10 deletions

View File

@ -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();
});
}

File diff suppressed because one or more lines are too long

View File

@ -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();
});
}
});

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '3.9-alpha-27234';
$wp_version = '3.9-alpha-27368';
/**
* 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