hyperRTE

editor class

also called HyperRTE is the main class of the library that wrap all the functionality in a simple api.

constructor(options)

takes options and return editor.

args:

returns: an instance of HyperRTE class.

options object:

a plain object containing options.

events

the editor class has a simple event system that allow for easy event based programming.

on(name, callback)

listen for an event and invoke a callback.
args:

off(name, callback)

unlisten for an event by removing the callback.
args:

once(name, callback)

listen for an event and invoke a callback one time.
args:

trigger(name, …args)

triggers an event supplied with arguments.
args:

the listners are called with the current instance as first argumment.

built in events

addButton(name, definition)

add a button to the button definitions.

args:

example

a simple button with icon:

editor.addButton('log', {
	title: 'log the content',
	icon: '<img src="info.svg">',
	state: (editor) => editor.content.length > 50, //highlight when content above 50 characters
	action: (editor) => console.log(editor.content)
})

an example on creator:

editor.addButton('log', {
	title: 'log the content',
	creator: (el) => el.append('log'),
	action: (editor) => console.log(editor.content)
})

actions

actions are key component of the editor structure, they imply an change in format (like bold/italic) or insertion or removing of items or a big change in the content (like undo/redo).

actions are not done unless the input is focus or if they are forced.

doAction(name, handler, force)

trigger an action of type “name”.
args:

element reference

content managment

there are various method and fields responsible for content managment.

get content

return the content of the editor as html string.

set content

set the content of the editor as html string

export()

return the content of the editor as html string, without any edit time content (like elements and classes used internally not part of the content).

cleaning managment

cleaning managment is very usefull feature in HyperRTE as it is responsible for producing clean and non-empty html structure.

how it work

clean()

clean the dom.

selection managment

various methods to manage the selection

focus()

focus the content element.

captureSelection()

capture the selection and return a funtion, once called reselect the selection.