Setka Post Editor initialization (JavaScript)
Terms and Definitions
Style Manager: web interface for creating and editing a branded style of a publication (module grid, text and color styles, icons, etc.). You can find it at editor.setka.io.
Post: HTML code of the post wrapped in <div class=“stk-post”>...</div>
.
Post style: a set of CSS rules for text styles, fonts, colors, dividers, etc., which determines a branded style of a publication. Post style is edited in Style Manager.
Post grid system: a set of CSS rules for building grid modules with columns and indents and for adaptation to mobile devices. The post grid system is edited in the Style Manager.
All styles and grid systems within one company are uploaded from Style Manager to CDN in the form of a CSS file with styles and a JSON file with meta information to be used in the editor.
The editor requires 5 files to operate properly. These files need to be loaded in the post-editing and/or view pages.
File | Description | Post-editing page | Post view page |
editor.min.js | Main editor file | yes | no |
editor.min.css | Editor UI styles | yes | no |
company_name.min.css | Post styles defined in the Style Manager (fonts, colors, grids, etc.) | yes | yes |
company_name.json | JSON with metadata required for work of the editor | yes | no |
public.js | JS code required for work of interactive capabilities of the editor (galleries, animation) | no | yes |
Editor integration steps
4 initial steps of the integration should be passed to use Setka Editor fully:
1. Load all of the required files to a post-editing page and add the editor initialization code.
2. Load all of the required files to a post view page.
3. Configure saving the post HTML code into a database and load it back into the editor.
4. Use the editor API to upload and delete images from your server.
1. Initializing the editor
Here is the editor initialization sample code:
Only one instance of Setka Editor can be launched on a page at the moment.
To stop and remove the working editor instance from the page, please use this method:
2. Add the company styles and scripts to the post view page
To view posts correctly, load these files to external pages of the site:
company_name.v.1.2.3.min.css
— CSS styles of the post.
public.v.1.2.3.js
— JS code for launching interactive elements (galleries, animations, footnotes. etc.)
Do not link the public.js
file to the post editing page.
Getting post's JSON
This method is available only with a JSONExport
key.
Getting assets (images, layouts, symbols, themes)
Getting a current post's style
Getting a current post's grid
3. Saving the HTML code to the database and loading it back to the editor
Setting a post's content
where HTML stands for a required string.
How to get the content from the editor for saving it to the database
There is a specific method to get the post HTML code from the editor:
Do not get the editor's content by queries to DOM elements on a page — they contain some extra elements and attributes, required only for working in the editor. They should not get into the saved post's HTML code. Always use the SetkaEditor.getHTML()
method.
How to open the previously saved post in the editor
To open the existing post in the editor, please call the SetkaEditor.replaceHTML()
method after the editor initialization:
Do not put the post's HTML code on its' editing page. If <script>
and <iframe>
tags are present in the code, they will be executed by the browser. Also, animation styles may apply to elements inside the editor.
Setka Editor works with its' own HTML code structure. The post should be wrapped into the <div class=”stk-post”>...</div>
container and contain elements with specific classes and attributes. Unfamiliar elements may come uneditable or cause the editor launch error. There is no sense in trying to open posts created in other editors, in Setka Editor.
4. Working with images
Setka Editor interface supports the following operations with images: loading, deleting, and editing the alt
attribute.
To make Setka Editor able to work with images from your server, please do the following:
1. Build the image operations API on your server or use one of the existing APIs. The implementation fully depends on your preferences.
2. Write JavaScript functions for API interactions (there are some examples below).
3. Specify these functions on editor initialization:
The editor supports the srcset
attribute for images. Thus, you can generate images of various sizes and handle them in the sizes
key on editor start and on loading new images. As a result, images that are fit to a user's browser width will be loaded automatically.
Loading images
Deleting images
Editing images
Launching the editor with a set of images
To start the editor with the specific set of images in the right sidebar (e.g., uploaded with an earlier saved post), this set should be added into the assets
object on start.
Getting images from the panel
Integration with image storages
In Setka Editor, you can not only download images manually from your PC or via the Unsplash library but can also set integration with the image storage from your CMS. Such integration allows you to use images already downloaded to your storage in new Setka Editor posts. Once you accomplish this integration, a new option called Media Library (you can set any custom name for it) will be added to the right panel.
Once you click on it, you will see a pop-up window with the pictures from your storage and a search field. You can choose a set of pictures that appears in the pop-up, e.g., choose the most frequently used images or a set of images for any search query (should be set on the side of your CMS), or even not show any images at all by default.
Once an image has been chosen, it is being uploaded to the editor's right panel, and you can work with it just like you do with any other image in Setka Editor, downloaded in any default way.
Here is an example of how this feature works with our WordPress storage:
Integration description
To run the integration with your media library, you need to send an object `customMediaLibrary`
to the editor's configuration. This object should have 4 keys:
responsible for a search field in the interface;
responsible for the integration's name in the interface;
this function is called during images download to the editor;
downloads images, inserted in a post.
An example of a full integration:
Additional initialization parameters
Setting post's style
where id stands for a required number.
Setting post's grid
where id stands for a required number.
Setting indents for the Setka Editor header
If you already have an element that sticks on top of the page (e.g., top navigation bar), you can set an indent for the Setka Editor header to prevent overlay of one panel to another.
Indent size should be equal to the height of your top or bottom sticky panel, respectively:
Tracking changes in the editor
To subscribe to post content changes in the editor, use the onPostContentChange
callback function:
Getting the editor's status
The method returns true/false depending on whether the editor is launched or not.
Getting editor's state
Getting editor's configuration
Launching the editor inside a scrollable container
If you are launching the editor inside the scrollable DOM container, you will need to pass its' CSS selector in the scrollingElement
parameter for the correct sticking of the top and bottom bars to the boundaries of this container:
Default value — window.document
.
Adding your own styles and scripts into the editor preview
To add your own styles or scripts to the editor preview mode (opens on pressing the TAB button), use previewCSS
and previewJS
keys, containing arrays with paths to required files of styles and scripts, respectively:
Working with the editor functions if requests to external CDNs are not possible
Even if you save style and editor files on your platform when working with the Style Manager API, some internal functions of the editor (Enhance Symbols, Unsplash, and WordPress Media Library integrations, image editor) are always loaded from the Setka Editor CDN. If requesting files from external resources is prohibited on your platform, save those files on your server and connect them to the editor's initialization.
Please note that the files should be hosted without a redirect. Editor internal functionality files can be received by contacting our support team on support@tiny.cloud or via chat.
To get these files on editor initialization, use the featureRootURL
key. You will need to pass the path to the folder with the files on your server via this key:
The editor will be requesting such files afterward:
More about custom integration:
Last updated