public
Description: Alpha repository for DUI.Stream. When it stabilizes, it will be merged back into DUI.
Homepage:
Clone URL: git://github.com/digg/stream.git
stream / advancedImageDemoCache.php
100644 100 lines (82 sloc) 3.109 kb
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
<?php
    /**
* Advanced Image Demo with Cache
*
* @author goffinet
* @version $Id$
* @copyright Digg Inc., 22 April, 2009
* @package default
**/
 
    $images = array(
            "img/advanced/dfltr.png",
            "img/advanced/dtrinh.png",
            "img/advanced/jstump.png",
            "img/advanced/lenn0x.png",
            "img/advanced/op12.png",
            "img/advanced/phatduckk.png",
            "img/advanced/sfrench.png",
            "img/advanced/thejakemarsh.png",
        );
    if ($_COOKIE["MXHR_Cached"]) {
        $cached = true;
    } else {
        setcookie("MXHR_Cached", "1");
        $cached = false;
    }
    
    function array2js($array)
    {
        $newArray = array();
        foreach($array as $val) {
            $newArray[] = "'" . $val . "'";
        }
        return "[" . implode(',',$newArray) . "]";
    }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
 
<head><title></title>
 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script type="text/javascript" src="js/DUI.js"></script>
<script type="text/javascript" src="js/Stream.js"></script>
<style type="text/css">
body{font-family:arial,helvetica,sans-serif;}
h1, h2, h3 {text-align:center;}
.column {width:50%; float:left;}
#stream {border: 4px solid #90B557; margin: 0pt auto; padding: 4px; width: 300px; -moz-border-radius: 3px; -webkit-border-radius: 3px; background: #ecffe1;}
#normal {border: 4px solid #5481AC; margin: 0pt auto; padding: 4px; width: 300px; -moz-border-radius: 3px; -webkit-border-radius: 3px; background: #edf2ff;}
</style>
</head>
 
<body>
 
<h1>DUI.Stream: Better living through MXHR</h1>
<h3>Advanced Image Demo with Caching</h3>
<div class="column" id="image_data">
<?php if ($cached): ?>
<div id="cached">
<?php foreach ($images as $img): ?><img src="<?php echo $img ?>?cache=MXHR" width="48" height="48"/><?php endforeach ?>
</div>
<?php else: ?>
<?php endif ?>
</div>
 
<script type="text/javascript">
 
if($.browser.msie) {
alert('Sorry, IE still handles object tags kind of stupidly, so this demo won\'t work for you yet. Try it in Firefox, it\'s pretty cool :)');
} else {
 
var s = new DUI.Stream();
if ($("#cached").length == 0) {
s.listen('image/png', function(payload) {
$('#image_data').append('<object type="image/png" data="data:image/gif;base64,' + payload + '" width="48" height="48"></object>');
});
s.listen('complete', function() {
var images = <?php echo array2js($images) ?>;
imgs = "";
for (var i = 0; i < images.length; i++) {
imgs += '<img src="' + images[i] + '?cache=MXHR" width="48" height="48" style="visibility:hidden"/>';
}
$(document.body).append(imgs);
});
s.load('testAdvancedImageData.php');
}
}
 
</script>
 
 
</body>
 
</html>