2022-04-20 10:38:24 +02:00
|
|
|
'use strict';
|
2022-04-20 12:40:30 +02:00
|
|
|
var subscribe_data = JSON.parse(document.getElementById('subscribe_data').textContent);
|
2022-05-06 03:46:59 +02:00
|
|
|
var payload = 'csrf_token=' + subscribe_data.csrf_token;
|
2020-03-15 22:46:08 +01:00
|
|
|
|
2019-05-05 15:35:54 +02:00
|
|
|
var subscribe_button = document.getElementById('subscribe');
|
2022-05-06 03:46:59 +02:00
|
|
|
subscribe_button.parentNode.action = 'javascript:void(0)';
|
2019-05-02 03:03:39 +02:00
|
|
|
|
2019-05-05 15:35:54 +02:00
|
|
|
if (subscribe_button.getAttribute('data-type') === 'subscribe') {
|
|
|
|
subscribe_button.onclick = subscribe;
|
|
|
|
} else {
|
|
|
|
subscribe_button.onclick = unsubscribe;
|
2019-01-28 04:06:28 +01:00
|
|
|
}
|
|
|
|
|
2022-05-06 03:46:59 +02:00
|
|
|
function subscribe() {
|
2019-01-28 05:12:07 +01:00
|
|
|
var fallback = subscribe_button.innerHTML;
|
|
|
|
subscribe_button.onclick = unsubscribe;
|
2019-05-05 15:35:54 +02:00
|
|
|
subscribe_button.innerHTML = '<b>' + subscribe_data.unsubscribe_text + ' | ' + subscribe_data.sub_count_text + '</b>';
|
2019-03-23 20:05:13 +01:00
|
|
|
|
2022-05-06 03:46:59 +02:00
|
|
|
var url = '/subscription_ajax?action_create_subscription_to_channel=1&redirect=false' +
|
|
|
|
'&c=' + subscribe_data.ucid;
|
2019-06-15 17:08:06 +02:00
|
|
|
|
2022-05-06 03:46:59 +02:00
|
|
|
helpers.xhr('POST', url, {payload: payload, retries: 5, entity_name: 'subscribe request'}, {
|
|
|
|
onNon200: function (xhr) {
|
|
|
|
subscribe_button.onclick = subscribe;
|
|
|
|
subscribe_button.innerHTML = fallback;
|
|
|
|
}
|
|
|
|
});
|
2019-01-28 04:06:28 +01:00
|
|
|
}
|
|
|
|
|
2022-05-06 03:46:59 +02:00
|
|
|
function unsubscribe() {
|
2019-01-28 05:12:07 +01:00
|
|
|
var fallback = subscribe_button.innerHTML;
|
|
|
|
subscribe_button.onclick = subscribe;
|
2019-05-05 15:35:54 +02:00
|
|
|
subscribe_button.innerHTML = '<b>' + subscribe_data.subscribe_text + ' | ' + subscribe_data.sub_count_text + '</b>';
|
2019-01-28 05:12:07 +01:00
|
|
|
|
2022-05-06 03:46:59 +02:00
|
|
|
var url = '/subscription_ajax?action_remove_subscriptions=1&redirect=false' +
|
|
|
|
'&c=' + subscribe_data.ucid;
|
2019-06-15 17:08:06 +02:00
|
|
|
|
2022-05-06 03:46:59 +02:00
|
|
|
helpers.xhr('POST', url, {payload: payload, retries: 5, entity_name: 'unsubscribe request'}, {
|
|
|
|
onNon200: function (xhr) {
|
|
|
|
subscribe_button.onclick = unsubscribe;
|
|
|
|
subscribe_button.innerHTML = fallback;
|
|
|
|
}
|
|
|
|
});
|
2019-01-28 04:06:28 +01:00
|
|
|
}
|