Helpers/utils

Classes

Interfaces

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#15

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#41


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#63


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#92


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#106


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#23

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#28

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#33

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#42


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#11


ConfigProto

ConfigProto(options, proto, deep?): IDictionary

Parameters

Name Type Default value
options IDictionary undefined
proto IDictionary undefined
deep number 0

Returns

IDictionary

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#50


ConfigFlatten

ConfigFlatten(obj): IDictionary

Parameters

Name Type
obj IDictionary

Returns

IDictionary

Defined in

src/core/helpers/utils/config-proto.ts#101


convertMediaUrlToVideoEmbed

convertMediaUrlToVideoEmbed(url, width?, height?): string

Javascript url pattern converter replace youtube/vimeo url in embed code.

Parameters

Name Type Default value
url string undefined
width number 400
height number 345

Returns

string

Defined in

src/core/helpers/utils/convert-media-url-to-video-embed.ts#17


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#16


error

error(message): Error

Helper for create Error object

Parameters

Name Type
message string

Returns

Error

Defined in

src/core/helpers/utils/error/error.ts#16


connection

connection(message): Error

Parameters

Name Type
message string

Returns

Error

Defined in

src/core/helpers/utils/error/error.ts#20


options

options(message): Error

Parameters

Name Type
message string

Returns

Error

Defined in

src/core/helpers/utils/error/error.ts#24


abort

abort(message): Error

Parameters

Name Type
message string

Returns

Error

Defined in

src/core/helpers/utils/error/error.ts#28


isAbort

isAbort(error): boolean

Parameters

Name Type
error unknown

Returns

boolean

Defined in

src/core/helpers/utils/error/error.ts#32


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#26


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


$$

$$<K>(selector, root): HTMLElementTagNameMap[K][]

Find all elements by selector and return Array. If it did not find any element it return empty array

Type parameters

Name Type
K extends HTMLTagNames

Parameters

Name Type Description
selector K CSS like selector
root HTMLElement | DocumentFragment | HTMLDocument -

Returns

HTMLElementTagNameMap[K][]

Example

Jodit.modules.Helpers.$$('.someselector').forEach(function (elm) {
     elm.addEventListener('click', function () {
         alert(''Clicked');
     });
})
Defined in

src/core/helpers/utils/selector.ts#47

$$<T>(selector, root): T[]

Type parameters

Name Type
T extends HTMLElement

Parameters

Name Type
selector string
root HTMLElement | DocumentFragment | HTMLDocument

Returns

T[]

Defined in

src/core/helpers/utils/selector.ts#52


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#93


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 | IUIElement

Returns

IDictionary<T>

Defined in

src/core/helpers/utils/selector.ts#127


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#149


resolveElement

resolveElement(element, od): HTMLElement

Try to find element by selector

Parameters

Name Type
element unknown
od Document | ShadowRoot

Returns

HTMLElement

Defined in

src/core/helpers/utils/selector.ts#191


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#34


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#44


callPromise

callPromise(condition, callback): CanPromise<void>

Parameters

Name Type
condition unknown
callback () => any

Returns

CanPromise<void>

Defined in

src/core/helpers/utils/utils.ts#53


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#72


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#99


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#116


getDataTransfer

getDataTransfer(event): Nullable<DataTransfer>

Get DataTransfer from different event types

Parameters

Name Type
event ClipboardEvent | DragEvent

Returns

Nullable<DataTransfer>

Defined in

jodit/src/core/helpers/utils/utils.ts:142

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