TinyMCE wplink:
- Remove the calls to getBookmark() and moveToBookmark() in IE. This is handled automatically when blurring and focusing the editor. - When inserting a link, move it out of the caret position element. If not, it may be removed with that element on clean-up before save. Fixes #38335. git-svn-id: https://develop.svn.wordpress.org/trunk@38808 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
456c23c551
commit
535ae49ab6
@ -125,10 +125,6 @@ var wpLink;
|
|||||||
} else {
|
} else {
|
||||||
editor = null;
|
editor = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( editor && window.tinymce.isIE ) {
|
|
||||||
editor.windowManager.wplinkBookmark = editor.selection.getBookmark();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! wpLink.isMCE() && document.selection ) {
|
if ( ! wpLink.isMCE() && document.selection ) {
|
||||||
@ -306,10 +302,15 @@ var wpLink;
|
|||||||
getAttrs: function() {
|
getAttrs: function() {
|
||||||
wpLink.correctURL();
|
wpLink.correctURL();
|
||||||
|
|
||||||
return {
|
var attrs = {
|
||||||
href: $.trim( inputs.url.val() ),
|
href: $.trim( inputs.url.val() )
|
||||||
target: inputs.openInNewTab.prop( 'checked' ) ? '_blank' : ''
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if ( inputs.openInNewTab.prop( 'checked' ) ) {
|
||||||
|
attrs.target = '_blank';
|
||||||
|
}
|
||||||
|
|
||||||
|
return attrs;
|
||||||
},
|
},
|
||||||
|
|
||||||
buildHtml: function(attrs) {
|
buildHtml: function(attrs) {
|
||||||
@ -391,12 +392,7 @@ var wpLink;
|
|||||||
|
|
||||||
mceUpdate: function() {
|
mceUpdate: function() {
|
||||||
var attrs = wpLink.getAttrs(),
|
var attrs = wpLink.getAttrs(),
|
||||||
link, text;
|
$link, text, hasText, $mceCaret;
|
||||||
|
|
||||||
if ( window.tinymce.isIE && editor.windowManager.wplinkBookmark ) {
|
|
||||||
editor.selection.moveToBookmark( editor.windowManager.wplinkBookmark );
|
|
||||||
editor.windowManager.wplinkBookmark = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! attrs.href ) {
|
if ( ! attrs.href ) {
|
||||||
editor.execCommand( 'unlink' );
|
editor.execCommand( 'unlink' );
|
||||||
@ -404,40 +400,54 @@ var wpLink;
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
link = getLink();
|
$link = editor.$( getLink() );
|
||||||
|
|
||||||
if ( inputs.wrap.hasClass( 'has-text-field' ) ) {
|
editor.undoManager.transact( function() {
|
||||||
text = inputs.text.val() || attrs.href;
|
if ( ! $link.length ) {
|
||||||
}
|
editor.execCommand( 'mceInsertLink', false, { href: '_wp_link_placeholder', 'data-wp-temp-link': 1 } );
|
||||||
|
$link = editor.$( 'a[data-wp-temp-link="1"]' ).removeAttr( 'data-wp-temp-link' );
|
||||||
if ( link ) {
|
hasText = $.trim( $link.text() );
|
||||||
if ( text ) {
|
|
||||||
if ( 'innerText' in link ) {
|
|
||||||
link.innerText = text;
|
|
||||||
} else {
|
|
||||||
link.textContent = text;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not editing any more
|
if ( ! $link.length ) {
|
||||||
attrs['data-wplink-edit'] = null;
|
editor.execCommand( 'unlink' );
|
||||||
editor.dom.setAttribs( link, attrs );
|
|
||||||
} else {
|
|
||||||
if ( text ) {
|
|
||||||
editor.selection.setNode( editor.dom.create( 'a', attrs, editor.dom.encode( text ) ) );
|
|
||||||
} else {
|
} else {
|
||||||
editor.execCommand( 'mceInsertLink', false, attrs );
|
if ( inputs.wrap.hasClass( 'has-text-field' ) ) {
|
||||||
|
text = inputs.text.val();
|
||||||
|
|
||||||
|
if ( text ) {
|
||||||
|
$link.text( text );
|
||||||
|
} else if ( ! hasText ) {
|
||||||
|
$link.text( attrs.href );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
attrs['data-wplink-edit'] = null;
|
||||||
|
attrs['data-mce-href'] = null; // attrs.href
|
||||||
|
$link.attr( attrs );
|
||||||
}
|
}
|
||||||
}
|
} );
|
||||||
|
|
||||||
wpLink.close( 'noReset' );
|
wpLink.close( 'noReset' );
|
||||||
editor.focus();
|
editor.focus();
|
||||||
editor.nodeChanged();
|
|
||||||
|
|
||||||
if ( link && editor.plugins.wplink ) {
|
if ( $link.length ) {
|
||||||
editor.plugins.wplink.checkLink( link );
|
$mceCaret = $link.parent( '#_mce_caret' );
|
||||||
|
|
||||||
|
if ( $mceCaret.length ) {
|
||||||
|
$mceCaret.before( $link.removeAttr( 'data-mce-bogus' ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
editor.selection.select( $link[0] );
|
||||||
|
editor.selection.collapse();
|
||||||
|
|
||||||
|
if ( editor.plugins.wplink ) {
|
||||||
|
editor.plugins.wplink.checkLink( $link[0] );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
editor.nodeChanged();
|
||||||
|
|
||||||
// Audible confirmation message when a link has been inserted in the Editor.
|
// Audible confirmation message when a link has been inserted in the Editor.
|
||||||
wp.a11y.speak( wpLinkL10n.linkInserted );
|
wp.a11y.speak( wpLinkL10n.linkInserted );
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user