2022-04-20 01:38:24 -07:00
|
|
|
'use strict';
|
2022-04-20 03:40:30 -07:00
|
|
|
var community_data = JSON.parse(document.getElementById('community_data').textContent);
|
2020-03-15 14:46:08 -07:00
|
|
|
|
2019-07-09 07:31:04 -07:00
|
|
|
function hide_youtube_replies(event) {
|
|
|
|
var target = event.target;
|
|
|
|
|
2022-04-20 03:23:24 -07:00
|
|
|
var sub_text = target.getAttribute('data-inner-text');
|
|
|
|
var inner_text = target.getAttribute('data-sub-text');
|
2019-07-09 07:31:04 -07:00
|
|
|
|
2022-04-20 03:23:24 -07:00
|
|
|
var body = target.parentNode.parentNode.children[1];
|
2019-07-09 07:31:04 -07:00
|
|
|
body.style.display = 'none';
|
|
|
|
|
|
|
|
target.innerHTML = sub_text;
|
|
|
|
target.onclick = show_youtube_replies;
|
|
|
|
target.setAttribute('data-inner-text', inner_text);
|
|
|
|
target.setAttribute('data-sub-text', sub_text);
|
|
|
|
}
|
|
|
|
|
|
|
|
function show_youtube_replies(event) {
|
|
|
|
var target = event.target;
|
|
|
|
|
2022-04-20 03:23:24 -07:00
|
|
|
var sub_text = target.getAttribute('data-inner-text');
|
|
|
|
var inner_text = target.getAttribute('data-sub-text');
|
2019-07-09 07:31:04 -07:00
|
|
|
|
2022-04-20 03:23:24 -07:00
|
|
|
var body = target.parentNode.parentNode.children[1];
|
2019-07-09 07:31:04 -07:00
|
|
|
body.style.display = '';
|
|
|
|
|
|
|
|
target.innerHTML = sub_text;
|
|
|
|
target.onclick = hide_youtube_replies;
|
|
|
|
target.setAttribute('data-inner-text', inner_text);
|
|
|
|
target.setAttribute('data-sub-text', sub_text);
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_youtube_replies(target, load_more) {
|
|
|
|
var continuation = target.getAttribute('data-continuation');
|
|
|
|
|
|
|
|
var body = target.parentNode.parentNode;
|
|
|
|
var fallback = body.innerHTML;
|
|
|
|
body.innerHTML =
|
|
|
|
'<h3 style="text-align:center"><div class="loading"><i class="icon ion-ios-refresh"></i></div></h3>';
|
2022-06-05 10:54:48 -07:00
|
|
|
|
2019-07-09 07:31:04 -07:00
|
|
|
var url = '/api/v1/channels/comments/' + community_data.ucid +
|
|
|
|
'?format=html' +
|
|
|
|
'&hl=' + community_data.preferences.locale +
|
|
|
|
'&thin_mode=' + community_data.preferences.thin_mode +
|
|
|
|
'&continuation=' + continuation;
|
|
|
|
|
2022-05-05 18:46:59 -07:00
|
|
|
helpers.xhr('GET', url, {}, {
|
|
|
|
on200: function (response) {
|
|
|
|
if (load_more) {
|
|
|
|
body = body.parentNode.parentNode;
|
|
|
|
body.removeChild(body.lastElementChild);
|
|
|
|
body.innerHTML += response.contentHtml;
|
|
|
|
} else {
|
|
|
|
body.removeChild(body.lastElementChild);
|
2019-07-09 07:31:04 -07:00
|
|
|
|
2022-05-05 18:46:59 -07:00
|
|
|
var p = document.createElement('p');
|
|
|
|
var a = document.createElement('a');
|
|
|
|
p.appendChild(a);
|
2019-07-09 07:31:04 -07:00
|
|
|
|
2022-05-05 18:46:59 -07:00
|
|
|
a.href = 'javascript:void(0)';
|
|
|
|
a.onclick = hide_youtube_replies;
|
|
|
|
a.setAttribute('data-sub-text', community_data.hide_replies_text);
|
|
|
|
a.setAttribute('data-inner-text', community_data.show_replies_text);
|
2022-05-21 03:35:41 -07:00
|
|
|
a.textContent = community_data.hide_replies_text;
|
2019-07-09 07:31:04 -07:00
|
|
|
|
2022-05-05 18:46:59 -07:00
|
|
|
var div = document.createElement('div');
|
|
|
|
div.innerHTML = response.contentHtml;
|
2019-07-09 07:31:04 -07:00
|
|
|
|
2022-05-05 18:46:59 -07:00
|
|
|
body.appendChild(p);
|
|
|
|
body.appendChild(div);
|
2019-07-09 07:31:04 -07:00
|
|
|
}
|
2022-05-05 18:46:59 -07:00
|
|
|
},
|
|
|
|
onNon200: function (xhr) {
|
|
|
|
body.innerHTML = fallback;
|
|
|
|
},
|
|
|
|
onTimeout: function (xhr) {
|
|
|
|
console.warn('Pulling comments failed');
|
|
|
|
body.innerHTML = fallback;
|
2019-07-09 07:31:04 -07:00
|
|
|
}
|
2022-05-05 18:46:59 -07:00
|
|
|
});
|
2019-07-09 07:31:04 -07:00
|
|
|
}
|