NEXT craftinamerica.org. Base setup for headless wordpress https://www.craftinamerica.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hero.vue 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template lang="pug">
  2. .hero.f-col(v-if="showHero")
  3. .hero--video(v-if="heroType === 'video'")
  4. iframe(
  5. v-if="isPlaying"
  6. :src="`https://www.youtube.com/embed/${heroIdFromUrl}?autoplay=1`"
  7. frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope"
  8. allowfullscreen
  9. ).embedded
  10. .blank.f-col(v-else)
  11. h3(v-if="heroText") {{ heroText }}
  12. img(:src="getThumbnailFromYt(showHero)" alt="hero alt image")
  13. button(v-if="showPlaybutton" @click="isPlaying = true") play
  14. .hero--image(v-else-if="heroType === 'image'")
  15. .hero--image--overlay.f-col
  16. div(v-html="heroText")
  17. img(:src="showHero" alt="hero alt image")
  18. .hero--image(v-else)
  19. .hero--image--overlay.f-col
  20. div(v-html="heroText")
  21. </template>
  22. <script>
  23. import { ytThumbnail } from '@/utils/helpers'
  24. import { mapState } from 'vuex'
  25. export default {
  26. data() {
  27. return {
  28. heroHeight: 0,
  29. isPlaying: false
  30. }
  31. },
  32. computed: {
  33. ...mapState({
  34. showHero: state => state.hero.url,
  35. heroText: state => state.hero.text,
  36. heroType: state => state.hero.type,
  37. showPlaybutton: state => state.hero.playbutton,
  38. }),
  39. heroIdFromUrl() {
  40. const url = this.showHero.split('/')
  41. return url.pop()
  42. }
  43. },
  44. methods: {
  45. onResize() {
  46. this.heroHeight = this.$el.offsetWidth / 1.8
  47. },
  48. getThumbnailFromYt(url) {
  49. return ytThumbnail(url, 'max')
  50. }
  51. },
  52. mounted() {
  53. this.heroHeight = this.$el.offsetWidth / 1.8
  54. this.$nextTick(() => {
  55. window.addEventListener('resize', this.onResize) })
  56. },
  57. watch: {
  58. $route() {
  59. // console.log('remounting hero')
  60. // console.log(this.$store)
  61. // Clear the hero between pages
  62. this.$store.commit('CLEAR_HERO')
  63. },
  64. heroHeight() {
  65. if(!this.showHero) return
  66. Object.assign(this.$el.style, {height: this.heroHeight + 'px'})
  67. }
  68. },
  69. beforeUnmount() {
  70. window.removeEventListener('resize', this.onResize)
  71. },
  72. }
  73. </script>
  74. <style lang="postcss">
  75. .hero
  76. background-color: rebeccapurple
  77. min-height: 35%
  78. width: 100%
  79. &--image
  80. width: 100%
  81. > img
  82. width: 100%
  83. &--overlay
  84. color: #ffffff
  85. position: absolute
  86. top: 30%
  87. width: 100%
  88. .embedded
  89. height: 100%
  90. width: 100%
  91. </style>