From c43a64701e518393672802387ef9665ebd8f2a7b Mon Sep 17 00:00:00 2001 From: pingjiang Date: Sat, 19 Jul 2014 10:35:50 +0800 Subject: [PATCH 1/3] Add summary file. --- summary.html | 172 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 172 insertions(+) create mode 100644 summary.html diff --git a/summary.html b/summary.html new file mode 100644 index 00000000..872e453f --- /dev/null +++ b/summary.html @@ -0,0 +1,172 @@ + + + + + All programming hello world code + + + + + + + + + + +
+
+ + + + +
+
+
    +
  • +

    Hello world in every programming language.

    +
    + +
    +
  • +
+
+ +
+
+ +

+ © 2014 Powered by jQuery, Boostrap and Github APIs. +

+
+ + + + + + + + + + + \ No newline at end of file From eac170562bb45b6b0d431a717ea75b58a4c32ba3 Mon Sep 17 00:00:00 2001 From: pingjiang Date: Sat, 19 Jul 2014 11:07:41 +0800 Subject: [PATCH 2/3] Fetch Code Content Content is decoded using atob, which would cause problem on old browsers. --- summary.html | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/summary.html b/summary.html index 872e453f..0e3b5994 100644 --- a/summary.html +++ b/summary.html @@ -67,7 +67,7 @@ // curl -i https://api.github.com/repos/pingjiang/hello-world/readme // curl -i https://api.github.com/repos/pingjiang/hello-world/contents/ jQuery(document).ready(function($) { - var REPOS_USER = 'pingjiang'; + var REPOS_USER = 'leachim6';// leachim6 var REPOS_NAME = 'hello-world'; var GITHUB_API = 'https://api.github.com/repos/' + REPOS_USER + '/' + REPOS_NAME + '/contents'; @@ -83,8 +83,31 @@ + data.documentation_url + '.

Please refresh later.

'); } + function loadContent(self_url, onSuccess) { + $.ajax({ + type: "POST", + url: self_url + '&callback=?', + crossDomain: true, + statusCode: { + 403: function(data) { + onGithubError(data); + } + }, + success: function (data) { + var result = data.data; + // console.log(result); + if (result.content == undefined || result.content == null) { + // onGithubError(result); + return; + } + var content = atob(result.content); + onSuccess(content); + }, + dataType: 'jsonp' + }); + } + function loadLanguages(langGroupName, appendToId, langGroup, onSuccess) { - // console.log('Load languages: ' + langGroupName + ', ' + langGroup); $.ajax({ type: "POST", url: langGroup + '&callback=?', @@ -101,12 +124,12 @@ return; } $.each(entries, function(i, entry) { - // console.log(entry.type + ' => ' + entry.name); if (entry.type == 'file') { - // console.log($(tabId + '>ul.langcodes')); - $('
  • ' + entry.name - + '

  • ').appendTo(appendToId); + loadContent(entry._links.self, function(content) { + $('
  • ' + entry.name + + '

    ' + content + '

    Code: ' + + entry.html_url + '

  • ').appendTo(appendToId); + }); } }); From 4db0a8501d620ca0b84bb0e69473625e2c01a942 Mon Sep 17 00:00:00 2001 From: pingjiang Date: Sat, 19 Jul 2014 11:37:31 +0800 Subject: [PATCH 3/3] Show code content --- summary.html | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/summary.html b/summary.html index 0e3b5994..1f9a887b 100644 --- a/summary.html +++ b/summary.html @@ -83,6 +83,14 @@ + data.documentation_url + '.

    Please refresh later.

    '); } + function htmlEncode(value){ + return $('
    ').text(value).html(); + } + + function htmlDecode(value){ + return $('
    ').html(value).text(); + } + function loadContent(self_url, onSuccess) { $.ajax({ type: "POST", @@ -95,9 +103,8 @@ }, success: function (data) { var result = data.data; - // console.log(result); if (result.content == undefined || result.content == null) { - // onGithubError(result); + onSuccess('Fetch content of code ' + self_url + ' failed.'); return; } var content = atob(result.content); @@ -125,9 +132,11 @@ } $.each(entries, function(i, entry) { if (entry.type == 'file') { + var codeCssClass = 'code-' + entry.name.split('.')[0].toLowerCase(); loadContent(entry._links.self, function(content) { + // console.log(content); $('
  • ' + entry.name - + '

  • ').appendTo(appendToId); }); }