A range and a flag indicating whether it is a reversed range or not. Range objects themselves do not record how they were created. If the range was created from a starting point which is greater than the end point (in document order), then the range is "reversed".
Inserts an element into text, effectively splitting the text node in two. This function takes care to modify the DOM tree only once.
The text node that will be cut in two by the new element.
The offset into the text node where the new element is to be inserted.
The node to insert. If undefined, then this function effectively splits the text node into two parts.
A pair containing a caret position marking the boundary between what comes before the material inserted and the material inserted, and a caret position marking the boundary between the material inserted and what comes after. If I insert "foo" at position 2 in "abcd", then the final result would be "abfoocd" and the first caret would mark the boundary between "ab" and "foo" and the second caret the boundary between "foo" and "cd".
Find child matching the class.
The element whose child we are looking for.
The class to use for matches.
The first child (in document order) that matches the class, or
null
if nothing matches.
Find children matching the class.
The element whose children we are looking for.
The class to use for matches.
The children (in document order) that match the class.
Starting with the node passed, and walking up the node's parents, returns the first node that matches the selector.
The node to start with.
The selector to use for matches.
The algorithm will search up to this limit, inclusively.
The first element that matches the selector, or null
if nothing
matches.
Starting with the node passed, and walking up the node's parents, returns the first element that matches the class.
The node to start with.
The class to use for matches.
The algorithm will search up to this limit, inclusively.
The first element that matches the class, or null
if nothing
matches.
Compare two positions in document order.
This function relies on DOM's compareDocumentPosition
function. Remember
that calling that function with attributes can be problematic. (For instance,
two attributes on the same element are not ordered.)
Node of the first position.
Offset of the first position.
Node of the second position.
Offset of the second position.
-1 if the first position comes before the second. 1 if the first position comes after the other. 0 if the two positions are equal.
A contains
function that handles attributes. Attributes are not part of
the node tree and performing a contains
test on them is always false
.
Yet it makes sense to say that an element A contains its own attributes and thus by transitivity if element A is contained by element B, then all attributes of A are contained by B. This function supports the contention just described.
Usage note: this function is typically not needed when doing tests in the GUI tree because we do not address attributes in that tree. There is, however, no harm in using it where it is not strictly needed. In the data tree, however, we do address attributes. Code that works with either tree (e.g. the "wed/dloc" module) should use this function as a general rule so that it can work with either tree.
The thing which should contain in the test.
The thing which should be contained in the test.
Whether container
contains contained
.
Given two trees A and B of DOM nodes, this function finds the node in tree B which corresponds to a node in tree A. The two trees must be structurally identical. If tree B is cloned from tree A, it will satisfy this requirement. This function does not work with attribute nodes.
The root of the first tree.
The root of the second tree.
A node in the first tree.
The node which corresponds to nodeInA
in treeB
.
Allows applying simple CSS selectors on the data tree as if it were an HTML
tree. This is necessary because the current browsers are unable to handle tag
prefixes or namespaces in selectors passed to matches
, querySelector
and related functions.
The steps are:
Convert selector
with toGUISelector into a selector that can be
applied to the GUI tree.
Convert node
to a GUI node.
Apply the converted selector to the GUI node.
Convert the resulting node to a data node.
The element to use as the starting point of the query.
The selector to use.
The namespaces that are known. This is used to convert element name prefixes to namespace URIs.
The resulting data node.
Allows applying simple CSS selectors on the data tree as if it were an HTML tree. Operates like dataFind but returns an array of nodes.
The data node to use as the starting point of the query.
The selector to use.
The namespaces that are known. This is used to convert element name prefixes to namespace URIs.
The resulting data nodes.
Removes the node. Mainly for use with the generic functions defined here.
The node to remove.
Deletes text from a text node. If the text node becomes empty, it is deleted.
The text node from which to delete text.
The index at which to delete text.
The length of text to delete.
Dumps the current selection to the console.
A message to output in front of the range information.
The window for which to dump selection information.
Dumps a range to the console.
A message to output in front of the range information.
The range.
Dumps a range to a string.
A message to output in front of the range information.
The range.
Returns the first descendant or the node passed to the function if the node happens to not have a descendant. The function searches in document order.
When passed <p><b>A</b><b><q>B</q></b></p>
this code would return the
text node "A" because it has no children and is first.
The node to search.
The first node which is both first in its parent and has no children.
Focuses the node itself or if the node is a text node, focuses the parent.
The node to focus.
Removes the contents between the start and end carets from the DOM tree. If two text nodes become adjacent, they are merged.
Start caret position.
Ending caret position.
The first item is the caret position indicating where the cut happened. The second item is a list of nodes, the cut contents.
Inserts an element into text, effectively splitting the text node in two. This function takes care to modify the DOM tree only once.
The text node that will be cut in two by the new element.
The offset into the text node where the new element is to be inserted.
The node to insert.
A pair containing a caret position marking the boundary between what comes before the material inserted and the material inserted, and a caret position marking the boundary between the material inserted and what comes after. If I insert "foo" at position 2 in "abcd", then the final result would be "abfoocd" and the first caret would mark the boundary between "ab" and "foo" and the second caret the boundary between "foo" and "cd".
Inserts text into a node. This function will use already existing text nodes whenever possible rather than create a new text node.
The node where the text is to be inserted.
The location in the node where the text is to be inserted.
The text to insert.
Whether the caret position returned should be placed at the end of the inserted text.
The result of inserting the text.
Gets the character immediately at the caret. The word "immediately" here means that this function does not walk the DOM. If the caret is pointing into an element node, it will check whether the node at the offset is a text node and use it. That's the extent to which it walks the DOM.
The caret position.
The character, if it exists.
Gets the character immediately before the caret. The word "immediately" here means that this function does not walk the DOM. If the caret is pointing into an element node, it will check whether the node before the offset is a text node and use it. That's the extent to which it walks the DOM.
The caret position.
The character, if it exists.
Gets the first range in the selection.
The window for which we want the selection.
The first range in the selection. Undefined if there is no selection or no range.
Converts an HTML string to an array of DOM nodes. This function is not responsible for checking the HTML for security holes it is the responsibility of the calling code to ensure the HTML passed is clean.
The HTML to convert.
The document for which to create the nodes. If not specified,
the document will be the global document
.
The resulting nodes.
Search an array.
The array to search.
The target to find.
-1 if the target is not found, or its index.
Inserts an element into text, effectively splitting the text node in two. This function takes care to modify the DOM tree only once.
The text node that will be cut in two by the new element.
The offset into the text node where the new element is to be inserted.
The node to insert.
A pair containing a caret position marking the boundary between what comes before the material inserted and the material inserted, and a caret position marking the boundary between the material inserted and what comes after. If I insert "foo" at position 2 in "abcd", then the final result would be "abfoocd" and the first caret would mark the boundary between "ab" and "foo" and the second caret the boundary between "foo" and "cd".
Inserts a node at the position specified. Mainly for use with the generic functions defined here.
The node which will become the parent of the inserted node.
The position at which to insert the node into the parent.
The node to insert.
Inserts text into a node. This function will use already existing text nodes whenever possible rather than create a new text node.
The node where the text is to be inserted.
The location in the node where the text is to be inserted.
The text to insert.
Whether to return the caret position at the end of the
inserted text or at the beginning. Default to true
.
The result of inserting the text.
Determine whether an element is displayed. This function is designed to
handle checks in wed's GUI tree, and not as a general purpose solution. It
only checks whether the element or its parents have display
set to
"none"
.
The DOM element for which we want to check whether it is displayed or not.
The parent of el
beyond which we do not search.
true
if the element or any of its parents is not
displayed. false
otherwise. If the search up the DOM tree hits root
,
then the value returned is false
.
Determines whether a range is well-formed. A well-formed range is one which starts and ends in the same element.
An object which has the startContainer
,
startOffset
, endContainer
, endOffset
attributes set. The
interpretation of these values is the same as for DOM Range
objects. Therefore, the object passed can be a DOM range.
true
if the range is well-formed. false
if not.
Returns the last descendant or the node passed to the function if the node happens to not have a descendant. The function searches in reverse document order.
When passed <p><b>A</b><b><q>B</q></b></p>
this code would return the
text node "B" because it has no children and is last.
The node to search.
The last node which is both last in its parent and has no children.
This function recursively links two DOM trees through the jQuery .data()
method. For an element in the first tree the data item named
"wed_mirror_node" points to the corresponding element in the second tree, and
vice-versa. It is presumed that the two DOM trees are perfect mirrors of each
other, although no test is performed to confirm this.
Makes a placeholder element
The text to put in the placeholder.
A node.
Merges a text node with the next text node, if present. When called on something which is not a text node or if the next node is not text, does nothing. Mainly for use with the generic functions defined here.
The node to merge with the next node.
A caret position between the two parts that were merged, or between the two nodes that were not merged (because they were not both text).
This function determines the caret position if the caret was moved forward.
This function does not fully emulate how a browser moves the caret. The sole emulation it performs is to check whether whitespace matters or not. It skips whitespace that does not matter.
A caret position where the search starts. This should be an array of length two that has in first position the node where the caret is and in second position the offset in that node. This pair is to be interpreted in the same way node, offset pairs are interpreted in selection or range objects.
A DOM node which indicates the container within which caret movements must be contained.
If true, and a text node would be returned, the function will instead return the parent of the text node.
The next caret position, or null
if such position does not
exist. The container
parameter constrains movements to positions inside
it.
Returns the element nodes that contain the start and the end of the range. If an end of the range happens to be in a text node, the element node will be that node's parent.
An object which has the startContainer
, startOffset
,
endContainer
, endOffset
attributes set. The interpretation of these
values is the same as for DOM Range
objects. Therefore, the object passed
can be a DOM range.
A pair of nodes.
Compare two locations that have already been determined to be in a parent-child relation. Important: the relationship must have been formally tested before calling this function.
-1 if parent
is before child
, 1 otherwise.
Checks whether a point is in the element's contents. This means inside the
element and not inside one of the scrollbars that the element may
have. The coordinates passed must be relative to the document. If the
coordinates are taken from an event, this means passing pageX
and
pageY
.
The element to check.
The x coordinate relative to the document.
The y coordinate relative to the document.
true
if inside, false
if not.
This function determines the caret position if the caret was moved backwards.
This function does not fully emulate how a browser moves the caret. The sole emulation it performs is to check whether whitespace matters or not. It skips whitespace that does not matter.
A caret position where the search starts. This should be an array of length two that has in first position the node where the caret is and in second position the offset in that node. This pair is to be interpreted in the same way node, offset pairs are interpreted in selection or range objects.
A DOM node which indicates the container within which caret movements must be contained.
If true, and a text node would be returned, the function will instead return the parent of the text node.
The previous caret position, or null
if such position does not
exist. The container
parameter constrains movements to positions inside
it.
Creates a range from two points in a document.
The range information.
Find a sibling matching the class.
The element whose sibling we are looking for.
The class to use for matches.
The first sibling (in document order) that matches the class, or
null
if nothing matches.
Splits a text node into two nodes. This function takes care to modify the DOM tree only once.
The text node to split into two text nodes.
The offset into the text node where to split.
The first element is the node before index after split and the second element is the node after the index after split.
Convert a string to HTML encoding. For instance if you want to have the
less-than symbol be part of the contents of a span
element, it would have
to be escaped to <
otherwise it would be interpreted as the beginning of
a tag. This function does this kind of escaping.
The text to convert.
The converted text.
Converts a CSS selector written as if it were run against the XML document being edited by wed into a selector that will match the corresponding items in the GUI tree. This implementation is extremely naive and likely to break on complex selectors. Some specific things it cannot do:
Match attributes.
Match pseudo-elements.
The selector to convert.
The namespaces that are known. This is used to convert element name prefixes to namespace URIs.
The converted selector.
This function recursively unlinks a DOM tree though the jQuery .data()
method.
A DOM node.
Generated using TypeDoc
A caret position in the form of a pair of values. The caret we are talking about here roughly corresponds to the caret that a "contenteditable" element would present to the user. It can index in text nodes and element nodes but not in attributes.