-
Notifications
You must be signed in to change notification settings - Fork 8
/
test7.php
109 lines (88 loc) · 3.35 KB
/
test7.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
//create a unique id so we cachebust
$id = uniqid(rand(),true);
?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Media Query Test: Cascade Override for High Resolution</title>
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0" />
<link rel="stylesheet" href="_css/style.css" />
<!-- Test 7 Styles -->
<style type="text/css">
#test7 {background-image:url('images/lowres.png?<?php echo $id; ?>');width:200px;height:75px;}
@media only screen and (-webkit-min-device-pixel-ratio: 1.5),
only screen and (min--moz-device-pixel-ratio: 1.5),
only screen and (-o-min-device-pixel-ratio: 3/2),
only screen and (min-device-pixel-ratio: 1.5)
{
#test7 {background-image:url('images/highres.png?<?php echo $id; ?>');width:200px;height:75px;}
}
</style>
<script type="text/javascript">
var startTime = (new Date().getTime());
</script>
</head>
<body>
<h1>Media Query Image Download Test</h1>
<h2 id="t5">Test Seven: Cascade Override for High Resolution</h2>
<p>
In this test, we start with a background image that is low res. Then we use a CSS media query to replace that background image if the it is a high resolution display.
</p>
<div id="test7"></div>
<h4>HTML Code</h4>
<code><div id="test7"></div></code>
<h4>CSS Code</h4>
<code><style type="text/css">
#test7 {background-image:url('images/lowres.png?<?php echo $id; ?>');width:200px;height:75px;}
@media only screen and (-webkit-min-device-pixel-ratio: 1.5),
only screen and (min--moz-device-pixel-ratio: 1.5),
only screen and (-o-min-device-pixel-ratio: 3/2),
only screen and (min-device-pixel-ratio: 1.5) {
#test7 {background-image:url('images/highres.png?<?php echo $id; ?>');width:200px;height:75px;}
}
</style>
</code>
<div id="loaded">
<h2>Results</h2>
</div>
<?php include('includes/testLinks.inc.php'); ?>
<script type="text/javascript" src="_js/imageTest.js"></script>
<script type="text/javascript" charset="utf-8">
var _bTestResults = {};
window.onload = function() {
//set the domain prefix so we can just pass image names
prefix = 'images/';
//set our suffix
//needed because setting image.src fires request
//this helps us avoid caching messing with the results
suffix = '<?php echo $id; ?>';
//get the div where we'll spit out the results
target = document.getElementById('loaded');
var images = [
['lowres.png', 'Loaded (low res)'],
['highres.png', 'Loaded (high res)']
];
_bTestResults = imageTest(images);
if (window.devicePixelRatio === undefined) {
_bTestResults['Pixel Ratio'] = 0;
} else {
_bTestResults['Pixel Ratio'] = window.devicePixelRatio;
}
target.innerHTML += "<p><strong>window.devicePixelRatio:</strong> " + _bTestResults['Pixel Ratio'] + "</p>";
// Fetch the Browserscope script that sucks the results from _bTestResults
(function() {
var _bTestKey = 'agt1YS1wcm9maWxlcnINCxIEVGVzdBjj-d0ODA';
var _bScript = document.createElement('script');
_bScript.src = 'http://www.browserscope.org/user/beacon/' + _bTestKey;
_bScript.src += '?sandboxid=44f7adc1dd3013d';
_bScript.setAttribute('async', 'true');
var scripts = document.getElementsByTagName('script');
var lastScript = scripts[scripts.length - 1];
lastScript.parentNode.insertBefore(_bScript, lastScript);
})();
}
</script>
</body>
</html>