TinyMCE, inline link:

- Fix in IE (again). Remove setting/getting placeholders, pass the link node instead.
- In the inline dialog: when the selected text looks like URL or email, pre-fill the URL field with it (same as in the modal).
- Fix setting the name of the main button in the modal: Add Link or Update.
- In the modal when clicking Update remove the link if the URL field is empty. That matches the inline dialog behaviour. Otherwise the modal remains open, nothing happens when clicking the Update button there.

See #33301.
Built from https://develop.svn.wordpress.org/trunk@36747


git-svn-id: http://core.svn.wordpress.org/trunk@36714 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz 2016-02-27 21:33:26 +00:00
parent b926f7803e
commit 32ac4bf58a
6 changed files with 68 additions and 66 deletions

View File

@ -78,6 +78,7 @@
},
reset: function() {
var urlInput = this.getEl().firstChild;
urlInput.value = '';
urlInput.nextSibling.value = '';
}
@ -88,6 +89,7 @@
var editToolbar;
var previewInstance;
var inputInstance;
var linkNode;
var $ = window.jQuery;
function getSelectedLink() {
@ -107,7 +109,6 @@
if ( link ) {
editor.selection.select( link );
editor.nodeChanged();
}
}
}
@ -152,9 +153,14 @@
editToolbar.on( 'show', function() {
if ( ! tinymce.$( document.body ).hasClass( 'modal-open' ) ) {
window.setTimeout( function() {
var element = editToolbar.$el.find( 'input.ui-autocomplete-input' )[0];
var element = editToolbar.$el.find( 'input.ui-autocomplete-input' )[0],
selection = linkNode && ( linkNode.textContent || linkNode.innerText );
if ( element ) {
if ( ! element.value && selection && typeof window.wpLink !== 'undefined' ) {
element.value = window.wpLink.getUrlFromSelection( selection );
}
element.focus();
element.select();
}
@ -171,8 +177,6 @@
} );
editor.addCommand( 'WP_Link', function() {
var link = getSelectedLink();
if ( tinymce.Env.ie && tinymce.Env.ie < 10 ) {
if ( typeof window.wpLink !== 'undefined' ) {
window.wpLink.open( editor.id );
@ -181,18 +185,16 @@
return;
}
linkNode = getSelectedLink();
editToolbar.tempHide = false;
if ( link ) {
editor.dom.setAttribs( link, { 'data-wplink-edit': true } );
if ( linkNode ) {
editor.dom.setAttribs( linkNode, { 'data-wplink-edit': true } );
} else {
removePlaceholders();
editor.execCommand( 'mceInsertLink', false, { href: '_wp_link_placeholder' } );
if ( tinymce.Env.ie ) {
editor.windowManager.wplinkBookmark = editor.selection.getBookmark();
}
linkNode = editor.$( 'a[href="_wp_link_placeholder"]' )[0];
editor.nodeChanged();
}
} );
@ -202,19 +204,13 @@
return;
}
var href, text,
linkNode = getSelectedLink();
var href, text;
if ( linkNode ) {
href = inputInstance.getURL();
text = inputInstance.getLinkText();
editor.focus();
if ( tinymce.isIE ) {
editor.selection.moveToBookmark( editor.windowManager.wplinkBookmark );
editor.windowManager.wplinkBookmark = null;
}
if ( ! href ) {
editor.dom.remove( linkNode, true );
return;
@ -240,12 +236,6 @@
inputInstance.reset();
removePlaceholders();
editor.focus();
if ( tinymce.isIE ) {
editor.selection.moveToBookmark( editor.windowManager.wplinkBookmark );
editor.windowManager.wplinkBookmark = null;
}
editToolbar.tempHide = false;
}
} );
@ -456,7 +446,7 @@
text = inputInstance.getLinkText() || null;
editor.focus(); // Needed for IE
window.wpLink.open( editor.id, url, text );
window.wpLink.open( editor.id, url, text, linkNode );
editToolbar.tempHide = true;
inputInstance.reset();

File diff suppressed because one or more lines are too long

View File

@ -2,12 +2,12 @@
var wpLink;
( function( $ ) {
var editor, correctedURL,
var editor, correctedURL, linkNode,
inputs = {},
isTouch = ( 'ontouchend' in document );
function getLink() {
return editor.dom.getParent( editor.selection.getNode(), 'a' );
return linkNode || editor.dom.getParent( editor.selection.getNode(), 'a[href]' );
}
wpLink = {
@ -125,11 +125,12 @@ var wpLink;
}
},
open: function( editorId, url, text ) {
open: function( editorId, url, text, node ) {
var ed,
$body = $( document.body );
$body.addClass( 'modal-open' );
linkNode = node;
wpLink.range = null;
@ -258,20 +259,20 @@ var wpLink;
url = url || editor.dom.getAttrib( linkNode, 'href' );
if ( url === '_wp_link_placeholder' ) {
url = '';
if ( url !== '_wp_link_placeholder' ) {
inputs.url.val( url );
inputs.openInNewTab.prop( 'checked', '_blank' === editor.dom.getAttrib( linkNode, 'target' ) );
inputs.submit.val( wpLinkL10n.update );
} else {
this.setDefaultValues( linkText );
}
inputs.url.val( url );
inputs.openInNewTab.prop( 'checked', '_blank' === editor.dom.getAttrib( linkNode, 'target' ) );
inputs.submit.val( wpLinkL10n.update );
} else {
text = editor.selection.getContent({ format: 'text' }) || text;
this.setDefaultValues();
linkText = editor.selection.getContent({ format: 'text' }) || text || '';
this.setDefaultValues( linkText );
}
if ( onlyText ) {
inputs.text.val( linkText || '' );
inputs.text.val( linkText );
inputs.wrap.addClass( 'has-text-field' );
} else {
inputs.text.val( '' );
@ -279,22 +280,24 @@ var wpLink;
}
},
close: function() {
close: function( reset ) {
$( document.body ).removeClass( 'modal-open' );
if ( ! wpLink.isMCE() ) {
wpLink.textarea.focus();
if ( reset !== 'noReset' ) {
if ( ! wpLink.isMCE() ) {
wpLink.textarea.focus();
if ( wpLink.range ) {
wpLink.range.moveToBookmark( wpLink.range.getBookmark() );
wpLink.range.select();
}
} else {
if ( editor.plugins.wplink ) {
editor.plugins.wplink.close();
}
if ( wpLink.range ) {
wpLink.range.moveToBookmark( wpLink.range.getBookmark() );
wpLink.range.select();
}
} else {
if ( editor.plugins.wplink ) {
editor.plugins.wplink.close();
}
editor.focus();
editor.focus();
}
}
inputs.backdrop.hide();
@ -394,13 +397,14 @@ var wpLink;
editor.focus();
if ( tinymce.isIE ) {
if ( tinymce.isIE && editor.windowManager.wplinkBookmark ) {
editor.selection.moveToBookmark( editor.windowManager.wplinkBookmark );
editor.windowManager.wplinkBookmark = null;
}
if ( ! attrs.href ) {
editor.execCommand( 'unlink' );
wpLink.close();
return;
}
@ -428,7 +432,8 @@ var wpLink;
}
}
wpLink.close();
wpLink.close( 'noReset' );
editor.focus();
editor.nodeChanged();
},
@ -455,30 +460,37 @@ var wpLink;
}
},
setDefaultValues: function() {
var selection,
getUrlFromSelection: function( selection ) {
var url,
emailRegexp = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,
urlRegexp = /^(https?|ftp):\/\/[A-Z0-9.-]+\.[A-Z]{2,4}[^ "]*$/i;
if ( this.isMCE() ) {
selection = editor.selection.getContent();
} else if ( document.selection && wpLink.range ) {
selection = wpLink.range.text;
} else if ( typeof this.textarea.selectionStart !== 'undefined' ) {
selection = this.textarea.value.substring( this.textarea.selectionStart, this.textarea.selectionEnd );
if ( ! selection ) {
if ( this.isMCE() ) {
selection = editor.selection.getContent({ format: 'text' });
} else if ( document.selection && wpLink.range ) {
selection = wpLink.range.text;
} else if ( typeof this.textarea.selectionStart !== 'undefined' ) {
selection = this.textarea.value.substring( this.textarea.selectionStart, this.textarea.selectionEnd );
}
}
selection = tinymce.trim( selection );
if ( selection && emailRegexp.test( selection ) ) {
// Selection is email address
inputs.url.val( 'mailto:' + selection );
return 'mailto:' + selection;
} else if ( selection && urlRegexp.test( selection ) ) {
// Selection is URL
inputs.url.val( selection.replace( /&amp;|&#0?38;/gi, '&' ) );
} else {
// Set URL to default.
inputs.url.val( '' );
return selection.replace( /&amp;|&#0?38;/gi, '&' );
}
return '';
},
setDefaultValues: function( selection ) {
inputs.url.val( this.getUrlFromSelection( selection ) );
// Update save prompt.
inputs.submit.val( wpLinkL10n.save );
}

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.5-beta1-36746';
$wp_version = '4.5-beta1-36747';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.