Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
submitLink() {
const { isActive, onChange, speak, value } = this.props;
const { inputValue, opensInNewWindow, text } = this.state;
const url = prependHTTP( inputValue );
const linkText = text || inputValue;
const format = createLinkFormat( {
url,
opensInNewWindow,
text: linkText,
} );
if ( isCollapsed( value ) && ! isActive ) { // insert link
const toInsert = applyFormat( create( { text: linkText } ), format, 0, linkText.length );
const newAttributes = insert( value, toInsert );
onChange( { ...newAttributes, needsSelectionUpdate: true } );
} else if ( text !== getTextContent( slice( value ) ) ) { // edit text in selected link
const toInsert = applyFormat( create( { text } ), format, 0, text.length );
const newAttributes = insert( value, toInsert, value.start, value.end );
onChange( { ...newAttributes, needsSelectionUpdate: true } );
} else { // transform selected text into link
// Clear any previous errors.
jQuery( wizardError[0] ).text( '' );
// Verify Title and Site URL fields are non-empty.
const validateTitle = validateField( jQuery( titleField ), event );
const validateURL = validateField( jQuery( externalSiteUrlField ), event );
if (
! validateTitle ||
! validateURL
) {
event.preventDefault();
return false;
}
let siteURL = prependHTTP( externalSiteUrlField.value );
if ( ! isURL( siteURL ) ) {
jQuery( wizardError[0] ).text( dt.invalid_url );
return false;
}
// Show the spinner and loading message.
wizardStatus.style.display = 'block';
// Remove wp-json from URL, if that was added
siteURL = siteURL.replace( /wp-json(\/)*/, '' );
// Ensure URL ends with trailing slash
siteURL = siteURL.replace( /\/?$/, '/' );
jQuery.ajax( {
url: ajaxurl,
submitLink( event ) {
const { isActive, value, onChange, speak } = this.props;
const { inputValue, opensInNewWindow } = this.state;
const url = prependHTTP( inputValue );
const selectedText = getTextContent( slice( value ) );
const format = createLinkFormat( {
url,
opensInNewWindow,
text: selectedText,
} );
event.preventDefault();
if ( isCollapsed( value ) && ! isActive ) {
const toInsert = applyFormat( create( { text: url } ), format, 0, url.length );
onChange( insert( value, toInsert ) );
} else {
onChange( applyFormat( value, format ) );
}
type = 'mailto';
}
if ( protocol.includes( 'tel' ) ) {
type = 'tel';
}
if ( startsWith( value, '#' ) ) {
type = 'internal';
}
return Promise.resolve(
[ {
id: '-1',
title: value,
url: type === 'URL' ? prependHTTP( value ) : value,
type,
} ]
);
};
event => {
event.preventDefault();
removeAllNotices();
if ( ! editedUrl ) {
return;
}
/*
* Ensure URL has `http` appended to it (if it doesn't already) before we
* accept it as the entered URL.
*/
const prependedURL = prependHTTP( editedUrl );
if ( ! isURL( prependedURL ) ) {
createErrorNotice(
__( "Your podcast couldn't be embedded. Please double check your URL.", 'jetpack' )
);
return;
}
/*
* Short-circuit feed fetching if we tried before, use useEffect otherwise.
* @see {@link https://github.com/Automattic/jetpack/pull/15213}
*/
if ( prependedURL === url ) {
fetchFeed( url );
} else {
setAttributes( { url: prependedURL } );
) : (
) }
);
}
}
const LinkViewer = ( { url, onEditLink } ) => {
return (
<div>
</div>
);
};