{# Shortcut variables #} {% set default = mediaembed.config.media %} {% set oembed = mediaembed.service %} {# Processing error #} {% if not mediaembed.success %} {% if default.responsive %} {% set class = "-responsive mediaembed-msod" %} {% else %} {% set class = " mediaembed-msod\" style=\"max-width: " ~ default.width ~ "px;" %} {% endif %}
{# Setup block #} {% else %} {% set response = oembed.attributes %} {# Normalize response #} {% if (response.width is empty) or not (response.width is defined) or (response.width == 0) %} {% set response = response|merge({'width' : default.width|default(1)}) %} {% endif %} {% if (response.height is empty) or not (response.height is defined) or (response.height == 0) %} {% set response = response|merge({'height' : default.height|default(1)}) %} {% endif %} {% set width = response.width %} {% set height = response.height %} {% set ratio = height / width %} {# Adjust OEmbed media dimensions or restrict them? #} {% if default.adjust %} {# Check if computed height is larger than default setting #} {% if (width * ratio) > default.height or (height / ratio) > default.width %} {# Rescale width and height #} {% set width = default.width|default(1) %} {% set height = (default.width * ratio)|round %} {% endif %} {% else %} {% set width = default.width|default(1) %} {% set height = default.height|default(1) %} {% endif %} {# Recompute aspect ratio #} {% set ratio = height / width %} {% set container_styles = "padding-bottom: " ~ "%.2f"|format(ratio * 100) ~ "%;" %} {# Embed responsive OEmbed media #} {% if default.responsive %} {% set responsive = "-responsive" %} {% set width = 1920 %} {% set height = (width * ratio)|round %} {% else %} {% set styles = " style=\"max-width: " ~ width ~ "px; max-height: " ~ height ~ "px;\"" %} {% endif %} {# Setup lazy loading media for those with preview enabled #} {% if default.preview %} {% set lazyload = " lazyload" %} {% set lazyload_script = " onclick=\"lazyload(this)\"" %} {% endif %} {% endif %}