boundaries.js is part of Aloha Editor project http://www.alohaeditor.org
Aloha Editor ● JavaScript Content Editing Library
Copyright (c) 2010-2015 Gentics Software GmbH, Vienna, Austria.
Contributors http://www.alohaeditor.org/docs/contributing.html
Aloha Editor ● JavaScript Content Editing Library
Copyright (c) 2010-2015 Gentics Software GmbH, Vienna, Austria.
Contributors http://www.alohaeditor.org/docs/contributing.html
Methods
-
commonContainer(start, end){Node}
-
Return the ancestor container that contains both the given boundaries.
Name Type Description start
Boundary end
Boundary -
container(boundary){Node}
-
Returns a boundary's container node.
Name Type Description boundary
Boundary -
create(node, offset){Boundary}
-
Creates a node boundary representing an (positive integer) offset
position inside of a container node.
The resulting boundary will be a normalized boundary, such that the
boundary will never describe a terminal position in a text node.Name Type Description node
Node offset
number -
document(boundary){Document}
-
Returns the document associated with the given boundary.
Name Type Description boundary
Boundary -
equals(a, b)
-
Compares two boundaries for equality. Boundaries are equal if their
corresponding containers and offsets are equal.Name Type Description a
Boundary b
Boundary -
fromBehindOfNode(node){Boundary}
-
Returns a boundary that is behind the given node.
Name Type Description node
Node -
fromEndOfNode(node){Boundary}
-
Returns a boundary that is at the end position inside the given node.
Name Type Description node
Node -
fromFrontOfNode(node){Boundary}
-
Returns a boundary that in front of the given node.
Name Type Description node
Node -
fromPosition()
-
This function is missing documentation.
- TODO
-
- Complete documentation.
-
fromRange(range){Array.<Boundary>}
-
Returns a start/end boundary tuple representing the start and end
positions of the given range.Name Type Description range
Range -
fromRangeEnd(range){Boundary}
-
Creates a boundary from the given range's end position.
Name Type Description range
Range -
fromRanges(ranges){Array.<Boundary>}
-
Returns an even-sized contiguous sequence of start/end boundaries
aligned in their pairs.Name Type Description ranges
Array.<Range> -
fromRangeStart(range){Boundary}
-
Creates a boundary from the given range's start position.
Name Type Description range
Range -
fromStartOfNode(node){Boundary}
-
Returns a boundary that is at the start position inside the given node.
Name Type Description node
Node -
get(doc){Array.<Boundary>}
-
Gets the boundaries of the currently selected range from the given
document element.Name Type Description doc
Document -
isAtEnd(boundary){boolean}
-
Checks if a boundary represents a position at the end of its container's
content.
The end boundary of the given selection is at the end position:
<b><i>f</i>{oo]</b> and <b><i>f</i>{oo}</b>
The first is at end of the text node "oo"and the other at end of the <b>
element.Name Type Description boundary
Boundary -
isAtStart(boundary){boolean}
-
Checks if a boundary (when normalized) represents a position at the
start of its container's content.
The start boundary of the given ranges is at the start position:
<b><i>f</i>[oo]</b> and <b><i>{f</i>oo}</b>
The first is at the start of the text node "oo" and the other at start
of the <i> element.Name Type Description boundary
Boundary -
isNodeBoundary(boundary){boolean}
-
Checks whether the given boundary is a position between nodes (as
opposed to a position inside of a text node).Name Type Description boundary
Boundary -
isTextBoundary(boundary){boolean}
-
Checks whether the given boundary is a position inside of a text nodes.
Name Type Description boundary
Boundary -
jumpOver(boundary){Boundary}
-
Skips the given boundary over the node that is next to the boundary.
Name Type Description boundary
Boundary -
next(boundary){Boundary}
-
Like Boundaries.prev(), but returns the boundary position that follows
from the given.Name Type Description boundary
Boundary -
nextNode(boundary){Node}
-
Returns the node after the given boundary, or the boundary's container
if the boundary is at the end position.Name Type Description boundary
Boundary -
nextWhile(boundary, cond){Boundary}
-
Steps forward while the given condition is true.
Name Type Description boundary
Boundary cond
function -
nodeAfter(boundary){Node}
-
Returns the node that is after the given boundary position.
Will return null if the given boundary is at the end position.
Note that the given boundary will be normalized.Name Type Description boundary
Boundary -
nodeBefore(boundary){Node}
-
Returns the node that is before the given boundary position.
Will returns null if the given boundary is at the start position.
Note that the given boundary will be normalized.Name Type Description boundary
Boundary -
normalize(boundary){Boundary}
-
Normalizes the boundary point (represented by a container and an offset
tuple) such that it will not point to the start or end of a text node.
This normalization reduces the number of states the a boundary can be
in, and thereby slightly increases the robusteness of the code written
against it.
It should be noted that native ranges controlled by the browser's DOM
implementation have the habit of changing by themselves, so even if a
range is set using a boundary that has been normalized this way, the
range could revert to an un-normalized state. See StableRange().
The returned value will either be a normalized copy of the given
boundary, or the given boundary itself if no normalization was done.Name Type Description boundary
Boundary -
offset(boundary){number}
-
Returns a boundary's offset.
Name Type Description boundary
Boundary -
prev(boundary){Boundary}
-
Returns a boundary that is at the previous position to the given.
If the given boundary represents a position inside of a text node, the
returned boundary will be moved behind that text node.
Given the markup below:
<div>
foo
<p>
bar
<b>
<u></u>
baz
</b>
</p>
</div>
the boundary positions which can be traversed with this function are
those marked with the pipe ("|") below:|foo|<p>|bar|<b>|<u>|</u>|baz|<b>|</p>|
This function complements Boundaries.next()Name Type Description boundary
Boundary -
prevNode(boundary){Node}
-
Returns the node before the given boundary, or the boundary container if
the boundary is at the end position.Name Type Description boundary
Boundary -
prevWhile(boundary, cond){Boundary}
-
Steps backwards while the given condition is true.
Name Type Description boundary
Boundary cond
function -
range(start, end){Range}
-
Creates a range based on the given start and end boundaries.
Name Type Description start
Boundary end
Boundary -
raw(node, offset){Boundary}
-
Creates a "raw" (un-normalized) boundary from the given node and offset.
Name Type Description node
Node offset
number -
select(start, end)
-
Sets the a range to the browser selection according to the given start
and end boundaries. This operation will cause the selection to be
visually rendered by the user agent.Name Type Description start
Boundary end
Boundary optional -
setRange(range, start, end)
-
Modifies the given range's start and end positions to the two respective
boundaries.Name Type Description range
Range start
Boundary end
Boundary -
setRangeEnd(range, boundary)
-
Sets the given range's end boundary.
Name Type Description range
Range Range to modify boundary
Boundary -
setRanges(ranges, boundaries)
-
Sets the start and end position of a list of ranges from the given list
of boundaries.
Because the range at index i in `ranges` will be modified using the
boundaries at index 2i and 2i + 1 in `boundaries`, the size of `ranges`
must be no less than half the size of `boundaries`.
Because the list of boundaries will need to be partitioned into pairs of
start/end tuples, it is required that the length of `boundaries` be
even. See Arrays.partition().Name Type Description ranges
Array.<Range> List of ranges to modify boundaries
Array.<Boundary> Even list of boundaries -
setRangeStart(range, boundary)
-
Sets the given range's start boundary.
Name Type Description range
Range Range to modify. boundary
Boundary -
stepWhile(boundary, cond, step){Boundary}
-
Steps through boundaries while the given condition is true.
Name Type Description boundary
Boundary Start position cond
function Predicate step
function Gets the next boundary -
walkWhile(boundary, cond, step, callback)
-
Walks along boundaries according to step(), applying callback() to each
boundary along the traversal until cond() returns false.Name Type Description boundary
Boundary Start position cond
function Predicate step
function Gets the next boundary callback
function Applied to each boundary