Support for lazy loading of rich embeds
authorAlexander Ebert <ebert@woltlab.com>
Fri, 14 May 2021 15:55:13 +0000 (17:55 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 14 May 2021 15:55:13 +0000 (17:55 +0200)
com.woltlab.wcf/templates/unfurlUrl.tpl
wcfsetup/install/files/style/ui/unfurlUrl.scss

index dc0ed1d4bc85ee766c338e8c753e829552b28946..3d85f6bafb6890654135aa0a672fdf768fc1633d 100644 (file)
@@ -2,13 +2,13 @@
        {if $object->isPlainUrl()}
                <a {anchorAttributes url=$object->url isUgc=$enableUgc}>{$object->title}</a>
        {else}
-               <div class="
-                       unfurlUrlCard
-                       {if $object->hasCoverImage()}unfurlUrlCardCoverImage{/if}
-                       {if $object->hasSquaredImage()}unfurlUrlCardSquaredImage{/if}
-               ">
-
-                       <div class="unfurlUrlImage"{if !$object->getImageUrl()|empty} style="background-image: url('{$object->getImageUrl()}')"{/if}></div>
+               <div class="unfurlUrlCard{*
+                       *}{if $object->hasCoverImage()} unfurlUrlCardCoverImage{/if}{*
+                       *}{if $object->hasSquaredImage()} unfurlUrlCardSquaredImage{/if}{*
+               *}">
+                       {if !$object->getImageUrl()|empty}
+                               <img src="{$object->getImageUrl()}" height="{$object->height}" width="{$object->width}" class="unfurlUrlImage" alt="" loading="lazy">
+                       {/if}
                        <div class="unfurlUrlInformation">
                                <div class="unfurlUrlTitle">{$object->title}</div>
                                <div class="unfurlUrlDescription">{$object->description}</div>
index 53d164214efc8d64c349468d608424c665cd1d48..f02fc763a5126d60b59690f563c18df56a361315 100644 (file)
                width: 400px;
 
                .unfurlUrlImage {
-                       height: 200px;
-                       position: relative;
+                       /* The `!important` is required because of `.messageBody > .messageText img`. */
+                       height: 200px !important;
+                       object-fit: cover;
+                       object-position: center;
+                       width: 600px;
                }
        }
 
                .unfurlUrlImage {
                        border-radius: 3px;
                        flex: 0 0 auto;
-                       height: 128px;
+                       /* The `!important` is required because of `.messageBody > .messageText img`. */
+                       height: 128px !important;
                        margin: 10px;
                        width: 128px;
 
                        @include screen-sm {
-                               height: 64px;
+                               height: 64px !important;
                                width: 64px;
                        }
 
                        @include screen-xs {
-                               height: 24px;
+                               height: 24px !important;
                                position: absolute;
                                width: 24px;
                        }
        }
 }
 
-.unfurlUrlImage {
-       background-position: center;
-       background-repeat: no-repeat;
-       background-size: cover;
-}
-
 .unfurlUrlInformation {
        position: relative;
        padding: 10px 10px 25px 10px;