How to use the @wordpress/url.prependHTTP 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 / format-library / src / link / modal.native.js View on Github external
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
github 10up / distributor / assets / js / admin-external-connection.js View on Github external
// 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,
github WordPress / gutenberg / packages / format-library / src / link / inline.js View on Github external
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 ) );
		}
github WordPress / gutenberg / packages / block-editor / src / components / link-control / index.js View on Github external
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,
			} ]
		);
	};
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 / button / link-popover.js View on Github external
const LinkViewer = ( { url, onEditLink } ) => {
	return (
		<div>
			
			
		</div>
	);
};