issues/27: cabinet owl.carousel Stimulus fix
This commit is contained in:
committed by
Valeriy Petrov
parent
0460846dac
commit
2ed344e503
+1
-1
@@ -25,6 +25,6 @@ yarn-error.log
|
||||
###< symfony/webpack-encore-bundle ###
|
||||
/*.md
|
||||
/*.lock
|
||||
!/yarn.lock
|
||||
/symfony.lock
|
||||
/yarn.lock
|
||||
/service.sh
|
||||
@@ -1,16 +1,13 @@
|
||||
import { Controller } from 'stimulus';
|
||||
import 'owl.carousel2/dist/assets/owl.carousel.css';
|
||||
import 'owl.carousel2/dist/assets/owl.theme.default.css';
|
||||
import 'owl.carousel2';
|
||||
|
||||
/*
|
||||
* This is an example Stimulus controller!
|
||||
*
|
||||
* Any element with a data-controller="hello" attribute will cause
|
||||
* this controller to be executed. The name "hello" comes from the filename:
|
||||
* hello_controller.js -> "hello"
|
||||
*
|
||||
* Delete this file or adapt it for your use!
|
||||
* owl.carousel2 is a legacy jQuery plugin that reads `window.jQuery` at module
|
||||
* evaluation time. When statically imported it lands in the eager shared chunk,
|
||||
* and depending on webpack chunk ordering it can evaluate before jQuery is ready,
|
||||
* throwing and breaking the whole Stimulus bootstrap. Load it lazily inside
|
||||
* connect() so it can never break unrelated controllers (e.g. registration).
|
||||
*/
|
||||
export default class extends Controller {
|
||||
static targets = ["showid"];
|
||||
@@ -18,6 +15,7 @@ export default class extends Controller {
|
||||
connect() {
|
||||
var slideshow = this.element;
|
||||
|
||||
import('owl.carousel2').then(function() {
|
||||
$(slideshow).owlCarousel({
|
||||
nav: true,
|
||||
margin: 15,
|
||||
@@ -42,6 +40,10 @@ export default class extends Controller {
|
||||
});
|
||||
|
||||
slideshow.classList.remove('hide');
|
||||
}).catch(function(e) {
|
||||
console.warn('owl.carousel failed to load', e);
|
||||
slideshow.classList.remove('hide');
|
||||
});
|
||||
|
||||
slideshow.querySelectorAll('.show-msg').forEach(function (el) {
|
||||
el.addEventListener('click', function (evn) {
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
},
|
||||
"license": "UNLICENSED",
|
||||
"private": true,
|
||||
"packageManager": "yarn@1.22.22",
|
||||
"scripts": {
|
||||
"dev-server": "encore dev-server",
|
||||
"dev": "encore dev",
|
||||
|
||||
Reference in New Issue
Block a user