Commit 84faf2e6 authored by Tim Zallmann's avatar Tim Zallmann

Updates to cropper css loading

Fixed Data Property Name
Added safe guard to css check
Added Changelog
parent cfeeecb5
export function loadCSSFile(path) { export function loadCSSFile(path) {
return new Promise(resolve => { return new Promise(resolve => {
const linkElement = document.createElement('link'); if (document.querySelector(`link[href="${path}"]`)) {
linkElement.type = 'text/css';
linkElement.rel = 'stylesheet';
// eslint-disable-next-line @gitlab/require-i18n-strings
linkElement.media = 'screen,print';
linkElement.onload = () => {
resolve(); resolve();
}; } else {
linkElement.href = path; const linkElement = document.createElement('link');
linkElement.type = 'text/css';
linkElement.rel = 'stylesheet';
// eslint-disable-next-line @gitlab/require-i18n-strings
linkElement.media = 'screen,print';
linkElement.onload = () => {
resolve();
};
linkElement.href = path;
document.head.appendChild(linkElement); document.head.appendChild(linkElement);
}
}); });
} }
...@@ -181,8 +181,8 @@ import { loadCSSFile } from '../lib/utils/css_utils'; ...@@ -181,8 +181,8 @@ import { loadCSSFile } from '../lib/utils/css_utils';
} }
} }
if (document.querySelector('.modal-profile-crop')) const cropModal = document.querySelector('.modal-profile-crop');
loadCSSFile(document.querySelector('.modal-profile-crop').dataset.croppercsspath); if (cropModal) loadCSSFile(cropModal.dataset.cropperCssPath);
$.fn.glCrop = function(opts) { $.fn.glCrop = function(opts) {
return this.each(function() { return this.each(function() {
......
...@@ -122,7 +122,7 @@ ...@@ -122,7 +122,7 @@
= f.submit s_("Profiles|Update profile settings"), class: 'btn btn-success' = f.submit s_("Profiles|Update profile settings"), class: 'btn btn-success'
= link_to _("Cancel"), user_path(current_user), class: 'btn btn-cancel' = link_to _("Cancel"), user_path(current_user), class: 'btn btn-cancel'
.modal.modal-profile-crop{ data: { croppercsspath: ActionController::Base.helpers.stylesheet_path('lazy_bundles/cropper.css') } } .modal.modal-profile-crop{ data: { cropper_css_path: ActionController::Base.helpers.stylesheet_path('lazy_bundles/cropper.css') } }
.modal-dialog .modal-dialog
.modal-content .modal-content
.modal-header .modal-header
......
---
title: Loads cropper css only when needed
merge_request: 44137
author:
type: performance
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment