| 1 |
/******/ (() => { // webpackBootstrap |
| 2 |
/******/ "use strict"; |
| 3 |
/******/ var __webpack_modules__ = ({ |
| 4 |
|
| 5 |
/***/ "@wordpress/url": |
| 6 |
/*!*****************************!*\ |
| 7 |
!*** external ["wp","url"] ***! |
| 8 |
\*****************************/ |
| 9 |
/***/ ((module) => { |
| 10 |
|
| 11 |
module.exports = window["wp"]["url"]; |
| 12 |
|
| 13 |
/***/ }) |
| 14 |
|
| 15 |
/******/ }); |
| 16 |
/************************************************************************/ |
| 17 |
/******/ // The module cache |
| 18 |
/******/ var __webpack_module_cache__ = {}; |
| 19 |
/******/ |
| 20 |
/******/ // The require function |
| 21 |
/******/ function __webpack_require__(moduleId) { |
| 22 |
/******/ // Check if module is in cache |
| 23 |
/******/ var cachedModule = __webpack_module_cache__[moduleId]; |
| 24 |
/******/ if (cachedModule !== undefined) { |
| 25 |
/******/ return cachedModule.exports; |
| 26 |
/******/ } |
| 27 |
/******/ // Create a new module (and put it into the cache) |
| 28 |
/******/ var module = __webpack_module_cache__[moduleId] = { |
| 29 |
/******/ // no module.id needed |
| 30 |
/******/ // no module.loaded needed |
| 31 |
/******/ exports: {} |
| 32 |
/******/ }; |
| 33 |
/******/ |
| 34 |
/******/ // Execute the module function |
| 35 |
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); |
| 36 |
/******/ |
| 37 |
/******/ // Return the exports of the module |
| 38 |
/******/ return module.exports; |
| 39 |
/******/ } |
| 40 |
/******/ |
| 41 |
/************************************************************************/ |
| 42 |
/******/ /* webpack/runtime/compat get default export */ |
| 43 |
/******/ (() => { |
| 44 |
/******/ // getDefaultExport function for compatibility with non-harmony modules |
| 45 |
/******/ __webpack_require__.n = (module) => { |
| 46 |
/******/ var getter = module && module.__esModule ? |
| 47 |
/******/ () => (module['default']) : |
| 48 |
/******/ () => (module); |
| 49 |
/******/ __webpack_require__.d(getter, { a: getter }); |
| 50 |
/******/ return getter; |
| 51 |
/******/ }; |
| 52 |
/******/ })(); |
| 53 |
/******/ |
| 54 |
/******/ /* webpack/runtime/define property getters */ |
| 55 |
/******/ (() => { |
| 56 |
/******/ // define getter functions for harmony exports |
| 57 |
/******/ __webpack_require__.d = (exports, definition) => { |
| 58 |
/******/ for(var key in definition) { |
| 59 |
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { |
| 60 |
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); |
| 61 |
/******/ } |
| 62 |
/******/ } |
| 63 |
/******/ }; |
| 64 |
/******/ })(); |
| 65 |
/******/ |
| 66 |
/******/ /* webpack/runtime/hasOwnProperty shorthand */ |
| 67 |
/******/ (() => { |
| 68 |
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) |
| 69 |
/******/ })(); |
| 70 |
/******/ |
| 71 |
/******/ /* webpack/runtime/make namespace object */ |
| 72 |
/******/ (() => { |
| 73 |
/******/ // define __esModule on exports |
| 74 |
/******/ __webpack_require__.r = (exports) => { |
| 75 |
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { |
| 76 |
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); |
| 77 |
/******/ } |
| 78 |
/******/ Object.defineProperty(exports, '__esModule', { value: true }); |
| 79 |
/******/ }; |
| 80 |
/******/ })(); |
| 81 |
/******/ |
| 82 |
/************************************************************************/ |
| 83 |
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 |
(() => { |
| 86 |
/*!************************************************!*\ |
| 87 |
!*** ./assets/src/apps/js/frontend/widgets.js ***! |
| 88 |
\************************************************/ |
| 89 |
__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__); |
| 92 |
|
| 93 |
function widgetRestAPI() { |
| 94 |
const widgets = document.querySelectorAll('.learnpress-widget-wrapper'); |
| 95 |
if (!widgets.length) { |
| 96 |
return; |
| 97 |
} |
| 98 |
const getResponse = async ele => { |
| 99 |
const widget = ele.dataset.widget ? JSON.parse(ele.dataset.widget) : ''; |
| 100 |
const response = await wp.apiFetch({ |
| 101 |
path: 'lp/v1/widgets/api', |
| 102 |
method: 'POST', |
| 103 |
data: { |
| 104 |
...widget |
| 105 |
} |
| 106 |
}); |
| 107 |
const { |
| 108 |
data, |
| 109 |
status, |
| 110 |
message |
| 111 |
} = response; |
| 112 |
if (data && status === 'success') { |
| 113 |
ele.insertAdjacentHTML('afterbegin', data); |
| 114 |
} else if (message) { |
| 115 |
ele.insertAdjacentHTML('afterbegin', `<div class="lp-ajax-message error" style="display:block">${message}</div>`); |
| 116 |
} |
| 117 |
delete ele.dataset.widget; |
| 118 |
ele.querySelector('.lp-skeleton-animation').remove(); |
| 119 |
}; |
| 120 |
if ('IntersectionObserver' in window) { |
| 121 |
const eleObserver = new IntersectionObserver((entries, observer) => { |
| 122 |
entries.forEach(entry => { |
| 123 |
if (entry.isIntersecting) { |
| 124 |
const ele = entry.target; |
| 125 |
getResponse(ele); |
| 126 |
eleObserver.unobserve(ele); |
| 127 |
} |
| 128 |
}); |
| 129 |
}); |
| 130 |
[...widgets].map(ele => ele.classList.contains('learnpress-widget-wrapper__restapi') && eleObserver.observe(ele)); |
| 131 |
} |
| 132 |
} |
| 133 |
document.addEventListener('DOMContentLoaded', function (event) { |
| 134 |
widgetRestAPI(); |
| 135 |
}); |
| 136 |
})(); |
| 137 |
|
| 138 |
/******/ })() |
| 139 |
; |
| 140 |
//# sourceMappingURL=widgets.js.map |