diff --git a/themes/freemind/layout/_partial/post/comment_footer.ejs b/themes/freemind/layout/_partial/post/comment_footer.ejs index 0525d9d..1efe1e1 100644 --- a/themes/freemind/layout/_partial/post/comment_footer.ejs +++ b/themes/freemind/layout/_partial/post/comment_footer.ejs @@ -4,7 +4,7 @@ <% if (item.fedi_url){ %>
Not comments found
"; + document.getElementById('mastodon-comments-list').innerHTML += "此文章下没有公开的评论。
"; } + document.getElementById('mastodon-comments-list').innerHTML += ` + ` + const dialog = document.getElementById('comment-dialog'); + + // open dialog on button click + Array.from(document.getElementsByClassName("addComment")).forEach(button => button.addEventListener('click', () => { + dialog.showModal(); + // this is a very very crude way of not focusing the field on a mobile device. + // the reason we don't want to do this, is because that will push the modal out of view + if(dialog.getBoundingClientRect().y > 100) { + document.getElementById("instanceName").focus(); + } + })); + + // when click on 'Go' button: go to the instance specified by the user + document.getElementById('go').addEventListener('click', () => { + let url = document.getElementById('instanceName').value.trim(); + if (url === '') { + // bail out - window.alert is not very elegant, but it works + window.alert("请填入你的网站地址!"); + return; + } + + // store the url in the local storage for next time + localStorage.setItem('mastodonUrl', url); + + if (!url.startsWith('https://')) { + url = `https://${url}`; + } + + window.open(`${url}/authorize_interaction?uri=${post_url}`, '_blank'); + }); + + // also when pressing enter in the input field + document.getElementById('instanceName').addEventListener('keydown', e => { + if (e.key === 'Enter') { + document.getElementById('go').dispatchEvent(new Event('click')); + } + }); + + // copy tye post's url when pressing copy + document.getElementById('copy').addEventListener('click', () => { + // select the input field, both for visual feedback, and so that the user can use CTRL/CMD+C for manual copying, if they don't trust you + document.getElementById('copyInput').select(); + navigator.clipboard.writeText(post_url); + // Confirm this by changing the button text + document.getElementById('copy').innerHTML = '已复制!'; + // restore button text after a second. + window.setTimeout(() => { + document.getElementById('copy').innerHTML = '复制'; + }, 1000); + }); + + // close dialog on button click, or escape button + document.getElementById('close').addEventListener('click', () => { + dialog.close(); + }); + dialog.addEventListener('keydown', e => { + if (e.key === 'Escape') dialog.close(); + }); + + // Close dialog, if clicked on backdrop + dialog.addEventListener('click', event => { + var rect = dialog.getBoundingClientRect(); + var isInDialog= + rect.top <= event.clientY + && event.clientY <=rect.top + rect.height + && rect.left<=event.clientX + && event.clientX <=rect.left + rect.width; + if (!isInDialog) { + dialog.close(); + } + }) commentsLoaded = true; });