Movie popup is now a prototype on the vue instance. Initialized in App and accessible on this.$popup

This commit is contained in:
2019-06-03 23:27:07 +02:00
parent a30529e192
commit ec5b74984d
2 changed files with 24 additions and 15 deletions

View File

@@ -10,7 +10,7 @@
</div> </div>
</header> </header>
<movie-popup v-if="moviePopupIsVisible" @close="closeMoviePopup" :id="moviePopupId" :type="moviePopupType"></movie-popup> <movie-popup v-if="moviePopupIsVisible" :id="popupID" :type="popupType"></movie-popup>
<section class="main"> <section class="main">
<transition name="fade" @after-leave="afterLeave"> <transition name="fade" @after-leave="afterLeave">
@@ -120,15 +120,23 @@ export default {
} }
}, },
created(){ created(){
window.addEventListener('popstate', this.onHistoryState); let that = this
window.addEventListener('pagehide', this.changeHistoryState); Vue.prototype.$popup = {
eventHub.$on('openMoviePopup', this.openMoviePopup); get isOpen() {
eventHub.$on('setSearchQuery', this.setSearchQuery); return that.moviePopupIsVisible
eventHub.$on('requestToken', this.requestToken); },
eventHub.$on('setUserStatus', this.setUserStatus); open: (id, type) => {
if (this.isTouchDevice()) { this.popupID = id || this.popupID
document.querySelector('body').classList.add('touch'); this.popupType = type || this.popupType
this.moviePopupIsVisible = true
console.log('opened')
},
close: () => {
this.moviePopupIsVisible = false
console.log('closed')
}
} }
console.log('MoviePopup registered at this.$popup and has state: ', this.$popup.isOpen)
} }
} }
</script> </script>

View File

@@ -1,8 +1,8 @@
<template> <template>
<div class="movie-popup" @click="$emit('close')"> <div class="movie-popup" @click="$popup.close()">
<div class="movie-popup__box" @click.stop> <div class="movie-popup__box" @click.stop>
<movie :id="id" :mediaType="type"></movie> <movie :id="id" :type="type"></movie>
<button class="movie-popup__close" @click="$emit('close')"></button> <button class="movie-popup__close" @click="$popup.close()"></button>
</div> </div>
<i class="loader"></i> <i class="loader"></i>
</div> </div>
@@ -15,11 +15,12 @@ export default {
props: ['id', 'type'], props: ['id', 'type'],
components: { Movie }, components: { Movie },
created(){ created(){
let that = this
window.addEventListener('keyup', function(e){ window.addEventListener('keyup', function(e){
if (e.keyCode == 27) { if (e.keyCode == 27) {
this.$emit('close'); that.$popup.close()
} }
}.bind(this)); })
} }
} }
</script> </script>
@@ -35,7 +36,7 @@ export default {
z-index: 20; z-index: 20;
width: 100%; width: 100%;
height: 100vh; height: 100vh;
background: rgba($c-dark, 0.98); background: rgba($c-dark, 0.93);
-webkit-overflow-scrolling: touch; -webkit-overflow-scrolling: touch;
overflow: auto; overflow: auto;
&__box{ &__box{