Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.0] Pluginless lazyloading for the core #30748

Merged
merged 20 commits into from
Sep 27, 2020
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ tinymce.PluginManager.add('jdragndrop', (editor) => {
urlPath = response.data.thumb_path;
}

tinyMCE.activeEditor.execCommand('mceInsertContent', false, `<img loading="lazy" src="${urlPath}" alt=""/>`);
tinyMCE.activeEditor.execCommand('mceInsertContent', false, `<img loading="lazy" src="${urlPath}" width="${response.data.width}" height="${response.data.height}" alt=""/>`);
}
},
onError: (xhr) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@

if (Joomla.selectedFile.url) {
if (!isElement(editor) && (typeof editor !== 'object')) {
Joomla.editors.instances[editor].replaceSelection(`<img loading="lazy" src="${Joomla.selectedFile.url}" alt=""/>`);
Joomla.editors.instances[editor].replaceSelection(`<img loading="lazy" src="${Joomla.selectedFile.url}" width="${Joomla.selectedFile.width}px" height="${Joomla.selectedFile.height}px" alt="" />`);
} else if (!isElement(editor) && (typeof editor === 'object' && editor.id)) {
window.parent.Joomla.editors.instances[editor.id].replaceSelection(`<img loading="lazy" src="${Joomla.selectedFile.url}" alt=""/>`);
window.parent.Joomla.editors.instances[editor.id].replaceSelection(`<img loading="lazy" src="${Joomla.selectedFile.url}" width="${Joomla.selectedFile.width}px" height="${Joomla.selectedFile.height}px" alt="" />`);
} else {
editor.value = Joomla.selectedFile.url;
editor.value = `${Joomla.selectedFile.url}?width=${Joomla.selectedFile.width}&height=${Joomla.selectedFile.height}`;
fieldClass.updatePreview();
}
}
Expand Down Expand Up @@ -68,7 +68,7 @@
const apiBaseUrl = `${Joomla.getOptions('system.paths').baseFull}index.php?option=com_media&format=json`;

