Skip to content

#4. Repaired links, added background changing when theme changes #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ jspm_packages

# Optional REPL history
.node_repl_history

.idea
149 changes: 89 additions & 60 deletions assets/contributors.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,95 @@
require(['gitbook'], function(gitbook) {

var githubOwner = "";
var backgroundColor;
var githubRepository = "";
var spinner = "<div class='spinner'><div class='bounce1'></div><div class='bounce2'></div><div class='bounce3'></div></div>";


var loadAndShowContributors = function(contributorsSection){
var settings = { "async": true,
"crossDomain": true,
"url": "https://api.github.com/repos/sta-szek/pojo-tester/stats/contributors",
"method": "GET"
}

$.ajax(settings).done(function (response) {
removeSpinner(contributorsSection);

var users = $(contributorsSection);
$.each(response, function(index,value){
var userContent = createUserContent(value);
$(users).append(userContent);
});
$(users).children().sort(function(a,b) {
return a.children[0].dataset.weight > b.children[0].dataset.weight;
}).appendTo(contributorsSection);
});
require(['gitbook'], function (gitbook) {

}
var githubOwner = "";
var backgroundColor = $(".book-summary").css("background-color");

var githubRepository = "";
var spinner = "<div class='spinner'><div class='bounce1'></div><div class='bounce2'></div><div class='bounce3'></div></div>";


var changeBackgroundForContributors = function () {
$(".contributor").each(function (index, element) {
$(element).css('background-color', backgroundColor);
});
};

function listenForThemeChanges() {
var $div = $(".book");
var observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
if (mutation.attributeName === "class") {
backgroundColor = $(".book-summary").css("background-color");
changeBackgroundForContributors();
}
});
});
observer.observe($div[0], {
attributes: true
});
}

var loadAndShowContributors = function (contributorsSection) {
var settings = {
"async": true,
"crossDomain": true,
"url": "https://api.github.com/repos/sta-szek/pojo-tester/stats/contributors",
"method": "GET"
}

$.ajax(settings).done(function (response) {
resetContributorsContent(contributorsSection);

var users = $(contributorsSection);
$.each(response, function (index, value) {
var userContent = createUserContent(value);
$(users).append(userContent);
});
$(users).children().sort(function (a, b) {
return a.children[0].dataset.weight > b.children[0].dataset.weight;
}).appendTo(contributorsSection);
});

listenForThemeChanges();

var createUserContent = function(githubContribution){
var additions = 0;
var deletions = 0;
$.each(githubContribution.weeks, function(){
additions+=this.a;
deletions+=this.d;
});
return $("<div class='contributor'></div>")
.css('background-color', backgroundColor)
.append("<div class='contributor-avatar' data-weight="+additions+"><img src='"+githubContribution.author.avatar_url+"'/></div>")
.append("<div class='contributor-data'><a href=''"+githubContribution.author.url+"'>"+githubContribution.author.login+"</a></br>additions "+additions+"</br>deletions "+deletions+"</div>");
}

var removeSpinner = function(contributorsSection){
$(contributorsSection).html("");
}

var showSpinner = function(contributorsSection){
$(contributorsSection).html(spinner);
}

gitbook.events.bind("page.change", function(event){
var contributorsSection = $("#GitHubContributors");
if(contributorsSection.length != 0){
backgroundColor= $($('.book-summary')[0]).css('backgroundColor');
showSpinner(contributorsSection);
loadAndShowContributors(contributorsSection);
}
});

gitbook.events.bind('start', function(e, config) {
githubOwner = config.githubcontributors.githubOwner;
githubRepository = config.githubcontributors.githubRepository;
});
var createUserContent = function (githubContribution) {
var additions = 0;
var deletions = 0;
$.each(githubContribution.weeks, function () {
additions += this.a;
deletions += this.d;
});
return $("<div class='contributor'></div>").css('background-color', backgroundColor)
.append("<div class='contributor-avatar' data-weight=" + additions + "><img src='" + githubContribution.author.avatar_url + "'/></div>")
.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>");
}

var resetContributorsContent = function (contributorsSection) {
$(contributorsSection).html("");
}

var showSpinner = function (contributorsSection) {
$(contributorsSection).html(spinner);
}

var format = function (number) {
var fixed = number.toFixed(1).replace(/(\d)(?=(\d{3})+\.)/g, "$1,");
return fixed.substring(0, fixed.length - 2);
}

gitbook.events.bind("page.change", function (event) {
var contributorsSection = $("#GitHubContributors");
if (contributorsSection.length != 0) {
backgroundColor = $($('.book-summary')[0]).css('backgroundColor');
showSpinner(contributorsSection);
loadAndShowContributors(contributorsSection);
}
});

gitbook.events.bind('start', function (e, config) {
githubOwner = config.githubcontributors.githubOwner;
githubRepository = config.githubcontributors.githubRepository;
});

});
79 changes: 46 additions & 33 deletions assets/style.css
Original file line number Diff line number Diff line change
@@ -1,63 +1,76 @@
.spinner {
margin: 100px auto 0;
width: 70px;
text-align: center;
margin: 100px auto 0;
width: 70px;
text-align: center;
}

