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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template lang="pug">
  2. .hero.w-max.f-col(v-if="heroUrl && !loading")
  3. .tint.w-max
  4. // youTube thumb with text and embedded video
  5. .hero--video.w-max(v-if="heroType === 'video'")
  6. iframe(
  7. v-if="isPlaying"
  8. :src="`https://www.youtube.com/embed/${heroIdFromUrl}?autoplay=1`"
  9. frameborder="0"
  10. allowfullscreen
  11. ).embedded.w-max
  12. .blank.f-col(v-else)
  13. .hero--image--overlay.w-max.f-col
  14. h2.t-up.t-cntr(v-if="heroText") {{ heroText }}
  15. img.w-max(:src="getThumbnailFromYt(heroUrl)" alt="hero youTube image")
  16. button(v-if="showPlaybutton" @click="isPlaying = true").z-top
  17. // Featured image with text
  18. .hero--image.w-max(v-else-if="heroType === 'image'")
  19. .hero--image--overlay.w-max.f-col
  20. h2.t-up.t-cntr(v-html="heroText")
  21. img.w-max(:src="heroUrl" alt="hero alt image")
  22. // Blank just text
  23. .hero--image(v-else)
  24. .hero--image--overlay.w-max.f-col
  25. div(v-html="heroText")
  26. .hero.loading.w-max.f-col(v-else-if="heroUrl && loading")
  27. .tint.w-max
  28. p loading... show hero: {{heroUrl}}
  29. </template>
  30. <script>
  31. import { ytThumbnail } from '@/utils/helpers'
  32. import { mapState } from 'vuex'
  33. export default {
  34. data() {
  35. return {
  36. heroHeight: 0,
  37. isPlaying: false,
  38. }
  39. },
  40. computed: {
  41. ...mapState({
  42. heroUrl: state => state.hero.url,
  43. heroText: state => state.hero.text,
  44. loading: state => state.loading,
  45. heroType: state => state.hero.type,
  46. showPlaybutton: state => state.hero.playbutton,
  47. }),
  48. heroIdFromUrl() {
  49. const url = this.heroUrl.split('/')
  50. return url.pop()
  51. },
  52. },
  53. methods: {
  54. onResize() {
  55. this.heroHeight = this.$el.offsetWidth / 1.8
  56. },
  57. getThumbnailFromYt(url) {
  58. return ytThumbnail(url, 'max')
  59. },
  60. },
  61. mounted() {
  62. this.heroHeight = this.$el.offsetWidth / 1.8
  63. this.$nextTick(() => {
  64. window.addEventListener('resize', this.onResize)
  65. })
  66. },
  67. watch: {
  68. $route() {
  69. // console.log('remounting hero')
  70. // console.log(this.$store)
  71. // Clear the hero between pages
  72. this.$store.commit('CLEAR_HERO')
  73. },
  74. heroHeight() {
  75. if (!this.heroUrl) return
  76. Object.assign(this.$el.style, { height: this.heroHeight + 'px' })
  77. },
  78. },
  79. beforeUnmount() {
  80. window.removeEventListener('resize', this.onResize)
  81. },
  82. }
  83. </script>
  84. <style lang="postcss">
  85. // prettier-ignore
  86. @import './../sss/theme.sss'
  87. @import './../sss/variables.sss'
  88. .hero
  89. min-height: 54vw
  90. position: relative
  91. overflow: hidden
  92. justify-content: flex-start !important
  93. &.loading
  94. justify-content: center !important
  95. .tint
  96. position: absolute
  97. height: 100%
  98. background-color: #00000055
  99. z-index: 0
  100. &--image
  101. min-width: 360px
  102. max-height: 50vh
  103. img
  104. position: relative
  105. min-width: 100vw
  106. height: auto
  107. z-index: -1
  108. &--overlay
  109. position: absolute
  110. height: 100%
  111. width: 100vw
  112. right: 0
  113. left: 0
  114. overflow: clip
  115. h2
  116. font-size: $ms-2
  117. margin: 0
  118. color: $cia_white
  119. text-shadow: 1px 1px $cia_black
  120. max-width: 90vw
  121. p
  122. display: none
  123. a
  124. color: inherit
  125. text-decoration: none
  126. &--video
  127. width: 100vw
  128. height: 100%
  129. .embedded
  130. /* min-height: 25vh */
  131. min-height: 54vw
  132. height: 100%
  133. position: relative
  134. z-index: 10002
  135. .blank
  136. position: absolute
  137. height: inherit
  138. width: inherit
  139. button
  140. position: absolute
  141. min-height: $ms-7
  142. min-width: $ms-7
  143. background-color: rgba(170,17,0,0.5)
  144. border-radius: 50%
  145. border: 2px white solid
  146. &:hover
  147. background-color: rgba(170,17,0,0.8)
  148. &:after
  149. content: ""
  150. position: absolute
  151. top: 19%
  152. left: 31%
  153. border-style: solid
  154. border-width: 1em 0 1em 1.6em
  155. border-color: transparent transparent transparent rgba(255, 255, 255, 0.7)
  156. @media (min-width: $medium)
  157. button
  158. height: $ms-9
  159. width: $ms-9
  160. border-width: 3px
  161. &:after
  162. top: 18%
  163. left: 30%
  164. border-width: 1.5em 0 1.5em 2.5em
  165. .hero
  166. /* min-height: 50vh */
  167. .embedded
  168. /* min-height: 50vh */
  169. min-height: 54vw
  170. .blank
  171. button
  172. &:after
  173. top: 19%
  174. left: 34%
  175. border-width: 1.4em 2.2em 1.5em
  176. &--image
  177. &--overlay
  178. h2
  179. font-size: 4vw
  180. margin-bottom: $ms--7
  181. max-width: 70vw
  182. p
  183. display: block
  184. font-size: $ms--5
  185. </style>