NDOJ/templates/actionbar/media-js.html

129 lines
3.9 KiB
HTML
Raw Normal View History

2022-11-17 00:48:32 +00:00
{% compress js %}
2023-01-27 23:11:10 +00:00
<script type="text/javascript">
$(document).ready(function () {
function ajax_vote(url, id, delta, on_success) {
return $.ajax({
url: url,
type: 'POST',
data: {
id: id
},
success: function (data, textStatus, jqXHR) {
var score = $('#pagevote-score-' + id);
score.text(parseInt(score.text()) + delta);
if (typeof on_success !== 'undefined')
on_success();
},
error: function (data, textStatus, jqXHR) {
alert('Could not vote: ' + data.responseText);
}
});
}
2022-11-17 00:48:32 +00:00
2023-01-27 23:11:10 +00:00
function ajax_bookmark(url, id, on_success) {
return $.ajax({
url: url,
type: 'POST',
data: {
id: id
},
success: function (data, textStatus, jqXHR) {
if (typeof on_success !== 'undefined')
on_success();
},
error: function (data, textStatus, jqXHR) {
alert('Could not bookmark: ' + data.responseText);
}
});
}
2022-11-17 19:17:45 +00:00
2023-02-07 23:22:37 +00:00
window.bookmark = function(id, e) {
e.stopPropagation();
2023-01-27 23:11:10 +00:00
var $bookmark = $('#bookmark-button-' + id);
if ($bookmark.hasClass('bookmarked')) {
ajax_bookmark('{{ url('undobookmark') }}', id, function () {
$bookmark.removeClass('bookmarked');
});
} else {
ajax_bookmark('{{ url('dobookmark') }}', id, function () {
if ($bookmark.hasClass('bookmarked'))
$bookmark.removeClass('bookmarked');
$bookmark.addClass('bookmarked');
});
}
}
2022-11-17 19:17:45 +00:00
2022-11-17 00:48:32 +00:00
2023-01-27 23:11:10 +00:00
var get_$votes = function (id) {
var $post = $('#page-vote-' + id);
return {
upvote: $('#like-button-' + id),
downvote: $('#dislike-button-' + id),
};
};
2022-11-17 00:48:32 +00:00
2023-02-07 23:22:37 +00:00
window.pagevote_upvote = function (id, e) {
e.stopPropagation();
2023-01-27 23:11:10 +00:00
var $votes = get_$votes(id);
if ($votes.upvote.hasClass('voted')) {
ajax_vote('{{ url('pagevote_downvote') }}', id, -1, function () {
$votes.upvote.removeClass('voted');
});
}
else {
var delta = 1;
if ($votes.downvote.hasClass('voted')) {
delta = 2;
}
for (let i = 0; i < delta; i++) {
ajax_vote('{{ url('pagevote_upvote') }}', id, 1, function () {
if ($votes.downvote.hasClass('voted'))
$votes.downvote.removeClass('voted');
$votes.upvote.addClass('voted');
2022-11-19 23:30:07 +00:00
});
2023-01-27 23:11:10 +00:00
}
}
};
2022-11-17 00:48:32 +00:00
2023-02-07 23:22:37 +00:00
window.pagevote_downvote = function (id, e) {
e.stopPropagation();
2023-01-27 23:11:10 +00:00
var $votes = get_$votes(id);
if ($votes.downvote.hasClass('voted')) {
ajax_vote('{{ url('pagevote_upvote') }}', id, 1, function () {
$votes.downvote.removeClass('voted');
});
}
else {
var delta = -1;
if ($votes.upvote.hasClass('voted')) {
delta = -2;
}
for (let i = 0; i > delta; i--) {
ajax_vote('{{ url('pagevote_downvote') }}', id, -1, function () {
if ($votes.upvote.hasClass('voted'))
$votes.upvote.removeClass('voted');
$votes.downvote.addClass('voted');
});
}
}
};
window.actionbar_share = function(element, e) {
2023-02-07 23:22:37 +00:00
e.stopPropagation();
link = $(element).attr("share-url") || window.location.href;
2023-01-27 23:11:10 +00:00
navigator.clipboard
.writeText(link)
.then(() => {
2023-11-01 07:08:36 +00:00
showTooltip(element, "{{_('Copied link')}}", 'n');
2022-11-17 00:48:32 +00:00
});
};
2023-01-27 23:11:10 +00:00
$('.actionbar-comment').on('click', function() {
2023-04-26 08:14:43 +00:00
if ($('#comment-section').css('display') == 'none') {
$('#comment-section').show();
} else {
$('#write-comment').click();
}
2023-01-27 23:11:10 +00:00
})
});
</script>
2022-11-17 00:48:32 +00:00
{% endcompress %}