Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // For an introduction to the Grid template, see the following documentation:
- // http://go.microsoft.com/fwlink/?LinkID=232446
- (function () {
- "use strict";
- WinJS.Binding.optimizeBindingReferences = true;
- var app = WinJS.Application;
- var activation = Windows.ApplicationModel.Activation;
- var nav = WinJS.Navigation;
- var blogButton, homeButton;
- var articlesList;
- app.addEventListener("activated", function (args) {
- if (args.detail.kind === activation.ActivationKind.launch) {
- if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
- // TODO: This application has been newly launched. Initialize
- // your application here.
- } else {
- // TODO: This application has been reactivated from suspension.
- // Restore application state here.
- }
- if (app.sessionState.history) {
- nav.history = app.sessionState.history;
- }
- var articlelistElement = document.getElementById("articlelist");
- articlesList = new WinJS.Binding.List();
- var publicMembers = { ItemList: articlesList };
- WinJS.Namespace.define("C9Data", publicMembers);
- args.setPromise(WinJS.UI.processAll().then(function () {
- downloadC9BlogFeed();
- var appBar = document.getElementById("appbar").winControl;
- homeButton = appBar.getCommandById("homeButton");
- homeButton.addEventListener("click", goToHome, false);
- blogButton = appBar.getCommandById("blogButton");
- blogButton.addEventListener("click", goToBlog, false);
- if (nav.location) {
- nav.history.current.initialPlaceholder = true;
- return nav.navigate(nav.location, nav.state);
- } else {
- return nav.navigate(Application.navigator.home);
- }
- }));
- }
- });
- function downloadC9BlogFeed() {
- WinJS.xhr({ url: "http://rutamaya501.blogspot.com/feeds/posts/default?alt=rss" }).then(function (rss) {
- var items = rss.responseXML.querySelectorAll("item");
- for (var n = 0; n < items.length; n++) {
- var article = {};
- article.title = items[n].querySelector("title").textContent;
- article.content = items[n].querySelector("description").textContent;
- var contentTag = null;
- var contentTagsUsed = ["encoded", "description", "content"];
- contentTagsUsed.forEach(function (t) {
- if (items[n].querySelector(t) != null && contentTag == null)
- contentTag = t;
- });
- var imgInContent = /<img [^>]*src="([^"]*)"[^>]*\/>/.exec(items[n].querySelector(contentTag).textContent);
- var imageUrl;
- if (items[n].querySelector("enclosure") != null)
- imageUrl = items[n].querySelector("enclosure").attributes.url.value;
- else if (items[n].querySelector("img") != null)
- imageUrl = items[n].querySelector("img").attributes.src.value;
- else if (imgInContent != null)
- imageUrl = imgInContent[1];
- article.thumbnail = imageUrl;
- articlesList.push(article);
- }
- });
- }
- function goToHome(eventInfo) {
- WinJS.Navigation.navigate("/pages/groupedItems/groupedItems.html");
- }
- function goToBlog(eventInfo) {
- WinJS.Navigation.navigate("/pages/rssPage/rssPage.html");
- }
- app.oncheckpoint = function (args) {
- // TODO: This application is about to be suspended. Save any state
- // that needs to persist across suspensions here. If you need to
- // complete an asynchronous operation before your application is
- // suspended, call args.setPromise().
- app.sessionState.history = nav.history;
- };
- app.start();
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement