Skip to content

Instantly share code, notes, and snippets.

@chardcastle
Created December 6, 2010 23:15
Show Gist options
  • Save chardcastle/731185 to your computer and use it in GitHub Desktop.
Save chardcastle/731185 to your computer and use it in GitHub Desktop.
Uses JQuery and a little HTML to run records from a CouchDB instance like a slide show.
<!Doctype html>
<html>
<head>
<script type="text/javascript" src="http://google.com/jsapi"></script>
<script type="text/javascript">
google.load('jquery','1.3.2')
</script>
</head>
<style type="text/css">
#thumb{
width:1%;
height:10px;
background:#b5000b;
}
#track{
background:#ccc;
width:500px;
}
</style>
<body>
<h1>Replicated data from Wikileaks</h1>
<p>This is a JSONP request to my <a href="http://hardcastle.couchone.com/_utils/">couchone</a> instance wich is in continious replication with another mirror of wikileaks. Just a technical exercise and for my own interest.</p>
Time till next summary:
<?php // Display a small indication of time ?>
<div id="track">
<div id="thumb"></div>
</div>
<?php // Destination for article summary ?>
<div id="news">&nbsp;</div>
<script type="text/javascript">
/**
* Global object to contain all methods and data
*/
var hardcastle = hardcastle || {};
var hardcastle = {
next:0,
skip:0,
// CouchDB adress to database design resource. Currently uses the example document
// and foo method
url:'http://hardcastle.couchone.com/wikileaks/_design/example/_view/foo',
get: function(){
// Make cross domain request
// Required for accessing information from the couchone.com domain
$.ajax({
dataType: 'jsonp',
data: 'limit=10&skip='+hardcastle.skip+'&callback=?',
jsonp: 'jsonp_callback',
url: hardcastle.url,
success: function (data) {
// Is called once the request for data has completed (AJAX) has completed
var limit = data['rows'].length;
// Call method within this object called "show"
hardcastle.show(data['rows'],0,limit);
},
});
},
show:function(data,index,limit)
{
if(index >= limit){
// Get more records
hardcastle.skip = limit + limit;
hardcastle.get();
}else{
// Add one to the internal pointer
hardcastle.next = index + 1;
// Reset the timer, by restoring slider to original size
$('body')
.find('#thumb')
.css('width','100%')
.end()
.find('#news')
// Add the news summary to the HTML target
.html(data[index]['value'])
.end()
.find('#thumb')
.animate({width:0},5000,function(){
// Once animation is complete - run the function again
hardcastle.show(data, hardcastle.next, limit);
})
.end();
}
}
}
// Once the dom is ready, run the function
$(function(){
hardcastle.get();
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment