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

How to insert text into editor after menu button is clicked? #1169

Open
cimenta opened this issue Jul 19, 2024 · 1 comment
Open

How to insert text into editor after menu button is clicked? #1169

cimenta opened this issue Jul 19, 2024 · 1 comment

Comments

@cimenta
Copy link

cimenta commented Jul 19, 2024

I want to add custom button to Trix editor that would allow a user to enter url of video (YouTube, Vimeo) and then new element will be inserted at current cursor position. The video ID would be encrypted.

I managed to add a button but I have troubles to use .insertString()


Trix.config.textAttributes.zzVideo = {
//    style: { color: "red" },
    parser: function(element) {
    
    var tEditor = document.querySelector("trix-editor")
    
    console.log(tEditor)
    console.log(tEditor.editor)
    console.log(element)
    console.log(element.editor)
    
    //tEditor.insertString("Hello")
 //   element.insertString("Hellow")
    
        return //element.style.color === "red"
    },
    inheritable: true
}

https://jsfiddle.net/radek/aL8ochdm/19/

If you also could guide me how to open a modal upon menu button click so user can enter the url it would be great.

@dhairyagabha
Copy link

This has been here for a while but may be this can help. I wrote a way to add some custom buttons to the menu. https://gist.github.com/dhairyagabha/034f5baefb054b7b960438aaf3d88341

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

2 participants