Implement an OnMouseover Event in TinyMCE Editor Instance

In my quest to enhance the functionality of an editor instance within TinyMCE (via a plugin), I have encountered a roadblock with regards to implementing onMouseOver and onMouseOut events. It appears that these specific events are not natively supported by TinyMCE's API. My intention is to have a control surface when the user hovers over the element to switch to "read-only" mode, among other potential actions. Is it necessary for me to manually inject code into TinyMCE in order to achieve this, or is there a hidden method through which this can be accomplished? And if manual coding is indeed required, what is the rationale behind the lack of support for these events in the API?

For the sake of clarity for those who may share the same degree of confusion as some previous respondents, my main objective is to associate an event with the TinyMCE.Editor instance generated by the TinyMCE library (the class that is supplied to the callback function within the setup parameter of TinyMCE.init). In essence, I aspire to execute the following:

tinyMCE.init({
  .
  .
  .
  setup : function(ed) { 
    TinyMCEReadOnlySetup(ed,true); 
    ed.onMouseOver.add(ShowButton(ed));
    ed.onMouseOut.add(HideButton(ed));
  },
  .
  .
  .
});

However, the variable 'ed' (which represents an instance of TinyMCE.Editor) does not seem to facilitate the addition of MouseOver events in the typical manner seen with other similar events.

Answer №1

If you want to switch between read-only and edit mode, you can do so by using the following code snippet:

ed.getDoc().designMode = "Off";

You can also save the editor content and restore it when the onChange event is triggered.

UPDATE:

To add a mouseover event listener, you can utilize the following code:

$('#' + ed.id +'_parent').bind('mouseover',function (evt){
   setTimeout("console.log('mouseover')",50);return false;
});

This functionality can be implemented in the onInit section of your plugin.

Answer №2

After some experimenting, I discovered a workaround for making this function properly. I ended up creating a custom plugin and implementing the following code within the initialization attribute:

ed.onInit.add(function(ed){
                   .
                   .
                   .

    document.getElementById(ed.id + '_parent').setAttribute('onmouseover',
      "tinyMCE.editor_ShowButton('" + ed.id + "');");
    document.getElementById(ed.id + '_parent').setAttribute('onmouseout',
      "tinyMCE.editor_HideButton('" + ed.id + "');");
    //ed.getBody().appendChild(newdiv);
 });

Although not the ideal solution, it effectively accomplishes the task at hand.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Methods for invoking a function from a separate .js file within React Native Expo

I'm new to using React and I've come across a challenge: In my Main.js file, there is a button: import * as React from 'react'; import { StyleSheet, Text, View, SafeAreaView, Pressable, Alert } from 'react-native'; import { M ...

When the hero banner text is too long, dynamic generation will insert it below the 3 action cards to prevent overlap, incorporating styling to maintain clarity and organization

I am encountering an issue with my dynamically generated hero banner. The issue arises when the body text of the banner is longer than usual, causing it to run behind the action cards positioned at the bottom of the banner. Here is a visual representation ...

A method of submitting by simply pressing the enter key alongside clicking on a Bootstrap button

Here is the HTML code I am using to input prompts into a chatbot: <div class="input-group mb-3"> <input type="text" class="form-control" id="chat-input"> <div class="input-group-append ...

How do I go about adding a specific class to every row within a Vue.js table?

I have an html table structured like this : <tbody> <tr v-for="employee in employees" :key="employee.EmployeeId" @dblclick="rowOnDblClick(emplo ...

Problem encountered when attempting to send an array of files in two dimensions

When I send multiple files using formData, it's structured like this: https://i.sstatic.net/BjePq.png Within my Spring MVC Controller: @PostMapping(value = "/marches") public Integer saveMarches( @RequestPart("formJson") FooBean formJson, ...

Using JavaScript to fetch and display a video

Recently, I delved into the world of web development by creating my own website using html, css and js. I had a vision of having a background video on my site, which I achieved with <div class="bg"><video src="res/res1.mp4" mut ...

Anticipated usage of 'this' within the class method

I've encountered an issue in my class where eslint is flagging a complaint about the usage of 'this' in the method 'getUrlParams' Below is the class in question: class PostSearch extends React.Component { constructor(props) { ...

What is the best way to assign a Vue property the value of a stringified element attribute?

Apologies for the question that may seem silly. Here is the code snippet I am currently working with: var app = new Vue({ el: '#app', data: { words: [] }, created() { let something = document.getElementById('word_data' ...

"Discover the best way to sort through an array of complex objects with varying levels of nesting using a specified search

I have come across similar answers, but none of them go beyond two levels deep. Therefore, I believe this is not a duplicate problem. My task is to filter an array of objects where each object may contain nested objects of unknown depth. In my data structu ...

If I dared to eliminate the emphasized line, this code would completely fall apart

<!DOCTYPE html> <html> <head> </head> <body> <h1 id="message-el">Ready to play?</h1> <p id="cards-el"></p> <p id="sum-el"></p> <butto ...

Tips for managing await requests in asynchronous loop functions - utilizing Node.js

I'm currently utilizing the CSV-parser npm module to read a CSV file and need to execute some operations on each line of data obtained from the CSV. const readstream = fs.createReadStream('src/working_file.csv'); const stream = readstream.p ...

Verifying if a Google Apps Script sheet name or string contains a combination of letters and numbers using JavaScript

I need help with my App Scripts code that checks for sheet names. In my project, there are two types of sheet names - those with only alphabets (e.g. master) and those with a combination of alphabets and numbers (PHY4125). The current code is set to check ...

Having trouble connecting DB and D3 using PHP. Struggling to follow D3noob's tutorial to completion

First and foremost, I want to express my gratitude to the amazing community here for all that I have learned. However, I'm currently facing some difficulties in finding the solution I need. I've encountered issues while trying to follow the inst ...

What are the steps to setting up Webpack-simple with Vue Cli 3?

I'm completely new to Vue Cli and the Vue framework in general, so any help is appreciated! From what I understand, in Vue Cli 2, the command was something like this: Vue init webpack-simple xxx However, with the latest major update (3), it has cha ...

Executing AJAX upon triggering the onchange event occurs prior to the full page loading

Let's paint the scenario. I have 2 dropdown menus. The first one triggers the onchange function which loads data into the second dropdown. It's functioning flawlessly, but I want to enhance it by loading data in the second dropdown using the onlo ...

What is the process for associating JSON reponses with button actions on a webpage?

I developed a JavaScript script that interacts with a Tableau server API to handle running jobs. The script presents the retrieved jobs on a web page, along with corresponding buttons that enable users to terminate specific jobs. While the script function ...

Obtain the currency symbol from a given price string

My dilemma with extracting currency symbols: var str1 = '10.00 €'; var str2 = '12.22 $'; I attempted to create a function that would only retrieve the currency symbol: function extractCurrencySymbol(str){ return str.replace(/[ ...

Creating a hierarchical menu structure by splitting strings in an array using an algorithm

I have an array of strings in Javascript that look like this: var array = [{ string: 'path1/path2/path3' }, { string: 'path1/path4/path5' }, { string: 'path1/path2/path6' }, { string: 'path10/path7' }, { s ...

What is the meaning of object in JavaScript?

I have written a script to add together 3 numbers using express and jade. In my index.jade file I have created 3 input fields and a submit button: !!! 5 html head title Test body form(name='form1', method='post', action=&a ...

How can I send parameters to a directive in AngularJS?

I am trying to pass an argument to a directive in AngularJS. After searching on Stack Overflow, I came across this thread: Angularjs - Pass argument to directive However, the solutions provided did not work for me. This is the Directive: app.directive( ...