OLD | NEW |
1 <?php | 1 <?php |
2 header("ACCEPT-CH: DPR, Width, Viewport-Width"); | 2 header("ACCEPT-CH: DPR, Width, Viewport-Width"); |
3 ?> | 3 ?> |
4 <!DOCTYPE html> | 4 <!DOCTYPE html> |
5 <body> | 5 <body> |
6 <script> | 6 <script> |
7 window.addEventListener("message", function (message) { | 7 window.addEventListener("message", function (message) { |
8 var pic = document.getElementById("pic"); | 8 var pic = document.getElementById("pic"); |
9 pic.removeChild(pic.childNodes[0]); | 9 pic.removeChild(document.getElementById("firstsource")); |
10 // TODO(yoav): this should trigger a load, but doesn't. See https://crbu
g.com/418903 | 10 setTimeout(function(){fail(4);}, 200); |
11 success(); | |
12 }); | 11 }); |
13 | 12 |
14 var fail = function(num) { | 13 var fail = function(num) { |
15 parent.postMessage("fail "+ num, "*"); | 14 parent.postMessage("fail "+ num, "*"); |
16 }; | 15 }; |
17 | 16 |
18 var success = function() { | 17 var success = function() { |
19 parent.postMessage("success", "*"); | 18 parent.postMessage("success", "*"); |
20 }; | 19 }; |
21 | 20 |
22 var remove = function() { | 21 var remove = function() { |
23 parent.postMessage("remove", "*"); | 22 parent.postMessage("remove", "*"); |
24 }; | 23 }; |
25 | 24 |
26 var counter = 1; | 25 var counter = 1; |
27 var error = function() { | 26 var error = function() { |
28 fail(counter); | 27 fail(counter); |
29 } | 28 } |
30 var load = function() { | 29 var load = function() { |
31 if (counter == 1) { | 30 if (counter == 1) { |
32 ++counter; | 31 ++counter; |
33 remove(); | 32 remove(); |
34 return; | 33 return; |
35 } | 34 } |
36 success(); | 35 success(); |
37 } | 36 } |
38 </script> | 37 </script> |
39 <picture id=pic> | 38 <picture id=pic> |
40 <source sizes="50vw" media="(min-width: 800px)" srcset="image-checks-for-wid
th.php?rw=400"> | 39 <source sizes="50vw" id="firstsource" media="(min-width: 800px)" srcset="ima
ge-checks-for-width.php?rw=400"> |
41 <source sizes="50vw" srcset="image-checks-for-width.php?rw=300"> | 40 <source sizes="40vw" srcset="image-checks-for-width.php?rw=320"> |
42 <img onerror="error()" onload="load()"> | 41 <img onerror="error()" onload="load()"> |
43 </picture> | 42 </picture> |
OLD | NEW |