Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 function addToPage(html) { | 5 function addToPage(html) { |
|
cjhopman
2015/03/12 02:39:22
Is this only called for pages 2+? Maybe we should
mdjones
2015/03/14 02:04:44
Done.
| |
| 6 var div = document.createElement('div'); | 6 var div = document.createElement('div'); |
| 7 div.innerHTML = html; | 7 div.innerHTML = html; |
| 8 document.getElementById('content').appendChild(div); | 8 document.getElementById('content').appendChild(div); |
| 9 fillYouTubePlaceholders(); | |
| 10 } | |
| 11 | |
| 12 function resizeIframes() { | |
| 13 iframeList = document.getElementsByTagName('iframe'); | |
| 14 for (var i = 0; i < iframeList.length; i++) { | |
| 15 var ratio = iframeList[i].clientHeight / iframeList[i].clientWidth; | |
| 16 iframeList[i].width = iframeList[i].parentElement.clientWidth; | |
| 17 iframeList[i].height = iframeList[i].parentElement.clientWidth * ratio; | |
| 18 } | |
| 19 } | |
| 20 | |
| 21 function fillYouTubePlaceholders() { | |
| 22 var placeholders = document.getElementsByClassName("embed-placeholder"); | |
| 23 for (var i = 0; i < placeholders.length; i++) { | |
| 24 if (!placeholders[i].hasAttribute('data-type') || | |
| 25 placeholders[i].getAttribute('data-type') != 'youtube' || | |
| 26 !placeholders[i].hasAttribute('data-id')) { | |
| 27 continue; | |
| 28 } | |
| 29 var embed = document.createElement('iframe'); | |
| 30 var url = 'http://www.youtube.com/embed/' + | |
| 31 placeholders[i].getAttribute('data-id'); | |
| 32 embed.setAttribute('src', url); | |
| 33 embed.setAttribute('type', 'text/html'); | |
| 34 embed.setAttribute('frameborder', '0'); | |
| 35 | |
| 36 var parent = placeholders[i].parentElement; | |
| 37 var width = parent.clientWidth; | |
| 38 var hdMult = 1080.0 / 1920.0; // YouTube frame width/height is always HD. | |
| 39 embed.setAttribute('width', width); | |
| 40 embed.setAttribute('height', width * hdMult); | |
| 41 | |
| 42 parent.replaceChild(embed, placeholders[i]); | |
| 43 } | |
| 9 } | 44 } |
| 10 | 45 |
| 11 function showLoadingIndicator(isLastPage) { | 46 function showLoadingIndicator(isLastPage) { |
| 12 document.getElementById('loadingIndicator').className = | 47 document.getElementById('loadingIndicator').className = |
| 13 isLastPage ? 'hidden' : 'visible'; | 48 isLastPage ? 'hidden' : 'visible'; |
| 14 updateLoadingIndicator(isLastPage); | 49 updateLoadingIndicator(isLastPage); |
| 15 } | 50 } |
| 16 | 51 |
| 17 // Maps JS Font Family to CSS class and then changes body class name. | 52 // Maps JS Font Family to CSS class and then changes body class name. |
| 18 // CSS classes must agree with distilledpage.css. | 53 // CSS classes must agree with distilledpage.css. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 }(); | 102 }(); |
| 68 | 103 |
| 69 // Add a listener to the "View Original" link to report opt-outs. | 104 // Add a listener to the "View Original" link to report opt-outs. |
| 70 document.getElementById('showOriginal').addEventListener('click', function(e) { | 105 document.getElementById('showOriginal').addEventListener('click', function(e) { |
| 71 var img = document.createElement('img'); | 106 var img = document.createElement('img'); |
| 72 img.src = "/vieworiginal"; | 107 img.src = "/vieworiginal"; |
| 73 img.style.display = "none"; | 108 img.style.display = "none"; |
| 74 document.body.appendChild(img); | 109 document.body.appendChild(img); |
| 75 }, true); | 110 }, true); |
| 76 | 111 |
| 112 window.addEventListener('orientationchange', function(e) { | |
| 113 // Wait for the page to have actually updated before resizing. | |
| 114 setTimeout(resizeIframes, 150); | |
| 115 }); | |
| 116 | |
| 117 window.addEventListener('resize', function(e) { | |
| 118 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.
| |
| 119 }); | |
| 120 | |
| 121 window.addEventListener('load', function(e) { | |
| 122 fillYouTubePlaceholders(); | |
| 123 }); | |
| 124 | |
| OLD | NEW |