Various JS optimizations

This commit is contained in:
Bernd Bestel 2023-05-21 18:01:47 +02:00
parent 825321593b
commit 979c67b44c
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
25 changed files with 64 additions and 87 deletions

View File

@ -28,7 +28,6 @@
"fullcalendar": "^3.10.1",
"gettext-translator": "3.0.1",
"jquery": "^3.6.0",
"jquery-lazy": "^1.7.11",
"jquery-serializejson": "^2.9.0",
"moment": "^2.27.0",
"nosleep.js": "^0.12.0",

View File

@ -583,15 +583,6 @@ if (window.location.hash)
$(window.location.hash).addClass("p-2 border border-info rounded");
}
$("#about-dialog-link").on("click", function()
{
bootbox.alert({
message: '<iframe height="400px" class="embed-responsive" src="' + U("/about?embedded") + '"></iframe>',
closeButton: false,
size: "large"
});
});
function RefreshLocaleNumberDisplay(rootSelector = "#page-content")
{
$(rootSelector + " .locale-number.locale-number-currency").each(function()
@ -674,22 +665,6 @@ $(document).on("click", ".easy-link-copy-textbox", function()
$(this).select();
});
// Summernote workaround: Make embeds responsive
// By wrapping any embeded video in a container with class "embed-responsive"
$(".note-video-clip").each(function()
{
$(this).parent().html('<div class="embed-responsive embed-responsive-16by9">' + $(this).wrap("<p/>").parent().html() + "</div>");
});
function LoadImagesLazy()
{
$(".lazy:visible").Lazy({
enableThrottle: true,
throttle: 500
});
}
LoadImagesLazy();
if (Grocy.CalendarFirstDayOfWeek)
{
moment.updateLocale(moment.locale(), {
@ -720,7 +695,7 @@ $(document).on("click", ".show-as-dialog-link", function(e)
var link = $(e.currentTarget).attr("href");
bootbox.dialog({
message: '<iframe height="650px" class="embed-responsive" src="' + link + '"></iframe>',
message: '<iframe height="650px" class="embed-responsive" src="' + link + '" loading="lazy"></iframe>',
size: 'large',
backdrop: true,
closeButton: false,
@ -738,7 +713,7 @@ $(document).on("click", ".show-as-dialog-link", function(e)
});
// Init Bootstrap tooltips
$('[data-toggle="tooltip"]').tooltip()
$('[data-toggle="tooltip"]').tooltip();
// serializeJSON defaults
$.serializeJSON.defaultOptions.checkboxUncheckedValue = "0";
@ -750,6 +725,7 @@ $(Grocy.UserPermissions).each(function(index, item)
$('.permission-' + item.permission_name).addClass('disabled').addClass('not-allowed');
}
});
$('a.link-return').not(".btn").each(function()
{
var base = $(this).data('href');
@ -762,8 +738,7 @@ $('a.link-return').not(".btn").each(function()
$(this).attr('href', base + '?returnto=' + encodeURIComponent(Grocy.CurrentUrlRelative));
}
})
});
$(document).on("click", "a.btn.link-return", function(e)
{
e.preventDefault();

View File

@ -324,7 +324,6 @@ $(document).on("click", ".change-table-columns-visibility-toggle", function()
var dataTable = $(dataTableSelector).DataTable();
dataTable.columns(columnIndex).visible(this.checked);
LoadImagesLazy();
});

View File

@ -6,8 +6,15 @@ $("textarea.wysiwyg-editor").summernote({
{
// Summernote workaround: Make images responsive
// By adding the "img-fluid" class to the img tag
$img = $('<img>').attr({ src: url, class: "img-fluid" })
$img = $('<img>').attr({ src: url, class: "img-fluid", loading: "lazy" })
$(this).summernote("insertNode", $img[0]);
}
}
});
// Summernote workaround: Make embeds responsive
// By wrapping any embeded video in a container with class "embed-responsive"
$(".note-video-clip").each(function()
{
$(this).parent().html('<div class="embed-responsive embed-responsive-16by9">' + $(this).wrap("<p/>").parent().html() + "</div>");
});

View File

@ -159,7 +159,6 @@ Grocy.Components.UserfieldsForm.Load = function()
formGroup.find('.userfield-file-show').removeClass('d-none');
formGroup.find('img.userfield-current-file')
.attr('src', U('/files/userfiles/' + value + '?force_serve_as=picture&best_fit_width=250&best_fit_height=250'));
LoadImagesLazy();
formGroup.find('.userfield-file-delete').click(
function()
@ -240,7 +239,6 @@ Grocy.Components.UserfieldsForm.Clear = function()
formGroup.find('.userfield-file-show').removeClass('d-none');
formGroup.find('img.userfield-current-file')
.attr('src', U('/files/userfiles/' + value + '?force_serve_as=picture&best_fit_width=250&best_fit_height=250'));
LoadImagesLazy();
formGroup.find('.userfield-file-delete').click(
function()

View File

@ -208,7 +208,7 @@ $(".calendar").each(function()
if (recipe.picture_file_name)
{
element.prepend('<div class="mx-auto mb-1"><img data-src="' + U("/api/files/recipepictures/") + btoa(recipe.picture_file_name) + '?force_serve_as=picture&best_fit_width=400" class="img-fluid rounded-circle lazy"></div>')
element.prepend('<div class="mx-auto mb-1"><img src="' + U("/api/files/recipepictures/") + btoa(recipe.picture_file_name) + '?force_serve_as=picture&best_fit_width=400" class="img-fluid rounded-circle" loading="lazy"></div>')
}
}
else if (event.type == "product")
@ -279,7 +279,7 @@ $(".calendar").each(function()
if (productDetails.product.picture_file_name)
{
element.prepend('<div class="mx-auto mb-1"><img data-src="' + U("/api/files/productpictures/") + btoa(productDetails.product.picture_file_name) + '?force_serve_as=picture&best_fit_width=400" class="img-fluid rounded-circle lazy"></div>')
element.prepend('<div class="mx-auto mb-1"><img src="' + U("/api/files/productpictures/") + btoa(productDetails.product.picture_file_name) + '?force_serve_as=picture&best_fit_width=400" class="img-fluid rounded-circle" loading="lazy"></div>')
}
}
else if (event.type == "note")
@ -352,7 +352,6 @@ $(".calendar").each(function()
});
RefreshLocaleNumberDisplay();
LoadImagesLazy();
$('[data-toggle="tooltip"]').tooltip();
if (!Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK)
@ -929,7 +928,7 @@ $(document).on("click", ".display-recipe-button", function(e)
function(result)
{
bootbox.dialog({
message: '<iframe height="650px" class="embed-responsive" src="' + U("/recipes?embedded&recipe=") + objectId + '#fullscreen"></iframe>',
message: '<iframe height="650px" class="embed-responsive" src="' + U("/recipes?embedded&recipe=") + objectId + '#fullscreen" loading="lazy"></iframe>',
size: 'extra-large',
backdrop: true,
closeButton: false,

View File

@ -10,7 +10,6 @@
});
$('#products-table tbody').removeClass("d-none");
productsTable.columns.adjust().draw();
LoadImagesLazy();
$("#search").on("keyup", Delay(function()
{

View File

@ -198,7 +198,7 @@ $("#test-quantityunit-plural-forms-button").on("click", function(e)
$("#save-quantityunit-button").click();
bootbox.alert({
message: '<iframe height="400px" class="embed-responsive" src="' + U("/quantityunitpluraltesting?embedded&qu=") + Grocy.EditObjectId.toString() + '"></iframe>',
message: '<iframe height="400px" class="embed-responsive" src="' + U("/quantityunitpluraltesting?embedded&qu=") + Grocy.EditObjectId.toString() + '" loading="lazy"></iframe>',
closeButton: false,
size: "large",
callback: function(result)

View File

@ -220,7 +220,7 @@ $(document).on('click', '.recipe-pos-edit-button', function(e)
var recipePosId = $(e.currentTarget).attr('data-recipe-pos-id');
bootbox.dialog({
message: '<iframe height="650px" class="embed-responsive" src="' + U("/recipe/") + Grocy.EditObjectId.toString() + '/pos/' + recipePosId.toString() + '?embedded&product=' + productId.toString() + '"></iframe>',
message: '<iframe height="650px" class="embed-responsive" src="' + U("/recipe/") + Grocy.EditObjectId.toString() + '/pos/' + recipePosId.toString() + '?embedded&product=' + productId.toString() + '" loading="lazy"></iframe>',
size: 'large',
backdrop: true,
closeButton: false,
@ -266,7 +266,7 @@ $("#recipe-pos-add-button").on("click", function(e)
e.preventDefault();
bootbox.dialog({
message: '<iframe height="650px" class="embed-responsive" src="' + U("/recipe/") + Grocy.EditObjectId + '/pos/new?embedded"></iframe>',
message: '<iframe height="650px" class="embed-responsive" src="' + U("/recipe/") + Grocy.EditObjectId + '/pos/new?embedded" loading="lazy"></iframe>',
size: 'large',
backdrop: true,
closeButton: false,

View File

@ -63,7 +63,6 @@ $("a[data-toggle='tab']").on("shown.bs.tab", function(e)
{
var tabId = $(e.target).attr("id");
window.localStorage.setItem("recipes_last_tab_id", tabId);
LoadImagesLazy();
});
$("#search").on("keyup", Delay(function()
@ -293,7 +292,7 @@ recipesTables.on('select', function(e, dt, type, indexes)
else
{
bootbox.dialog({
message: '<iframe height="650px" class="embed-responsive" src="' + U("/recipes?embedded&recipe=") + selectedRecipeId + '#fullscreen"></iframe>',
message: '<iframe height="650px" class="embed-responsive" src="' + U("/recipes?embedded&recipe=") + selectedRecipeId + '#fullscreen" loading="lazy"></iframe>',
size: 'extra-large',
backdrop: true,
closeButton: false,
@ -325,7 +324,7 @@ $(".recipe-gallery-item").on("click", function(e)
else
{
bootbox.dialog({
message: '<iframe height="650px" class="embed-responsive" src="' + U("/recipes?embedded&recipe=") + selectedRecipeId + '#fullscreen"></iframe>',
message: '<iframe height="650px" class="embed-responsive" src="' + U("/recipes?embedded&recipe=") + selectedRecipeId + '#fullscreen" loading="lazy"></iframe>',
size: 'extra-large',
backdrop: true,
closeButton: false,
@ -419,8 +418,6 @@ if (window.location.hash === "#fullscreen")
$("#selectedRecipeToggleFullscreenButton").click();
}
LoadImagesLazy();
$(document).on('click', '.recipe-grocycode-label-print', function(e)
{
e.preventDefault();

View File

@ -35,7 +35,6 @@ var stockOverviewTable = $('#stock-overview-table').DataTable({
$('#stock-overview-table tbody').removeClass("d-none");
stockOverviewTable.columns.adjust().draw();
LoadImagesLazy();
$("#location-filter").on("change", function()
{

View File

@ -108,7 +108,8 @@
<p>
@if($mode == 'edit')
<img src="{{ $U('/battery/' . $battery->id . '/grocycode?size=60') }}"
class="float-lg-left">
class="float-lg-left"
loading="lazy">
@endif
</p>
<p>

View File

@ -323,7 +323,8 @@
<p>
@if($mode == 'edit')
<img src="{{ $U('/chore/' . $chore->id . '/grocycode?size=60') }}"
class="float-lg-left">
class="float-lg-left"
loading="lazy">
@endif
</p>
<p>

View File

@ -79,9 +79,12 @@
@if(GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING)<strong>{{ $__t('Average shelf life') }}:</strong> <span id="productcard-product-average-shelf-life"></span><br>@endif
<strong>{{ $__t('Spoil rate') }}:</strong> <span id="productcard-product-spoil-rate"></span>
<p class="w-75 mt-3 mx-auto"><img id="productcard-product-picture"
data-src=""
class="img-fluid img-thumbnail d-none lazy"></p>
<p class="w-75 mt-3 mx-auto">
<img id="productcard-product-picture"
class="img-fluid img-thumbnail d-none"
src=""
loading="lazy">
</p>
@if(GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING)
<h5 class="mt-3">{{ $__t('Price history') }}</h5>

View File

@ -44,9 +44,9 @@ $excludeFieldTypes = [];
<a class="show-as-dialog-link"
href="{{ $U('/files/userfiles/'. $userfieldObject->value . '?force_serve_as=picture') }}">
<img src="{{ $U('/files/userfiles/'. $userfieldObject->value . '?force_serve_as=picture&best_fit_width=32&best_fit_height=32') }}"
class="lazy"
title="{{ base64_decode(explode('_', $userfieldObject->value)[1]) }}"
alt="{{ base64_decode(explode('_', $userfieldObject->value)[1]) }}">
alt="{{ base64_decode(explode('_', $userfieldObject->value)[1]) }}"
loading="lazy">
</a>
@else
{{ $userfieldObject->value }}

View File

@ -203,8 +203,8 @@
</div>
<img src=""
alt="{{ $userfield->name }}"
class="userfield-current-file userfield-file-show d-none lazy mt-1 discrete-link"
data-uf-name="{{ $userfield->name }}" />
class="userfield-current-file userfield-file-show d-none mt-1 discrete-link"
loading="lazy" />
</div>
@endif

View File

@ -466,7 +466,8 @@
<i class="fa-solid fa-user"></i>
@else
<img class="rounded-circle"
src="{{ $U('/files/userpictures/' . base64_encode(GROCY_USER_PICTURE_FILE_NAME) . '_' . base64_encode(GROCY_USER_PICTURE_FILE_NAME) . '?force_serve_as=picture&best_fit_width=32&best_fit_height=32') }}">
src="{{ $U('/files/userpictures/' . base64_encode(GROCY_USER_PICTURE_FILE_NAME) . '_' . base64_encode(GROCY_USER_PICTURE_FILE_NAME) . '?force_serve_as=picture&best_fit_width=32&best_fit_height=32') }}"
loading="lazy">
@endif
{{ GROCY_USER_USERNAME }}
</a>
@ -666,9 +667,8 @@
<a class="dropdown-item discrete-link"
href="{{ $U('/barcodescannertesting') }}"><i class="fa-solid fa-barcode"></i>&nbsp;{{ $__t('Barcode scanner testing') }}</a>
<div class="dropdown-divider"></div>
<a id="about-dialog-link"
class="dropdown-item discrete-link"
href="#"><i class="fa-solid fa-info fa-fw"></i>&nbsp;{{ $__t('About Grocy') }}</a>
<a class="dropdown-item discrete-link show-as-dialog-link"
href="{{ $U('/about?embedded') }}"><i class="fa-solid fa-info fa-fw"></i>&nbsp;{{ $__t('About Grocy') }}</a>
</div>
</li>
</ul>
@ -696,7 +696,6 @@
<script src="{{ $U('/node_modules/toastr/build/toastr.min.js?v=', true) }}{{ $version }}"></script>
<script src="{{ $U('/node_modules/sprintf-js/dist/sprintf.min.js?v=', true) }}{{ $version }}"></script>
<script src="{{ $U('/node_modules/gettext-translator/dist/translator.js?v=', true) }}{{ $version }}"></script>
<script src="{{ $U('/node_modules/jquery-lazy/jquery.lazy.min.js?v=', true) }}{{ $version }}"></script>
<script src="{{ $U('/node_modules/nosleep.js/dist/NoSleep.min.js?v=', true) }}{{ $version }}"></script>
@if(in_array('bootstrap-combobox', $GROCY_REQUIRED_FRONTEND_PACKAGES))

View File

@ -738,7 +738,8 @@
<p>
@if($mode == 'edit')
<img src="{{ $U('/product/' . $product->id . '/grocycode?size=60') }}"
class="float-lg-left">
class="float-lg-left"
loading="lazy">
@endif
</p>
<p>
@ -869,8 +870,9 @@
</div>
@if($mode == "edit" && !empty($product->picture_file_name))
<img id="current-product-picture"
data-src="{{ $U('/api/files/productpictures/' . base64_encode($product->picture_file_name) . '?force_serve_as=picture&best_fit_width=400') }}"
class="img-fluid img-thumbnail mt-2 lazy mb-5">
src="{{ $U('/api/files/productpictures/' . base64_encode($product->picture_file_name) . '?force_serve_as=picture&best_fit_width=400') }}"
class="img-fluid img-thumbnail mt-2 mb-5"
loading="lazy">
<p id="delete-current-product-picture-on-save-hint"
class="form-text text-muted font-italic d-none mb-5">{{ $__t('The current picture will be deleted on save') }}</p>
@else

View File

@ -212,8 +212,8 @@
@endif
</td>
<td>
<img data-src="{{ $U('/product/' . $product->id . '/grocycode?size=25') }}"
class="lazy">
<img src="{{ $U('/product/' . $product->id . '/grocycode?size=25') }}"
loading="lazy">
</td>
@include('components.userfields_tbody', array(

View File

@ -326,8 +326,9 @@
</div>
@if(!empty($recipe->picture_file_name))
<img id="current-recipe-picture"
data-src="{{ $U('/api/files/recipepictures/' . base64_encode($recipe->picture_file_name) . '?force_serve_as=picture&best_fit_width=400') }}"
class="img-fluid img-thumbnail mt-2 lazy mb-5">
src="{{ $U('/api/files/recipepictures/' . base64_encode($recipe->picture_file_name) . '?force_serve_as=picture&best_fit_width=400') }}"
class="img-fluid img-thumbnail mt-2 mb-5"
loading="lazy">
<p id="delete-current-recipe-picture-on-save-hint"
class="form-text text-muted font-italic d-none mb-5">{{ $__t('The current picture will be deleted on save') }}</p>
@else
@ -350,7 +351,8 @@
<p>
@if($mode == 'edit')
<img src="{{ $U('/recipe/' . $recipe->id . '/grocycode?size=60') }}"
class="float-lg-left">
class="float-lg-left"
loading="lazy">
@endif
</p>
<p>

View File

@ -257,8 +257,9 @@
<div id="RecipeGalleryCard-{{ $recipe->id }}"
class="card recipe-card">
@if(!empty($recipe->picture_file_name))
<img data-src="{{ $U('/api/files/recipepictures/' . base64_encode($recipe->picture_file_name) . '?force_serve_as=picture&best_fit_width=400') }}"
class="card-img-top lazy">
<img src="{{ $U('/api/files/recipepictures/' . base64_encode($recipe->picture_file_name) . '?force_serve_as=picture&best_fit_width=400') }}"
class="card-img-top"
loading="lazy">
@endif
<div class="card-body text-center">
<h5 class="card-title mb-1">{{ $recipe->name }}</h5>
@ -323,8 +324,9 @@
id="recipe-{{ $index + 1 }}"
role="tabpanel">
@if(!empty($recipe->picture_file_name))
<img class="card-img-top lazy"
src="{{ $U('/api/files/recipepictures/' . base64_encode($recipe->picture_file_name) . '?force_serve_as=picture') }}">
<img class="card-img-top"
src="{{ $U('/api/files/recipepictures/' . base64_encode($recipe->picture_file_name) . '?force_serve_as=picture') }}"
loading="lazy">
@endif
<div class="card-body">
<div class="shadow p-4 mb-5 bg-white rounded mt-n5 d-print-none @if(empty($recipe->picture_file_name)) d-none @endif">

View File

@ -322,7 +322,8 @@
<div class="modal-body">
<iframe id="shopping-list-stock-add-workflow-purchase-form-frame"
class="embed-responsive"
src=""></iframe>
src=""
loading="lazy"></iframe>
</div>
<div class="modal-footer">
<span id="shopping-list-stock-add-workflow-purchase-item-count"

View File

@ -436,8 +436,8 @@
</td>
<td>
@if(!empty($currentStockEntry->product_picture_file_name))
<img data-src="{{ $U('/api/files/productpictures/' . base64_encode($currentStockEntry->product_picture_file_name) . '?force_serve_as=picture&best_fit_width=64&best_fit_height=64') }}"
class="lazy">
<img src="{{ $U('/api/files/productpictures/' . base64_encode($currentStockEntry->product_picture_file_name) . '?force_serve_as=picture&best_fit_width=64&best_fit_height=64') }}"
loading="lazy">
@endif
</td>
<td class="@if(!GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING) d-none @endif">

View File

@ -159,8 +159,9 @@
</div>
@if(!empty($user->picture_file_name))
<img id="current-user-picture"
data-src="{{ $U('/api/files/userpictures/' . base64_encode($user->picture_file_name) . '?force_serve_as=picture&best_fit_width=400') }}"
class="img-fluid img-thumbnail mt-2 lazy mb-5">
src="{{ $U('/api/files/userpictures/' . base64_encode($user->picture_file_name) . '?force_serve_as=picture&best_fit_width=400') }}"
class="img-fluid img-thumbnail mt-2 mb-5"
loading="lazy">
<p id="delete-current-user-picture-on-save-hint"
class="form-text text-muted font-italic d-none mb-5">{{ $__t('The current picture will be deleted on save') }}</p>
@else

View File

@ -1156,19 +1156,12 @@ jpeg-js@^0.4.1:
resolved "https://registry.yarnpkg.com/jpeg-js/-/jpeg-js-0.4.4.tgz#a9f1c6f1f9f0fa80cdb3484ed9635054d28936aa"
integrity sha512-WZzeDOEtTOBK4Mdsar0IqEU5sMr3vSV2RqkAIzUEV2BHnUfKGyswWFPFwK5EeDo93K3FohSHbLAjj0s1Wzd+dg==
jquery-lazy@^1.7.11:
version "1.7.11"
resolved "https://registry.yarnpkg.com/jquery-lazy/-/jquery-lazy-1.7.11.tgz#f4146501ba64cad95cc5c20f184ac1b1d3712fe5"
integrity sha512-jNAOMwfgf+lYaOCc/atBVjbOzAIRW5BUyjQ4b4jJPkQM6I0zGZd4m/Y73ekfAlrQQDg3/Dge3YNhW7Cqjgi0UA==
dependencies:
jquery ">=1.7.2"
jquery-serializejson@^2.9.0:
version "2.9.0"
resolved "https://registry.yarnpkg.com/jquery-serializejson/-/jquery-serializejson-2.9.0.tgz#03e3764e3a4b42c1c5aae9f93d7f19320c5f35a6"
integrity sha512-xR7rjl0tRKIVioV5lOkOSv7K8BHMvGzYzC7Ech1iAYuZiYf0ksEpLC8OqjA5VApXf/qn/49O9hTmW70+/EA0vA==
jquery@>=1.10, jquery@>=1.12.0, jquery@>=1.7, jquery@>=1.7.2, jquery@^3.6.0:
jquery@>=1.10, jquery@>=1.12.0, jquery@>=1.7, jquery@^3.6.0:
version "3.7.0"
resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.7.0.tgz#fe2c01a05da500709006d8790fe21c8a39d75612"
integrity sha512-umpJ0/k8X0MvD1ds0P9SfowREz2LenHsQaxSohMZ5OMNEU2r0tf8pdeEFTHMFxWVxKNyU9rTtK3CWzUCTKJUeQ==