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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. /* background-color: rebeccapurple */
  90. /* min-height: 25vh */
  91. min-height: 54vw
  92. position: relative
  93. overflow: hidden
  94. justify-content: flex-start !important
  95. &.loading
  96. justify-content: center !important
  97. .tint
  98. position: absolute
  99. height: 100%
  100. background-color: #00000055
  101. z-index: 0
  102. &--image
  103. min-width: 360px
  104. max-height: 50vh
  105. img
  106. position: relative
  107. min-width: 100vw
  108. height: auto
  109. z-index: -1
  110. &--overlay
  111. position: absolute
  112. height: 100%
  113. width: 100vw
  114. right: 0
  115. left: 0
  116. overflow: clip
  117. h2
  118. font-size: $ms-2
  119. margin: 0
  120. color: $cia_white
  121. text-shadow: 1px 1px $cia_black
  122. max-width: 90vw
  123. p
  124. display: none
  125. a
  126. color: inherit
  127. text-decoration: none
  128. &--video
  129. width: 100vw
  130. height: 100%
  131. .embedded
  132. /* min-height: 25vh */
  133. min-height: 54vw
  134. height: 100%
  135. position: relative
  136. z-index: 10002
  137. .blank
  138. position: absolute
  139. height: inherit
  140. width: inherit
  141. button
  142. position: absolute
  143. min-height: $ms-7
  144. min-width: $ms-7
  145. background-color: rgba(170,17,0,0.5)
  146. border-radius: 50%
  147. border: 2px white solid
  148. &:hover
  149. background-color: rgba(170,17,0,0.8)
  150. &:after
  151. content: ""
  152. position: absolute
  153. top: 19%
  154. left: 31%
  155. border-style: solid
  156. border-width: 1em 0 1em 1.6em
  157. border-color: transparent transparent transparent rgba(255, 255, 255, 0.7)
  158. @media (min-width: $medium)
  159. button
  160. height: $ms-9
  161. width: $ms-9
  162. border-width: 3px
  163. &:after
  164. top: 18%
  165. left: 30%
  166. border-width: 1.5em 0 1.5em 2.5em
  167. .hero
  168. /* min-height: 50vh */
  169. .embedded
  170. /* min-height: 50vh */
  171. min-height: 54vw
  172. .blank
  173. button
  174. &:after
  175. top: 19%
  176. left: 34%
  177. border-width: 1.4em 2.2em 1.5em
  178. &--image
  179. &--overlay
  180. h2
  181. font-size: 4vw
  182. margin-bottom: $ms--7
  183. max-width: 70vw
  184. p
  185. display: block
  186. font-size: $ms--5
  187. </style>