@@ -423,68 +423,35 @@ Create a JavaScript widget in your module's `/view/frontend/web/js/content-type/
423
423
* Copyright © Magento, Inc. All rights reserved.
424
424
* See COPYING.txt for license details.
425
425
*/
426
-
427
- define ([' jquery' ], function ($ ) {
426
+
427
+ define ([
428
+ ' jquery' ,
429
+ ' slick'
430
+ ], function ($ ) {
428
431
' 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
474
451
});
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
-
486
452
};
487
453
});
454
+
488
455
```
489
456
490
457
### Add XML configuration to load it on the frontend
0 commit comments