CONTENTS

Accessing the editor in JavaScript

There are two methods to access the editor in JavaScript:

  1. Specify the <applet> attribute name and get the applet's reference with document.applets['applet_name']
     
  2. Specify the <applet> attribute id and get the applet's reference with document.getElementById('applet_name')
Using the obtained reference you can call the applet functions, for example:
<applet name="painter" ... >
    ...
</applet>

<script language="javascript">
    var painter = document.applets['painter'];
    painter.somefunc();
</script>

The list of available functions

getBase64Image(options)

Parameters:
  options - the list of save_options. The list can be empty.

Returns: The image file encoded by BASE64 method.
loadImage(imageURL, bgimageURL, inseparable_bgimage_URL, mask_URL)

Allows loading new images without reloading current web page.

Parameters:
    imageURL    - URL of the main (editable) image.
    bgimageURL  - URL of the background image.
    inseparable_bgimage_URL - URL of the inseparable background image.
    mask_URL    - URL of the mask image.

Notes:
    * If one or more images is unnecessary the parameter should be set to empty string.
    * URLs can be specified as absolute or relative to the current page.
    * Instead of loading images by URL you can pass BASE64 encoded images using
      the data URI:
        data:<MIME-type>;base64,<your_base64_image_data>
      Example:
        data:image/gif;base64,
	R0lGODlhMgAyAPABAAAAAP///yH5BAAAAAAALAAAAAAyADIAAAKSjI+py+0Po5y02ouz3rz7D4ai
	ApTm2JgAeaJBKcHiWtGebOGanfGX3wv+FsAYpliEJCPJJcNJQugSUCqlesBmrxOtoamSGscPnlfr
	zaLJV+x6qGQzW+UuKp1O+fCdKZ8DlAc2Z5WTUldo+LQ09SJEhES04aQSlriTpwaSmUnoeUen1ujy
	Ukl6ipqqusra6vqqWgAAOw==
saveImage(save_script_url,save_options)

Triggers saving of the image. The specified script is requested on the server.
Possible save options can be found here.
Example:

saveImage('save.php','format:png');
addSaveField(name,value)

Allows to add custom fields in the save request. This function (if necessary) should be invoked before saveImage(). After each call of saveImage() the list of custom fields is discarded.
Example:

addSaveField('image_title','Picture 1');
showProgress(text)

Displays the progress box with the specified text.
This function is usefull when you save the image with JavaScript + HTML form.
To remove the displayed box call the function with empty string.

setMode(mode)

Sets the current drawing mode. This function allows to set the current tool, color, stroke, texture, font. The parameter mode is a string in the following format:

tool:tool_name; color:color_spec; stroke:stroke_name; texture:texture_name; font:font_spec

Examples:
setMode('tool:curve;       color:#FF0000; stroke:solid2;');
setMode('tool:filled_rect; color:#000000; texture:solid;');
setMode('tool:text;        color:#0000FF; font:Monospaced-plain-16;');
Each item (tool, color, stroke, texture, font) is optional, i.e. if anyone is not specified it stays unchanged.
getMode(item)

Returns: the value of the specified mode item.
The parameter item can be one of the following: "tool", "color", "stroke", "texture", "font".

doAction(action)

Executes one of the following actions: clear,undo,redo,save,print, open, paste, insert_clipart.
Example:

doAction('clear');
isChanged()
Returns: true if the image has been changed, otherwise returns false.
getImageWidth()
Returns: the image width.
getImageHeight()
Returns: the image height.