- Fix complex character input in Japanese, Chinese, etc. Was broken in getCursorOffset() in editor-expand.js.
- Disable auto-scrolling in some edge cases when editor expanding is enabled.
See #28328.

Built from https://develop.svn.wordpress.org/trunk@29302


git-svn-id: http://core.svn.wordpress.org/trunk@29084 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz 2014-07-26 00:08:19 +00:00
parent f3ede5702e
commit b9f97e8352
4 changed files with 28 additions and 50 deletions

View File

@ -124,13 +124,18 @@ jQuery( document ).ready( function($) {
$visualEditor = $contentWrap.find( '.mce-edit-area' );
$statusBar = $contentWrap.find( '.mce-statusbar' ).filter( ':visible' );
// Adjust when switching editor modes.
editor.on( 'show', function() {
setTimeout( function() {
editor.execCommand( 'wpAutoResize' );
adjust();
}, 300 );
} );
function getCursorOffset() {
var node = editor.selection.getNode(),
view, offset;
if ( editor.plugins.wpview && ( view = editor.plugins.wpview.getView( node ) ) ) {
offset = view.getBoundingClientRect();
} else {
offset = node.getBoundingClientRect();
}
return offset.height ? offset : false;
}
// Make sure the cursor is always visible.
// This is not only necessary to keep the cursor between the toolbars,
@ -150,13 +155,18 @@ jQuery( document ).ready( function($) {
return;
}
cursorTop = offset.top + editor.getContentAreaContainer().getElementsByTagName( 'iframe' )[0].getBoundingClientRect().top;
cursorTop = offset.top + editor.getContentAreaContainer().firstChild.getBoundingClientRect().top;
cursorBottom = cursorTop + offset.height;
cursorTop = cursorTop - buffer;
cursorBottom = cursorBottom + buffer;
editorTop = $adminBar.outerHeight() + $tools.outerHeight() + $visualTop.outerHeight();
editorBottom = windowHeight - $bottom.outerHeight();
// Don't scroll if the node is taller than the visible part of the editor
if ( editorBottom - editorTop < offset.height ) {
return;
}
if ( cursorTop < editorTop && ( key === VK.UP || key === VK.LEFT || key === VK.BACKSPACE ) ) {
window.scrollTo( window.pageXOffset, cursorTop + window.pageYOffset - editorTop );
} else if ( cursorBottom > editorBottom ) {
@ -164,44 +174,13 @@ jQuery( document ).ready( function($) {
}
} );
function getCursorOffset() {
var selection = editor.selection,
node = selection.getNode(),
range = selection.getRng(),
view, clone, offset;
if ( tinymce.Env.ie && tinymce.Env.ie < 9 ) {
return;
}
if ( editor.plugins.wpview && ( view = editor.plugins.wpview.getView( node ) ) ) {
offset = view.getBoundingClientRect();
} else if ( selection.isCollapsed() ) {
clone = range.cloneRange();
if ( clone.startContainer.length > 1 ) {
if ( clone.startContainer.length > clone.endOffset ) {
clone.setEnd( clone.startContainer, clone.endOffset + 1 );
} else {
clone.setStart( clone.startContainer, clone.endOffset - 1 );
}
selection.setRng( clone );
offset = selection.getRng().getBoundingClientRect();
selection.setRng( range );
} else {
offset = node.getBoundingClientRect();
}
} else {
offset = range.getBoundingClientRect();
}
if ( ! offset.height ) {
return;
}
return offset;
}
// Adjust when switching editor modes.
editor.on( 'show', function() {
setTimeout( function() {
editor.execCommand( 'wpAutoResize' );
adjust();
}, 300 );
} );
editor.on( 'hide', function() {
textEditorResize();

View File

@ -1 +1 @@
window.wp=window.wp||{},jQuery(document).ready(function(a){function b(){if(!h||h.isHidden()){var a,b=o.height();p.width(o.width()),p.text(o.val()+"&nbsp;"),a=p.height(),300>a&&(a=300),a!==b&&(o.height(a),c())}}function c(a){if(!s||!s.settings.visible){var b,c,d,j,v,w,x,y,z,A=q.outerHeight(),B=i.scrollTop(),C=i.height(),D=i.width(),E=D>600?k.height():0,F="scroll"!==a,G=h&&!h.isHidden();G?(b=e,c=f):(b=n,c=o),d=m.outerHeight(),j=b.parent().offset().top,v=b.outerHeight(),w=c.offset().top,x=c.outerHeight(),y=c.outerWidth(),z=G?g.outerHeight():0,(!t||F)&&B>=j-d-E&&j-d-E+x-r>=B?(t=!0,b.css({position:"fixed",top:E+d,width:c.parent().width()-(b.outerWidth()-b.width()),borderTop:"1px solid #e5e5e5"}),m.css({position:"fixed",top:E,width:y+2})):(t||F)&&(j-d-E>=B?(t=!1,b.css({position:"absolute",top:0,borderTop:"none",width:c.parent().width()-(b.outerWidth()-b.width())}),m.css({position:"absolute",top:0,width:l.width()})):B>=j-d-E+x-r&&(t=!1,b.css({position:"absolute",top:x-r}),m.css({position:"absolute",top:x-r+1,width:l.width()}))),(!u||F)&&w+x+A+z+1>=B+C?(u=!0,q.css({position:"fixed",bottom:0,width:y+2,borderTop:"1px solid #dedede"})):(u||F)&&B+C>w+x+A+z-1&&(u=!1,q.css({position:"relative",bottom:"auto",width:"100%",borderTop:"none"})),F&&(l.css({paddingTop:m.outerHeight()}),G?f.css({paddingTop:e.outerHeight()}):(o.css({marginTop:n.outerHeight()}),p.width(o.width())))}}function d(a){for(var b=1;6>b;b++)setTimeout(a,500*b)}var e,f,g,h,i=a(window),j=a(document),k=a("#wpadminbar"),l=a("#wp-content-wrap"),m=a("#wp-content-editor-tools"),n=a("#ed_toolbar"),o=a("#content"),p=a('<div id="content-textarea-clone"></div>'),q=a("#post-status-info"),r=200,s=window.wp.editor&&window.wp.editor.fullscreen,t=!1,u=!1;p.insertAfter(o),l.addClass("wp-editor-expand"),a("#content-resize-handle").hide(),p.css({"font-family":o.css("font-family"),"font-size":o.css("font-size"),"line-height":o.css("line-height"),padding:o.css("padding"),"padding-top":37,"white-space":"pre-wrap","word-wrap":"break-word"}),o.on("focus input propertychange",function(){b()}),o.on("keyup",function(a){var b,c,d,e,f,g=jQuery.ui.keyCode,h=a.keyCode,j=document.createRange(),l=o[0].selectionStart,r=o[0].selectionEnd,s=p[0].firstChild,t=i.height(),u=10;if(!l||!r||l===r){try{j.setStart(s,l),j.setEnd(s,r+1)}catch(v){}b=j.getBoundingClientRect(),b.height&&(c=b.top-u,d=c+b.height+u,e=k.outerHeight()+m.outerHeight()+n.outerHeight(),f=t-q.outerHeight(),e>c&&(h===g.UP||h===g.LEFT||h===g.BACKSPACE)?window.scrollTo(window.pageXOffset,c+window.pageYOffset-e):d>f&&window.scrollTo(window.pageXOffset,d+window.pageYOffset-f))}}),j.on("tinymce-editor-init.editor-expand",function(a,j){function n(){var a,b,c,d=j.selection,e=d.getNode(),f=d.getRng();if(!(tinymce.Env.ie&&tinymce.Env.ie<9)&&(j.plugins.wpview&&(a=j.plugins.wpview.getView(e))?c=a.getBoundingClientRect():d.isCollapsed()?(b=f.cloneRange(),b.startContainer.length>1?(b.startContainer.length>b.endOffset?b.setEnd(b.startContainer,b.endOffset+1):b.setStart(b.startContainer,b.endOffset-1),d.setRng(b),c=d.getRng().getBoundingClientRect(),d.setRng(f)):c=e.getBoundingClientRect()):c=f.getBoundingClientRect(),c.height))return c}"content"===j.id&&(h=j,j.settings.autoresize_min_height=300,e=l.find(".mce-toolbar-grp"),f=l.find(".mce-edit-area"),g=l.find(".mce-statusbar").filter(":visible"),j.on("show",function(){setTimeout(function(){j.execCommand("wpAutoResize"),c()},300)}),j.on("keyup",function(a){var b,c,d,f,g=tinymce.util.VK,h=a.keyCode,l=n(),o=i.height(),p=10;l&&(b=l.top+j.getContentAreaContainer().getElementsByTagName("iframe")[0].getBoundingClientRect().top,c=b+l.height,b-=p,c+=p,d=k.outerHeight()+m.outerHeight()+e.outerHeight(),f=o-q.outerHeight(),d>b&&(h===g.UP||h===g.LEFT||h===g.BACKSPACE)?window.scrollTo(window.pageXOffset,b+window.pageYOffset-d):c>f&&window.scrollTo(window.pageXOffset,c+window.pageYOffset-f))}),j.on("hide",function(){b(),c()}),j.on("setcontent wp-autoresize wp-toolbar-toggle",function(){c()}),d(c))}),i.on("scroll.editor-expand resize.editor-expand",function(a){c(a.type)}),s&&s.pubsub.subscribe("hidden",function(){b(),c()}),j.on("wp-collapse-menu.editor-expand postboxes-columnchange.editor-expand editor-classchange.editor-expand",c),l.hasClass("html-active")&&d(function(){c(),b()})});
window.wp=window.wp||{},jQuery(document).ready(function(a){function b(){if(!h||h.isHidden()){var a,b=o.height();p.width(o.width()),p.text(o.val()+"&nbsp;"),a=p.height(),300>a&&(a=300),a!==b&&(o.height(a),c())}}function c(a){if(!s||!s.settings.visible){var b,c,d,j,v,w,x,y,z,A=q.outerHeight(),B=i.scrollTop(),C=i.height(),D=i.width(),E=D>600?k.height():0,F="scroll"!==a,G=h&&!h.isHidden();G?(b=e,c=f):(b=n,c=o),d=m.outerHeight(),j=b.parent().offset().top,v=b.outerHeight(),w=c.offset().top,x=c.outerHeight(),y=c.outerWidth(),z=G?g.outerHeight():0,(!t||F)&&B>=j-d-E&&j-d-E+x-r>=B?(t=!0,b.css({position:"fixed",top:E+d,width:c.parent().width()-(b.outerWidth()-b.width()),borderTop:"1px solid #e5e5e5"}),m.css({position:"fixed",top:E,width:y+2})):(t||F)&&(j-d-E>=B?(t=!1,b.css({position:"absolute",top:0,borderTop:"none",width:c.parent().width()-(b.outerWidth()-b.width())}),m.css({position:"absolute",top:0,width:l.width()})):B>=j-d-E+x-r&&(t=!1,b.css({position:"absolute",top:x-r}),m.css({position:"absolute",top:x-r+1,width:l.width()}))),(!u||F)&&w+x+A+z+1>=B+C?(u=!0,q.css({position:"fixed",bottom:0,width:y+2,borderTop:"1px solid #dedede"})):(u||F)&&B+C>w+x+A+z-1&&(u=!1,q.css({position:"relative",bottom:"auto",width:"100%",borderTop:"none"})),F&&(l.css({paddingTop:m.outerHeight()}),G?f.css({paddingTop:e.outerHeight()}):(o.css({marginTop:n.outerHeight()}),p.width(o.width())))}}function d(a){for(var b=1;6>b;b++)setTimeout(a,500*b)}var e,f,g,h,i=a(window),j=a(document),k=a("#wpadminbar"),l=a("#wp-content-wrap"),m=a("#wp-content-editor-tools"),n=a("#ed_toolbar"),o=a("#content"),p=a('<div id="content-textarea-clone"></div>'),q=a("#post-status-info"),r=200,s=window.wp.editor&&window.wp.editor.fullscreen,t=!1,u=!1;p.insertAfter(o),l.addClass("wp-editor-expand"),a("#content-resize-handle").hide(),p.css({"font-family":o.css("font-family"),"font-size":o.css("font-size"),"line-height":o.css("line-height"),padding:o.css("padding"),"padding-top":37,"white-space":"pre-wrap","word-wrap":"break-word"}),o.on("focus input propertychange",function(){b()}),o.on("keyup",function(a){var b,c,d,e,f,g=jQuery.ui.keyCode,h=a.keyCode,j=document.createRange(),l=o[0].selectionStart,r=o[0].selectionEnd,s=p[0].firstChild,t=i.height(),u=10;if(!l||!r||l===r){try{j.setStart(s,l),j.setEnd(s,r+1)}catch(v){}b=j.getBoundingClientRect(),b.height&&(c=b.top-u,d=c+b.height+u,e=k.outerHeight()+m.outerHeight()+n.outerHeight(),f=t-q.outerHeight(),e>c&&(h===g.UP||h===g.LEFT||h===g.BACKSPACE)?window.scrollTo(window.pageXOffset,c+window.pageYOffset-e):d>f&&window.scrollTo(window.pageXOffset,d+window.pageYOffset-f))}}),j.on("tinymce-editor-init.editor-expand",function(a,j){function n(){var a,b,c=j.selection.getNode();return b=j.plugins.wpview&&(a=j.plugins.wpview.getView(c))?a.getBoundingClientRect():c.getBoundingClientRect(),b.height?b:!1}"content"===j.id&&(h=j,j.settings.autoresize_min_height=300,e=l.find(".mce-toolbar-grp"),f=l.find(".mce-edit-area"),g=l.find(".mce-statusbar").filter(":visible"),j.on("keyup",function(a){var b,c,d,f,g=tinymce.util.VK,h=a.keyCode,l=n(),o=i.height(),p=10;l&&(b=l.top+j.getContentAreaContainer().firstChild.getBoundingClientRect().top,c=b+l.height,b-=p,c+=p,d=k.outerHeight()+m.outerHeight()+e.outerHeight(),f=o-q.outerHeight(),f-d<l.height||(d>b&&(h===g.UP||h===g.LEFT||h===g.BACKSPACE)?window.scrollTo(window.pageXOffset,b+window.pageYOffset-d):c>f&&window.scrollTo(window.pageXOffset,c+window.pageYOffset-f)))}),j.on("show",function(){setTimeout(function(){j.execCommand("wpAutoResize"),c()},300)}),j.on("hide",function(){b(),c()}),j.on("setcontent wp-autoresize wp-toolbar-toggle",function(){c()}),d(c))}),i.on("scroll.editor-expand resize.editor-expand",function(a){c(a.type)}),s&&s.pubsub.subscribe("hidden",function(){b(),c()}),j.on("wp-collapse-menu.editor-expand postboxes-columnchange.editor-expand editor-classchange.editor-expand",c),l.hasClass("html-active")&&d(function(){c(),b()})});

View File

@ -286,8 +286,7 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
});
editor.dom.bind( editor.getBody().parentNode, 'mousedown mouseup click', function( event ) {
var view = getView( event.target ),
deselectEventType;
var view = getView( event.target );
firstFocus = false;

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.0-beta2-20140725';
$wp_version = '4.0-beta2-20140726';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.