Class: FrontendScriptApi

FrontendScriptApi

Members

currentNote

Properties:
Name Type Description
note object where script is currently executing
Source:

originEntity

Properties:
Name Type Description
entity object | null whose event triggered this execution
Source:

startNote

Properties:
Name Type Description
note object where script started executing
Source:

Methods

activateNewNote(notePath) → {Promise.<void>}

Activates newly created note. Compared to this.activateNote() also refreshes tree.
Parameters:
Name Type Description
notePath string (or noteId)
Source:
Returns:
Type
Promise.<void>

activateNote(notePath) → {Promise.<void>}

Activates note in the tree and in the note detail.
Parameters:
Name Type Description
notePath string (or noteId)
Source:
Returns:
Type
Promise.<void>

addButtonToToolbar(opts)

Adds new button the the plugin area.
Parameters:
Name Type Description
opts ToolbarButtonOptions
Source:
Create note link (jQuery object) for given note.
Parameters:
Name Type Attributes Description
notePath string (or noteId)
noteTitle string <optional>
if not present we'll use note title
Source:

formatDateISO(date) → {string}

Parameters:
Name Type Description
date Date
Source:
Returns:
date in YYYY-MM-DD format
Type
string

getActiveNote() → {NoteFull}

Source:
Returns:
active note (loaded into right pane)
Type
NoteFull

getActiveNoteContent() → {string}

Source:
Returns:
content of active note (loaded into right pane)
Type
string

getCodeMimeTypes() → {array}

Source:
Returns:
list of currently used code mime types
Type
array

getDefaultCodeMimeTypes() → {array}

Source:
Returns:
list of default code mime types
Type
array

getInstanceName() → {string}

Instance name identifies particular Trilium instance. It can be useful for scripts if some action needs to happen on only one specific instance.
Source:
Returns:
Type
string

getNotes(noteIds, silentNotFoundErroropt) → {Promise.<Array.<NoteShort>>}

Returns list of notes. If note is missing from cache, it's loaded. This is often used to bulk-fill the cache with notes which would have to be picked one by one otherwise (by e.g. createNoteLink())
Parameters:
Name Type Attributes Description
noteIds Array.<string>
silentNotFoundError boolean <optional>
don't report error if the note is not found
Source:
Returns:
Type
Promise.<Array.<NoteShort>>

isNoteStillActive() → {boolean}

This method checks whether user navigated away from the note from which the scripts has been started. This is necessary because script execution is async and by the time it is finished, the user might have already navigated away from this page - the end result would be that script might return data for the wrong note.
Source:
Returns:
returns true if the original note is still loaded, false if user switched to another
Type
boolean

onNoteChange(func)

Parameters:
Name Type Description
func function callback called on note change as user is typing (not necessarily tied to save event)
Source:

parseDate(str) → {Date}

Parameters:
Name Type Description
str string
Source:
Returns:
parsed object
Type
Date

protectActiveNote()

Source:

refreshTree() → {Promise.<void>}

Refresh tree
Source:
Returns:
Type
Promise.<void>

runOnServer(script, params) → {Promise.<*>}

Executes given anonymous function on the server. Internally this serializes the anonymous function into string and sends it to backend via AJAX.
Parameters:
Name Type Description
script string script to be executed on the backend
params Array.<?> list of parameters to the anonymous function to be send to backend
Source:
Returns:
return value of the executed function on the backend
Type
Promise.<*>

setCodeMimeTypes(types)

Parameters:
Name Type Description
types array list of mime types to be used
Source:

setupElementTooltip($el)

Parameters:
Name Type Description
$el object jquery object on which to setup the tooltip
Source:

showError(message)

Show error message to the user.
Parameters:
Name Type Description
message string
Source:

showMessage(message)

Show info message to the user.
Parameters:
Name Type Description
message string
Source: