Skip to content

Commit 858c4fb

Browse files
committed
MAGETWO-92550: Implement extensible mechanism to load widgets dynamic
1 parent a27737b commit 858c4fb

File tree

1 file changed

+25
-58
lines changed

1 file changed

+25
-58
lines changed

app/code/Magento/PageBuilder/docs/content-type-configuration.md

Lines changed: 25 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -423,68 +423,35 @@ Create a JavaScript widget in your module's `/view/frontend/web/js/content-type/
423423
* Copyright © Magento, Inc. All rights reserved.
424424
* See COPYING.txt for license details.
425425
*/
426-
427-
define(['jquery'], function ($) {
426+
427+
define([
428+
'jquery',
429+
'slick'
430+
], function ($) {
428431
'use strict';
429-
430-
/**
431-
* Show the overlay on hover of specific elements
432-
*
433-
* @param {JQuery<Element>[]} $elements
434-
*/
435-
function showOverlayOnHover($elements) {
436-
$elements.each(function (index, element) {
437-
var overlayEl = $(element).find('.pagebuilder-overlay'),
438-
overlayColor = overlayEl.attr('data-overlay-color');
439-
440-
$(element).hover(
441-
function () {
442-
overlayEl.css('background-color', overlayColor);
443-
},
444-
function () {
445-
overlayEl.css('background-color', 'transparent');
446-
}
447-
);
448-
});
449-
}
450-
451-
/**
452-
* Show button on hover of specific elements
453-
*
454-
* @param {JQuery<Element>[]} $elements
455-
* @param {String} buttonClass
456-
*/
457-
function showButtonOnHover($elements, buttonClass) {
458-
$elements.each(function (index, element) {
459-
var buttonEl = $(element).find(buttonClass);
460-
461-
$(element).hover(
462-
function () {
463-
buttonEl.css({
464-
'opacity': '1',
465-
'visibility': 'visible'
466-
});
467-
}, function () {
468-
buttonEl.css({
469-
'opacity': '0',
470-
'visibility': 'hidden'
471-
});
472-
}
473-
);
432+
433+
return function (config, sliderElement) {
434+
435+
var $element = $(sliderElement);
436+
437+
/**
438+
* Prevent each slick slider from being initialized more than once which could throw an error.
439+
*/
440+
if ($element.hasClass('slick-initialized')) {
441+
$element.slick('unslick');
442+
}
443+
444+
$element.slick({
445+
autoplay: $element.data('autoplay') === 1,
446+
autoplaySpeed: $element.data('autoplay-speed') || 0,
447+
fade: $element.data('fade') === 1,
448+
infinite: $element.data('is-infinite') === 1,
449+
arrows: $element.data('show-arrows') === 1,
450+
dots: $element.data('show-dots') === 1
474451
});
475-
}
476-
477-
return function (config, element) {
478-
479-
var buttonClass = config.buttonSelector,
480-
overlayHoverSelector = '[data-show-overlay="%s"] > a'.replace('%s', config.showOverlay),
481-
overlayButtonSelector = '[data-show-button="%s"] > a'.replace('%s', config.showOverlay);
482-
483-
showOverlayOnHover($(element).find(overlayHoverSelector));
484-
showButtonOnHover($(element).find(overlayButtonSelector), buttonClass);
485-
486452
};
487453
});
454+
488455
```
489456

490457
### Add XML configuration to load it on the frontend

0 commit comments

Comments
 (0)