Skip to content

Commit

Permalink
Merge pull request #26 from pboivin/feat/add-js-config-option
Browse files Browse the repository at this point in the history
feat: Add `js` config option
  • Loading branch information
ptrckvzn committed Nov 13, 2021
2 parents c6e8f0b + a0772a4 commit 3db2ef3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
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

0 comments on commit 3db2ef3

Please sign in to comment.