Page tree
Skip to end of metadata
Go to start of metadata

This methods allows users of the advanced API to invoke Java code in their custom plugin from Javascript. A TextEvent of Raise Event action will be triggered when this method is called with the eventName argument as the value of the extraString on the TextEvent.

Available since EditLive 8.1.0.124

It is important to call Event.setHandled(true) when the event has been handled. If setHandled is not set to true EditLive will attempt to invoke a Javascript function using the value of the eventName parameter.

Syntax

JavaScript
editliveInstance.performRaiseEvent(eventName);

Parameters

eventName

This is a string representing the name of the event to be called in the custom Java plugin.

Example

Calling performRaiseEvent will trigger a Java TextEvent. In this case a Raise Event Action of the value of "doSomething" will be raised.

 

editlive_js.performRaiseEvent("doSomething");

 

In the custom Java plugin this TextEvent must be caught. It is very important that the setHandled(true) is called on the event otherwise EditLive will fallback to calling a javascript function with the name of eventName value. The Creating Plugins Utilizing Advanced APIs Tutorial has an example on how to write a custom plugin and listen to TextEvents.

import javax.swing.JOptionPane;
import com.ephox.editlive.ELJBean;
import com.ephox.editlive.common.EventListener;
import com.ephox.editlive.common.TextEvent;
import com.ephox.editlive.plugins.Plugin;
import com.ephox.editlive.plugins.SafeLoadingPlugin;

public class AdvancedAPIPlugin extends SafeLoadingPlugin implements EventListener, Plugin {

	public AdvancedAPIPlugin(final ELJBean bean) {
		super(bean, "8", "insertHTML");
	}

	@Override
	public void raiseEvent(TextEvent e) {
		if (e.isRaiseEventAction("doSomething")) {
			e.setHandled(true);
			JOptionPane.showMessageDialog(null, "Did something");
		}
	}

	@Override
	protected void editorInitialized() {
		getBean().getEventBroadcaster().registerBeanEditorListener(this);
	}
}
  • No labels