Drafty

Drafty

Drafty

Constructor

new Drafty()

The main object which performs all the formatting actions.
Source:

Methods

(static) append(first, second) → {Drafty}

Append one Drafty document to another.
Source:
Parameters:
Name Type Description
first Drafty Drafty document to append to.
second Drafty Drafty document being appended.
Returns:
Type:
Drafty
first document with the second appended to it.

(static) appendButton(content, title, name, actionType, actionValue, refUrl) → {Drafty}

Append clickable button to Drafty document.
Source:
Parameters:
Name Type Description
content Drafty | string is Drafty object to insert button to or a string to be used as button text.
title string is the text to be used as button title.
name string of the button. Client should return it to the server when the button is clicked.
actionType string is the type of the button, one of 'url' or 'pub'.
actionValue string is the value to return on click:
refUrl string is the URL to go to when the 'url' button is clicked.
Returns:
Type:
Drafty
updated content.

(static) appendImage(content, imageDesc) → {Drafty}

Append inline image to Drafty content.
Source:
Parameters:
Name Type Description
content Drafty object to add image to.
imageDesc ImageDesc object with image paramenets.
Returns:
Type:
Drafty
updated content.

(static) attachFile(content, object) → {Drafty}

Attach file to Drafty content. Either as a blob or as a reference.
Source:
Parameters:
Name Type Description
content Drafty object to attach file to.
object AttachmentDesc containing attachment description and data.
Returns:
Type:
Drafty
updated content.

(static) attachJSON(content, data)

Attach a generic JS object. The object is attached as a json string. Intended for representing a form response.
Source:
Parameters:
Name Type Description
content Drafty object to attach file to.
data Object to convert to json string and attach.

(static) attachments(content, callback, context)

Enumerate attachments.
Source:
Parameters:
Name Type Description
content Drafty drafty object to process for attachments.
callback AttachmentCallback callback to call for each attachment.
context Object value of "this" for callback.

(static) attrValue(style, data) → {Object}

For a given data bundle generate an object with HTML attributes, for instance, given {url: "http://www.example.com/"} return {href: "http://www.example.com/"}
Source:
Parameters:
Name Type Description
style string two-letter style to generate attributes for.
data Object data bundle to convert to attributes
Returns:
Type:
Object
object with HTML attributes.

(static) format(content, formatter, context) → {Object}

Transform Drafty using custom formatting.
Source:
Parameters:
Name Type Description
content Drafty content to transform.
formatter Formatter callback which transforms individual elements
context Object context provided to formatter as 'this'.
Returns:
Type:
Object
transformed object

(static) getContentType() → {string}

Drafty MIME type.
Source:
Returns:
Type:
string
HTTP Content-Type "text/x-drafty".

(static) getDownloadUrl()

Given the entity, get URL which can be used for downloading entity data.
Source:
Parameters:
Name Type Description
entity.data Object to get the URl from.

(static) getEntityMimeType()

Get entity mime type.
Source:
Parameters:
Name Type Description
entity.data Object to get the type for.

(static) getEntitySize()

Get approximate size of the entity.
Source:
Parameters:
Name Type Description
entity.data Object to get the size for.

(static) getPreviewUrl() → {string}

Given the entity, get URL which can be used for previewing the entity.
Source:
Parameters:
Name Type Description
entity.data Object to get the URl from.
Returns:
Type:
string
url for previewing or null if no such url is available.

(static) hasAttachments(content)

Check if the drafty content has attachments.
Source:
Parameters:
Name Type Description
content Drafty content to check for attachments.
Returns:
true if there are attachments.

(static) init(plainText)

Initialize Drafty document to a plain text string.
Source:
Parameters:
Name Type Description
plainText String string to use as Drafty content.
Returns:
new Drafty document or null is plainText is not a string.

(static) insertButton(content, at, len, name, actionType, actionValue, refUrl) → {Drafty}

Insert clickable button into Drafty document.
Source:
Parameters:
Name Type Description
content Drafty | string is Drafty object to insert button to or a string to be used as button text.
at number is location where the button is inserted.
len number is the length of the text to be used as button title.
name string of the button. Client should return it to the server when the button is clicked.
actionType string is the type of the button, one of 'url' or 'pub'.
actionValue string is the value to return on click:
refUrl string is the URL to go to when the 'url' button is clicked.
Returns:
Type:
Drafty
updated content.

(static) insertImage(content, at, imageDesc) → {Drafty}

Insert inline image into Drafty document.
Source:
Parameters:
Name Type Description
content Drafty object to add image to.
at integer index where the object is inserted. The length of the image is always 1.
imageDesc ImageDesc object with image paramenets and data.
Returns:
Type:
Drafty
updated content.

(static) isPlainText(content)

Returns true if content has no markup and no entities.
Source:
Parameters:
Name Type Description
content Drafty content to check for presence of markup.
Returns:
true is content is plain text, false otherwise.

(static) isProcessing() → {boolean}

Check if the entity data is not ready for sending, such as being uploaded to the server.
Source:
Parameters:
Name Type Description
entity.data Object to get the URl from.
Returns:
Type:
boolean
true if upload is in progress, false otherwise.

(static) isValid(content)

Checks if the object represets is a valid Drafty document.
Source:
Parameters:
Name Type Description
content Drafty content to check for validity.
Returns:
true is content is valid, false otherwise.

(static) parse(content) → {Drafty}

Parse plain text into Drafty document.
Source:
Parameters:
Name Type Description
content String plain-text content to parse.
Returns:
Type:
Drafty
parsed object or null if the source is not plain text.

(static) tagName(style) → {string}

Get HTML tag for a given two-letter style name
Source:
Parameters:
Name Type Description
style string two-letter style, like ST or LN
Returns:
Type:
string
tag name

(static) toPlainText(content)

Given structured representation of rich text, convert it to plain text.
Source:
Parameters:
Name Type Description
content Drafty content to convert to plain text.

(static) wrapAsForm(content, at, len) → {Drafty}

Wraps content into an interactive form.
Source:
Parameters:
Name Type Description
content Drafty | string to wrap into a form.
at number index where the forms starts.
len number length of the form content.
Returns:
Type:
Drafty
updated content.

Type Definitions

AttachmentCallback(data, index)

Callback for applying custom formatting/transformation to a Drafty object. Called once for each syle span.
Source:
Parameters:
Name Type Description
data Object attachment data
index number attachment's index in `content.ent`.

AttachmentDesc

Source:
Type:
  • Object

Formatter(style, data, values, index)

Callback for applying custom formatting/transformation to a Drafty object. Called once for each syle span.
Source:
Parameters:
Name Type Description
style string style code such as "ST" or "IM".
data Object entity's data
values Object possibly styled subspans contained in this style span.
index number of the current element among its siblings.

ImageDesc

Source:
Type:
  • Object