Move image loading() method into trait

This commit is contained in:
Matias Griese
2020-05-28 15:21:03 +03:00
parent 6876e1a38a
commit 9565994e5c
2 changed files with 18 additions and 114 deletions

View File

@@ -280,6 +280,24 @@ trait ImageMediaTrait
return $this;
}
/**
* Allows to set the loading attribute from Markdown or Twig
*
* @param string|null $value
* @return $this
*/
public function loading($value = null)
{
if (is_null($value)) {
$value = Grav::instance()['config']->get('images.defaults.loading', 'auto');
}
if ($value && $value !== 'auto') {
$this->attributes['loading'] = $value;
}
return $this;
}
/**
* Filter image by using user defined filter parameters.
*

View File

@@ -247,120 +247,6 @@ class ImageMedium extends Medium implements ImageMediaInterface, ImageManipulate
return parent::lightbox($width, $height, $reset);
}
/**
* Sets or gets the quality of the image
*
* @param int $quality 0-100 quality
* @return int|$this
*/
public function quality($quality = null)
{
if ($quality) {
if (!$this->image) {
$this->image();
}
$this->quality = $quality;
return $this;
}
return $this->quality;
}
/**
* Sets image output format.
*
* @param string $format
* @return $this
*/
public function format($format)
{
if (!$this->image) {
$this->image();
}
$this->format = $format;
return $this;
}
/**
* Set or get sizes parameter for srcset media action
*
* @param string $sizes
* @return string
*/
public function sizes($sizes = null)
{
if ($sizes) {
$this->sizes = $sizes;
return $this;
}
return empty($this->sizes) ? '100vw' : $this->sizes;
}
/**
* Allows to set the width attribute from Markdown or Twig
* Examples: ![Example](myimg.png?width=200&height=400)
* ![Example](myimg.png?resize=100,200&width=100&height=200)
* ![Example](myimg.png?width=auto&height=auto)
* ![Example](myimg.png?width&height)
* {{ page.media['myimg.png'].width().height().html }}
* {{ page.media['myimg.png'].resize(100,200).width(100).height(200).html }}
*
* @param mixed $value A value or 'auto' or empty to use the width of the image
* @return $this
*/
public function width($value = 'auto')
{
if (!$value || $value === 'auto') {
$this->attributes['width'] = $this->get('width');
} else {
$this->attributes['width'] = $value;
}
return $this;
}
/**
* Allows to set the height attribute from Markdown or Twig
* Examples: ![Example](myimg.png?width=200&height=400)
* ![Example](myimg.png?resize=100,200&width=100&height=200)
* ![Example](myimg.png?width=auto&height=auto)
* ![Example](myimg.png?width&height)
* {{ page.media['myimg.png'].width().height().html }}
* {{ page.media['myimg.png'].resize(100,200).width(100).height(200).html }}
*
* @param mixed $value A value or 'auto' or empty to use the height of the image
* @return $this
*/
public function height($value = 'auto')
{
if (!$value || $value === 'auto') {
$this->attributes['height'] = $this->get('height');
} else {
$this->attributes['height'] = $value;
}
return $this;
}
public function loading($value = null)
{
if (is_null($value)) {
$value = Grav::instance()['config']->get('images.defaults.loading', 'auto');
}
if ($value && $value !== 'auto') {
$this->attributes['loading'] = $value;
}
return $this;
}
/**
* Forward the call to the image processing method.
*