The utils object
- Source:
Methods
(static) getEmojisByAtrribute(attr) → {Object}
Parameters:
Name | Type | Description |
---|---|---|
attr |
String | The attribute according to which the returned map should be keyed. |
- Source:
Returns:
- Map of emojis with the passed in attribute values as keys and a list of emojis for a particular category as values.
- Type
- Object
(static) isOnlyEmojis(shortname) → {Boolean}
Determines whether the passed in string is just a single emoji shortname;
Parameters:
Name | Type | Description |
---|---|---|
shortname |
String | A string which migh be just an emoji shortname |
- Source:
Returns:
- Type
- Boolean
(static) shortnamesToEmojis(str, options) → {Array}
Returns an emoji represented by the passed in shortname. Scans the passed in text for shortnames and replaces them with emoji unicode glyphs or alternatively if it's a custom emoji without unicode representation then a lit-html TemplateResult which represents image tag markup is returned.
The shortname needs to be defined in emojis.json
and needs to have either a cp
attribute for the codepoint, or
an url
attribute which points to the source for the image.
Parameters:
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
str |
String | String containg the shortname(s) |
|||||||||
options |
Object |
Properties
|
- Source:
Returns:
An array of at least one string, or otherwise strings and lit-html TemplateResult objects.
- Type
- Array
(static) shortnamesToUnicode(str) → {String}
Replaces all shortnames in the passed in string with their unicode (emoji) representation.
Parameters:
Name | Type | Description |
---|---|---|
str |
String | String containing the shortname(s) |
- Source:
Returns:
- Type
- String
addClass(className, el)
Add a class to an element.
Parameters:
Name | Type | Description |
---|---|---|
className |
string | |
el |
Element |
- Source:
applyDragResistance(value, default_value) → {Integer}
Applies some resistance to value
around the default_value
.
If value is close enough to default_value
, then it is returned, otherwise
value
is returned.
Parameters:
Name | Type | Description |
---|---|---|
value |
Integer | |
default_value |
Integer |
- Source:
Returns:
- Type
- Integer
calculateElementHeight(el) → {integer}
Return the height of the passed in DOM element, based on the heights of its children.
Parameters:
Name | Type | Description |
---|---|---|
el |
HTMLElement |
- Source:
Returns:
- Type
- integer
(private) clearTimers(timeout, interval)
Clears the specified timeout and interval.
Parameters:
Name | Type | Description |
---|---|---|
timeout |
number | Id if the timeout to clear. |
interval |
number | Id of the interval to clear. |
- Copyright:
- Simen Bekkhus 2016
- License:
- MIT
- Source:
(private) getCurrentWord(input, indexopt, delineatoropt)
Returns the current word being written in the input element
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
input |
HTMLElement | The HTMLElement in which text is being entered |
|
index |
integer |
<optional> |
An optional rightmost boundary index. If given, the text value of the input element will only be considered up until this index. |
delineator |
string |
<optional> |
An optional string delineator to differentiate between words. |
- Source:
getOOBURLMarkup(url) → {String}
Returns the markup for a URL that points to a downloadable asset (such as a video, image or audio file).
Parameters:
Name | Type | Description |
---|---|---|
url |
String |
- Source:
Returns:
- Type
- String
(private) getResolveablePromise()
Returns a promise object on which resolve
or reject
can be called.
- Source:
(private) matchesSelector(el, selector)
Checks whether the DOM element matches the given selector.
Parameters:
Name | Type | Description |
---|---|---|
el |
DOMElement | The DOM element |
selector |
String | The selector |
- Source:
(private) merge(first, second)
Merge the second object into the first one.
Parameters:
Name | Type | Description |
---|---|---|
first |
Object | |
second |
Object |
- Source:
(private) nextUntil(el, selector)
Return the element's siblings until one matches the selector.
Parameters:
Name | Type | Description |
---|---|---|
el |
HTMLElement | |
selector |
String |
- Source:
(private) onMultipleEvents(events:, callback:)
Call the callback once all the events have been triggered
Parameters:
Name | Type | Description |
---|---|---|
events: |
Array | An array of objects, with keys |
callback: |
function | The function to call once all events have been triggered. |
- Source:
(private) queryChildren(el, selector)
Returns a list of children of the DOM element that match the selector.
Parameters:
Name | Type | Description |
---|---|---|
el |
DOMElement | the DOM element |
selector |
String | the selector they should be matched against |
- Source:
removeClass(className, el)
Remove a class from an element.
Parameters:
Name | Type | Description |
---|---|---|
className |
string | |
el |
Element |
- Source:
(private) slideOut(el, duration)
Shows/expands an element by sliding it out of itself
Parameters:
Name | Type | Description |
---|---|---|
el |
HTMLElement | The HTML string |
duration |
Number | The duration amount in milliseconds |
- Source:
(private) stringToElement(s)
Converts an HTML string into a DOM element. Expects that the HTML string has only one top-level element, i.e. not multiple ones.
Parameters:
Name | Type | Description |
---|---|---|
s |
String | The HTML string |
- Source:
(private) unescapeHTML(string)
Helper method that replace HTML-escaped symbols with equivalent characters (e.g. transform occurrences of '&' to '&')
Parameters:
Name | Type | Description |
---|---|---|
string |
String | a String containing the HTML-escaped symbols. |
- Source:
waitUntil(func, max_waitopt, check_delayopt) → {Promise}
Creates a Promise that resolves if the passed in function returns a truthy value. Rejects if it throws or does not return truthy within the given max_wait.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
func |
function | The function called every check_delay, and the result of which is the resolved value of the promise. |
||
max_wait |
number |
<optional> |
300 | The time to wait before rejecting the promise. |
check_delay |
number |
<optional> |
3 | The time to wait before each invocation of {func}. |
- Copyright:
- Simen Bekkhus 2016
- License:
- MIT
- Source:
Returns:
A promise resolved with the value of func, or rejected with the exception thrown by it or it times out.
- Type
- Promise
(private) webForm2xForm(field)
Takes an HTML DOM and turns it into an XForm field.
Parameters:
Name | Type | Description |
---|---|---|
field |
DOMElement | the field to convert |
- Source:
(private) xForm2webForm(field)
Takes a field in XMPP XForm (XEP-004: Data Forms) format and turns it into an HTML field. Returns either text or a DOM element (which is not ideal, but fine for now).
Parameters:
Name | Type | Description |
---|---|---|
field |
XMLElement | the field to convert |
- Source: