TinyMCE, inline link:

- Remove proxying through WordPress to test if an URL exists.
- Fix and enhance the regex that tests if the URL is well formed.

Fixes #36638.
Built from https://develop.svn.wordpress.org/trunk@38159


git-svn-id: http://core.svn.wordpress.org/trunk@38100 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz
2016-07-26 23:24:28 +00:00
parent 101545cbb5
commit 5bccb0020d
7 changed files with 11 additions and 90 deletions

View File

@@ -93,8 +93,9 @@
var doingUndoRedo;
var doingUndoRedoTimer;
var $ = window.jQuery;
var urlErrors = {};
var emailRegex = /^(mailto:)?[a-z0-9._%+-]+@[a-z0-9][a-z0-9.-]*\.[a-z]{2,63}$/i;
var urlRegex1 = /^https?:\/\/([^\s/?.#-][^\s\/?.#]*\.?)+(\/[^\s"]*)?$/i;
var urlRegex2 = /^https?:\/\/[^\/]+\.[^\/]+($|\/)/i;
var speak = ( typeof window.wp !== 'undefined' && window.wp.a11y && window.wp.a11y.speak ) ? window.wp.a11y.speak : function() {};
var hasLinkError = false;
@@ -150,16 +151,6 @@
});
}
function setLinkError( $link ) {
hasLinkError = true;
$link.attr( 'data-wplink-url-error', 'true' );
speak( editor.translate( 'Warning: the link has been inserted but the destination cannot be reached.' ), 'assertive' );
if ( toolbar && toolbar.visible() ) {
toolbar.$el.find( '.wp-link-preview a' ).addClass( 'wplink-url-error' );
}
}
function checkLink( node ) {
var $link = editor.$( node );
var href = $link.attr( 'href' );
@@ -170,34 +161,13 @@
hasLinkError = false;
if ( /^http/i.test( href ) && ! /^https?:\/\/[a-z0-9][a-z0-9.-]*\.[a-z]{2,63}(\/|$)/i.test( href ) ) {
urlErrors[href] = true;
}
if ( urlErrors.hasOwnProperty( href ) ) {
setLinkError( $link );
return;
if ( /^http/i.test( href ) && ( ! urlRegex1.test( href ) || ! urlRegex2.test( href ) ) ) {
hasLinkError = true;
$link.attr( 'data-wplink-url-error', 'true' );
speak( editor.translate( 'Warning: the link has been inserted but may have errors. Please test it.' ), 'assertive' );
} else {
$link.removeAttr( 'data-wplink-url-error' );
}
$.post(
window.ajaxurl, {
action: 'test_url',
nonce: $( '#_wplink_urltest_nonce' ).val(),
href: href
},
'json'
).done( function( response ) {
if ( response.success ) {
return;
}
if ( response.data && response.data.httpError ) {
urlErrors[href] = true;
setLinkError( $link );
}
});
}
editor.on( 'preinit', function() {

File diff suppressed because one or more lines are too long