Notifications
Clear all

wpForo 1.x.x [Solved] Selection to quote in answer

11 Posts
5 Users
12 Likes
3,385 Views
antonM
Posts: 131
Topic starter
(@antonm)
Estimable Member
Joined: 7 years ago

Hi all!

I would like to share a solution for the subject. I use it on my own forum with Q&A layout (3), but it must work with other layouts.

Make next changes in the file: \wp-content\plugins\wpforo\wpf-assets\js\frontend.js

Before line:

jQuery(document).ready(function($){

Add next function:

function getTextSelection(e){

if ( e.target.tagName !== 'A' ) {

var mouseKey = e.button || e.which || null;
var pageX = e.pageX || e.clientX + document.documentElement.scrollLeft;
var pageY = e.pageY || e.clientY + document.documentElement.scrollTop;

setTimeout(function() {
var selectedText = '';
if (window.getSelection) {
selectedText = window.getSelection().toString();
} else if (document.getSelection) {
selectedText = document.getSelection().toString();
} else if (document.selection) {
selectedText = document.selection.createRange().text;
}

if ( selectedText !== '' ) {
var $selection = jQuery(window.getSelection().anchorNode.parentNode) || jQuery(document.getSelection().anchorNode.parentNode) || jQuery(document.selection.createRange().parentElement())
var isPost = $selection.closest('div.wpforo-post-content, div.wpforo-comment-content');
}

if ( selectedText !== '' && mouseKey <= 1 && jQuery('#wpf-form-wrapper').length && isPost.length > 0 ) {
jQuery("#selQuote").remove();

var toolTip = jQuery("<div class='wpf-tool-tip' id='selQuote'></div>");
toolTip.css({
position: 'absolute',
top: (pageY + 10),
left: (pageX > 160 ? pageX - 160 : pageX - 10)
});
var link = jQuery("<a href='#wpf-form-wrapper'>Add quote to answer</a>").on('click', function () {
var editorContent = tinyMCE.activeEditor.getContent();
editorContent += "<blockquote><p>" + selectedText + "</p></blockquote><p></p>"
tinyMCE.activeEditor.setContent(editorContent);
tinymce.execCommand('mceFocus',false,'postbody');
tinyMCE.activeEditor.selection.select(tinyMCE.activeEditor.getBody(), true);
tinyMCE.activeEditor.selection.collapse(false);


jQuery('html, body').animate({ scrollTop: jQuery("#wpf-form-wrapper").offset().top }, 500);

if (window.getSelection) {
if (window.getSelection().empty) { // Chrome
window.getSelection().empty();
} else if (window.getSelection().removeAllRanges) { // Firefox
window.getSelection().removeAllRanges();
}
} else if (document.selection) { // IE?
document.selection.empty();
}
jQuery("#selQuote").remove();
return false;
});

toolTip.append(link);

jQuery('body').append(toolTip);
} else {
jQuery("#selQuote").remove();
}
}, 0);
}

}

After line:

jQuery(document).ready(function($){

Next line:

$(document).on('mouseup', getTextSelection);

Save file. Update site in your browser.

It works with text in the post. Just select with the mouse any text and click on the appeared button "Add quote to answer".

@robert, if you want, you can bundle this function into wpForo.

Any feedback is welcome.

10 Replies
1 Reply
(@mrsamg)
Joined: 8 years ago

Reputable Member
Posts: 237

Oooh I like this. I often want to quote only a small part of a big block of text. And on mobile, trying to delete some of the quote is a right pain to do.

Robert
Posts: 10503
Admin
(@robert)
Support Team
Joined: 8 years ago

Thank you very much @antonm,

We'll probably add this in near future releases.

antonM
Posts: 131
Topic starter
(@antonm)
Estimable Member
Joined: 7 years ago

Thanks to everyone for the feedback!

@robert, please, test this function on mobile devices. It works perfectly on desktop, but I didn't test it in mobile browsers. This function is really useful. I used it for years on the old forum.

Posts: 29
(@moderworks)
Eminent Member
Joined: 5 years ago

Hello,

This feature is present in all modern forums, why it is not implemented on wpforo?

Posts: 986
Moderator
(@martin)
Support Team
Joined: 8 years ago

@moderworks,

This feature is present in all modern forums, why it is not implemented on wpforo?

I'm sorry but wpForo doesn't have Multiquote function yet. They should quote one by one in separate replies or use the simple Quote button. Just copy the text, paste in editor, select and click on quote button Like I did it here.

The Multiquote feature is already in our to-do list. We'll do our best to make it available with future releases as soon as possible. You  just need to press on Enter twice: Vide0 example:  https://www.screencast.com/t/VP5QR5k0vOD

 

1 Reply
(@moderworks)
Joined: 5 years ago

Eminent Member
Posts: 29
Posted by: Martin

@moderworks,

This feature is present in all modern forums, why it is not implemented on wpforo?

I'm sorry but wpForo doesn't have Multiquote function yet. They should quote one by one in separate replies or use the simple Quote button. Just copy the text, paste in editor, select and click on quote button Like I did it here.

The Multiquote feature is already in our to-do list. We'll do our best to make it available with future releases as soon as possible. You  just need to press on Enter twice: Vide0 example:  https://www.screencast.com/t/VP5QR5k0vOD

Not convenient, you see. I have to quote the whole post to answer one phrase.

The Multiquote feature is already in our to-do list.

This makes me happy!

I do not know if I explained the essence of the problem. I speak English quite badly. The possibility of citing part of the user's message is very necessary, this function is implemented in almost all modern forums.

Page 1 / 2