eton Avatar
Oct 23, 2024 18:42:09 GMT -5 @eton said:
I'm seeing the code in the footer instead of the header and missing quite a few updates as you've mentioned, especially the update geared toward the double and triple-clickers. Also, notice that the <dialog> now precedes the script on newer releases to ensure proper reference when multiple dialogs bearing the same class are on the page (e.g. when plugin and script are both enabled).
Oct 23, 2024 5:56:42 GMT -5 Quote Highlighted Text (Latest Version) said:
<dialog class="quick-quote-div" style="/*display: none;*/margin:0; border: grey solid 1px; border-radius: 5px; opacity: 0.8; padding: 5px; background-color: white;">
<form method="dialog">
<input name="quote" value="Quick Quote" type="submit" class="ui-button quick-quote-button" autofocus >
</form>
</dialog>
<!-- Quick Quotes (UPDATED Oct 23, 2024 @ 1729681002992) -->
<script>
(() => {
var isIE = document.all;
var mouseX = 0;
var mouseY = 0;
function getMouseXY(e) {
if (!e)
e = window.event;
if (e) {
mouseX = isIE ? (e.clientX + document.body.scrollLeft) : e.pageX;
mouseY = isIE ? (e.clientY + document.body.scrollTop) : e.pageY;
}
}
document.addEventListener('mousemove', getMouseXY, true);
htm_specials_tags = {
"remove": [
'.quote_clear',
'.quote_header',
'.quote_avatar_container',
'.spoiler_header'
],
"unwrap": [
'.quote_body'
],
"replace":[
['div.quote','className'],
['div.spoiler[id]', 'data-tag'],
['iframe[src*="youtube.com"]','','video']
]
}
function cleanupHTML(htm){
const container = $('<div></div>').html(htm);
$('' + htm_specials_tags['remove'], container).remove()
$('' + htm_specials_tags['unwrap'], container).each((i,e)=>{$(e).contents().unwrap()});
for(let j =0, tag = htm_specials_tags['replace'][0]; j < htm_specials_tags['replace'].length; tag = htm_specials_tags['replace'][++j]){
$(tag[0],container).each((i,e)=>{
let n = e[tag[1]]? $(`<${e[tag[1]]}>${e.innerHTML}</${e[tag[1]]}>`)
: (tag[2]? $(`<${tag[2]}>${e.innerHTML}</${tag[2]}>`):$());
if(n.length){
for(const t of e.attributes)n.attr(t.name,t.value);
$(e).replaceWith(n);
}
});
}
return container.html()
}
function getSelectionHtml() {
var html = "";
if (typeof window.getSelection != "undefined") {
var sel = window.getSelection();
if ($(sel.anchorNode).parents('.message').is($(sel.focusNode).parents('.message')) && sel.rangeCount) {
if($(sel.anchorNode).parents('.quote').is($(sel.focusNode).parents('.quote'))){ quotequote=$(sel.focusNode).parents('.quote'); }else{ quotequote=null;}
var container = document.createElement("div");
for (var i = 0, len = sel.rangeCount; i < len; ++i) {
container.appendChild(sel.getRangeAt(i).cloneContents());
}
html = container.innerHTML;
}
} else if (typeof document.selection != "undefined") {
if (document.selection.type == "Text") {
html = document.selection.createRange().htmlText;
}
}
return cleanupHTML(html);
}
var messageIDnum,
messageIDsliced,
messageAuthor,
messageTimestamp,
messageNew,
quoteText,
quotequote;
getSelectionHtml.mouseup = function (event) {
var htmlSelection = getSelectionHtml();
getSelectionHtml.mouseup.timeout && clearTimeout(getSelectionHtml.mouseup.timeout)
quoteText = htmlSelection.replace(/>/g, "]");
quoteText = quoteText.replace(/</g, "[");
if ($('.unblocked .message:hover').length != 0) {
if (htmlSelection != '') {
getSelectionHtml.mouseup.timeout = setTimeout(function () {
$(".quick-quote-div").css({
position: "absolute",
top: mouseY,
left: mouseX
});
$(".quick-quote-div")[0].showModal();
setTimeout(function () {
if ($('.quick-quote-div:hover').length == 0) {
$('.quick-quote-div')[0].close()
htmlSelection = ''
quoteText = ''
}
}, 2500)
}, 600);
if(quotequote){
messageNew = `
`
}else{
messageIDnum = $('.post:hover').attr('id');
messageIDsliced = messageIDnum.substr(messageIDnum.lastIndexOf("-") + 1);
messageAuthor = $('.post:hover .mini-profile').find('.user-link').attr('title') || $('.post:hover .mini-profile').find('[itemtype$="/Person"] span[itemprop="name"]').text();
messageTimestamp = $('.post:hover .info').find('abbr:first').attr('data-timestamp');
messageTimestamp = messageTimestamp.substring(0, messageTimestamp.length - 3);
messageNew = '
'
}
}
}
}
$('.quick-quote-button').click(function () {
if (quoteText != '') {
pb.data('quick_reply') ? $('.quick-reply textarea').replaceSelection(messageNew + "\n")[0].scrollIntoView({
block: 'start',
inline: 'nearest',
behavior: 'smooth'
})
: $('<form></form>', {
method: 'POST',
action: proboards.route('new_post', {
thread_id: pb.item('thread', pb.item('post', +messageIDsliced)['thread_id']).id
})
})
.append($('<input>', {
name: 'quick_message'
}).val(messageNew))
.append($('<input>', {
name: 'csrf_token'
}).val(proboards.data("csrf_token") || "null"))
.appendTo('body').attr('id', 'quick_form'),
setTimeout(function () {
pb.data('quick_reply') && $('.quick-reply textarea')[0].focus();
$('#quick_form').submit()
}, 500);
htmlSelection = quoteText = '';
$('.quick-quote-div')[0].close();
}
});
$(document).ready(function () {
$(document).bind("mouseup", getSelectionHtml.mouseup);
$('.quick-quote-div').on('click', (event) => {
event.target.tagName == 'DIALOG' && event.target.close();
})
});
})();
/** UPDATES:
- encapsulate to avoid global variables getting overwritten
- switched to <dialog> for top-layer treatment
- used jQuery.fn.replaceSelection to insert at caret position in quick reply
- look for timestamp only in .content > .info
- search mini-profile only for author
- support quoting guest posts
- scroll quick reply into view and set focus on typing area
- redirect to full reply if no quick reply is available
- ignore selections that are outbounds of the post content
- moved button click handler out of selection handler to avoid duplicate or multiple quotes on a single click
- properly cite nested quotes and add logic to convert them back to BBCode
- delayed button popup to allow for triple-click selections
- made BBCode convertor expandable and added spoilers to the list of tags that require special treatment
- added youtube to specials converter
**/
</script>
/** UPDATES:
- encapsulate to avoid global variables getting overwritten
- switched to <dialog> for top-layer treatment
- used jQuery.fn.replaceSelection to insert at caret position in quick reply
- look for timestamp only in .content > .info
- search mini-profile only for author
- support quoting guest posts
- scroll quick reply into view and set focus on typing area
- redirect to full reply if no quick reply is available
- ignore selections that are out of bounds of the post content
- moved button click handler out of selection handler to avoid duplicate or multiple quotes on a single click
- properly cite nested quotes and add logic to convert them back to BBCode
- delayed button popup to allow for triple-click selections
- made BBCode convertor expandable and added spoilers to the list of tags that require special treatment
- added youtube to specials converter
**/
Also, I'm building a list of HTML elements that need special treatment to return to their BBCode counterparts. It still won't be perfect, but it will be an improvement.
htm_specials_tags = {
"remove": [
'.quote_clear',
'.quote_header',
'.quote_avatar_container',
'.spoiler_header'
],
"unwrap": [
'.quote_body'
],
"replace":[ /* [selector, attribute containing bbcode tagname, or static tagname]
['div.quote','className'],
['div.spoiler[id]', 'data-tag'],
['iframe[src*="youtube.com"]','','video']
]
}
And thanks for getting me some much-needed feedback so this could move forward @bigballofyarn 😁👍
(I am still trying to get in contact with David to see if this plugin can be given an open-source license or at least a designated caretaker so modernizations can actually be merged into the plugin itself)
Test quoting a quote...
Aaron Avatar
Jul 16, 2024 19:52:10 GMT -5 Aaron said:
By the time you read this post, I'm letting you know that I've decided to leave this forum as of today. This might be a tough pill to swallow and break the hearts of many who I had the pleasure of communicating with, but it's the right decision I have to make for me to leave to try and focus on my mental health struggles I've been having to face and deal with. I want to say a huge word of thanks to everyone for giving me a chance to engage in conversations, play forum games with you, and communicate with me. But I want to give a very huge word of thanks to you, bigballofyarn , for giving me second chance five years ago. You not only made me a better member, but you also made me a better person.
Always be yourself, always be you 💚
Thank you all and god bless.
- Fix for double and triple clicks not in place (code needs to be updated and moved to proper location)
- quotes containing quotes need the update to convert back to BBCode with correct citations properly
- spoilers need the update to convert back to BBCode properly
- what other tag needs an update to convert back to BBCode properly (
)