TinyMCE wpView:
- Improve the fake caret hide/show. - Improve getView() speed. - Add callback for showing the proper path when a view is selected. This currently doesn't work, will start working after we update TinyMCE. props avryl, see #28567, #28595. Built from https://develop.svn.wordpress.org/trunk@29022 git-svn-id: http://core.svn.wordpress.org/trunk@28810 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
d237bc419d
commit
00ff787a86
|
@ -12,9 +12,16 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
|
||||||
cursorInterval, lastKeyDownNode, setViewCursorTries, focus;
|
cursorInterval, lastKeyDownNode, setViewCursorTries, focus;
|
||||||
|
|
||||||
function getView( node ) {
|
function getView( node ) {
|
||||||
return editor.dom.getParent( node, function( node ) {
|
// Doing this directly is about 40% faster
|
||||||
return editor.dom.hasClass( node, 'wpview-wrap' );
|
while ( node && node.parentNode ) {
|
||||||
});
|
if ( node.className && (' ' + node.className + ' ').indexOf(' wpview-wrap ') !== -1 ) {
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
node = node.parentNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,6 +62,7 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
|
||||||
function setViewCursor( before, view ) {
|
function setViewCursor( before, view ) {
|
||||||
var location = before ? 'before' : 'after',
|
var location = before ? 'before' : 'after',
|
||||||
offset = before ? 0 : 1;
|
offset = before ? 0 : 1;
|
||||||
|
deselect();
|
||||||
editor.selection.setCursorLocation( editor.dom.select( '.wpview-selection-' + location, view )[0], offset );
|
editor.selection.setCursorLocation( editor.dom.select( '.wpview-selection-' + location, view )[0], offset );
|
||||||
editor.nodeChanged();
|
editor.nodeChanged();
|
||||||
}
|
}
|
||||||
|
@ -111,6 +119,8 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
|
||||||
dom.bind( clipboard, 'beforedeactivate focusin focusout', _stop );
|
dom.bind( clipboard, 'beforedeactivate focusin focusout', _stop );
|
||||||
dom.bind( selected, 'beforedeactivate focusin focusout', _stop );
|
dom.bind( selected, 'beforedeactivate focusin focusout', _stop );
|
||||||
|
|
||||||
|
tinymce.DOM.addClass( editor.getContainer(), 'wpview-selected' );
|
||||||
|
|
||||||
// Make sure that the editor is focused.
|
// Make sure that the editor is focused.
|
||||||
// It is possible that the editor is not focused when the mouse event fires
|
// It is possible that the editor is not focused when the mouse event fires
|
||||||
// without focus, the selection will not work properly.
|
// without focus, the selection will not work properly.
|
||||||
|
@ -274,6 +284,8 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
|
||||||
var view = getView( event.target ),
|
var view = getView( event.target ),
|
||||||
deselectEventType;
|
deselectEventType;
|
||||||
|
|
||||||
|
firstFocus = false;
|
||||||
|
|
||||||
// Contain clicks inside the view wrapper
|
// Contain clicks inside the view wrapper
|
||||||
if ( view ) {
|
if ( view ) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
@ -484,33 +496,32 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
|
||||||
|
|
||||||
if ( keyCode === VK.LEFT ) {
|
if ( keyCode === VK.LEFT ) {
|
||||||
setViewCursor( true, view );
|
setViewCursor( true, view );
|
||||||
deselect();
|
|
||||||
} else if ( keyCode === VK.UP ) {
|
} else if ( keyCode === VK.UP ) {
|
||||||
if ( view.previousSibling ) {
|
if ( view.previousSibling ) {
|
||||||
if ( getView( view.previousSibling ) ) {
|
if ( getView( view.previousSibling ) ) {
|
||||||
setViewCursor( true, view.previousSibling );
|
setViewCursor( true, view.previousSibling );
|
||||||
} else {
|
} else {
|
||||||
|
deselect();
|
||||||
selection.select( view.previousSibling, true );
|
selection.select( view.previousSibling, true );
|
||||||
selection.collapse();
|
selection.collapse();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
setViewCursor( true, view );
|
setViewCursor( true, view );
|
||||||
}
|
}
|
||||||
deselect();
|
|
||||||
} else if ( keyCode === VK.RIGHT ) {
|
} else if ( keyCode === VK.RIGHT ) {
|
||||||
setViewCursor( false, view );
|
setViewCursor( false, view );
|
||||||
deselect();
|
|
||||||
} else if ( keyCode === VK.DOWN ) {
|
} else if ( keyCode === VK.DOWN ) {
|
||||||
if ( view.nextSibling ) {
|
if ( view.nextSibling ) {
|
||||||
if ( getView( view.nextSibling ) ) {
|
if ( getView( view.nextSibling ) ) {
|
||||||
setViewCursor( false, view.nextSibling );
|
setViewCursor( false, view.nextSibling );
|
||||||
} else {
|
} else {
|
||||||
|
deselect();
|
||||||
selection.setCursorLocation( view.nextSibling, 0 );
|
selection.setCursorLocation( view.nextSibling, 0 );
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
setViewCursor( false, view );
|
setViewCursor( false, view );
|
||||||
}
|
}
|
||||||
deselect();
|
|
||||||
} else if ( keyCode === VK.ENTER ) {
|
} else if ( keyCode === VK.ENTER ) {
|
||||||
handleEnter( view );
|
handleEnter( view );
|
||||||
} else if ( keyCode === VK.DELETE || keyCode === VK.BACKSPACE ) {
|
} else if ( keyCode === VK.DELETE || keyCode === VK.BACKSPACE ) {
|
||||||
|
@ -586,10 +597,19 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
|
||||||
dom.removeClass( views, 'wpview-selection-after' );
|
dom.removeClass( views, 'wpview-selection-after' );
|
||||||
dom.removeClass( views, 'wpview-cursor-hide' );
|
dom.removeClass( views, 'wpview-cursor-hide' );
|
||||||
|
|
||||||
if ( view && editor.selection.isCollapsed() && focus ) {
|
if ( ! selected ) {
|
||||||
if ( className === 'wpview-selection-before' || className === 'wpview-selection-after' ) {
|
tinymce.DOM.removeClass( editor.getContainer(), 'wpview-selected' );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( focus ) {
|
||||||
|
if ( view ) {
|
||||||
|
if ( className === 'wpview-selection-before' || className === 'wpview-selection-after' && editor.selection.isCollapsed() ) {
|
||||||
setViewCursorTries = 0;
|
setViewCursorTries = 0;
|
||||||
|
|
||||||
|
deselect();
|
||||||
|
|
||||||
|
tinymce.DOM.addClass( editor.getContainer(), 'wpview-selected' );
|
||||||
|
|
||||||
// Make sure the cursor arrived in the right node.
|
// Make sure the cursor arrived in the right node.
|
||||||
// This is necessary for Firefox.
|
// This is necessary for Firefox.
|
||||||
if ( lKDN === view.previousSibling ) {
|
if ( lKDN === view.previousSibling ) {
|
||||||
|
@ -609,12 +629,26 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
|
||||||
dom.addClass( view, 'wpview-cursor-hide' );
|
dom.addClass( view, 'wpview-cursor-hide' );
|
||||||
}
|
}
|
||||||
}, 500 );
|
}, 500 );
|
||||||
// If the cursor happens to be anywhere around the view, then set the cursor properly.
|
// If the cursor lands anywhere else in the view, set the cursor before it.
|
||||||
// Only try this once to prevent a loop. (You never know.)
|
// Only try this once to prevent a loop. (You never know.)
|
||||||
} else if ( ! selected && ! setViewCursorTries ) {
|
} else if ( className !== 'wpview-clipboard' && ! setViewCursorTries ) {
|
||||||
|
deselect();
|
||||||
setViewCursorTries++;
|
setViewCursorTries++;
|
||||||
setViewCursor( true, view );
|
setViewCursor( true, view );
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
deselect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
editor.on( 'resolvename', function( event ) {
|
||||||
|
if ( editor.dom.hasClass( event.target, 'wpview-wrap' ) ) {
|
||||||
|
event.name = editor.dom.getAttrib( event.target, 'data-wpview-type' ) || 'wpview';
|
||||||
|
event.stopPropagation();
|
||||||
|
} else if ( getView( event.target ) ) {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
Binary file not shown.
Loading…
Reference in New Issue