Skip to content

Commit

Permalink
Add option for small images gthomas2#46
Browse files Browse the repository at this point in the history
  • Loading branch information
TomoTsuyuki committed Jul 22, 2022
1 parent cfed6a9 commit d6d322c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,13 @@ private function process_img_tag(array $match) {

$imageinfo = (object) $file->get_imageinfo();
if ($imageinfo->width <= $maxwidth && !local::file_is_public($file->get_contenthash())) {
return $match[0];
if (empty($this->config->lovsmallimage) || $this->config->loadonvisible == 999) {
return $match[0];
} else {
// Apply load on visible.
$url = new \moodle_url($CFG->wwwroot . '/' . $match[3]);
return $this->apply_loadonvisible($match, $file, $url, $url);
}
}

$optimisedpath = local::get_optimised_path($file, $match[3]);
Expand Down
2 changes: 2 additions & 0 deletions lang/en/filter_imageopt.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
$string['donotloadonvisible'] = 'No placeholding, load immediately';
$string['loadonvisibilityall'] = 'All images';
$string['loadonvisibilityafter'] = 'After {$a} image(s)';
$string['lovsmallimage'] = 'Load when visible for small images';
$string['lovsmallimagedesc'] = 'Apply "Load when visible" for images which are smaller than "Maximum image width"';
$string['widthattribute'] = 'Image width attribute';
$string['widthattributedesc'] = 'How should existing image width attributes be dealt with';
$string['widthattpreserve'] = 'Preserve user width attributes in all cases';
Expand Down
7 changes: 7 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@
$settings->add(new admin_setting_configselect('filter_imageopt/loadonvisible', get_string('loadonvisible', 'filter_imageopt'),
get_string('loadonvisibledesc', 'filter_imageopt'), 5, $choices));

$settings->add(new admin_setting_configcheckbox(
'filter_imageopt/lovsmallimage',
get_string('lovsmallimage', 'filter_imageopt'),
get_string('lovsmallimagedesc', 'filter_imageopt'),
0
));

$choices = [
local::WIDTH_ATT_PRESERVE_MAX => get_string('widthattpreserveltmax', 'filter_imageopt'),
local::WIDTH_ATT_PRESERVE => get_string('widthattpreserve', 'filter_imageopt')
Expand Down

0 comments on commit d6d322c

Please sign in to comment.