Ticket #28328: 28328.19.patch
File 28328.19.patch, 8.2 KB (added by , 11 years ago) |
---|
-
src/wp-admin/css/edit.css
378 378 overflow: hidden; 379 379 } 380 380 381 .wp-fullscreen-wrap #content-textarea-clone { 382 display: none; 383 } 384 381 385 #timestampdiv select { 382 386 height: 21px; 383 387 line-height: 14px; -
src/wp-admin/js/editor-expand.js
1 /* global tinymce */1 /* global tinymce, console */ 2 2 3 3 window.wp = window.wp || {}; 4 4 … … 12 12 $visualEditor, 13 13 $textTop = $( '#ed_toolbar' ), 14 14 $textEditor = $( '#content' ), 15 textEditorPaddingTop = parseInt( $textEditor.css( 'padding-top' ), 10 ), 15 16 $textEditorClone = $( '<div id="content-textarea-clone"></div>' ), 16 17 $bottom = $( '#post-status-info' ), 17 18 $statusBar, … … 42 43 } ); 43 44 44 45 $textEditor.on( 'keyup', function() { 45 var range = document.createRange(), 46 var VK = tinymce.util.VK, 47 key = event.keyCode, 48 range = document.createRange(), 46 49 start = $textEditor[0].selectionStart, 47 50 end = $textEditor[0].selectionEnd, 48 51 textNode = $textEditorClone[0].firstChild, 49 52 windowHeight = $window.height(), 53 buffer = 10, 50 54 offset, cursorTop, cursorBottom, editorTop, editorBottom; 51 55 52 56 if ( start && end && start !== end ) { 53 57 return; 54 58 } 55 59 56 range.setStart( textNode, start ); 57 range.setEnd( textNode, end + 1 ); 60 // These are not TinyMCE ranges. 61 try { 62 range.setStart( textNode, start ); 63 range.setEnd( textNode, end + 1 ); 64 } catch ( e ) { 65 console.log( e ); 66 } 58 67 59 68 offset = range.getBoundingClientRect(); 60 69 … … 62 71 return; 63 72 } 64 73 65 cursorTop = offset.top ;66 cursorBottom = cursorTop + offset.height ;67 editorTop = $adminBar.outerHeight() + $t extTop.outerHeight();74 cursorTop = offset.top - buffer; 75 cursorBottom = cursorTop + offset.height + buffer; 76 editorTop = $adminBar.outerHeight() + $tools.outerHeight() + $textTop.outerHeight(); 68 77 editorBottom = windowHeight - $bottom.outerHeight(); 69 78 70 if ( cursorTop < editorTop || cursorBottom > editorBottom ) { 71 window.scrollTo( window.pageXOffset, cursorTop + window.pageYOffset - windowHeight / 2 ); 79 if ( cursorTop < editorTop && ( key === VK.UP || key === VK.LEFT || key === VK.BACKSPACE ) ) { 80 window.scrollTo( window.pageXOffset, cursorTop + window.pageYOffset - editorTop ); 81 } else if ( cursorBottom > editorBottom ) { 82 window.scrollTo( window.pageXOffset, cursorBottom + window.pageYOffset - editorBottom ); 72 83 } 73 84 } ); 74 85 … … 77 88 return; 78 89 } 79 90 80 var hiddenHeight = $textEditorClone.width( $textEditor.width() ).text( $textEditor.val() + ' ' ).height(), 81 textEditorHeight = $textEditor.height(); 91 var textEditorHeight = $textEditor.height(), 92 hiddenHeight; 93 94 $textEditorClone.width( $textEditor.width() ); 95 $textEditorClone.text( $textEditor.val() + ' ' ); 96 97 hiddenHeight = $textEditorClone.height(); 82 98 83 99 if ( hiddenHeight < 300 ) { 84 100 hiddenHeight = 300; … … 90 106 91 107 $textEditor.height( hiddenHeight ); 92 108 93 adjust( 'resize');109 adjust( true ); 94 110 } 95 111 96 112 // We need to wait for TinyMCE to initialize. … … 118 134 editor.on( 'show', function() { 119 135 setTimeout( function() { 120 136 editor.execCommand( 'wpAutoResize' ); 121 adjust( 'resize');137 adjust( true ); 122 138 }, 200 ); 123 139 } ); 124 140 … … 195 211 196 212 editor.on( 'hide', function() { 197 213 textEditorResize(); 198 adjust( 'resize');214 adjust( true ); 199 215 } ); 200 216 201 217 // Adjust when the editor resizes. 202 editor.on( 'nodechange setcontent keyup FullscreenStateChanged', function() { 203 adjust( 'resize' ); 204 } ); 205 206 editor.on( 'wp-toolbar-toggle', function() { 207 $visualEditor.css( { 208 paddingTop: $visualTop.outerHeight() 209 } ); 218 editor.on( 'nodechange setcontent keyup FullscreenStateChanged wp-toolbar-toggle', function() { 219 adjust( true ); 210 220 } ); 211 221 212 222 // And adjust "immediately". 213 223 // Allow some time to load CSS etc. 214 224 setTimeout( function() { 215 $visualEditor.css( { 216 paddingTop: $visualTop.outerHeight() 217 } ); 218 219 adjust( 'resize' ); 225 adjust( true ); 220 226 }, 500 ); 221 227 } ); 222 228 223 229 // Adjust when the window is scrolled or resized. 224 230 $window.on( 'scroll resize', function( event ) { 225 adjust( event.type );231 adjust( event.type === 'resize' ); 226 232 } ); 227 233 228 // Adjust when e xiting fullscreen mode.234 // Adjust when entering/exiting fullscreen mode. 229 235 fullscreen && fullscreen.pubsub.subscribe( 'hidden', function() { 230 adjust( 'resize' ); 236 textEditorResize(); 237 adjust( true ); 231 238 } ); 232 239 233 240 // Adjust when collapsing the menu. 234 241 $document.on( 'wp-collapse-menu.editor-expand', function() { 235 adjust( 'resize');242 adjust( true ); 236 243 } ) 237 244 238 245 // Adjust when changing the columns. 239 246 .on( 'postboxes-columnchange.editor-expand', function() { 240 adjust( 'resize');247 adjust( true ); 241 248 } ) 242 249 243 250 // Adjust when changing the body class. 244 251 .on( 'editor-classchange.editor-expand', function() { 245 adjust( 'resize');252 adjust( true ); 246 253 } ); 247 254 248 255 // Adjust the toolbars based on the active editor mode. 249 function adjust( eventType ) {256 function adjust( resize ) { 250 257 // Make sure we're not in fullscreen mode. 251 258 if ( fullscreen && fullscreen.settings.visible ) { 252 259 return; … … 287 294 statusBarHeight = visual ? $statusBar.outerHeight() : 0; 288 295 289 296 // Maybe pin the top. 290 if ( ( ! fixedTop || eventType === 'resize') &&297 if ( ( ! fixedTop || resize ) && 291 298 // Handle scrolling down. 292 299 ( windowPos >= ( topPos - toolsHeight - adminBarHeight ) && 293 300 // Handle scrolling up. … … 307 314 width: editorWidth + 2 308 315 } ); 309 316 // Maybe unpin the top. 310 } else if ( fixedTop || eventType === 'resize') {317 } else if ( fixedTop || resize ) { 311 318 // Handle scrolling up. 312 319 if ( windowPos <= ( topPos - toolsHeight - adminBarHeight ) ) { 313 320 fixedTop = false; … … 342 349 } 343 350 344 351 // Maybe adjust the bottom bar. 345 if ( ( ! fixedBottom || eventType === 'resize') &&352 if ( ( ! fixedBottom || resize ) && 346 353 // + 1 for the border around the .wp-editor-container. 347 354 ( windowPos + windowHeight ) <= ( editorPos + editorHeight + bottomHeight + statusBarHeight + 1 ) ) { 348 355 fixedBottom = true; … … 353 360 width: editorWidth + 2, 354 361 borderTop: '1px solid #dedede' 355 362 } ); 356 } else if ( fixedBottom&&363 } else if ( ( fixedBottom || resize ) && 357 364 ( windowPos + windowHeight ) > ( editorPos + editorHeight + bottomHeight + statusBarHeight - 1 ) ) { 358 365 fixedBottom = false; 359 366 … … 364 371 borderTop: 'none' 365 372 } ); 366 373 } 374 375 if ( resize ) { 376 $contentWrap.css( { 377 paddingTop: $tools.outerHeight() 378 } ); 379 380 if ( visual ) { 381 $visualEditor.css( { 382 paddingTop: $visualTop.outerHeight() 383 } ); 384 } else { 385 $textEditor.add( $textEditorClone ).css( { 386 paddingTop: $textTop.outerHeight() + textEditorPaddingTop 387 } ); 388 $textEditorClone.width( $textEditor.width() ); 389 } 390 } 367 391 } 368 392 369 393 textEditorResize(); 370 394 371 $tools.css( { 372 position: 'absolute', 373 top: 0, 374 width: $contentWrap.width() 375 } ); 395 adjust( true ); 376 396 377 $contentWrap.css( { 378 paddingTop: $tools.outerHeight() 379 } ); 380 381 // This needs to execute after quicktags is ready or a button is added... 397 // Ideally we need to resize just after QuickTags is ready. 382 398 setTimeout( function() { 383 $textEditor.css( { 384 paddingTop: $textTop.outerHeight() + parseInt( $textEditor.css( 'padding-top' ), 10 ) 385 } ); 399 adjust( true ); 386 400 }, 500 ); 387 401 }); -
src/wp-includes/css/editor.css
757 757 position: relative; 758 758 } 759 759 760 /* editor-expand.js override */ 761 .wp-fullscreen-wrap { 762 padding-top: 0 !important; 763 } 764 760 765 #wp-content-editor-tools { 761 766 background-color: #f1f1f1; 762 767 padding-top: 20px; … … 789 794 box-sizing: border-box; 790 795 } 791 796 797 /* editor-expand.js override */ 798 .wp-fullscreen-wrap .wp-editor-area { 799 padding-top: 10px !important; 800 } 801 802 /* editor-expand.js override */ 803 .wp-fullscreen-wrap .mce-edit-area { 804 padding-top: 0 !important; 805 } 806 792 807 .wp-editor-container textarea.wp-editor-area { 793 808 width: 100%; 794 809 margin: 0;