This repository has been archived by the owner on Apr 1, 2018. It is now read-only.
forked from t413/SinglePaged
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathsite.js
151 lines (132 loc) · 5.09 KB
/
site.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
$.extend($.easing,
{
def: 'easeOutQuad',
easeInOutExpo: function (x, t, b, c, d) {
if (t==0) return b;
if (t==d) return b+c;
if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
}
});
(function( $ ) {
var settings;
var disableScrollFn = false;
var navItems;
var navs = {}, sections = {};
$.fn.navScroller = function(options) {
settings = $.extend({
scrollToOffset: 170,
scrollSpeed: 800,
activateParentNode: true,
}, options );
navItems = this;
//attatch click listeners
navItems.on('click', function(event){
event.preventDefault();
var navID = $(this).attr("href").substring(1);
disableScrollFn = true;
activateNav(navID);
populateDestinations(); //recalculate these!
$('html,body').animate({scrollTop: sections[navID] - settings.scrollToOffset},
settings.scrollSpeed, "easeInOutExpo", function(){
disableScrollFn = false;
}
);
});
//populate lookup of clicable elements and destination sections
populateDestinations(); //should also be run on browser resize, btw
// setup scroll listener
$(document).scroll(function(){
if (disableScrollFn) { return; }
var page_height = $(window).height();
var pos = $(this).scrollTop();
for (i in sections) {
if ((pos + settings.scrollToOffset >= sections[i]) && sections[i] < pos + page_height){
activateNav(i);
}
}
});
};
function populateDestinations() {
navItems.each(function(){
var scrollID = $(this).attr('href').substring(1);
navs[scrollID] = (settings.activateParentNode)? this.parentNode : this;
sections[scrollID] = $(document.getElementById(scrollID)).offset().top;
});
}
function activateNav(navID) {
for (nav in navs) { $(navs[nav]).removeClass('active'); }
$(navs[navID]).addClass('active');
}
})( jQuery );
// Populate contributors section
$(function(){
var property = function(key) {
return function(obj) {
return obj == null ? void 0 : obj[key];
};
};
var pluck = function(obj, key){
return obj.map(property(key));
}
var processData = function(data){
return data.map(
function(contributor){
return {
commits: pluck(contributor.weeks, 'c').reduce(function(a, b) { return a+b; }),
avatar: contributor.author.avatar_url,
name: contributor.author.login,
url: contributor.author.html_url
}
}
);
};
$.when(
$.getJSON('https://api.github.com/repos/coala/coala/stats/contributors'),
$.getJSON('https://api.github.com/repos/coala/coala-bears/stats/contributors')
$.getJSON('https://api.github.com/repos/coala/documentation/stats/contributors')
).done(function(data1, data2){
var processed = processData(data1[0].concat(data2[0]));
for (var i = 0; i < processed.length; i++) {
for(var j=i+1; j < processed.length; j++) {
if (processed[i]['name'] == processed[j]['name']) {
processed[i]['commits'] += processed[j]['commits'];
processed.splice(j, 1);
}
}
}
var sorted = processed.sort(function(a, b){
return a.commits > b.commits;
});
sorted.reverse();
sorted.slice(0,10).forEach(function(contributor, index){
$template = $('#contributors .template').clone();
$template.removeClass('template');
$template.find('.gravatar').attr('src', contributor.avatar);
$template.find('.commits strong').text(contributor.commits);
$template.find('.nick a').text(contributor.name);
$template.find('.nick a').attr('href', contributor.url)
$template.show().appendTo('#contributors');
});
// Change contributor count
$('#contributor-count').text(processed.length);
});
});
$(document).ready(function (){
$('nav li a').navScroller();
//section divider icon click gently scrolls to reveal the section
$(".sectiondivider").on('click', function(event) {
$('html,body').animate({scrollTop: $(event.target.parentNode).offset().top - 50}, 400, "linear");
});
//links going to other sections nicely scroll
$(".container a").each(function(){
if ($(this).attr("href").charAt(0) == '#'){
$(this).on('click', function(event) {
event.preventDefault();
var target = $(event.target).closest("a");
var targetHight = $(target.attr("href")).offset().top
$('html,body').animate({scrollTop: targetHight - 170}, 800, "easeInOutExpo");
});
}
});
});