-
-
Notifications
You must be signed in to change notification settings - Fork 771
/
profile.js
130 lines (109 loc) · 3.57 KB
/
profile.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
$(document).ready(function() {
$('#kudos-section').on('click keypress', '.flip-card', e => {
if ($(e.target).is('a')) {
e.stopPropagation();
return;
}
$(e.currentTarget).toggleClass('turn');
});
setupTabs('#activity-tabs');
const tabSection = document.querySelector('#activity-tabs-sections');
const updateViewBtn = document.querySelector('#update-view-btn');
let fetchInProgress = false;
function updateView(ignoreScrollOffset) {
window.setTimeout(updateView, 300);
if (fetchInProgress) {
return;
}
const activityContainer = document.querySelector('.tab-section.active .activities');
const activityCount = activityContainer ? parseInt(activityContainer.getAttribute('count')) || 0 : 0;
const loadingImg = document.querySelector('.loading_img');
if (activityContainer.children.length < activityCount) {
updateViewBtn.style['visibility'] = 'visible';
} else {
updateViewBtn.style['visibility'] = 'hidden';
return;
}
if (ignoreScrollOffset || window.scrollY >= tabSection.scrollHeight) {
const activityName = activityContainer.id;
let page = parseInt(activityContainer.getAttribute('page')) || 0;
fetchInProgress = true;
loadingImg.className = loadingImg.className.replace('hidden', 'visible');
fetch(location.href.replace(location.hash, '') + '?p=' + (++page) + '&a=' + activityName).then(
function(response) {
if (response.status === 200) {
response.text().then(
function(html) {
const results = document.createElement('div');
activityContainer.setAttribute('page', page);
results.insertAdjacentHTML('afterBegin', html);
const childs = results.children;
while (childs.length) {
activityContainer.append(childs[0]);
}
fetchInProgress = false;
loadingImg.className = loadingImg.className.replace('visible', 'hidden');
}
);
return;
}
fetchInProgress = false;
hideBusyOverlay();
}
).catch(
function() {
fetchInProgress = false;
loadingImg.className = loadingImg.className.replace('visible', 'hidden');
}
);
}
}
if (updateViewBtn) {
updateViewBtn.addEventListener('click',
function() {
updateView(true);
},
false
);
updateView();
}
});
(function($) {
$(document).on('click', '.load-more', function() {
var address = $('#preferred-address').prop('title');
var link = $(this);
var page = link.data('page');
var request = link.data('request');
var handle = link.data('handle');
if (!handle) {
return;
}
$.ajax({
type: 'POST',
url: '/lazy_load_kudos/',
data: {
'page': page,
'request': request,
'address': address,
'handle': handle,
'csrfmiddlewaretoken': '{{csrf_token}}' // from index.html
},
success: function(data) {
// if there are still more pages to load,
// add 1 to the "Load More Posts" link's page data attribute
// else hide the link
if (data.has_next) {
link.data('page', page + 1);
} else {
link.hide();
}
// append html to the posts div
var elem = '#' + request;
$(elem + ' div').first().append(data.kudos_html);
},
error: function(xhr, status, error) {
// shit happens friends!
}
});
});
}(jQuery));