1
|
CKEditor Imageresponsive Plugin
|
2
|
==========
|
3
|
|
4
|
Copyright (c) 2003-2014, Clemens Krack All rights reserved.
|
5
|
See http://ckeditor.com/license for license information.
|
6
|
|
7
|
This is a further enhancement to the image2 plugin (enhanced image) by CKSource.
|
8
|
It includes support for the responsive images attributes `srcset` and `sizes`.
|
9
|
Two textfields are added to the dialog window, and it is possible to integrate with your custom fileuploader.
|
10
|
|
11
|
## Installation
|
12
|
|
13
|
1. Download the package.
|
14
|
2. Extract files and save them in ckeditor/plugins/imageresponsive directory.
|
15
|
3. Enable the plugin:
|
16
|
`config.extraPlugins = 'imageresponsive';`
|
17
|
|
18
|
**Dependencies:** Requires the following plugins to work: Image2, Widget, Line Utilities, Dialog, Clipboard.
|
19
|
|
20
|
## How to use
|
21
|
|
22
|
Either simply let users set the sizes and srcset attributes by hand, or integrate it with your own filebrowser/quickupload plugin.
|
23
|
|
24
|
## Integrating with your own filebrowser
|
25
|
|
26
|
You can integrate this plugin further, when using a custom quickupload / filebrowser plugin for CKEditor.
|
27
|
|
28
|
You should implement the logic to save uploaded images in different sizes in your connector.
|
29
|
These can either be static sizes or just percentages based on the width of the uploaded image.
|
30
|
When using static sizes, you should check for the original dimensions and only use sizes lower than that.
|
31
|
|
32
|
When putting the callback to CKEditor into your custom filebrowser, you can pass in a complete srcset.
|
33
|
This is done via the third parameter, which is executed in the scope of the dialog, if it is a function.
|
34
|
|
35
|
window.parent.CKEDITOR.tools.callFunction(callback, "/images/upload.jpg", function() {
|
36
|
// Get the reference to a dialog window.
|
37
|
var element,
|
38
|
dialog = this.getDialog();
|
39
|
// Check if this is the Image dialog window.
|
40
|
if ( dialog.getName() == 'imageresponsive' ) {
|
41
|
// Get the reference to a text field that holds the "srcset" attribute.
|
42
|
element = dialog.getContentElement( 'info', 'srcset' );
|
43
|
// Assign the new value.
|
44
|
if ( element )
|
45
|
element.setValue( 'upload-small.jpg 100w, upload-medium.jpg 500w, upload-big.jpg 1000w' );
|
46
|
}
|
47
|
});
|