overflow: auto;
padding: 10px;
}
+
+ .unknownDimensionContainer {
+ position: relative;
+ width: 384px;
+ height: 216px;
+ max-width: 100%;
+ display: inline-block;
+ }
+
+ .unknownDimensionContainer amp-img img {
+ object-fit: contain;
+ }
</style>
{literal}<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>{/literal}
<script async custom-element="amp-carousel" src="https://cdn.ampproject.org/v0/amp-carousel-0.1.js"></script>
while ($elements->length) {
/** @var \DOMElement $element */
$element = $elements->item(0);
- if ($tag === 'img') {
- $styles = $element->getAttribute('style');
- if (preg_match('~\bheight:\s*(\d+)px\b~', $styles, $matches)) $element->setAttribute('height', $matches[1]);
- if (preg_match('~\bwidth:\s*(\d+)px\b~', $styles, $matches)) $element->setAttribute('width', $matches[1]);
-
- if (!$element->getAttribute('height') || !$element->getAttribute('width')) {
- DOMUtil::removeNode($element);
- continue;
- }
-
- $element->removeAttribute('style');
- }
$newElement = $element->ownerDocument->createElement('amp-' . $tag);
$newElement->setAttribute($attr->localName, $attr->nodeValue);
}
+ if ($tag === 'img') {
+ $styles = $newElement->getAttribute('style');
+ $newElement->removeAttribute('style');
+ if (preg_match('~\bheight:\s*(\d+)px\b~', $styles, $matches)) $newElement->setAttribute('height', $matches[1]);
+ if (preg_match('~\bwidth:\s*(\d+)px\b~', $styles, $matches)) $newElement->setAttribute('width', $matches[1]);
+
+ if (!$newElement->getAttribute('height') || !$newElement->getAttribute('width')) {
+ $newElement->setAttribute('layout', 'fill');
+
+ $container = $newElement->ownerDocument->createElement('span');
+ $container->setAttribute('class', 'unknownDimensionContainer');
+ $container->appendChild($newElement);
+ $newElement = $container;
+ }
+ }
+
$element->parentNode->insertBefore($newElement, $element);
DOMUtil::removeNode($element);
}