Custom Elements 8-3
8.3 Custom Elements within Contributor
The contributor form communicates to a custom element by executing functions implemented by the custom element. As part of the initialization process, a custom
element needs to register these functions by passing their function pointers to the contributor form.
This section contains the following topics:
■
Section 8.3.1, Communication from a Contributor Form to a Custom Element
■
Section 8.3.2, Communication from a Custom Element to a Contributor Form
8.3.1 Communication from a Contributor Form to a Custom Element
The contributor form communicates to a custom element by executing functions implemented by the custom element. As part of the initialization process, a custom
element needs to register these functions by passing their function pointers to the contributor form.
The following is a list of functions that can be registered with the contributor form. None of these functions need to be implemented by the custom element; however, a
few of them are required if the intention is to collect and save data from a Contributor user. Furthermore, all of these functions except the IsDirty function, when executed,
will be passed a callback function pointer to execute when the task is complete. This allows for asynchronous communication if a custom element needs to perform an
asynchronous task during execution.
Function Description
CanCloseElementcallback; The contributor form will execute this method when the contributor updates information within the element. The
implementation of the function should calculate whether the custom element can be safely closed. For instance, if the data
does not pass validation, then the custom element should indicate that it cannot be closed.
GetElementContentcallback; The contributor form will execute this method when the contributor updates information within the element. The
implementation of the function should pass back string content to be saved.
Hidecallback; The contributor form will execute this method whenever the
form performs a DHTML task that overlays a HTML element over the custom element. For instance, this method will be
executed when the metadata tab is activated and the contributor elements are obscured.
This method was introduced specifically for the Ephox-based elements, because Java applets always have top z-index. All
other elements HTML-based elements can ignore this method. Showcallback;
The contributor form will execute this method whenever the form performs a DHTML task that removes an overlay that
makes custom elements reappear. This method was introduced specifically for the Ephox-based
elements, because Java applets always have top z-index. All other elements HTML-based elements can ignore this method.
IsDirty; The contributor form will execute this method whenever the
form popup is closed. The custom element should calculate whether or not unsaved changes exist and then notify the
contributor if there are unsaved changes.
8-4 Oracle Fusion Middleware Technical Reference Guide for Site Studio
The following is a JavaScript code snippet of how a custom element can register functions with the contributor form:
function CanCloseElementcallback {
No data validation in this sample - just pass back a true value. callback{canClose: true};
Here is an example of passing a false value callback{canClose: false, reason: Failed validation. Use only lowercase
letters.}; }
function GetElementContentcallback {
Pass back some sample content for demo purposes. callbackThis is my Custom Element Content.;
} function Showcallback
{ Just handle this notification by executing the callback.
callback; }
function Hidecallback {
Just handle this notification by executing the callback. callback;
} function IsDirty
{ This Custom Element is never dirty - so pass a false value.
return {isDirty: false}; }
Set callback methods for the Contributor Form to send notifications to this Element.
ElementAPI.SetCallbackCanCloseElement, CanCloseElement; ElementAPI.SetCallbackGetElementContent, GetElementContent;
ElementAPI.SetCallbackShow, Show; ElementAPI.SetCallbackHide, Hide;
ElementAPI.SetCallbackIsDirty, IsDirty;
8.3.2 Communication from a Custom Element to a Contributor Form