|
Accessing HTMLEditor From Javascript
The demo includes functional examples how to access the HTMLEditor content using javascript.
There are available the following functions:
public void setContent(String htmlContent) - sets the content of the HTMLEditor. The content could be an html document, portion of html document or plain text
public void setURLEncodedContent(String htmlURLEncodedContent) - sets the content of the HTMLEditor. The content could be an html document which is URLEncoded - it will be decoded by the editor and rendered properly.
public String getContent() - returns the content of the html editor as entire html document (includes tags <html>, and <body>).
public String getSelectedContent() - returns the content only within the selection. If there is no selection, empty string will be returned.
public String getBodyContent() - returns the content of the html editor as a potion of html document (without tags <html>, and <body>). For use with content management systems is recommended using this function when editing single pieces of pages. If you have inserted portion of document using setContent method this will return what you need.
public String getPlainText() - returns the content of the html editor as plain text without any formatting.
public String getSelectedEditor() - returns the selected tab of the editor - return values could be "VISUAL_EDITOR", "SOURCE_EDITOR", "PAGE_PREVIEW". (Enterprise Only)
public void insertContent(String htmlContent) -inserts html content inside the editor without erasing the rest of the document. The new content is inserted at the current caret position
public void insertText(String plainText) -inserts plain text content inside the editor without erasing the rest of the document. The new content is inserted at the current caret position. The text inserted will take the attributes of the text at the caret position (ex. bold, italic etc.) If there is a selection, the selection will be replaced with the new text.
public void insertImage(String imageURL) -inserts an image inside the editor. It could be also relative URL - the correct resolving of the relative URLs depends on the configuration of the applet parameter absoluteDocumentTranslationURL
public void insertLink(String linkURL) -inserts a hyperlink over the selected text in the editor. For correct resolving of relative URLs if used as an applet you may cosider the Applet Edition of this product.
public void setDefaultCharset(String charsetMimeType) -set the default charset for converting the document content. This value will be used as default if charset statement is not specified in the page loaded. If there is a statement indicating the charset of the page such as "<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">" this statement will be parsed and used instead of the default one. The charset is used when loading and saving documents.
public void saveToLocation(String locationURL, boolean entireFile) - sends the content of the HTMLEditor using method POST to the server script specified in locationURL and sends it as entire document if entireFile is true, otherwise it will send only the portion of the document as specified in getBodyContent()
public void saveToDefaultLocation() - sends the content of the HTMLEditor using method POST to the server script specified in the applet parameter saveURL and sends it as entire document using also the parameters variableName and parametersToSend if specified, otherwise the default variable name is html_content.
public void openLocation(String location) - opens new document from the location specified. The parameter location should be a fully qualified URL.When used as an applet the document obviously should be from the same server where the applet resides.
Only in external window mode is available the following function:
public void startVisualEditor() - starts and shows the window of the HMTLEditor without the need to click on the applet button.
public boolean uploadMultipartContent(String saveLocation, boolean entireFile) - this will upload the content of the editor to the server as multipart form data - it will bundle together with the html document all images, hyperlink targets etc. which are local object or have a host different from this of the editor it self. The return value is true if the upload is successful, false otherwise. You can make the browser wait until the upload is completed waiting for the return value for a variable from javascript. The saveLocation sould be the URL of the server side script which receives the content of the editor, entireFile indicates whether the content of the HTML document should be entire page (including HTML, body etc.) or only a fragment of page -paragraph etc.
public void addJavascriptButton("shortcutToolbar","helloFromJavascript()","http://host/icon.gif","Tooltip Text") - this will add new javascript button on the specified toolbar. The toolbars are as follows: shortcutToolbar - the toolbar with open, save, etc. shortcuts, and formattingToolbar - which contains all text formatting buttons. The second parameter is the javascript function to be invoked, third parameter is the icon of the button (should be a fully qualified URL), and last is the tooltip text to be displayed when the mouse is over the button.
public void focus() - will transfer the focus to the editor. You can use this function in conjunction with the parameter transferFocusOnTAB in order to manage the focus over the various form elements.
public void setSaveLocation(String url_location) - will set dinamically the save location for the remote save functionalities.
public void setUploadedObjectsTranslationPath(String url) - will set dinamically the translation path for resolving uploaded objects.
public void setExternalStyleSheetLocation(String urtl) - will load dinamically stylesheets into the editor.
public void setDocumentLenghtLimit(int limit, String warningMessage) - can be used to specify document length limit of the length of the entire document including the HTML markup. If the limit is reached, warning message will be shown to the user. If the message is null, default message will be displayed.
public void resetDocumentLenghtLimit() - will reset the previosly imposed document length limit.
public boolean isDocumentEdited() - will return true or false indicating whether the document has been edited (changed) by the user or not. This can be useful for checking if the docuemnt has been changed before performing save operations or ask the user to save before leaving the page.
|