Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion css/cloudinary.css

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions css/images/undo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion js/cloudinary.js

Large diffs are not rendered by default.

183 changes: 122 additions & 61 deletions php/ui/component/class-crops.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class Crops extends Select {
* @var string
*/
protected $demo_files = array(
'leather_bag.jpg',
'lady.jpg',
'horses.jpg',
'docs/addons/objectdetection/dirt-road-1851258_1280.jpg',
'docs/model-993911_640.jpg',
'docs/shoppable_bag.png',
);

/**
Expand Down Expand Up @@ -96,7 +96,6 @@ protected function info_box( $struct ) {
* @return array
*/
protected function input( $struct ) {

$mode = $this->setting->get_param( 'mode', 'demos' );
$wrapper = $this->get_part( 'div' );
$wrapper['attributes']['class'][] = 'cld-size-items';
Expand All @@ -112,89 +111,130 @@ protected function input( $struct ) {
}
$sizes = Utils::get_registered_sizes();

$selector = $this->make_selector();
$wrapper['children']['control-selector'] = $selector;
// Create size selector (tabs).
$size_selector = $this->make_size_selector( $sizes );
$wrapper['children']['size-selector'] = $size_selector;

// Get demo files.
$mode = $this->setting->get_param( 'mode', 'demos' );

/**
* Filter the demo files.
*
* @hook cloudinary_registered_sizes
* @since 3.1.3
*
* @param $demo_files {array} array of demo files.
*
* @return {array}
*/
$examples = apply_filters( 'cloudinary_demo_crop_files', $this->demo_files );

if ( 'full' === $mode ) {
$public_id = $this->setting->get_root_setting()->get_param( 'preview_id' );
if ( ! empty( $public_id ) ) {
$examples = array( $public_id );
}
}

// Create content area for each size.
foreach ( $sizes as $size => $details ) {
if ( empty( $details['crop'] ) ) {
continue;
}
$row = $this->get_part( 'div' );
$row['attributes']['class'][] = 'cld-size-items-item';
$row['attributes']['class'][] = 'crop-preview';
$row['content'] = $size;

$image = $this->get_part( 'img' );
$image['content'] = $size;
$size_array = array();

$size_content = $this->get_part( 'div' );
$size_content['attributes']['class'][] = 'cld-size-content';
$size_content['attributes']['data-size'] = $size;
$size_content['render'] = true;

$size_array = array();
if ( ! empty( $details['width'] ) ) {
$size_array[] = 'w_' . $details['width'];
$image['attributes']['width'] = $details['width'];
$size_array[] = 'w_' . $details['width'];
}
if ( ! empty( $details['height'] ) ) {
$size_array[] = 'h_' . $details['height'];
$image['attributes']['height'] = $details['height'];
$size_array[] = 'h_' . $details['height'];
}
$size_dimensions = implode( ',', $size_array );

// Create image previews container.
$images_container = $this->get_part( 'div' );
$images_container['attributes']['class'][] = 'cld-size-images';
$images_container['render'] = true;

foreach ( $examples as $index => $file ) {
$image_wrapper = $this->get_part( 'div' );
$image_wrapper['attributes']['class'][] = 'cld-size-image-wrapper';
$image_wrapper['render'] = true;

$image = $this->get_part( 'img' );
$image['attributes']['data-size'] = $size_dimensions;
$image['attributes']['data-file'] = $file;
$image['render'] = true;
if ( ! empty( $details['width'] ) ) {
$image['attributes']['width'] = $details['width'];
}
if ( ! empty( $details['height'] ) ) {
$image['attributes']['height'] = $details['height'];
}

$image_wrapper['children']['image'] = $image;
$images_container['children'][ 'image-' . $index ] = $image_wrapper;
}
$image['attributes']['data-size'] = implode( ',', $size_array );
$size_key = $details['width'] . 'x' . $details['height'];

// Create single input field with disable checkbox.
$size_key = $details['width'] . 'x' . $details['height'];
if ( empty( $value[ $size_key ] ) ) {
$value[ $size_key ] = '';
}
$row['children']['size'] = $image;
$row['children']['input'] = $this->make_input( $this->get_name() . '[' . $size_key . ']', $value[ $size_key ] );

$input_wrapper = $this->make_input( $this->get_name() . '[' . $size_key . ']', $value[ $size_key ] );

// Set the placeholder.
$placeholder = 'c_fill,g_auto';

if ( 'thumbnail' === $size ) {
$placeholder = 'c_thumb,g_auto';
}
$row['children']['input']['children']['input']['attributes']['placeholder'] = $placeholder;
$input_wrapper['children']['input']['attributes']['placeholder'] = $placeholder;

$wrapper['children'][ $size ] = $row;
$size_content['children']['input'] = $input_wrapper;
$size_content['children']['images'] = $images_container;

$wrapper['children'][ 'content-' . $size ] = $size_content;
}

return $wrapper;
}

/**
* Make an image selector.
* Make a size selector (tabs).
*
* @param array $sizes The registered sizes.
* @return array
*/
protected function make_selector() {
protected function make_size_selector( $sizes ) {
$selector = $this->get_part( 'div' );
$selector['attributes']['class'][] = 'cld-image-selector';
$mode = $this->setting->get_param( 'mode', 'demos' );
$selector['attributes']['class'][] = 'cld-size-selector';
$selector['render'] = true;

/**
* Filter the demo files.
*
* @hook cloudinary_registered_sizes
* @since 3.1.3
*
* @param $demo_files {array} array of demo files.
*
* @return {array}
*/
$examples = apply_filters( 'cloudinary_demo_crop_files', $this->demo_files );
if ( 'full' === $mode ) {
$public_id = $this->setting->get_root_setting()->get_param( 'preview_id' );
if ( ! empty( $public_id ) ) {
$examples = array(
$public_id,
);
$index = 0;
foreach ( $sizes as $size => $details ) {
if ( empty( $details['crop'] ) ) {
continue;
}
}
foreach ( $examples as $index => $file ) {
$name = pathinfo( $file, PATHINFO_FILENAME );
$item = $this->get_part( 'span' );
$item['attributes']['data-image'] = $file;

$item = $this->get_part( 'span' );
$item['attributes']['data-size'] = $size;
$item['attributes']['class'][] = 'cld-size-selector-item';
$item['render'] = true;

if ( 0 === $index ) {
$item['attributes']['data-selected'] = true;

}
$item['attributes']['class'][] = 'cld-image-selector-item';

$item['content'] = $name;
$selector['children'][ 'image-' . $index ] = $item;
$item['content'] = $size;
$selector['children'][ 'size-' . $size ] = $item;
++$index;
}

return $selector;
Expand All @@ -215,9 +255,11 @@ protected function make_input( $name, $value ) {
'crop-size-inputs',
);

$label = $this->get_part( 'label' );
$label['attributes']['for'] = $name;
$label['content'] = __( 'Disable', 'cloudinary' );
// Disable toggle control.
$control = $this->get_part( 'label' );
$control['attributes']['class'][] = 'cld-input-on-off-control';
$control['attributes']['class'][] = 'medium';
$control['attributes']['for'] = $name;

$check = $this->get_part( 'input' );
$check['attributes']['type'] = 'checkbox';
Expand All @@ -230,15 +272,34 @@ protected function make_input( $name, $value ) {
$check['attributes']['checked'] = 'checked';
}

$slider = $this->get_part( 'span' );
$slider['attributes']['class'][] = 'cld-input-on-off-control-slider';
$slider['render'] = true;

$control['children']['input'] = $check;
$control['children']['slider'] = $slider;

$label = $this->get_part( 'span' );
$label['attributes']['class'] = 'cld-input-on-off-control-label';
$label['content'] = __( 'Disable', 'cloudinary' );

$input = $this->get_part( 'input' );
$input['attributes']['type'] = 'text';
$input['attributes']['name'] = $name;
$input['attributes']['value'] = '--' !== $value ? $value : '';
$input['attributes']['class'][] = 'regular-text';

$wrapper['children']['input'] = $input;
$wrapper['children']['label'] = $label;
$wrapper['children']['check'] = $check;
$clear_button = $this->get_part( 'button' );
$clear_button['attributes']['type'] = 'button';
$clear_button['attributes']['class'][] = 'button';
$clear_button['attributes']['class'][] = 'clear-crop-input';
$clear_button['attributes']['title'] = __( 'Reset input', 'cloudinary' );
$clear_button['content'] = Utils::get_inline_svg( 'css/images/undo.svg', false ) . '<span>' . __( 'Reset', 'cloudinary' ) . '</span>';

$wrapper['children']['input'] = $input;
$wrapper['children']['button'] = $clear_button;
$wrapper['children']['control'] = $control;
$wrapper['children']['label'] = $label;

return $wrapper;
}
Expand Down
1 change: 1 addition & 0 deletions src/css/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ $color-transformations-cyan: #54c8db;
$color-transformations-background: #262c35;
$color-transformations-asset: #333B4C;


/** Sizes */
$content-width: 870px;
$size-small: 783px;
Expand Down
98 changes: 93 additions & 5 deletions src/css/components/ui/_sizes-preview.scss
Original file line number Diff line number Diff line change
Expand Up @@ -73,30 +73,118 @@
}
}

.crop-size-inputs{
.crop-size-inputs {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 16px;
max-width: 400px;
flex-wrap: wrap;
}

.cld-ui-input.regular-text {
max-width: 260px;
}

.cld-ui-input.regular-text[disabled]{
background-color: $color-light-grey;
opacity: 0.5;
}

.disable-toggle {
margin: 0;
}

// Medium size toggle (between mini and standard)
.cld-input-on-off-control.medium {
width: 25px;
height: 13px;
margin-right: 0;

.cld-input-on-off-control-slider::before {
height: 9px;
width: 9px;
left: 2px;
bottom: 2px;
}

input:checked + .cld-input-on-off-control-slider::before {
transform: translateX(12px);
}
}

.cld-input-on-off-control-label {
font-size: 12px;
}

.button.clear-crop-input {
display: inline-flex;
align-items: center;
gap: 6px;
background: transparent;
border: none;
color: $color-cld-blue;
padding: 0;
cursor: pointer;
box-shadow: none;
font-size: 14px;
font-weight: 600;
margin-right: 40px;

svg {
width: 16px;
height: 16px;
fill: currentColor;
}

&:hover {
background: transparent;
opacity: 0.8;
}

&:focus {
box-shadow: none;
outline: none;
}
}

}

&-image-selector {
&-size-selector {
display: flex;
flex-wrap: nowrap;
overflow-x: scroll;
scrollbar-width: thin;
border: 1px solid $color-light-grey;
border-radius: 4px;
width: fit-content;
max-width: 100%;

margin-bottom: 42px;
padding: 4px;

&-item {
border: 1px solid $color-light-grey;
padding: 3px 6px;
flex-shrink: 0;
white-space: nowrap;
padding: 8px;
margin: 0 3px -1px 0;
cursor: pointer;
color: $color-transformations-asset;
background-color: transparent;

font-weight: 600;

&[data-selected] {
background-color: $color-light-grey;
color: $color-cld-blue;
background-color: rgba(52, 72, 197, 0.06);
}
}
}

&-size-images {
display: flex;
flex-wrap: wrap;
gap: 10px;

margin-bottom: 42px;
}
Loading