diff --git a/src/wp-admin/js/post.js b/src/wp-admin/js/post.js index 03211b7a39..d95aea6530 100644 --- a/src/wp-admin/js/post.js +++ b/src/wp-admin/js/post.js @@ -374,6 +374,7 @@ jQuery(document).ready( function($) { sticky = '', last = 0, co = $('#content'), + $document = $(document), $editSlugWrap = $('#edit-slug-box'), postId = $('#post_ID').val() || 0, $submitpost = $('#submitpost'), @@ -509,7 +510,7 @@ jQuery(document).ready( function($) { }); } - $(document).on( 'autosave-disable-buttons.edit-post', function() { + $document.on( 'autosave-disable-buttons.edit-post', function() { $submitButtons.addClass( 'disabled' ); }).on( 'autosave-enable-buttons.edit-post', function() { if ( ! wp.heartbeat || ! wp.heartbeat.hasConnectionError() ) { @@ -940,7 +941,7 @@ jQuery(document).ready( function($) { // word count if ( typeof(wpWordCount) != 'undefined' ) { - $(document).triggerHandler('wpcountwords', [ co.val() ]); + $document.triggerHandler('wpcountwords', [ co.val() ]); co.keyup( function(e) { var k = e.keyCode || e.charCode; @@ -949,7 +950,7 @@ jQuery(document).ready( function($) { return true; if ( 13 == k || 8 == last || 46 == last ) - $(document).triggerHandler('wpcountwords', [ co.val() ]); + $document.triggerHandler('wpcountwords', [ co.val() ]); last = k; return true; @@ -985,7 +986,6 @@ jQuery(document).ready( function($) { // Resize the visual and text editors ( function() { var editor, offset, mce, - $document = $( document ), $textarea = $('textarea#content'), $handle = $('#post-status-info'); @@ -1063,4 +1063,28 @@ 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 + var $content = $('#content').on( 'onwheel' in $document[0] ? 'wheel.text-editor-scroll' : 'mousewheel.text-editor-scroll', function( event ) { + var delta, origEvent = event.originalEvent; + + if ( wp.editor && wp.editor.fullscreen.settings.visible ) { + return; + } + + if ( typeof origEvent.deltaY !== 'undefined' ) { + delta = origEvent.deltaY; + + if ( typeof origEvent.deltaMode !== 'undefined' && origEvent.deltaMode === origEvent.DOM_DELTA_LINE ) { + delta *= 20; + } + } else { + delta = -origEvent.wheelDelta; + } + + $content.scrollTop( $content.scrollTop() + delta ); + 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 f4f7178478..c6cde9bac8 100644 --- a/src/wp-includes/js/tinymce/plugins/wordpress/plugin.js +++ b/src/wp-includes/js/tinymce/plugins/wordpress/plugin.js @@ -315,43 +315,34 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) { 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 ( ! ( '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; - 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; + if ( editor.settings.wp_fullscreen ) { + return; } - } else { - delta = -event.wheelDelta; - } - // Reverse direction for MacOS - if ( env.mac ) { - delta *= -1; - } + if ( typeof event.deltaY !== 'undefined' ) { + delta = event.deltaY; - event.preventDefault(); + if ( typeof event.deltaMode !== 'undefined' && event.deltaMode === event.DOM_DELTA_LINE ) { + delta *= 20; + } + } else { + delta = -event.wheelDelta; + } - if ( ( docElement.scrollTop === 0 && delta < 0 ) || - ( docElement.clientHeight + docElement.scrollTop === docElement.scrollHeight && delta > 0 ) ) { + event.preventDefault(); - return; - } - - if ( env.webkit ) { - doc.body.scrollTop += delta; - } else { - docElement.scrollTop += delta; - } - }); + if ( env.webkit ) { + doc.body.scrollTop += delta; + } else { + docElement.scrollTop += delta; + } + }); + } }); // Word count