| @@ -1,18 +1,556 @@ | ||
| 1 | -/******/ (function() { // webpackBootstrap | |
| 1 | +/******/ (() => { // webpackBootstrap | |
| 2 | 2 | /******/ "use strict"; |
| 3 | 3 | /******/ var __webpack_modules__ = ({ |
| 4 | 4 | |
| 5 | -/***/ "@wordpress/url": | |
| 6 | -/*!*****************************!*\ | |
| 7 | - !*** external ["wp","url"] ***! | |
| 8 | - \*****************************/ | |
| 9 | -/***/ (function(module) { | |
| 5 | +/***/ "./assets/src/js/api.js" | |
| 6 | +/*!******************************!*\ | |
| 7 | + !*** ./assets/src/js/api.js ***! | |
| 8 | + \******************************/ | |
| 9 | +(__unused_webpack_module, __webpack_exports__, __webpack_require__) { | |
| 10 | 10 | |
| 11 | -module.exports = window["wp"]["url"]; | |
| 11 | +__webpack_require__.r(__webpack_exports__); | |
| 12 | +/* harmony export */ __webpack_require__.d(__webpack_exports__, { | |
| 13 | +/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) | |
| 14 | +/* harmony export */ }); | |
| 15 | +/** | |
| 16 | + * List API on backend | |
| 17 | + * | |
| 18 | + * @since 4.2.6 | |
| 19 | + * @version 1.0.2 | |
| 20 | + */ | |
| 12 | 21 | |
| 13 | -/***/ }) | |
| 22 | +const lplistAPI = {}; | |
| 23 | +let lp_rest_url; | |
| 24 | +if ('undefined' !== typeof lpDataAdmin) { | |
| 25 | + lp_rest_url = lpDataAdmin.lp_rest_url; | |
| 26 | + lplistAPI.admin = { | |
| 27 | + // apiAdminNotice: lp_rest_url + 'lp/v1/admin/tools/admin-notices', | |
| 28 | + apiSearchCourses: lp_rest_url + 'lp/v1/admin/tools/search-course', | |
| 29 | + apiSearchUsers: lp_rest_url + 'lp/v1/admin/tools/search-user', | |
| 30 | + apiAssignUserCourse: lp_rest_url + 'lp/v1/admin/tools/assign-user-course', | |
| 31 | + apiUnAssignUserCourse: lp_rest_url + 'lp/v1/admin/tools/unassign-user-course' | |
| 32 | + }; | |
| 33 | +} | |
| 34 | +if ('undefined' !== typeof lpData) { | |
| 35 | + lp_rest_url = lpData.lp_rest_url; | |
| 36 | + lplistAPI.frontend = { | |
| 37 | + apiWidgets: lp_rest_url + 'lp/v1/widgets/api', | |
| 38 | + apiCourses: lp_rest_url + 'lp/v1/courses/archive-course', | |
| 39 | + // Deprecated API, don't load from v4.3.7 | |
| 40 | + apiAJAX: lp_rest_url + 'lp/v1/load_content_via_ajax/', | |
| 41 | + // Deprecated since 4.3.0 | |
| 42 | + apiProfileCoverImage: lp_rest_url + 'lp/v1/profile/cover-image' | |
| 43 | + }; | |
| 44 | +} | |
| 45 | +if (lp_rest_url) { | |
| 46 | + lplistAPI.apiCourses = lp_rest_url + 'lp/v1/courses/'; | |
| 47 | + lplistAPI.apiEditCoursesArchiveBlock = lp_rest_url + 'lp/v1/courses/edit-archive-block'; | |
| 48 | + lplistAPI.apiCoursesSuggest = lp_rest_url + 'lp/v1/courses/courses-suggest'; | |
| 49 | +} | |
| 50 | +/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (lplistAPI); | |
| 14 | 51 | |
| 52 | +/***/ }, | |
| 53 | + | |
| 54 | +/***/ "./assets/src/js/utils.js" | |
| 55 | +/*!********************************!*\ | |
| 56 | + !*** ./assets/src/js/utils.js ***! | |
| 57 | + \********************************/ | |
| 58 | +(__unused_webpack_module, __webpack_exports__, __webpack_require__) { | |
| 59 | + | |
| 60 | +__webpack_require__.r(__webpack_exports__); | |
| 61 | +/* harmony export */ __webpack_require__.d(__webpack_exports__, { | |
| 62 | +/* harmony export */ debounce: () => (/* binding */ debounce), | |
| 63 | +/* harmony export */ eventHandlers: () => (/* binding */ eventHandlers), | |
| 64 | +/* harmony export */ fullScreenView: () => (/* binding */ fullScreenView), | |
| 65 | +/* harmony export */ getDataOfForm: () => (/* binding */ getDataOfForm), | |
| 66 | +/* harmony export */ getFieldKeysOfForm: () => (/* binding */ getFieldKeysOfForm), | |
| 67 | +/* harmony export */ listenElementCreated: () => (/* binding */ listenElementCreated), | |
| 68 | +/* harmony export */ listenElementViewed: () => (/* binding */ listenElementViewed), | |
| 69 | +/* harmony export */ lpAddQueryArgs: () => (/* binding */ lpAddQueryArgs), | |
| 70 | +/* harmony export */ lpAjaxParseJsonOld: () => (/* binding */ lpAjaxParseJsonOld), | |
| 71 | +/* harmony export */ lpClassName: () => (/* binding */ lpClassName), | |
| 72 | +/* harmony export */ lpFetchAPI: () => (/* binding */ lpFetchAPI), | |
| 73 | +/* harmony export */ lpGetCurrentURLNoParam: () => (/* binding */ lpGetCurrentURLNoParam), | |
| 74 | +/* harmony export */ lpOnElementReady: () => (/* binding */ lpOnElementReady), | |
| 75 | +/* harmony export */ lpSetLoadingEl: () => (/* binding */ lpSetLoadingEl), | |
| 76 | +/* harmony export */ lpShowHideEl: () => (/* binding */ lpShowHideEl), | |
| 77 | +/* harmony export */ mergeDataWithDatForm: () => (/* binding */ mergeDataWithDatForm), | |
| 78 | +/* harmony export */ toggleCollapse: () => (/* binding */ toggleCollapse), | |
| 79 | +/* harmony export */ toggleEnable: () => (/* binding */ toggleEnable) | |
| 80 | +/* harmony export */ }); | |
| 81 | +/** | |
| 82 | + * Utils functions | |
| 83 | + * | |
| 84 | + * @param url | |
| 85 | + * @param data | |
| 86 | + * @param functions | |
| 87 | + * @since 4.2.5.1 | |
| 88 | + * @version 1.0.7 | |
| 89 | + */ | |
| 90 | +const lpClassName = { | |
| 91 | + hidden: 'lp-hidden', | |
| 92 | + loading: 'loading', | |
| 93 | + elCollapse: 'lp-collapse', | |
| 94 | + elSectionToggle: '.lp-section-toggle', | |
| 95 | + elTriggerToggle: '.lp-trigger-toggle', | |
| 96 | + elBtnFullScreen: '.lp-btn-full-screen-view', | |
| 97 | + elFullScreen: 'lp-full-screen-view', | |
| 98 | + elBtnFullScreenClose: 'lp-full-screen-view__close' | |
| 99 | +}; | |
| 100 | +const lpFetchAPI = (url, data = {}, functions = {}) => { | |
| 101 | + if ('function' === typeof functions.before) { | |
| 102 | + functions.before(); | |
| 103 | + } | |
| 104 | + fetch(url, { | |
| 105 | + method: 'GET', | |
| 106 | + ...data | |
| 107 | + }).then(response => response.json()).then(response => { | |
| 108 | + if ('function' === typeof functions.success) { | |
| 109 | + functions.success(response); | |
| 110 | + } | |
| 111 | + }).catch(err => { | |
| 112 | + if ('function' === typeof functions.error) { | |
| 113 | + functions.error(err); | |
| 114 | + } | |
| 115 | + }).finally(() => { | |
| 116 | + if ('function' === typeof functions.completed) { | |
| 117 | + functions.completed(); | |
| 118 | + } | |
| 119 | + }); | |
| 120 | +}; | |
| 121 | + | |
| 122 | +/** | |
| 123 | + * Get current URL without params. | |
| 124 | + * | |
| 125 | + * @since 4.2.5.1 | |
| 126 | + */ | |
| 127 | +const lpGetCurrentURLNoParam = () => { | |
| 128 | + let currentUrl = window.location.href; | |
| 129 | + const hasParams = currentUrl.includes('?'); | |
| 130 | + if (hasParams) { | |
| 131 | + currentUrl = currentUrl.split('?')[0]; | |
| 132 | + } | |
| 133 | + return currentUrl; | |
| 134 | +}; | |
| 135 | +const lpAddQueryArgs = (endpoint, args) => { | |
| 136 | + const url = new URL(endpoint); | |
| 137 | + Object.keys(args).forEach(arg => { | |
| 138 | + url.searchParams.set(arg, args[arg]); | |
| 139 | + }); | |
| 140 | + return url; | |
| 141 | +}; | |
| 142 | + | |
| 143 | +/** | |
| 144 | + * Listen element viewed. | |
| 145 | + * | |
| 146 | + * @param el | |
| 147 | + * @param callback | |
| 148 | + * @since 4.2.5.8 | |
| 149 | + */ | |
| 150 | +const listenElementViewed = (el, callback) => { | |
| 151 | + const observerSeeItem = new IntersectionObserver(function (entries) { | |
| 152 | + for (const entry of entries) { | |
| 153 | + if (entry.isIntersecting) { | |
| 154 | + callback(entry); | |
| 155 | + } | |
| 156 | + } | |
| 157 | + }); | |
| 158 | + observerSeeItem.observe(el); | |
| 159 | +}; | |
| 160 | + | |
| 161 | +/** | |
| 162 | + * Listen element created. | |
| 163 | + * | |
| 164 | + * @param callback | |
| 165 | + * @since 4.2.5.8 | |
| 166 | + */ | |
| 167 | +const listenElementCreated = callback => { | |
| 168 | + const observerCreateItem = new MutationObserver(function (mutations) { | |
| 169 | + mutations.forEach(function (mutation) { | |
| 170 | + if (mutation.addedNodes) { | |
| 171 | + mutation.addedNodes.forEach(function (node) { | |
| 172 | + if (node.nodeType === 1) { | |
| 173 | + callback(node); | |
| 174 | + } | |
| 175 | + }); | |
| 176 | + } | |
| 177 | + }); | |
| 178 | + }); | |
| 179 | + observerCreateItem.observe(document, { | |
| 180 | + childList: true, | |
| 181 | + subtree: true | |
| 182 | + }); | |
| 183 | + // End. | |
| 184 | +}; | |
| 185 | + | |
| 186 | +/** | |
| 187 | + * Listen element created. | |
| 188 | + * | |
| 189 | + * @param selector | |
| 190 | + * @param callback | |
| 191 | + * @since 4.2.7.1 | |
| 192 | + */ | |
| 193 | +const lpOnElementReady = (selector, callback) => { | |
| 194 | + const element = document.querySelector(selector); | |
| 195 | + if (element) { | |
| 196 | + callback(element); | |
| 197 | + return; | |
| 198 | + } | |
| 199 | + const observer = new MutationObserver((mutations, obs) => { | |
| 200 | + const element = document.querySelector(selector); | |
| 201 | + if (element) { | |
| 202 | + obs.disconnect(); | |
| 203 | + callback(element); | |
| 204 | + } | |
| 205 | + }); | |
| 206 | + observer.observe(document.documentElement, { | |
| 207 | + childList: true, | |
| 208 | + subtree: true | |
| 209 | + }); | |
| 210 | +}; | |
| 211 | + | |
| 212 | +// Parse JSON from string with content include LP_AJAX_START. | |
| 213 | +const lpAjaxParseJsonOld = data => { | |
| 214 | + if (typeof data !== 'string') { | |
| 215 | + return data; | |
| 216 | + } | |
| 217 | + const m = String.raw({ | |
| 218 | + raw: data | |
| 219 | + }).match(/<-- LP_AJAX_START -->(.*)<-- LP_AJAX_END -->/s); | |
| 220 | + try { | |
| 221 | + if (m) { | |
| 222 | + data = JSON.parse(m[1].replace(/(?:\r\n|\r|\n)/g, '')); | |
| 223 | + } else { | |
| 224 | + data = JSON.parse(data); | |
| 225 | + } | |
| 226 | + } catch (e) { | |
| 227 | + data = {}; | |
| 228 | + } | |
| 229 | + return data; | |
| 230 | +}; | |
| 231 | + | |
| 232 | +// status 0: hide, 1: show | |
| 233 | +const lpShowHideEl = (el, status = 0) => { | |
| 234 | + if (!el) { | |
| 235 | + return; | |
| 236 | + } | |
| 237 | + if (!status) { | |
| 238 | + el.classList.add(lpClassName.hidden); | |
| 239 | + } else { | |
| 240 | + el.classList.remove(lpClassName.hidden); | |
| 241 | + } | |
| 242 | +}; | |
| 243 | + | |
| 244 | +// status 0: hide, 1: show | |
| 245 | +const lpSetLoadingEl = (el, status) => { | |
| 246 | + if (!el) { | |
| 247 | + return; | |
| 248 | + } | |
| 249 | + if (!status) { | |
| 250 | + el.classList.remove(lpClassName.loading); | |
| 251 | + } else { | |
| 252 | + el.classList.add(lpClassName.loading); | |
| 253 | + } | |
| 254 | +}; | |
| 255 | + | |
| 256 | +// Toggle collapse section | |
| 257 | +const toggleCollapse = (e, target, elTriggerClassName = '', elsExclude = [], callback) => { | |
| 258 | + if (!elTriggerClassName) { | |
| 259 | + elTriggerClassName = lpClassName.elTriggerToggle; | |
| 260 | + } | |
| 261 | + | |
| 262 | + // Exclude elements, which should not trigger the collapse toggle | |
| 263 | + if (elsExclude && elsExclude.length > 0) { | |
| 264 | + for (const elExclude of elsExclude) { | |
| 265 | + if (target.closest(elExclude)) { | |
| 266 | + return; | |
| 267 | + } | |
| 268 | + } | |
| 269 | + } | |
| 270 | + const elTrigger = target.closest(elTriggerClassName); | |
| 271 | + if (!elTrigger) { | |
| 272 | + return; | |
| 273 | + } | |
| 274 | + | |
| 275 | + //console.log( 'elTrigger', elTrigger ); | |
| 276 | + | |
| 277 | + const elSectionToggle = elTrigger.closest(`${lpClassName.elSectionToggle}`); | |
| 278 | + if (!elSectionToggle) { | |
| 279 | + return; | |
| 280 | + } | |
| 281 | + elSectionToggle.classList.toggle(`${lpClassName.elCollapse}`); | |
| 282 | + if ('function' === typeof callback) { | |
| 283 | + callback(elSectionToggle); | |
| 284 | + } | |
| 285 | +}; | |
| 286 | + | |
| 287 | +// Get data of form | |
| 288 | +const getDataOfForm = form => { | |
| 289 | + const dataSend = {}; | |
| 290 | + const formData = new FormData(form); | |
| 291 | + for (const pair of formData.entries()) { | |
| 292 | + const key = pair[0]; | |
| 293 | + const value = formData.getAll(key); | |
| 294 | + if (!dataSend.hasOwnProperty(key)) { | |
| 295 | + // Convert value array to string. | |
| 296 | + dataSend[key] = value.join(','); | |
| 297 | + } | |
| 298 | + } | |
| 299 | + return dataSend; | |
| 300 | +}; | |
| 301 | + | |
| 302 | +// Get field keys of form | |
| 303 | +const getFieldKeysOfForm = form => { | |
| 304 | + const keys = []; | |
| 305 | + const elements = form.elements; | |
| 306 | + for (let i = 0; i < elements.length; i++) { | |
| 307 | + const name = elements[i].name; | |
| 308 | + if (name && !keys.includes(name)) { | |
| 309 | + keys.push(name); | |
| 310 | + } | |
| 311 | + } | |
| 312 | + return keys; | |
| 313 | +}; | |
| 314 | + | |
| 315 | +// Merge data handle with data form. | |
| 316 | +const mergeDataWithDatForm = (elForm, dataHandle) => { | |
| 317 | + const dataForm = getDataOfForm(elForm); | |
| 318 | + const keys = getFieldKeysOfForm(elForm); | |
| 319 | + keys.forEach(key => { | |
| 320 | + if (!dataForm.hasOwnProperty(key)) { | |
| 321 | + delete dataHandle[key]; | |
| 322 | + } else if (dataForm[key][0] === '') { | |
| 323 | + delete dataForm[key]; | |
| 324 | + delete dataHandle[key]; | |
| 325 | + } | |
| 326 | + }); | |
| 327 | + dataHandle = { | |
| 328 | + ...dataHandle, | |
| 329 | + ...dataForm | |
| 330 | + }; | |
| 331 | + return dataHandle; | |
| 332 | +}; | |
| 333 | + | |
| 334 | +/** | |
| 335 | + * Event trigger | |
| 336 | + * For each list of event handlers, listen event on document. | |
| 337 | + * | |
| 338 | + * eventName: 'click', 'change', ... | |
| 339 | + * eventHandlers = [ { selector: '.lp-button', callBack: function(){}, class: object } ] | |
| 340 | + * | |
| 341 | + * @param eventName | |
| 342 | + * @param eventHandlers | |
| 343 | + */ | |
| 344 | +const eventHandlers = (eventName, eventHandlers) => { | |
| 345 | + document.addEventListener(eventName, e => { | |
| 346 | + const target = e.target; | |
| 347 | + let args = { | |
| 348 | + e, | |
| 349 | + target | |
| 350 | + }; | |
| 351 | + eventHandlers.forEach(eventHandler => { | |
| 352 | + args = { | |
| 353 | + ...args, | |
| 354 | + ...eventHandler | |
| 355 | + }; | |
| 356 | + | |
| 357 | + //console.log( args ); | |
| 358 | + | |
| 359 | + // Check condition before call back | |
| 360 | + if (eventHandler.conditionBeforeCallBack) { | |
| 361 | + if (eventHandler.conditionBeforeCallBack(args) !== true) { | |
| 362 | + return; | |
| 363 | + } | |
| 364 | + } | |
| 365 | + | |
| 366 | + // Special check for keydown event with checkIsEventEnter = true | |
| 367 | + if (eventName === 'keydown' && eventHandler.checkIsEventEnter) { | |
| 368 | + if (e.key !== 'Enter') { | |
| 369 | + return; | |
| 370 | + } | |
| 371 | + } | |
| 372 | + if (target.closest(eventHandler.selector)) { | |
| 373 | + if (eventHandler.class) { | |
| 374 | + // Call method of class, function callBack will understand exactly {this} is class object. | |
| 375 | + eventHandler.class[eventHandler.callBack](args); | |
| 376 | + } else { | |
| 377 | + // For send args is objected, {this} is eventHandler object, not class object. | |
| 378 | + eventHandler.callBack(args); | |
| 379 | + } | |
| 380 | + } | |
| 381 | + }); | |
| 382 | + }); | |
| 383 | +}; | |
| 384 | + | |
| 385 | +/** | |
| 386 | + * Debounce - delays function execution until after `wait` ms of inactivity. | |
| 387 | + * | |
| 388 | + * Each call resets the timer. Only the last call in a burst executes. | |
| 389 | + * | |
| 390 | + * USE CASES: | |
| 391 | + * - Search inputs, form validation, window resize | |
| 392 | + * - Multiple elements need independent timers | |
| 393 | + * - When you need to call with different arguments | |
| 394 | + * | |
| 395 | + * EXAMPLES: | |
| 396 | + * const debouncedSearch = debounce( (query) => fetchResults(query), 300 ); | |
| 397 | + * searchInput.addEventListener('input', (e) => debouncedSearch(e.target.value)); | |
| 398 | + * | |
| 399 | + * const debouncedResize = debounce( recalculateLayout, 250 ); | |
| 400 | + * window.addEventListener('resize', debouncedResize); | |
| 401 | + * | |
| 402 | + * ⚠️ Create ONCE outside event handlers, not inside. | |
| 403 | + * | |
| 404 | + * @param {Function} func - Function to debounce (can be anonymous) | |
| 405 | + * @param {number} wait - Milliseconds to wait (default: 500) | |
| 406 | + * @return {Function} Debounced wrapper function | |
| 407 | + * @since 4.3.7 | |
| 408 | + * @version 1.0.0 | |
| 409 | + */ | |
| 410 | +const debounce = (func, wait = 500) => { | |
| 411 | + let timer; | |
| 412 | + return args => { | |
| 413 | + clearTimeout(timer); | |
| 414 | + timer = setTimeout(() => func(args), wait); | |
| 415 | + }; | |
| 416 | +}; | |
| 417 | + | |
| 418 | +/** | |
| 419 | + * Initialize lp-toggle-enable components. | |
| 420 | + * | |
| 421 | + * Finds all `.lp-toggle-enable` elements and wires up toggle behavior. | |
| 422 | + * Reads initial state from `data-enabled` attribute ("true"/"false"). | |
| 423 | + * Calls `data-on-toggle` callback (if provided via options) on state change. | |
| 424 | + * | |
| 425 | + * HTML structure: | |
| 426 | + * <label class="lp-toggle-enable" data-enabled="true"> | |
| 427 | + * <input type="checkbox" class="lp-toggle-enable__input" /> | |
| 428 | + * <span class="lp-toggle-enable__track"></span> | |
| 429 | + * </label> | |
| 430 | + * | |
| 431 | + * @param {string} selector CSS selector for toggle elements (default: '.lp-toggle-enable') | |
| 432 | + * @param {Function} onToggle Optional callback( el, isEnabled ) called on state change | |
| 433 | + * @since 4.4.5 | |
| 434 | + * @version 1.0.0 | |
| 435 | + */ | |
| 436 | +window.lpToggleEnableInit = 0; | |
| 437 | +const toggleEnable = (onToggle = null) => { | |
| 438 | + if (window.lpToggleEnableInit) { | |
| 439 | + return; | |
| 440 | + } | |
| 441 | + window.lpToggleEnableInit = 1; | |
| 442 | + const selector = '.lp-toggle-enable'; | |
| 443 | + const updateUI = (toggle, isEnabled) => { | |
| 444 | + toggle.classList.toggle('is-enabled', isEnabled); | |
| 445 | + const input = toggle.querySelector('.lp-toggle-enable__input'); | |
| 446 | + if (input) { | |
| 447 | + input.checked = isEnabled; | |
| 448 | + input.value = isEnabled ? '1' : '0'; | |
| 449 | + } | |
| 450 | + }; | |
| 451 | + | |
| 452 | + // Delegate click handling via eventHandlers. | |
| 453 | + eventHandlers('click', [{ | |
| 454 | + selector, | |
| 455 | + callBack: args => { | |
| 456 | + const { | |
| 457 | + e, | |
| 458 | + target | |
| 459 | + } = args; | |
| 460 | + const toggle = target.closest(selector); | |
| 461 | + if (!toggle || toggle.classList.contains('is-disabled')) { | |
| 462 | + return; | |
| 463 | + } | |
| 464 | + e.preventDefault(); | |
| 465 | + const isEnabled = !toggle.classList.contains('is-enabled'); | |
| 466 | + updateUI(toggle, isEnabled); | |
| 467 | + if ('function' === typeof onToggle) { | |
| 468 | + onToggle(toggle, isEnabled); | |
| 469 | + } | |
| 470 | + } | |
| 471 | + }]); | |
| 472 | +}; | |
| 473 | + | |
| 474 | +/** | |
| 475 | + * Initialize custom fullscreen view buttons. | |
| 476 | + * | |
| 477 | + * Delegates clicks on `.lp-btn-full-screen-view` buttons to | |
| 478 | + * `lpToggleFullscreenView`. Reads the `data-target` attribute to find the | |
| 479 | + * target element. Falls back to the button's parent element when | |
| 480 | + * `data-target` is not provided. | |
| 481 | + * | |
| 482 | + * @since 4.4.5 | |
| 483 | + * @version 1.0.0 | |
| 484 | + */ | |
| 485 | +window.lpFullScreenViewInit = 0; | |
| 486 | +const fullScreenView = () => { | |
| 487 | + if (window.lpFullScreenViewInit) { | |
| 488 | + return; | |
| 489 | + } | |
| 490 | + window.lpFullScreenViewInit = 1; | |
| 491 | + let lastScrollY = 0; | |
| 492 | + const lpToggleFullscreenView = (elTarget, elBtnFullScreen = null) => { | |
| 493 | + const isFullscreen = elTarget.classList.contains(lpClassName.elFullScreen); | |
| 494 | + if (isFullscreen) { | |
| 495 | + elTarget.classList.remove(lpClassName.elFullScreen); | |
| 496 | + document.documentElement.classList.remove('lp-full-screen-active'); | |
| 497 | + window.scrollTo(0, lastScrollY); | |
| 498 | + } else { | |
| 499 | + lastScrollY = window.scrollY; | |
| 500 | + elTarget.classList.add(lpClassName.elFullScreen); | |
| 501 | + document.documentElement.classList.add('lp-full-screen-active'); | |
| 502 | + } | |
| 503 | + if (!isFullscreen) { | |
| 504 | + if (!elTarget.querySelector(`.${lpClassName.elBtnFullScreenClose}`)) { | |
| 505 | + const closeButton = document.createElement('button'); | |
| 506 | + closeButton.type = 'button'; | |
| 507 | + closeButton.className = lpClassName.elBtnFullScreenClose; | |
| 508 | + closeButton.setAttribute('aria-label', 'Close'); | |
| 509 | + closeButton.innerHTML = lpData.i18n.closeButtonFullScreen || 'Close ×'; | |
| 510 | + closeButton.addEventListener('click', e => { | |
| 511 | + e.preventDefault(); | |
| 512 | + lpToggleFullscreenView(elTarget); | |
| 513 | + }); | |
| 514 | + elTarget.appendChild(closeButton); | |
| 515 | + } | |
| 516 | + } else { | |
| 517 | + const closeButton = elTarget.querySelector(`.${lpClassName.elBtnFullScreenClose}`); | |
| 518 | + if (closeButton) { | |
| 519 | + closeButton.remove(); | |
| 520 | + } | |
| 521 | + } | |
| 522 | + }; | |
| 523 | + eventHandlers('click', [{ | |
| 524 | + selector: lpClassName.elBtnFullScreen, | |
| 525 | + callBack: args => { | |
| 526 | + const { | |
| 527 | + e, | |
| 528 | + target | |
| 529 | + } = args; | |
| 530 | + const elBtnFullScreen = target.closest(lpClassName.elBtnFullScreen); | |
| 531 | + if (!elBtnFullScreen) { | |
| 532 | + console.log('No full screen button found'); | |
| 533 | + return; | |
| 534 | + } | |
| 535 | + e.preventDefault(); | |
| 536 | + let elTarget = null; | |
| 537 | + const targetSelector = elBtnFullScreen.dataset.targetFullscreen; | |
| 538 | + console.log(targetSelector); | |
| 539 | + if (targetSelector) { | |
| 540 | + elTarget = document.querySelector(targetSelector); | |
| 541 | + } | |
| 542 | + if (!elTarget) { | |
| 543 | + console.log('No target element found'); | |
| 544 | + return; | |
| 545 | + } | |
| 546 | + lpToggleFullscreenView(elTarget, elBtnFullScreen); | |
| 547 | + } | |
| 548 | + }]); | |
| 549 | +}; | |
| 550 | + | |
| 551 | +/***/ } | |
| 552 | + | |
| 15 | 553 | /******/ }); |
| 16 | 554 | /************************************************************************/ |
| 17 | 555 | /******/ // The module cache |
| 18 | 556 | /******/ var __webpack_module_cache__ = {}; |
| @@ -31,8 +569,14 @@ | ||
| 31 | 569 | /******/ exports: {} |
| 32 | 570 | /******/ }; |
| 33 | 571 | /******/ |
| 34 | 572 | /******/ // Execute the module function |
| 573 | +/******/ if (!(moduleId in __webpack_modules__)) { | |
| 574 | +/******/ delete __webpack_module_cache__[moduleId]; | |
| 575 | +/******/ var e = new Error("Cannot find module '" + moduleId + "'"); | |
| 576 | +/******/ e.code = 'MODULE_NOT_FOUND'; | |
| 577 | +/******/ throw e; | |
| 578 | +/******/ } | |
| 35 | 579 | /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); |
| 36 | 580 | /******/ |
| 37 | 581 | /******/ // Return the exports of the module |
| 38 | 582 | /******/ return module.exports; |
| @@ -38,24 +582,12 @@ | ||
| 38 | 582 | /******/ return module.exports; |
| 39 | 583 | /******/ } |
| 40 | 584 | /******/ |
| 41 | 585 | /************************************************************************/ |
| 42 | -/******/ /* webpack/runtime/compat get default export */ | |
| 43 | -/******/ !function() { | |
| 44 | -/******/ // getDefaultExport function for compatibility with non-harmony modules | |
| 45 | -/******/ __webpack_require__.n = function(module) { | |
| 46 | -/******/ var getter = module && module.__esModule ? | |
| 47 | -/******/ function() { return module['default']; } : | |
| 48 | -/******/ function() { return module; }; | |
| 49 | -/******/ __webpack_require__.d(getter, { a: getter }); | |
| 50 | -/******/ return getter; | |
| 51 | -/******/ }; | |
| 52 | -/******/ }(); | |
| 53 | -/******/ | |
| 54 | 586 | /******/ /* webpack/runtime/define property getters */ |
| 55 | -/******/ !function() { | |
| 587 | +/******/ (() => { | |
| 56 | 588 | /******/ // define getter functions for harmony exports |
| 57 | -/******/ __webpack_require__.d = function(exports, definition) { | |
| 589 | +/******/ __webpack_require__.d = (exports, definition) => { | |
| 58 | 590 | /******/ for(var key in definition) { |
| 59 | 591 | /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { |
| 60 | 592 | /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); |
| 61 | 593 | /******/ } |
| @@ -60,86 +592,123 @@ | ||
| 60 | 592 | /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); |
| 61 | 593 | /******/ } |
| 62 | 594 | /******/ } |
| 63 | 595 | /******/ }; |
| 64 | -/******/ }(); | |
| 596 | +/******/ })(); | |
| 65 | 597 | /******/ |
| 66 | 598 | /******/ /* webpack/runtime/hasOwnProperty shorthand */ |
| 67 | -/******/ !function() { | |
| 68 | -/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } | |
| 69 | -/******/ }(); | |
| 599 | +/******/ (() => { | |
| 600 | +/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) | |
| 601 | +/******/ })(); | |
| 70 | 602 | /******/ |
| 71 | 603 | /******/ /* webpack/runtime/make namespace object */ |
| 72 | -/******/ !function() { | |
| 604 | +/******/ (() => { | |
| 73 | 605 | /******/ // define __esModule on exports |
| 74 | -/******/ __webpack_require__.r = function(exports) { | |
| 606 | +/******/ __webpack_require__.r = (exports) => { | |
| 75 | 607 | /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { |
| 76 | 608 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); |
| 77 | 609 | /******/ } |
| 78 | 610 | /******/ Object.defineProperty(exports, '__esModule', { value: true }); |
| 79 | 611 | /******/ }; |
| 80 | -/******/ }(); | |
| 612 | +/******/ })(); | |
| 81 | 613 | /******/ |
| 82 | 614 | /************************************************************************/ |
| 83 | 615 | var __webpack_exports__ = {}; |
| 84 | -// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. | |
| 85 | -!function() { | |
| 86 | -/*!************************************************!*\ | |
| 87 | - !*** ./assets/src/apps/js/frontend/widgets.js ***! | |
| 88 | - \************************************************/ | |
| 616 | +// This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk. | |
| 617 | +(() => { | |
| 618 | +/*!*******************************************!*\ | |
| 619 | + !*** ./assets/src/js/frontend/widgets.js ***! | |
| 620 | + \*******************************************/ | |
| 89 | 621 | __webpack_require__.r(__webpack_exports__); |
| 90 | -/* harmony import */ var _wordpress_url__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/url */ "@wordpress/url"); | |
| 91 | -/* harmony import */ var _wordpress_url__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_url__WEBPACK_IMPORTED_MODULE_0__); | |
| 622 | +/* harmony import */ var _utils_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils.js */ "./assets/src/js/utils.js"); | |
| 623 | +/* harmony import */ var _api__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../api */ "./assets/src/js/api.js"); | |
| 92 | 624 | |
| 93 | 625 | |
| 94 | 626 | function widgetRestAPI() { |
| 95 | - const widgets = document.querySelectorAll('.learnpress-widget-wrapper'); | |
| 96 | - | |
| 627 | + const widgets = document.querySelectorAll('.learnpress-widget-wrapper:not(.loaded)'); | |
| 97 | 628 | if (!widgets.length) { |
| 98 | 629 | return; |
| 99 | 630 | } |
| 631 | + const getResponse = ele => { | |
| 632 | + const lang = lpData.urlParams.lang ? `?lang=${lpData.urlParams.lang}` : ''; | |
| 633 | + const widgetData = ele.dataset.widget ? JSON.parse(ele.dataset.widget) : ''; | |
| 634 | + const url = _api__WEBPACK_IMPORTED_MODULE_1__["default"].frontend.apiWidgets + lang; | |
| 635 | + const paramsFetch = { | |
| 636 | + method: 'POST', | |
| 637 | + headers: { | |
| 638 | + 'Content-Type': 'application/json' | |
| 639 | + }, | |
| 640 | + body: JSON.stringify({ | |
| 641 | + ...widgetData, | |
| 642 | + ...{ | |
| 643 | + params_url: lpData.urlParams | |
| 644 | + } | |
| 645 | + }) | |
| 646 | + }; | |
| 647 | + if (0 !== parseInt(lpData.user_id)) { | |
| 648 | + paramsFetch.headers['X-WP-Nonce'] = lpData.nonce; | |
| 649 | + } | |
| 650 | + const callBack = { | |
| 651 | + before: () => {}, | |
| 652 | + success: res => { | |
| 653 | + const { | |
| 654 | + data, | |
| 655 | + status, | |
| 656 | + message | |
| 657 | + } = res; | |
| 658 | + if (data && status === 'success') { | |
| 659 | + ele.insertAdjacentHTML('afterbegin', data); | |
| 660 | + } else if (message) { | |
| 661 | + ele.insertAdjacentHTML('afterbegin', `<div class="lp-ajax-message error" style="display:block">${message}</div>`); | |
| 662 | + } | |
| 663 | + const elBtnDone = ele.querySelector('.course-filter-submit.lp-btn-done'); | |
| 664 | + if (elBtnDone) { | |
| 665 | + if (window.outerWidth <= 991) { | |
| 666 | + (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpShowHideEl)(elBtnDone, 1); | |
| 667 | + } else { | |
| 668 | + (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpShowHideEl)(elBtnDone, 0); | |
| 669 | + } | |
| 670 | + } | |
| 671 | + }, | |
| 672 | + error: error => {}, | |
| 673 | + completed: () => { | |
| 674 | + //delete ele.dataset.widget; | |
| 675 | + const elSkeleton = ele.querySelector('.lp-skeleton-animation'); | |
| 676 | + if (elSkeleton) { | |
| 677 | + elSkeleton.remove(); | |
| 678 | + } | |
| 100 | 679 | |
| 101 | - const getResponse = async ele => { | |
| 102 | - const widget = ele.dataset.widget ? JSON.parse(ele.dataset.widget) : ''; | |
| 103 | - const response = await wp.apiFetch({ | |
| 104 | - path: 'lp/v1/widgets/api', | |
| 105 | - method: 'POST', | |
| 106 | - data: { ...widget | |
| 680 | + // Set temporary count course fields filter selected | |
| 681 | + const classCourseFilter = 'lp-form-course-filter'; | |
| 682 | + const courseFilter = document.querySelector(`.${classCourseFilter}`); | |
| 683 | + if (courseFilter) { | |
| 684 | + window.lpCourseFilter.countFieldsSelected(courseFilter); | |
| 685 | + } | |
| 107 | 686 | } |
| 108 | - }); | |
| 109 | - const { | |
| 110 | - data, | |
| 111 | - status, | |
| 112 | - message | |
| 113 | - } = response; | |
| 687 | + }; | |
| 114 | 688 | |
| 115 | - if (data && status === 'success') { | |
| 116 | - ele.insertAdjacentHTML('afterbegin', data); | |
| 117 | - } else if (message) { | |
| 118 | - ele.insertAdjacentHTML('afterbegin', `<div class="lp-ajax-message error" style="display:block">${message}</div>`); | |
| 689 | + // Call API load widget | |
| 690 | + (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.lpFetchAPI)(url, paramsFetch, callBack); | |
| 691 | + }; | |
| 692 | + widgets.forEach(ele => { | |
| 693 | + ele.classList.add('loaded'); | |
| 694 | + if (ele.classList.contains('learnpress-widget-wrapper__restapi')) { | |
| 695 | + getResponse(ele); | |
| 119 | 696 | } |
| 697 | + }); | |
| 698 | +} | |
| 699 | +widgetRestAPI(); | |
| 120 | 700 | |
| 121 | - delete ele.dataset.widget; | |
| 122 | - ele.querySelector('.lp-skeleton-animation').remove(); | |
| 123 | - }; | |
| 701 | +// Case 2: readystatechange, find all elements with the class '.lp-load-ajax-element' not have class 'loaded' | |
| 702 | +document.addEventListener('readystatechange', event => { | |
| 703 | + widgetRestAPI(); | |
| 704 | +}); | |
| 124 | 705 | |
| 125 | - if ('IntersectionObserver' in window) { | |
| 126 | - const eleObserver = new IntersectionObserver((entries, observer) => { | |
| 127 | - entries.forEach(entry => { | |
| 128 | - if (entry.isIntersecting) { | |
| 129 | - const ele = entry.target; | |
| 130 | - getResponse(ele); | |
| 131 | - eleObserver.unobserve(ele); | |
| 132 | - } | |
| 133 | - }); | |
| 134 | - }); | |
| 135 | - [...widgets].map(ele => ele.classList.contains('learnpress-widget-wrapper__restapi') && eleObserver.observe(ele)); | |
| 136 | - } | |
| 137 | -} | |
| 138 | - | |
| 139 | -document.addEventListener('DOMContentLoaded', function (event) { | |
| 706 | +// Case 3: DOMContentLoaded, find all elements with the class '.lp-load-ajax-element' not have class 'loaded' | |
| 707 | +document.addEventListener('DOMContentLoaded', () => { | |
| 140 | 708 | widgetRestAPI(); |
| 141 | 709 | }); |
| 142 | -}(); | |
| 710 | +})(); | |
| 711 | + | |
| 143 | 712 | /******/ })() |
| 144 | 713 | ; |
| 145 | 714 | //# sourceMappingURL=widgets.js.map |