EditorContext.blur(Object object)
Blurs the editor and hides the on-screen keyboard.
Since: 1.0.17
Parameters
The input parameter is an object containing the following fields.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| success | function | No | Callback triggered when the API call is successful. |
| fail | function | No | Callback triggered when the API call fails. |
| complete | function | No | Callback triggered when the API call is complete, regardless of success or failure. |
Example:
has.createSelectorQuery().select('#editor').context((res) => {
let editorCtx = res.context;
editorCtx.blur({
success: () => {
console.info('blur success');
},
fail: () => {
console.error('blur fail');
},
complete: () => {
console.info('blur complete');
}
});
}).exec(); EditorContext.clear(Object object)
Clears the editor content.
Since: 1.0.17
Parameters
The input parameter is an object containing the following fields.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| success | function | No | Callback triggered when the API call is successful. |
| fail | function | No | Callback triggered when the API call fails. |
| complete | function | No | Callback triggered when the API call is complete, regardless of success or failure. |
Example:
has.createSelectorQuery().select('#editor').context((res) => {
let editorCtx = res.context;
editorCtx.clear({
success: () => {
console.info('clear success');
},
fail: () => {
console.error('clear fail');
},
complete: () => {
console.info('clear complete');
}
});
}).exec(); EditorContext.deleteText(Object object)
Deletes the content within the specified selection range.
Since: 1.0.17
Parameters
The input parameter is an object containing the following fields.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| index | number | Yes | Start position of the selection. |
| length | number | No | Length of the selection. |
| success | function | No | Callback triggered when the API call is successful. |
| fail | function | No | Callback triggered when the API call fails. |
| complete | function | No | Callback triggered when the API call is complete, regardless of success or failure. |
Example:
has.createSelectorQuery().select('#editor').context((res) => {
let editorCtx = res.context;
editorCtx.deleteText({
index: 1,
length: 2,
success: () => {
console.info('deleteText success');
},
fail: () => {
console.error('deleteText fail');
},
complete: () => {
console.info('deleteText complete');
}
});
}).exec(); EditorContext.format(string name, string value)
Modifies the format of the currently selected text by specifying a property (name) and its desired setting (value).
Since: 1.0.17
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Attribute name. The available options are listed in the table below. |
| value | string | - | Attribute value. Its necessity and valid options depend on name. For details, see the table below. |
Available options for name and value combinations
| name | value | Description |
|---|---|---|
| bold | true, false, or null | Bold. The default value is true. |
| italic | true, false, or null | Italic. The default value is true. |
| underline | true, false, or null | Underline. The default value is true. |
| strike | true, false, or null | Strikethrough. The default value is true. |
| ins | true, false, or null | Underline. The default value is true. |
| script | sub / sup | Superscript or subscript. |
| header | h1 / h2 / h3 / h4 / h5 / h6 | Title. |
| align | left / center / right / justify | Alignment mode. |
| direction | rtl | Text direction. |
| indent | -1 / +1 | Increases (+1) or decreases (-1) paragraph indentation by one step. |
| list | ordered / bullet / checked / unchecked | List. |
| color | hex color | Color (in hexadecimal format). Example: EditorContext.format('color','#ff0000') |
| backgroundColor | hex color | Background color (in hexadecimal format). Example: EditorContext.format('backgroundColor','#ff0000') |
| margin / marginTop / marginBottom / marginLeft / marginRight | css style | Outer margin. Example: EditorContext.format('margin','4px 8px') EditorContext.format('marginTop','4px') |
| padding / paddingTop / paddingBottom / paddingLeft / paddingRight | css style | Inner margin. Example: EditorContext.format('padding','4px 8px') EditorContext.format('paddingTop','4px') |
| font / fontSize / fontStyle / fontVariant / fontWeight / fontFamily | css style | Font. Example: EditorContext.format('font','italic bold 16px') EditorContext.format('fontSize','16px') EditorContext.format('fontStyle','italic') EditorContext.format('fontVariant ','small-caps') EditorContext.format('fontWeight ','bold') EditorContext.format('fontFamily','sans-serif') |
| lineHeight | css style | Line height. Example: EditorContext.format('lineHeight','20px') |
| letterSpacing | css style | Spacing between characters. Example: EditorContext.format('letterSpacing','2px') |
| textDecoration | css style | Text decoration. Example: EditorContext.format('textDecoration','underline') |
| textIndent | css style | Text indentation. Example: EditorContext.format('textIndent','8px') |
| wordWrap | css style | Rule for wrapping words. Example: EditorContext.format('wordWrap','revert') |
| wordBreak | css style | Rule for breaking words. Example: EditorContext.format('wordBreak','break-all') |
| whiteSpace | css style | Rule for processing whitespace. Example: EditorContext.format('whiteSpace','wrap') |
Example:
has.createSelectorQuery().select('#editor').context((res) => {
let editorCtx = res.context;
editorCtx.format('bold', true);
}).exec(); EditorContext.getBounds(Object object)
Obtains the position and size of the specified selection.
Since: 1.0.17
Parameters
The input parameter is an object containing the following fields.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| index | number | Yes | Start position of the selection. |
| length | number | No | Length of the selection. |
| success | function | No | Callback triggered when the API call is successful. |
| fail | function | No | Callback triggered when the API call fails. |
| complete | function | No | Callback triggered when the API call is complete, regardless of success or failure. |
Return value of success
| Parameter | Type | Description |
|---|---|---|
| bounds | Object | Size and position of the selection relative to the viewport. |
Attributes of bounds
| Attribute | Type | Description |
|---|---|---|
| left | number | Distance from the left edge of the viewport. |
| top | number | Distance from the upper edge of the viewport. |
| width | number | Width of the selected text. |
| height | number | Row height of the input box. |
Example:
has.createSelectorQuery().select('#editor').context((res) => {
let editorCtx = res.context;
editorCtx.getBounds({
index: 1,
length: 2,
success: (res) => {
const left = res.bounds.left;
const top = res.bounds.top;
const width = res.bounds.width;
const height = res.bounds.height;
},
fail: () => {
console.error('getBounds fail');
},
complete: () => {
console.info('getBounds complete');
}
});
}).exec(); EditorContext.getContents(Object object)
Obtains the editor content.
Since: 1.0.17
Parameters
The input parameter is an object containing the following fields.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| success | function | No | Callback triggered when the API call is successful. |
| fail | function | No | Callback triggered when the API call fails. |
| complete | function | No | Callback triggered when the API call is complete, regardless of success or failure. |
Return value of success
| Parameter | Type | Description |
|---|---|---|
| html | string | HTML content with tags. |
| text | string | Plain text. |
| delta | Object | Delta object. |
Example:
has.createSelectorQuery().select('#editor').context(function (res) {
let editorCtx = res.context;
editorCtx.getContents({
success: (res) => {
const { html, text, delta } = res;
},
fail: () => {
console.error('getContents fail');
},
complete: () => {
console.info('getContents complete');
}
})
}).exec(); EditorContext.getSelection(Object object)
Obtains the current selection.
Since: 1.0.17
Parameters
The input parameter is an object containing the following fields.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| success | function | No | Callback triggered when the API call is successful. |
| fail | function | No | Callback triggered when the API call fails. |
| complete | function | No | Callback triggered when the API call is complete, regardless of success or failure. |
Return value of success
| Parameter | Type | Description |
|---|---|---|
| range | Object | Selection range, where index indicates the start position, and length indicates the selection length. |
| bounds | Object | Size and position of the selection relative to the viewport. |
Attributes of range
| Attribute | Type | Description |
|---|---|---|
| index | number | Start location. |
| length | number | Length of the selection. |
Attributes of bounds
| Attribute | Type | Description |
|---|---|---|
| left | number | Distance from the left edge of the viewport. |
| top | number | Distance from the upper edge of the viewport. |
| width | number | Width of the selected text. |
| height | number | Row height of the input box. |
Example:
has.createSelectorQuery().select('#editor').context((res) => {
let editorCtx = res.context;
editorCtx.getSelection({
success: (res) => {
const left = res.bounds.left;
const top = res.bounds.top;
const width = res.bounds.width;
const height = res.bounds.height;
const index = res.range.index;
const length = res.range.length;
},
fail: () => {
console.error('getSelection fail');
},
complete: () => {
console.info('getSelection complete');
}
});
}).exec(); EditorContext.getSelectionText(Object object)
Obtains the plain text from the selection range of the editor. It returns an empty result if the editor is out of focus or nothing is selected.
Since: 1.0.17
Parameters
The input parameter is an object containing the following fields.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| success | function | No | Callback triggered when the API call is successful. |
| fail | function | No | Callback triggered when the API call fails. |
| complete | function | No | Callback triggered when the API call is complete, regardless of success or failure. |
Return value of success
| Parameter | Type | Description |
|---|---|---|
| text | string | Plain text. |
Example:
has.createSelectorQuery().select('#editor').context((res) => {
let editorCtx = res.context;
editorCtx.getSelectionText({
success: (res) => {
const text = res.text;
},
fail: () => {
console.error('getSelectionText fail');
},
complete: () => {
console.info('getSelectionText complete');
}
});
}).exec(); EditorContext.insertDivider(Object object)
Inserts a divider.
Since: 1.0.17
Parameters
The input parameter is an object containing the following fields.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| success | function | No | Callback triggered when the API call is successful. |
| fail | function | No | Callback triggered when the API call fails. |
| complete | function | No | Callback triggered when the API call is complete, regardless of success or failure. |
Example:
has.createSelectorQuery().select('#editor').context((res) => {
let editorCtx = res.context;
editorCtx.insertDivider({
success: () => {
console.info('insertDivider success');
},
fail: () => {
console.error('insertDivider fail');
},
complete: () => {
console.info('insertDivider complete');
}
});
}).exec(); EditorContext.insertImage(Object object)
Inserts an image.
Since: 1.0.17
Parameters
The input parameter is an object containing the following fields.
| Parameter | Type | Default Value | Mandatory | Description |
|---|---|---|---|---|
| src | string | - | Yes | URL of the image. Only http and https are supported. |
| nowrap | boolean | false | No | Whether to automatically add a line break after the image. By default, wrapping is enabled. |
| alt | string | - | No | Alternative text displayed if the image fails to load. |
| width | string | - | No | Width of the image, in pixels or percentage. |
| height | string | - | No | Height of the image, in pixels or percentage. |
| extClass | string | - | No | Class name added to the img element. |
| data | Object | - | No | Custom data attached to the image as a serialized string in the data-custom property (format: name=value;name1=value2). |
| success | function | - | No | Callback triggered when the API call is successful. |
| fail | function | - | No | Callback triggered when the API call fails. |
| complete | function | - | No | Callback triggered when the API call is complete, regardless of success or failure. |
Example:
has.createSelectorQuery().select('#editor').context((res) => {
let editorCtx = res.context;
editorCtx.insertImage({
src: 'https://www.example.com/xxx.png', // Replace the example with the actual image resource address.
width: '100px',
height: '50px',
extClass: 'imgWrap',
success: () => {
console.info('insertImage success');
},
fail: () => {
console.error('insertImage fail');
},
complete: () => {
console.info('insertImage complete');
}
});
}).exec(); EditorContext.insertText(Object object)
Replaces any currently selected text in the editor with new text.
Since: 1.0.17
Parameters
The input parameter is an object containing the following fields.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| text | string | No | Text content. |
| success | function | No | Callback triggered when the API call is successful. |
| fail | function | No | Callback triggered when the API call fails. |
| complete | function | No | Callback triggered when the API call is complete, regardless of success or failure. |
Example:
has.createSelectorQuery().select('#editor').context((res) => {
let editorCtx = res.context;
editorCtx.insertText({
text: 'Hello World',
success: () => {
console.info('insertText success');
},
fail: () => {
console.error('insertText fail');
},
complete: () => {
console.info('insertText complete');
}
});
}).exec(); EditorContext.redo(Object object)
Redoes the previous operation.
Since: 1.0.17
Parameters
The input parameter is an object containing the following fields.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| success | function | No | Callback triggered when the API call is successful. |
| fail | function | No | Callback triggered when the API call fails. |
| complete | function | No | Callback triggered when the API call is complete, regardless of success or failure. |
Example:
has.createSelectorQuery().select('#editor').context((res) => {
let editorCtx = res.context;
editorCtx.redo({
success: () => {
console.info('redo success');
},
fail: () => {
console.error('redo fail');
},
complete: () => {
console.info('redo complete');
}
});
}).exec(); EditorContext.removeFormat(Object object)
Removes all text formatting from the currently selected text in the editor.
Since: 1.0.17
Parameters
The input parameter is an object containing the following fields.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| success | function | No | Callback triggered when the API call is successful. |
| fail | function | No | Callback triggered when the API call fails. |
| complete | function | No | Callback triggered when the API call is complete, regardless of success or failure. |
Example:
has.createSelectorQuery().select('#editor').context((res) => {
let editorCtx = res.context;
editorCtx.removeFormat({
success: () => {
console.info('removeFormat success');
},
fail: () => {
console.error('removeFormat fail');
},
complete: () => {
console.info('removeFormat complete');
}
});
}).exec(); EditorContext.scrollIntoView()
Scrolls the editor cursor to the visible area of the window.
Since: 1.0.17
Example:
has.createSelectorQuery().select('#editor').context((res) => {
let editorCtx = res.context;
editorCtx.scrollIntoView();
}).exec(); EditorContext.setContents(Object object)
Sets the initial content for the editor. If both HTML and a delta object are provided, only the delta data is used.
Since: 1.0.17
Parameters
The input parameter is an object containing the following fields.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| html | string | No | HTML data with tags. |
| delta | Object | No | Delta object. |
| success | function | No | Callback triggered when the API call is successful. |
| fail | function | No | Callback triggered when the API call fails. |
| complete | function | No | Callback triggered when the API call is complete, regardless of success or failure. |
Example:
has.createSelectorQuery().select('#editor').context((res) => {
let editorCtx = res.context;
editorCtx.setContents({
delta: {},
success: () => {
console.info('setContents success');
},
fail: () => {
console.error('setContents fail');
},
complete: () => {
console.info('setContents complete');
}
});
}).exec(); EditorContext.setSelection(Object object)
Sets the current selection.
Since: 1.0.17
Parameters
The input parameter is an object containing the following fields.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| index | number | Yes | Start position of the selection. |
| length | number | No | Length of the selection. |
| success | function | No | Callback triggered when the API call is successful. |
| fail | function | No | Callback triggered when the API call fails. |
| complete | function | No | Callback triggered when the API call is complete, regardless of success or failure. |
Example:
has.createSelectorQuery().select('#editor').context((res) => {
let editorCtx = res.context;
editorCtx.setSelection({
index: 1,
length: 2,
success: () => {
console.info('setSelection success');
},
fail: () => {
console.error('setSelection fail');
},
complete: () => {
console.info('setSelection complete');
}
});
}).exec(); EditorContext.undo(Object object)
Undoes the previous operation.
Since: 1.0.17
Parameters
The input parameter is an object containing the following fields.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| success | function | No | Callback triggered when the API call is successful. |
| fail | function | No | Callback triggered when the API call fails. |
| complete | function | No | Callback triggered when the API call is complete, regardless of success or failure. |
Example:
has.createSelectorQuery().select('#editor').context((res) => {
let editorCtx = res.context;
editorCtx.undo({
success: () => {
console.info('undo success');
},
fail: () => {
console.error('undo fail');
},
complete: () => {
console.info('undo complete');
}
});
}).exec();