-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathresponsive-craft-visual.vue
63 lines (49 loc) · 1.73 KB
/
responsive-craft-visual.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<!-- Conditionally render landscape or portrait visual instances -->
<script lang='coffee'>
import responsiveVisualMixin from '../mixins/visual/responsive-visual'
import CraftVisual, { getAssetObject, makeSrcset } from './craft-visual'
import { ucFirst } from '../services/helpers'
export default
name: 'ResponsiveCraftVisual'
mixins: [ responsiveVisualMixin ]
props: {
...responsiveVisualMixin.props
# Add support for array props
landscapeImage: Object | Array
portraitImage: Object | Array
landscapeVideo: Object | Array
portraitVideo: Object | Array
# Shorthands, for passing a supertable with landscape or portrait object
image: Object | Array
video: Object | Array
}
methods:
# Get the specified asset
# mediaType: image|video
# viewportType: portrait|landscape
getAsset: (mediaType, viewportType) ->
# Get from supertable shorthand object
if superTableAsset = getAssetObject @[mediaType]
then getAssetObject superTableAsset[viewportType]
# Get explicit value
else getAssetObject @[viewportType + ucFirst(mediaType)]
# Passthru the logic that makes a srceset from the passed in prop
makeSrcset: makeSrcset
# Make the appropriate visual instance
render: (create) ->
# Create visual for the current viewport width
if @landscape || @portrait
unless @isResponsive
then create CraftVisual, @landscape || @portrait, @$slots.default
else create CraftVisual, {
...@responsiveConfig
scopedSlots: ['image-source']: =>
@responsiveSources.map (data) -> create 'source', data
}, @$slots.default
# No assets were discovered, so explicitly clear the asset props
else create CraftVisual, { props: {
...@$props
image: undefined
video: undefined
}}, @$slots.default
</script>