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
7 changes: 6 additions & 1 deletion assets/js/blocks.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,12 @@ export default registerBlockType(
displayEpisodeType: {
type: 'boolean',
default: false,
}
},
isDocked: {
type: 'string',
default: 'none',
enum: ['none', 'top', 'bottom'],
},
},
transforms,

Expand Down
79 changes: 79 additions & 0 deletions assets/js/blocks/podcast/index.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,84 @@
body.has-docked-bottom {
padding-bottom: 150px;
&.docked-in-editor .docked-bottom {
bottom: 24px;
}
}

body.has-docked-top {
padding-top: 150px;

&.docked-in-editor {
padding-top: 0px;
}
&.docked-in-editor .editor-styles-wrapper {
padding-top: 150px;
}
&.docked-in-editor .docked-top {
top: 60px;
}

&.logged-in.admin-bar {
padding-top: 182px;
}

&.logged-in.admin-bar .docked-top {
top: 32px;
}
}

.wp-block-podcasting-podcast-outer {
border: 1px solid #707070;
border-radius: 4px;
padding: 20px;

&.docked-bottom {
margin: 0;
background-color: var(--wp--preset--color--base);
position: fixed;
bottom: 0;
left: 0;
right: 0;
z-index: 34;
border-radius: 4px 4px 0px 0px;
max-width: initial;

& .wp-block-podcasting-podcast__container {
margin-bottom: 0px;
}

& .wp-block-podcasting-podcast__details {
width: 100%;
}

& .wp-block-podcasting-podcast__toggle-details-button {
margin-bottom: 20px;
}
}

&.docked-top {
margin: 0;
background-color: var(--wp--preset--color--base);
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 34;
border-radius: 0px 0px 4px 4px;
max-width: initial;

& .wp-block-podcasting-podcast__container {
margin-bottom: 0px;
}

& .wp-block-podcasting-podcast__details {
width: 100%;
}

& .wp-block-podcasting-podcast__toggle-details-button {
margin-bottom: 20px;
}
}
}

.wp-block-podcasting-podcast__container {
Expand All @@ -13,9 +90,11 @@
}

