Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Executable via "onclick"? #21

Open
annando opened this issue May 4, 2023 · 3 comments
Open

Executable via "onclick"? #21

annando opened this issue May 4, 2023 · 3 comments

Comments

@annando
Copy link

annando commented May 4, 2023

At first thanks a lot for this slim piece of code!

From what I have seen, the only way invoking it, is to execute it indirectly via some trigger. I would like to use the code in Friendica for the comment fields. But to make that work, the script needs to be executed via the "onclick" attribute.

Is this prepared in any way? I'm a JS rookie, so it could be that the question is really stupid :-)

@woody180
Copy link
Owner

woody180 commented May 9, 2023

Hello.. you can create .js file. import it in to your project and inside js file put following
new EmojiPicker({ trigger: [ { selector: '.first-btn', insertInto: ['.one', '.two'] // '.selector' can be used without array }, { selector: '.second-btn', insertInto: '.two' } ], closeButton: true, //specialButtons: green });

inside "selector" add class/id of the button from which will invoke emoji picker

@annando
Copy link
Author

annando commented May 9, 2023

My problem is that I have got a handful of textareas on the page that I have to address via their id. The id values are always different. So the best would be to execute the picker via some <button ... onclick='Picker({{id}})'>...</button>.

Also I have got another problem. Currently I'm using a class name. But The class is assigned after the page loaded (when a user clicks on "comment"). This means that the picker doesn't find the class and thus cannot execute the trigger. This is why we had to tweak the code a little bit: https://github.com/friendica/friendica/blob/develop/view/js/vanillaEmojiPicker/vanillaEmojiPicker.js#L7716

@msamyel
Copy link

msamyel commented Feb 25, 2024

I was facing the same issue in my project. If you know you are only going to have so many pairs of emoji pickers and textareas, you can set up the triggers when initializing EmojiPicker and they will trigger even if you add those elements later.

function* range(start, end, step = 1) {
    for (let i = start; i < end; i += step) {
        yield i;
    }
}

let indices = range(0,1000);

const trigger = [...indices.map(x => ({
                selector: "#emoji_trigger_" + x,
                insertInto: "#textarea_id_" + x}))];

new EmojiPicker({
            trigger: trigger,
            closeButton: true
        });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants