0

I am trying to make a fun plugin that does things like: If you type the word "love", it will make a bunch of heart emojis appear to shoot out of the end of the word.

I have so far made a plugin that detects when you've typed one of the keywords, and I've made the hearts shoot out of the TinyMCE content area, from a set position (e.g. the top left), and I'm able to tell how many characters from the start the cursor is at. I have not been able to figure out how to get the X,Y co-ordinates of the cursor in order to position the emojis so they shoot out of the end of the word.

Most of my searches have shown solutions for how to get the position in number of characters of the cursor, or how to move the cursor somewhere, but I haven't been able to find anything about getting the X,Y co-ordinates of it.

I am able to get the X,Y co-ordinates of elements in general, including for the .tox-sidebar-wrap for the active editor.

I would be happy with either the offset from the top left of any of: .tox-sidebar-wrap, the entire TinyMCE editor (.tox.tox-tinymce), the document, or the window, and I would set it there from within a keyup event handler from within my plugin.

Any pointers appreciated!

Ben Holness
  • 2,457
  • 3
  • 28
  • 49

0 Answers0