Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:area17/twill-image into develop
Browse files Browse the repository at this point in the history
* 'develop' of github.com:area17/twill-image:
  Update README.md
  feat: Add js config option
  fix: Use srcSetWebp in wep image source
  • Loading branch information
ptrckvzn committed Nov 13, 2021
2 parents 78f0635 + 3db2ef3 commit 996de31
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ In a Blade file.
<script src="{{ asset('/twill-image.js') }}"></script>
```

The JavaScript module is not required. If you prefer to rely only on the browser's native `loading` attribute, set the [`js` config option](#list-of-options) to `false`.


## Usage

Expand Down Expand Up @@ -407,6 +409,7 @@ See [above section](#preset) about the `preset` method.
|`background_color`|`string`|`#e3e3e3`| |
|`lqip`|`boolean`|`true`|Uses Twill LQIP method to generate responsive placeholder|
|`webp_support`|`boolean`|`true`|If set to `false`, the `type` attribute is omitted from `<source>` elements|
|`js`|`boolean`|`true`|If set to `false`, lazy-loading will simply rely on the image's `loading` attribute|
|`presets`|`object`| | |

## Art directed images
Expand Down
10 changes: 10 additions & 0 deletions config/twill-image.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@
*/
'webp_support' => true,

/*
|--------------------------------------------------------------------------
| Enable JavaScript
|--------------------------------------------------------------------------
|
| Tells if the JavaScript module should be used.
|
*/
'js' => true,

/*
|--------------------------------------------------------------------------
| Image Presets
Expand Down
2 changes: 1 addition & 1 deletion src/Services/ImageStyles.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function main($loading = 'eager')
$style['background-color'] = $this->backgroundColor;
}

$style['opacity'] = $loading === 'lazy' ? 0 : 1;
$style['opacity'] = (config('twill-image.js') && $loading === 'lazy') ? 0 : 1;

return $this->implodeStyles($style);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ViewModels/ImageViewModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ protected function setSourcesAttributes()

if (config('twill-image.webp_support')) {
$sources[] = $this->buildSourceObject(
$image['srcSet'],
$image['srcSetWebp'],
$image['aspectRatio'],
$this->mimeType("webp"),
);
Expand Down

0 comments on commit 996de31

Please sign in to comment.