diff --git a/assets/js/blocks.js b/assets/js/blocks.js old mode 100755 new mode 100644 index 0f30003f..f853b92f --- a/assets/js/blocks.js +++ b/assets/js/blocks.js @@ -120,7 +120,12 @@ export default registerBlockType( displayEpisodeType: { type: 'boolean', default: false, - } + }, + isDocked: { + type: 'string', + default: 'none', + enum: ['none', 'top', 'bottom'], + }, }, transforms, diff --git a/assets/js/blocks/podcast/index.scss b/assets/js/blocks/podcast/index.scss index 3c321f2d..d317dfbf 100644 --- a/assets/js/blocks/podcast/index.scss +++ b/assets/js/blocks/podcast/index.scss @@ -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 { @@ -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; diff --git a/assets/js/edit.js b/assets/js/edit.js index b7e4e0d9..9d489237 100644 --- a/assets/js/edit.js +++ b/assets/js/edit.js @@ -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'; @@ -70,7 +70,8 @@ function Edit( props ) { displayExplicitBadge, displaySeasonNumber, displayEpisodeNumber, - displayEpisodeType + displayEpisodeType, + isDocked, } = attributes; const duration = attributes.duration || ''; @@ -185,6 +186,8 @@ function Edit( props ) { setFeaturedImage(image.id); }; + const blockRef = useRef(document.querySelector('.wp-block-podcasting-podcast-outer')); + return ( {controls} @@ -285,7 +288,31 @@ function Edit( props ) { 'simple-podcasting' )} checked={displayEpisodeType} - onChange={() => setAttributes({ displayEpisodeType: !displayEpisodeType})} + onChange={() => setAttributes({ displayEpisodeType: !displayEpisodeType })} + /> + + + + setAttributes({ isDocked }) + } /> @@ -420,7 +447,7 @@ function Edit( props ) { -
+
{src ? ( <>
diff --git a/includes/blocks/podcast/markup.php b/includes/blocks/podcast/markup.php index 316c6137..6b21d9fb 100644 --- a/includes/blocks/podcast/markup.php +++ b/includes/blocks/podcast/markup.php @@ -23,6 +23,7 @@ 'displaySeasonNumber' => false, 'displayEpisodeNumber' => false, 'displayEpisodeType' => false, + 'isDocked' => 'none', ] ); @@ -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' ); ?> -
+ +
@@ -74,46 +93,99 @@ -
- - - - - - - - - - - - - - - - - + -
- - - - - - - - - - - - - - - - - - +
+
+
- + +
+ +