How to use the @wordpress/url.isURL function in @wordpress/url

To help you get started, we’ve selected a few @wordpress/url examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github WordPress / gutenberg / packages / block-library / src / image / edit.native.js View on Github external
componentDidMount() {
		const { attributes, setAttributes } = this.props;

		// This will warn when we have `id` defined, while `url` is undefined.
		// This may help track this issue: https://github.com/wordpress-mobile/WordPress-Android/issues/9768
		// where a cancelled image upload was resulting in a subsequent crash.
		if ( attributes.id && ! attributes.url ) {
			// eslint-disable-next-line no-console
			console.warn( 'Attributes has id with no url.' );
		}

		if ( attributes.id && attributes.url && ! isURL( attributes.url ) ) {
			if ( attributes.url.indexOf( 'file:' ) === 0 ) {
				requestMediaImport( attributes.url, ( mediaId, mediaUri ) => {
					if ( mediaUri ) {
						setAttributes( { url: mediaUri, id: mediaId } );
					}
				} );
			}
			mediaUploadSync();
		}
	}
github WordPress / gutenberg / packages / block-editor / src / components / rich-text / index.js View on Github external
if ( onReplace && isEmpty( value ) ) {
				onReplace( content );
			} else {
				splitValue( value, content );
			}

			return;
		}

		let mode = onReplace && onSplit ? 'AUTO' : 'INLINE';

		if (
			__unstableEmbedURLOnPaste &&
			isEmpty( value ) &&
			isURL( plainText.trim() )
		) {
			mode = 'BLOCKS';
		}

		const content = pasteHandler( {
			HTML: html,
			plainText,
			mode,
			tagName,
			canUserUseUnfilteredHTML,
		} );

		if ( typeof content === 'string' ) {
			let valueToInsert = create( { html: content } );

			// If there are active formats, merge them with the pasted formats.
github 10up / distributor / assets / js / admin-external-connection.js View on Github external
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,
		method: 'post',
github WordPress / gutenberg / packages / block-library / src / media-text / media-container.native.js View on Github external
onMediaPressed() {
		const { mediaId, mediaUrl } = this.props;

		if ( this.state.isUploadInProgress ) {
			requestImageUploadCancelDialog( mediaId );
		} else if ( mediaId && ! isURL( mediaUrl ) ) {
			requestImageFailedRetryDialog( mediaId );
		}
	}
github WordPress / gutenberg / packages / format-library / src / link / index.native.js View on Github external
addLink() {
			const { value, onChange } = this.props;
			const text = getTextContent( slice( value ) );

			if ( text && isURL( text ) ) {
				onChange( applyFormat( value, { type: name, attributes: { url: text } } ) );
			} else {
				this.setState( { addingLink: true } );
			}
		}
github Automattic / vip-go-mu-plugins-built / jetpack / extensions / blocks / podcast-player / edit.js View on Github external
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 } );
			}
github WordPress / gutenberg / packages / block-library / src / media-text / media-container.native.js View on Github external
renderVideo( params, openMediaOptions ) {
		const { mediaUrl, isSelected } = this.props;
		const { isUploadInProgress } = this.state;
		const { isUploadFailed, retryMessage } = params;
		const showVideo = isURL( mediaUrl ) && ! isUploadInProgress && ! isUploadFailed;

		return (
github WordPress / gutenberg / packages / block-library / src / navigation-menu / menu-item-inserter.js View on Github external
onChangeSearchInput( value ) {
		this.setState( {
			isUrlInput: isURL( value ),
			currentSearchInput: value,
		} );
	}
github WordPress / gutenberg / packages / block-library / src / gallery / gallery-image.native.js View on Github external
onMediaPressed() {
		const { id, url } = this.props;

		this.onSelectImage();

		if ( this.state.isUploadInProgress ) {
			requestImageUploadCancelDialog( id );
		} else if ( ( this.state.didUploadFail ) || ( id && ! isURL( url ) ) ) {
			requestImageFailedRetryDialog( id );
		}
	}