diff options
author | Anthony G. Basile <blueness@gentoo.org> | 2020-01-06 14:32:30 -0500 |
---|---|---|
committer | Anthony G. Basile <blueness@gentoo.org> | 2020-01-06 14:32:30 -0500 |
commit | 10ef81bf85ad0a4bad0d204838e14c99ca2526f7 (patch) | |
tree | b4bb36a326d41de12d1a6181d2a2baf34696ac24 /plugins/jetpack/extensions/blocks/mailchimp/view.js | |
parent | Updating script for Update (diff) | |
download | blogs-gentoo-10ef81bf85ad0a4bad0d204838e14c99ca2526f7.tar.gz blogs-gentoo-10ef81bf85ad0a4bad0d204838e14c99ca2526f7.tar.bz2 blogs-gentoo-10ef81bf85ad0a4bad0d204838e14c99ca2526f7.zip |
Update jetpack 8.0
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'plugins/jetpack/extensions/blocks/mailchimp/view.js')
-rw-r--r-- | plugins/jetpack/extensions/blocks/mailchimp/view.js | 91 |
1 files changed, 0 insertions, 91 deletions
diff --git a/plugins/jetpack/extensions/blocks/mailchimp/view.js b/plugins/jetpack/extensions/blocks/mailchimp/view.js deleted file mode 100644 index a2ec7680..00000000 --- a/plugins/jetpack/extensions/blocks/mailchimp/view.js +++ /dev/null @@ -1,91 +0,0 @@ -/** - * Internal dependencies - */ -import emailValidator from 'email-validator'; - -/** - * Internal dependencies - */ -import './view.scss'; - -const blockClassName = 'wp-block-jetpack-mailchimp'; - -function fetchSubscription( blogId, email ) { - const url = - 'https://public-api.wordpress.com/rest/v1.1/sites/' + - encodeURIComponent( blogId ) + - '/email_follow/subscribe?email=' + - encodeURIComponent( email ); - return new Promise( function( resolve, reject ) { - const xhr = new XMLHttpRequest(); - xhr.open( 'GET', url ); - xhr.onload = function() { - if ( xhr.status === 200 ) { - const res = JSON.parse( xhr.responseText ); - resolve( res ); - } else { - const res = JSON.parse( xhr.responseText ); - reject( res ); - } - }; - xhr.send(); - } ); -} - -function activateSubscription( block, blogId ) { - const form = block.querySelector( 'form' ); - const errorClass = 'error'; - const processingEl = block.querySelector( '.' + blockClassName + '_processing' ); - const errorEl = block.querySelector( '.' + blockClassName + '_error' ); - const successEl = block.querySelector( '.' + blockClassName + '_success' ); - form.addEventListener( 'submit', e => { - e.preventDefault(); - const emailField = form.querySelector( 'input' ); - emailField.classList.remove( errorClass ); - const email = emailField.value; - if ( ! emailValidator.validate( email ) ) { - emailField.classList.add( errorClass ); - return; - } - block.classList.add( 'is-processing' ); - processingEl.classList.add( 'is-visible' ); - fetchSubscription( blogId, email ).then( - response => { - processingEl.classList.remove( 'is-visible' ); - if ( response.error && response.error !== 'member_exists' ) { - errorEl.classList.add( 'is-visible' ); - } else { - successEl.classList.add( 'is-visible' ); - } - }, - () => { - processingEl.classList.remove( 'is-visible' ); - errorEl.classList.add( 'is-visible' ); - } - ); - } ); -} - -const initializeMailchimpBlocks = () => { - const mailchimpBlocks = Array.from( document.querySelectorAll( '.' + blockClassName ) ); - mailchimpBlocks.forEach( block => { - 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 ); - } - } - } ); -}; - -if ( typeof window !== 'undefined' && typeof document !== 'undefined' ) { - // `DOMContentLoaded` may fire before the script has a chance to run - if ( document.readyState === 'loading' ) { - document.addEventListener( 'DOMContentLoaded', initializeMailchimpBlocks ); - } else { - initializeMailchimpBlocks(); - } -} |