| 1 |
/******/ (() => { // webpackBootstrap |
| 2 |
/******/ "use strict"; |
| 3 |
/******/ var __webpack_modules__ = ({ |
| 4 |
|
| 5 |
/***/ "./assets/src/js/utils.js" |
| 6 |
/*!********************************!*\ |
| 7 |
!*** ./assets/src/js/utils.js ***! |
| 8 |
\********************************/ |
| 9 |
(__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 10 |
|
| 11 |
__webpack_require__.r(__webpack_exports__); |
| 12 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 13 |
/* harmony export */ debounce: () => (/* binding */ debounce), |
| 14 |
/* harmony export */ eventHandlers: () => (/* binding */ eventHandlers), |
| 15 |
/* harmony export */ getDataOfForm: () => (/* binding */ getDataOfForm), |
| 16 |
/* harmony export */ getFieldKeysOfForm: () => (/* binding */ getFieldKeysOfForm), |
| 17 |
/* harmony export */ listenElementCreated: () => (/* binding */ listenElementCreated), |
| 18 |
/* harmony export */ listenElementViewed: () => (/* binding */ listenElementViewed), |
| 19 |
/* harmony export */ lpAddQueryArgs: () => (/* binding */ lpAddQueryArgs), |
| 20 |
/* harmony export */ lpAjaxParseJsonOld: () => (/* binding */ lpAjaxParseJsonOld), |
| 21 |
/* harmony export */ lpClassName: () => (/* binding */ lpClassName), |
| 22 |
/* harmony export */ lpFetchAPI: () => (/* binding */ lpFetchAPI), |
| 23 |
/* harmony export */ lpGetCurrentURLNoParam: () => (/* binding */ lpGetCurrentURLNoParam), |
| 24 |
/* harmony export */ lpOnElementReady: () => (/* binding */ lpOnElementReady), |
| 25 |
/* harmony export */ lpSetLoadingEl: () => (/* binding */ lpSetLoadingEl), |
| 26 |
/* harmony export */ lpShowHideEl: () => (/* binding */ lpShowHideEl), |
| 27 |
/* harmony export */ mergeDataWithDatForm: () => (/* binding */ mergeDataWithDatForm), |
| 28 |
/* harmony export */ toggleCollapse: () => (/* binding */ toggleCollapse) |
| 29 |
/* harmony export */ }); |
| 30 |
/** |
| 31 |
* Utils functions |
| 32 |
* |
| 33 |
* @param url |
| 34 |
* @param data |
| 35 |
* @param functions |
| 36 |
* @since 4.2.5.1 |
| 37 |
* @version 1.0.6 |
| 38 |
*/ |
| 39 |
const lpClassName = { |
| 40 |
hidden: 'lp-hidden', |
| 41 |
loading: 'loading', |
| 42 |
elCollapse: 'lp-collapse', |
| 43 |
elSectionToggle: '.lp-section-toggle', |
| 44 |
elTriggerToggle: '.lp-trigger-toggle' |
| 45 |
}; |
| 46 |
const lpFetchAPI = (url, data = {}, functions = {}) => { |
| 47 |
if ('function' === typeof functions.before) { |
| 48 |
functions.before(); |
| 49 |
} |
| 50 |
fetch(url, { |
| 51 |
method: 'GET', |
| 52 |
...data |
| 53 |
}).then(response => response.json()).then(response => { |
| 54 |
if ('function' === typeof functions.success) { |
| 55 |
functions.success(response); |
| 56 |
} |
| 57 |
}).catch(err => { |
| 58 |
if ('function' === typeof functions.error) { |
| 59 |
functions.error(err); |
| 60 |
} |
| 61 |
}).finally(() => { |
| 62 |
if ('function' === typeof functions.completed) { |
| 63 |
functions.completed(); |
| 64 |
} |
| 65 |
}); |
| 66 |
}; |
| 67 |
|
| 68 |
/** |
| 69 |
* Get current URL without params. |
| 70 |
* |
| 71 |
* @since 4.2.5.1 |
| 72 |
*/ |
| 73 |
const lpGetCurrentURLNoParam = () => { |
| 74 |
let currentUrl = window.location.href; |
| 75 |
const hasParams = currentUrl.includes('?'); |
| 76 |
if (hasParams) { |
| 77 |
currentUrl = currentUrl.split('?')[0]; |
| 78 |
} |
| 79 |
return currentUrl; |
| 80 |
}; |
| 81 |
const lpAddQueryArgs = (endpoint, args) => { |
| 82 |
const url = new URL(endpoint); |
| 83 |
Object.keys(args).forEach(arg => { |
| 84 |
url.searchParams.set(arg, args[arg]); |
| 85 |
}); |
| 86 |
return url; |
| 87 |
}; |
| 88 |
|
| 89 |
/** |
| 90 |
* Listen element viewed. |
| 91 |
* |
| 92 |
* @param el |
| 93 |
* @param callback |
| 94 |
* @since 4.2.5.8 |
| 95 |
*/ |
| 96 |
const listenElementViewed = (el, callback) => { |
| 97 |
const observerSeeItem = new IntersectionObserver(function (entries) { |
| 98 |
for (const entry of entries) { |
| 99 |
if (entry.isIntersecting) { |
| 100 |
callback(entry); |
| 101 |
} |
| 102 |
} |
| 103 |
}); |
| 104 |
observerSeeItem.observe(el); |
| 105 |
}; |
| 106 |
|
| 107 |
/** |
| 108 |
* Listen element created. |
| 109 |
* |
| 110 |
* @param callback |
| 111 |
* @since 4.2.5.8 |
| 112 |
*/ |
| 113 |
const listenElementCreated = callback => { |
| 114 |
const observerCreateItem = new MutationObserver(function (mutations) { |
| 115 |
mutations.forEach(function (mutation) { |
| 116 |
if (mutation.addedNodes) { |
| 117 |
mutation.addedNodes.forEach(function (node) { |
| 118 |
if (node.nodeType === 1) { |
| 119 |
callback(node); |
| 120 |
} |
| 121 |
}); |
| 122 |
} |
| 123 |
}); |
| 124 |
}); |
| 125 |
observerCreateItem.observe(document, { |
| 126 |
childList: true, |
| 127 |
subtree: true |
| 128 |
}); |
| 129 |
// End. |
| 130 |
}; |
| 131 |
|
| 132 |
/** |
| 133 |
* Listen element created. |
| 134 |
* |
| 135 |
* @param selector |
| 136 |
* @param callback |
| 137 |
* @since 4.2.7.1 |
| 138 |
*/ |
| 139 |
const lpOnElementReady = (selector, callback) => { |
| 140 |
const element = document.querySelector(selector); |
| 141 |
if (element) { |
| 142 |
callback(element); |
| 143 |
return; |
| 144 |
} |
| 145 |
const observer = new MutationObserver((mutations, obs) => { |
| 146 |
const element = document.querySelector(selector); |
| 147 |
if (element) { |
| 148 |
obs.disconnect(); |
| 149 |
callback(element); |
| 150 |
} |
| 151 |
}); |
| 152 |
observer.observe(document.documentElement, { |
| 153 |
childList: true, |
| 154 |
subtree: true |
| 155 |
}); |
| 156 |
}; |
| 157 |
|
| 158 |
// Parse JSON from string with content include LP_AJAX_START. |
| 159 |
const lpAjaxParseJsonOld = data => { |
| 160 |
if (typeof data !== 'string') { |
| 161 |
return data; |
| 162 |
} |
| 163 |
const m = String.raw({ |
| 164 |
raw: data |
| 165 |
}).match(/<-- LP_AJAX_START -->(.*)<-- LP_AJAX_END -->/s); |
| 166 |
try { |
| 167 |
if (m) { |
| 168 |
data = JSON.parse(m[1].replace(/(?:\r\n|\r|\n)/g, '')); |
| 169 |
} else { |
| 170 |
data = JSON.parse(data); |
| 171 |
} |
| 172 |
} catch (e) { |
| 173 |
data = {}; |
| 174 |
} |
| 175 |
return data; |
| 176 |
}; |
| 177 |
|
| 178 |
// status 0: hide, 1: show |
| 179 |
const lpShowHideEl = (el, status = 0) => { |
| 180 |
if (!el) { |
| 181 |
return; |
| 182 |
} |
| 183 |
if (!status) { |
| 184 |
el.classList.add(lpClassName.hidden); |
| 185 |
} else { |
| 186 |
el.classList.remove(lpClassName.hidden); |
| 187 |
} |
| 188 |
}; |
| 189 |
|
| 190 |
// status 0: hide, 1: show |
| 191 |
const lpSetLoadingEl = (el, status) => { |
| 192 |
if (!el) { |
| 193 |
return; |
| 194 |
} |
| 195 |
if (!status) { |
| 196 |
el.classList.remove(lpClassName.loading); |
| 197 |
} else { |
| 198 |
el.classList.add(lpClassName.loading); |
| 199 |
} |
| 200 |
}; |
| 201 |
|
| 202 |
// Toggle collapse section |
| 203 |
const toggleCollapse = (e, target, elTriggerClassName = '', elsExclude = [], callback) => { |
| 204 |
if (!elTriggerClassName) { |
| 205 |
elTriggerClassName = lpClassName.elTriggerToggle; |
| 206 |
} |
| 207 |
|
| 208 |
// Exclude elements, which should not trigger the collapse toggle |
| 209 |
if (elsExclude && elsExclude.length > 0) { |
| 210 |
for (const elExclude of elsExclude) { |
| 211 |
if (target.closest(elExclude)) { |
| 212 |
return; |
| 213 |
} |
| 214 |
} |
| 215 |
} |
| 216 |
const elTrigger = target.closest(elTriggerClassName); |
| 217 |
if (!elTrigger) { |
| 218 |
return; |
| 219 |
} |
| 220 |
|
| 221 |
//console.log( 'elTrigger', elTrigger ); |
| 222 |
|
| 223 |
const elSectionToggle = elTrigger.closest(`${lpClassName.elSectionToggle}`); |
| 224 |
if (!elSectionToggle) { |
| 225 |
return; |
| 226 |
} |
| 227 |
elSectionToggle.classList.toggle(`${lpClassName.elCollapse}`); |
| 228 |
if ('function' === typeof callback) { |
| 229 |
callback(elSectionToggle); |
| 230 |
} |
| 231 |
}; |
| 232 |
|
| 233 |
// Get data of form |
| 234 |
const getDataOfForm = form => { |
| 235 |
const dataSend = {}; |
| 236 |
const formData = new FormData(form); |
| 237 |
for (const pair of formData.entries()) { |
| 238 |
const key = pair[0]; |
| 239 |
const value = formData.getAll(key); |
| 240 |
if (!dataSend.hasOwnProperty(key)) { |
| 241 |
// Convert value array to string. |
| 242 |
dataSend[key] = value.join(','); |
| 243 |
} |
| 244 |
} |
| 245 |
return dataSend; |
| 246 |
}; |
| 247 |
|
| 248 |
// Get field keys of form |
| 249 |
const getFieldKeysOfForm = form => { |
| 250 |
const keys = []; |
| 251 |
const elements = form.elements; |
| 252 |
for (let i = 0; i < elements.length; i++) { |
| 253 |
const name = elements[i].name; |
| 254 |
if (name && !keys.includes(name)) { |
| 255 |
keys.push(name); |
| 256 |
} |
| 257 |
} |
| 258 |
return keys; |
| 259 |
}; |
| 260 |
|
| 261 |
// Merge data handle with data form. |
| 262 |
const mergeDataWithDatForm = (elForm, dataHandle) => { |
| 263 |
const dataForm = getDataOfForm(elForm); |
| 264 |
const keys = getFieldKeysOfForm(elForm); |
| 265 |
keys.forEach(key => { |
| 266 |
if (!dataForm.hasOwnProperty(key)) { |
| 267 |
delete dataHandle[key]; |
| 268 |
} else if (dataForm[key][0] === '') { |
| 269 |
delete dataForm[key]; |
| 270 |
delete dataHandle[key]; |
| 271 |
} |
| 272 |
}); |
| 273 |
dataHandle = { |
| 274 |
...dataHandle, |
| 275 |
...dataForm |
| 276 |
}; |
| 277 |
return dataHandle; |
| 278 |
}; |
| 279 |
|
| 280 |
/** |
| 281 |
* Event trigger |
| 282 |
* For each list of event handlers, listen event on document. |
| 283 |
* |
| 284 |
* eventName: 'click', 'change', ... |
| 285 |
* eventHandlers = [ { selector: '.lp-button', callBack: function(){}, class: object } ] |
| 286 |
* |
| 287 |
* @param eventName |
| 288 |
* @param eventHandlers |
| 289 |
*/ |
| 290 |
const eventHandlers = (eventName, eventHandlers) => { |
| 291 |
document.addEventListener(eventName, e => { |
| 292 |
const target = e.target; |
| 293 |
let args = { |
| 294 |
e, |
| 295 |
target |
| 296 |
}; |
| 297 |
eventHandlers.forEach(eventHandler => { |
| 298 |
args = { |
| 299 |
...args, |
| 300 |
...eventHandler |
| 301 |
}; |
| 302 |
|
| 303 |
//console.log( args ); |
| 304 |
|
| 305 |
// Check condition before call back |
| 306 |
if (eventHandler.conditionBeforeCallBack) { |
| 307 |
if (eventHandler.conditionBeforeCallBack(args) !== true) { |
| 308 |
return; |
| 309 |
} |
| 310 |
} |
| 311 |
|
| 312 |
// Special check for keydown event with checkIsEventEnter = true |
| 313 |
if (eventName === 'keydown' && eventHandler.checkIsEventEnter) { |
| 314 |
if (e.key !== 'Enter') { |
| 315 |
return; |
| 316 |
} |
| 317 |
} |
| 318 |
if (target.closest(eventHandler.selector)) { |
| 319 |
if (eventHandler.class) { |
| 320 |
// Call method of class, function callBack will understand exactly {this} is class object. |
| 321 |
eventHandler.class[eventHandler.callBack](args); |
| 322 |
} else { |
| 323 |
// For send args is objected, {this} is eventHandler object, not class object. |
| 324 |
eventHandler.callBack(args); |
| 325 |
} |
| 326 |
} |
| 327 |
}); |
| 328 |
}); |
| 329 |
}; |
| 330 |
|
| 331 |
/** |
| 332 |
* Debounce - delays function execution until after `wait` ms of inactivity. |
| 333 |
* |
| 334 |
* Each call resets the timer. Only the last call in a burst executes. |
| 335 |
* |
| 336 |
* USE CASES: |
| 337 |
* - Search inputs, form validation, window resize |
| 338 |
* - Multiple elements need independent timers |
| 339 |
* - When you need to call with different arguments |
| 340 |
* |
| 341 |
* EXAMPLES: |
| 342 |
* const debouncedSearch = debounce( (query) => fetchResults(query), 300 ); |
| 343 |
* searchInput.addEventListener('input', (e) => debouncedSearch(e.target.value)); |
| 344 |
* |
| 345 |
* const debouncedResize = debounce( recalculateLayout, 250 ); |
| 346 |
* window.addEventListener('resize', debouncedResize); |
| 347 |
* |
| 348 |
* ⚠️ Create ONCE outside event handlers, not inside. |
| 349 |
* |
| 350 |
* @param {Function} func - Function to debounce (can be anonymous) |
| 351 |
* @param {number} wait - Milliseconds to wait (default: 500) |
| 352 |
* @return {Function} Debounced wrapper function |
| 353 |
* @since 4.3.7 |
| 354 |
* @version 1.0.0 |
| 355 |
*/ |
| 356 |
const debounce = (func, wait = 500) => { |
| 357 |
let timer; |
| 358 |
return args => { |
| 359 |
clearTimeout(timer); |
| 360 |
timer = setTimeout(() => func(args), wait); |
| 361 |
}; |
| 362 |
}; |
| 363 |
|
| 364 |
/***/ } |
| 365 |
|
| 366 |
/******/ }); |
| 367 |
/************************************************************************/ |
| 368 |
/******/ // The module cache |
| 369 |
/******/ var __webpack_module_cache__ = {}; |
| 370 |
/******/ |
| 371 |
/******/ // The require function |
| 372 |
/******/ function __webpack_require__(moduleId) { |
| 373 |
/******/ // Check if module is in cache |
| 374 |
/******/ var cachedModule = __webpack_module_cache__[moduleId]; |
| 375 |
/******/ if (cachedModule !== undefined) { |
| 376 |
/******/ return cachedModule.exports; |
| 377 |
/******/ } |
| 378 |
/******/ // Create a new module (and put it into the cache) |
| 379 |
/******/ var module = __webpack_module_cache__[moduleId] = { |
| 380 |
/******/ // no module.id needed |
| 381 |
/******/ // no module.loaded needed |
| 382 |
/******/ exports: {} |
| 383 |
/******/ }; |
| 384 |
/******/ |
| 385 |
/******/ // Execute the module function |
| 386 |
/******/ if (!(moduleId in __webpack_modules__)) { |
| 387 |
/******/ delete __webpack_module_cache__[moduleId]; |
| 388 |
/******/ var e = new Error("Cannot find module '" + moduleId + "'"); |
| 389 |
/******/ e.code = 'MODULE_NOT_FOUND'; |
| 390 |
/******/ throw e; |
| 391 |
/******/ } |
| 392 |
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); |
| 393 |
/******/ |
| 394 |
/******/ // Return the exports of the module |
| 395 |
/******/ return module.exports; |
| 396 |
/******/ } |
| 397 |
/******/ |
| 398 |
/************************************************************************/ |
| 399 |
/******/ /* webpack/runtime/define property getters */ |
| 400 |
/******/ (() => { |
| 401 |
/******/ // define getter functions for harmony exports |
| 402 |
/******/ __webpack_require__.d = (exports, definition) => { |
| 403 |
/******/ for(var key in definition) { |
| 404 |
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { |
| 405 |
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); |
| 406 |
/******/ } |
| 407 |
/******/ } |
| 408 |
/******/ }; |
| 409 |
/******/ })(); |
| 410 |
/******/ |
| 411 |
/******/ /* webpack/runtime/hasOwnProperty shorthand */ |
| 412 |
/******/ (() => { |
| 413 |
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) |
| 414 |
/******/ })(); |
| 415 |
/******/ |
| 416 |
/******/ /* webpack/runtime/make namespace object */ |
| 417 |
/******/ (() => { |
| 418 |
/******/ // define __esModule on exports |
| 419 |
/******/ __webpack_require__.r = (exports) => { |
| 420 |
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { |
| 421 |
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); |
| 422 |
/******/ } |
| 423 |
/******/ Object.defineProperty(exports, '__esModule', { value: true }); |
| 424 |
/******/ }; |
| 425 |
/******/ })(); |
| 426 |
/******/ |
| 427 |
/************************************************************************/ |
| 428 |
var __webpack_exports__ = {}; |
| 429 |
// This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk. |
| 430 |
(() => { |
| 431 |
/*!*******************************************!*\ |
| 432 |
!*** ./assets/src/js/admin/learnpress.js ***! |
| 433 |
\*******************************************/ |
| 434 |
__webpack_require__.r(__webpack_exports__); |
| 435 |
/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils */ "./assets/src/js/utils.js"); |
| 436 |
|
| 437 |
const $ = jQuery; |
| 438 |
const $doc = $(document); |
| 439 |
const makePaymentsSortable = function makePaymentsSortable() { |
| 440 |
// Make payments sortable |
| 441 |
$('.learn-press-payments.sortable tbody').sortable({ |
| 442 |
handle: '.dashicons-menu', |
| 443 |
helper(e, ui) { |
| 444 |
ui.children().each(function () { |
| 445 |
$(this).width($(this).width()); |
| 446 |
}); |
| 447 |
return ui; |
| 448 |
}, |
| 449 |
axis: 'y', |
| 450 |
start(event, ui) {}, |
| 451 |
stop(event, ui) {}, |
| 452 |
update(event, ui) { |
| 453 |
const order = $(this).children().map(function () { |
| 454 |
return $(this).find('input[name="payment-order"]').val(); |
| 455 |
}).get(); |
| 456 |
$.post({ |
| 457 |
url: '', |
| 458 |
data: { |
| 459 |
'lp-ajax': 'update-payment-order', |
| 460 |
order, |
| 461 |
nonce: $('input[name=lp-settings-nonce]').val() |
| 462 |
}, |
| 463 |
success(response) {} |
| 464 |
}); |
| 465 |
} |
| 466 |
}); |
| 467 |
}; |
| 468 |
|
| 469 |
/** Start Nhamdv code */ |
| 470 |
|
| 471 |
const lpMetaboxCustomFields = () => { |
| 472 |
$('.lp-metabox__custom-fields').on('click', '.lp-metabox-custom-field-button', function () { |
| 473 |
const row = $(this).data('row').replace(/lp_metabox_custom_fields_key/gi, Math.floor(Math.random() * 1000) + 1); |
| 474 |
$(this).closest('table').find('tbody').append(row); |
| 475 |
updateSort($(this).closest('.lp-metabox__custom-fields')); |
| 476 |
return false; |
| 477 |
}); |
| 478 |
$('.lp-metabox__custom-fields').on('click', 'a.delete', function () { |
| 479 |
$(this).closest('tr').remove(); |
| 480 |
updateSort($(this).closest('.lp-metabox__custom-fields')); |
| 481 |
return false; |
| 482 |
}); |
| 483 |
$('.lp-metabox__custom-fields tbody').sortable({ |
| 484 |
items: 'tr', |
| 485 |
cursor: 'move', |
| 486 |
axis: 'y', |
| 487 |
handle: 'td.sort', |
| 488 |
scrollSensitivity: 40, |
| 489 |
forcePlaceholderSize: true, |
| 490 |
helper: 'clone', |
| 491 |
opacity: 0.65, |
| 492 |
update(event, ui) { |
| 493 |
updateSort($(this).closest('.lp-metabox__custom-fields')); |
| 494 |
} |
| 495 |
}); |
| 496 |
const updateSort = element => { |
| 497 |
const items = element.find('tbody tr'); |
| 498 |
items.each(function (i, item) { |
| 499 |
$(this).find('.sort .count').val(i); |
| 500 |
}); |
| 501 |
}; |
| 502 |
}; |
| 503 |
const lpMetaboxRepeaterField = () => { |
| 504 |
const updateSort = element => { |
| 505 |
const items = element.find('.lp_repeater_meta_box__field'); |
| 506 |
items.each(function (i, item) { |
| 507 |
$(this).find('.lp_repeater_meta_box__field__count').val(i); |
| 508 |
$(this).find('.lp_repeater_meta_box__title__title > span').text(i + 1); |
| 509 |
}); |
| 510 |
}; |
| 511 |
$('.lp_repeater_meta_box__add').on('click', function () { |
| 512 |
const row = $(this).data('add').replace(/lp_metabox_repeater_key/gi, Math.floor(Math.random() * 1000) + 1); |
| 513 |
$(this).closest('.lp_repeater_meta_box__wrapper').find('.lp_repeater_meta_box__fields').append(row); |
| 514 |
updateSort($(this).closest('.lp_repeater_meta_box__wrapper')); |
| 515 |
$(this).closest('.lp_repeater_meta_box__wrapper').find('.lp_repeater_meta_box__fields').last().find('input').trigger('focus'); |
| 516 |
return false; |
| 517 |
}); |
| 518 |
$('.lp_repeater_meta_box__wrapper').on('click', 'a.lp_repeater_meta_box__title__delete', function () { |
| 519 |
$(this).closest('.lp_repeater_meta_box__field').remove(); |
| 520 |
updateSort($(this).closest('.lp_repeater_meta_box__wrapper')); |
| 521 |
return false; |
| 522 |
}); |
| 523 |
$('.lp_repeater_meta_box__fields').on('click', '.lp_repeater_meta_box__title__toggle, .lp_repeater_meta_box__title__title', function () { |
| 524 |
const field = $(this).closest('.lp_repeater_meta_box__field'); |
| 525 |
if (field.hasClass('lp_repeater_meta_box__field_active')) { |
| 526 |
field.removeClass('lp_repeater_meta_box__field_active'); |
| 527 |
} else { |
| 528 |
field.addClass('lp_repeater_meta_box__field_active'); |
| 529 |
} |
| 530 |
return false; |
| 531 |
}); |
| 532 |
$('.lp_repeater_meta_box__fields').sortable({ |
| 533 |
items: '.lp_repeater_meta_box__field', |
| 534 |
cursor: 'grab', |
| 535 |
axis: 'y', |
| 536 |
handle: '.lp_repeater_meta_box__title__sort', |
| 537 |
scrollSensitivity: 40, |
| 538 |
forcePlaceholderSize: true, |
| 539 |
helper: 'clone', |
| 540 |
opacity: 0.65, |
| 541 |
update(event, ui) { |
| 542 |
updateSort($(this).closest('.lp_repeater_meta_box__wrapper')); |
| 543 |
} |
| 544 |
}); |
| 545 |
}; |
| 546 |
const lpMetaboxExtraInfo = () => { |
| 547 |
$('.lp_course_extra_meta_box__add').on('click', function () { |
| 548 |
$(this).closest('.lp_course_extra_meta_box__content').find('.lp_course_extra_meta_box__fields').append($(this).data('add')); |
| 549 |
$(this).closest('.lp_course_extra_meta_box__content').find('.lp_course_extra_meta_box__field').last().find('input').trigger('focus'); |
| 550 |
return false; |
| 551 |
}); |
| 552 |
|
| 553 |
/*document.querySelectorAll( '.lp_course_extra_meta_box__fields' ).forEach( ( ele ) => { |
| 554 |
ele.addEventListener( 'keydown', ( e ) => { |
| 555 |
const inputs = ele.querySelectorAll( '.lp_course_extra_meta_box__input' ); |
| 556 |
|
| 557 |
if ( e.keyCode === 13 ) { |
| 558 |
e.preventDefault(); |
| 559 |
inputs.forEach( ( input ) => { |
| 560 |
input.blur(); |
| 561 |
} ); |
| 562 |
return false; |
| 563 |
} |
| 564 |
} ); |
| 565 |
} );*/ |
| 566 |
|
| 567 |
$('.lp_course_extra_meta_box__fields').on('click', 'a.delete', function () { |
| 568 |
$(this).closest('.lp_course_extra_meta_box__field').remove(); |
| 569 |
return false; |
| 570 |
}); |
| 571 |
$('.lp_course_extra_meta_box__fields').sortable({ |
| 572 |
items: '.lp_course_extra_meta_box__field', |
| 573 |
cursor: 'grab', |
| 574 |
axis: 'y', |
| 575 |
handle: '.sort', |
| 576 |
scrollSensitivity: 40, |
| 577 |
forcePlaceholderSize: true, |
| 578 |
helper: 'clone', |
| 579 |
opacity: 0.65 |
| 580 |
}); |
| 581 |
|
| 582 |
// FAQs metabox. |
| 583 |
$('.lp_course_faq_meta_box__add').on('click', function () { |
| 584 |
$(this).closest('.lp_course_faq_meta_box__content').find('.lp_course_faq_meta_box__fields').append($(this).data('add')); |
| 585 |
return false; |
| 586 |
}); |
| 587 |
|
| 588 |
/*document.querySelectorAll( '.lp_course_faq_meta_box__fields' ).forEach( ( ele ) => { |
| 589 |
ele.addEventListener( 'keydown', ( e ) => { |
| 590 |
const inputs = ele.querySelectorAll( '.lp_course_faq_meta_box__field input' ); |
| 591 |
const textareas = ele.querySelectorAll( '.lp_course_faq_meta_box__field textarea' ); |
| 592 |
|
| 593 |
if ( e.keyCode === 13 ) { |
| 594 |
e.preventDefault(); |
| 595 |
[ ...inputs, ...textareas ].forEach( ( input ) => { |
| 596 |
input.blur(); |
| 597 |
} ); |
| 598 |
return false; |
| 599 |
} |
| 600 |
} ); |
| 601 |
} );*/ |
| 602 |
|
| 603 |
$('.lp_course_faq_meta_box__fields').on('click', 'a.delete', function () { |
| 604 |
$(this).closest('.lp_course_faq_meta_box__field').remove(); |
| 605 |
return false; |
| 606 |
}); |
| 607 |
$('.lp_course_faq_meta_box__fields').sortable({ |
| 608 |
items: '.lp_course_faq_meta_box__field', |
| 609 |
cursor: 'grab', |
| 610 |
axis: 'y', |
| 611 |
handle: '.sort', |
| 612 |
scrollSensitivity: 40, |
| 613 |
forcePlaceholderSize: true, |
| 614 |
helper: 'clone', |
| 615 |
opacity: 0.65 |
| 616 |
}); |
| 617 |
}; |
| 618 |
|
| 619 |
// Nhamdv. |
| 620 |
const lpGetFinalQuiz = () => { |
| 621 |
const btns = document.querySelectorAll('.lp-metabox-get-final-quiz'); |
| 622 |
[...btns].map(btn => { |
| 623 |
btn.addEventListener('click', e => { |
| 624 |
e.preventDefault(); |
| 625 |
const text = btn.textContent, |
| 626 |
loading = btn.dataset.loading, |
| 627 |
message = document.querySelector('.lp-metabox-evaluate-final_quiz'); |
| 628 |
if (message) { |
| 629 |
message.remove(); |
| 630 |
} |
| 631 |
btn.textContent = loading; |
| 632 |
getResponse(btn).then(data => { |
| 633 |
const { |
| 634 |
message, |
| 635 |
data: responseData |
| 636 |
} = data; |
| 637 |
btn.textContent = text; |
| 638 |
const newNode = document.createElement('div'); |
| 639 |
newNode.className = 'lp-metabox-evaluate-final_quiz'; |
| 640 |
newNode.innerHTML = responseData || message; |
| 641 |
btn.parentNode.insertBefore(newNode, btn.nextSibling); |
| 642 |
}); |
| 643 |
}); |
| 644 |
}); |
| 645 |
const getResponse = async btn => { |
| 646 |
const response = await wp.apiFetch({ |
| 647 |
path: 'lp/v1/admin/course/get_final_quiz', |
| 648 |
method: 'POST', |
| 649 |
data: { |
| 650 |
courseId: btn.dataset.postid || '' |
| 651 |
} |
| 652 |
}); |
| 653 |
return response; |
| 654 |
}; |
| 655 |
}; |
| 656 |
const lpMetaboxColorPicker = () => { |
| 657 |
$('.lp-metabox__colorpick').iris({ |
| 658 |
change(event, ui) { |
| 659 |
$(this).parent().find('.colorpickpreview').css({ |
| 660 |
backgroundColor: ui.color.toString() |
| 661 |
}); |
| 662 |
}, |
| 663 |
hide: true, |
| 664 |
border: true |
| 665 |
}).on('click focus', function (event) { |
| 666 |
event.stopPropagation(); |
| 667 |
$('.iris-picker').hide(); |
| 668 |
$(this).closest('td').find('.iris-picker').show(); |
| 669 |
$(this).data('original-value', $(this).val()); |
| 670 |
}).on('change', function () { |
| 671 |
if ($(this).is('.iris-error')) { |
| 672 |
const originalValue = $(this).data('original-value'); |
| 673 |
if (originalValue.match(/^\#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/)) { |
| 674 |
$(this).val($(this).data('original-value')).trigger('change'); |
| 675 |
} else { |
| 676 |
$(this).val('').trigger('change'); |
| 677 |
} |
| 678 |
} |
| 679 |
}); |
| 680 |
$('body').on('click', function () { |
| 681 |
$('.iris-picker').hide(); |
| 682 |
}); |
| 683 |
}; |
| 684 |
const lpMetaboxImage = () => { |
| 685 |
$('.lp-metabox-field__image').each((i, ele) => { |
| 686 |
let lpImageFrame; |
| 687 |
const addImage = $(ele).find('.lp-metabox-field__image--add'); |
| 688 |
const delImage = $(ele).find('.lp-metabox-field__image--delete'); |
| 689 |
const image = $(ele).find('.lp-metabox-field__image--image'); |
| 690 |
const inputVal = $(ele).find('.lp-metabox-field__image--id'); |
| 691 |
if (!inputVal.val()) { |
| 692 |
addImage.show(); |
| 693 |
delImage.hide(); |
| 694 |
} else { |
| 695 |
addImage.hide(); |
| 696 |
delImage.show(); |
| 697 |
} |
| 698 |
addImage.on('click', event => { |
| 699 |
event.preventDefault(); |
| 700 |
if (lpImageFrame) { |
| 701 |
lpImageFrame.open(); |
| 702 |
return; |
| 703 |
} |
| 704 |
lpImageFrame = wp.media({ |
| 705 |
title: addImage.data('choose'), |
| 706 |
button: { |
| 707 |
text: addImage.data('update') |
| 708 |
}, |
| 709 |
multiple: false |
| 710 |
}); |
| 711 |
lpImageFrame.on('select', function () { |
| 712 |
const attachment = lpImageFrame.state().get('selection').first().toJSON(); |
| 713 |
const attachmentImage = attachment.sizes && attachment.sizes.thumbnail ? attachment.sizes.thumbnail.url : attachment.url; |
| 714 |
image.append('<div class="lp-metabox-field__image--inner"><img src="' + attachmentImage + '" alt="" style="max-width:100%;"/></div>'); |
| 715 |
inputVal.val(attachment.id); |
| 716 |
addImage.hide(); |
| 717 |
delImage.show(); |
| 718 |
}); |
| 719 |
lpImageFrame.open(); |
| 720 |
}); |
| 721 |
delImage.on('click', event => { |
| 722 |
event.preventDefault(); |
| 723 |
image.html(''); |
| 724 |
addImage.show(); |
| 725 |
delImage.hide(); |
| 726 |
inputVal.val(''); |
| 727 |
}); |
| 728 |
}); |
| 729 |
}; |
| 730 |
const lpMetaboxImageAdvanced = () => { |
| 731 |
$('.lp-metabox-field__image-advanced').each((i, element) => { |
| 732 |
let lpImageFrame; |
| 733 |
const imageGalleryIds = $(element).find('#lp-gallery-images-ids'); |
| 734 |
const listImages = $(element).find('.lp-metabox-field__image-advanced-images'); |
| 735 |
const btnUpload = $(element).find('.lp-metabox-field__image-advanced-upload > a'); |
| 736 |
$(btnUpload).on('click', event => { |
| 737 |
event.preventDefault(); |
| 738 |
if (lpImageFrame) { |
| 739 |
lpImageFrame.open(); |
| 740 |
return; |
| 741 |
} |
| 742 |
lpImageFrame = wp.media({ |
| 743 |
title: btnUpload.data('choose'), |
| 744 |
button: { |
| 745 |
text: btnUpload.data('update') |
| 746 |
}, |
| 747 |
states: [new wp.media.controller.Library({ |
| 748 |
title: btnUpload.data('choose'), |
| 749 |
filterable: 'all', |
| 750 |
multiple: true |
| 751 |
})] |
| 752 |
}); |
| 753 |
lpImageFrame.on('select', function () { |
| 754 |
const selection = lpImageFrame.state().get('selection'); |
| 755 |
let attachmentIds = imageGalleryIds.val(); |
| 756 |
selection.forEach(function (attachment) { |
| 757 |
attachment = attachment.toJSON(); |
| 758 |
if (attachment.id) { |
| 759 |
attachmentIds = attachmentIds ? attachmentIds + ',' + attachment.id : attachment.id; |
| 760 |
const attachmentImage = attachment.sizes && attachment.sizes.thumbnail ? attachment.sizes.thumbnail.url : attachment.url; |
| 761 |
listImages.append('<li class="image" data-attachment_id="' + attachment.id + '"><img src="' + attachmentImage + '" /><ul class="actions"><li><a href="#" class="delete" title="' + btnUpload.data('delete') + '">' + btnUpload.data('text') + '</a></li></ul></li>'); |
| 762 |
} |
| 763 |
}); |
| 764 |
imageGalleryIds.val(attachmentIds); |
| 765 |
}); |
| 766 |
lpImageFrame.open(); |
| 767 |
}); |
| 768 |
listImages.sortable({ |
| 769 |
items: 'li.image', |
| 770 |
cursor: 'move', |
| 771 |
scrollSensitivity: 40, |
| 772 |
forcePlaceholderSize: true, |
| 773 |
forceHelperSize: false, |
| 774 |
helper: 'clone', |
| 775 |
opacity: 0.65, |
| 776 |
placeholder: 'lp-metabox-sortable-placeholder', |
| 777 |
start(event, ui) { |
| 778 |
ui.item.css('background-color', '#f6f6f6'); |
| 779 |
}, |
| 780 |
stop(event, ui) { |
| 781 |
ui.item.removeAttr('style'); |
| 782 |
}, |
| 783 |
update() { |
| 784 |
let attachmentIds = ''; |
| 785 |
listImages.find('li.image').css('cursor', 'default').each(function () { |
| 786 |
const attachmentId = $(this).attr('data-attachment_id'); |
| 787 |
attachmentIds = attachmentIds + attachmentId + ','; |
| 788 |
}); |
| 789 |
imageGalleryIds.val(attachmentIds); |
| 790 |
} |
| 791 |
}); |
| 792 |
$(listImages).find('li.image').each((i, ele) => { |
| 793 |
const del = $(ele).find('a.delete'); |
| 794 |
del.on('click', () => { |
| 795 |
$(ele).remove(); |
| 796 |
let attachmentIds = ''; |
| 797 |
$(listImages).find('li.image').css('cursor', 'default').each(function () { |
| 798 |
const attachmentId = $(this).attr('data-attachment_id'); |
| 799 |
attachmentIds = attachmentIds + attachmentId + ','; |
| 800 |
}); |
| 801 |
imageGalleryIds.val(attachmentIds); |
| 802 |
return false; |
| 803 |
}); |
| 804 |
}); |
| 805 |
}); |
| 806 |
}; |
| 807 |
const lpMetaboxCourseTabs = () => { |
| 808 |
$(document.body).on('lp-metabox-course-tab-panels', function () { |
| 809 |
$('ul.lp-meta-box__course-tab__tabs').show(); |
| 810 |
$('ul.lp-meta-box__course-tab__tabs a').on('click', function (e) { |
| 811 |
e.preventDefault(); |
| 812 |
const panelWrap = $(this).closest('div.lp-meta-box__course-tab'); |
| 813 |
$('ul.lp-meta-box__course-tab__tabs li', panelWrap).removeClass('active'); |
| 814 |
$(this).parent().addClass('active'); |
| 815 |
$('div.lp-meta-box-course-panels', panelWrap).hide(); |
| 816 |
$($(this).attr('href')).show(); |
| 817 |
}); |
| 818 |
$('div.lp-meta-box__course-tab').each(function () { |
| 819 |
$(this).find('ul.lp-meta-box__course-tab__tabs li').eq(0).find('a').trigger('click'); |
| 820 |
}); |
| 821 |
}).trigger('lp-metabox-course-tab-panels'); |
| 822 |
}; |
| 823 |
|
| 824 |
// use to show and hide field condition logic metabox. |
| 825 |
/*const lpMetaboxCondition = () => { |
| 826 |
const fields = document.querySelectorAll( '.lp-meta-box .form-field' ); |
| 827 |
|
| 828 |
fields.forEach( ( field ) => { |
| 829 |
if ( field.hasAttribute( 'data-show' ) && field.dataset.show ) { |
| 830 |
lpMetaboxConditionType( field, field.dataset.show, 'show' ); |
| 831 |
} else if ( field.hasAttribute( 'data-hide' ) && field.dataset.hide ) { |
| 832 |
lpMetaboxConditionType( field, field.dataset.hide, 'hide' ); |
| 833 |
} |
| 834 |
} ); |
| 835 |
};*/ |
| 836 |
|
| 837 |
/*const lpMetaboxConditionType = ( field, conditions, typeCondition = 'show' ) => { |
| 838 |
const condition = JSON.parse( conditions ), |
| 839 |
eles = document.querySelectorAll( `input[id^="${ condition[ 0 ] }"]` ), |
| 840 |
logic = condition[ 1 ] === '=' ? '=' : '!=', |
| 841 |
dataLogic = condition[ 2 ]; |
| 842 |
|
| 843 |
const switchCase = ( type, ele, target ) => { |
| 844 |
switch ( type ) { |
| 845 |
case 'checkbox': |
| 846 |
let val = dataLogic; |
| 847 |
|
| 848 |
if ( dataLogic === 'yes' || dataLogic === '1' || dataLogic === 1 || dataLogic === 'true' ) { |
| 849 |
val = true; |
| 850 |
} else if ( dataLogic === 'no' || dataLogic === '0' || dataLogic === 0 || dataLogic === 'false' ) { |
| 851 |
val = false; |
| 852 |
} |
| 853 |
|
| 854 |
if ( logic == '!=' && val !== Boolean( target ? target.checked : ele.checked ) ) { |
| 855 |
field.style.display = typeCondition === 'show' ? '' : 'none'; |
| 856 |
} else if ( logic == '=' && val == Boolean( target ? target.checked : ele.checked ) ) { |
| 857 |
field.style.display = typeCondition === 'show' ? '' : 'none'; |
| 858 |
} else { |
| 859 |
field.style.display = typeCondition === 'show' ? 'none' : ''; |
| 860 |
} |
| 861 |
break; |
| 862 |
} |
| 863 |
}; |
| 864 |
|
| 865 |
eles.forEach( ( ele ) => { |
| 866 |
const type = ele.getAttribute( 'type' ); |
| 867 |
|
| 868 |
switchCase( type, ele ); |
| 869 |
|
| 870 |
ele.addEventListener( 'change', ( e ) => { |
| 871 |
const target = e.target; |
| 872 |
|
| 873 |
switchCase( type, ele, target ); |
| 874 |
} ); |
| 875 |
} ); |
| 876 |
};*/ |
| 877 |
|
| 878 |
/** End Nhamdv code */ |
| 879 |
|
| 880 |
const initTooltips = function initTooltips() { |
| 881 |
$('.learn-press-tooltip').each(function () { |
| 882 |
const $el = $(this), |
| 883 |
args = $.extend({ |
| 884 |
title: 'data-tooltip', |
| 885 |
offset: 10, |
| 886 |
gravity: 's' |
| 887 |
}, $el.data()); |
| 888 |
$el.tipsy(args); |
| 889 |
}); |
| 890 |
}; |
| 891 |
const initSelect2 = function initSelect2() { |
| 892 |
if ($.fn.select2) { |
| 893 |
const elSelect2 = $('.lp-select-2 select'); |
| 894 |
elSelect2.select2({ |
| 895 |
placeholder: 'Select a value' |
| 896 |
}); |
| 897 |
elSelect2.on('change.select2', function (e) { |
| 898 |
const el = $(e.target); |
| 899 |
const val = el.val(); |
| 900 |
if (!val.length) { |
| 901 |
el.val(null); |
| 902 |
} |
| 903 |
}); |
| 904 |
$('.lp_autocomplete_metabox_field').each(function () { |
| 905 |
const dataAtts = $(this).data('atts'); |
| 906 |
let action = dataAtts.action; |
| 907 |
if (!action) { |
| 908 |
switch (dataAtts.data) { |
| 909 |
case 'users': |
| 910 |
action = dataAtts.rest_url + 'wp/v2/users'; |
| 911 |
break; |
| 912 |
default: |
| 913 |
action = dataAtts.rest_url + 'wp/v2/' + dataAtts.data; |
| 914 |
break; |
| 915 |
} |
| 916 |
} |
| 917 |
$(this).find('select').select2({ |
| 918 |
placeholder: dataAtts.placeholder ? dataAtts.placeholder : 'Select', |
| 919 |
ajax: { |
| 920 |
url: action, |
| 921 |
dataType: 'json', |
| 922 |
delay: 250, |
| 923 |
beforeSend(xhr) { |
| 924 |
xhr.setRequestHeader('X-WP-Nonce', dataAtts.nonce); |
| 925 |
}, |
| 926 |
data(params) { |
| 927 |
return { |
| 928 |
search: params.term |
| 929 |
}; |
| 930 |
}, |
| 931 |
processResults(data) { |
| 932 |
return { |
| 933 |
results: data.map(item => { |
| 934 |
return { |
| 935 |
id: item.id, |
| 936 |
text: item.title && item.title.rendered ? item.title.rendered : item.name |
| 937 |
}; |
| 938 |
}) |
| 939 |
}; |
| 940 |
}, |
| 941 |
cache: true |
| 942 |
}, |
| 943 |
minimumInputLength: 2 |
| 944 |
}); |
| 945 |
}); |
| 946 |
} |
| 947 |
}; |
| 948 |
const initSingleCoursePermalink = function initSingleCoursePermalink() { |
| 949 |
$doc.on('change', '.learn-press-single-course-permalink input[type="radio"]', function () { |
| 950 |
const $check = $(this), |
| 951 |
$row = $check.closest('.learn-press-single-course-permalink'); |
| 952 |
if ($row.hasClass('custom-base')) { |
| 953 |
$row.find('input[type="text"]').prop('readonly', false); |
| 954 |
} else { |
| 955 |
$row.siblings('.custom-base').find('input[type="text"]').prop('readonly', true); |
| 956 |
} |
| 957 |
}).on('change', 'input.learn-press-course-base', function () { |
| 958 |
$('#course_permalink_structure').val($(this).val()); |
| 959 |
}).on('focus', '#course_permalink_structure', function () { |
| 960 |
$('#learn_press_custom_permalink').click(); |
| 961 |
}).on('change', '#learn_press_courses_page_id', function () { |
| 962 |
$('tr.learn-press-courses-page-id').toggleClass('hide-if-js', !parseInt(this.value)); |
| 963 |
}); |
| 964 |
}; |
| 965 |
const togglePaymentStatus = function togglePaymentStatus(e) { |
| 966 |
e.preventDefault(); |
| 967 |
const $row = $(this).closest('tr'), |
| 968 |
$button = $(this), |
| 969 |
status = $row.find('.status').hasClass('enabled') ? 'no' : 'yes'; |
| 970 |
$.ajax({ |
| 971 |
url: '', |
| 972 |
data: { |
| 973 |
'lp-ajax': 'update-payment-status', |
| 974 |
status, |
| 975 |
id: $row.data('payment'), |
| 976 |
nonce: $('input[name=lp-settings-nonce]').val() |
| 977 |
}, |
| 978 |
success(response) { |
| 979 |
response = (0,_utils__WEBPACK_IMPORTED_MODULE_0__.lpAjaxParseJsonOld)(response); |
| 980 |
for (const i in response) { |
| 981 |
$('#payment-' + i + ' .status').toggleClass('enabled', response[i]); |
| 982 |
} |
| 983 |
} |
| 984 |
}); |
| 985 |
}; |
| 986 |
const updateEmailStatus = function updateEmailStatus() { |
| 987 |
(function () { |
| 988 |
$.post({ |
| 989 |
url: window.location.href, |
| 990 |
data: { |
| 991 |
'lp-ajax': 'update_email_status', |
| 992 |
status: $(this).parent().hasClass('enabled') ? 'no' : 'yes', |
| 993 |
id: $(this).data('id'), |
| 994 |
nonce: $('input[name=lp-settings-nonce]').val() |
| 995 |
}, |
| 996 |
dataType: 'text', |
| 997 |
success: $.proxy(function (res) { |
| 998 |
res = (0,_utils__WEBPACK_IMPORTED_MODULE_0__.lpAjaxParseJsonOld)(res); |
| 999 |
for (const i in res) { |
| 1000 |
$('#email-' + i + ' .status').toggleClass('enabled', res[i]); |
| 1001 |
} |
| 1002 |
}, this) |
| 1003 |
}); |
| 1004 |
}).apply(this); |
| 1005 |
}; |
| 1006 |
const lpMetaboxsalePriceDate = () => { |
| 1007 |
// Don't run in LearnPress Frontend Editor Add-on. |
| 1008 |
if (!$('#course-settings').length) { |
| 1009 |
return; |
| 1010 |
} |
| 1011 |
$('.lp_sale_dates_fields').each(function () { |
| 1012 |
const wrap = $(this).closest('#price_course_data'); |
| 1013 |
let saleScheduleSet = false; |
| 1014 |
$(this).find('input').each(function () { |
| 1015 |
if ('' !== $(this).val()) { |
| 1016 |
saleScheduleSet = true; |
| 1017 |
} |
| 1018 |
}); |
| 1019 |
if (saleScheduleSet) { |
| 1020 |
wrap.find('.lp_sale_price_schedule').hide(); |
| 1021 |
wrap.find('.lp_sale_dates_fields').show(); |
| 1022 |
} else { |
| 1023 |
wrap.find('.lp_sale_price_schedule').show(); |
| 1024 |
wrap.find('.lp_sale_dates_fields').hide(); |
| 1025 |
} |
| 1026 |
}); |
| 1027 |
$('.lp-meta-box-course-panels').on('click', '.lp_sale_price_schedule', function () { |
| 1028 |
const wrap = $(this).closest('#price_course_data'); |
| 1029 |
$(this).hide(); |
| 1030 |
wrap.find('.lp_cancel_sale_schedule').show(); |
| 1031 |
wrap.find('.lp_sale_dates_fields').show(); |
| 1032 |
return false; |
| 1033 |
}); |
| 1034 |
$('.lp-meta-box-course-panels').on('click', '.lp_cancel_sale_schedule', function () { |
| 1035 |
const wrap = $(this).closest('div.lp-meta-box-course-panels'); |
| 1036 |
$(this).hide(); |
| 1037 |
wrap.find('.lp_sale_price_schedule').show(); |
| 1038 |
wrap.find('.lp_sale_dates_fields').hide(); |
| 1039 |
wrap.find('.lp_sale_dates_fields').find('input').val(''); |
| 1040 |
return false; |
| 1041 |
}); |
| 1042 |
$(document).on('input', '#price_course_data', function (e) { |
| 1043 |
const $this = $(this), |
| 1044 |
regularPrice = $('.lp_meta_box_regular_price'), |
| 1045 |
salePrice = $('.lp_meta_box_sale_price'), |
| 1046 |
$target = $(e.target).attr('id'); |
| 1047 |
$this.find('.learn-press-tip-floating').remove(); |
| 1048 |
if (parseInt(salePrice.val()) > parseInt(regularPrice.val())) { |
| 1049 |
if ($target === '_lp_price') { |
| 1050 |
regularPrice.parent('.form-field').append('<div class="learn-press-tip-floating">' + lpAdminCourseEditorSettings.i18n.notice_price + '</div>'); |
| 1051 |
} else if ($target === '_lp_sale_price') { |
| 1052 |
salePrice.parent('.form-field').append('<div class="learn-press-tip-floating">' + lpAdminCourseEditorSettings.i18n.notice_sale_price + '</div>'); |
| 1053 |
} |
| 1054 |
} |
| 1055 |
}); |
| 1056 |
|
| 1057 |
/*const datePickerSelect = function( datepicker ) { |
| 1058 |
const option = $( datepicker ).is( '#_lp_sale_start' ) ? 'minDate' : 'maxDate', |
| 1059 |
otherDateField = 'minDate' === option ? $( '#_lp_sale_end' ) : $( '#_lp_sale_start' ), |
| 1060 |
date = $( datepicker ).datetimepicker( 'getDate' ); |
| 1061 |
|
| 1062 |
$( otherDateField ).datetimepicker( 'option', option, date ); |
| 1063 |
$( datepicker ).trigger( 'change' ); |
| 1064 |
}; |
| 1065 |
|
| 1066 |
$( '.lp_sale_dates_fields' ).each( function() { |
| 1067 |
$( this ).find( 'input' ).datetimepicker( { |
| 1068 |
timeFormat: 'HH:mm', |
| 1069 |
separator: ' ', |
| 1070 |
dateFormat: 'yy-mm-dd', |
| 1071 |
showButtonPanel: true, |
| 1072 |
onSelect() { |
| 1073 |
datePickerSelect( $( this ) ); |
| 1074 |
}, |
| 1075 |
} ); |
| 1076 |
|
| 1077 |
$( this ).find( 'input' ).each( function() { |
| 1078 |
datePickerSelect( $( this ) ); |
| 1079 |
} ); |
| 1080 |
} );*/ |
| 1081 |
}; |
| 1082 |
const lpHidePassingGrade = () => { |
| 1083 |
const listHides = ['evaluate_final_quiz', 'evaluate_final_assignment']; |
| 1084 |
const inputLists = document.querySelectorAll('input[type=radio][name=_lp_course_result]'); |
| 1085 |
[...inputLists].map((ele, i) => { |
| 1086 |
if (ele.checked && listHides.includes(ele.value)) { |
| 1087 |
$('._lp_passing_condition_field').hide(); |
| 1088 |
} |
| 1089 |
return null; |
| 1090 |
}); |
| 1091 |
$('input[type=radio][name=_lp_course_result]').on('change', function (e) { |
| 1092 |
if (listHides.includes(e.target.value)) { |
| 1093 |
$('._lp_passing_condition_field').hide(); |
| 1094 |
} else { |
| 1095 |
$('._lp_passing_condition_field').show(); |
| 1096 |
} |
| 1097 |
}); |
| 1098 |
}; |
| 1099 |
const callbackFilterTemplates = function callbackFilterTemplates() { |
| 1100 |
const $link = $(this); |
| 1101 |
if ($link.hasClass('current')) { |
| 1102 |
return false; |
| 1103 |
} |
| 1104 |
const $templatesList = $('#learn-press-template-files'), |
| 1105 |
$templates = $templatesList.find('tr[data-template]'), |
| 1106 |
template = $link.data('template'), |
| 1107 |
filter = $link.data('filter'); |
| 1108 |
$link.addClass('current').siblings('a').removeClass('current'); |
| 1109 |
if (!template) { |
| 1110 |
if (!filter) { |
| 1111 |
$templates.removeClass('hide-if-js'); |
| 1112 |
} else { |
| 1113 |
$templates.map(function () { |
| 1114 |
$(this).toggleClass('hide-if-js', $(this).data('filter-' + filter) !== 'yes'); |
| 1115 |
}); |
| 1116 |
} |
| 1117 |
} else { |
| 1118 |
$templates.map(function () { |
| 1119 |
$(this).toggleClass('hide-if-js', $(this).data('template') !== template); |
| 1120 |
}); |
| 1121 |
} |
| 1122 |
$('#learn-press-no-templates').toggleClass('hide-if-js', !!$templatesList.find('tr.template-row:not(.hide-if-js):first').length); |
| 1123 |
return false; |
| 1124 |
}; |
| 1125 |
const toggleEmails = function toggleEmails(e) { |
| 1126 |
e.preventDefault(); |
| 1127 |
const $button = $(this), |
| 1128 |
status = $button.data('status'); |
| 1129 |
$.ajax({ |
| 1130 |
url: '', |
| 1131 |
data: { |
| 1132 |
'lp-ajax': 'update_email_status', |
| 1133 |
nonce: $('input[name=lp-settings-nonce]').val(), |
| 1134 |
status |
| 1135 |
}, |
| 1136 |
success(response) { |
| 1137 |
response = (0,_utils__WEBPACK_IMPORTED_MODULE_0__.lpAjaxParseJsonOld)(response); |
| 1138 |
for (const i in response) { |
| 1139 |
$('#email-' + i + ' .status').toggleClass('enabled', response[i]); |
| 1140 |
} |
| 1141 |
} |
| 1142 |
}); |
| 1143 |
}; |
| 1144 |
const onReady = function onReady() { |
| 1145 |
makePaymentsSortable(); |
| 1146 |
initSelect2(); |
| 1147 |
initTooltips(); |
| 1148 |
initSingleCoursePermalink(); |
| 1149 |
|
| 1150 |
// lp Metabox in LP4. |
| 1151 |
lpMetaboxCourseTabs(); |
| 1152 |
lpMetaboxCustomFields(); |
| 1153 |
lpMetaboxColorPicker(); |
| 1154 |
lpMetaboxImageAdvanced(); |
| 1155 |
lpMetaboxImage(); |
| 1156 |
lpMetaboxsalePriceDate(); |
| 1157 |
lpMetaboxExtraInfo(); |
| 1158 |
lpHidePassingGrade(); |
| 1159 |
lpGetFinalQuiz(); |
| 1160 |
//lpMetaboxCondition(); |
| 1161 |
lpMetaboxRepeaterField(); |
| 1162 |
$(document).on('click', '.learn-press-payments .status .dashicons', togglePaymentStatus).on('click', '.change-email-status', updateEmailStatus).on('click', '.learn-press-filter-template', callbackFilterTemplates).on('click', '#learn-press-enable-emails, #learn-press-disable-emails', toggleEmails); |
| 1163 |
}; |
| 1164 |
$(document).ready(onReady); |
| 1165 |
|
| 1166 |
// Events |
| 1167 |
document.addEventListener('keydown', function (e) { |
| 1168 |
const target = e.target; |
| 1169 |
if (e.key === 'Enter' || e.keyCode === 13) { |
| 1170 |
// When enter on input on Extra information Options, blur it. |
| 1171 |
if (target.classList.contains('lp_course_extra_meta_box__input')) { |
| 1172 |
e.preventDefault(); |
| 1173 |
target.blur(); |
| 1174 |
} else if (target.tagName === 'INPUT') { |
| 1175 |
if (target.closest('.lp_course_faq_meta_box__field')) { |
| 1176 |
e.preventDefault(); |
| 1177 |
target.blur(); |
| 1178 |
} |
| 1179 |
} |
| 1180 |
} |
| 1181 |
}); |
| 1182 |
})(); |
| 1183 |
|
| 1184 |
/******/ })() |
| 1185 |
; |
| 1186 |
//# sourceMappingURL=learnpress.js.map |