From aa6e844435d7975869d33c95a36a15b87a911502 Mon Sep 17 00:00:00 2001 From: Ella Iseulde Van Dorpe Date: Wed, 1 Jun 2016 10:23:17 +0000 Subject: [PATCH] Editor: autoresize fixes for text * Resize on backspace. * Don't make it smaller than the minimum height. Props azaozz, iseulde. See #36482. git-svn-id: https://develop.svn.wordpress.org/trunk@37603 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/js/bookmarklet.min.js | 2 +- src/wp-admin/js/editor-expand.js | 29 +++++++++++++++++++---------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/wp-admin/js/bookmarklet.min.js b/src/wp-admin/js/bookmarklet.min.js index 7f0a3d21f0..089a849516 100644 --- a/src/wp-admin/js/bookmarklet.min.js +++ b/src/wp-admin/js/bookmarklet.min.js @@ -1 +1 @@ -(function(a,b,c,d){function e(a,c){if("undefined"!=typeof c){var d=b.createElement("input");d.name=a,d.value=c,d.type="hidden",p.appendChild(d)}}var f,g,h,i,j,k,l,m,n,o=a.encodeURIComponent,p=b.createElement("form"),q=b.getElementsByTagName("head")[0],r="_press_this_app",s=!0;if(d){if(!c.match(/^https?:/))return void(top.location.href=d);if(d+="&u="+o(c),c.match(/^https:/)&&d.match(/^http:/)&&(s=!1),a.getSelection?h=a.getSelection()+"":b.getSelection?h=b.getSelection()+"":b.selection&&(h=b.selection.createRange().text||""),d+="&buster="+(new Date).getTime(),s||(b.title&&(d+="&t="+o(b.title.substr(0,256))),h&&(d+="&s="+o(h.substr(0,512)))),f=a.outerWidth||b.documentElement.clientWidth||600,g=a.outerHeight||b.documentElement.clientHeight||700,f=800>f||f>5e3?600:.7*f,g=800>g||g>3e3?700:.9*g,!s)return void a.open(d,r,"location,resizable,scrollbars,width="+f+",height="+g);i=q.getElementsByTagName("meta")||[];for(var t=0;t200);t++){var u=i[t],v=u.getAttribute("name"),w=u.getAttribute("property"),x=u.getAttribute("content");x&&(v?e("_meta["+v+"]",x):w&&e("_meta["+w+"]",x))}j=q.getElementsByTagName("link")||[];for(var y=0;y=50);y++){var z=j[y],A=z.getAttribute("rel");("canonical"===A||"icon"===A||"shortlink"===A)&&e("_links["+A+"]",z.getAttribute("href"))}b.body.getElementsByClassName&&(k=b.body.getElementsByClassName("hfeed")[0]),k=b.getElementById("content")||k||b.body,l=k.getElementsByTagName("img")||[];for(var B=0;B=100);B++)n=l[B],n.src.indexOf("avatar")>-1||n.className.indexOf("avatar")>-1||n.width&&n.width<256||n.height&&n.height<128||e("_images[]",n.src);m=b.body.getElementsByTagName("iframe")||[];for(var C=0;C=50);C++)e("_embeds[]",m[C].src);b.title&&e("t",b.title),h&&e("s",h),p.setAttribute("method","POST"),p.setAttribute("action",d),p.setAttribute("target",r),p.setAttribute("style","display: none;"),a.open("about:blank",r,"location,resizable,scrollbars,width="+f+",height="+g),b.body.appendChild(p),p.submit()}})(window,document,top.location.href,window.pt_url); \ No newline at end of file +(function(a,b,c,d){function e(a,c){if("undefined"!=typeof c){var d=b.createElement("input");d.name=a,d.value=c,d.type="hidden",p.appendChild(d)}}var f,g,h,i,j,k,l,m,n,o=a.encodeURIComponent,p=b.createElement("form"),q=b.getElementsByTagName("head")[0],r="_press_this_app",s=!0;if(d){if(!c.match(/^https?:/))return void(top.location.href=d);if(d+="&u="+o(c),c.match(/^https:/)&&d.match(/^http:/)&&(s=!1),a.getSelection?h=a.getSelection()+"":b.getSelection?h=b.getSelection()+"":b.selection&&(h=b.selection.createRange().text||""),d+="&buster="+(new Date).getTime(),s||(b.title&&(d+="&t="+o(b.title.substr(0,256))),h&&(d+="&s="+o(h.substr(0,512)))),f=a.outerWidth||b.documentElement.clientWidth||600,g=a.outerHeight||b.documentElement.clientHeight||700,f=800>f||f>5e3?600:.7*f,g=800>g||g>3e3?700:.9*g,!s)return void a.open(d,r,"location,resizable,scrollbars,width="+f+",height="+g);i=q.getElementsByTagName("meta")||[];for(var t=0;t200);t++){var u=i[t],v=u.getAttribute("name"),w=u.getAttribute("property"),x=u.getAttribute("content");x&&(v?e("_meta["+v+"]",x):w&&e("_meta["+w+"]",x))}j=q.getElementsByTagName("link")||[];for(var y=0;y=50);y++){var z=j[y],A=z.getAttribute("rel");"canonical"!==A&&"icon"!==A&&"shortlink"!==A||e("_links["+A+"]",z.getAttribute("href"))}b.body.getElementsByClassName&&(k=b.body.getElementsByClassName("hfeed")[0]),k=b.getElementById("content")||k||b.body,l=k.getElementsByTagName("img")||[];for(var B=0;B=100);B++)n=l[B],n.src.indexOf("avatar")>-1||n.className.indexOf("avatar")>-1||n.width&&n.width<256||n.height&&n.height<128||e("_images[]",n.src);m=b.body.getElementsByTagName("iframe")||[];for(var C=0;C=50);C++)e("_embeds[]",m[C].src);b.title&&e("t",b.title),h&&e("s",h),p.setAttribute("method","POST"),p.setAttribute("action",d),p.setAttribute("target",r),p.setAttribute("style","display: none;"),a.open("about:blank",r,"location,resizable,scrollbars,width="+f+",height="+g),b.body.appendChild(p),p.submit()}})(window,document,top.location.href,window.pt_url); \ No newline at end of file diff --git a/src/wp-admin/js/editor-expand.js b/src/wp-admin/js/editor-expand.js index bcc1f4e7ca..43ef3b12aa 100644 --- a/src/wp-admin/js/editor-expand.js +++ b/src/wp-admin/js/editor-expand.js @@ -16,7 +16,7 @@ $textTop = $( '#ed_toolbar' ), $textEditor = $( '#content' ), textEditor = $textEditor[0], - textEditorLength = 0, + oldTextLength = 0, $bottom = $( '#post-status-info' ), $menuBar = $(), $statusBar = $(), @@ -76,8 +76,6 @@ } function textEditorResize() { - var reduce, scrollHeight; - if ( mceEditor && ! mceEditor.isHidden() ) { return; } @@ -86,17 +84,28 @@ return; } - reduce = textEditorLength > ( textEditorLength = textEditor.value.length ); - scrollHeight = textEditor.scrollHeight; + var length = textEditor.value.length; + var height = parseInt( textEditor.style.height, 10 ); - if ( reduce ) { + if ( length < oldTextLength ) { + // textEditor.scrollHeight is not adjusted until the next line. textEditor.style.height = 'auto'; - textEditor.style.height = scrollHeight + 'px'; - adjust(); - } else if ( parseInt( textEditor.style.height, 10 ) < scrollHeight ) { - textEditor.style.height = scrollHeight + 'px'; + + if ( textEditor.scrollHeight >= autoresizeMinHeight ) { + textEditor.style.height = textEditor.scrollHeight + 'px'; + } else { + textEditor.style.height = autoresizeMinHeight + 'px'; + } + + if ( textEditor.scrollHeight < height ) { + adjust(); + } + } else if ( height < textEditor.scrollHeight ) { + textEditor.style.height = textEditor.scrollHeight + 'px'; adjust(); } + + oldTextLength = length; } // We need to wait for TinyMCE to initialize.