Various JS optimizations

This commit is contained in:
Bernd Bestel
2023-05-21 18:01:47 +02:00
parent 825321593b
commit 979c67b44c
25 changed files with 64 additions and 87 deletions

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()
{