How to use @wordpress/dom-ready - 10 common examples

To help you get started, we’ve selected a few @wordpress/dom-ready 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 Automattic / vip-go-mu-plugins-built / jetpack / extensions / blocks / mailchimp / view.js View on Github external
const blog_id = block.getAttribute( 'data-blog-id' );
		try {
			activateSubscription( block, blog_id );
		} catch ( err ) {
			if ( 'production' !== process.env.NODE_ENV ) {
				// eslint-disable-next-line no-console
				console.error( err );
			}
		}

		block.setAttribute( 'data-jetpack-block-initialized', 'true' );
	} );
};

if ( typeof window !== 'undefined' ) {
	domReady( initializeMailchimpBlocks );
}
github gambitph / Stackable / src / block / accordion / frontend.js View on Github external
// Accessibility: https://www.w3.org/TR/wai-aria-practices/examples/accordion/accordion.html
	const heading = el.querySelector( '.ugb-accordion__heading h4, .ugb-accordion__title' )
	const content = el.querySelector( '.ugb-accordion__text, .ugb-accordion__content' )

	heading.setAttribute( 'id', `ugb-accordion-${ instanceID }__heading` )
	content.setAttribute( 'id', `ugb-accordion-${ instanceID }__content` )
	heading.setAttribute( 'aria-controls', `ugb-accordion-${ instanceID }__content` )
	content.setAttribute( 'aria-labelledby', `ugb-accordion-${ instanceID }__heading` )
	instanceID++
}

export const initAll = () => {
	document.querySelectorAll( '.ugb-accordion' ).forEach( el => init( el ) )
}

domReady( initAll )
github dsifford / academic-bloggers-toolkit / src / js / _legacy / _entrypoints / options-page / style-form.tsx View on Github external
constructor(props: {}) {
        super(props);
        this.store = new Store(top.ABT.options.citation_style);
        domReady(() => {
            // can't remember why this was needed, but keep it.
            this.store.style = top.ABT.options.citation_style;
        });
    }
github gambitph / Stackable / src / block / columns / auto-select.js View on Github external
setTimeout( () => {
				const selectedBlock = getSelectedBlock()
				if ( selectedBlock && selectedBlock.name === 'ugb/column' ) {
					clearSelectedBlock() // Clear first or else our inspector will show all options.
					const columnsBlockClientIds = getBlockParents( selectedBlock.clientId )
					if ( columnsBlockClientIds.length ) {
						selectBlock( columnsBlockClientIds[ 0 ] )
					}
				}
			}, 0 )
		}
		blocks = newBlocks
	} )
}

domReady( initAutoAttemptRecovery )
github gambitph / Stackable / src / block / design-library / index.js View on Github external
const toolbar = document.querySelector( '.edit-post-header-toolbar' )
	if ( ! toolbar ) {
		return
	}

	const buttonDiv = document.createElement( 'div' )
	buttonDiv.classList.add( 'ugb-insert-library-button__wrapper' )

	if ( ! toolbar.querySelector( '.ugb-insert-library-button__wrapper' ) ) {
		render( , buttonDiv )
		toolbar.appendChild( buttonDiv )
	}
}

domReady( mountDesignLibrary )
github ampproject / amp-wp / assets / src / amp-validation / amp-validated-urls-index.js View on Github external
/**
 * WordPress dependencies
 */
import domReady from '@wordpress/dom-ready';

/**
 * Internal dependencies
 */
import setValidationErrorRowsSeenClass from './set-validation-error-rows-seen-class';

domReady( setValidationErrorRowsSeenClass );
github Yoast / wordpress-seo / js / src / structured-data-blocks / global-block-subscriber.js View on Github external
*/
function setupSubscriber() {
	let previousBlocks = null;

	subscribe( () => {
		const blocks = select( "core/editor" ).getBlocks();

		if ( blocks !== previousBlocks ) {
			recurseBlocks( blocks );

			previousBlocks = blocks;
		}
	} );
}

domReady( setupSubscriber );

export default setupSubscriber;
github Automattic / vip-go-mu-plugins-built / jetpack / extensions / blocks / image-compare / view.js View on Github external
* This code is incorporated into Image Compare plugin, which is licensed under
 * GPLv2+, however you may use Juxtapose code separately under the terms of its
 * original MPL 2.0 license if you wish.
 */

/**
 * WordPress dependencies
 */
import domReady from '@wordpress/dom-ready';

/**
 * Internal dependencies
 */
import './view.scss';

domReady( function () {
	const juxtapose = {
		sliders: [],
		OPTIMIZATION_ACCEPTED: 1,
		OPTIMIZATION_WAS_CONSTRAINED: 2,
	};

	function Graphic( properties, slider ) {
		const self = this;
		this.image = new Image();

		this.loaded = false;
		this.image.onload = function () {
			self.loaded = true;
			slider._onLoaded();
		};
github Automattic / vip-go-mu-plugins-built / jetpack / extensions / blocks / tiled-gallery / view.js View on Github external
}

	const observer = new ResizeObserver( handleObservedResize );

	galleries.forEach( gallery => {
		if ( gallery.getAttribute( 'data-jetpack-block-initialized' ) === 'true' ) {
			return;
		}

		observer.observe( gallery );
		gallery.setAttribute( 'data-jetpack-block-initialized', 'true' );
	} );
};

if ( typeof window !== 'undefined' ) {
	domReady( observeGalleries );
}
github Automattic / jetpack / extensions / blocks / tiled-gallery / view.js View on Github external
* Setup ResizeObserver to follow each gallery on the page
 */
const observeGalleries = () => {
	const galleries = getGalleries();

	if ( galleries.length === 0 ) {
		return;
	}

	const observer = new ResizeObserver( handleObservedResize );

	galleries.forEach( gallery => observer.observe( gallery ) );
};

if ( typeof window !== 'undefined' ) {
	domReady( observeGalleries );
}

@wordpress/dom-ready

Execute callback after the DOM is loaded.

GPL-2.0-or-later
Latest version published 17 days ago

Package Health Score

95 / 100
Full package analysis

Popular @wordpress/dom-ready functions