Ticket #36482: 36482.2.patch
File 36482.2.patch, 4.8 KB (added by , 9 years ago) |
---|
-
src/wp-admin/css/edit.css
383 383 top: 0; 384 384 visibility: hidden; 385 385 overflow: hidden; 386 max-width: 100%;387 border: 1px solid transparent;388 386 } 389 387 390 388 .wp-editor-expand #wp-content-editor-tools { -
src/wp-admin/js/editor-expand.js
15 15 $visualEditor = $(), 16 16 $textTop = $( '#ed_toolbar' ), 17 17 $textEditor = $( '#content' ), 18 textEditor = $textEditor[0], 19 textEditorLength = 0, 18 20 $textEditorClone = $( '<div id="content-textarea-clone" class="wp-exclude-emoji"></div>' ), 21 textEditorClonelineHeight = parseInt( $textEditor.css( 'line-height' ), 10 ), 19 22 $bottom = $( '#post-status-info' ), 20 23 $menuBar = $(), 21 24 $statusBar = $(), … … 87 90 function textEditorKeyup( event ) { 88 91 var VK = jQuery.ui.keyCode, 89 92 key = event.keyCode, 90 range = document.createRange(),91 selStart = $textEditor[0].selectionStart,92 selEnd = $textEditor[0].selectionEnd,93 textNode = $textEditorClone[0].firstChild,94 93 buffer = 10, 95 offset , cursorTop, cursorBottom, editorTop, editorBottom;94 offset; 96 95 97 if ( selStart && selEnd && selStart !== selEnd) {96 if ( key !== VK.UP && key !== VK.LEFT && key !== VK.BACKSPACE ) { 98 97 return; 99 98 } 100 99 101 // These are not TinyMCE ranges. 102 try { 103 range.setStart( textNode, selStart ); 104 range.setEnd( textNode, selEnd + 1 ); 105 } catch ( ex ) {} 100 $textEditorClone.text( $textEditor.val().substring( 0, $textEditor[0].selectionStart ) || '.' ); 106 101 107 offset = range.getBoundingClientRect(); 102 offset = 103 $textEditor.offset().top + 104 $textEditorClone.height() - 105 textEditorClonelineHeight - 106 window.pageYOffset - 107 heights.adminBarHeight - 108 heights.toolsHeight - 109 heights.textTopHeight; 108 110 109 if ( ! offset.height ) { 110 return; 111 } 112 113 cursorTop = offset.top - buffer; 114 cursorBottom = cursorTop + offset.height + buffer; 115 editorTop = heights.adminBarHeight + heights.toolsHeight + heights.textTopHeight; 116 editorBottom = heights.windowHeight - heights.bottomHeight; 117 118 if ( cursorTop < editorTop && ( key === VK.UP || key === VK.LEFT || key === VK.BACKSPACE ) ) { 119 window.scrollTo( window.pageXOffset, cursorTop + window.pageYOffset - editorTop ); 120 } else if ( cursorBottom > editorBottom ) { 121 window.scrollTo( window.pageXOffset, cursorBottom + window.pageYOffset - editorBottom ); 111 if ( offset < buffer ) { 112 window.scrollTo( window.pageXOffset, window.pageYOffset + offset ); 122 113 } 123 114 } 124 115 125 116 function textEditorResize() { 117 var pageYOffset, height, 118 reduce = textEditorLength && textEditorLength > textEditor.value.length; 119 126 120 if ( ( mceEditor && ! mceEditor.isHidden() ) || ( ! mceEditor && initialMode === 'tinymce' ) ) { 127 121 return; 128 122 } 129 123 130 var textEditorHeight = $textEditor.height(),131 hiddenHeight;124 textEditorLength = textEditor.value.length; 125 height = textEditor.style.height; 132 126 133 $textEditorClone.width( $textEditor.width() - 22 );134 $textEditorClone.text( $textEditor.val() + ' ' );127 if ( reduce ) { 128 pageYOffset = window.pageYOffset; 135 129 136 hiddenHeight = $textEditorClone.height(); 130 textEditor.style.height = 'auto'; 131 textEditor.style.height = textEditor.scrollHeight + 'px'; 137 132 138 if ( hiddenHeight < autoresizeMinHeight ) { 139 hiddenHeight = autoresizeMinHeight; 133 window.scrollTo( window.pageXOffset, pageYOffset ); 134 } else if ( parseInt( textEditor.style.height, 10 ) < textEditor.scrollHeight ) { 135 textEditor.style.height = textEditor.scrollHeight + 'px'; 140 136 } 141 137 142 if ( h iddenHeight === textEditorHeight ) {143 return;138 if ( height !== textEditor.style.height ) { 139 adjust(); 144 140 } 145 146 $textEditor.height( hiddenHeight );147 148 adjust();149 141 } 150 142 151 143 // We need to wait for TinyMCE to initialize. … … 474 466 475 467 if ( event && event.deltaHeight > 0 && event.deltaHeight < 100 ) { 476 468 window.scrollBy( 0, event.deltaHeight ); 477 } else if ( advanced ) {469 } else if ( visual && advanced ) { 478 470 fixedBottom = true; 479 471 480 472 $statusBar.css( { … … 604 596 marginTop: heights.textTopHeight 605 597 } ); 606 598 607 $textEditorClone.width( contentWrapWidth - 20 - ( borderWidth * 2) );599 $textEditorClone.width( $textEditor.width() ); 608 600 } 609 601 } 610 602 } … … 660 652 }); 661 653 662 654 $textEditor.on( 'focus.editor-expand input.editor-expand propertychange.editor-expand', textEditorResize ); 663 $textEditor.on( 'keyup.editor-expand', textEditorKeyup);655 $textEditor.on( 'keyup.editor-expand', _.debounce( textEditorKeyup, 500 ) ); 664 656 mceBind(); 665 657 666 658 // Adjust when entering/exiting fullscreen mode.