Helpers/utils
- Classes
- Loader
- AbortError
- alreadyLoadedList
- keepNames
- cns
- hAlignElement
- clearAlign
- alignElement
- appendScriptAsync
- appendStyleAsync
- loadNext
- loadNextStyle
- assert
- attr
- browser
- buildQuery
- completeUrl
- ConfigProto
- ConfigFlatten
- ConfigDeepFlatten
- convertMediaUrlToVideoEmbed
- css
- clearCenterAlign
- ctrlKey
- dataBind
- defaultLanguage
- error
- connection
- options
- abort
- isAbort
- isAtom
- markAsAtomic
- fastClone
- getClassName
- get
- humanSizeToBytes
- markDeprecated
- parseQuery
- reset
- inView
- scrollIntoViewIfNeeded
- $$
- getXPathByElement
- refs
- cssPath
- resolveElement
- set
- call
- markOwner
- callPromise
- loadImage
- keys
- memorizeExec
- getDataTransfer
- previewBox
Classes
Loader
Loader: (jodit: IViewBased, url: string) => Promise<any>
Type declaration
(jodit, url): Promise<any>
Parameters
| Name | Type |
|---|---|
jodit |
IViewBased |
url |
string |
Returns
Promise<any>
Defined in
src/core/helpers/utils/append-script.ts#16
AbortError
AbortError: DOMException & { name: "AbortError" }
AbortError is not a separate exception, but rather a DOMException with a special name.
https://webidl.spec.whatwg.org/#aborterror
Defined in
src/core/helpers/utils/error/errors/abort-error.ts#17
alreadyLoadedList
Const alreadyLoadedList: Map<string, Promise<any>>
Defined in
src/core/helpers/utils/append-script.ts#18
keepNames
Const keepNames: Map<Function, string>
Defined in
src/core/helpers/utils/get-class-name.ts#14
cns
Const cns: Console = console
By default, terser will remove all console.* but
if you use this object it will not be
Defined in
src/core/helpers/utils/mark-deprecated.ts#15
hAlignElement
hAlignElement(image, align): void
Align image
Parameters
| Name | Type |
|---|---|
image |
HTMLElement |
align |
ImageHAlign |
Returns
void
Defined in
src/core/helpers/utils/align.ts#18
clearAlign
clearAlign(node): void
Remove text-align style for all selected children
Parameters
| Name | Type |
|---|---|
node |
Node |
Returns
void
Defined in
src/core/helpers/utils/align.ts#48
alignElement
alignElement(command, box): void
Apply align for element
Parameters
| Name | Type |
|---|---|
command |
string |
box |
HTMLElement |
Returns
void
Defined in
src/core/helpers/utils/align.ts#65
appendScriptAsync
appendScriptAsync(jodit, url): Promise<any>
Load script and return promise
Parameters
| Name | Type |
|---|---|
jodit |
IViewBased<IViewOptions> |
url |
string |
Returns
Promise<any>
Defined in
src/core/helpers/utils/append-script.ts#37
appendStyleAsync
appendStyleAsync(jodit, url): Promise<any>
Download CSS style script
Parameters
| Name | Type |
|---|---|
jodit |
IViewBased<IViewOptions> |
url |
string |
Returns
Promise<any>
Defined in
src/core/helpers/utils/append-script.ts#61
loadNext
loadNext(jodit, urls, i?): Promise<void>
Parameters
| Name | Type | Default value |
|---|---|---|
jodit |
IViewBased<IViewOptions> |
undefined |
urls |
string[] |
undefined |
i |
number |
0 |
Returns
Promise<void>
Defined in
src/core/helpers/utils/append-script.ts#90
loadNextStyle
loadNextStyle(jodit, urls, i?): Promise<void>
Parameters
| Name | Type | Default value |
|---|---|---|
jodit |
IViewBased<IViewOptions> |
undefined |
urls |
string[] |
undefined |
i |
number |
0 |
Returns
Promise<void>
Defined in
src/core/helpers/utils/append-script.ts#104
assert
assert<T>(condition, message): asserts condition
Asserts that condition is truthy (or evaluates to true).
Type parameters
| Name |
|---|
T |
Parameters
| Name | Type |
|---|---|
condition |
undefined | null | false | "" | 0 | T |
message |
string |
Returns
asserts condition
Defined in
src/core/helpers/utils/assert.ts#19
attr
attr(elm, key): null | string
Get attribute
Parameters
| Name | Type |
|---|---|
elm |
Element |
key |
string |
Returns
null | string
Defined in
src/core/helpers/utils/attr.ts#24
attr(elm, key, value): void
Remove attribute
Parameters
| Name | Type |
|---|---|
elm |
Element |
key |
string |
value |
null |
Returns
void
Defined in
src/core/helpers/utils/attr.ts#29
attr(elm, key, value): null
Set attribute
Parameters
| Name | Type |
|---|---|
elm |
Element |
key |
string |
value |
undefined | null | string | number | boolean |
Returns
null
Defined in
src/core/helpers/utils/attr.ts#34
attr(elm, attributes): null
Set or remove several attributes
Parameters
| Name | Type |
|---|---|
elm |
Element |
attributes |
IDictionary<null | string | number | boolean> |
Returns
null
Defined in
src/core/helpers/utils/attr.ts#43
browser
browser(browser): string | boolean
Module returns method that is used to determine the browser
Parameters
| Name | Type |
|---|---|
browser |
string |
Returns
string | boolean
Example
console.log(Jodit.modules.Helpers.browser('mse'));
console.log(Jodit.modules.Helpers.browser('chrome'));
console.log($Jodit.modules.Helpers.browser('opera'));
console.log(Jodit.modules.Helpers.browser('firefox'));
console.log(Jodit.modules.Helpers.browser('mse') && Jodit.modules.Helpers.browser('version') > 10);
Defined in
src/core/helpers/utils/browser.ts#22
buildQuery
buildQuery(data, prefix?): string
Build query string
Parameters
| Name | Type |
|---|---|
data |
IDictionary |
prefix? |
string |
Returns
string
Defined in
src/core/helpers/utils/build-query.ts#17
completeUrl
completeUrl(url): string
Parameters
| Name | Type |
|---|---|
url |
string |
Returns
string
Defined in
src/core/helpers/utils/complete-url.ts#13
ConfigProto
ConfigProto(options, proto, deep?): IDictionary
Parameters
| Name | Type | Default value |
|---|---|---|
options |
IDictionary |
undefined |
proto |
IDictionary |
undefined |
deep |
number |
0 |
Returns
Example
const defaultConfig = {
a: {
b: {
c: 2
},
e: 5
},
d: {
g: 7
}
};
const options = ConfigProto({a: {
b: {
c: 1
}
}}, defaultConfig);
console.log(options.a.b.c); // 1
console.log(options.a.e); // 5
console.log(options.d.g); // 7
defaultConfig.d.g = 8;
console.log(options.d.g); // 8
Defined in
src/core/helpers/utils/config-proto.ts#51
ConfigFlatten
ConfigFlatten(obj): IDictionary
Parameters
| Name | Type |
|---|---|
obj |
IDictionary |
Returns
Defined in
src/core/helpers/utils/config-proto.ts#102
ConfigDeepFlatten
ConfigDeepFlatten(obj): IDictionary
Returns a plain object from a prototype-based object.
const editor = Jodit.make('#editor', {
image: {
dialogWidth: 500
}
});
console.log(editor.o.image.openOnDblClick) // true
// But you can't get all options in plain object
console.log(JSON.stringify(editor.o.image)); // {"dialogWidth":500}
const plain = Jodit.modules.Helpers.ConfigDeepFlatten(editor.o.image);
console.log(JSON.stringify(plain)); // {"dialogWidth":500, "openOnDblClick": true, "editSrc": true, ...}
Parameters
| Name | Type |
|---|---|
obj |
IDictionary |
Returns
Defined in
src/core/helpers/utils/config-proto.ts#126
convertMediaUrlToVideoEmbed
convertMediaUrlToVideoEmbed(url, «destructured»?): string
Javascript url pattern converter replace youtube/vimeo url in embed code.
Parameters
| Name | Type | Default value |
|---|---|---|
url |
string |
undefined |
«destructured» |
Object |
{} |
› width? |
number |
400 |
› height? |
number |
345 |
Returns
string
Defined in
src/core/helpers/utils/convert-media-url-to-video-embed.ts#19
css
css(element, key): string | number
Get the value of a computed style property for the first element in the set of matched elements or set one or
more CSS properties for every matched element
Parameters
| Name | Type | Description |
|---|---|---|
element |
HTMLElement |
HTML element |
key |
keyof CSSStyleDeclaration |
An object of property-value pairs to set. A CSS property name. |
Returns
string | number
Defined in
src/core/helpers/utils/css.ts#22
css(element, key): string | number
Get the value of a computed style property for the first element in the set of matched elements or set one or
more CSS properties for every matched element
Parameters
| Name | Type | Description |
|---|---|---|
element |
HTMLElement |
HTML element |
key |
string | IStyle |
An object of property-value pairs to set. A CSS property name. |
Returns
string | number
Defined in
src/core/helpers/utils/css.ts#27
css(element, key, value): string | number
Get the value of a computed style property for the first element in the set of matched elements or set one or
more CSS properties for every matched element
Parameters
| Name | Type | Description |
|---|---|---|
element |
HTMLElement |
HTML element |
key |
string | IStyle |
An object of property-value pairs to set. A CSS property name. |
value |
StyleValue |
A value to set for the property. |
Returns
string | number
Defined in
src/core/helpers/utils/css.ts#32
css(element, key, onlyStyleMode): string | number
Get the value of a computed style property for the first element in the set of matched elements or set one or
more CSS properties for every matched element
Parameters
| Name | Type | Description |
|---|---|---|
element |
HTMLElement |
HTML element |
key |
string | IStyle |
An object of property-value pairs to set. A CSS property name. |
onlyStyleMode |
boolean |
Get value from style attribute, without calculating |
Returns
string | number
Defined in
src/core/helpers/utils/css.ts#38
clearCenterAlign
clearCenterAlign(image): void
Clear center align
Parameters
| Name | Type |
|---|---|
image |
HTMLElement |
Returns
void
Defined in
src/core/helpers/utils/css.ts#123
ctrlKey
ctrlKey(e): boolean
CTRL pressed
Parameters
| Name | Type |
|---|---|
e |
MouseEvent | KeyboardEvent |
Returns
boolean
true ctrl key was pressed
Defined in
src/core/helpers/utils/ctrl-key.ts#15
dataBind
dataBind<T>(elm, key, value?): T
Type parameters
| Name | Type |
|---|---|
T |
any |
Parameters
| Name | Type |
|---|---|
elm |
object | Node | IViewComponent<IViewBased<IViewOptions>> |
key |
string |
value? |
T |
Returns
T
Defined in
src/core/helpers/utils/data-bind.ts#16
defaultLanguage
defaultLanguage(language?, defaultLanguage?): string
Try define user language
Parameters
| Name | Type | Default value |
|---|---|---|
language? |
string |
undefined |
defaultLanguage |
string |
'en' |
Returns
string
Defined in
src/core/helpers/utils/default-language.ts#17
error
error(message): Error
Helper for create Error object
Parameters
| Name | Type |
|---|---|
message |
string |
Returns
Defined in
src/core/helpers/utils/error/error.ts#16
connection
connection(message): Error
Parameters
| Name | Type |
|---|---|
message |
string |
Returns
Defined in
src/core/helpers/utils/error/error.ts#20
options
options(message): Error
Parameters
| Name | Type |
|---|---|
message |
string |
Returns
Defined in
src/core/helpers/utils/error/error.ts#24
abort
abort(message?): Error
Parameters
| Name | Type | Default value |
|---|---|---|
message |
string |
'Aborted' |
Returns
Defined in
src/core/helpers/utils/error/errors/abort-error.ts#19
isAbort
isAbort(error): error is AbortError
Parameters
| Name | Type |
|---|---|
error |
unknown |
Returns
error is AbortError
Deprecated
use isAbortError instead
Defined in
src/core/helpers/utils/error/errors/abort-error.ts#26
isAtom
isAtom(obj): boolean
Parameters
| Name | Type |
|---|---|
obj |
unknown |
Returns
boolean
Defined in
src/core/helpers/utils/extend.ts#13
markAsAtomic
markAsAtomic<T>(obj): T
Type parameters
| Name |
|---|
T |
Parameters
| Name | Type |
|---|---|
obj |
T |
Returns
T
Defined in
src/core/helpers/utils/extend.ts#17
fastClone
fastClone<T>(object): T
Type parameters
| Name |
|---|
T |
Parameters
| Name | Type |
|---|---|
object |
T |
Returns
T
Defined in
src/core/helpers/utils/extend.ts#27
getClassName
getClassName(obj): string
Parameters
| Name | Type |
|---|---|
obj |
IDictionary |
Returns
string
Defined in
src/core/helpers/utils/get-class-name.ts#16
get
get<T>(chain, obj): Nullable<T>
Safe access in tree object
Type parameters
| Name |
|---|
T |
Parameters
| Name | Type |
|---|---|
chain |
string |
obj |
IDictionary |
Returns
Nullable<T>
Example
const obj = {
a: {
b: {
c: {
e: false
}
}
}
};
console.log(Jodit.modules.Helpers.get('a.b.c.d.e', obj) === false); // true
console.log(Jodit.modules.Helpers.get('a.b.a.d.e', obj) === null); // false
Defined in
src/core/helpers/utils/get.ts#34
humanSizeToBytes
humanSizeToBytes(human): number
Converts from human readable file size (kb,mb,gb,tb) to bytes
Parameters
| Name | Type | Description |
|---|---|---|
human |
string |
readable file size. Example 1gb or 11.2mb |
Returns
number
Defined in
src/core/helpers/utils/human-size-to-bytes.ts#15
markDeprecated
markDeprecated(method, names?, ctx?): (...args: any[]) => void
Mark function as deprecated
Parameters
| Name | Type | Default value |
|---|---|---|
method |
Function |
undefined |
names |
string[] |
undefined |
ctx |
any |
null |
Returns
fn
(...args): void
Parameters
| Name | Type |
|---|---|
...args |
any[] |
Returns
void
Defined in
src/core/helpers/utils/mark-deprecated.ts#20
parseQuery
parseQuery(queryString): IDictionary<string>
Parse query string
Parameters
| Name | Type |
|---|---|
queryString |
string |
Returns
IDictionary<string>
Defined in
src/core/helpers/utils/parse-query.ts#16
reset
reset<T>(key): Nullable<T>
Reset Vanilla JS native function
Type parameters
| Name | Type |
|---|---|
T |
extends Function |
Parameters
| Name | Type |
|---|---|
key |
string |
Returns
Nullable<T>
Example
reset('Array.from')(Set([1,2,3])) // [1, 2, 3]
You must use the function derived from the method immediately as its iframe is being removed
Defined in
src/core/helpers/utils/reset.ts#27
inView
inView(elm, root, doc): boolean
Check if element is in view
Parameters
| Name | Type |
|---|---|
elm |
HTMLElement |
root |
HTMLElement |
doc |
Document |
Returns
boolean
Defined in
src/core/helpers/utils/scroll-into-view.ts#21
scrollIntoViewIfNeeded
scrollIntoViewIfNeeded(elm, root, doc): void
Scroll element into view if it is not in view
Parameters
| Name | Type |
|---|---|
elm |
Nullable<Node> |
root |
HTMLElement |
doc |
Document |
Returns
void
Defined in
src/core/helpers/utils/scroll-into-view.ts#55
$$
$$<T>(selector, root): T[]
Type parameters
| Name | Type |
|---|---|
T |
extends HTMLElement |
Parameters
| Name | Type |
|---|---|
selector |
string |
root |
HTMLElement | DocumentFragment |
Returns
T[]
Deprecated
Do not use it in new code
Defined in
src/core/helpers/utils/selector.ts#50
getXPathByElement
getXPathByElement(element, root): string
Calculate XPath selector
Parameters
| Name | Type |
|---|---|
element |
HTMLElement |
root |
HTMLElement |
Returns
string
Defined in
src/core/helpers/utils/selector.ts#94
refs
refs<T>(root): IDictionary<T>
Find all ref or data-ref elements inside HTMLElement
Type parameters
| Name | Type |
|---|---|
T |
extends HTMLElement |
Parameters
| Name | Type |
|---|---|
root |
HTMLElement | { container: HTMLElement } |
Returns
IDictionary<T>
Defined in
src/core/helpers/utils/selector.ts#128
cssPath
cssPath(el): Nullable<string>
Calculate full CSS selector
Parameters
| Name | Type |
|---|---|
el |
Element |
Returns
Nullable<string>
Defined in
src/core/helpers/utils/selector.ts#150
resolveElement
resolveElement(element, od): HTMLElement
Try to find element by selector
Parameters
| Name | Type |
|---|---|
element |
unknown |
od |
Document | ShadowRoot |
Returns
Defined in
src/core/helpers/utils/selector.ts#192
set
set<T>(chain, value, obj): void
Safe access in tree object
Type parameters
| Name |
|---|
T |
Parameters
| Name | Type |
|---|---|
chain |
string |
value |
unknown |
obj |
IDictionary |
Returns
void
Example
const a = {}, b = {};
Jodit.modules.Helpers.set('a.b.c.d.e', 1, a);
console.log(a);// {a: {b: {c: {d: {e: 1}}}}}
Jodit.modules.Helpers.set('a.0.e', 1, b);
console.log(b);// {a: [{e: 1}]}
Defined in
src/core/helpers/utils/set.ts#30
call
call<T, R>(func, ...args): R
Call function with parameters
Type parameters
| Name | Type |
|---|---|
T |
extends any[] |
R |
R |
Parameters
| Name | Type |
|---|---|
func |
(...args: T) => R |
...args |
T |
Returns
R
Example
const f = Math.random();
Jodit.modules.Helpers.call(f > 0.5 ? Math.ceil : Math.floor, f);
Defined in
src/core/helpers/utils/utils.ts#35
markOwner
markOwner(jodit, elm): void
Mark element for debugging
Parameters
| Name | Type |
|---|---|
jodit |
IViewBased<IViewOptions> |
elm |
HTMLElement |
Returns
void
Defined in
src/core/helpers/utils/utils.ts#45
callPromise
callPromise(condition, callback?): CanPromise<void>
Parameters
| Name | Type |
|---|---|
condition |
unknown |
callback? |
() => any |
Returns
CanPromise<void>
Defined in
src/core/helpers/utils/utils.ts#54
loadImage
loadImage(src, jodit): RejectablePromise<HTMLImageElement>
Allow load image in promise
Parameters
| Name | Type |
|---|---|
src |
string |
jodit |
IViewBased<IViewOptions> |
Returns
RejectablePromise<HTMLImageElement>
Defined in
src/core/helpers/utils/utils.ts#73
keys
keys(obj, own?): string[]
Parameters
| Name | Type | Default value |
|---|---|---|
obj |
object |
undefined |
own |
boolean |
true |
Returns
string[]
Defined in
src/core/helpers/utils/utils.ts#100
memorizeExec
memorizeExec<T>(editor, _, «destructured», preProcessValue?): false | void
Memorize last user chose
Type parameters
| Name | Type |
|---|---|
T |
extends IJodit = IJodit |
Parameters
| Name | Type |
|---|---|
editor |
T |
_ |
unknown |
«destructured» |
Object |
› control |
IControlType<T, IToolbarButton> |
preProcessValue? |
(value: string) => string |
Returns
false | void
Defined in
src/core/helpers/utils/utils.ts#117
getDataTransfer
getDataTransfer(event): Nullable<DataTransfer>
Get DataTransfer from different event types
Parameters
| Name | Type |
|---|---|
event |
ClipboardEvent | DragEvent |
Returns
Defined in
jodit/src/core/helpers/utils/utils.ts:143
previewBox
previewBox(editor, defaultValue?, points?, container?): [HTMLElement, () => void]
Generates a copy of an HTML document, resizes images, executes JS
beforePreviewBox(string | undefined, 'pt' | 'px' | '')
afterPreviewBox(HTMLElement)
Parameters
| Name | Type | Default value |
|---|---|---|
editor |
IJodit |
undefined |
defaultValue? |
string |
undefined |
points |
"" | "px" | "pt" |
'px' |
container |
Nullable<HTMLElement> |
null |
Returns
[HTMLElement, () => void]
Defined in
jodit/src/core/helpers/utils/print.ts:71