Ticket #23042: 23042-2.patch
| File 23042-2.patch, 4.9 KB (added by azaozz, 5 months ago) |
|---|
-
wp-admin/js/post.js
685 685 686 686 // resizable textarea#content 687 687 (function() { 688 var textarea = $('textarea#content'), offset = null, el;688 var textarea = $('textarea#content'), handle; 689 689 // No point for touch devices 690 if ( 'ontouchstart' in window )690 if ( !textarea.length || 'ontouchstart' in window ) 691 691 return; 692 692 693 function dragging(e) { 694 textarea.height( Math.max(50, offset + e.pageY) + 'px' ); 695 return false; 696 } 693 textarea.css('resize', 'none'); 694 handle = $('<div id="content-resize-handle"><br></div>'); 695 $('#wp-content-wrap').append(handle); 697 696 698 function endDrag(e) {699 var height = $('#wp-content-editor-container').height();697 handle.on('mousedown', function(e) { 698 var height, offset = textarea.height() - e.pageY; 700 699 701 textarea.focus(); 702 $(document).unbind('mousemove', dragging).unbind('mouseup', endDrag); 700 textarea.blur(); 703 701 704 height -= 33; // compensate for toolbars, padding... 705 // sanity check 706 if ( height > 50 && height < 5000 && height != getUserSetting( 'ed_size' ) ) 707 setUserSetting( 'ed_size', height ); 708 } 702 $(document).on( 'mousemove.wp-editor-resize', function(e) { 703 height = Math.max(50, offset + e.pageY) 704 textarea.height( height ); 705 e.preventDefault(); 706 }).on( 'mouseup.wp-editor-resize', function(e) { 707 textarea.focus(); 708 $(document).off( '.wp-editor-resize' ); 709 709 710 textarea.css('resize', 'none');711 el = $('<div id="content-resize-handle"><br></div>');712 $('#wp-content-wrap').append(el); 713 el.on('mousedown', function(e) {714 offset = textarea.height() - e.pageY;715 textarea.blur();716 $(document).mousemove(dragging).mouseup(endDrag);717 return false;710 // compensate for textarea padding, 'height' has been set while dragging 711 height += 20; 712 713 // sanity check 714 if ( height > 50 && height < 5000 ) 715 setUserSetting( 'ed_size', height ); 716 }); 717 e.preventDefault(); // stop the browser selecting/highlighting elements 718 718 }); 719 719 })(); 720 720 721 721 if ( typeof(tinymce) != 'undefined' ) { 722 722 tinymce.onAddEditor.add(function(mce, ed){ 723 var get_textarea_height; 724 723 725 // iOS expands the iframe to full height and the user cannot adjust it. 724 726 if ( ed.id != 'content' || tinymce.isIOS5 ) 725 727 return; 726 728 729 get_textarea_height = function() { 730 var height, ifr_height = $('#content_ifr').height(), 731 tb_height = $('#content_tbl tr.mceFirst').height(); 732 733 if ( !ifr_height || !tb_height ) 734 return false; 735 736 // total height including toolbar and statusbar 737 height = ifr_height + tb_height + 21; 738 // textarea height = total height - 33px Quicktags toolbar 739 height -= 33; 740 741 return height; 742 } 743 727 744 // resize TinyMCE to match the textarea height when switching Text -> Visual 728 745 ed.onLoadContent.add( function(ed, o) { 729 var ifr_height, height = parseInt( $('#content').css('height'), 10 ), 746 var ifr_height, node = document.getElementById('content'), 747 height = node ? parseInt( node.style.height, 10 ) : 360, 730 748 tb_height = $('#content_tbl tr.mceFirst').height(); 731 749 732 if ( height && !isNaN(height) && tb_height ) { 750 if ( isNaN(height) || height < 50 || height > 5000 ) { 751 height = 360; // default height for the main editor 752 setUserSetting('ed_size', height); 753 } 754 755 if ( tb_height ) 733 756 ifr_height = (height - tb_height) + 12; // compensate for padding in the textarea 734 // sanity check 735 if ( ifr_height > 50 && ifr_height < 5000 ) { 736 $('#content_tbl').css('height', '' ); 737 $('#content_ifr').css('height', ifr_height + 'px' ); 738 } 757 else 758 ifr_height = 340; 759 760 // sanity check 761 if ( ifr_height > 50 && ifr_height < 5000 ) { 762 $('#content_tbl').css('height', '' ); 763 $('#content_ifr').css('height', ifr_height + 'px' ); 739 764 } 740 765 }); 741 766 742 767 // resize the textarea to match TinyMCE's height when switching Visual -> Text 743 768 ed.onSaveContent.add( function(ed, o) { 744 var height = $('#content_tbl').height();769 var height = get_textarea_height(); 745 770 746 if ( height && height > 83 && height < 5000 ) {747 height -= 33;771 if ( !height || height < 50 || height > 5000 ) 772 height = 360; 748 773 749 $('#content').css( 'height', height + 'px' ); 750 } 774 $('textarea#content').css( 'height', height + 'px' ); 751 775 }); 752 776 753 777 // save on resizing TinyMCE 754 778 ed.onPostRender.add(function() { 755 779 $('#content_resize').on('mousedown.wp-mce-resize', function(e){ 756 780 $(document).on('mouseup.wp-mce-resize', function(e){ 757 var height = $('#wp-content-editor-container').height();781 var height = get_textarea_height(); 758 782 759 height -= 33;760 783 // sanity check 761 if ( height > 50 && height < 5000 && height != getUserSetting( 'ed_size' ))784 if ( height && height > 50 && height < 5000 ) 762 785 setUserSetting( 'ed_size', height ); 763 786 764 787 $(document).off('mouseup.wp-mce-resize');
