Skip to content

Commit

Permalink
Remove lazyload functionality from SizedImage
Browse files Browse the repository at this point in the history
  • Loading branch information
gmlnchv committed Apr 18, 2019
1 parent 9be6d9e commit a8ae436
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 70 deletions.
107 changes: 47 additions & 60 deletions src/models/SizedImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,64 +7,51 @@

class SizedImage extends DataObject
{
private static $table_name = 'SizedImage';

private static $db = [
'Name' => 'Varchar(255)',
'Size' => 'Varchar(100)',
'Rule' => 'Varchar(100)'
];

private static $has_one = [
'Image' => Image::class
];

private static $owns = [
'Image'
];

private static $summary_fields = [
'ID' => 'ID',
'Size' => 'Size',
'Image.CMSThumbnail' => 'Thumbnail'
];

public function getCMSFields()
{
$fields = parent::getCMSFields();

$name = $fields->dataFieldByName('Name');
$name->setDescription('For reference only');

return $fields;
}

/**
* This object should exists only if it has an image
*/
public function exists()
{
return $this->Image() && $this->Image()->exists();
}

/**
* Proxy method to be able to render the lazyloaded template
* @see DNADesign\Images\Extensions\LazyloadedImage
*/
public function getLazyloaded()
{
if ($this->Image()->exists() && $this->Image()->hasMethod('getLazyloaded')) {
return $this->Image()->getLazyloaded();
}

return $this->Image();
}

/**
* Render normal image by default
*/
public function forTemplate()
{
return ($this->Image()->exists()) ? $this->Image()->fortemplate() : '';
}
private static $table_name = 'SizedImage';

private static $db = [
'Name' => 'Varchar(255)',
'Size' => 'Varchar(100)',
'Rule' => 'Varchar(100)'
];

private static $has_one = [
'Image' => Image::class
];

private static $owns = [
'Image'
];

private static $summary_fields = [
'ID' => 'ID',
'Size' => 'Size',
'Image.CMSThumbnail' => 'Thumbnail'
];

public function getCMSFields()
{
$fields = parent::getCMSFields();

$name = $fields->dataFieldByName('Name');
$name->setDescription('For reference only');

return $fields;
}

/**
* This object should exists only if it has an image
*/
public function exists()
{
return $this->Image() && $this->Image()->exists();
}

/**
* Render normal image by default
*/
public function forTemplate()
{
return ($this->Image()->exists()) ? $this->Image()->fortemplate() : '';
}
}
11 changes: 1 addition & 10 deletions src/templates/DNADesign/Images/Models/MultipleSizeImage.ss
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
<% if $Lazyload %>
<picture>
<% loop $Sources %>
<source media="($Rule)" data-srcset="$Image.URL">
<% end_loop %>
$BaseImage.Lazyloaded
</picture>
<% else %>
<picture>
<% loop $Sources %>
<source media="($Rule)" srcset="$Image.URL">
<% end_loop %>
$BaseImage
{$BaseImage}
</picture>
<% end_if %>

0 comments on commit a8ae436

Please sign in to comment.