// NOTICE! This file exists in WPCOM & WPCOMSH. Updates need to be synced to both repos. /* eslint-disable no-multi-str */ /* global gifting_banner */ ( function () { document.addEventListener( 'DOMContentLoaded', function () { const hostnames = [ 'wordpress.com', 'w.link', 'automattic.com' ]; // Make sure we never show the banner on these hostnames. if ( hostnames.includes( window.location.hostname ) ) { return; } const bumpStat = function ( statName ) { new Image().src = document.location.protocol + '//pixel.wp.com/b.gif' + '?v=wpcom-no-pv' + '&x_simple_gifting_banner=' + statName + '&rand=' + Math.random(); }; if ( ! document.cookie.includes( 'wpcom_gifting_banner_gifter=true' ) ) { giftingBanner(); bumpStat( 'viewed_total' ); document.getElementById( 'wpcom-gifting-banner-button' ).onclick = function () { bumpStat( 'clicked' ); window.location.href = gifting_banner.checkout_link; }; document.getElementById( 'wpcom-gifting-banner-more-info-button' ).onclick = function () { bumpStat( 'moreinfo' ); window.open( gifting_banner.more_info_link, '_blank' ); }; } } ); /** * Prepend the gifting banner to the document body. */ function giftingBanner() { // Check for hash in URL to see if we should dismiss the banner const hash = location.hash; if ( '#gift-thank-you' === hash ) { const expiration = new Date(); expiration.setTime( expiration.getTime() + 1000 * 60 * 60 * 24 * gifting_banner.dismiss_days_count ); const expires = 'expires=' + expiration.toUTCString(); document.cookie = 'wpcom_gifting_banner_gifter=true;' + expires + ';path=/'; location.hash = ''; return; } const notice = document.createElement( 'div' ); notice.setAttribute( 'id', 'wpcom-gifting-banner' ); notice.classList.add( 'wpcom-gifting-banner' ); document.documentElement.classList.add( 'has-wpcom-gifting-banner' ); notice.innerHTML = '
' + '' + '
' + '' + '🎁' + '' + '
' + '' + '
'; const title = document.createTextNode( gifting_banner.i18n.title ); const subtitle = document.createTextNode( gifting_banner.i18n.subtitle ); const more_info_button = document.createElement( 'BUTTON' ); more_info_button.setAttribute( 'id', 'wpcom-gifting-banner-more-info-button' ); more_info_button.setAttribute( 'class', 'wpcom-gifting-banner__more-info-button' ); const button_text = document.createTextNode( gifting_banner.i18n.button_text ); notice.getElementsByClassName( 'wpcom-gifting-banner__title' )[ 0 ].appendChild( title ); notice.getElementsByClassName( 'wpcom-gifting-banner__subtitle' )[ 0 ].appendChild( subtitle ); notice .getElementsByClassName( 'wpcom-gifting-banner__subtitle' )[ 0 ] .appendChild( more_info_button ); notice.getElementsByClassName( 'wpcom-gifting-banner__button' )[ 0 ].appendChild( button_text ); document.body.prepend( notice ); } } )();