Skip to content

Commit

Permalink
Merge branch 'release/2.18.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Misplon committed Oct 22, 2022
2 parents 7a97e47 + e172e16 commit 4574a81
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 54 deletions.
41 changes: 1 addition & 40 deletions css/admin.less
Original file line number Diff line number Diff line change
Expand Up @@ -174,46 +174,6 @@
.so-rows-container{
padding: 20px 15px 0 15px;

// See tpl/js-templates.php variable $row_color_count. It should match the number of colors defined here.
@row_colors: #CDE2EC, #F2C2BE, #D5CCDF, #CAE7CD, #E2DCB1;

.row-colors( @i: 1 ) when ( @i <= length( @row_colors ) ) {
@row_color: extract( @row_colors, @i );

// The color selectors
.so-row-color-@{i} {
&.so-row-color {
background-color: @row_color;
border: 1px solid darken( @row_color, 11% );

&.so-row-color-selected:before {
background: darken( @row_color, 10% );
}
}
}

// The actual container
.so-row-container.so-row-color-@{i} .so-cells .cell {
.cell-wrapper {
background-color: @row_color;
}

&.cell-selected .cell-wrapper {
background-color: darken( @row_color, 14% );
}

.resize-handle {
background-color: lighten( @row_color, 7% );

&:hover {
background-color: lighten( @row_color, 4% );
}
}
}

.row-colors( ( @i + 1 ) );
} .row-colors();

h3.so-row-label {
display: inline-block;
font-size: 1em;
Expand Down Expand Up @@ -288,6 +248,7 @@
}

ul li.so-row-colors-container {
clear: both;
display: flex;
justify-content: space-around;

Expand Down
97 changes: 97 additions & 0 deletions inc/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ function enqueue_admin_scripts( $prefix = '', $force = false ) {
'copy_content' => siteorigin_panels_setting( 'copy-content' ),
'cache' => array(),
'instant_open' => siteorigin_panels_setting( 'instant-open-widgets' ),
'add_media' => __( 'Choose Media', 'siteorigin-panels' ),
'default_columns' => apply_filters( 'siteorigin_panels_default_row_columns', array(
array(
'weight' => 0.5,
Expand Down Expand Up @@ -609,6 +610,38 @@ function enqueue_admin_styles( $prefix = '', $force = false ) {
SITEORIGIN_PANELS_VERSION
);
do_action( 'siteorigin_panel_enqueue_admin_styles' );

$row_colors = SiteOrigin_Panels_Admin::get_row_colors();
$row_colors_css = '';
foreach ( $row_colors as $id => $color ) {
$name = ! empty( $color['name'] ) ? sanitize_title( $color['name'] ) : $id;
$row_colors_css .= '
.siteorigin-panels-builder .so-rows-container .so-row-color-' . $name . '.so-row-color {
background-color: ' . $color['active'] . ';
border: 1px solid ' . $color['inactive'] . ';
}
.siteorigin-panels-builder .so-rows-container .so-row-color-' . $name . '.so-row-color.so-row-color-selected:before {
background: ' . $color['active'] . ';
}
.siteorigin-panels-builder .so-rows-container .so-row-container.so-row-color-' . $name . ' .so-cells .cell .cell-wrapper {
background-color: ' . $color['inactive'] . ';
}
.siteorigin-panels-builder .so-rows-container .so-row-container.so-row-color-' . $name . ' .so-cells .cell.cell-selected .cell-wrapper {
background-color: ' . $color['active'] . ';
}
.siteorigin-panels-builder .so-rows-container .so-row-container.so-row-color-' . $name . ' .so-cells .cell .resize-handle {
background-color: ' . $color['cell_divider'] . ';
}
.siteorigin-panels-builder .so-rows-container .so-row-container.so-row-color-' . $name . ' .so-cells .cell .resize-handle:hover {
background-color: ' . $color['cell_divider_hover'] . ';
}';
}

if ( ! empty( $row_colors_css ) ) {
wp_add_inline_style( 'so-panels-admin', $row_colors_css );
}
}
}

Expand Down Expand Up @@ -958,6 +991,70 @@ function js_templates() {
include plugin_dir_path( __FILE__ ) . '../tpl/js-templates.php';
}

public static function get_row_colors() {
$row_colors = apply_filters( 'siteorigin_panels_admin_row_colors', array(
1 => array(
'name' => __( 'Soft Blue', 'siteorigin-panels' ),
'inactive' => '#cde2ec',
'active' => '#a4cadd',
'cell_divider' => '#e7f1f6',
'cell_divider_hover' => '#dcebf2',
),
2 => array(
'name' => __( 'Soft Red', 'siteorigin-panels' ),
'inactive' => '#f2c2be',
'active' => '#e9968f',
'cell_divider' => '#f8dedc',
'cell_divider_hover' => '#f5d2cf',
),
3 => array(
'name' => __( 'Grayish Violet', 'siteorigin-panels' ),
'inactive' => '#d5ccdf',
'active' => '#b9aac9',
'cell_divider' => '#e7e2ed',
'cell_divider_hover' => '#dfd9e7',
),
4 => array(
'name' => __( 'Lime Green', 'siteorigin-panels' ),
'inactive' => '#cae7cd',
'active' => '#a3d6a9',
'cell_divider' => '#e3f2e4',
'cell_divider_hover' => '#d8edda',
),
5 => array(
'name' => __( 'Desaturated Yellow', 'siteorigin-panels' ),
'inactive' => '#e2dcb1',
'active' => '#d3ca88',
'cell_divider' => '#ece8cb',
'cell_divider_hover' => '#e8e3c0',
),
) );

// Ensure all of the colors are valid.
foreach ( $row_colors as $id => $color ) {
unset( $name );
if (
! empty( $color['inactive'] ) &&
! empty( $color['active'] ) &&
! empty( $color['cell_divider'] ) &&
! empty( $color['cell_divider_hover'] )
) {
// If color has a name set, store it and re-apply later.
if ( ! empty( $color['name'] ) ) {
$name = $color['name'];
unset( $color['name'] );
}

$valid_row_colors[ $id ] = array_map( 'sanitize_hex_color', $color );

if ( ! empty( $name ) ) {
$valid_row_colors[ $id ]['name'] = $name;
}
}
}
return ! empty( $valid_row_colors ) ? $valid_row_colors : array();
}

/**
* Render a widget form with all the Page Builder specific fields.
*
Expand Down
3 changes: 3 additions & 0 deletions inc/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,9 @@ function render( $post_id = false, $enqueue_css = true, $panels_data = false, &
if ( $panels_data === false ) {
return false;
}
} elseif ( is_string( $panels_data ) ) {
// If $panels_data is a string, it's likely json, try decoding it.
$panels_data = json_decode( $panels_data, true );
}

$panels_data = apply_filters( 'siteorigin_panels_data', $panels_data, $post_id );
Expand Down
25 changes: 20 additions & 5 deletions inc/styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,29 +251,36 @@ static function get_general_style_fields( $id, $label ) {
'priority' => 20,
'default' => 15,
'description' => __( 'Enter a value between 0 and 100.', 'siteorigin-panels' ),
),
'inset' => array(
'name' => __( 'Inset', 'siteorigin-panels' ),
'type' => 'checkbox',
'priority' => 30,
'default' => false,
'description' => sprintf( __( 'Inset box shadows appear inside the %s.', 'siteorigin-panels' ), strtolower( $label ) ),
),
'offset_horizontal' => array(
'name' => __( 'Horizontal Offset', 'siteorigin-panels' ),
'type' => 'measurement',
'priority' => 30,
'priority' => 40,
'default' => 0,
),
'offset_vertical' => array(
'name' => __( 'Vertical Offset', 'siteorigin-panels' ),
'type' => 'measurement',
'priority' => 40,
'priority' => 50,
'default' => '5px',
),
'blur' => array(
'name' => __( 'Blur', 'siteorigin-panels' ),
'type' => 'measurement',
'priority' => 50,
'priority' => 60,
'default' => '15px',
),
'spread' => array(
'name' => __( 'Spread', 'siteorigin-panels' ),
'type' => 'measurement',
'priority' => 60,
'priority' => 70,
),
),
);
Expand All @@ -297,6 +304,13 @@ static function get_general_style_fields( $id, $label ) {
'default' => 30,
'description' => __( 'Enter a value between 0 and 100.', 'siteorigin-panels' ),
),
'inset' => array(
'name' => __( 'Inset', 'siteorigin-panels' ),
'type' => 'checkbox',
'priority' => 30,
'default' => false,
'description' => sprintf( __( 'Inset box shadows appear inside the %s.', 'siteorigin-panels' ), strtolower( $label ) ),
),
'offset_horizontal' => array(
'name' => __( 'Horizontal Offset', 'siteorigin-panels' ),
'type' => 'measurement',
Expand Down Expand Up @@ -660,6 +674,7 @@ function add_parallax( $output, $context ) {
static function generate_box_shadow_css( $prefix, $style ) {
if ( ! class_exists( 'SiteOrigin_Color_Object' ) ) require plugin_dir_path( __FILE__ ) . '../widgets/lib/color.php';

$box_shadow_inset = ! empty( $style[ $prefix . '_inset' ] ) ? 'inset' : '';
$box_shadow_offset_horizontal = ! empty( $style[ $prefix . '_offset_horizontal' ] ) ? $style[ $prefix . '_offset_horizontal' ] : 0;
$box_shadow_offset_vertical = ! empty( $style[ $prefix . '_offset_vertical' ] ) ? $style[ $prefix . '_offset_vertical' ] : '5px';
$box_shadow_blur = ! empty( $style[ $prefix . '_blur' ] ) ? $style[ $prefix . '_blur' ] : '15px';
Expand All @@ -676,7 +691,7 @@ static function generate_box_shadow_css( $prefix, $style ) {
$box_shadow_opacity = isset( $style[ $prefix . '_opacity' ] ) && is_numeric( $style[ $prefix . '_opacity' ] ) ? min( 100, $style[ $prefix . '_opacity' ] ) / 100 : $box_shadow_default;

return array(
'box-shadow' => "$box_shadow_offset_horizontal $box_shadow_offset_vertical $box_shadow_blur $box_shadow_spread rgba($box_shadow_color, $box_shadow_opacity )"
'box-shadow' => "$box_shadow_inset $box_shadow_offset_horizontal $box_shadow_offset_vertical $box_shadow_blur $box_shadow_spread rgba($box_shadow_color, $box_shadow_opacity )"
);
}

Expand Down
24 changes: 24 additions & 0 deletions js/siteorigin-panels/view/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,30 @@ module.exports = Backbone.View.extend( {
silent: false
}, options );

// Allow for external field validation when attempting to close a widget.
if ( typeof this.widgetView == 'object' ) {
var values = this.getFormValues();
if ( typeof values.widgets == 'object' ) {
validSave = $( document ).triggerHandler(
'close_dialog_validation',
[
// Widget values.
values.widgets[ this.model.cid ],
// Widget Class
this.model.attributes.class,
// Model instance - used for finding field markup.
this.model.cid,
// Instance.
this
]
);
}

if ( typeof validSave == 'boolean' && ! validSave ) {
return false;
}
}

if ( ! options.silent ) {
this.trigger( 'close_dialog' );
}
Expand Down
2 changes: 1 addition & 1 deletion js/siteorigin-panels/view/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ module.exports = Backbone.View.extend( {
// Create the media frame.
frame = wp.media( {
// Set the title of the modal.
title: 'choose',
title: panelsOptions.add_media,

// Tell the modal to show only images.
library: {
Expand Down
7 changes: 7 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ SiteOrigin Premium includes access to our professional email support service, pe

== Changelog ==

= 2.18.0 - 22 October 2022 =
* Box Shadow: Added a new `Inset` setting. Inset box shadows appear inside the row, cell, or widget.
* Media Modal: Updated the title to `Choose Media`.
* Developer: Added `siteorigin_panels_admin_row_colors` filter.
* Developer: Added a client side event to allow for widget validation.
* Developer: Accounted for a situation where `$panels_data` is passed as a string containing JSON rather than an array.

= 2.17.0 - 28 August 2022 =
* Row, Cell, and Widget Design Settings: Added Border Radius and Box Shadow settings.

Expand Down
13 changes: 5 additions & 8 deletions tpl/js-templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,12 @@
<li><a class="so-row-delete so-needs-confirm" data-confirm="<?php esc_attr_e('Are you sure?', 'siteorigin-panels') ?>"><?php _e('Delete Row', 'siteorigin-panels') ?></a></li>
<li class="so-row-colors-container">
<?php
// See css/admin.less variable @row_colors. This should match the number of colors defined there.
$row_color_count = 5;

for ( $i = 1; $i <= $row_color_count; $i++ ) {
$classes = array( 'so-row-color', 'so-row-color-' . $i );

$row_colors = SiteOrigin_Panels_Admin::get_row_colors();
foreach ( $row_colors as $id => $color ) {
$name = ! empty( $color['name'] ) ? sanitize_title( $color['name'] ) : $id;
?>
<div data-color-label="<?php echo esc_attr( $i ); ?>"
class="<?php echo esc_attr( implode( ' ', $classes ) ) ?>{{% if( rowColorLabel == '<?php echo esc_attr( $i ); ?>' ) print(' so-row-color-selected'); %}}"
<div data-color-label="<?php echo esc_attr( $name ); ?>"
class="<?php echo esc_attr( 'so-row-color so-row-color-' . $name ); ?>{{% if( rowColorLabel == '<?php echo esc_attr( $name ); ?>' ) print(' so-row-color-selected'); %}}"
></div>
<?php
}
Expand Down

0 comments on commit 4574a81

Please sign in to comment.