Joomla.request({
url: `${apiBaseUrl}&task=api.files&url=true&path=${data.path}&${Joomla.getOptions('csrf.token')}=1&format=json`,
url: `${apiBaseUrl}&task=api.files&url=true&path=${data.path}&${Joomla.getOptions('csrf.token')}=1`,
zero-24 marked this conversation as resolved.
Show resolved Hide resolved
method: 'GET',
perform: true,
headers: { 'Content-Type': 'application/json' },
Expand Down
1 change: 0 additions & 1 deletion installation/sql/mysql/base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,6 @@ INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`,
(0, 'plg_workflow_publishing', 'plugin', 'publishing', 'workflow', 0, 1, 1, 0, 1, '', '{}', '', 0, 0),
(0, 'plg_workflow_featuring', 'plugin', 'featuring', 'workflow', 0, 1, 1, 0, 1, '', '{}', '', 0, 0),
(0, 'plg_workflow_notification', 'plugin', 'notification', 'workflow', 0, 1, 1, 0, 1, '', '{}', '', 0, 0),
zero-24 marked this conversation as resolved.
Show resolved Hide resolved
(0, 'plg_content_imagelazyload', 'plugin', 'imagelazyload', 'content', 0, 0, 1, 0, 1, '', '{}', '', 0, 0);

-- Templates
INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `locked`, `manifest_cache`, `params`, `custom_data`, `ordering`, `state`) VALUES
Expand Down
1 change: 0 additions & 1 deletion installation/sql/postgresql/base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,6 @@ INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder",
(0, 'plg_workflow_publishing', 'plugin', 'publishing', 'workflow', 0, 1, 1, 0, 1, '', '{}', '', 0, 0),
(0, 'plg_workflow_featuring', 'plugin', 'featuring', 'workflow', 0, 1, 1, 0, 1, '', '{}', '', 0, 0),
(0, 'plg_workflow_notification', 'plugin', 'notification', 'workflow', 0, 1, 1, 0, 1, '', '{}', '', 0, 0),
zero-24 marked this conversation as resolved.
Show resolved Hide resolved
(0, 'plg_content_imagelazyload', 'plugin', 'imagelazyload', 'content', 0, 0, 1, 0, 1, '', '{}', '', 0, 0);

-- Templates
INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder", "client_id", "enabled", "access", "protected", "locked", "manifest_cache", "params", "custom_data", "ordering", "state") VALUES
Expand Down
1 change: 0 additions & 1 deletion libraries/src/Extension/ExtensionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ class ExtensionHelper
array('plugin', 'emailcloak', 'content', 0),
array('plugin', 'fields', 'content', 0),
array('plugin', 'finder', 'content', 0),
array('plugin', 'imagelazyload', 'content', 0),
array('plugin', 'joomla', 'content', 0),
array('plugin', 'loadmodule', 'content', 0),
array('plugin', 'pagebreak', 'content', 0),
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/HTML/HTMLHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ public static function image($file, $alt, $attribs = null, $relative = false, $r
}

// Default to lazy you can disable lazyloading by passing $attribs['loading'] = 'eager';
if (!isset($attribs['loading']))
if (is_array($attribs) && !isset($attribs['loading']))
zero-24 marked this conversation as resolved.
Show resolved Hide resolved
{
$attribs['loading'] = 'lazy';
}
Expand Down
56 changes: 0 additions & 56 deletions plugins/content/imagelazyload/imagelazyload.php

This file was deleted.

18 changes: 0 additions & 18 deletions plugins/content/imagelazyload/imagelazyload.xml

This file was deleted.

20 changes: 16 additions & 4 deletions plugins/fields/imagelist/tmpl/imagelist.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*/
defined('_JEXEC') or die;

use Joomla\CMS\Image\Image;

if ($field->value == '')
{
return;
Expand All @@ -31,18 +33,28 @@
continue;
}

$imageFilePath = htmlentities($path, ENT_COMPAT, 'UTF-8', true);

if ($fieldParams->get('directory', '/') !== '/')
{
$buffer .= sprintf('<img loading="lazy" src="images/%s/%s"%s>',
$imageInfo = Image::getImageFileProperties('images/' . $fieldParams->get('directory') . '/' . $imageFilePath);

$buffer .= sprintf('<img loading="lazy" width="%s" height="%s" src="images/%s/%s"%s>',
$imageInfo->width,
$imageInfo->height,
$fieldParams->get('directory'),
htmlentities($path, ENT_COMPAT, 'UTF-8', true),
$imageFilePath,
$class
);
}
else
{
$buffer .= sprintf('<img loading="lazy" src="images/%s"%s>',
htmlentities($path, ENT_COMPAT, 'UTF-8', true),
$imageInfo = Image::getImageFileProperties('images/' . $imageFilePath);

$buffer .= sprintf('<img loading="lazy" width="%s" height="%s" src="images/%s"%s>',
$imageInfo->width,
$imageInfo->height,
$imageFilePath,
$class
);
}
Expand Down
16 changes: 11 additions & 5 deletions plugins/fields/media/tmpl/media.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*/
defined('_JEXEC') or die;

use Joomla\CMS\Image\Image;

if ($field->value == '')
{
return;
Expand All @@ -26,13 +28,17 @@

if ($value)
{
$path = $value['imagefile'];
$alt = ' alt="' . htmlentities($value['alt_text'], ENT_COMPAT, 'UTF-8', true) . '"';
$alt = ' alt="' . htmlentities($value['alt_text'], ENT_COMPAT, 'UTF-8', true) . '"';
$imagePath = htmlentities($value['imagefile'], ENT_COMPAT, 'UTF-8', true);

if (file_exists($path))
if (file_exists($imagePath))
{
$buffer .= sprintf('<img loading="lazy" src="%s"%s%s>',
htmlentities($path, ENT_COMPAT, 'UTF-8', true),
$imageInfo = Image::getImageFileProperties($imagePath);

$buffer .= sprintf('<img loading="lazy" width="%s" height="%s" src="%s"%s%s>',
$imageInfo->width,
$imageInfo->height,
$imagePath,
$class,
$alt
);
Expand Down