HTML and CSS Reference
In-Depth Information
script.src = 'http://search.twitter.com/search.
¬
json?q=html5 -RT&rpp=100&callback=saveTweets';
document.body.appendChild(script);
}
// our Twitter API callback function
function saveTweets(tweets) {
tweets.results.forEach(function (tweet) {
db.transaction(function (tx) {
var time = (new Date(Date.parse(tweet.created_at))).
¬
getTime();
tx.executeSql('INSERT INTO tweets (id, screen_name,
¬
date, text) VALUES (?, ?, ?, ?)', [tweet.id,
¬
tweet.from_user, time / 1000, tweet.text]);
¬
// divide by 1000 to get to seconds
});
});
}
function show(amount) {
db.transaction(function (tx) {
tx.executeSql('SELECT * FROM tweets' + (amount !=
¬
'all' ? ' WHERE date > strftime(“%s”, “now”, “-' +
¬
amount + ' minutes”)' : ''), [], function
¬
(tx, results) {
var html = [],
len = results.rows.length;
for (var i = 0; i < len; i++) {
html.push('<li>' + results.rows.item(i).text +
¬
'</li>');
}
tweetEl.innerHTML = html.join('');
});
});
}
// bind the click handlers for the radio buttons
[].forEach.call(document.querySelectorAll('input
¬
[type=radio]'), function (el) {
el.onclick = function () {
show(this.value);
}