.spinner > div {
width: 18px;
height: 18px;
background-color: #333;
width: 18px;
height: 18px;
background-color: #333;

border-radius: 100%;
display: inline-block;
-webkit-animation: sk-bouncedelay 1.4s infinite ease-in-out both;
animation: sk-bouncedelay 1.4s infinite ease-in-out both;
border-radius: 100%;
display: inline-block;
-webkit-animation: sk-bouncedelay 1.4s infinite ease-in-out both;
animation: sk-bouncedelay 1.4s infinite ease-in-out both;
}

.spinner .bounce1 {
-webkit-animation-delay: -0.32s;
animation-delay: -0.32s;
-webkit-animation-delay: -0.32s;
animation-delay: -0.32s;
}

.spinner .bounce2 {
-webkit-animation-delay: -0.16s;
animation-delay: -0.16s;
-webkit-animation-delay: -0.16s;
animation-delay: -0.16s;
}

@-webkit-keyframes sk-bouncedelay {
0%, 80%, 100% { -webkit-transform: scale(0) }
40% { -webkit-transform: scale(1.0) }
0%, 80%, 100% {
-webkit-transform: scale(0)
}
40% {
-webkit-transform: scale(1.0)
}
}

@keyframes sk-bouncedelay {
0%, 80%, 100% {
-webkit-transform: scale(0);
transform: scale(0);
} 40% {
-webkit-transform: scale(1.0);
transform: scale(1.0);
}
0%, 80%, 100% {
-webkit-transform: scale(0);
transform: scale(0);
}
40% {
-webkit-transform: scale(1.0);
transform: scale(1.0);
}
}

.contributor-avatar {
width: 100px;
height: 100px;
display: inline-block;
width: 100px;
height: 100px;
display: inline-block;
}

.contributor {
width: 300px;
display: inline-block;
margin-right: 5px;
margin-bottom: 5px
width: 300px;
display: inline-block;
margin-right: 5px;
margin-bottom: 5px
}

.contributor-data {
display: inline-block;
margin-left: 10px;
display: inline-block;
margin-left: 10px;
}

.contributor-additions {
color: #6cc644;
}

.contributor-deletions {
color: #bd2c00;
}

.contributors {
width: 610px;
width: 610px;
}
18 changes: 9 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module.exports = {
website: {
assets: "./assets",
js: [ "contributors.js" ],
css: [ "style.css" ]
},
website: {
assets: "./assets",
js: ["contributors.js"],
css: ["style.css"]
},

blocks: {
GitHubContributors: function(block) {
return "<div id='GitHubContributors' class='contributors'></div>";
blocks: {
GitHubContributors: function (block) {
return "</div></div><div id='GitHubContributors' class='contributors'></div>";
}
}
}

};
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/sta-szek/gitbook-plugin-github-contributors.git"
"url": "git+https://github.com/sta-szek/gitbook-plugin-githubcontributors.git"
},
"keywords": [
"gitbook",
Expand All @@ -25,9 +25,9 @@
"author": "sta-szek <yoyo@wp.eu> (https://github.com/sta-szek)",
"license": "GPL-3.0",
"bugs": {
"url": "https://github.com/sta-szek/gitbook-plugin-github-contributors/issues"
"url": "https://github.com/sta-szek/gitbook-plugin-githubcontributors/issues"
},
"homepage": "https://github.com/sta-szek/gitbook-plugin-github-contributors#readme",
"homepage": "https://github.com/sta-szek/gitbook-plugin-githubcontributors#readme",
"gitbook": {
"properties": {
"githubOwner": {
Expand Down