Skip to content

Commit

Permalink
Merge pull request #596 from wintercms/wip/1.2-fix-mediamanger-thumbn…
Browse files Browse the repository at this point in the history
…ail-view

[WIP] 1.2 - Fix MediaManger Thumbnail View
  • Loading branch information
LukeTowers authored Jul 6, 2022
2 parents c0119a0 + b29d1b9 commit c9a72b8
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 317 deletions.
407 changes: 133 additions & 274 deletions modules/backend/widgets/MediaManager.php

Large diffs are not rendered by default.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,7 @@ MediaManagerImageCropPopup.prototype.updateSelectionSizeLabel=function(width,hei
return}this.selectionSizeLabel.setAttribute('class','')
this.selectionSizeLabel.querySelector('[data-label=selection-width]').textContent=parseInt(width)
this.selectionSizeLabel.querySelector('[data-label=selection-height]').textContent=parseInt(height)}
MediaManagerImageCropPopup.prototype.onPopupHidden=function(event,element,popup){this.$popupElement.find('form').request(this.options.alias+'::onEndCroppingSession')
$(document).trigger('mousedown')
MediaManagerImageCropPopup.prototype.onPopupHidden=function(event,element,popup){$(document).trigger('mousedown')
this.dispose()}
MediaManagerImageCropPopup.prototype.onPopupShown=function(event,element,popup){this.$popupElement=popup
this.$popupElement.on('change','[data-control="selection-mode"]',this.proxy(this.onSelectionModeChanged))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,6 @@
// ============================

MediaManagerImageCropPopup.prototype.onPopupHidden = function(event, element, popup) {
this.$popupElement.find('form').request(this.options.alias+'::onEndCroppingSession')

// Release clickedElement reference inside redactor.js
// If we don't do it, the image editor popup DOM elements
// won't be removed from the memory.
Expand Down
18 changes: 8 additions & 10 deletions modules/backend/widgets/mediamanager/partials/_item-icon.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<div class="icon-container <?= $itemType ?>">
<div class="icon-wrapper"><i class="<?= $this->itemTypeToIconClass($item, $itemType) ?>"></i></div>

<?php
if ($itemType == System\Classes\MediaLibraryItem::FILE_TYPE_IMAGE):
$thumbnailPath = $this->thumbnailExists($thumbnailParams, $item->path, $item->lastModified);
?>

<?php if (
$itemType == System\Classes\MediaLibraryItem::FILE_TYPE_IMAGE
&& $thumbnailUrl = $this->getResizedImageUrl($item->path, $thumbnailParams)
): ?>
<div>
<?php if (!$thumbnailPath): ?>
<div class="image-placeholder"
<?php if (!$thumbnailUrl): ?>
<div
class="image-placeholder"
data-width="<?= $thumbnailParams['width'] ?>"
data-height="<?= $thumbnailParams['height'] ?>"
data-path="<?= e($item->path) ?>"
Expand All @@ -19,8 +18,7 @@
</div>
<?php else: ?>
<?= $this->makePartial('thumbnail-image', [
'isError' => $this->thumbnailIsError($thumbnailPath),
'imageUrl' => $this->getThumbnailImageUrl($thumbnailPath)
'imageUrl' => $thumbnailUrl,
]) ?>
<?php endif ?>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php if (!$isError): ?>
<?php if ($imageUrl): ?>
<img src="<?= $imageUrl ?>"/>
<?php else: ?>
<i class="icon-chain-broken" title="<?= e(trans('backend::lang.media.thumbnail_error')) ?>"></i>
<p class="thumbnail-error-message"><?= e(trans('backend::lang.media.thumbnail_error')) ?></p>
<?php endif ?>
<?php endif ?>
27 changes: 0 additions & 27 deletions modules/system/classes/ImageResizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ class ImageResizer
*/
public const CACHE_PREFIX = 'system.resizer.';

/**
* Available methods to use when processing images
*/
public const METHOD_RESIZE = 'resize';
public const METHOD_CROP = 'crop';

/**
* @var array Available sources to get images from
*/
Expand Down Expand Up @@ -108,27 +102,6 @@ public function __construct($image, $width = 0, $height = 0, $options = [])
$this->options = array_merge($this->getDefaultOptions(), $options);
}

/**
* A simple static method for resizing an image and receiving the output path
*
* @throws ApplicationException If an invalid resize mode is passed to the the method.
*/
public static function processImage(
mixed $image,
int|float $width = 0,
int|float $height = 0,
array $options = [],
string $method = self::METHOD_RESIZE
): string {
if (!in_array($method, [static::METHOD_RESIZE, static::METHOD_CROP])) {
throw new \ApplicationException('Invalid method passed to processImage');
}

$resizer = new static($image, $width, $height, $options);
$resizer->{$method}();
return $resizer->getPathToResizedImage();
}

/**
* Get the default options for the resizer
*/
Expand Down
2 changes: 2 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@
<exclude-pattern>*/vendor/*</exclude-pattern>
<!-- Ignore this view file as fixing the issues in here will break the template -->
<exclude-pattern>modules/system/views/exception.php</exclude-pattern>
<!-- Ignore this view file as PHPCS wants line 8 to have 44 spaces instead of 12, clearly insane -->
<exclude-pattern>modules/backend/widgets/mediamanager/partials/_item-icon.php</exclude-pattern>
<!-- Ignore this test case completely as it's testing a parse error -->
<exclude-pattern>tests/fixtures/plugins/testvendor/goto/Plugin.php</exclude-pattern>
</ruleset>

0 comments on commit c9a72b8

Please sign in to comment.