Created
November 7, 2014 15:54
-
-
Save poonkave/4f011855bbce36718f3b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css" /> | |
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script> | |
<script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script> | |
<script type="text/javascript" src="https://www.google.com/jsapi"></script> | |
<script type="text/javascript"> | |
(function () { | |
var googleResult = []; | |
var newsTopic = "w"; | |
function initialize() { | |
var feed = new google.feeds.Feed("https://news.google.com/news/feeds?pz=1&cf=all&ned=en_ie&hl=en&topic=" + newsTopic + "&output=rss"); | |
feed.setResultFormat(google.feeds.Feed.JSON_FORMAT); | |
//feed.includeHistoricalEntries(); | |
feed.setNumEntries(100); | |
feed.load(function (result) { | |
if (!result.error) { | |
googleResult = result; | |
var output = '<ul data-role="listview" xdata-filter="true">'; | |
var container = document.getElementById("feed"); | |
for (var i = 0; i < result.feed.entries.length; i++) { | |
var entry = result.feed.entries[i]; | |
output += '<li>'; | |
output += '<a href= "#feedContent?i=' + i + '" >'; | |
output += '<h1>' + entry.title + '</h1>'; | |
output += '<p>' + entry.contentSnippet + '</p>'; | |
output += '</a>'; | |
output += '</li>'; | |
} | |
output += '</ul>'; | |
$('#newsList').html(output); | |
$('#newsList').trigger('create'); | |
$.mobile.loading("hide"); | |
} | |
}); | |
}; | |
google.load("feeds", "1"); | |
google.setOnLoadCallback(initialize); | |
$(document).on("pagebeforechange", function (e, data) { | |
// We only want to handle changePage() calls where the caller is | |
// asking us to load a page by URL | |
if (typeof data.toPage === "string") { | |
// We are being asked to load a page by URL | |
var u = $.mobile.path.parseUrl(data.toPage), | |
_re = "#feedContent"; | |
if (u.hash.search(_re) !== -1) { | |
var i = urlParam("i", data.toPage); | |
$("#feedContent").remove(); | |
var $page = $("<div data-role='page' id='feedContent' data-add-back-btn='true'><div data-role='header'><h1>" + googleResult.feed.entries[i].title + "</h1></div></div>"); | |
var $content = $("<div data-role='content' id='feedContent'></div>"); | |
$content.append(googleResult.feed.entries[i].content); | |
$page.append($content); | |
$.mobile.pageContainer.append($page); | |
} | |
_re = "#feeds"; | |
if (u.hash.search(_re) !== -1) { | |
newsTopic = urlParam("topic", data.toPage); | |
e.preventDefault(); | |
$.mobile.loading("show"); | |
initialize(); | |
return; | |
} | |
} | |
}); | |
// Determine url param | |
var urlParam = function (name, url) { | |
var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(url); | |
return results !== null ? results[1] || "" : ""; | |
} | |
})(); | |
</script> | |
</head> | |
<body> | |
<div data-role="page" id="newsFeed"> | |
<div data-role="header"> | |
<h1>Google News feeds</h1> | |
</div> | |
<div data-role="content" id="newsList"> | |
</div> | |
<div data-role="footer" data-id="foo1" data-position="fixed"> | |
<div data-role="navbar"> | |
<ul> | |
<li><a href="#feeds?topic=w" class="ui-btn-active ui-state-persist">World</a></li> | |
<li><a href="#feeds?topic=h">Health</a></li> | |
<li><a href="#feeds?topic=s">Sports</a></li> | |
<li><a href="#feeds?topic=b">Business</a></li> | |
</ul> | |
</div> | |
<!-- /navbar --> | |
</div> | |
<!-- /footer --> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment