Skip to content

Commit

Permalink
feat: Allow to set width with autoresize
Browse files Browse the repository at this point in the history
Fixes #91
  • Loading branch information
octfx committed May 4, 2024
1 parent 05575f8 commit 21b6e96
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
8 changes: 7 additions & 1 deletion includes/EmbedService/EmbedHtmlFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class EmbedHtmlFormatter {
* description: String - Optional Description
* @return string
*/
public static function toHtml( AbstractEmbedService $service, array $config = [] ): string {
public static function toHtml( AbstractEmbedService $service, array $config = [], array $args = [] ): string {
if ( $service instanceof OEmbedServiceInterface ) {
return self::makeIframe( $service );
}
Expand Down Expand Up @@ -60,6 +60,12 @@ public static function toHtml( AbstractEmbedService $service, array $config = []

if ( $config['autoresize'] === true ) {
$config['class'] .= ' embedvideo--autoresize';
if ( isset( $args['width'] ) ) {
$inlineStyles['container'] .= sprintf( 'max-width:%dpx', $width );
}
if ( isset( $args['height'] ) ) {
$inlineStyles['wrapper'] .= sprintf( 'max-height:%dpx', $height );
}
} else {
// Autoresize does not need inline width and height
$inlineStyles['container'] .= sprintf( 'width:%dpx', $width );
Expand Down
3 changes: 2 additions & 1 deletion includes/EmbedVideo.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ public function output(): array {
// This does the whole HTML generation
EmbedHtmlFormatter::toHtml(
$this->service,
$this->makeHtmlFormatConfig( $this->service )
$this->makeHtmlFormatConfig( $this->service ),
$this->args
),
'noparse' => true,
'isHTML' => true
Expand Down

0 comments on commit 21b6e96

Please sign in to comment.