Skip to content

Commit

Permalink
Add additional controls to HTML5 audio attributes (#1756)
Browse files Browse the repository at this point in the history
Adds support for `autoplay`, `controls`, `loop`, and `preload` attributes, with rudimentary validation for preload.

Those for `autoplay`, `controls`, and `loop` are copied directly from pfcloutier-druide/aaa3f82

See also #1442.
  • Loading branch information
iainsgillis authored and rhukster committed Nov 28, 2017
1 parent 59dd0d1 commit 4c16053
Showing 1 changed file with 108 additions and 0 deletions.
108 changes: 108 additions & 0 deletions system/src/Grav/Common/Page/Medium/AudioMedium.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,114 @@ protected function sourceParsedownElement(array $attributes, $reset = true)
];
}

/**
* Allows to set or remove the HTML5 default controls
*
* @param bool $display
* @return $this
*/
public function controls($display = true)
{
if($display)
{
$this->attributes['controls'] = true;
}
else
{
unset($this->attributes['controls']);
}
return $this;
}

/**
* Allows to set the preload behaviour
*
* @param $preload
* @return $this
*/
public function preload($preload)
{
$validPreloadAttrs = array('auto','metadata','none');

if (in_array($preload, $validPreloadAttrs))
{
$this->attributes['preload'] = $preload;
}
return $this;
}

/**
* Allows to set the controlsList behaviour
* Separate multiple values with a hyphen
*
* @param $controlsList
* @return $this
*/
public function controlsList($controlsList)
{
$controlsList = str_replace('-', ' ', $controlsList);
$this->attributes['controlsList'] = $controlsList;
return $this;
}

/**
* Allows to set the mute attribute
*
* @param bool $status
* @return $this
*/
public function mute($status = false)
{
if($status)
{
$this->attributes['mute'] = true;
}
else
{
unset($this->attributes['mute']);
}
return $this;
}

/**
* Allows to set the loop attribute
*
* @param bool $status
* @return $this
*/
public function loop($status = false)
{
if($status)
{
$this->attributes['loop'] = true;
}
else
{
unset($this->attributes['loop']);
}
return $this;
}

/**
* Allows to set the autoplay attribute
*
* @param bool $status
* @return $this
*/
public function autoplay($status = false)
{
if($status)
{
$this->attributes['autoplay'] = true;
}
else
{
unset($this->attributes['autoplay']);
}
return $this;
}


/**
* Reset medium.
*
Expand Down

0 comments on commit 4c16053

Please sign in to comment.