Index: components/dom_distiller/core/javascript/dom_distiller_viewer.js |
diff --git a/components/dom_distiller/core/javascript/dom_distiller_viewer.js b/components/dom_distiller/core/javascript/dom_distiller_viewer.js |
index 55f53bbf3854feaebdf305bed92df2acce7a9ef2..548222f2913b11d523d991de33875ff8f1da7591 100644 |
--- a/components/dom_distiller/core/javascript/dom_distiller_viewer.js |
+++ b/components/dom_distiller/core/javascript/dom_distiller_viewer.js |
@@ -6,6 +6,41 @@ function addToPage(html) { |
var div = document.createElement('div'); |
div.innerHTML = html; |
document.getElementById('content').appendChild(div); |
+ fillYouTubePlaceholders(); |
+} |
+ |
+function resizeIframes() { |
+ iframeList = document.getElementsByTagName('iframe'); |
+ for (var i = 0; i < iframeList.length; i++) { |
+ var ratio = iframeList[i].clientHeight / iframeList[i].clientWidth; |
+ iframeList[i].width = iframeList[i].parentElement.clientWidth; |
+ iframeList[i].height = iframeList[i].parentElement.clientWidth * ratio; |
+ } |
+} |
+ |
+function fillYouTubePlaceholders() { |
+ var placeholders = document.getElementsByClassName("embed-placeholder"); |
+ for (var i = 0; i < placeholders.length; i++) { |
+ if (!placeholders[i].hasAttribute('data-type') || |
+ placeholders[i].getAttribute('data-type') != 'youtube' || |
+ !placeholders[i].hasAttribute('data-id')) { |
+ continue; |
+ } |
+ var embed = document.createElement('iframe'); |
+ var url = 'http://www.youtube.com/embed/' + |
+ placeholders[i].getAttribute('data-id'); |
+ embed.setAttribute('src', url); |
+ embed.setAttribute('type', 'text/html'); |
+ embed.setAttribute('frameborder', '0'); |
+ |
+ var parent = placeholders[i].parentElement; |
+ var width = parent.clientWidth; |
+ var hdMult = 1080.0 / 1920.0; // YouTube frame width/height is always HD. |
+ embed.setAttribute('width', width); |
+ embed.setAttribute('height', width * hdMult); |
+ |
+ parent.replaceChild(embed, placeholders[i]); |
+ } |
} |
function showLoadingIndicator(isLastPage) { |
@@ -74,3 +109,16 @@ document.getElementById('showOriginal').addEventListener('click', function(e) { |
document.body.appendChild(img); |
}, true); |
+window.addEventListener('orientationchange', function(e) { |
+ // Wait for the page to have actually updated before resizing. |
+ setTimeout(resizeIframes, 150); |
+}); |
+ |
+window.addEventListener('resize', function(e) { |
+ setTimeout(resizeIframes, 150); |
cjhopman
2015/03/12 02:39:22
How about using an approach like http://flwebsites
mdjones
2015/03/14 02:04:44
Done.
|
+}); |
+ |
+window.addEventListener('load', function(e) { |
+ fillYouTubePlaceholders(); |
+}); |
+ |