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 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template lang="pug">
  2. .hero.w-max.f-col(v-if="showHero")
  3. .hero--video.w-max(v-if="heroType === 'video'")
  4. iframe(
  5. v-if="isPlaying"
  6. :src="`https://www.youtube.com/embed/${heroIdFromUrl}?autoplay=1`"
  7. frameborder="0"
  8. allowfullscreen
  9. ).embedded.w-max
  10. .blank.f-col(v-else)
  11. h3(v-if="heroText") {{ heroText }}
  12. img.w-max(:src="getThumbnailFromYt(showHero)" alt="hero alt image")
  13. //- button(v-if="showPlaybutton" @click="isPlaying = true") play
  14. button(v-if="showPlaybutton" @click="isPlaying = true")
  15. .hero--image.w-max(v-else-if="heroType === 'image'")
  16. .hero--image--overlay.w-max.f-col
  17. h2.t-up.t-cntr(v-html="heroText")
  18. img.w-max(:src="showHero" alt="hero alt image")
  19. .hero--image(v-else)
  20. .hero--image--overlay.w-max.f-col
  21. div(v-html="heroText")
  22. //- if not hero image then heading overlay to show only in main article
  23. </template>
  24. <script>
  25. import { ytThumbnail } from '@/utils/helpers'
  26. import { mapState } from 'vuex'
  27. export default {
  28. data() {
  29. return {
  30. heroHeight: 0,
  31. isPlaying: false
  32. }
  33. },
  34. computed: {
  35. ...mapState({
  36. showHero: state => state.hero.url,
  37. heroText: state => state.hero.text,
  38. heroType: state => state.hero.type,
  39. showPlaybutton: state => state.hero.playbutton,
  40. }),
  41. heroIdFromUrl() {
  42. const url = this.showHero.split('/')
  43. return url.pop()
  44. }
  45. },
  46. methods: {
  47. onResize() {
  48. this.heroHeight = this.$el.offsetWidth / 1.8
  49. },
  50. getThumbnailFromYt(url) {
  51. return ytThumbnail(url, 'max')
  52. }
  53. },
  54. mounted() {
  55. this.heroHeight = this.$el.offsetWidth / 1.8
  56. this.$nextTick(() => {
  57. window.addEventListener('resize', this.onResize) })
  58. },
  59. watch: {
  60. $route() {
  61. // console.log('remounting hero')
  62. // console.log(this.$store)
  63. // Clear the hero between pages
  64. this.$store.commit('CLEAR_HERO')
  65. },
  66. heroHeight() {
  67. if(!this.showHero) return
  68. Object.assign(this.$el.style, {height: this.heroHeight + 'px'})
  69. }
  70. },
  71. beforeUnmount() {
  72. window.removeEventListener('resize', this.onResize)
  73. },
  74. }
  75. </script>
  76. <style lang="postcss">
  77. @import './../sss/theme.sss'
  78. @import './../sss/variables.sss'
  79. .hero
  80. background-color: rebeccapurple
  81. min-height: 35%
  82. &--image
  83. &--overlay
  84. color: $cia_white
  85. position: absolute
  86. /* top: 30% */
  87. margin: 20% 0
  88. h2
  89. /* need better responsive solution for heading size */
  90. /* font-size: 1.5vh */
  91. color: $cia_white
  92. text-shadow: 1px 1px $cia_black
  93. max-width: 70vw
  94. &--video
  95. width: 100vw
  96. height: 100%
  97. .embedded
  98. min-height: 210px
  99. height: 100%
  100. .blank
  101. button
  102. position: absolute
  103. height: $ms-8
  104. width: $ms-8
  105. background-color: rgba(170,17,0,0.4)
  106. border-radius: 50%
  107. border-width: 3px
  108. border-color: white
  109. border-style: solid
  110. &:after
  111. content: ""
  112. position: absolute
  113. top: 20%
  114. left: 30%
  115. border-style: solid
  116. border-width: 1.2em 0 1.2em 2.1em
  117. border-color: transparent transparent transparent white
  118. @media (min-width: $medium)
  119. button
  120. height: $ms-9
  121. width: $ms-9
  122. border-width: 4px
  123. &:after
  124. top: 18%
  125. left: 30%
  126. border-width: 1.5em 0 1.5em 2.5em
  127. </style>