{"action":"opened","issue":{"url":"https://api.github.com/repos/doanminhvuong/plugin/issues/1","repository_url":"https://api.github.com/repos/doanminhvuong/plugin","labels_url":"https://api.github.com/repos/doanminhvuong/plugin/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/doanminhvuong/plugin/issues/1/comments","events_url":"https://api.github.com/repos/doanminhvuong/plugin/issues/1/events","html_url":"https://github.com/doanminhvuong/plugin/issues/1","id":248232367,"number":1,"title":"sitemap.js","user":{"login":"doanminhvuong","id":30768158,"avatar_url":"https://avatars0.githubusercontent.com/u/30768158?v=4","gravatar_id":"","url":"https://api.github.com/users/doanminhvuong","html_url":"https://github.com/doanminhvuong","followers_url":"https://api.github.com/users/doanminhvuong/followers","following_url":"https://api.github.com/users/doanminhvuong/following{/other_user}","gists_url":"https://api.github.com/users/doanminhvuong/gists{/gist_id}","starred_url":"https://api.github.com/users/doanminhvuong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/doanminhvuong/subscriptions","organizations_url":"https://api.github.com/users/doanminhvuong/orgs","repos_url":"https://api.github.com/users/doanminhvuong/repos","events_url":"https://api.github.com/users/doanminhvuong/events{/privacy}","received_events_url":"https://api.github.com/users/doanminhvuong/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-08-06T08:05:04Z","updated_at":"2017-08-06T08:05:04Z","closed_at":null,"body":"---------------------------------------------------\r\n\r\n\r\n   var postTitle = new Array();     // array of posttitles\r\n   var postUrl = new Array();       // array of posturls\r\n   var postDate = new Array();      // array of post publish dates\r\n   var postSum = new Array();       // array of post summaries\r\n   var postLabels = new Array();    // array of post labels\r\n\r\n// global variables\r\n   var sortBy = \"datenewest\";         // default value for sorting ToC\r\n   var tocLoaded = false;           // true if feed is read and ToC can be displayed\r\n   var numChars = 250;              // number of characters in post summary\r\n   var postFilter = '';             // default filter value\r\n   var tocdiv = document.getElementById(\"bp_toc\"); //the toc container\r\n   var totalEntires =0; //Entries grabbed till now\r\n   var totalPosts =0; //Total number of posts in the blog.\r\n\r\n// main callback function\r\n\r\nfunction loadtoc(json) {\r\n\r\n   function getPostData() {\r\n   // this functions reads all postdata from the json-feed and stores it in arrays\r\n      if (\"entry\" in json.feed) {\r\n         var numEntries = json.feed.entry.length;\r\n         totalEntires = totalEntires + numEntries;\r\n         totalPosts=json.feed.openSearch$totalResults.$t\r\n         if(totalPosts>totalEntires)\r\n         {\r\n         var nextjsoncall = document.createElement('script');\r\n         nextjsoncall.type = 'text/javascript';\r\n         startindex=totalEntires+1;\r\n         nextjsoncall.setAttribute(\"src\", \"/feeds/posts/summary?start-index=\" + startindex + \"&max-results=500&alt=json-in-script&callback=loadtoc\");\r\n         tocdiv.appendChild(nextjsoncall);\r\n         }\r\n      // main loop gets all the entries from the feed\r\n         for (var i = 0; i < numEntries; i++) {\r\n         // get the entry from the feed\r\n            var entry = json.feed.entry[i];\r\n\r\n         // get the posttitle from the entry\r\n            var posttitle = entry.title.$t;\r\n\r\n         // get the post date from the entry\r\n            var postdate = entry.published.$t.substring(0,10);\r\n\r\n         // get the post url from the entry\r\n            var posturl;\r\n            for (var k = 0; k < entry.link.length; k++) {\r\n               if (entry.link[k].rel == 'alternate') {\r\n               posturl = entry.link[k].href;\r\n               break;\r\n               }\r\n            }\r\n\r\n         // get the post contents from the entry\r\n         // strip all html-characters, and reduce it to a summary\r\n            if (\"content\" in entry) {\r\n               var postcontent = entry.content.$t;}\r\n            else\r\n               if (\"summary\" in entry) {\r\n                  var postcontent = entry.summary.$t;}\r\n               else var postcontent = \"\";\r\n         // strip off all html-tags\r\n            var re = /<\\S[^>]*>/g; \r\n            postcontent = postcontent.replace(re, \"\");\r\n         // reduce postcontent to numchar characters, and then cut it off at the last whole word\r\n            if (postcontent.length > numChars) {\r\n               postcontent = postcontent.substring(0,numChars);\r\n               var quoteEnd = postcontent.lastIndexOf(\" \");\r\n               postcontent = postcontent.substring(0,quoteEnd) + '...';\r\n            }\r\n\r\n         // get the post labels from the entry\r\n            var pll = '';\r\n            if (\"category\" in entry) {\r\n               for (var k = 0; k < entry.category.length; k++) {\r\n                  pll += '<a href=\"javascript:filterPosts(\\'' + entry.category[k].term + '\\');\" title=\"Click here to select all posts with label \\'' + entry.category[k].term + '\\'\">' + entry.category[k].term + '</a>,  ';\r\n               }\r\n            var l = pll.lastIndexOf(',');\r\n            if (l != -1) { pll = pll.substring(0,l); }\r\n            }\r\n\r\n         // add the post data to the arrays\r\n            postTitle.push(posttitle);\r\n            postDate.push(postdate);\r\n            postUrl.push(posturl);\r\n            postSum.push(postcontent);\r\n            postLabels.push(pll);\r\n         }\r\n      }\r\n      if(totalEntires==totalPosts) {tocLoaded=true;showToc();}\r\n   } // end of getPostData\r\n\r\n// start of showtoc function body\r\n// get the number of entries that are in the feed\r\n//   numEntries = json.feed.entry.length;\r\n\r\n// get the postdata from the feed\r\n   getPostData();\r\n\r\n// sort the arrays\r\n   sortPosts(sortBy);\r\n   tocLoaded = true;\r\n}\r\n\r\n\r\n\r\n// filter and sort functions\r\n\r\n\r\nfunction filterPosts(filter) {\r\n// This function changes the filter\r\n// and displays the filtered list of posts\r\n  // document.getElementById(\"bp_toc\").scrollTop = document.getElementById(\"bp_toc\").offsetTop;;\r\n   postFilter = filter;\r\n   displayToc(postFilter);\r\n} // end filterPosts\r\n\r\nfunction allPosts() {\r\n// This function resets the filter\r\n// and displays all posts\r\n\r\n   postFilter = '';\r\n   displayToc(postFilter);\r\n} // end allPosts\r\n\r\nfunction sortPosts(sortBy) {\r\n// This function is a simple bubble-sort routine\r\n// that sorts the posts\r\n\r\n   function swapPosts(x,y) {\r\n   // Swaps 2 ToC-entries by swapping all array-elements\r\n      var temp = postTitle[x];\r\n      postTitle[x] = postTitle[y];\r\n      postTitle[y] = temp;\r\n      var temp = postDate[x];\r\n      postDate[x] = postDate[y];\r\n      postDate[y] = temp;\r\n      var temp = postUrl[x];\r\n      postUrl[x] = postUrl[y];\r\n      postUrl[y] = temp;\r\n      var temp = postSum[x];\r\n      postSum[x] = postSum[y];\r\n      postSum[y] = temp;\r\n      var temp = postLabels[x];\r\n      postLabels[x] = postLabels[y];\r\n      postLabels[y] = temp;\r\n   } // end swapPosts\r\n\r\n   for (var i=0; i < postTitle.length-1; i++) {\r\n      for (var j=i+1; j<postTitle.length; j++) {\r\n         if (sortBy == \"titleasc\") { if (postTitle[i] > postTitle[j]) { swapPosts(i,j); } }\r\n         if (sortBy == \"titledesc\") { if (postTitle[i] < postTitle[j]) { swapPosts(i,j); } }\r\n         if (sortBy == \"dateoldest\") { if (postDate[i] > postDate[j]) { swapPosts(i,j); } }\r\n         if (sortBy == \"datenewest\") { if (postDate[i] < postDate[j]) { swapPosts(i,j); } }\r\n      }\r\n   }\r\n} // end sortPosts\r\n\r\n// displaying the toc\r\n\r\nfunction displayToc(filter) {\r\n// this function creates a three-column table and adds it to the screen\r\n   var numDisplayed = 0;\r\n   var tocTable = '';\r\n   var tocHead1 = 'POST TITLE';\r\n   var tocTool1 = 'Click to sort by title';\r\n   var tocHead2 = 'POST DATE';\r\n   var tocTool2 = 'Click to sort by date';\r\n   var tocHead3 = 'LABELS';\r\n   var tocTool3 = '';\r\n   if (sortBy == \"titleasc\") { \r\n      tocTool1 += ' (descending)';\r\n      tocTool2 += ' (newest first)';\r\n   }\r\n   if (sortBy == \"titledesc\") { \r\n      tocTool1 += ' (ascending)';\r\n      tocTool2 += ' (newest first)';\r\n   }\r\n   if (sortBy == \"dateoldest\") { \r\n      tocTool1 += ' (ascending)';\r\n      tocTool2 += ' (newest first)';\r\n   }\r\n   if (sortBy == \"datenewest\") { \r\n      tocTool1 += ' (ascending)';\r\n      tocTool2 += ' (oldest first)';\r\n   }\r\n   if (postFilter != '') {\r\n      tocTool3 = 'Click to show all posts';\r\n   }\r\n   tocTable += '<table>';\r\n   tocTable += '<tr>';\r\n   tocTable += '<td class=\"toc-header-col1\">';\r\n   tocTable += '<a href=\"javascript:toggleTitleSort();\" title=\"' + tocTool1 + '\">' + tocHead1 + '</a>';\r\n   tocTable += '</td>';\r\n   tocTable += '<td class=\"toc-header-col2\">';\r\n   tocTable += '<a href=\"javascript:toggleDateSort();\" title=\"' + tocTool2 + '\">' + tocHead2 + '</a>';\r\n   tocTable += '</td>';\r\n   tocTable += '<td class=\"toc-header-col3\">';\r\n   tocTable += '<a href=\"javascript:allPosts();\" title=\"' + tocTool3 + '\">' + tocHead3 + '</a>';\r\n   tocTable += '</td>';\r\n   tocTable += '</tr>';\r\n   for (var i = 0; i < postTitle.length; i++) {\r\n      if (filter == '') {\r\n         tocTable += '<tr><td class=\"toc-entry-col1\"><a href=\"' + postUrl[i] + '\" title=\"' + postSum[i] + '\">' + postTitle[i] + '</a></td><td class=\"toc-entry-col2\">' + postDate[i] + '</td><td class=\"toc-entry-col3\">' + postLabels[i] + '</td></tr>';\r\n         numDisplayed++;\r\n      } else {\r\n          z = postLabels[i].lastIndexOf(filter);\r\n          if ( z!= -1) {\r\n             tocTable += '<tr><td class=\"toc-entry-col1\"><a href=\"' + postUrl[i] + '\" title=\"' + postSum[i] + '\">' + postTitle[i] + '</a></td><td class=\"toc-entry-col2\">' + postDate[i] + '</td><td class=\"toc-entry-col3\">' + postLabels[i] + '</td></tr>';\r\n             numDisplayed++;\r\n          }\r\n        }\r\n   }\r\n   tocTable += '</table>';\r\n   if (numDisplayed == postTitle.length) {\r\n      var tocNote = '<span class=\"toc-note\">Displaying all ' + postTitle.length + ' posts<br/></span>'; }\r\n   else {\r\n      var tocNote = '<span class=\"toc-note\">Displaying ' + numDisplayed + ' posts labeled \\'';\r\n      tocNote += postFilter + '\\' of '+ postTitle.length + ' posts total<br/></span>';\r\n   }\r\n   tocdiv.innerHTML = tocNote + tocTable;\r\n} // end of displayToc\r\n\r\nfunction toggleTitleSort() {\r\n   if (sortBy == \"titleasc\") { sortBy = \"titledesc\"; }\r\n   else { sortBy = \"titleasc\"; }\r\n   sortPosts(sortBy);\r\n   displayToc(postFilter);\r\n} // end toggleTitleSort\r\n\r\nfunction toggleDateSort() {\r\n   if (sortBy == \"datenewest\") { sortBy = \"dateoldest\"; }\r\n   else { sortBy = \"datenewest\"; }\r\n   sortPosts(sortBy);\r\n   displayToc(postFilter);\r\n} // end toggleTitleSort\r\n\r\n\r\nfunction showToc() {\r\n  if (tocLoaded) { \r\n     displayToc(postFilter);\r\n     var toclink = document.getElementById(\"toclink\");\r\n   \r\n  }\r\n  else { alert(\"Just wait... TOC is loading\"); }\r\n}\r\n\r\nfunction hideToc() {\r\n  var tocdiv = document.getElementById(\"toc\");\r\n  tocdiv.innerHTML = '';\r\n  var toclink = document.getElementById(\"toclink\");\r\n  toclink.innerHTML = '<a href=\"#\" onclick=\"scroll(0,0); showToc(); Effect.toggle('+\"'toc-result','blind');\"+'\">� Show Table of Contents</a> <img src=\"https://1.bp.blogspot.com/-MMsDm64XZtM/VzQD8tvFJ-I/AAAAAAAAXhk/L2JgChUq2_w0vZHuPhaPGp_xGuA_YDaKQCLcB/s1600/new_1.gif\"/>';\r\n}"}}
{"actor":{"display_login":"doanminhvuong"}}