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) { |
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 fillYouTubePlaceholders() { | |
13 var placeholders = document.getElementsByClassName("embed-placeholder"); | |
cjhopman
2015/03/19 03:34:47
s/"/'/g
mdjones
2015/03/19 18:08:39
Done.
| |
14 for (var i = 0; i < placeholders.length; i++) { | |
15 if (!placeholders[i].hasAttribute('data-type') || | |
16 placeholders[i].getAttribute('data-type') != 'youtube' || | |
17 !placeholders[i].hasAttribute('data-id')) { | |
18 continue; | |
19 } | |
20 var embed = document.createElement('iframe'); | |
21 var url = 'http://www.youtube.com/embed/' + | |
22 placeholders[i].getAttribute('data-id'); | |
23 embed.setAttribute('class', 'youtubeIframe'); | |
24 embed.setAttribute('src', url); | |
25 embed.setAttribute('type', 'text/html'); | |
26 embed.setAttribute('frameborder', '0'); | |
27 | |
28 var parent = placeholders[i].parentElement; | |
29 var width = parent.clientWidth; | |
30 var hdMult = 1080.0 / 1920.0; // YouTube frame width/height is always HD. | |
31 embed.setAttribute('width', width); | |
32 embed.setAttribute('height', width * hdMult); | |
cjhopman
2015/03/19 03:34:47
Are these needed? Aren't they set by css now?
mdjones
2015/03/19 18:08:39
Done.
| |
33 | |
34 var container = document.createElement('div'); | |
35 container.setAttribute('class', 'youtubeContainer'); | |
36 container.appendChild(embed); | |
37 | |
38 parent.replaceChild(container, placeholders[i]); | |
39 } | |
9 } | 40 } |
10 | 41 |
11 function showLoadingIndicator(isLastPage) { | 42 function showLoadingIndicator(isLastPage) { |
12 document.getElementById('loadingIndicator').className = | 43 document.getElementById('loadingIndicator').className = |
13 isLastPage ? 'hidden' : 'visible'; | 44 isLastPage ? 'hidden' : 'visible'; |
14 updateLoadingIndicator(isLastPage); | 45 updateLoadingIndicator(isLastPage); |
15 } | 46 } |
16 | 47 |
17 // Maps JS Font Family to CSS class and then changes body class name. | 48 // Maps JS Font Family to CSS class and then changes body class name. |
18 // CSS classes must agree with distilledpage.css. | 49 // CSS classes must agree with distilledpage.css. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 }; | 97 }; |
67 }(); | 98 }(); |
68 | 99 |
69 // Add a listener to the "View Original" link to report opt-outs. | 100 // Add a listener to the "View Original" link to report opt-outs. |
70 document.getElementById('showOriginal').addEventListener('click', function(e) { | 101 document.getElementById('showOriginal').addEventListener('click', function(e) { |
71 var img = document.createElement('img'); | 102 var img = document.createElement('img'); |
72 img.src = "/vieworiginal"; | 103 img.src = "/vieworiginal"; |
73 img.style.display = "none"; | 104 img.style.display = "none"; |
74 document.body.appendChild(img); | 105 document.body.appendChild(img); |
75 }, true); | 106 }, true); |
76 | |
OLD | NEW |