Skip to content

Commit 2ffc0b9

Browse files
authored
Implement spteclazyload (#7)
* Implement stefanpoensgen/SptecLazyload
1 parent 4b6a256 commit 2ffc0b9

File tree

12 files changed

+98
-15
lines changed

12 files changed

+98
-15
lines changed

CHANGELOG_de-DE.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 1.0.10
2+
3+
* FEATURE Thumbnails werden nun erst geladen, sobald der Besucher auch in der Nähe ist
4+
15
# 1.0.9
26

37
* BUGFIX Behebe Problem mit thumbnail-variable, wenn kein Thumbnail existiert

CHANGELOG_en-GB.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 1.0.10
2+
3+
* FEATURE Thumbnails will be lazy loaded
4+
15
# 1.0.9
26

37
* BUGFIX Fix thumbnail-variable, which occurs, when no thumbnail exists

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) [![Shopware Store](https://img.shields.io/badge/shopware-store-blue.svg?style=flat-square)](https://store.shopware.com/en/frosh69611263569f/thumbnailprocessor-plugin.html)
44

55

6-
This plugins allows you to use variable thumbnails, if your filesystem (or storage-adapter) supports it.
7-
It will add parameters to original image paths.
6+
This plugins allows you to use variable thumbnails, if your filesystem (or storage-adapter) supports it.
7+
Additionally it has built-in Lazyloading.
8+
You can use this, if you don't want thumbnails to be created on you development-system, too.
9+
It will add parameters to original image paths.
810
So you are able to save storage and add new thumbnails on the fly.
911

1012
| Version | Requirements
@@ -16,6 +18,10 @@ So you are able to save storage and add new thumbnails on the fly.
1618

1719
Download the plugin from the release page and enable it in shopware.
1820

21+
### From source
22+
23+
Run `npm install` in `src/Resources/app/storefront` within the plugin directory
24+
1925
## Usage
2026
While active, this will access all thumbnails variable from original image. The thumbnail-files won't be needed anymore.
2127

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"thumbnail"
1212
],
1313
"description": "This plugins allows you to use variable thumbnails, without having them on storage.",
14-
"version": "1.0.9",
14+
"version": "1.0.10",
1515
"type": "shopware-platform-plugin",
1616
"license": "mit",
1717
"authors": [
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// eslint-disable-next-line func-names
2+
module.exports = function (params) {
3+
return {
4+
resolve: {
5+
modules: [
6+
`${params.basePath}Resources/app/storefront/node_modules`
7+
]
8+
}
9+
};
10+
};

src/Resources/app/storefront/dist/storefront/js/frosh-platform-thumbnail-processor.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Resources/app/storefront/package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "froshplatformthumbnailprocessor-storefront-packages",
3+
"version": "1.0.0",
4+
"private": true,
5+
"dependencies": {
6+
"lazysizes": "^5.2.1"
7+
},
8+
"author": "Sebastian König (@tinect)",
9+
"license": "MIT"
10+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import Debouncer from 'src/helper/debouncer.helper';
2+
import 'lazysizes';
3+
import 'lazysizes/plugins/native-loading/ls.native-loading';
4+
import 'lazysizes/plugins/attrchange/ls.attrchange';
5+
import 'lazysizes/plugins/parent-fit/ls.parent-fit';
6+
import 'lazysizes/plugins/object-fit/ls.object-fit';
7+
8+
document.addEventListener('lazyloaded', Debouncer.debounce(function(event){
9+
if(event.target.classList.contains('tns-complete')) {
10+
window.dispatchEvent(new Event('resize'));
11+
}
12+
}, 400));

src/Resources/store/de.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
Verschwende keine Rechenleistung und keinen Speicherplatz mit Thumbnails! Mit diesem Plugin können Sie auf dynamische Thumbnails zurückgreifen.
1+
Verschwende keine Rechenleistung und keinen Speicherplatz mit Thumbnails!
2+
Mit diesem Plugin können Sie auf dynamische Thumbnails zurückgreifen. Außerdem stellt dieses Plugin die Funktion von LazyLoading für Thumbnails zu Verfügung.
23
Jeder Artikel, jedes Bild in der Einkaufswelten hat berechtigterweise Thumbnails. Diese werden standardmäßig
34
automatisch beim Upload erzeugt und gespeichert.
45
An diesem Punkt greift dieses Plugin ein und stellt die Funktion zur Verfügung, dass keine Thumbnails mehr erstellt

src/Resources/store/en.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Don't waste the computing power and space with thumbnails! With this plugin you can access dynamic thumbnails.
2+
This plugin also provides the LazyLoading function for thumbnails.
23
Every product, every picture in the shopping worlds legitimately has thumbnails. These become standard
34
generated and saved automatically during upload.
45
At this point this plugin intervenes and provides the function that no more thumbnails are created have to be created.

src/Resources/views/storefront/utilities/thumbnail.html.twig

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{% if not shopware.config.FroshPlatformThumbnailProcessor.config.FixListingThumbnailSizes %}
22
{{ include('@Storefront/storefront/utilities/thumbnail.html.twig') }}
33
{% else %}
4-
{# FROSH: we are just removing max-width here, nothing more #}
54

65
{# activate load per default. If it is not activated only a data-src is set instead of the src tag. #}
76
{% if load is not defined %}
@@ -49,16 +48,38 @@
4948
{% for key, value in shopware.theme.breakpoint|reverse %}(min-width: {{ value }}px) {{ sizes[key] }}{% if not loop.last %}, {% endif %}{% endfor %}, {{ sizeFallback }}vw
5049
{% endapply %}{% endset %}
5150
{% endif %}
52-
<img {% if load %}src="{{ media|sw_encode_media_url }}" {% else %}data-src="{{ media|sw_encode_media_url }}" {% endif %}
53-
{% if media.thumbnails|length > 0 %}
54-
{% if load %}srcset="{{ srcsetValue }}" {% else %}data-srcset="{{ srcsetValue }}" {% endif %}
55-
{% if sizes['default'] %}
56-
sizes="{{ sizes['default'] }}"
57-
{% elseif sizes|length > 0 %}
58-
sizes="{{ sizesValue }}"
59-
{% endif %}
51+
52+
{% if load is same as(true) %}
53+
{% if attributes.class %}
54+
{% set attributes = attributes|merge({'class': 'lazyload ' ~ attributes.class}) %}
55+
{% else %}
56+
{% set attributes = attributes|merge({'class': 'lazyload'}) %}
6057
{% endif %}
61-
{% for key, value in attributes %}{% if value != '' %} {{ key }}="{{ value }}"{% endif %}{% endfor %}
62-
/>
58+
59+
<img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
60+
data-src="{{ media|sw_encode_media_url }}"
61+
{% if media.thumbnails|length > 0 %}
62+
data-srcset="{{ srcsetValue }}"
63+
{% if sizes['default'] %}
64+
data-sizes="{{ sizes['default'] }}"
65+
{% elseif sizes|length > 0 %}
66+
data-sizes="{{ sizesValue }}"
67+
{% endif %}
68+
{% endif %}
69+
{% for key, value in attributes %}{% if value != '' %} {{ key }}="{{ value }}"{% endif %}{% endfor %}
70+
/>
71+
{% else %}
72+
<img data-src="{{ media|sw_encode_media_url }}"
73+
{% if media.thumbnails|length > 0 %}
74+
data-srcset="{{ srcsetValue }}"
75+
{% if sizes['default'] %}
76+
sizes="{{ sizes['default'] }}"
77+
{% elseif sizes|length > 0 %}
78+
sizes="{{ sizesValue }}"
79+
{% endif %}
80+
{% endif %}
81+
{% for key, value in attributes %}{% if value != '' %} {{ key }}="{{ value }}"{% endif %}{% endfor %}
82+
/>
83+
{% endif %}
6384

6485
{% endif %}

0 commit comments

Comments
 (0)