.wp-block-podcasting-podcast__show-art {
display: none;
margin-bottom: 20px;

@media (min-width: 768px) {
display: block;
flex-basis: 100px;
margin-bottom: 0;
margin-right: 20px;
Expand Down
35 changes: 31 additions & 4 deletions assets/js/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const ALLOWED_MEDIA_TYPES = ['audio'];
const { select } = wp.data;

import { Button } from '@wordpress/components';
import { useState, useEffect } from '@wordpress/element';
import { useState, useEffect, useRef } from '@wordpress/element';
import { dispatch, useSelect, useDispatch } from '@wordpress/data';
import { createBlock } from '@wordpress/blocks';

Expand Down Expand Up @@ -70,7 +70,8 @@ function Edit( props ) {
displayExplicitBadge,
displaySeasonNumber,
displayEpisodeNumber,
displayEpisodeType
displayEpisodeType,
isDocked,
} = attributes;

const duration = attributes.duration || '';
Expand Down Expand Up @@ -185,6 +186,8 @@ function Edit( props ) {
setFeaturedImage(image.id);
};

const blockRef = useRef(document.querySelector('.wp-block-podcasting-podcast-outer'));

return (
<Fragment>
{controls}
Expand Down Expand Up @@ -285,7 +288,31 @@ function Edit( props ) {
'simple-podcasting'
)}
checked={displayEpisodeType}
onChange={() => setAttributes({ displayEpisodeType: !displayEpisodeType})}
onChange={() => setAttributes({ displayEpisodeType: !displayEpisodeType })}
/>
</PanelRow>
<PanelRow>
<RadioControl
label={__('Dock Player', 'simple-podcasting')}
help={__('This will only affect the position of the player on the frontend.', 'simple-podcasting')}
selected={isDocked}
options={[
{
label: __('None', 'simple-podcasting'),
value: 'none',
},
{
label: __('Top', 'simple-podcasting'),
value: 'top',
},
{
label: __('Bottom', 'simple-podcasting'),
value: 'bottom',
},
]}
onChange={(isDocked) =>
setAttributes({ isDocked })
}
/>
</PanelRow>
<PanelRow>
Expand Down Expand Up @@ -420,7 +447,7 @@ function Edit( props ) {
</PanelRow>
</PanelBody>
</InspectorControls>
<div className="wp-block-podcasting-podcast-outer">
<div ref={blockRef} className="wp-block-podcasting-podcast-outer">
{src ? (
<>
<div className="wp-block-podcasting-podcast__container">
Expand Down
150 changes: 111 additions & 39 deletions includes/blocks/podcast/markup.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
'displaySeasonNumber' => false,
'displayEpisodeNumber' => false,
'displayEpisodeType' => false,
'isDocked' => 'none',
]
);

Expand All @@ -46,8 +47,26 @@
$term_image_id = '';
}

/*
* If not on a single post, set isDocked to none.
*
* This is to prevent having multiple instances of the podcast block with same docked position.
*/
$is_docked = ! is_singular() ? 'none' : $attributes['isDocked'];

// Output the body class based on isDocked value
$body_class = '';
if ( 'top' === $is_docked ) {
$body_class = 'has-docked-top';
} elseif ( 'bottom' === $is_docked ) {
$body_class = 'has-docked-bottom';
}

$podcast_details_id = wp_unique_prefixed_id( 'podcast-details' );
$toggle_details_button_id = wp_unique_prefixed_id( 'toggle-details-button' );
?>
<div class="wp-block-podcasting-podcast-outer">

<div class="wp-block-podcasting-podcast-outer <?php echo 'docked-' . sanitize_html_class( $is_docked ); ?>">
<div class="wp-block-podcasting-podcast__container">
<?php if ( $attributes['displayArt'] && ( has_post_thumbnail() || ! empty( $term_image_id ) ) ) : ?>
<div class="wp-block-podcasting-podcast__show-art">
Expand All @@ -74,46 +93,99 @@
<?php the_title(); ?>
</h3>
<?php endif; ?>
<div class="wp-block-podcasting-podcast__show-details">
<?php if ( $attributes['displayShowTitle'] && ! empty( $show_name ) ) : ?>
<span class="wp-block-podcasting-podcast__title">
<?php echo esc_html( $show_name ); ?>
</span>
<?php endif; ?>
<?php if ( $attributes['displaySeasonNumber'] && ! empty( $season_number ) ) : ?>
<span class="wp-block-podcasting-podcast__season">
<?php esc_html_e( 'Season: ', 'simple-podcasting' ); ?>
<?php echo esc_html( $season_number ); ?>
</span>
<?php endif; ?>
<?php if ( $attributes['displayEpisodeNumber'] && ! empty( $episode_number ) ) : ?>
<span class="wp-block-podcasting-podcast__episode">
<?php esc_html_e( 'Episode: ', 'simple-podcasting' ); ?>
<?php echo esc_html( $episode_number ); ?>
</span>
<?php endif; ?>
<div id="<?php echo esc_attr( $podcast_details_id ); ?>" style="display: none;" aria-hidden="true">
<div class="wp-block-podcasting-podcast__show-details">
<?php if ( $attributes['displayShowTitle'] && ! empty( $show_name ) ) : ?>
<span class="wp-block-podcasting-podcast__title">
<?php echo esc_html( $show_name ); ?>
</span>
<?php endif; ?>
<?php if ( $attributes['displaySeasonNumber'] && ! empty( $season_number ) ) : ?>
<span class="wp-block-podcasting-podcast__season">
<?php esc_html_e( 'Season: ', 'simple-podcasting' ); ?>
<?php echo esc_html( $season_number ); ?>
</span>
<?php endif; ?>
<?php if ( $attributes['displayEpisodeNumber'] && ! empty( $episode_number ) ) : ?>
<span class="wp-block-podcasting-podcast__episode">
<?php esc_html_e( 'Episode: ', 'simple-podcasting' ); ?>
<?php echo esc_html( $episode_number ); ?>
</span>
<?php endif; ?>
</div>
<div class="wp-block-podcasting-podcast__show-details">
<?php if ( $attributes['displayDuration'] && ! empty( $duration ) ) : ?>
<span class="wp-block-podcasting-podcast__duration">
<?php esc_html_e( 'Listen Time: ', 'simple-podcasting' ); ?>
<?php echo esc_html( $duration ); ?>
</span>
<?php endif; ?>
<?php if ( $attributes['displayEpisodeType'] && ! empty( $episode_type ) && 'none' !== $episode_type ) : ?>
<span class="wp-block-podcasting-podcast__episode-type">
<?php esc_html_e( 'Episode type: ', 'simple-podcasting' ); ?>
<?php echo esc_html( $episode_type ); ?>
</span>
<?php endif; ?>
<?php if ( $attributes['displayExplicitBadge'] && ! empty( $explicit ) ) : ?>
<span class="wp-block-podcasting-podcast__explicit-badge">
<?php esc_html_e( 'Explicit: ', 'simple-podcasting' ); ?>
<?php echo esc_html( $explicit ); ?>
</span>
<?php endif; ?>
</div>
</div>
<div class="wp-block-podcasting-podcast__show-details">
<?php if ( $attributes['displayDuration'] && ! empty( $duration ) ) : ?>
<span class="wp-block-podcasting-podcast__duration">
<?php esc_html_e( 'Listen Time: ', 'simple-podcasting' ); ?>
<?php echo esc_html( $duration ); ?>
</span>
<?php endif; ?>
<?php if ( $attributes['displayEpisodeType'] && ! empty( $episode_type ) && 'none' !== $episode_type ) : ?>
<span class="wp-block-podcasting-podcast__episode-type">
<?php esc_html_e( 'Episode type: ', 'simple-podcasting' ); ?>
<?php echo esc_html( $episode_type ); ?>
</span>
<?php endif; ?>
<?php if ( $attributes['displayExplicitBadge'] && ! empty( $explicit ) ) : ?>
<span class="wp-block-podcasting-podcast__explicit-badge">
<?php esc_html_e( 'Explicit: ', 'simple-podcasting' ); ?>
<?php echo esc_html( $explicit ); ?>
</span>
<?php endif; ?>
<div class="wp-block-podcasting-podcast__toggle-details">
<button class="wp-block-podcasting-podcast__toggle-details-button" id="<?php echo esc_attr( $toggle_details_button_id ); ?>" aria-expanded="false" aria-controls="<?php echo esc_attr( $podcast_details_id ); ?>" aria-label="<?php esc_attr_e( 'Toggle podcast details', 'simple-podcasting' ); ?>">
<?php esc_html_e( 'More', 'simple-podcasting' ); ?>
</button>
</div>
<?php
if ( isset( $is_docked ) && 'none' !== $is_docked ) {
echo wp_kses_post( $content );
}
?>
</div>
</div>
<?php echo wp_kses_post( $content ); ?>

<?php
if ( isset( $is_docked ) && 'none' === $is_docked ) {
echo wp_kses_post( $content );
}
?>
</div>

<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function() {
// Add the body class for docked position
<?php if ( $body_class ) : ?>
document.body.classList.add('<?php echo esc_attr( $body_class ); ?>');
<?php endif; ?>

var toggleButton = document.getElementById('<?php echo esc_attr( $toggle_details_button_id ); ?>');
var detailsDiv = document.getElementById('<?php echo esc_attr( $podcast_details_id ); ?>');

// If isDocked is 'none', show details by default
<?php if ( 'none' === $is_docked ) : ?>
detailsDiv.style.display = 'block';
detailsDiv.setAttribute('aria-hidden', 'false');
toggleButton.textContent = <?php echo wp_json_encode( __( 'Less', 'simple-podcasting' ) ); ?>;
toggleButton.style.display = 'none';
toggleButton.setAttribute('aria-expanded', 'true');
toggleButton.setAttribute('aria-hidden', 'true');
<?php endif; ?>

toggleButton.addEventListener('click', function() {
if (detailsDiv.style.display === 'none') {
detailsDiv.style.display = 'block';
detailsDiv.setAttribute('aria-hidden', 'false');
toggleButton.textContent = <?php echo wp_json_encode( __( 'Less', 'simple-podcasting' ) ); ?>;
toggleButton.setAttribute('aria-expanded', 'true');
} else {
detailsDiv.style.display = 'none';
detailsDiv.setAttribute('aria-hidden', 'true');
toggleButton.textContent = <?php echo wp_json_encode( __( 'More', 'simple-podcasting' ) ); ?>;
toggleButton.setAttribute('aria-expanded', 'false');
}
});
});
</script>
Loading