| 1 |
jQuery(document).ready(function () { |
| 2 |
const slug = "yaymail"; |
| 3 |
const pluginSettingPage = "yaymail-settings"; |
| 4 |
const REST_URL = |
| 5 |
window[`${slug}LicenseData`].apiSettings.restUrl; |
| 6 |
const ADMIN_URL = |
| 7 |
window[`${slug}LicenseData`].apiSettings.adminUrl; |
| 8 |
const POST_OPTIONS = { |
| 9 |
method: "POST", |
| 10 |
headers: { |
| 11 |
"Content-type": "application/json", |
| 12 |
}, |
| 13 |
}; |
| 14 |
|
| 15 |
jQuery(".yaycommerce-license-layout").on( |
| 16 |
"click", |
| 17 |
`.yaycommerce-activate-license-button[data-plugin*='${slug}']`, |
| 18 |
handleActivate |
| 19 |
); |
| 20 |
jQuery(".yaycommerce-license-layout").on( |
| 21 |
"click", |
| 22 |
`.yaycommerce-update-license[data-plugin*='${slug}']`, |
| 23 |
handleUpdate |
| 24 |
); |
| 25 |
jQuery(".yaycommerce-license-layout").on( |
| 26 |
"click", |
| 27 |
`.yaycommerce-remove-license[data-plugin*='${slug}']`, |
| 28 |
handleRemove |
| 29 |
); |
| 30 |
|
| 31 |
let timeout; |
| 32 |
|
| 33 |
async function handleActivate(event) { |
| 34 |
event.preventDefault(); |
| 35 |
clearTimeout(timeout); |
| 36 |
const { plugin } = jQuery(this).data(); |
| 37 |
beforeCallAPI(plugin, "activate"); |
| 38 |
hideMessage(plugin); |
| 39 |
const licenseKey = jQuery(`#${plugin}_license_input`).val(); |
| 40 |
|
| 41 |
const response = await fetch(`${REST_URL}/license/activate`, { |
| 42 |
...POST_OPTIONS, |
| 43 |
body: JSON.stringify({ |
| 44 |
license_key: licenseKey, |
| 45 |
plugin, |
| 46 |
}), |
| 47 |
}).then((response) => response.json()); |
| 48 |
afterCallAPI(plugin, "activate"); |
| 49 |
if (response.success) { |
| 50 |
replaceSuccessfullContent(response); |
| 51 |
} else { |
| 52 |
showMessage(response); |
| 53 |
timeout = setTimeout(()=>{ |
| 54 |
hideMessage(plugin) |
| 55 |
},3000); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
async function handleUpdate(event) { |
| 60 |
event.preventDefault(); |
| 61 |
const { plugin } = jQuery(this).data(); |
| 62 |
beforeCallAPI(plugin, "update"); |
| 63 |
const response = await fetch(`${REST_URL}/license/update`, { |
| 64 |
...POST_OPTIONS, |
| 65 |
body: JSON.stringify({ |
| 66 |
plugin, |
| 67 |
}), |
| 68 |
}).then((response) => response.json()); |
| 69 |
afterCallAPI(plugin, "update"); |
| 70 |
if (response.success) { |
| 71 |
replaceSuccessfullContent(response); |
| 72 |
} else { |
| 73 |
replaceActivatorContent(response); |
| 74 |
} |
| 75 |
} |
| 76 |
async function handleRemove(event) { |
| 77 |
event.preventDefault(); |
| 78 |
const { plugin } = jQuery(this).data(); |
| 79 |
beforeCallAPI(plugin, "remove"); |
| 80 |
const response = await fetch(`${REST_URL}/license/delete`, { |
| 81 |
...POST_OPTIONS, |
| 82 |
body: JSON.stringify({ |
| 83 |
plugin, |
| 84 |
}), |
| 85 |
}).then((response) => response.json()); |
| 86 |
afterCallAPI(plugin, "remove"); |
| 87 |
replaceActivatorContent(response); |
| 88 |
} |
| 89 |
|
| 90 |
function replaceSuccessfullContent(data) { |
| 91 |
jQuery( |
| 92 |
`#${data.slug}_license_card .yaycommerce-license-card-header-item` |
| 93 |
).html(` |
| 94 |
${data.name} |
| 95 |
<span class="yaycommerce-license-badge ${data.is_expired ? "error" : "success"}">${data.is_expired ? "Expired" : "Active"}</span> |
| 96 |
`); |
| 97 |
jQuery(`#${data.slug}_license_card .yaycommerce-license-card-body`).html(` |
| 98 |
<table class="yaycommerce-license-table"> |
| 99 |
<tbody> |
| 100 |
<tr class="yaycommerce-license-tr"> |
| 101 |
<td class="yaycommerce-license-key-text" >Your License Key:</td> |
| 102 |
<td class="yaycommerce-license-text"> |
| 103 |
<input type="text" disabled value="${ |
| 104 |
data.formatted_license_key |
| 105 |
}" /> |
| 106 |
</td> |
| 107 |
<td> |
| 108 |
<button class="button yaycommerce-update-license" data-plugin="${data.slug}"> |
| 109 |
<span>Update</span> |
| 110 |
<span class="activate-loading sync-loading"> |
| 111 |
<svg |
| 112 |
data-v-7957300f="" |
| 113 |
xmlns="http://www.w3.org/2000/svg" |
| 114 |
viewBox="0 0 24 24" |
| 115 |
> |
| 116 |
<path |
| 117 |
data-v-7957300f="" |
| 118 |
d="M21.66 10.37a.62.62 0 00.07-.19l.75-4a1 1 0 00-2-.36l-.37 2a9.22 9.22 0 00-16.58.84 1 1 0 00.55 1.3 1 1 0 001.31-.55A7.08 7.08 0 0112.07 5a7.17 7.17 0 016.24 3.58l-1.65-.27a1 1 0 10-.32 2l4.25.71h.16a.93.93 0 00.34-.06.33.33 0 00.1-.06.78.78 0 00.2-.11l.08-.1a1.07 1.07 0 00.14-.16.58.58 0 00.05-.16zM19.88 14.07a1 1 0 00-1.31.56A7.08 7.08 0 0111.93 19a7.17 7.17 0 01-6.24-3.58l1.65.27h.16a1 1 0 00.16-2L3.41 13a.91.91 0 00-.33 0H3a1.15 1.15 0 00-.32.14 1 1 0 00-.18.18l-.09.1a.84.84 0 00-.07.19.44.44 0 00-.07.17l-.75 4a1 1 0 00.8 1.22h.18a1 1 0 001-.82l.37-2a9.22 9.22 0 0016.58-.83 1 1 0 00-.57-1.28z" |
| 119 |
></path> |
| 120 |
</svg> |
| 121 |
</span> |
| 122 |
</button> |
| 123 |
<button class="button yaycommerce-remove-license" data-plugin="${data.slug}"> |
| 124 |
<span>Remove</span> |
| 125 |
<span class="activate-loading sync-loading"> |
| 126 |
<svg |
| 127 |
data-v-7957300f="" |
| 128 |
xmlns="http://www.w3.org/2000/svg" |
| 129 |
viewBox="0 0 24 24" |
| 130 |
> |
| 131 |
<path |
| 132 |
data-v-7957300f="" |
| 133 |
d="M21.66 10.37a.62.62 0 00.07-.19l.75-4a1 1 0 00-2-.36l-.37 2a9.22 9.22 0 00-16.58.84 1 1 0 00.55 1.3 1 1 0 001.31-.55A7.08 7.08 0 0112.07 5a7.17 7.17 0 016.24 3.58l-1.65-.27a1 1 0 10-.32 2l4.25.71h.16a.93.93 0 00.34-.06.33.33 0 00.1-.06.78.78 0 00.2-.11l.08-.1a1.07 1.07 0 00.14-.16.58.58 0 00.05-.16zM19.88 14.07a1 1 0 00-1.31.56A7.08 7.08 0 0111.93 19a7.17 7.17 0 01-6.24-3.58l1.65.27h.16a1 1 0 00.16-2L3.41 13a.91.91 0 00-.33 0H3a1.15 1.15 0 00-.32.14 1 1 0 00-.18.18l-.09.1a.84.84 0 00-.07.19.44.44 0 00-.07.17l-.75 4a1 1 0 00.8 1.22h.18a1 1 0 001-.82l.37-2a9.22 9.22 0 0016.58-.83 1 1 0 00-.57-1.28z" |
| 134 |
></path> |
| 135 |
</svg> |
| 136 |
</span> |
| 137 |
</button> |
| 138 |
</td> |
| 139 |
</tr> |
| 140 |
<tr class="yaycommerce-license-tr"> |
| 141 |
<td class="yaycommerce-license-key-text" >Expiration Date:</td> |
| 142 |
<td class="yaycommerce-license-text"> |
| 143 |
${data.expires} |
| 144 |
${ |
| 145 |
data.is_expired |
| 146 |
? `<strong class="yaycommerce-license-expired-text">(Expired)</strong>` |
| 147 |
: "" |
| 148 |
} |
| 149 |
</td> |
| 150 |
</tr> |
| 151 |
</tbody> |
| 152 |
</table> |
| 153 |
<p> |
| 154 |
${ |
| 155 |
!data.is_expired |
| 156 |
? `<a href="${ADMIN_URL}admin.php?page=${pluginSettingPage}"><strong>Start customizing</strong></a>` |
| 157 |
: "" |
| 158 |
} |
| 159 |
</p> |
| 160 |
<p>Need more licenses? <a class="yaycommerce-license-buy-now" href="${data.plugin_url}" target="_blank">Buy Now</a></p> |
| 161 |
${ |
| 162 |
data.is_expired |
| 163 |
? `<p><strong class="yaycommerce-license-expired-text">Your license is expired! <a href="${data.renewal_url}" class="yaycommerce-license-expired-text" target="_blank">Renew Now!</a></strong></p>` |
| 164 |
: "" |
| 165 |
} |
| 166 |
|
| 167 |
`); |
| 168 |
} |
| 169 |
function replaceActivatorContent(data) { |
| 170 |
jQuery(`#${data.slug}_license_card .yaycommerce-license-card-header-item`).html( |
| 171 |
`${data.name} activation` |
| 172 |
); |
| 173 |
jQuery(`#${data.slug}_license_card .yaycommerce-license-card-body`).html(` |
| 174 |
<div class="yaycommerce-license-control"> |
| 175 |
<div class="yaycommerce-license-text" for="inspector-select-control-text">Enter a license key</div> |
| 176 |
<div class="yaycommerce-license-base-control"> |
| 177 |
<div class="yaycommerce-license-base-control-field"> |
| 178 |
<input class="yaycommerce-license-text-control-input yaycommerce-license-input" type="password" id="${data.slug}_license_input" value="" /> |
| 179 |
<button class="button-primary yaycommerce-activate-license-button" id="${data.slug}_activate_button" data-plugin="${data.slug}"> |
| 180 |
<span>Activate License</span> |
| 181 |
<span class="activate-loading sync-loading"> |
| 182 |
<svg |
| 183 |
data-v-7957300f="" |
| 184 |
xmlns="http://www.w3.org/2000/svg" |
| 185 |
viewBox="0 0 24 24" |
| 186 |
> |
| 187 |
<path |
| 188 |
data-v-7957300f="" |
| 189 |
d="M21.66 10.37a.62.62 0 00.07-.19l.75-4a1 1 0 00-2-.36l-.37 2a9.22 9.22 0 00-16.58.84 1 1 0 00.55 1.3 1 1 0 001.31-.55A7.08 7.08 0 0112.07 5a7.17 7.17 0 016.24 3.58l-1.65-.27a1 1 0 10-.32 2l4.25.71h.16a.93.93 0 00.34-.06.33.33 0 00.1-.06.78.78 0 00.2-.11l.08-.1a1.07 1.07 0 00.14-.16.58.58 0 00.05-.16zM19.88 14.07a1 1 0 00-1.31.56A7.08 7.08 0 0111.93 19a7.17 7.17 0 01-6.24-3.58l1.65.27h.16a1 1 0 00.16-2L3.41 13a.91.91 0 00-.33 0H3a1.15 1.15 0 00-.32.14 1 1 0 00-.18.18l-.09.1a.84.84 0 00-.07.19.44.44 0 00-.07.17l-.75 4a1 1 0 00.8 1.22h.18a1 1 0 001-.82l.37-2a9.22 9.22 0 0016.58-.83 1 1 0 00-.57-1.28z" |
| 190 |
></path> |
| 191 |
</svg> |
| 192 |
</span> |
| 193 |
</button> |
| 194 |
</div> |
| 195 |
<p>To receive updates, please enter your valid ${data.name} license key</p> |
| 196 |
</div> |
| 197 |
<div class="yaycommerce-license-text" for="inspector-select-control-text">By activating ${data.name}, you'll have:</div> |
| 198 |
<ul class="yaycommerce-license-in-feature"> |
| 199 |
<li>Auto-update to the latest version</li> |
| 200 |
<li>Premium Technical Support</li> |
| 201 |
<li>Live Chat 1-1 on Facebook for any questions</li> |
| 202 |
</ul> |
| 203 |
</div> |
| 204 |
`); |
| 205 |
} |
| 206 |
function showMessage(data) { |
| 207 |
const { slug, success, message } = data; |
| 208 |
jQuery(`#${slug}_license_card .yaycommerce-license-message`).addClass("show"); |
| 209 |
if (!success) { |
| 210 |
jQuery(`#${slug}_license_card .yaycommerce-license-message`).html(` |
| 211 |
<span>${message}</span> |
| 212 |
`); |
| 213 |
} |
| 214 |
} |
| 215 |
function hideMessage(slug) { |
| 216 |
jQuery(`#${slug}_license_card .yaycommerce-license-message`).removeClass( |
| 217 |
"show" |
| 218 |
); |
| 219 |
jQuery(`#${slug}_license_card .yaycommerce-license-message`).html(""); |
| 220 |
} |
| 221 |
|
| 222 |
function beforeCallAPI(plugin, action) { |
| 223 |
if (action === "activate") { |
| 224 |
jQuery(`.yaycommerce-activate-license-button[data-plugin=${plugin}]`) |
| 225 |
.find(".activate-loading") |
| 226 |
.css("display", "inline-flex"); |
| 227 |
} |
| 228 |
|
| 229 |
if (action === "update") { |
| 230 |
jQuery(`.yaycommerce-update-license[data-plugin=${plugin}]`) |
| 231 |
.find(".activate-loading") |
| 232 |
.css("display", "inline-flex"); |
| 233 |
} |
| 234 |
|
| 235 |
if (action === "remove") { |
| 236 |
jQuery(`.yaycommerce-remove-license[data-plugin=${plugin}]`) |
| 237 |
.find(".activate-loading") |
| 238 |
.css("display", "inline-flex"); |
| 239 |
} |
| 240 |
|
| 241 |
jQuery(`.yaycommerce-activate-license-button[data-plugin=${plugin}]`).attr( |
| 242 |
"disabled", |
| 243 |
true |
| 244 |
); |
| 245 |
jQuery(`.yaycommerce-update-license[data-plugin=${plugin}]`).attr( |
| 246 |
"disabled", |
| 247 |
true |
| 248 |
); |
| 249 |
jQuery(`.yaycommerce-remove-license[data-plugin="${plugin}"]`).attr( |
| 250 |
"disabled", |
| 251 |
true |
| 252 |
); |
| 253 |
} |
| 254 |
|
| 255 |
function afterCallAPI(plugin, action) { |
| 256 |
if (action === "activate") { |
| 257 |
jQuery(`.yaycommerce-activate-license-button[data-plugin=${plugin}]`) |
| 258 |
.find(".activate-loading") |
| 259 |
.hide(); |
| 260 |
} |
| 261 |
|
| 262 |
if (action === "update") { |
| 263 |
jQuery(`.yaycommerce-update-license[data-plugin=${plugin}]`) |
| 264 |
.find(".activate-loading") |
| 265 |
.hide(); |
| 266 |
} |
| 267 |
|
| 268 |
if (action === "remove") { |
| 269 |
jQuery(`.yaycommerce-remove-license[data-plugin=${plugin}]`) |
| 270 |
.find(".activate-loading") |
| 271 |
.hide(); |
| 272 |
} |
| 273 |
jQuery(`.yaycommerce-activate-license-button[data-plugin=${plugin}]`).attr( |
| 274 |
"disabled", |
| 275 |
false |
| 276 |
); |
| 277 |
jQuery(`.yaycommerce-update-license[data-plugin=${plugin}]`).attr( |
| 278 |
"disabled", |
| 279 |
false |
| 280 |
); |
| 281 |
jQuery(`.yaycommerce-remove-license[data-plugin="${plugin}"]`).attr( |
| 282 |
"disabled", |
| 283 |
false |
| 284 |
); |
| 285 |
} |
| 286 |
}); |
| 287 |
|