Skip to content

Commit

Permalink
Flatten view data
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrckvzn committed Oct 1, 2021
1 parent e33bb7b commit 9ebc315
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 29 deletions.
8 changes: 6 additions & 2 deletions resources/views/main-image.blade.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
@include('image::picture', [
'fallback' => $src,
'fallback' => $mainSrc,
'attributes' => 'data-main-image',
'sources' => $mainSources ?? [],
'style' => $mainStyle,
])
<noscript>
@include('image::picture', [
'fallback' => $src,
'fallback' => $mainSrc,
'attributes' => 'data-main-image',
'shouldLoad' => true,
'sources' => $mainSources ?? [],
'style' => $mainStyle,
])
</noscript>
7 changes: 4 additions & 3 deletions resources/views/placeholder.blade.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
@php
$attributes = 'aria-hidden="true" data-placeholder-image';
@endphp
@if(isset($src) && !!$src)
@if(isset($placeholderSrc) && !!$placeholderSrc)
@include('image::picture', [
'fallback' => $src,
'fallback' => $placeholderSrc,
'alt' => "",
'attributes' => $attributes,
'sizes' => $sizes,
'style' => $style,
'sources' => $placeholderSources ?? [],
'style' => $placeholderStyle,
])
@else
<div style="{{$style}}" {!! $attributes !!}></div>
Expand Down
8 changes: 4 additions & 4 deletions resources/views/wrapper.blade.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<div
class="{{$wrapper['classes']}}"
style="{{$wrapper['style']}}"
class="{{$wrapperClasses}}"
style="{{$wrapperStyle}}"
data-twill-image-wrapper
>
@include('image::sizer')
@include('image::placeholder', $placeholder)
@include('image::main-image', $main)
@include('image::placeholder')
@include('image::main-image')
</div>
33 changes: 13 additions & 20 deletions src/ViewModels/ImageViewModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,29 +344,22 @@ protected function setLqipAttributes()
public function toArray(): array
{
return array_filter([
'layout' => $this->layout,
'wrapper' => [
'classes' => $this->wrapperClasses(),
'style' => $this->styleService->wrapper(),
],
'placeholder' => [
'src' => $this->lqipSrc,
'sources' => $this->lqipSources,
'style' => $this->styleService->placeholder(),
],
'main' => [
'loading' => $this->loading,
'shouldLoad' => $this->loading === 'eager',
'style' => $this->styleService->main($this->loading),
'src' => $this->src,
'sources' => $this->sources,
'alt' => $this->alt,
],
'alt' => $this->alt,
'width' => $this->width,
'aspectRatio' => $this->data['image']['aspectRatio'],
'height' => $this->height,
'layout' => $this->layout,
'loading' => $this->loading,
'mainStyle' => $this->styleService->main($this->loading),
'mainSrc' => $this->src,
'mainSources' => $this->sources,
'placeholderSrc' => $this->lqipSrc,
'placeholderSources' => $this->lqipSources,
'placeholderStyle' => $this->styleService->placeholder(),
'shouldLoad' => $this->loading === 'eager',
'sizes' => $this->sizes,
'aspectRatio' => $this->data['image']['aspectRatio'],
'width' => $this->width,
'wrapperClasses' => $this->wrapperClasses(),
'wrapperStyle' => $this->styleService->wrapper(),
]);
}
}

0 comments on commit 9ebc315

Please sign in to comment.