The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Developing custom quote

3 posters

Go down

Solved Developing custom quote

Post by Wizzard May 18th 2024, 1:56 pm

I am trying to develop a bit different quote feature for PunBB version. When I select text, it should show two buttons (as it does) and then when I click let's say on "Quote" button it should put selected text inside textarea. However, this doesn't happen.
Forum: https://forumwitches.forumotion.com/
My script:

Code:
$(document).ready(function() {
    $(document).on('mouseup', function (e) {
        const selection = window.getSelection();
        const selectedText = selection.toString().trim();
        const postEntry = $(e.target).closest('.post-entry');

        if (selectedText.length > 0 && postEntry.length > 0) {
            const range = selection.getRangeAt(0);
            const rect = range.getBoundingClientRect();

            // Remove existing buttons if any
            $('#quote-buttons').remove();

            // Create floating buttons
            const quoteButtons = $('<div id="quote-buttons"></div>').css({
                position: 'absolute',
                top: `${rect.bottom + window.scrollY}px`,
                left: `${rect.left + window.scrollX}px`,
                backgroundColor: 'white',
                border: '1px solid #ccc',
                padding: '5px',
                zIndex: '1000'
            });

            // Add "Add to quoted" button
            const addToQuotedButton = $('<button id="add-to-quoted">Add to quoted</button>').on('click', function() {
                console.log("Add to quoted button clicked");
                let quotedText = localStorage.getItem('quotedText') || '';
                quotedText += `[quote]${selectedText}[/quote]\n`;
                localStorage.setItem('quotedText', quotedText);
                quoteButtons.remove();
            });
            quoteButtons.append(addToQuotedButton);

            // Add "Quote" button
            const quoteNowButton = $('<button id="quote-now">Quote</button>').on('click', function() {
                console.log("Quote button clicked");
                const textarea = $('.sceditor-container textarea');
                if (textarea.length > 0) {
                    textarea.val(textarea.val() + `[quote]${selectedText}[/quote]\n`);
                }
                quoteButtons.remove();
            });
            quoteButtons.append(quoteNowButton);

            // Add floating buttons to the body
            $('body').append(quoteButtons);
        } else {
            $('#quote-buttons').remove();
        }
    });
});

What is the issue there?


Last edited by King Baldwing IV on May 18th 2024, 8:33 pm; edited 1 time in total
Wizzard
Wizzard
Forumember

Male Posts : 125
Reputation : 23
Language : English

https://net-cafe.forumotion.com/

Back to top Go down

Solved Re: Developing custom quote

Post by Wizzard May 18th 2024, 5:51 pm

Ok, I have found the issue. I won't share it yet until code is ready to be shared publicly. Smile
Wizzard
Wizzard
Forumember

Male Posts : 125
Reputation : 23
Language : English

https://net-cafe.forumotion.com/

SarkZKalie likes this post

Back to top Go down

Solved Re: Developing custom quote

Post by skouliki May 18th 2024, 8:32 pm

Please don't double post. Your posts need to be separated by 24 hours before bumping. Please use the edit button, instead!
Please read our forum rules: ESF General Rules

skouliki
skouliki
Manager
Manager

Female Posts : 15397
Reputation : 1709
Language : English,Greek
Location : Greece

http://iconskouliki.forumgreek.com

Back to top Go down

Solved Re: Developing custom quote

Post by SLGray May 19th 2024, 4:18 am

Problem solved & topic archived.
Please read our forum rules:  ESF General Rules


Developing custom quote Slgray10

When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.
SLGray
SLGray
Administrator
Administrator

Male Posts : 51570
Reputation : 3525
Language : English
Location : United States

https://forumsclub.com/gc/128-link-directory/

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum