jQuery(document).ready(function ($){
var container=$('#dcf-container');
if(container.length){
$.ajax({
url: dcfCommentFeatures.ajax_url,
type: 'POST',
data: {
action: 'dcf_fetch_activity'
},
success: function (response){
if(!response||!response.success){
return;
}
var data=response.data;
container.find('#dcf-lifetime').text(data.lifetime_text);
if(data.today > 0){
container.find('#dcf-approved-today').text(data.today_text);
}else{
container.find('#dcf-today-card').css('display', 'none');
}
var presence=container.find('#dcf-presence');
presence.find('.dcf-presence-text').text(data.presence_text);
presence.toggleClass('is-online', !!data.presence_online);
presence.css('visibility', 'visible');
if(data.reply_hours > 0){
container.find('#dcf-reply-hours').text(data.reply_hours);
container.find('#dcf-reply-card').css('visibility', 'visible');
}
if(data.comments.length > 0){
var rows=container.find('#dcf-rows');
data.comments.forEach(function (comment){
var html='<div class="dream-comment-features"><p>';
html +=comment.status + ' <strong>' + comment.author + '</strong>';
if(comment.post_link!=='#'){
html +=': <a href="' + comment.post_link + '">' + comment.post_title + '</a>';
}else{
html +=': ' + comment.post_title;
}
html +=' <small>(';
html +=dcfCommentFeatures.i18n.time_ago.replace('%s', comment.time_ago);
html +=')</small></p></div>';
rows.append(html);
});
container.find('#dcf-load').css('visibility', 'visible');
}}
});
container.on('click', '#dcf-load', function (){
var button=$(this);
var open=button.attr('aria-expanded')==='true';
button.attr('aria-expanded', open ? 'false':'true');
container.find('#dcf-list').toggle(!open);
});
}
window.dcfAfterComment=function (){
var notice=$('#dcf-postsubmit');
if(!notice.length||notice.is(':visible')){
return;
}
notice.slideDown(200);
};
$(document).on('click', '#dcf-copy-link', function (){
var button=$(this);
var url=button.attr('data-url');
var done=button.attr('data-done');
if(!url||button.hasClass('is-done')){
return;
}
var confirmed=function (){
if(!button.attr('data-label')){
button.attr('data-label', button.text());
}
button.addClass('is-done').attr('aria-live', 'polite').text(done);
window.setTimeout(function (){
button.removeClass('is-done').text(button.attr('data-label'));
}, 2500);
};
if(window.navigator&&navigator.clipboard&&navigator.clipboard.writeText){
navigator.clipboard.writeText(url).then(confirmed, function (){
dcfCopyFallback(url, confirmed);
});
}else{
dcfCopyFallback(url, confirmed);
}});
function dcfCopyFallback(url, onSuccess){
var field=$('<textarea readonly></textarea>')
.val(url)
.css({ position: 'fixed', top: '-1000px', left: '-1000px', opacity: 0 })
.appendTo('body');
try {
field[0].select();
field[0].setSelectionRange(0, url.length);
if(document.execCommand ('copy')){
onSuccess();
}} catch (e){
}
field.remove();
}});