| @@ -97,11 +97,20 @@ | ||
| 97 | 97 | } else { |
| 98 | 98 | __tagembed__toast.danger({ message: __tagembed__message.__tagembed__message.replace(/-/g, ' '), position: '__tagembed__is-top-right' }); |
| 99 | 99 | } |
| 100 | 100 | /*--Start--Show Popup On Plan Upgrade Time*/ |
| 101 | - if (__tagembed__message.hasOwnProperty("planName") && __tagembed__message.hasOwnProperty("amount") && __tagembed__message.hasOwnProperty("paymentId")) { | |
| 101 | + /* Every query string value is read through one trimmed lookup, so a key that arrives with | |
| 102 | + no value at all (&paymentId) counts as absent instead of printing a blank box. */ | |
| 103 | + let __tagembed__queryValue = function (key) { | |
| 104 | + let __tagembed__raw = __tagembed__message[key]; | |
| 105 | + return String(__tagembed__raw === undefined || __tagembed__raw === null ? "" : __tagembed__raw).trim(); | |
| 106 | + }; | |
| 107 | + let __tagembed__planName = __tagembed__queryValue("planName"); | |
| 108 | + if (__tagembed__planName) { | |
| 102 | 109 | let __tagembed__upgrade_account_popup = document.querySelector("#__tagembed__upgrade_account_popup"); |
| 103 | - /* Built with DOM methods. The three query string values are inserted as text | |
| 110 | + /* The popup markup only exists on the upgrade screen, so nothing is built when it is absent. */ | |
| 111 | + if (!__tagembed__upgrade_account_popup) return; | |
| 112 | + /* Built with DOM methods. The query string values are inserted as text | |
| 104 | 113 | nodes only, so no markup can be produced from them. */ |
| 105 | 114 | let __tagembed__makeElement = function (tag, className) { |
| 106 | 115 | let __tagembed__element = document.createElement(tag); |
| 107 | 116 | if (className) __tagembed__element.className = className; |
| @@ -130,17 +139,30 @@ | ||
| 130 | 139 | __tagembed__checkImg.setAttribute("alt", "check"); |
| 131 | 140 | let __tagembed__heading = document.createElement("h2"); |
| 132 | 141 | __tagembed__heading.appendChild(document.createTextNode("Congratulations! ")); |
| 133 | 142 | let __tagembed__headingSpan = document.createElement("span"); |
| 134 | - __tagembed__headingSpan.textContent = "Your account has been upgraded"; | |
| 143 | + /* The popup repeats the message that came back in the query string, so an upgrade and a | |
| 144 | + downgrade each read correctly instead of both claiming an upgrade. */ | |
| 145 | + __tagembed__headingSpan.textContent = __tagembed__message.__tagembed__message.replace(/-/g, ' '); | |
| 135 | 146 | __tagembed__heading.appendChild(__tagembed__headingSpan); |
| 136 | 147 | let __tagembed__detail = __tagembed__makeElement("div", "__tagembed__plandetail"); |
| 137 | - __tagembed__detail.appendChild(__tagembed__makePlanBox("Amount", "$" + __tagembed__message.amount)); | |
| 138 | - __tagembed__detail.appendChild(__tagembed__makePlanBox("Payment Id", __tagembed__message.paymentId)); | |
| 139 | - __tagembed__detail.appendChild(__tagembed__makePlanBox("Plan", __tagembed__message.planName)); | |
| 148 | + /* A free plan costs nothing, so a missing or zero amount is left out rather than shown as $0. */ | |
| 149 | + let __tagembed__amount = __tagembed__queryValue("amount"); | |
| 150 | + let __tagembed__amountValue = Number(__tagembed__amount); | |
| 151 | + if (__tagembed__amount && !(isFinite(__tagembed__amountValue) && 0 === __tagembed__amountValue)) | |
| 152 | + __tagembed__detail.appendChild(__tagembed__makePlanBox("Amount", "$" + __tagembed__amount)); | |
| 153 | + /* A downgrade carries no payment, so the payment id is shown only when one actually arrived. */ | |
| 154 | + let __tagembed__paymentId = __tagembed__queryValue("paymentId"); | |
| 155 | + if (__tagembed__paymentId) | |
| 156 | + __tagembed__detail.appendChild(__tagembed__makePlanBox("Payment Id", __tagembed__paymentId)); | |
| 157 | + /* The free plan is the fallback every downgrade lands on, so naming it adds nothing. */ | |
| 158 | + if ("free" !== __tagembed__planName.toLowerCase()) | |
| 159 | + __tagembed__detail.appendChild(__tagembed__makePlanBox("Plan", __tagembed__planName)); | |
| 140 | 160 | __tagembed__thankyou.appendChild(__tagembed__checkImg); |
| 141 | 161 | __tagembed__thankyou.appendChild(__tagembed__heading); |
| 142 | - __tagembed__thankyou.appendChild(__tagembed__detail); | |
| 162 | + /* A free downgrade leaves out every detail, so the empty row is not added at all. */ | |
| 163 | + if (__tagembed__detail.hasChildNodes()) | |
| 164 | + __tagembed__thankyou.appendChild(__tagembed__detail); | |
| 143 | 165 | __tagembed__body.appendChild(__tagembed__thankyou); |
| 144 | 166 | __tagembed__inn.appendChild(__tagembed__body); |
| 145 | 167 | __tagembed__wrap.appendChild(__tagembed__closeBtn); |
| 146 | 168 | __tagembed__wrap.appendChild(__tagembed__inn); |