Advertisement
FANMixco

default.js

Feb 6th, 2013
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. // For an introduction to the Grid template, see the following documentation:
  2. // http://go.microsoft.com/fwlink/?LinkID=232446
  3. (function () {
  4. "use strict";
  5.  
  6. WinJS.Binding.optimizeBindingReferences = true;
  7.  
  8. var app = WinJS.Application;
  9. var activation = Windows.ApplicationModel.Activation;
  10. var nav = WinJS.Navigation;
  11. var blogButton, homeButton;
  12. var articlesList;
  13.  
  14. app.addEventListener("activated", function (args) {
  15. if (args.detail.kind === activation.ActivationKind.launch) {
  16. if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
  17. // TODO: This application has been newly launched. Initialize
  18. // your application here.
  19. } else {
  20. // TODO: This application has been reactivated from suspension.
  21. // Restore application state here.
  22. }
  23.  
  24. if (app.sessionState.history) {
  25. nav.history = app.sessionState.history;
  26. }
  27.  
  28. var articlelistElement = document.getElementById("articlelist");
  29.  
  30. articlesList = new WinJS.Binding.List();
  31. var publicMembers = { ItemList: articlesList };
  32. WinJS.Namespace.define("C9Data", publicMembers);
  33.  
  34. args.setPromise(WinJS.UI.processAll().then(function () {
  35.  
  36. downloadC9BlogFeed();
  37.  
  38. var appBar = document.getElementById("appbar").winControl;
  39.  
  40. homeButton = appBar.getCommandById("homeButton");
  41. homeButton.addEventListener("click", goToHome, false);
  42.  
  43. blogButton = appBar.getCommandById("blogButton");
  44. blogButton.addEventListener("click", goToBlog, false);
  45.  
  46.  
  47. if (nav.location) {
  48. nav.history.current.initialPlaceholder = true;
  49. return nav.navigate(nav.location, nav.state);
  50. } else {
  51. return nav.navigate(Application.navigator.home);
  52. }
  53. }));
  54. }
  55. });
  56.  
  57. function downloadC9BlogFeed() {
  58. WinJS.xhr({ url: "http://rutamaya501.blogspot.com/feeds/posts/default?alt=rss" }).then(function (rss) {
  59. var items = rss.responseXML.querySelectorAll("item");
  60.  
  61. for (var n = 0; n < items.length; n++) {
  62. var article = {};
  63. article.title = items[n].querySelector("title").textContent;
  64. article.content = items[n].querySelector("description").textContent;
  65. var contentTag = null;
  66. var contentTagsUsed = ["encoded", "description", "content"];
  67. contentTagsUsed.forEach(function (t) {
  68. if (items[n].querySelector(t) != null && contentTag == null)
  69. contentTag = t;
  70. });
  71. var imgInContent = /<img [^>]*src="([^"]*)"[^>]*\/>/.exec(items[n].querySelector(contentTag).textContent);
  72. var imageUrl;
  73. if (items[n].querySelector("enclosure") != null)
  74. imageUrl = items[n].querySelector("enclosure").attributes.url.value;
  75. else if (items[n].querySelector("img") != null)
  76. imageUrl = items[n].querySelector("img").attributes.src.value;
  77. else if (imgInContent != null)
  78. imageUrl = imgInContent[1];
  79.  
  80. article.thumbnail = imageUrl;
  81. articlesList.push(article);
  82.  
  83. }
  84. });
  85. }
  86.  
  87. function goToHome(eventInfo) {
  88. WinJS.Navigation.navigate("/pages/groupedItems/groupedItems.html");
  89. }
  90.  
  91. function goToBlog(eventInfo) {
  92. WinJS.Navigation.navigate("/pages/rssPage/rssPage.html");
  93. }
  94.  
  95. app.oncheckpoint = function (args) {
  96. // TODO: This application is about to be suspended. Save any state
  97. // that needs to persist across suspensions here. If you need to
  98. // complete an asynchronous operation before your application is
  99. // suspended, call args.setPromise().
  100. app.sessionState.history = nav.history;
  101. };
  102.  
  103. app.start();
  104. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement