Skip to content

Commit 995989d

Browse files
author
Piotr Joński
authored
Merge pull request #5 from sta-szek/#4-Wrong-link-destination
#4. Repaired links, added background changing when theme changes
2 parents 71305ac + aa47b81 commit 995989d

File tree

5 files changed

+149
-105
lines changed

5 files changed

+149
-105
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ jspm_packages
3535

3636
# Optional REPL history
3737
.node_repl_history
38+
39+
.idea

assets/contributors.js

Lines changed: 89 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,95 @@
1-
require(['gitbook'], function(gitbook) {
2-
3-
var githubOwner = "";
4-
var backgroundColor;
5-
var githubRepository = "";
6-
var spinner = "<div class='spinner'><div class='bounce1'></div><div class='bounce2'></div><div class='bounce3'></div></div>";
7-
8-
9-
var loadAndShowContributors = function(contributorsSection){
10-
var settings = { "async": true,
11-
"crossDomain": true,
12-
"url": "https://api.github.com/repos/sta-szek/pojo-tester/stats/contributors",
13-
"method": "GET"
14-
}
15-
16-
$.ajax(settings).done(function (response) {
17-
removeSpinner(contributorsSection);
18-
19-
var users = $(contributorsSection);
20-
$.each(response, function(index,value){
21-
var userContent = createUserContent(value);
22-
$(users).append(userContent);
23-
});
24-
$(users).children().sort(function(a,b) {
25-
return a.children[0].dataset.weight > b.children[0].dataset.weight;
26-
}).appendTo(contributorsSection);
27-
});
1+
require(['gitbook'], function (gitbook) {
282

29-
}
3+
var githubOwner = "";
4+
var backgroundColor = $(".book-summary").css("background-color");
5+
6+
var githubRepository = "";
7+
var spinner = "<div class='spinner'><div class='bounce1'></div><div class='bounce2'></div><div class='bounce3'></div></div>";
8+
9+
10+
var changeBackgroundForContributors = function () {
11+
$(".contributor").each(function (index, element) {
12+
$(element).css('background-color', backgroundColor);
13+
});
14+
};
15+
16+
function listenForThemeChanges() {
17+
var $div = $(".book");
18+
var observer = new MutationObserver(function (mutations) {
19+
mutations.forEach(function (mutation) {
20+
if (mutation.attributeName === "class") {
21+
backgroundColor = $(".book-summary").css("background-color");
22+
changeBackgroundForContributors();
23+
}
24+
});
25+
});
26+
observer.observe($div[0], {
27+
attributes: true
28+
});
29+
}
30+
31+
var loadAndShowContributors = function (contributorsSection) {
32+
var settings = {
33+
"async": true,
34+
"crossDomain": true,
35+
"url": "https://api.github.com/repos/sta-szek/pojo-tester/stats/contributors",
36+
"method": "GET"
37+
}
38+
39+
$.ajax(settings).done(function (response) {
40+
resetContributorsContent(contributorsSection);
41+
42+
var users = $(contributorsSection);
43+
$.each(response, function (index, value) {
44+
var userContent = createUserContent(value);
45+
$(users).append(userContent);
46+
});
47+
$(users).children().sort(function (a, b) {
48+
return a.children[0].dataset.weight > b.children[0].dataset.weight;
49+
}).appendTo(contributorsSection);
50+
});
51+
52+
listenForThemeChanges();
3053

31-
var createUserContent = function(githubContribution){
32-
var additions = 0;
33-
var deletions = 0;
34-
$.each(githubContribution.weeks, function(){
35-
additions+=this.a;
36-
deletions+=this.d;
37-
});
38-
return $("<div class='contributor'></div>")
39-
.css('background-color', backgroundColor)
40-
.append("<div class='contributor-avatar' data-weight="+additions+"><img src='"+githubContribution.author.avatar_url+"'/></div>")
41-
.append("<div class='contributor-data'><a href=''"+githubContribution.author.url+"'>"+githubContribution.author.login+"</a></br>additions "+additions+"</br>deletions "+deletions+"</div>");
42-
}
43-
44-
var removeSpinner = function(contributorsSection){
45-
$(contributorsSection).html("");
46-
}
47-
48-
var showSpinner = function(contributorsSection){
49-
$(contributorsSection).html(spinner);
50-
}
51-
52-
gitbook.events.bind("page.change", function(event){
53-
var contributorsSection = $("#GitHubContributors");
54-
if(contributorsSection.length != 0){
55-
backgroundColor= $($('.book-summary')[0]).css('backgroundColor');
56-
showSpinner(contributorsSection);
57-
loadAndShowContributors(contributorsSection);
5854
}
59-
});
6055

61-
gitbook.events.bind('start', function(e, config) {
62-
githubOwner = config.githubcontributors.githubOwner;
63-
githubRepository = config.githubcontributors.githubRepository;
64-
});
56+
var createUserContent = function (githubContribution) {
57+
var additions = 0;
58+
var deletions = 0;
59+
$.each(githubContribution.weeks, function () {
60+
additions += this.a;
61+
deletions += this.d;
62+
});
63+
return $("<div class='contributor'></div>").css('background-color', backgroundColor)
64+
.append("<div class='contributor-avatar' data-weight=" + additions + "><img src='" + githubContribution.author.avatar_url + "'/></div>")
65+
.append("<div class='contributor-data'><a href='" + githubContribution.author.html_url + "'>" + githubContribution.author.login + "</a><div class='contributor-additions'> " + format(additions) + " ++</div><div class='contributor-deletions'>" + format(deletions) + " --</div></div>");
66+
}
67+
68+
var resetContributorsContent = function (contributorsSection) {
69+
$(contributorsSection).html("");
70+
}
71+
72+
var showSpinner = function (contributorsSection) {
73+
$(contributorsSection).html(spinner);
74+
}
75+
76+
var format = function (number) {
77+
var fixed = number.toFixed(1).replace(/(\d)(?=(\d{3})+\.)/g, "$1,");
78+
return fixed.substring(0, fixed.length - 2);
79+
}
80+
81+
gitbook.events.bind("page.change", function (event) {
82+
var contributorsSection = $("#GitHubContributors");
83+
if (contributorsSection.length != 0) {
84+
backgroundColor = $($('.book-summary')[0]).css('backgroundColor');
85+
showSpinner(contributorsSection);
86+
loadAndShowContributors(contributorsSection);
87+
}
88+
});
89+
90+
gitbook.events.bind('start', function (e, config) {
91+
githubOwner = config.githubcontributors.githubOwner;
92+
githubRepository = config.githubcontributors.githubRepository;
93+
});
6594

6695
});

assets/style.css

Lines changed: 46 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,76 @@
11
.spinner {
2-
margin: 100px auto 0;
3-
width: 70px;
4-
text-align: center;
2+
margin: 100px auto 0;
3+
width: 70px;
4+
text-align: center;
55
}
66

77
.spinner > div {
8-
width: 18px;
9-
height: 18px;
10-
background-color: #333;
8+
width: 18px;
9+
height: 18px;
10+
background-color: #333;
1111

12-
border-radius: 100%;
13-
display: inline-block;
14-
-webkit-animation: sk-bouncedelay 1.4s infinite ease-in-out both;
15-
animation: sk-bouncedelay 1.4s infinite ease-in-out both;
12+
border-radius: 100%;
13+
display: inline-block;
14+
-webkit-animation: sk-bouncedelay 1.4s infinite ease-in-out both;
15+
animation: sk-bouncedelay 1.4s infinite ease-in-out both;
1616
}
1717

1818
.spinner .bounce1 {
19-
-webkit-animation-delay: -0.32s;
20-
animation-delay: -0.32s;
19+
-webkit-animation-delay: -0.32s;
20+
animation-delay: -0.32s;
2121
}
2222

2323
.spinner .bounce2 {
24-
-webkit-animation-delay: -0.16s;
25-
animation-delay: -0.16s;
24+
-webkit-animation-delay: -0.16s;
25+
animation-delay: -0.16s;
2626
}
2727

2828
@-webkit-keyframes sk-bouncedelay {
29-
0%, 80%, 100% { -webkit-transform: scale(0) }
30-
40% { -webkit-transform: scale(1.0) }
29+
0%, 80%, 100% {
30+
-webkit-transform: scale(0)
31+
}
32+
40% {
33+
-webkit-transform: scale(1.0)
34+
}
3135
}
3236

3337
@keyframes sk-bouncedelay {
34-
0%, 80%, 100% {
35-
-webkit-transform: scale(0);
36-
transform: scale(0);
37-
} 40% {
38-
-webkit-transform: scale(1.0);
39-
transform: scale(1.0);
40-
}
38+
0%, 80%, 100% {
39+
-webkit-transform: scale(0);
40+
transform: scale(0);
41+
}
42+
40% {
43+
-webkit-transform: scale(1.0);
44+
transform: scale(1.0);
45+
}
4146
}
4247

4348
.contributor-avatar {
44-
width: 100px;
45-
height: 100px;
46-
display: inline-block;
49+
width: 100px;
50+
height: 100px;
51+
display: inline-block;
4752
}
4853

4954
.contributor {
50-
width: 300px;
51-
display: inline-block;
52-
margin-right: 5px;
53-
margin-bottom: 5px
55+
width: 300px;
56+
display: inline-block;
57+
margin-right: 5px;
58+
margin-bottom: 5px
5459
}
5560

5661
.contributor-data {
57-
display: inline-block;
58-
margin-left: 10px;
62+
display: inline-block;
63+
margin-left: 10px;
64+
}
65+
66+
.contributor-additions {
67+
color: #6cc644;
68+
}
69+
70+
.contributor-deletions {
71+
color: #bd2c00;
5972
}
6073

6174
.contributors {
62-
width: 610px;
75+
width: 610px;
6376
}

index.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
module.exports = {
2-
website: {
3-
assets: "./assets",
4-
js: [ "contributors.js" ],
5-
css: [ "style.css" ]
6-
},
2+
website: {
3+
assets: "./assets",
4+
js: ["contributors.js"],
5+
css: ["style.css"]
6+
},
77

8-
blocks: {
9-
GitHubContributors: function(block) {
10-
return "<div id='GitHubContributors' class='contributors'></div>";
8+
blocks: {
9+
GitHubContributors: function (block) {
10+
return "</div></div><div id='GitHubContributors' class='contributors'></div>";
11+
}
1112
}
12-
}
1313

1414
};

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"repository": {
1313
"type": "git",
14-
"url": "git+https://github.com/sta-szek/gitbook-plugin-github-contributors.git"
14+
"url": "git+https://github.com/sta-szek/gitbook-plugin-githubcontributors.git"
1515
},
1616
"keywords": [
1717
"gitbook",
@@ -25,9 +25,9 @@
2525
"author": "sta-szek <yoyo@wp.eu> (https://github.com/sta-szek)",
2626
"license": "GPL-3.0",
2727
"bugs": {
28-
"url": "https://github.com/sta-szek/gitbook-plugin-github-contributors/issues"
28+
"url": "https://github.com/sta-szek/gitbook-plugin-githubcontributors/issues"
2929
},
30-
"homepage": "https://github.com/sta-szek/gitbook-plugin-github-contributors#readme",
30+
"homepage": "https://github.com/sta-szek/gitbook-plugin-githubcontributors#readme",
3131
"gitbook": {
3232
"properties": {
3333
"githubOwner": {

0 commit comments

Comments
 (0)