Make Wagtail image, lazy loading and gray background
This commit is contained in:
parent
026db8156a
commit
dca3f3e39f
|
|
@ -1,22 +1,32 @@
|
||||||
<template>
|
<template>
|
||||||
|
<div class="wagtail-image">
|
||||||
<img
|
<img
|
||||||
:src="modifiedUrl"
|
:src="modifiedUrl"
|
||||||
alt="Responsive Image"
|
:alt="alt"
|
||||||
|
class="wagtail-image__image"
|
||||||
|
v-show="loaded"
|
||||||
ref="imgElement"
|
ref="imgElement"
|
||||||
|
@load="loaded = true"
|
||||||
/>
|
/>
|
||||||
|
<div
|
||||||
|
class="wagtail-image__placeholder"
|
||||||
|
v-show="!loaded"
|
||||||
|
></div>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed, onMounted } from 'vue';
|
import { ref, computed, onMounted } from 'vue';
|
||||||
|
|
||||||
// Using props in Vue 3 setup script
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
src: String,
|
src: String,
|
||||||
|
alt: String(''),
|
||||||
});
|
});
|
||||||
|
|
||||||
const imgElement = ref(null);
|
const imgElement = ref(null);
|
||||||
const width = ref(0);
|
const width = ref(0);
|
||||||
const height = ref(0);
|
const height = ref(0);
|
||||||
|
const loaded = ref(false);
|
||||||
|
|
||||||
const modifiedUrl = computed(() => {
|
const modifiedUrl = computed(() => {
|
||||||
console.log('x, y, hdpi, retina:', width.value, height.value, isHighDensity(), isRetina());
|
console.log('x, y, hdpi, retina:', width.value, height.value, isHighDensity(), isRetina());
|
||||||
|
|
@ -33,6 +43,7 @@ const modifiedUrl = computed(() => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const updateDimensions = () => {
|
const updateDimensions = () => {
|
||||||
|
console.log(imgElement);
|
||||||
if (imgElement.value && imgElement.value.parentElement) {
|
if (imgElement.value && imgElement.value.parentElement) {
|
||||||
const { clientWidth, clientHeight } = imgElement.value.parentElement;
|
const { clientWidth, clientHeight } = imgElement.value.parentElement;
|
||||||
width.value = clientWidth;
|
width.value = clientWidth;
|
||||||
|
|
@ -69,3 +80,20 @@ const isRetina = () => {
|
||||||
|
|
||||||
onMounted(updateDimensions);
|
onMounted(updateDimensions);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
@import 'styles/helpers';
|
||||||
|
|
||||||
|
.wagtail-image {
|
||||||
|
max-width: 100%;
|
||||||
|
|
||||||
|
&__image {
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__placeholder {
|
||||||
|
background-color: $color-silver-light;
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -266,7 +266,6 @@ AWS_S3_CUSTOM_DOMAIN = "{}.s3-{}.amazonaws.com".format(
|
||||||
)
|
)
|
||||||
if USE_AWS:
|
if USE_AWS:
|
||||||
STORAGE_BACKEND = "storages.backends.s3boto3.S3Boto3Storage"
|
STORAGE_BACKEND = "storages.backends.s3boto3.S3Boto3Storage"
|
||||||
# use with cloudfront
|
|
||||||
MEDIA_URL = "https://%s/" % AWS_S3_CUSTOM_DOMAIN
|
MEDIA_URL = "https://%s/" % AWS_S3_CUSTOM_DOMAIN
|
||||||
else:
|
else:
|
||||||
STORAGE_BACKEND = "django.core.files.storage.FileSystemStorage"
|
STORAGE_BACKEND = "django.core.files.storage.FileSystemStorage"
|
||||||
|
|
@ -388,6 +387,7 @@ WAGTAILSEARCH_BACKENDS = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WAGTAILDOCS_DOCUMENT_MODEL = "books.CustomDocument"
|
WAGTAILDOCS_DOCUMENT_MODEL = "books.CustomDocument"
|
||||||
|
WAGTAILADMIN_BASE_URL = "/cms/"
|
||||||
|
|
||||||
|
|
||||||
GRAPHQL_QUERIES_DIR = os.path.join(
|
GRAPHQL_QUERIES_DIR = os.path.join(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue