Preview Plugin
Adds a preview button that opens a modal dialog displaying the editor's content as it would appear to end users. This plugin allows previewing the final output without leaving the editor.
Features
- Preview button in toolbar
- Modal dialog displaying content
- Full WYSIWYG rendering
- Works in both source and WYSIWYG modes
- Configurable dialog size (1024x600px default)
- Clean up on dialog close
- Supports custom content via command
- Eye icon for button
Configuration Options
This plugin has no additional configuration options beyond the control configuration.
preview
Control
Icon: 'eye'
Command: 'preview'
Mode: MODE_SOURCE + MODE_WYSIWYG
(available in both modes)
Tooltip: 'Preview'
Opens a modal dialog showing a preview of the editor's content.
Basic Usage
const editor = Jodit.make('#editor');
// Click Preview button in toolbar
Programmatic Preview
const editor = Jodit.make('#editor');
// Open preview dialog
editor.execCommand('preview');
Preview Custom Content
const editor = Jodit.make('#editor');
// Preview specific HTML
editor.execCommand('preview', false, '<h1>Custom Preview Content</h1>');
Custom Button Configuration
Jodit.make('#editor', {
buttons: ['bold', 'italic', 'preview'],
controls: {
preview: {
icon: 'eye',
tooltip: 'Show Preview'
}
}
});
Preview Dialog Creation
When preview command is executed:
- Dialog Creation: Creates new dialog via
editor.dlg()
- Size Setting: Sets dialog size to 1024x600px
- Modal Mode: Sets dialog as modal (blocks editor interaction)
- Title: Sets header to localized "Preview"
- Content Rendering: Calls
previewBox()
helper to render content - Cleanup: Registers cleanup function for dialog close event
Content Source
The preview uses:
defaultValue
parameter if provided to command- Otherwise, current editor content (
editor.value
)
Preview Rendering
The previewBox()
helper:
- Creates preview container
- Applies editor styles to preview
- Renders HTML content
- Returns cleanup function
- Uses 'px' as dimension unit
Dialog Lifecycle
- Open: Dialog opens with preview content
- Display: Content rendered in modal dialog
- User Interaction: User can view (but not edit) content
- Close: User closes dialog
- Cleanup: Registered cleanup function executes
preview
Opens preview dialog displaying editor content.
Syntax:
editor.execCommand('preview', false, content?: string)
Parameters:
content
(optional): Custom HTML to preview instead of editor content
Example:
// Preview current editor content
editor.execCommand('preview');
// Preview custom HTML
editor.execCommand('preview', false, '<div>Custom content</div>');
Edge Cases
-
Empty Editor: Preview shows empty content (blank dialog)
-
Source Mode: Preview button works in source mode too (parses HTML)
-
Custom Content: Providing
defaultValue
overrides editor content -
Modal Dialog: Dialog blocks all editor interaction until closed
-
Size Fixed: Dialog size is hardcoded (1024x600px)
-
Multiple Previews: Opening preview while one is open closes previous
-
Cleanup: Resources cleaned up via
afterClose
event handler
Notes
- Plugin is functional (not class-based), registered via
pluginSystem.add()
- Preview button appears in toolbar with eye icon
- Dialog size is fixed at 1024x600px (not configurable)
- The
previewBox()
helper is shared with print plugin - Preview content is read-only (not editable)
- Dialog title uses localized "Preview" text
- The plugin uses modal dialog to prevent editor interaction during preview
- Dialog automatically cleans up resources on close
- Preview rendering uses same styles as editor for consistency
- The command accepts optional HTML parameter for custom previews
- Button is available in both SOURCE and WYSIWYG modes
- Dialog content container retrieved via
dialog.getElm('content')
- The
previewBox()
function returns array:[element, cleanupFunction]
- Cleanup function registered with
dialog.e.on(dialog, 'afterClose', ...)
- Preview does not modify editor content (read-only view)
- No configuration options for dialog size or behavior
- Plugin has no initialization or destruction logic (registers button/command only)
Typical Use Case
Users need to see how their content will appear to end readers before publishing. The preview plugin provides this by:
- Opening a clean view of the content
- Removing editor UI elements
- Showing the final rendered output
- Allowing quick inspection without leaving the editor
This is useful for:
- Checking formatting and layout
- Verifying images and media display correctly
- Ensuring content appears as intended
- Quick quality assurance before saving/publishing
preview
preview(editor
): void
Parameters
Name | Type |
---|---|
editor |
IJodit |
Returns
void
Defined in
jodit/src/plugins/preview/preview.ts:28