|
@@ -6,7 +6,14 @@ export default {
|
|
props: ['html'], // get the html from parent with props
|
|
props: ['html'], // get the html from parent with props
|
|
data() {
|
|
data() {
|
|
return {
|
|
return {
|
|
- template: null // compiled template from html used in render
|
|
+ template: null, // compiled template from html used in render
|
|
|
|
+ showrooms: [],
|
|
|
|
+ showroomsOdd: [],
|
|
|
|
+ showroomsEven: [],
|
|
|
|
+ showroomMode: 1,
|
|
|
|
+ showroomInterval: 0,
|
|
|
|
+ showroomI:0,
|
|
|
|
+ showroomJ:0
|
|
}
|
|
}
|
|
},
|
|
},
|
|
beforeMount() {
|
|
beforeMount() {
|
|
@@ -33,43 +40,77 @@ export default {
|
|
methods: {
|
|
methods: {
|
|
initShowroomCarroussel(){
|
|
initShowroomCarroussel(){
|
|
console.log("startShowroomCarroussel");
|
|
console.log("startShowroomCarroussel");
|
|
- let $showrooms = document.querySelectorAll('.field--name-computed-showrooms-reference > .field__item')
|
|
+ this.showrooms = document.querySelectorAll('.field--name-computed-showrooms-reference > .field__item')
|
|
- console.log('$showrooms', $showrooms);
|
|
+ console.log('showrooms', this.showrooms);
|
|
|
|
+
|
|
|
|
+ for (var i = 0; i < this.showrooms.length; i++) {
|
|
|
|
+ if (i%2 === 0) {
|
|
|
|
+ this.showroomsOdd.push(this.showrooms[i])
|
|
|
|
+ }else{
|
|
|
|
+ this.showroomsEven.push(this.showrooms[i])
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ console.log('Odd', this.showroomsOdd);
|
|
|
|
+ console.log('Even', this.showroomsEven);
|
|
|
|
|
|
// TODO: share media query and variables between scss and js
|
|
// TODO: share media query and variables between scss and js
|
|
let column_width= 205
|
|
let column_width= 205
|
|
let column_goutiere= 13
|
|
let column_goutiere= 13
|
|
let bp = (column_width + column_goutiere )*7 +1
|
|
let bp = (column_width + column_goutiere )*7 +1
|
|
const mediaQuery = window.matchMedia(`(min-width: ${bp}px)`)
|
|
const mediaQuery = window.matchMedia(`(min-width: ${bp}px)`)
|
|
- if (mediaQuery.matches) {
|
|
+ // Register event listener
|
|
- let $showroomsOdd = []
|
|
+ mediaQuery.addListener(this.checkShowroomMode)
|
|
- let $showroomsEven = []
|
|
+ this.checkShowroomMode(mediaQuery)
|
|
- for (var i = 0; i < $showrooms.length; i++) {
|
|
+
|
|
- if (i%2 === 0) {
|
|
+ // this.showroomInterval = setInterval(this.switchShowroomCarroussel.bind(this), 5000);
|
|
- $showroomsOdd.push($showrooms[i])
|
|
+ // console.log('this.showroomInterval', this.showroomInterval);
|
|
- }else{
|
|
+ // this.switchShowroomCarroussel()
|
|
- $showroomsEven.push($showrooms[i])
|
|
+ },
|
|
- }
|
|
+ checkShowroomMode(mq){
|
|
|
|
+ // default mode 1
|
|
|
|
+ let newmode = 1
|
|
|
|
+ if (mq.matches) {
|
|
|
|
+ // if mediaquery match switch to mode 2
|
|
|
|
+ newmode = 2
|
|
|
|
+ }
|
|
|
|
+ if(newmode !== this.showroomMode) {
|
|
|
|
+ // if new mode different from old mode
|
|
|
|
+ // reset sowrooms classes
|
|
|
|
+ for (var i = 0; i < this.showrooms.length; i++) {
|
|
|
|
+ this.showrooms[i].classList.remove('active')
|
|
}
|
|
}
|
|
- console.log('Odd', $showroomsOdd);
|
|
+ // record new mode
|
|
- console.log('Even', $showroomsEven);
|
|
+ this.showroomMode = newmode
|
|
- this.switchShowroomCarroussel($showroomsEven, 0)
|
|
+ // clear interval
|
|
- this.switchShowroomCarroussel($showroomsOdd, 0)
|
|
+ // if (this.showroomInterval) {
|
|
- }else{
|
|
+ clearInterval(this.showroomInterval)
|
|
- this.switchShowroomCarroussel($showrooms, 0)
|
|
+ this.showroomInterval = 0
|
|
|
|
+ // }
|
|
|
|
+ // reset indexes
|
|
|
|
+ this.showroomI = 0
|
|
|
|
+ this.showroomJ = 0
|
|
}
|
|
}
|
|
|
|
+ // in any case (re)launch the animation
|
|
|
|
+ this.showroomInterval = setInterval(this.switchShowroomCarroussel.bind(this), 5000);
|
|
|
|
+ console.log('this.showroomInterval', this.showroomInterval);
|
|
|
|
+ this.switchShowroomCarroussel()
|
|
},
|
|
},
|
|
- switchShowroomCarroussel($elmts, i){
|
|
+ switchShowroomCarroussel(){
|
|
// console.log('switchShowroomCarroussel i', $elmts, i);
|
|
// console.log('switchShowroomCarroussel i', $elmts, i);
|
|
|
|
+ if (this.showroomMode === 1) {
|
|
|
|
+ this.showrooms[this.showroomI].classList.add('active')
|
|
|
|
+ this.showrooms[this.showroomI-1 < 0 ? this.showrooms.length -1 : this.showroomI-1].classList.remove('active')
|
|
|
|
+ this.showroomI = this.showroomI+1 >= this.showrooms.length ? 0 : this.showroomI+1
|
|
|
|
+ }else{
|
|
|
|
+ this.showroomsOdd[this.showroomI].classList.add('active')
|
|
|
|
+ this.showroomsOdd[this.showroomI-1 < 0 ? this.showroomsOdd.length -1 : this.showroomI-1].classList.remove('active')
|
|
|
|
+ this.showroomI = this.showroomI+1 >= this.showroomsOdd.length ? 0 : this.showroomI+1
|
|
|
|
|
|
- $elmts[i].classList.add('active')
|
|
+ this.showroomsEven[this.showroomJ].classList.add('active')
|
|
- $elmts[i-1 < 0 ? $elmts.length -1 : i-1].classList.remove('active')
|
|
+ this.showroomsEven[this.showroomJ-1 < 0 ? this.showroomsEven.length -1 : this.showroomJ-1].classList.remove('active')
|
|
|
|
+ this.showroomJ = this.showroomJ+1 >= this.showroomsEven.length ? 0 : this.showroomJ+1
|
|
|
|
|
|
- i++
|
|
|
|
- if(i >= $elmts.length){
|
|
|
|
- i = 0
|
|
|
|
}
|
|
}
|
|
- setTimeout(this.switchShowroomCarroussel.bind(this,$elmts,i), 5000);
|
|
|
|
},
|
|
},
|
|
onClickLink(e){
|
|
onClickLink(e){
|
|
console.log("onClickLink", e, this.$router, this.$route);
|
|
console.log("onClickLink", e, this.$router, this.$route);
|