Ticket #32706: 32706.1.patch
File 32706.1.patch, 7.0 KB (added by , 10 years ago) |
---|
-
src/wp-admin/css/press-this.css
2038 2038 top: -1px; 2039 2039 margin-left: 11px; 2040 2040 } 2041 2042 /* Text editor */ 2043 #pressthis { 2044 color: #404040; 2045 resize: none; 2046 } 2047 2048 .wp-editor-wrap .quicktags-toolbar { 2049 background: transparent; 2050 border: none; 2051 } -
src/wp-admin/includes/class-wp-press-this.php
1376 1376 'toolbar1' => 'bold,italic,bullist,numlist,blockquote,link,unlink', 1377 1377 'toolbar2' => 'undo,redo', 1378 1378 ), 1379 'quicktags' => false, 1379 'quicktags' => true, 1380 'default_editor' => 'tinymce', 1380 1381 ) ); 1381 1382 1382 1383 ?> -
src/wp-admin/js/press-this.js
5 5 ( function( $, window ) { 6 6 var PressThis = function() { 7 7 var editor, $mediaList, $mediaThumbWrap, 8 $window = $( window ), 9 $document = $( document ), 8 10 saveAlert = false, 9 11 editLinkVisible = false, 10 12 textarea = document.createElement( 'textarea' ), … … 17 19 isOffScreen = 'is-off-screen', 18 20 isHidden = 'is-hidden', 19 21 offscreenHidden = isOffScreen + ' ' + isHidden, 22 $textEditor = $( '#pressthis' ), 23 textEditor = $textEditor[0], 24 textLength = 0, 20 25 transitionEndEvent = ( function() { 21 26 var style = document.documentElement.style; 22 27 … … 114 119 $( '.post-actions button' ).removeAttr( 'disabled' ); 115 120 } 116 121 122 function textEditorResize( reset ) { 123 var pageYOffset, height; 124 125 if ( editor && ! editor.isHidden() ) { 126 return; 127 } 128 129 reset = ( reset === 'reset' ) || ( textLength && textLength > textEditor.value.length ); 130 height = textEditor.style.height; 131 132 if ( reset ) { 133 pageYOffset = window.pageYOffset; 134 135 textEditor.style.height = 'auto'; 136 textEditor.style.height = textEditor.scrollHeight + 'px'; 137 window.scrollTo( window.pageXOffset, pageYOffset ); 138 } else if ( parseInt( textEditor.style.height, 10 ) < textEditor.scrollHeight ) { 139 textEditor.style.height = textEditor.scrollHeight + 'px'; 140 } 141 142 textLength = textEditor.value.length; 143 } 144 145 function mceGetCursorOffset() { 146 if ( ! editor ) { 147 return false; 148 } 149 150 var node = editor.selection.getNode(), 151 range, view, offset; 152 153 if ( editor.wp && editor.wp.getView && ( view = editor.wp.getView( node ) ) ) { 154 offset = view.getBoundingClientRect(); 155 } else { 156 range = editor.selection.getRng(); 157 158 try { 159 offset = range.getClientRects()[0]; 160 } catch( er ) {} 161 162 if ( ! offset ) { 163 offset = node.getBoundingClientRect(); 164 } 165 } 166 167 return offset.height ? offset : false; 168 } 169 170 // Make sure the caret is always visible. 171 function mceKeyup( event ) { 172 var VK = window.tinymce.util.VK, 173 key = event.keyCode; 174 175 // Bail on special keys. 176 if ( key <= 47 && ! ( key === VK.SPACEBAR || key === VK.ENTER || key === VK.DELETE || key === VK.BACKSPACE || key === VK.UP || key === VK.LEFT || key === VK.DOWN || key === VK.UP ) ) { 177 return; 178 // OS keys, function keys, num lock, scroll lock 179 } else if ( ( key >= 91 && key <= 93 ) || ( key >= 112 && key <= 123 ) || key === 144 || key === 145 ) { 180 return; 181 } 182 183 mceScroll( key ); 184 } 185 186 function mceScroll( key ) { 187 var cursorTop, cursorBottom, editorTop, editorBottom, 188 offset = mceGetCursorOffset(), 189 bufferTop = 50, 190 bufferBottom = 65, 191 VK = window.tinymce.util.VK; 192 193 if ( ! offset ) { 194 return; 195 } 196 197 cursorTop = offset.top + editor.iframeElement.getBoundingClientRect().top; 198 cursorBottom = cursorTop + offset.height; 199 cursorTop = cursorTop - bufferTop; 200 cursorBottom = cursorBottom + bufferBottom; 201 editorBottom = $window.height(); 202 203 // Don't scroll if the node is taller than the visible part of the editor 204 if ( editorBottom < offset.height ) { 205 return; 206 } 207 208 if ( cursorTop < 0 && ( key === VK.UP || key === VK.LEFT || key === VK.BACKSPACE ) ) { 209 window.scrollTo( window.pageXOffset, cursorTop + window.pageYOffset ); 210 } else if ( cursorBottom > editorBottom ) { 211 window.scrollTo( window.pageXOffset, cursorBottom + window.pageYOffset - editorBottom ); 212 } 213 } 214 117 215 /** 118 216 * Replace emoji images with chars and sanitize the text content. 119 217 */ … … 256 354 newContent = '[embed]' + src + '[/embed]'; 257 355 } 258 356 259 if ( ! hasSetFocus ) { 260 editor.setContent( '<p>' + newContent + '</p>' + editor.getContent() ); 261 } else { 262 editor.execCommand( 'mceInsertContent', false, newContent ); 357 if ( ! editor.isHidden() ) { 358 if ( ! hasSetFocus ) { 359 editor.setContent( '<p>' + newContent + '</p>' + editor.getContent() ); 360 } else { 361 editor.execCommand( 'mceInsertContent', false, newContent ); 362 } 363 } else if ( window.QTags ) { 364 window.QTags.insertContent( newContent ); 263 365 } 264 366 } 265 367 … … 648 750 * Set app events and other state monitoring related code. 649 751 */ 650 752 function monitor() { 651 $ ( document ).on( 'tinymce-editor-init', function( event, ed ) {753 $document.on( 'tinymce-editor-init', function( event, ed ) { 652 754 editor = ed; 653 755 654 756 editor.on( 'nodechange', function() { … … 655 757 hasSetFocus = true; 656 758 resetDraftButton(); 657 759 } ); 760 761 editor.on( 'show', function() { 762 setTimeout( function() { 763 editor.execCommand( 'wpAutoResize' ); 764 }, 300 ); 765 }); 766 767 editor.on( 'hide', function() { 768 setTimeout( function() { 769 textEditorResize( 'reset' ); 770 }, 100 ); 771 }); 772 773 editor.on( 'keyup', mceKeyup ); 774 editor.on( 'undo redo', mceScroll ); 775 658 776 }).on( 'click.press-this keypress.press-this', '.suggested-media-thumbnail', function( event ) { 659 777 if ( event.type === 'click' || event.keyCode === 13 ) { 660 778 insertSelectedMedia( $( this ) ); … … 722 840 } 723 841 } ); 724 842 725 $ ( window ).on( 'beforeunload.press-this', function() {843 $window.on( 'beforeunload.press-this', function() { 726 844 if ( saveAlert || ( editor && editor.isDirty() ) ) { 727 845 return __( 'saveAlert' ); 728 846 } 729 } ); 847 } ).on( 'resize.press-this', function() { 848 textEditorResize( 'reset' ); 849 }); 730 850 731 851 $( 'button.add-cat-toggle' ).on( 'click.press-this', function() { 732 852 var $this = $( this ); … … 761 881 } 762 882 } ); 763 883 884 $textEditor.on( 'focus.press-this input.press-this propertychange.press-this', textEditorResize ); 885 764 886 return true; 765 887 } 766 888 … … 777 899 } 778 900 779 901 // Let's go! 780 $ ( document ).ready( function() {902 $document.ready( function() { 781 903 render(); 782 904 monitor(); 783 905 refreshCatsCache();