PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.8
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.8
4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 All 139 releases
learnpress / assets / js / dist / blocks / course-image.js

course-image.js in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.4.8, at assets/js/dist/blocks/course-image.js

463 lines 18.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /******/ (() => { // webpackBootstrap
2 /******/ "use strict";
3 /******/ var __webpack_modules__ = ({
4
5 /***/ "./assets/src/apps/js/blocks/course-elements/course-image/edit.js"
6 /*!************************************************************************!*\
7 !*** ./assets/src/apps/js/blocks/course-elements/course-image/edit.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 */ edit: () => (/* binding */ edit)
14 /* harmony export */ });
15 /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
16 /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
17 /* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n");
18 /* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__);
19 /* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/block-editor */ "@wordpress/block-editor");
20 /* harmony import */ var _wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2__);
21 /* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/components */ "@wordpress/components");
22 /* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__);
23
24
25
26
27 const edit = props => {
28 const {
29 attributes,
30 setAttributes,
31 context
32 } = props;
33 const blockProps = (0,_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2__.useBlockProps)();
34 const {
35 lpCourseData
36 } = context;
37 const courseImage = lpCourseData?.image || '<div class="course-img"><img src="/wp-content/plugins/learnpress/assets/images/no-image.png" alt="course thumbnail placeholder"</div>';
38 const sizeOption = [{
39 label: 'Thumbnail',
40 value: 'thumbnail'
41 }, {
42 label: 'Medium',
43 value: 'medium'
44 }, {
45 label: 'Large',
46 value: 'large'
47 }, {
48 label: 'Full',
49 value: 'full'
50 }, {
51 label: 'Custom',
52 value: 'custom'
53 }];
54 const getStyledCourseImage = () => {
55 if (lpCourseData?.image && attributes.size === 'custom' && attributes.customWidth === 500 && attributes.customHeight === 300) {
56 return lpCourseData?.image;
57 }
58 let width = 2560;
59 let height = 2560;
60 if (attributes.size === 'thumbnail') {
61 width = 150;
62 height = 150;
63 }
64 if (attributes.size === 'medium') {
65 width = 300;
66 height = 300;
67 }
68 if (attributes.size === 'large') {
69 width = 1024;
70 height = 724;
71 }
72 if (attributes.size === 'full') {
73 width = 2560;
74 height = 2560;
75 }
76 if (attributes.size === 'custom') {
77 if (attributes.customWidth && attributes.customWidth > 0) {
78 width = attributes.customWidth;
79 }
80 if (attributes.customHeight && attributes.customHeight > 0) {
81 height = attributes.customHeight;
82 }
83 if (attributes.customWidth == 0) {
84 width = 2560;
85 }
86 if (attributes.customHeight == 0) {
87 width = 2560;
88 }
89 }
90 const ratio = width / height;
91 return `<div class="course-img"><img src="/wp-content/plugins/learnpress/assets/images/no-image.png" width="${width}" height="${height}" style="aspect-ratio: ${ratio}; object-fit:cover;" alt="course thumbnail placeholder"</div>`;
92 };
93 return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_block_editor__WEBPACK_IMPORTED_MODULE_2__.InspectorControls, null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.PanelBody, {
94 title: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)('Settings', 'learnpress')
95 }, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.SelectControl, {
96 label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)('Size', 'learnpress'),
97 value: props.attributes.size,
98 options: sizeOption,
99 onChange: value => {
100 if (value !== 'custom') {
101 setAttributes({
102 customWidth: 500,
103 customHeight: 300
104 });
105 }
106 setAttributes({
107 size: value
108 });
109 }
110 }), props.attributes.size === 'custom' ? (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
111 style: {
112 display: 'flex',
113 gap: '12px'
114 }
115 }, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.__experimentalInputControl, {
116 label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)('Width', 'learnpress'),
117 type: "number",
118 min: 0,
119 style: {
120 flex: 1
121 },
122 placeholder: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)('Auto', 'learnpress'),
123 suffix: (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
124 style: {
125 marginRight: '8px'
126 }
127 }, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)('px', 'learnpress')),
128 value: props.attributes.customWidth,
129 onChange: value => {
130 const numValue = parseInt(value, 10);
131 if (!isNaN(Number(numValue)) && numValue >= 0) {
132 setAttributes({
133 customWidth: Number(numValue)
134 });
135 } else {
136 setAttributes({
137 customWidth: 500
138 });
139 }
140 }
141 }), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.__experimentalInputControl, {
142 label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)('Height', 'learnpress'),
143 type: "number",
144 min: 0,
145 style: {
146 flex: 1
147 },
148 placeholder: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)('Auto', 'learnpress'),
149 suffix: (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
150 style: {
151 marginRight: '8px'
152 }
153 }, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)('px', 'learnpress')),
154 value: props.attributes.customHeight,
155 onChange: value => {
156 const numValue = parseInt(value, 10);
157 if (!isNaN(Number(numValue)) && numValue >= 0) {
158 setAttributes({
159 customHeight: Number(numValue)
160 });
161 } else {
162 setAttributes({
163 customHeight: 300
164 });
165 }
166 }
167 })) : '', (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.ToggleControl, {
168 label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)('Make the image a link', 'learnpress'),
169 checked: props.attributes.isLink ? true : false,
170 onChange: value => {
171 props.setAttributes({
172 isLink: value ? true : false
173 });
174 }
175 }), props.attributes.isLink ? (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__.ToggleControl, {
176 label: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)('Open is new tab', 'learnpress'),
177 checked: props.attributes.target ? true : false,
178 onChange: value => {
179 props.setAttributes({
180 target: value ? true : false
181 });
182 }
183 }) : '')), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("a", null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
184 ...blockProps,
185 dangerouslySetInnerHTML: {
186 __html: getStyledCourseImage() || courseImage
187 }
188 })));
189 };
190
191 /***/ },
192
193 /***/ "./assets/src/apps/js/blocks/course-elements/course-image/save.js"
194 /*!************************************************************************!*\
195 !*** ./assets/src/apps/js/blocks/course-elements/course-image/save.js ***!
196 \************************************************************************/
197 (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
198
199 __webpack_require__.r(__webpack_exports__);
200 /* harmony export */ __webpack_require__.d(__webpack_exports__, {
201 /* harmony export */ save: () => (/* binding */ save)
202 /* harmony export */ });
203 const save = props => null;
204
205 /***/ },
206
207 /***/ "./assets/src/apps/js/blocks/utilBlock.js"
208 /*!************************************************!*\
209 !*** ./assets/src/apps/js/blocks/utilBlock.js ***!
210 \************************************************/
211 (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
212
213 __webpack_require__.r(__webpack_exports__);
214 /* harmony export */ __webpack_require__.d(__webpack_exports__, {
215 /* harmony export */ checkTemplatesCanLoadBlock: () => (/* binding */ checkTemplatesCanLoadBlock)
216 /* harmony export */ });
217 /* harmony import */ var _wordpress_blocks__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/blocks */ "@wordpress/blocks");
218 /* harmony import */ var _wordpress_blocks__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_blocks__WEBPACK_IMPORTED_MODULE_0__);
219 /* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data");
220 /* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_1__);
221 /**
222 * Check if the block can be loaded in the current template.
223 *
224 * @since 4.2.8.4
225 * @version 1.0.0
226 */
227
228
229 let currentPostIdOld = null;
230 const checkTemplatesCanLoadBlock = (templates, metadata, callBack) => {
231 (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_1__.subscribe)(() => {
232 const metaDataNew = {
233 ...metadata
234 };
235 const store = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_1__.select)('core/editor') || null;
236 if (!store || typeof store.getCurrentPostId !== 'function' || !store.getCurrentPostId()) {
237 return;
238 }
239 const currentPostId = store.getCurrentPostId();
240 if (currentPostId === null) {
241 return;
242 }
243 if (currentPostIdOld === currentPostId) {
244 return;
245 }
246 currentPostIdOld = currentPostId;
247 if ((0,_wordpress_blocks__WEBPACK_IMPORTED_MODULE_0__.getBlockType)(metaDataNew.name)) {
248 (0,_wordpress_blocks__WEBPACK_IMPORTED_MODULE_0__.unregisterBlockType)(metaDataNew.name);
249 if (templates.includes(currentPostId)) {
250 metaDataNew.ancestor = null;
251 callBack(metaDataNew);
252 } else {
253 if (!metaDataNew.ancestor) {
254 metaDataNew.ancestor = [];
255 }
256 callBack(metaDataNew);
257 }
258 }
259 });
260 };
261
262
263 /***/ },
264
265 /***/ "react"
266 /*!************************!*\
267 !*** external "React" ***!
268 \************************/
269 (module) {
270
271 module.exports = window["React"];
272
273 /***/ },
274
275 /***/ "@wordpress/block-editor"
276 /*!*************************************!*\
277 !*** external ["wp","blockEditor"] ***!
278 \*************************************/
279 (module) {
280
281 module.exports = window["wp"]["blockEditor"];
282
283 /***/ },
284
285 /***/ "@wordpress/blocks"
286 /*!********************************!*\
287 !*** external ["wp","blocks"] ***!
288 \********************************/
289 (module) {
290
291 module.exports = window["wp"]["blocks"];
292
293 /***/ },
294
295 /***/ "@wordpress/components"
296 /*!************************************!*\
297 !*** external ["wp","components"] ***!
298 \************************************/
299 (module) {
300
301 module.exports = window["wp"]["components"];
302
303 /***/ },
304
305 /***/ "@wordpress/data"
306 /*!******************************!*\
307 !*** external ["wp","data"] ***!
308 \******************************/
309 (module) {
310
311 module.exports = window["wp"]["data"];
312
313 /***/ },
314
315 /***/ "@wordpress/i18n"
316 /*!******************************!*\
317 !*** external ["wp","i18n"] ***!
318 \******************************/
319 (module) {
320
321 module.exports = window["wp"]["i18n"];
322
323 /***/ },
324
325 /***/ "./assets/src/apps/js/blocks/course-elements/course-image/block.json"
326 /*!***************************************************************************!*\
327 !*** ./assets/src/apps/js/blocks/course-elements/course-image/block.json ***!
328 \***************************************************************************/
329 (module) {
330
331 module.exports = /*#__PURE__*/JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":3,"name":"learnpress/course-image","title":"Course Image","category":"learnpress-course-elements","icon":"format-image","description":"Renders template Image Course PHP templates.","textdomain":"learnpress","keywords":["image single course","learnpress"],"ancestor":["learnpress/single-course","learnpress/course-item-template"],"usesContext":["lpCourseData"],"attributes":{"isLink":{"type":"boolean","default":true},"target":{"type":"boolean","default":false},"size":{"type":"string","default":"custom"},"customWidth":{"type":"number","default":500},"customHeight":{"type":"number","default":300}},"supports":{"multiple":true,"html":false,"shadow":true,"__experimentalBorder":{"color":true,"radius":true,"width":true,"__experimentalDefaultControls":{"width":false,"color":false,"radius":false}}}}');
332
333 /***/ }
334
335 /******/ });
336 /************************************************************************/
337 /******/ // The module cache
338 /******/ const __webpack_module_cache__ = {};
339 /******/
340 /******/ // The require function
341 /******/ function __webpack_require__(moduleId) {
342 /******/ // Check if module is in cache
343 /******/ const cachedModule = __webpack_module_cache__[moduleId];
344 /******/ if (cachedModule !== undefined) {
345 /******/ return cachedModule.exports;
346 /******/ }
347 /******/ // Create a new module (and put it into the cache)
348 /******/ const module = __webpack_module_cache__[moduleId] = {
349 /******/ // no module.id needed
350 /******/ // no module.loaded needed
351 /******/ exports: {}
352 /******/ };
353 /******/
354 /******/ // Execute the module function
355 /******/ if (!(moduleId in __webpack_modules__)) {
356 /******/ delete __webpack_module_cache__[moduleId];
357 /******/ const e = new Error("Cannot find module '" + moduleId + "'");
358 /******/ e.code = 'MODULE_NOT_FOUND';
359 /******/ throw e;
360 /******/ }
361 /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
362 /******/
363 /******/ // Return the exports of the module
364 /******/ return module.exports;
365 /******/ }
366 /******/
367 /************************************************************************/
368 /******/ /* webpack/runtime/compat get default export */
369 /******/ (() => {
370 /******/ // getDefaultExport function for compatibility with non-harmony modules
371 /******/ __webpack_require__.n = (module) => {
372 /******/ const getter = module && module.__esModule ?
373 /******/ () => (module['default']) :
374 /******/ () => (module);
375 /******/ __webpack_require__.d(getter, { a: getter });
376 /******/ return getter;
377 /******/ };
378 /******/ })();
379 /******/
380 /******/ /* webpack/runtime/define property getters */
381 /******/ (() => {
382 /******/ // define getter/value functions for harmony exports
383 /******/ __webpack_require__.d = (exports, definition) => {
384 /******/ if(Array.isArray(definition)) {
385 /******/ var i = 0;
386 /******/ while(i < definition.length) {
387 /******/ var key = definition[i++];
388 /******/ var binding = definition[i++];
389 /******/ if(!__webpack_require__.o(exports, key)) {
390 /******/ if(binding === 0) {
391 /******/ Object.defineProperty(exports, key, { enumerable: true, value: definition[i++] });
392 /******/ } else {
393 /******/ Object.defineProperty(exports, key, { enumerable: true, get: binding });
394 /******/ }
395 /******/ } else if(binding === 0) { i++; }
396 /******/ }
397 /******/ } else {
398 /******/ for(var key in definition) {
399 /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
400 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
401 /******/ }
402 /******/ }
403 /******/ }
404 /******/ };
405 /******/ })();
406 /******/
407 /******/ /* webpack/runtime/hasOwnProperty shorthand */
408 /******/ (() => {
409 /******/ __webpack_require__.o = (obj, prop) => (Object.hasOwn(obj, prop))
410 /******/ })();
411 /******/
412 /******/ /* webpack/runtime/make namespace object */
413 /******/ (() => {
414 /******/ // define __esModule on exports
415 /******/ __webpack_require__.r = (exports) => {
416 /******/ if(Symbol.toStringTag) {
417 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
418 /******/ }
419 /******/ Object.defineProperty(exports, '__esModule', { value: true });
420 /******/ };
421 /******/ })();
422 /******/
423 /************************************************************************/
424 let __webpack_exports__ = {};
425 // This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk.
426 (() => {
427 /*!*************************************************************************!*\
428 !*** ./assets/src/apps/js/blocks/course-elements/course-image/index.js ***!
429 \*************************************************************************/
430 __webpack_require__.r(__webpack_exports__);
431 /* harmony import */ var _edit__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./edit */ "./assets/src/apps/js/blocks/course-elements/course-image/edit.js");
432 /* harmony import */ var _save__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./save */ "./assets/src/apps/js/blocks/course-elements/course-image/save.js");
433 /* harmony import */ var _block_json__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./block.json */ "./assets/src/apps/js/blocks/course-elements/course-image/block.json");
434 /* harmony import */ var _wordpress_blocks__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/blocks */ "@wordpress/blocks");
435 /* harmony import */ var _wordpress_blocks__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_blocks__WEBPACK_IMPORTED_MODULE_3__);
436 /* harmony import */ var _utilBlock_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../utilBlock.js */ "./assets/src/apps/js/blocks/utilBlock.js");
437 /**
438 * Register block course image.
439 */
440
441
442
443
444
445
446 const templatesName = ['learnpress/learnpress//single-lp_course', 'learnpress/learnpress//single-lp_course-offline'];
447 (0,_utilBlock_js__WEBPACK_IMPORTED_MODULE_4__.checkTemplatesCanLoadBlock)(templatesName, _block_json__WEBPACK_IMPORTED_MODULE_2__, metadataNew => {
448 (0,_wordpress_blocks__WEBPACK_IMPORTED_MODULE_3__.registerBlockType)(metadataNew.name, {
449 ...metadataNew,
450 edit: _edit__WEBPACK_IMPORTED_MODULE_0__.edit,
451 save: _save__WEBPACK_IMPORTED_MODULE_1__.save
452 });
453 });
454 (0,_wordpress_blocks__WEBPACK_IMPORTED_MODULE_3__.registerBlockType)(_block_json__WEBPACK_IMPORTED_MODULE_2__.name, {
455 ..._block_json__WEBPACK_IMPORTED_MODULE_2__,
456 edit: _edit__WEBPACK_IMPORTED_MODULE_0__.edit,
457 save: _save__WEBPACK_IMPORTED_MODULE_1__.save
458 });
459 })();
460
461 /******/ })()
462 ;
463 //# sourceMappingURL=course-image.js.map