- Installation Guides
- Browser Support
- Languages Support
- Shortcuts
- Activation
- Examples
- Customize the Editor
- Use-cases
- Plugins
- APIs
- Development Frameworks
- Server Integrations
- Server SDKs
- Migration Guides
- Changelog
- Tutorials
- Froala Docs
- /
- Concepts
- /
- Image
- /
- Manager
Image Concepts
Image Manager
By default the Froala Rich Text Editor's image manager displays images stored on our servers and it just simulates the delete behavior. In order to display the images from your own server you have to use a server-side language. This article is meant to help you understand how the editor's image manager works.
Flow
-
Include the image manager plugin file.
The image manager is a plugin for the WYSIWYG HTML editor and the
image_manager.min.jsfile must be included before being able to use it.
-
Set the editor's image manager options.
When using the image manager, you can customize up to 9 options and 5 events:
โขimageManagerPreloaderis the path to a gif file to be displayed while loading the images from the server in the image manager. If this option is not used then a loading text will appear.
โขimageManagerPageSizeis the number of images loaded per page in the image manager.
โขimageManagerScrollOffsetis the distance in pixels from the bottom of the scrollable content at which to trigger the loading of the next page of images.
โขimageManagerLoadURLis the URL where the request to load the images is made.
โขimageManagerLoadMethodis the HTTP image manager load images request type.
โขimageManagerLoadParamsare additional parameters that are passed in the load images request to the server.
โขimageManager.errorevent is triggered if any errors occur while loading the images list from the server in the image manager.
โขimageManager.imageLoadedevent is triggered after an image was loaded in image manager.
โขimageManager.imagesLoadedevent is triggered after the request to load images in the image manager has been completed successfully.
โขimageManagerDeleteURLis the URL where the request to delete an image is made.
โขimageManagerDeleteMethodis the HTTP image manager delete image request type.
โขimageManagerDeleteParamsare additional params that are passed in the delete request to the server.
โขimageManager.beforeDeleteImageevent is triggered before deleting an image from the image manager.
โขimageManager.imageDeletedevent is triggered after the image was deleted from image manager.
-
AJAX request from editor to the imageManagerLoadURL link.
When the image manager button is clicked, a HTTP request is automatically made to the server in order to retrieve the list with images to be displayed.
-
The server processes the HTTP request to load images.
The server has to process the GET request (or the one specified by
imageManagerLoadMethod) and return an array of links for the images. The returned array needs to look like:[ { "url": "http://exmaple.com/images/photo1.jpg", "thumb": "http://exmaple.com/thumbs/photo1.jpg", "tag": "flower" }, { "url": "http://exmaple.com/images/photo2.jpg", "thumb": "http://exmaple.com/thumbs/photo2.jpg", "tag": "sport" } ]Whereurlis required,thumbis recommended andtagis optional. The image Object may also contain additional data that will be added as image attributesdata-*. E.g.:[ { "url": "http://exmaple.com/images/photo1.jpg", "thumb": "http://exmaple.com/thumbs/photo1.jpg", "tag": "flower", "name": "Photo 1 Name", "id": "103454285" } ]<img src='https://exmaple.com/images/photo1.jpg' data-name='Photo 1 Name' data-id='103454285'>If you need help with the server side process please check out the Froala SDKs.
-
The editor loads the images in the image manager.
When the request finishes successfully the
imageManager.imagesLoadedevent is triggered and the rich text editor will load the images in the image manager. After an image is loaded in the image manager theimageManager.imageLoadedevent is triggered. If the returned array does not follow the right structure or the images cannot be loaded,imageManager.errorevent is triggered.
-
AJAX request from editor to the imageManagerDeleteURL link.
When the delete button on an image in the image manager is clicked, a HTTP request is automatically made to the server with a
srcparameter containing the image file name.
-
The server processes the HTTP request to delete the image.
The server has to process the request and physically delete the image. An example for this action can be found in the Froala Editor SDKS.
Note: Returning a JSON with an error field will throw an error with the custom message contained. E.g. { "error": "My custom error message." }
The following snippet highlights how to initialize the Froala WYSIWYG HTML Editor in order to use the image manager.
// Include the image manager plugin.
<script src="../../js/plugins/image_manager.min.js"></script>
<script>
new FroalaEditor('.selector', {
// Set a preloader.
imageManagerPreloader: "/images/loader.gif",
// Set page size.
imageManagerPageSize: 20,
// Set a scroll offset (value in pixels).
imageManagerScrollOffset: 10,
// Set the load images request URL.
imageManagerLoadURL: "http://example.com/load_images",
// Set the load images request type.
imageManagerLoadMethod: "GET",
// Additional load params.
imageManagerLoadParams: {user_id: 4219762},
// Set the delete image request URL.
imageManagerDeleteURL: "http://example.com/delete_image",
// Set the delete image request type.
imageManagerDeleteMethod: "DELETE",
// Additional delete params.
imageManagerDeleteParams: {param: 'value'},
events: {
'imageManager.error': function (error, response) {
// Bad link. One of the returned image links cannot be loaded.
if (error.code == 10) { ... }
// Error during request.
else if (error.code == 11) { ... }
// Missing imagesLoadURL option.
else if (error.code == 12) { ... }
// Parsing response failed.
else if (error.code == 13) { ... }
....
},
'imageManager.imagesLoaded': function (data) {
// Do something when the request finishes with success.
alert ('Images have been loaded.');
},
'imageManager.imageLoaded': function ($img) {
// Do something when an image is loaded in the image manager
alert ('Image has been loaded.');
},
'imageManager.beforeDeleteImage': function ($img) {
// Do something before deleting an image from the image manager.
alert ('Image will be deleted.');
},
'imageManager.imageDeleted': function (data) {
// Do something after the image was deleted from the image manager.
alert ('Image has been deleted.');
}
}
})
</script>
Do you think we can improve this article? Let us know.
