2022-04-20 14:08:24 +05:30
|
|
|
'use strict';
|
2022-04-20 16:10:30 +05:30
|
|
|
var subscribe_data = JSON.parse(document.getElementById('subscribe_data').textContent);
|
2022-05-06 07:16:59 +05:30
|
|
|
var payload = 'csrf_token=' + subscribe_data.csrf_token;
|
2020-03-16 03:16:08 +05:30
|
|
|
|
2019-05-05 19:05:54 +05:30
|
|
|
var subscribe_button = document.getElementById('subscribe');
|
2022-05-06 07:16:59 +05:30
|
|
|
subscribe_button.parentNode.action = 'javascript:void(0)';
|
2019-05-02 06:33:39 +05:30
|
|
|
|
2019-05-05 19:05:54 +05:30
|
|
|
if (subscribe_button.getAttribute('data-type') === 'subscribe') {
|
|
|
|
subscribe_button.onclick = subscribe;
|
|
|
|
} else {
|
|
|
|
subscribe_button.onclick = unsubscribe;
|
2019-01-28 08:36:28 +05:30
|
|
|
}
|
|
|
|
|
2022-05-06 07:16:59 +05:30
|
|
|
function subscribe() {
|
2019-01-28 09:42:07 +05:30
|
|
|
var fallback = subscribe_button.innerHTML;
|
|
|
|
subscribe_button.onclick = unsubscribe;
|
2019-05-05 19:05:54 +05:30
|
|
|
subscribe_button.innerHTML = '<b>' + subscribe_data.unsubscribe_text + ' | ' + subscribe_data.sub_count_text + '</b>';
|
2019-03-24 00:35:13 +05:30
|
|
|
|
2022-05-06 07:16:59 +05:30
|
|
|
var url = '/subscription_ajax?action_create_subscription_to_channel=1&redirect=false' +
|
|
|
|
'&c=' + subscribe_data.ucid;
|
2019-06-15 20:38:06 +05:30
|
|
|
|
2022-05-06 07:16:59 +05:30
|
|
|
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 08:36:28 +05:30
|
|
|
}
|
|
|
|
|
2022-05-06 07:16:59 +05:30
|
|
|
function unsubscribe() {
|
2019-01-28 09:42:07 +05:30
|
|
|
var fallback = subscribe_button.innerHTML;
|
|
|
|
subscribe_button.onclick = subscribe;
|
2019-05-05 19:05:54 +05:30
|
|
|
subscribe_button.innerHTML = '<b>' + subscribe_data.subscribe_text + ' | ' + subscribe_data.sub_count_text + '</b>';
|
2019-01-28 09:42:07 +05:30
|
|
|
|
2022-05-06 07:16:59 +05:30
|
|
|
var url = '/subscription_ajax?action_remove_subscriptions=1&redirect=false' +
|
|
|
|
'&c=' + subscribe_data.ucid;
|
2019-06-15 20:38:06 +05:30
|
|
|
|
2022-05-06 07:16:59 +05:30
|
|
|
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 08:36:28 +05:30
|
|
|
}
|