1/** 2 * My Account page behaviors (classic page-* PHP scripts). 3 */ 4( function () { 5 'use strict'; 6 7 function removeUrlParameter( url, parameter ) { 8 if ( ! url ) { 9 return url; 10 } 11 12 var urlparts = url.split( '?' ); 13 if ( urlparts.length < 2 ) { 14 return url; 15 } 16 17 var prefix = encodeURIComponent( parameter ) + '='; 18 var pars = urlparts[1].split( /[&;]/g ); 19 20 for ( var i = pars.length; i-- > 0; ) { 21 if ( pars[i].lastIndexOf( prefix, 0 ) !== -1 ) { 22 pars.splice( i, 1 ); 23 } 24 } 25 26 return urlparts[0] + ( pars.length > 0 ? '?' + pars.join( '&' ) : '' ); 27 } 28 29 function stripNoiseFromLinks( root ) { 30 var links = root.querySelectorAll( 'a[href]' ); 31 links.forEach( function ( link ) { 32 var href = link.getAttribute( 'href' ); 33 if ( ! href ) { 34 return; 35 } 36 href = removeUrlParameter( href, 'edd-message' ); 37 href = removeUrlParameter( href, 'updated' ); 38 link.setAttribute( 'href', href ); 39 } ); 40 } 41 42 function openInNewTab( selector ) { 43 document.querySelectorAll( selector ).forEach( function ( el ) { 44 el.setAttribute( 'target', '_blank' ); 45 el.setAttribute( 'rel', 'noopener noreferrer' ); 46 } ); 47 } 48 49 /** 50 * EDD subscription status markup is plain text â map labels to badge classes. 51 */ 52 function tagSubscriptionStatuses() { 53 var map = { 54 active: 'is-active', 55 trialling: 'is-trialling', 56 trialing: 'is-trialling', 57 cancelled: 'is-cancelled', 58 canceled: 'is-cancelled', 59 expired: 'is-expired', 60 failing: 'is-failing', 61 'needs attention': 'is-needs_attention', 62 }; 63 64 document 65 .querySelectorAll( '.edd-blocks-subscriptions__subscription-status' ) 66 .forEach( function ( el ) { 67 var key = ( el.textContent || '' ).trim().toLowerCase(); 68 var cls = map[ key ]; 69 if ( cls ) { 70 el.classList.add( cls ); 71 } 72 } ); 73 } 74 75 function subscriptionFlash() { 76 var params = new URLSearchParams( window.location.search ); 77 var messageKey = params.get( 'edd-message' ); 78 var text = null; 79 80 if ( 'cancelled' === messageKey ) { 81 text = 82 "Your subscription was successfully cancelled. We're sorry to see you go!"; 83 } else if ( 'reactivated' === messageKey ) { 84 text = 'Your subscription was successfully reactivated!'; 85 } 86 87 if ( ! text ) { 88 return; 89 } 90 91 var mount = 92 document.querySelector( '.wsft-my-account' ) || 93 document.querySelector( 'main' ); 94 if ( ! mount ) { 95 return; 96 } 97 98 var heading = mount.querySelector( 'h2' ); 99 var alert = document.createElement( 'div' ); 100 alert.className = 'edd-alert edd-alert-success wsft-edd-account-flash'; 101 alert.setAttribute( 'role', 'status' ); 102 alert.innerHTML = '<strong>Success:</strong> ' + text; 103 104 if ( heading && heading.parentNode ) { 105 heading.parentNode.insertBefore( alert, heading.nextSibling ); 106 } else { 107 mount.insertBefore( alert, mount.firstChild ); 108 } 109 } 110 111 document.addEventListener( 'DOMContentLoaded', function () { 112 var main = document.querySelector( 'main' ) || document.body; 113 114 openInNewTab( '.edd_purchase_details a' ); 115 openInNewTab( 'a.edd_subscription_invoice' ); 116 openInNewTab( '.edd_subscription_invoice' ); 117 118 stripNoiseFromLinks( main ); 119 tagSubscriptionStatuses(); 120 121 if ( /\/my-account\/subscriptions\/?/.test( window.location.pathname ) ) { 122 subscriptionFlash(); 123 } 124 } ); 125} )();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.