The MarkupEditor logo

Class: BehaviorConfig

BehaviorConfig()

BehaviorConfig contains static utility methods to obtain a JavaScript object with properties that define the behavior configuration of the MarkupEditor. The class makes it convenient to write and use the utility methods, but an instance of BehaviorConfig itself is not meaningful.

BehaviorConfig.standard() is the default for the MarkupEditor. It can be overridden by passing a new BehaviorConfig by name using the behavior attribute of the <markup-editor> element. You can use the pre-defined static methods like standard() and customize what it returns, or you can use your own BehaviorConfig.

To customize the behavior config, for example, in a userscript named mybehavior.js:

import {MU} from "src/markup-editor.js"
let behaviorConfig = MU.BehaviorConfig.desktop()        // Use the desktop config as a baseline
MU.registerConfig(behaviorConfig, "MyBehaviorConfig")   // Register the instance by name so we can reference it

Then, where you insert the <markup-editor> element, set the BehaviorConfig by name:

<markup-editor userscript="mybehavior.js" behavior="MyBehaviorConfig">

BehaviorConfig lets you control whether the editor takes focus immediately or not, and allows you to defer to the MarkupDelegate for insert options, so you can use your own (perhaps "native") dialogs for file selection, link insertion, and image insertion.

The following properties are supported:

{
   "focusAfterLoad": true,     // Whether the editor should take focus after loading
   "selectImage": false,       // Whether to show a "Select..." button in the Insert Image dialog
   "insertLink": false,        // Whether to defer to the MarkupDelegate rather than use the default LinkDialog
   "insertImage": false,       // Whether to defer to the MarkupDelagate rather than use the default ImageDialog
}

Constructor

new BehaviorConfig()

Methods

(static) desktop() → {object}

Return the desktop behavior configuration object. This is the same as full() but with selectImage enabled.

Returns:

A JavaScript object with settings for desktop-style usage.

Type
object

(static) fromJSON(string) → {object}

Return a behavior configuration object, but defined from a stringified JSON object.

Parameters:
Name Type Description
string string

A stringified object, perhaps used as an external definition of a behavior configuration

Returns:

An object parsed from the JSON in string, should contain data for all properties

Type
object

(static) full() → {object}

Return a behavior configuration object with all options enabled.

Returns:

A JavaScript object with all options enabled.

Type
object

(static) standard() → {object}

Return a default behavior configuration object.

Returns:

A JavaScript object with all settings.

Type
object

Table of contents