Skip to content

Commit

Permalink
added deferred/responsive images
Browse files Browse the repository at this point in the history
  • Loading branch information
Makreig committed Jul 9, 2019
1 parent 020ae5a commit a86f0fe
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 35 deletions.
34 changes: 33 additions & 1 deletion _config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,36 @@ SilverStripe\CMS\Model\SiteTree:
- ilateral\SilverStripe\Carousel\Extensions\CarouselPage
SilverStripe\Admin\LeftAndMain:
extra_requirements_javascript:
- 'i-lateral/silverstripe-carousel: client/dist/scripts/carouseladmin.js'
- 'i-lateral/silverstripe-carousel: client/dist/scripts/carouseladmin.js'
---
After: 'silverstripe-responsive-images/*'
---
Heyday\ResponsiveImages\ResponsiveImageExtension:
sets:
TallCarousel:
arguments:
'(min-width: 1200px) and (min-device-pixel-ratio: 2.0)': [3840, 2160] # xl
'(min-width: 1200px)': [1920, 1080]
'(min-width: 992px) and (min-device-pixel-ratio: 2.0)': [2400, 1536] # lg
'(min-width: 992px)': [1200, 768]
'(min-width: 768px) and (min-device-pixel-ratio: 2.0)': [1948, 1536] # md
'(min-width: 768px)': [992, 768]
default_arguments: [800, 700] # xs
ShortCarousel:
arguments:
'(min-width: 1200px) and (min-device-pixel-ratio: 2.0)': [3840, 1400] # xl
'(min-width: 1200px)': [1920, 700]
'(min-width: 992px) and (min-device-pixel-ratio: 2.0)': [2400, 1200] # lg
'(min-width: 992px)': [1200, 600]
'(min-width: 768px) and (min-device-pixel-ratio: 2.0)': [1948, 1100] # md
'(min-width: 768px)': [992, 550]
default_arguments: [800, 700] # xs
LetterboxCarousel:
arguments:
'(min-width: 1200px) and (min-device-pixel-ratio: 2.0)': [3840, 800] # xl
'(min-width: 1200px)': [1920, 400]
'(min-width: 992px) and (min-device-pixel-ratio: 2.0)': [2400, 800] # lg
'(min-width: 992px)': [1200, 400]
'(min-width: 768px) and (min-device-pixel-ratio: 2.0)': [1948, 1000] # md
'(min-width: 768px)': [992, 500]
default_arguments: [800, 700] # xs
6 changes: 5 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@

## 2.0.3

* Require stable focuspoint
* Require stable focuspoint

## 2.1.0

* Added defered/responsive images
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"require": {
"silverstripe/cms": "~4.0",
"symbiote/silverstripe-gridfieldextensions": "~3.1",
"jonom/focuspoint": "~3.0"
"jonom/focuspoint": "~3.0",
"i-lateral/silverstripe-deferedimages": "^1.1"
},
"autoload": {
"psr-4": {
Expand Down
38 changes: 21 additions & 17 deletions src/extensions/CarouselPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@

namespace ilateral\SilverStripe\Carousel\Extensions;

use SilverStripe\ORM\DataExtension;
use SilverStripe\Dev\Debug;
use SilverStripe\Assets\Image;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\FieldGroup;
use SilverStripe\ORM\DataExtension;
use SilverStripe\Core\Config\Config;
use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\NumericField;
use SilverStripe\Forms\FieldGroup;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Forms\GridField\GridField;
use Heyday\ResponsiveImages\ResponsiveImageExtension;
use ilateral\SilverStripe\Carousel\Model\CarouselSlide;
use SilverStripe\Forms\GridField\GridFieldAddNewButton;
use Symbiote\GridFieldExtensions\GridFieldOrderableRows;
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
use ilateral\SilverStripe\Carousel\Model\CarouselSlide;

/**
* Extension to all page objects that add carousel slide relationships
Expand All @@ -33,8 +39,7 @@ class CarouselPage extends DataExtension
'ShowCarousel' => 'Boolean',
"CarouselShowIndicators" => "Boolean",
"CarouselShowControls" => "Boolean",
'CarouselWidth' => 'Int',
'CarouselHeight'=> 'Int',
"CarouselProfile" => "Varchar",
"CarouselInterval" => "Int"
];

Expand All @@ -55,8 +60,7 @@ class CarouselPage extends DataExtension
* @config
*/
private static $defaults = [
'CarouselWidth' => 750,
'CarouselHeight' => 350,
'CarouselProfile' => 'ShortCarousel',
'CarouselInterval' => 3000,
];

Expand All @@ -77,8 +81,7 @@ public function updateCMSFields(FieldList $fields)
}

$fields->removeByName('ShowCarousel');
$fields->removeByName('CarouselWidth');
$fields->removeByName('CarouselHeight');
$fields->removeByName('CarouselProfile');

parent::updateCMSFields($fields);
}
Expand Down Expand Up @@ -113,17 +116,18 @@ public function updateSettingsFields(FieldList $fields)
);

if($this->owner->ShowCarousel) {
$array = [];
foreach (array_keys(Config::inst()->get(ResponsiveImageExtension::class, 'sets')) as $key => $value) {
$array[$value] = $value;
}
$fields->addFieldsToTab(
'Root.Settings',
[
NumericField::create(
'CarouselWidth',
$this->owner->fieldLabel('CarouselWidth')
),
NumericField::create(
'CarouselHeight',
$this->owner->fieldLabel('CarouselHeight')
),
DropdownField::create(
'CarouselProfile',
$this->owner->fieldLabel('CarouselProfile'),
$array
)->setEmptyString('Choose one'),
NumericField::create(
'CarouselInterval',
$this->owner->fieldLabel('CarouselInterval')
Expand Down
19 changes: 9 additions & 10 deletions src/model/CarouselSlide.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,17 @@ class CarouselSlide extends DataObject
*/
private static $default_sort = "Sort ASC";


public function getSizedImage()
/**
* Get fully rendered image for template
*
* @return HTMLText
*/
public function getRenderedImage()
{
$parent = $this->Parent();
$width = $parent->CarouselWidth;
$height = $parent->CarouselHeight;

if($width && $height) {
return $this->Image()->FocusFill($width, $height);
} else {
return false;
}
$profile = $parent->CarouselProfile;

return $this->Image->{$profile}();
}

public function getCMSFields()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@
<div class="carousel-inner">
<% loop $Slides %>
<div class="carousel-item <% if $First %>active<% end_if %>">
<img
class="d-block w-100"
src="$SizedImage.URL"
alt="$SizedImage.Title"
>
$RenderedImage
<% if Title %>
<div class="carousel-caption text-center d-none d-md-block slide-content">
<% if $Link.LinkURL %>
Expand Down

0 comments on commit a86f0fe

Please sign in to comment.