本文整理汇总了TypeScript中tinymce/core/api/dom/DOMUtils.DOMUtils.nodeIndex方法的典型用法代码示例。如果您正苦于以下问题:TypeScript DOMUtils.nodeIndex方法的具体用法?TypeScript DOMUtils.nodeIndex怎么用?TypeScript DOMUtils.nodeIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tinymce/core/api/dom/DOMUtils.DOMUtils
的用法示例。
在下文中一共展示了DOMUtils.nodeIndex方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
const getPoint = function (dom: DOMUtils, trim: TrimFn, normalized: boolean, rng: Range, start: boolean) {
let container = rng[start ? 'startContainer' : 'endContainer'];
let offset = rng[start ? 'startOffset' : 'endOffset'];
const point = [];
let childNodes, after = 0;
const root = dom.getRoot();
if (NodeType.isText(container)) {
point.push(normalized ? getNormalizedTextOffset(trim, container, offset) : offset);
} else {
childNodes = container.childNodes;
if (offset >= childNodes.length && childNodes.length) {
after = 1;
offset = Math.max(0, childNodes.length - 1);
}
point.push(dom.nodeIndex(childNodes[offset], normalized) + after);
}
for (; container && container !== root; container = container.parentNode) {
point.push(dom.nodeIndex(container, normalized));
}
return point;
};
示例2: TreeWalker
const findTextNodeRelative = (dom: DOMUtils, isAfterNode: boolean, collapsed: boolean, left: boolean, startNode: Node): Option<CaretPosition> => {
let walker, lastInlineElement, parentBlockContainer;
const body = dom.getRoot();
let node;
const nonEmptyElementsMap = dom.schema.getNonEmptyElements();
parentBlockContainer = dom.getParent(startNode.parentNode, dom.isBlock) || body;
// Lean left before the BR element if it's the only BR within a block element. Gecko bug: #6680
// This: <p><br>|</p> becomes <p>|<br></p>
if (left && NodeType.isBr(startNode) && isAfterNode && dom.isEmpty(parentBlockContainer)) {
return Option.some(CaretPosition(startNode.parentNode, dom.nodeIndex(startNode)));
}
// Walk left until we hit a text node we can move to or a block/br/img
walker = new TreeWalker(startNode, parentBlockContainer);
while ((node = walker[left ? 'prev' : 'next']())) {
// Break if we hit a non content editable node
if (dom.getContentEditableParent(node) === 'false' || isCeFalseCaretContainer(node, body)) {
return Option.none();
}
// Found text node that has a length
if (NodeType.isText(node) && node.nodeValue.length > 0) {
if (hasParentWithName(node, body, 'A') === false) {
return Option.some(CaretPosition(node, left ? node.nodeValue.length : 0));
}
return Option.none();
}
// Break if we find a block or a BR/IMG/INPUT etc
if (dom.isBlock(node) || nonEmptyElementsMap[node.nodeName.toLowerCase()]) {
return Option.none();
}
lastInlineElement = node;
}
// Only fetch the last inline element when in caret mode for now
if (collapsed && lastInlineElement) {
return Option.some(CaretPosition(lastInlineElement, 0));
}
return Option.none();
};
示例3: if
const restoreEndPoint = (dom: DOMUtils, suffix: string, bookmark: IdBookmark) => {
let marker = dom.get(bookmark.id + '_' + suffix), node, idx, next, prev;
const keep = bookmark.keep;
let container, offset;
if (marker) {
node = marker.parentNode;
if (suffix === 'start') {
if (!keep) {
idx = dom.nodeIndex(marker);
} else {
if (marker.hasChildNodes()) {
node = marker.firstChild;
idx = 1;
} else if (isValidTextNode(marker.nextSibling)) {
node = marker.nextSibling;
idx = 0;
} else if (isValidTextNode(marker.previousSibling)) {
node = marker.previousSibling;
idx = marker.previousSibling.data.length;
} else {
node = marker.parentNode;
idx = dom.nodeIndex(marker) + 1;
}
}
container = node;
offset = idx;
} else {
if (!keep) {
idx = dom.nodeIndex(marker);
} else {
if (marker.hasChildNodes()) {
node = marker.firstChild;
idx = 1;
} else if (isValidTextNode(marker.previousSibling)) {
node = marker.previousSibling;
idx = marker.previousSibling.data.length;
} else {
node = marker.parentNode;
idx = dom.nodeIndex(marker);
}
}
container = node;
offset = idx;
}
if (!keep) {
prev = marker.previousSibling;
next = marker.nextSibling;
// Remove all marker text nodes
Tools.each(Tools.grep(marker.childNodes), (node) => {
if (NodeType.isText(node)) {
node.nodeValue = node.nodeValue.replace(/\uFEFF/g, '');
}
});
// Remove marker but keep children if for example contents where inserted into the marker
// Also remove duplicated instances of the marker for example by a
// split operation or by WebKit auto split on paste feature
while ((marker = dom.get(bookmark.id + '_' + suffix))) {
dom.remove(marker, true);
}
// If siblings are text nodes then merge them unless it's Opera since it some how removes the node
// and we are sniffing since adding a lot of detection code for a browser with 3% of the market
// isn't worth the effort. Sorry, Opera but it's just a fact
if (prev && next && prev.nodeType === next.nodeType && NodeType.isText(prev) && !Env.opera) {
idx = prev.nodeValue.length;
prev.appendData(next.nodeValue);
dom.remove(next);
if (suffix === 'start') {
container = prev;
offset = idx;
} else {
container = prev;
offset = idx;
}
}
}
return Option.some(CaretPosition(container, offset));
} else {
return Option.none();
}
};