|
1 | 1 | /*
|
2 |
| - * jQuery Github Repos v0.3.1 |
| 2 | + * jQuery Github Repos v0.2.2 |
3 | 3 | * A jQuery plugin to display your Github Repositories.
|
4 | 4 | * http://git.io/3A1RMg
|
5 | 5 | *
|
|
49 | 49 | Plugin.prototype.init = function () {
|
50 | 50 |
|
51 | 51 | var self = this;
|
| 52 | + var cached = sessionStorage.getItem('gh-repos:' + this.repo); |
| 53 | + |
| 54 | + // Attempt to get cached repo data |
| 55 | + if (window.sessionStorage && (cached != null)) { |
| 56 | + self.applyTemplate(JSON.parse(cached)); |
| 57 | + } |
| 58 | + else { |
52 | 59 |
|
53 | 60 | $.ajax({
|
54 | 61 | url: 'https://api.github.com/repos/' + this.repo,
|
|
61 | 68 | return;
|
62 | 69 | }
|
63 | 70 | else {
|
| 71 | + |
64 | 72 | self.applyTemplate(results.data);
|
| 73 | + |
| 74 | + // Cache data |
| 75 | + if (window.sessionStorage) { |
| 76 | + sessionStorage.setItem('gh-repos:' + self.repo, JSON.stringify(results.data)); |
| 77 | + } |
| 78 | + |
65 | 79 | }
|
66 | 80 |
|
67 | 81 | }
|
68 | 82 | });
|
69 | 83 |
|
| 84 | + |
| 85 | + |
| 86 | + } |
| 87 | + |
70 | 88 | };
|
71 | 89 |
|
72 | 90 | Plugin.prototype.applyTemplate = function (repo) {
|
73 | 91 |
|
74 | 92 | var self = this;
|
75 |
| - |
76 | 93 | var date = new Date(repo.pushed_at);
|
77 | 94 | var pushed_at = date.getMonth() + '/' + date.getDate() + '/' + date.getFullYear();
|
78 | 95 |
|
|
91 | 108 | <p>' + repo.description + ' — <a href="' + repo.url.replace('api.','').replace('repos/','') + '#readme">Read More</a></p> \
|
92 | 109 | </div> \
|
93 | 110 | <div class="github-box-download"> \
|
94 |
| - <p class="repo-update">Latest commit to <strong>master</strong> on ' + repo.pushed_at + '</p> \ |
| 111 | + <p class="repo-update">Latest commit to <strong>master</strong> on ' + pushed_at + '</p> \ |
95 | 112 | <a class="repo-download" href="' + repo.url.replace('api.','').replace('repos/','') + '/zipball/master">Download as zip</a> \
|
96 | 113 | </div> \
|
97 | 114 | </div> \
|
98 | 115 | ');
|
99 | 116 |
|
100 |
| - // console.log($widget); |
101 | 117 | self.appendTemplate($widget);
|
102 | 118 |
|
103 | 119 | };
|
|
0 commit comments