How to use nextNodeDescendants method in wpt

Best JavaScript code snippet using wpt

Utils.ts

Source:Utils.ts Github

copy

Full Screen

...236 let node = range.startContainer;237 while (isEffectivelyContained(node.parentNode, range)) {238 node = node.parentNode;239 }240 let stop = nextNodeDescendants(range.endContainer);241 let nodeList = [];242 while (isBefore(node, stop)) {243 if (isEffectivelyContained(node, range)244 && condition(node)) {245 nodeList.push(node);246 node = nextNodeDescendants(node);247 continue;248 }249 node = nextNode(node);250 }251 return nodeList;252}253// 获得所有有效包含的节点 list254function getAllEffectivelyContainedNodes(range: Range, condition: Function) {255 if (typeof condition == "undefined") {256 condition = function () { return true };257 }258 let node = range.startContainer;259 while (isEffectivelyContained(node.parentNode, range)) {260 node = node.parentNode;261 }262 let stop = nextNodeDescendants(range.endContainer);263 let nodeList = [];264 while (isBefore(node, stop)) {265 if (isEffectivelyContained(node, range)266 && condition(node)) {267 nodeList.push(node);268 }269 node = nextNode(node);270 }271 return nodeList;272}273// 一个可以被修改的元素274// 如果是 "B", "EM", "I", "S", "SPAN", "STRIKE", "STRONG", "SUB", "SUP", "U" , 除了样式没有任何其他的属性275// 除了 Font 元素的 style color face size 等276// 除了 A 元素的 href277// 其他都不可以278function isModifiableElement(node): boolean {279 if (!isHtmlElement(node)) {280 return false;281 }282 if (["B", "EM", "I", "S", "SPAN", "STRIKE", "STRONG", "SUB", "SUP", "U"].includes(node.tagName)) {283 if (node.attributes.length == 0) {284 return true;285 }286 if (node.attributes.length == 1287 && node.hasAttribute("style")) {288 return true;289 }290 }291 if (node.tagName == "FONT" || node.tagName == "A") {292 let numAttrs = node.attributes.length;293 if (node.hasAttribute("style")) {294 numAttrs--;295 }296 if (node.tagName == "FONT") {297 if (node.hasAttribute("color")) {298 numAttrs--;299 }300 if (node.hasAttribute("face")) {301 numAttrs--;302 }303 if (node.hasAttribute("size")) {304 numAttrs--;305 }306 }307 if (node.tagName == "A"308 && node.hasAttribute("href")) {309 numAttrs--;310 }311 if (numAttrs == 0) {312 return true;313 }314 }315 return false;316}317// 一个简单的可以被修改的元素318function isSimpleModifiableElement(node) {319 // 一个简单的可修改元素是HTML元素,其至少具有以下一项320 if (!isHtmlElement(node)) {321 return false;322 }323 // 只有这些元素可能是简单的可修改元素。324 if (["A", "B", "EM", "FONT", "I", "S", "SPAN", "STRIKE", "STRONG", "SUB", "SUP", "U"].includes(node.tagName)) {325 return false;326 }327 // 如果是一个 a, b, em, font, i, s, span, strike, strong, sub, sup, u 元素,并且没有元素属性328 if (node.attributes.length == 0) {329 return true;330 }331 // 如果它具有多个属性,则此之后的所有操作都会失败。332 if (node.attributes.length > 1) {333 return false;334 }335 // 它是一个a , b, em, font, i, s, span, str, strike, strong, sub, sup 或 u元素,336 // 其元素恰好具有一个 style 属性, 但是没有设置设置CSS属性(包括无效或无法识别的属性)。337 // 请勿尝试无效或无法识别的内容。338 if (node.hasAttribute("style")339 && node.style.length == 0) {340 return true;341 }342 // 如果是一个 A 元素, 并且只有 href 属性也算是343 if (node.tagName == "A"344 && node.hasAttribute("href")) {345 return true;346 }347 // 如果是 font 元素并且只有一个属性,color | face | size348 if (node.tagName == "FONT"349 && (node.hasAttribute("color")350 || node.hasAttribute("face")351 || node.hasAttribute("size")352 )) {353 return true;354 }355 // 如果是一个 b | strong 元素并且只有一个属性 style 并且只有一个样式属性 font-weight356 if ((node.tagName == "B" || node.tagName == "STRONG")357 && node.hasAttribute("style")358 && node.style.length == 1359 && node.style.fontWeight != "") {360 return true;361 }362 // 如果是一个 i | em 元素并且只有一个属性 style 并且只有一个样式属性 font-style363 if ((node.tagName == "I" || node.tagName == "EM")364 && node.hasAttribute("style")365 && node.style.length == 1366 && node.style.fontStyle != "") {367 return true;368 }369 // 如果是 a | font | span 并且只有一个属性 style,并且它的 text-decoration 为空370 if ((node.tagName == "A" || node.tagName == "FONT" || node.tagName == "SPAN")371 && node.hasAttribute("style")372 && node.style.length == 1373 && node.style.textDecoration == "") {374 return true;375 }376 // 如果是一个 "A", "FONT", "S", "SPAN", "STRIKE", "U" 元素,并且有 style 属性377 // 并且仅只设置了一个样式 "line-through", "underline", "overline", "none" 中的之一378 // 奇怪的 length 检查是为了针对 Firefox 做的调整,走 8.02a 开始的版本379 if (["A", "FONT", "S", "SPAN", "STRIKE", "U"].indexOf(node.tagName) != -1380 && node.hasAttribute("style")381 && (node.style.length == 1382 || (node.style.length == 4383 && "MozTextBlink" in node.style384 && "MozTextDecorationColor" in node.style385 && "MozTextDecorationLine" in node.style386 && "MozTextDecorationStyle" in node.style)387 || (node.style.length == 4388 && "MozTextBlink" in node.style389 && "textDecorationColor" in node.style390 && "textDecorationLine" in node.style391 && "textDecorationStyle" in node.style)392 )393 && (node.style.textDecoration == "line-through"394 || node.style.textDecoration == "underline"395 || node.style.textDecoration == "overline"396 || node.style.textDecoration == "none"397 )) {398 return true;399 }400}401// 是否是一个可编辑可以格式化的可见节点,它可以是 TextNode,ImgNode 或 brNode402function isFormattableNode(node) {403 return isEditable(node)404 && isVisible(node)405 && (node.nodeType == Node.TEXT_NODE406 || isHtmlElement(node, ["img", "br"]));407}408//409/**410 * @description 是块级元素吗411 * @param node412 * @returns boolean413 */414function isBlockNode(node) {415 const verify = ['inline', 'inline-block', 'inline-table', 'none']416 return node417 && ((node.nodeType === Node.ELEMENT_NODE && verify.includes(getComputedStyle(node).display) === false)418 || node.nodeType === Node.DOCUMENT_NODE419 || node.nodeType === Node.DOCUMENT_FRAGMENT_NODE)420}421/**422 * @description 内联节点是不是块节点的节点423 * @param node424 * @returns425 */426function isInlineNode(node) {427 return node && !isBlockNode(node);428}429/**430 * @description 是否可编辑元素431 * 1.一个用户可编辑的元素(例如一个使用 contenteditable 的HTML元素,或是在启用了 designMode 的 Document 的子元素)432 * @param node433 * @returns boolean434 *435 */436function isEditingHost(node) {437 return node438 && isHtmlElement(node)439 && (node.contentEditable === 'true'440 || (node.parentNode441 && node.parentNode.nodeType === Node.DOCUMENT_NODE442 && node.parentNode.designMode === 'on'));443}444/**445 * @description 是否可以被编辑446 * @param node447 * @returns boolean448 * 1.如果它是一个可编辑的节点,但不是可编辑的主要根节点449 * 2.它确实没有将 contenteditable 属性设置为 false 状态450 * 3.其父级是编辑根节点或可编辑的451 * 4.并且它是一个 HTML 元素,或者是一个 svg 或 math 元素,或者它不是 Element 且其父元素是 HTML 元素。452 */453function isEditable(node): boolean {454 return node455 && !isEditingHost(node)456 && (node.nodeType !== Node.ELEMENT_NODE || node.contentEditable !== 'false')457 && (isEditingHost(node.parentNode) || isEditable(node.parentNode))458 && (isHtmlElement(node)459 || (node.nodeType === Node.ELEMENT_NODE && node.namespaceURI === 'http://www.w3.org/2000/svg' && node.localName === 'svg')460 || (node.nodeType === Node.ELEMENT_NODE && node.namespaceURI === 'http://www.w3.org/1998/Math/MathML' && node.localName === 'math')461 || (node.nodeType !== Node.ELEMENT_NODE && isHtmlElement(node.parentNode)));462}463/**464 * @description 是否有可编辑的后代节点465 * @param node466 * @returns467 */468function hasEditableDescendants(node) {469 for (let i = 0; i < node.childNodes.length; i++) {470 if (isEditable(node.childNodes[i])471 || hasEditableDescendants(node.childNodes[i])) {472 return true;473 }474 }475 return false;476}477/**478 * @description479 * 1. 如果节点不可编辑,那么编辑根节点为 null480 * 2. 如果节点是编辑根节点,则返回节点本身481 * 3. 如果节点是可编辑的,则可编辑的根节点为该节点的最近祖先。482 * @param node483 * @returns484 */485function getEditingHostOf(node) {486 if (isEditingHost(node)) {487 return node;488 } else if (isEditable(node)) {489 let ancestor = node.parentNode;490 while (!isEditingHost(ancestor)) {491 ancestor = ancestor.parentNode;492 }493 return ancestor;494 } else {495 return null;496 }497}498/**499 * @description 是否拥有共同的可编辑根节点祖先500 * @param node1501 * @param node2502 * @returns503 */504function inSameEditingHost(node1, node2) {505 return getEditingHostOf(node1)506 && getEditingHostOf(node1) == getEditingHostOf(node2);507}508/**509 * @description 是否是折叠的空格510 * @param br511 * @returns512 */513function isCollapsedLineBreak(br) {514 if (!isHtmlElement(br, "br")) {515 return false;516 }517 // 在它后面添加一个zwsp(零宽空格),看看这是否会改变最近的非内联父级的高度。518 // 注意:这实际上是不可靠的,因为父级可能有固定的高度或其他东西。519 let ref = br.parentNode;520 while (getComputedStyle(ref).display == "inline") {521 ref = ref.parentNode;522 }523 let refStyle = ref.hasAttribute("style") ? ref.getAttribute("style") : null;524 ref.style.height = "auto";525 ref.style.maxHeight = "none";526 ref.style.minHeight = "0";527 let space = document.createTextNode("\u200b");528 let origHeight = ref.offsetHeight;529 if (origHeight == 0) {530 throw "isCollapsedLineBreak: original height is zero, bug?";531 }532 br.parentNode.insertBefore(space, br.nextSibling);533 let finalHeight = ref.offsetHeight;534 space.parentNode.removeChild(space);535 if (refStyle === null) {536 ref.setAttribute("style", "");537 ref.removeAttribute("style");538 } else {539 ref.setAttribute("style", refStyle);540 }541 // 如果zwsp(零宽空格)没有创建一条全新的竖线 caret,而只是使一条现有的caret稍微高一点,那么可以允许。542 // firefox6.0 在第一行是粗体时显示这种行为。543 return origHeight < finalHeight - 5;544}545/**546 * @description 是否是多余无效的 br547 * 多余的换行符是不具有视觉效果的br,因为从DOM中将其删除不会改变布局,除了是作为li的唯一子代的br548 * @param br549 * @returns550 */551function isExtraneousLineBreak(br) {552 if (!isHtmlElement(br, "br")) {553 return false;554 }555 if (isHtmlElement(br.parentNode, "li")556 && br.parentNode.childNodes.length == 1) {557 return false;558 }559 // 使换行符消失,看看这是否会改变块的高度。560 // 是的,这是一个 css hack。我们必须重置参考节点上的高度等,因为否则它的高度不会改变,如果它不是自动的。561 let ref = br.parentNode;562 while (getComputedStyle(ref).display == "inline") {563 ref = ref.parentNode;564 }565 let refStyle = ref.hasAttribute("style") ? ref.getAttribute("style") : null;566 ref.style.height = "auto";567 ref.style.maxHeight = "none";568 ref.style.minHeight = "0";569 let brStyle = br.hasAttribute("style") ? br.getAttribute("style") : null;570 let origHeight = ref.offsetHeight;571 if (origHeight == 0) {572 throw "isExtraneousLineBreak: original height is zero, bug?";573 }574 br.setAttribute("style", "display:none");575 let finalHeight = ref.offsetHeight;576 if (refStyle === null) {577 ref.setAttribute("style", "");578 ref.removeAttribute("style");579 } else {580 ref.setAttribute("style", refStyle);581 }582 if (brStyle === null) {583 br.removeAttribute("style");584 } else {585 br.setAttribute("style", brStyle);586 }587 return origHeight == finalHeight;588}589/**590 * @description 是否是空白节点?591 * 空白节点是其数据为空字符串的Text节点; 或其数据仅由一个或多个制表符(0x0009),换行符(0x000A),回车符(0x000D)和/或 空格(0x0020),并且其父级是一个元素,其 'white-space' 的解析值为 'normal' 或“ nowrap”;或者其数据仅由一个或多个制表符(0x0009)组成的Text节点,回车符(0x000D )和/或空格(0x0020),并且其父项是Element,其对 'white-space' 的解析值为 'pre-line'592 * @param node593 * @returns594 */595function isWhitespaceNode(node) {596 return node597 && node.nodeType == Node.TEXT_NODE598 && (node.data == ""599 || (600 /^[\t\n\r ]+$/.test(node.data)601 && node.parentNode602 && node.parentNode.nodeType == Node.ELEMENT_NODE603 && ["normal", "nowrap"].indexOf(getComputedStyle(node.parentNode).whiteSpace) != -1)604 || (605 /^[\t\r ]+$/.test(node.data)606 && node.parentNode607 && node.parentNode.nodeType == Node.ELEMENT_NODE608 && getComputedStyle(node.parentNode).whiteSpace == "pre-line"609 ));610}611/**612 * @description 如果以下算法返回true,则节点是折叠的空白节点613 * @param node614 * @returns615 *616 */617function isCollapsedWhitespaceNode(node) {618 // 如果不是空白节点返回619 if (!isWhitespaceNode(node)) {620 return false;621 }622 // 如果 node 的 data 为空,返回 true623 if (node.data == "") {624 return true;625 }626 // 查看祖先节点627 let ancestor = node.parentNode;628 // 如果祖先节点也是空的,返回 ture629 if (!ancestor) {630 return true;631 }632 // 如果祖先节点的属性 display 显示为 none, 返回 ture633 if (getAncestors(node).some(function (ancestor) {634 return ancestor.nodeType == Node.ELEMENT_NODE635 && getComputedStyle(ancestor).display == "none";636 })) {637 return true;638 }639 // 当祖先不是块节点且其父节点不为空时,将祖先设置为其父节点640 while (!isBlockNode(ancestor)641 && ancestor.parentNode) {642 ancestor = ancestor.parentNode;643 }644 // 创建引用节点645 let reference = node;646 // 而 reference 是祖先的后代: 向前查询647 while (reference != ancestor) {648 // 让 reference 按树顺序作为其前面的节点.649 reference = previousNode(reference);650 // 如果是块级节点或者 br 返回 true651 if (isBlockNode(reference)652 || isHtmlElement(reference, "br")) {653 return true;654 }655 // 如果 reference 是不是空格节点的 Text 节点 或 img,请退出此循环656 if ((reference.nodeType == Node.TEXT_NODE && !isWhitespaceNode(reference))657 || isHtmlElement(reference, "img")) {658 break;659 }660 }661 // reference = node662 reference = node;663 // reference 是祖先的后代 向前查询664 let stop = nextNodeDescendants(ancestor);665 while (reference != stop) {666 // 令 reference 为树后的节点,如果没有这样的节点,则为null。667 reference = nextNode(reference);668 // 如果 reference 是块节点或 br,则返回true669 if (isBlockNode(reference)670 || isHtmlElement(reference, "br")) {671 return true;672 }673 // 如果 reference 是不是空格节点的Text节点或img,请退出此循环。674 if ((reference && reference.nodeType == Node.TEXT_NODE && !isWhitespaceNode(reference))675 || isHtmlElement(reference, "img")) {676 break;677 }678 }679 // 都不满足返回 false680 return false;681}682/**683 * @description 判断节点是可见的,如果某个节点是块节点,或不是折叠空格节点的文本节点,或img,或不是无关换行符的br,或任何具有可见子代的节点,则该节点是可见的;排除具有祖先容器元素且其 'display' 属性解析值为 'none' 的任何节点684 * @param node685 * @returns boolean686 */687function isVisible(node) {688 if (!node) {689 return false;690 }691 if (getAncestors(node).concat(node)692 .filter(function (node) { return node.nodeType == Node.ELEMENT_NODE })693 .some(function (node) { return getComputedStyle(node).display == "none" })) {694 return false;695 }696 if (isBlockNode(node)697 || (node.nodeType == Node.TEXT_NODE && !isCollapsedWhitespaceNode(node))698 || isHtmlElement(node, "img")699 || (isHtmlElement(node, "br") && !isExtraneousLineBreak(node))) {700 return true;701 }702 for (let i = 0; i < node.childNodes.length; i++) {703 if (isVisible(node.childNodes[i])) {704 return true;705 }706 }707 return false;708}709/**710 * @description 节点是不可见的711 * @param node712 * @returns713 */714function isInvisible(node) {715 return node && !isVisible(node);716}717/**718 * @description 是折叠的块级属性719 * 折叠的块级属性可以是不是无关的换行符的折叠换行符,也可以是作为内联节点的元素,其子元素都是不可见的或折叠的块级属性,并且至少有一个子元素是折叠的块级属性。720 * @param node721 * @returns722 */723function isCollapsedBlockProp(node) {724 if (isCollapsedLineBreak(node)725 && !isExtraneousLineBreak(node)) {726 return true;727 }728 if (!isInlineNode(node)729 || node.nodeType != Node.ELEMENT_NODE) {730 return false;731 }732 let hasCollapsedBlockPropChild = false;733 for (let i = 0; i < node.childNodes.length; i++) {734 if (!isInvisible(node.childNodes[i])735 && !isCollapsedBlockProp(node.childNodes[i])) {736 return false;737 }738 if (isCollapsedBlockProp(node.childNodes[i])) {739 hasCollapsedBlockPropChild = true;740 }741 }742 return hasCollapsedBlockPropChild;743}744/**745 * @description 获得相邻的下个最近的 node 节点746 * @param node747 * @returns748 */749function nextNode(node: Node) {750 if (node.hasChildNodes()) {751 return node.firstChild;752 }753 return nextNodeDescendants(node);754}755/**756 * @description 下个节点的后代节点757 * @param node758 * @returns759 */760function nextNodeDescendants(node: Node) {761 while (node && !node.nextSibling) {762 node = node.parentNode;763 }764 if (!node) {765 return null;766 }767 return node.nextSibling;768}769/**770 * @description 前一个节点的后代节点771 * @param node772 * @returns773 */774function previousNode(node) {775 if (node.previousSibling) {776 node = node.previousSibling;777 while (node.hasChildNodes()) {778 node = node.lastChild;779 }780 return node;781 }782 if (node.parentNode783 && node.parentNode.nodeType == Node.ELEMENT_NODE) {784 return node.parentNode;785 }786 return null;787}788/**789 * @description 如果祖先是后代的祖先,则返回true,否则返回false。790 */791function isAncestor(ancestor, descendant) {792 return ancestor793 && descendant794 && Boolean(ancestor.compareDocumentPosition(descendant) & Node.DOCUMENT_POSITION_CONTAINED_BY);795}796/**797 * @description 是否是后代的祖先798 * @param ancestor799 * @param descendant800 * @returns801 */802function isAncestorContainer(ancestor, descendant) {803 return (ancestor || descendant)804 && (ancestor == descendant || isAncestor(ancestor, descendant));805}806/**807 * @description 是否是后代节点,其他情况返回 false808 * @param descendant809 * @param ancestor810 * @returns811 */812function isDescendant(descendant, ancestor) {813 return ancestor814 && descendant815 && Boolean(ancestor.compareDocumentPosition(descendant) & Node.DOCUMENT_POSITION_CONTAINED_BY);816}817/**818 * @description 是否在 node1 在 node2 之前 返回 ture819 * @param node1820 * @param node2821 * @returns822 */823function isBefore(node1, node2) {824 return Boolean(node1.compareDocumentPosition(node2) & Node.DOCUMENT_POSITION_FOLLOWING);825}826/**827 * @description 是否在 node1 在 node2 之后 返回 ture828 * @param node1829 * @param node2830 * @returns831 */832function isAfter(node1, node2) {833 return Boolean(node1.compareDocumentPosition(node2) & Node.DOCUMENT_POSITION_PRECEDING);834}835/**836 * @description 获得所有的祖先837 * @param node838 * @returns839 */840function getAncestors(node) {841 const ancestors = [];842 while (node.parentNode) {843 ancestors.unshift(node.parentNode);844 node = node.parentNode;845 }846 return ancestors;847}848/**849 * @description 获得包含自己的所有祖先850 * @param node851 * @returns852 */853function getInclusiveAncestors(node) {854 return getAncestors(node).concat(node);855}856/**857 * @description 获得所有后代节点858 * @param node859 * @returns860 */861function getDescendants(node) {862 const descendants = [];863 const stop = nextNodeDescendants(node);864 while ((node = nextNode(node)) && node != stop) {865 descendants.push(node);866 }867 return descendants;868}869/**870 * @description 获得包含自己的所有后代节点871 * @param node872 * @returns873 */874function getInclusiveDescendants(node) {875 return [node].concat(getDescendants(node));876}877// 转换特别的属性878function convertProperty(property) {879 // Special-case for now880 const map = {881 'fontFamily': 'font-family',882 'fontSize': 'font-size',883 'fontStyle': 'font-style',884 'fontWeight': 'font-weight',885 'textDecoration': 'text-decoration',886 };887 if (typeof map[property] != 'undefined') {888 return map[property];889 }890 return property;891}892// 返回给定CSS大小的<font size = X>值,如果存在,则返回undefined没有。893function cssSizeToLegacy(cssVal) {894 return {895 "x-small": 1,896 "small": 2,897 "medium": 3,898 "large": 4,899 "x-large": 5,900 "xx-large": 6,901 "xxx-large": 7902 }[cssVal];903}904// 根据给定的旧大小返回CSS大小。905function legacySizeToCss(legacyVal) {906 return {907 1: "x-small",908 2: "small",909 3: "medium",910 4: "large",911 5: "x-large",912 6: "xx-large",913 7: "xxx-large",914 }[legacyVal];915}916// HTML中的 “方向性”。 我不用担心非HTML元素。917// “元素的方向性是'ltr'或'rtl',并且根据以下适当的步骤确定”918function getDirectionality(element) {919 // 如果元素的排版方向性是 ltr 那么结果也是 ltr920 if (element.dir == "ltr") {921 return "ltr";922 }923 // 如果元素的排版方向性是 rtl 那么结果也是 rtl924 if (element.dir == "rtl") {925 return "rtl";926 }927 // 如果元素的根节点是 html,那么直接跳过判断,返回默认值928 if (!isHtmlElement(element.parentNode)) {929 return "ltr";930 }931 // 如果没有定义文本的排列方向,寻找父节点,子节点默认集成父节点的方向性932 return getDirectionality(element.parentNode);933}934// 获得 node 在当前节点层级的 index935function getNodeIndex(node) {936 let ret = 0;937 while (node.previousSibling) {938 ret++;939 node = node.previousSibling;940 }941 return ret;942}943/**944 * @description 获得 node 的 length945 * [ProcessingInstruction, DocumentType] 通常返回 0946 * [Text, Comment] 返回自身的 length947 * [anthor] 返回 node's childNodes's length948 */949function getNodeLength(node) {950 switch (node.nodeType) {951 case Node.PROCESSING_INSTRUCTION_NODE:952 case Node.DOCUMENT_TYPE_NODE:953 return 0;954 case Node.TEXT_NODE:955 case Node.COMMENT_NODE:956 return node.length;957 default:958 return node.childNodes.length;959 }960}961/**962 * @description 判断由DOM Range定义的两个边界点彼此相对的位置。963 * @param nodeA964 * @param offsetA965 * @param nodeB966 * @param offsetB967 *968 */969function getPosition(nodeA, offsetA, nodeB, offsetB) {970 // 如果节点A与节点B相同,971 // 则如果偏移量A等于偏移量B,则返回相等972 // 如果偏移量A小于偏移量B,则返回之前973 // 如果偏移量A大于偏移量B,则返回之后974 if (nodeA == nodeB) {975 if (offsetA == offsetB) {976 return "equal";977 }978 if (offsetA < offsetB) {979 return "before";980 }981 if (offsetA > offsetB) {982 return "after";983 }984 }985 // 如果节点A以树顺序在节点B之后,计算(节点B,偏移量B)相对于(节点A,偏移量A)的位置。986 // 如果它在之前,则在返回 after。如果在之后,则返回 before987 if (nodeB.compareDocumentPosition(nodeA) & Node.DOCUMENT_POSITION_FOLLOWING) {988 let pos = getPosition(nodeB, offsetB, nodeA, offsetA);989 if (pos == "before") {990 return "after";991 }992 if (pos == "after") {993 return "before";994 }995 }996 // 如果 nodeA 是 nodeB 的祖先997 if (nodeB.compareDocumentPosition(nodeA) & Node.DOCUMENT_POSITION_CONTAINS) {998 // 计算子节点,nodeB 是 nodeA 的子节点999 let child = nodeB;1000 // 当 child 不是节点A的子代时,将 child 设置为其父代。1001 while (child.parentNode != nodeA) {1002 child = child.parentNode;1003 }1004 // 如果子项的索引小于偏移量A,则返回 after1005 if (getNodeIndex(child) < offsetA) {1006 return "after";1007 }1008 }1009 return "before";1010}1011/**1012 * @description 返回由DOM Range定义的 node的最远祖先。1013 */1014function getFurthestAncestor(node) {1015 let root = node;1016 while (root.parentNode != null) {1017 root = root.parentNode;1018 }1019 return root;1020}1021/**1022 * 由DOM范围定义为“包含”: “如果节点的最远祖先与范围的根相同,并且 node 0 的起始位置在 Range.startContainer 之后,结束节点在 Range.endContainer 之前,那么这个节点被范围包含1023 */1024function isContained(node, range: Range) {1025 let pos1 = getPosition(node, 0, range.startContainer, range.startOffset);1026 let pos2 = getPosition(node, getNodeLength(node), range.endContainer, range.endOffset);1027 return getFurthestAncestor(node) == getFurthestAncestor(range.startContainer)1028 && pos1 == "after"1029 && pos2 == "before";1030}1031// 获得选区范围内包含的所有节点, 忽略包裹的祖先节点1032function getContainedNodes(range, condition) {1033 if (typeof condition == "undefined") {1034 condition = function () { return true };1035 }1036 let node = range.startContainer;1037 if (node.hasChildNodes()1038 && range.startOffset < node.childNodes.length) {1039 // 一个子节点被包裹1040 node = node.childNodes[range.startOffset];1041 } else if (range.startOffset == getNodeLength(node)) {1042 // 不能包含任何后代1043 node = nextNodeDescendants(node);1044 } else {1045 // 如果没有子节点, 该节点也不可以被包含1046 node = nextNode(node);1047 }1048 let stop = range.endContainer;1049 if (stop.hasChildNodes()1050 && range.endOffset < stop.childNodes.length) {1051 // 最后一个包含的节点之后的节点是子节点1052 stop = stop.childNodes[range.endOffset];1053 } else {1054 // 可能包含此节点和/或其某些子节点1055 stop = nextNodeDescendants(stop);1056 }1057 let nodeList = [];1058 while (isBefore(node, stop)) {1059 if (isContained(node, range)1060 && condition(node)) {1061 nodeList.push(node);1062 node = nextNodeDescendants(node);1063 continue;1064 }1065 node = nextNode(node);1066 }1067 return nodeList;1068}1069// 获得选区范围内包含的所有节点, 不忽略包裹的祖先节点1070function getAllContainedNodes(range, condition) {1071 if (typeof condition == "undefined") {1072 condition = function () { return true };1073 }1074 let node = range.startContainer;1075 if (node.hasChildNodes()1076 && range.startOffset < node.childNodes.length) {1077 // 一个子节点被包裹1078 node = node.childNodes[range.startOffset];1079 } else if (range.startOffset == getNodeLength(node)) {1080 // 不能包含任何后代1081 node = nextNodeDescendants(node);1082 } else {1083 // 如果没有子节点, 该节点也不可以被包含1084 node = nextNode(node);1085 }1086 let stop = range.endContainer;1087 if (stop.hasChildNodes()1088 && range.endOffset < stop.childNodes.length) {1089 // 最后一个包含的节点之后的节点是子节点1090 stop = stop.childNodes[range.endOffset];1091 } else {1092 // 可能包含此节点和/或其某些子节点1093 stop = nextNodeDescendants(stop);1094 }1095 let nodeList = [];1096 while (isBefore(node, stop)) {1097 if (isContained(node, range)1098 && condition(node)) {1099 nodeList.push(node);1100 }1101 node = nextNode(node);1102 }1103 return nodeList;1104}1105function normalizeColor(color) {1106 let resultCache = {}1107 if (color.toLowerCase() == "currentcolor") {...

Full Screen

Full Screen

dom-utils.ts

Source:dom-utils.ts Github

copy

Full Screen

...220 break221 }222 }223 reference = node224 let stop = nextNodeDescendants(ancestor)225 while (reference != stop) {226 reference = nextNode(reference)227 if (isBlockNode(reference)228 || isHtmlElement(reference, 'br')) {229 return true230 }231 if (reference232 && reference.nodeType == Node.TEXT_NODE233 && !isWhitespaceNode(reference)234 || isHtmlElement(reference, 'img')235 ) {236 break237 }238 }239 return false240}241export function isVisible(node) {242 if (!node) return false243 if (244 getAncestors(node)245 .concat(node)246 .filter(function (node) {247 return node.nodeType == Node.ELEMENT_NODE248 })249 .some(function (node) {250 return getComputedStyle(node).display == 'none'251 })252 ) {253 return false254 }255 if (isBlockNode(node)256 || (node.nodeType == Node.TEXT_NODE && !isCollapsedWhitespaceNode(node))257 || isHtmlElement(node, 'img')258 || (isHtmlElement(node, 'br') && !isExtraneousLineBreak(node))) {259 return true260 }261 for (let i = 0; i < node.childNodes.length; i++) {262 if (isVisible(node.childNodes[i])) return true263 }264 return false265}266export function isInvisible(node) {267 return node && !isVisible(node)268}269export function isCollapsedBlockProp(node) {270 if (isCollapsedLineBreak(node) && !isExtraneousLineBreak(node)) {271 return true272 }273 if (!isInlineNode(node) || node.nodeType != Node.ELEMENT_NODE) {274 return false275 }276 let hasCollapsedBlockPropChild = false277 for (let i = 0; i < node.childNodes.length; i++) {278 if (!isInvisible(node.childNodes[i])279 && !isCollapsedBlockProp(node.childNodes[i])280 ) {281 return false282 }283 if (isCollapsedBlockProp(node.childNodes[i])) {284 hasCollapsedBlockPropChild = true285 }286 }287 return hasCollapsedBlockPropChild288}289export function isHtmlNamespace(ns) {290 return ns === null || ns === htmlNamespace291}292export function isHtmlElement(node, tags?) {293 if (typeof tags == 'string') {294 tags = [tags]295 }296 if (typeof tags == 'object') {297 tags = tags.map(function (tag) {298 return tag.toUpperCase()299 })300 }301 return node302 && node.nodeType == Node.ELEMENT_NODE303 && isHtmlNamespace(node.namespaceURI)304 && (typeof tags == 'undefined' || tags.indexOf(node.tagName) != -1)305}306export function nextNode(node) {307 if (node.hasChildNodes()) {308 return node.firstChild309 }310 return nextNodeDescendants(node)311}312export function nextNodeDescendants(node) {313 while (node && !node.nextSibling) {314 node = node.parentNode315 }316 if (!node) {317 return null318 }319 return node.nextSibling320}321export function previousNode(node) {322 if (node.previousSibling) {323 node = node.previousSibling324 while (node.hasChildNodes()) {325 node = node.lastChild326 }327 return node328 }329 if (node.parentNode330 && node.parentNode.nodeType == Node.ELEMENT_NODE) {331 return node.parentNode332 }333 return null334}335export function isAncestor(ancestor, descendant) {336 return ancestor337 && descendant338 && Boolean(ancestor.compareDocumentPosition(descendant) & Node.DOCUMENT_POSITION_CONTAINED_BY)339}340export function isAncestorContainer(ancestor, descendant) {341 return (ancestor || descendant)342 && (ancestor == descendant || isAncestor(ancestor, descendant))343}344export function isDescendant(descendant, ancestor) {345 return ancestor346 && descendant347 && Boolean(ancestor.compareDocumentPosition(descendant) & Node.DOCUMENT_POSITION_CONTAINED_BY)348}349export function isBefore(node1: Node, node2: Node) {350 return Boolean(node1.compareDocumentPosition(node2) & Node.DOCUMENT_POSITION_FOLLOWING)351}352export function isAfter(node1: Node, node2: Node) {353 return Boolean(node1.compareDocumentPosition(node2) & Node.DOCUMENT_POSITION_PRECEDING)354}355export function getAncestors(node, condition?: Function | null) {356 const ancestors = []357 if (!condition) condition = function (node) { return true }358 while (node.parentNode && condition(node)) {359 ancestors.unshift(node.parentNode)360 node = node.parentNode361 }362 return ancestors363}364export function getInclusiveAncestors(node: Node, condition?: Function) {365 return getAncestors(node, condition).concat(node)366}367export function getDescendants(node: Node) {368 const descendants = []369 let stop = nextNodeDescendants(node)370 while ((node = nextNode(node)) && node != stop) {371 descendants.push(node)372 }373 return descendants374}375export function getInclusiveDescendants(node) {376 return [node].concat(getDescendants(node))377}378export function getDirectionality(element) {379 if (element.dir == 'ltr') {380 return 'ltr'381 }382 if (element.dir == 'rtl') {383 return 'rtl'384 }385 if (!isHtmlElement(element.parentNode)) {386 return 'ltr'387 }388 return getDirectionality(element.parentNode)389}390export function getBlockNodeOf(node) {391 while (isInlineNode(node)) {392 node = node.parentNode;393 }394 return node;395}396export function getNodeIndex(node) {397 let ret = 0398 while (node.previousSibling) {399 ret++400 node = node.previousSibling;401 }402 return ret403}404export function getNodeLength(node) {405 switch (node.nodeType) {406 case Node.PROCESSING_INSTRUCTION_NODE:407 case Node.DOCUMENT_TYPE_NODE:408 return 0;409 case Node.TEXT_NODE:410 case Node.COMMENT_NODE:411 return node.length;412 default:413 return node.childNodes.length;414 }415}416function getPosition(nodeA: Node, offsetA: number, nodeB: Node, offsetB: number): string {417 if (nodeA == nodeB) {418 if (offsetA == offsetB) return 'equal'419 if (offsetA < offsetB) return 'before'420 if (offsetA > offsetB) return 'after'421 }422 if (nodeB.compareDocumentPosition(nodeA) & Node.DOCUMENT_POSITION_FOLLOWING) {423 const pos = getPosition(nodeB, offsetB, nodeA, offsetA);424 if (pos == 'before') return 'after'425 if (pos == 'after') 'before'426 }427 if (nodeB.compareDocumentPosition(nodeA) & Node.DOCUMENT_POSITION_CONTAINS) {428 let child = nodeB;429 while (child.parentNode != nodeA) child = child.parentNode430 if (getNodeIndex(child) < offsetA) return 'after';431 }432 return 'before';433}434// 获得最远的祖先节点435function getFurthestAncestor(node) {436 let root = node437 while (root.parentNode) {438 root = root.parentNode;439 }440 return root;441}442// 被包含定义为在开始节点之后,在结束节点之前,就认为被包含443function isContained(node: Node, range: Range) {444 const startPosition = getPosition(node, 0, range.startContainer, range.startOffset);445 const endPosition = getPosition(node, getNodeLength(node), range.endContainer, range.endOffset);446 return getFurthestAncestor(node) == getFurthestAncestor(range.startContainer)447 && startPosition == 'after'448 && endPosition == 'before';449}450export function isContainedNode(node: Node, otherNode: Node) {451 return node.contains(otherNode)452}453// 是否有效被包含454function isEffectivelyContained(node: Node, range: Range) {455 if (range.collapsed) return false;456 if (isContained(node, range)) return true;457 if (node == range.startContainer458 && node.nodeType == Node.TEXT_NODE459 && getNodeLength(node) != range.startOffset) {460 return true;461 }462 if (node == range.endContainer463 && node.nodeType == Node.TEXT_NODE464 && range.endOffset != 0) {465 return true;466 }467 if (node.hasChildNodes()468 && [].every.call(node.childNodes, (child: Node) => isEffectivelyContained(child, range))469 && (!isDescendant(range.startContainer, node)470 || range.startContainer.nodeType != Node.TEXT_NODE471 || range.startOffset == 0)472 && (!isDescendant(range.endContainer, node)473 || range.endContainer.nodeType != Node.TEXT_NODE474 || range.endOffset == getNodeLength(range.endContainer)475 )476 ) {477 return true;478 }479 return false;480}481// 与 get(All)ContainedNodes() 类似,但用于有效包含的节点 不包含 TextNode482export function getEffectivelyContainedNodes(range: Range, condition?: Function) {483 if (typeof condition == 'undefined') {484 condition = function() { return true };485 }486 let node = range.startContainer487 while (isEffectivelyContained(node.parentNode, range)) {488 node = node.parentNode489 }490 // 获得选区结束的下个节点491 let stop = nextNodeDescendants(range.endContainer);492 const nodeList = []493 while (isBefore(node, stop)) {494 if (isEffectivelyContained(node, range)495 && condition(node)) {496 nodeList.push(node)497 node = nextNodeDescendants(node)498 continue;499 }500 node = nextNode(node);501 }502 return nodeList;503}504export function getAllEffectivelyContainedNodes(range: Range, condition?: Function) {505 if (typeof condition == 'undefined') {506 condition = function() { return true };507 }508 // 获得开始节点的最顶层被包裹在选区范围内的节点509 let node = range.startContainer;510 while (isEffectivelyContained(node.parentNode, range)) {511 node = node.parentNode;512 }513 // 获得选区结束的下个节点514 let stop = nextNodeDescendants(range.endContainer);515 // 开始对节点进行读取,进行树深度前序遍历得到选中的 list516 const nodeList = [];517 while (isBefore(node, stop)) {518 // 判断是否当前节点被有效包含,因为会存在范围溢出的情况519 // condition 对当前节点进行判断,默认会选中所有节点520 if (isEffectivelyContained(node, range)521 && condition(node)) {522 nodeList.push(node);523 }524 node = nextNode(node);525 }526 return nodeList;...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

...9export function nextNode(node) {10 if (node.hasChildNodes()) {11 return node.firstChild12 }13 return nextNodeDescendants(node)14}15export function nextNodeDescendants(node) {16 while (node && !node.nextSibling) {17 node = node.parentNode18 }19 if (!node) {20 return null21 }22 return node.nextSibling23}24// 获得当前 node 的index25export function getNodeIndex(node) {26 let ret = 027 while (node.previousSibling) {28 ret++29 node = node.previousSibling;30 }31 return ret32}33// 获得节点的具体长度34export function getNodeLength(node) {35 switch (node.nodeType) {36 case Node.PROCESSING_INSTRUCTION_NODE:37 case Node.DOCUMENT_TYPE_NODE:38 return 0;39 case Node.TEXT_NODE:40 case Node.COMMENT_NODE:41 return node.length;42 default:43 return node.childNodes.length;44 }45}46// 获得节点位置47export function getPosition(nodeA, offsetA, nodeB, offsetB) {48 if (nodeA == nodeB) {49 if (offsetA == offsetB) return 'equal'50 if (offsetA < offsetB) return 'before'51 if (offsetA > offsetB) return 'after'52 }53 if (nodeB.compareDocumentPosition(nodeA) & Node.DOCUMENT_POSITION_FOLLOWING) {54 const pos = getPosition(nodeB, offsetB, nodeA, offsetA);55 if (pos == 'before') return 'after'56 if (pos == 'after') 'before'57 }58 if (nodeB.compareDocumentPosition(nodeA) & Node.DOCUMENT_POSITION_CONTAINS) {59 let child = nodeB;60 while (child.parentNode != nodeA) child = child.parentNode61 if (getNodeIndex(child) < offsetA) return 'after';62 }63 return 'before';64}65// 获得最远的祖先节点66export function getFurthestAncestor(node) {67 let root = node68 while (root.parentNode) {69 root = root.parentNode;70 }71 return root;72}73// 被包含定义为在开始节点之后,在结束节点之前,就认为被包含74export function isContained(node, range) {75 const startPosition = getPosition(node, 0, range.startContainer, range.startOffset);76 const endPosition = getPosition(node, getNodeLength(node), range.endContainer, range.endOffset);77 return getFurthestAncestor(node) == getFurthestAncestor(range.startContainer)78 && startPosition == 'after'79 && endPosition == 'before';80}81// 是否有效被包含82export function isEffectivelyContained(node, range) {83 if (range.collapsed) return false;84 if (isContained(node, range)) return true;85 if (node == range.startContainer86 && node.nodeType == Node.TEXT_NODE87 && getNodeLength(node) != range.startOffset) {88 return true;89 }90 if (node == range.endContainer91 && node.nodeType == Node.TEXT_NODE92 && range.endOffset != 0) {93 return true;94 }95 if (node.hasChildNodes()96 && [].every.call(node.childNodes, (child) => isEffectivelyContained(child, range))97 && (!isDescendant(range.startContainer, node)98 || range.startContainer.nodeType != Node.TEXT_NODE99 || range.startOffset == 0)100 && (!isDescendant(range.endContainer, node)101 || range.endContainer.nodeType != Node.TEXT_NODE102 || range.endOffset == getNodeLength(range.endContainer)103 )104 ) {105 return true;106 }107 return false;108}109// 获得所有被包含的节点110export function getAllEffectivelyContainedNodes(range, condition) {111 if (typeof condition == 'undefined') {112 condition = function() { return true };113 }114 // 获得开始节点的最顶层被包裹在选区范围内的节点115 let node = range.startContainer;116 while (isEffectivelyContained(node.parentNode, range)) {117 node = node.parentNode;118 }119 // 获得选区结束的下个节点120 let stop = nextNodeDescendants(range.endContainer);121 // 开始对节点进行读取,进行树深度前序遍历得到选中的 list122 const nodeList = [];123 while (isBefore(node, stop)) {124 // 判断是否当前节点被有效包含,因为会存在范围溢出的情况125 // condition 对当前节点进行判断,默认会选中所有节点126 if (isEffectivelyContained(node, range)127 && condition(node)) {128 nodeList.push(node);129 }130 node = nextNode(node);131 }132 return nodeList;133}134export function isContainedNode(node, otherNode) {...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var tree = new WebFXTree('Root');2var node1 = tree.add(new WebFXTreeItem('Node 1'));3var node2 = tree.add(new WebFXTreeItem('Node 2'));4var node3 = tree.add(new WebFXTreeItem('Node 3'));5var node4 = tree.add(new WebFXTreeItem('Node 4'));6var node5 = tree.add(new WebFXTreeItem('Node 5'));7var node6 = node1.add(new WebFXTreeItem('Node 6'));8var node7 = node1.add(new WebFXTreeItem('Node 7'));9var node8 = node2.add(new WebFXTreeItem('Node 8'));10var node9 = node2.add(new WebFXTreeItem('Node 9'));11var node10 = node3.add(new WebFXTreeItem('Node 10'));12var node11 = node3.add(new WebFXTreeItem('Node 11'));13var node12 = node4.add(new WebFXTreeItem('Node 12'));14var node13 = node4.add(new WebFXTreeItem('Node 13'));15var node14 = node5.add(new WebFXTreeItem('Node 14'));16var node15 = node5.add(new WebFXTreeItem('Node 15'));17var node16 = node6.add(new WebFXTreeItem('Node 16'));18var node17 = node6.add(new WebFXTreeItem('Node 17'));19var node18 = node7.add(new WebFXTreeItem('Node 18'));20var node19 = node7.add(new WebFXTreeItem('Node 19'));21var node20 = node8.add(new WebFXTreeItem('Node 20'));22var node21 = node8.add(new WebFXTreeItem('Node 21'));23var node22 = node9.add(new WebFXTreeItem('Node 22'));24var node23 = node9.add(new WebFXTreeItem('Node 23'));25var node24 = node10.add(new WebFXTreeItem('Node 24'));26var node25 = node10.add(new WebFXTreeItem('Node 25'));27var node26 = node11.add(new WebFXTreeItem('Node 26'));28var node27 = node11.add(new WebFXTreeItem('Node 27'));29var node28 = node12.add(new WebFXTreeItem('Node 28'));30var node29 = node12.add(new WebFXTreeItem('Node 29

Full Screen

Using AI Code Generation

copy

Full Screen

1var tree = new WebFXTree('Root');2var node1 = tree.add(new WebFXTreeItem('Node 1'));3var node2 = tree.add(new WebFXTreeItem('Node 2'));4var node3 = tree.add(new WebFXTreeItem('Node 3'));5var node4 = tree.add(new WebFXTreeItem('Node 4'));6var node5 = tree.add(new WebFXTreeItem('Node 5'));7var node6 = node1.add(new WebFXTreeItem('Node 6'));8var node7 = node1.add(new WebFXTreeItem('Node 7'));9var node8 = node2.add(new WebFXTreeItem('Node 8'));10var node9 = node2.add(new WebFXTreeItem('Node 9'));11var node10 = node3.add(new WebFXTreeItem('Node 10'));12var node11 = node3.add(new WebFXTreeItem('Node 11'));13var node12 = node4.add(new WebFXTreeItem('Node 12'));14var node13 = node4.add(new WebFXTreeItem('Node 13'));15var node14 = node5.add(new WebFXTreeItem('Node 14'));16var node15 = node5.add(new WebFXTreeItem('Node 15'));17var node16 = node6.add(new WebFXTreeItem('Node 16'));18var node17 = node6.add(new WebFXTreeItem('Node 17'));19var node18 = node7.add(new WebFXTreeItem('Node 18'));20var node19 = node7.add(new WebFXTreeItem('Node 19'));21var node20 = node8.add(new WebFXTreeItem('Node 20'));22var node21 = node8.add(new WebFXTreeItem('Node 21'));23var node22 = node9.add(new WebFXTreeItem('Node 22'));24var node23 = node9.add(new WebFXTreeItem('Node 23'));25var node24 = node10.add(new WebFXTreeItem('Node 24'));26var node25 = node10.add(new WebFXTreeItem('Node 25'));27var node26 = node11.add(new WebFXTreeItem('Node 26'));28var node27 = node11.add(new WebFXTreeItem('Node 27'));29var node28 = node12.add(new WebFXTreeItem('Node 28'));30var node29 = node12.add(new WebFXTreeItem('Node 29

Full Screen

Using AI Code Generation

copy

Full Screen

1var tree = new WPTree();2var node1 = new WPNode();3node1.name = "node1";4var node2 = new WPNode();5node2.name = "node2";6var node3 = new WPNode();7node3.name = "node3";8var node4 = new WPNode();9node4.name = "node4";10var node5 = new WPNode();11node5.name = "node5";12var node6 = new WPNode();13node6.name = "node6";14var node7 = new WPNode();15node7.name = "node7";16var node8 = new WPNode();17node8.name = "node8";18var node9 = new WPNode();19node9.name = "node9";20var node10 = new WPNode();21node10.name = "node10";22var node11 = new WPNode();23node11.name = "node11";24var node12 = new WPNode();25node12.name = "node12";26var node13 = new WPNode();27node13.name = "node13";28var node14 = new WPNode();29node14.name = "node14";30var node15 = new WPNode();31node15.name = "node15";32var node16 = new WPNode();33node16.name = "node16";34tree.root = node1;35node1.addChild(node2);36node1.addChild(node3);37node1.addChild(node4);38node1.addChild(node5);39node1.addChild(node6);40node1.addChild(node7);41node1.addChild(node8);42node1.addChild(node9);43node1.addChild(node10);44node1.addChild(node11);45node1.addChild(node12);46node1.addChild(node13);47node1.addChild(node14);48node1.addChild(node15);49node1.addChild(node16);50var nodeArray = tree.nextNodeDescendants(node1, 3);51for (var i = 0; i < nodeArray.length; i++) {52 console.log(nodeArray[i].name);53}54var tree = new WPTree();55var node1 = new WPNode();56node1.name = "node1";57var node2 = new WPNode();58node2.name = "node2";59var node3 = new WPNode();60node3.name = "node3";

Full Screen

Using AI Code Generation

copy

Full Screen

1var tree = new WPTree();2tree.root = new WPNode("root");3var child1 = new WPNode("child1");4var child2 = new WPNode("child2");5var child3 = new WPNode("child3");6var child4 = new WPNode("child4");7var child5 = new WPNode("child5");8var child6 = new WPNode("child6");9var child7 = new WPNode("child7");10var child8 = tew WPNree("child8");11var child9 = new WPNode("child9");12var child10 = new WPNode("child10");13var child11 = new WPNode("child11");14var child12 = new WPNode("child12");15var child13 = new WPNode("child13");16var child14 = new WPNode("child14");17var child15 = new WPNode("child15");18var child16 = new WPNode("child16");19var child17 = new WPNode("child17");20var child18 = new WPNode("child18");21var child19 = new WPNode("child19");22var child20 = new WPNode("child20");23var child21 = new WPNode("child21");24var child22 = new WPNode("child22");25var child23 = new WPNode("child23");26var child24 = new WPNode("child24");27var child25 = new WPNode("child25");28var child26 = new WPNode("child26");29var child27 = new WPNode("child27");30var child28 = new WPNode("child28");31var child29 = new WPNode("child29");32var child30 = new WPNode("child30");33var child31 = new WPNode("child31");34var child32 = new WPNode("child32");35var child33 = new WPNode("child33");36var child34 = new WPNode("child34");37var child35 = new WPNode("child35");38var child36 = new WPNode("child36");39var child37 = new WPNode("child37");40var child38 = new WPNode("child38");41var child39 = new WPNode("child39");42var child40 = new WPNode("child40");43var child41 = new WPNode("child41");44var child42 = new WPNode("child42");45var child43 = new WPNode("child43");

Full Screen

Using AI Code Generation

copy

Full Screen

1var node = new WPTree();2tree.root = new WPNode("root");3var child1 = new WPNode("child1");4var child2 = new WPNode("child2");5var child3 = new WPNode("child3");6var child4 = new WPNode("child4");7var child5 = new WPNode("child5");8var child6 = new WPNode("child6");9var child7 = new WPNode("child7");10var child8 = new WPNode("child8");11var child9 = new WPNode("child9");12var child10 = new WPNode("child10");13var child11 = new WPNode("child11");14var child12 = new WPNode("child12");15var child13 = new WPNode("child13");16var child14 = new WPNode("child14");17var child15 = new WPNode("child15");18var child16 = new WPNode("child16");19var child17 = new WPNode("child17");20var child18 = new WPNode("child18");21var child19 = new WPNode("child19");22var child20 = new WPNode("child20");23var child21 = new WPNode("child21");24var child22 = new WPNode("child22");25var child23 = new WPNode("child23");26var child24 = new WPNode("child24");27var child25 = new WPNode("child25");28var child26 = new WPNode("child26");29var child27 = new WPNode("child27");30var child28 = new WPNode("child28");31var child29 = new WPNode("child29");32var child30 = new WPNode("child30");33var child31 = new WPNode("child31");34var child32 = new WPNode("child32");35var child33 = new WPNode("child33");36var child34 = new WPNode("child34");37var child35 = new WPNode("child35");38var child36 = new WPNode("child36");39var child37 = new WPNode("child37");40var child38 = new WPNode("child38");41var child39 = new WPNode("child39");42var child40 = new WPNode("child40");43var child41 = new WPNode("child41");44var child42 = new WPNode("child42");45var child43 = new WPNode("child43");

Full Screen

Using AI Code Generation

copy

Full Screen

1var node = tree.getNodeById(1);2var descendants = node.nextNodeDescendants();3var i = 0;4while (i < descendants.length) {5 alert(descendants[i].id);6 i++;7}8var node = tree.getNodeById(1);9var nextDescendant = node.nextNode();10alert(nextDescendant.id);11var node = tree.getNodeById(1);12var descendants = node.previousNodeDescendants();13var i = 0;14while (i < descendants.length) {15 alert(descendants[i].id);16 i++;17}hildren

Full Screen

Using AI Code Generation

copy

Full Screen

1var tree = wptree.getTree("tree1");2var node = tree.getNode("node1");3var nextNodeDescendants = node.nextNodeDescendants();4var tree = wptree.getTree("tree1");5var node = tree.getNode("node1");6var nextNodeDescendants = node.nextNodeDescendants("tag1");7var tree = wptree.getTree("tree1");8var node = tree.getNode("node1");9var nextNodeDescendants = node.nextNodeDescendants("tag1","value1");10var tree = wptree.getTree("tree1");11var noe = tee.getNode("nod1");12var extNodeDescendants = node.nextNodeDescendants("tag1","value1");13var tree = wptree.getTree("tree1");14var node = tree.getNode("node1");15var nextNodeDescendants = node.nextNodeDescendants("tag1","value1");16var tree = wptree.getTree("tree1");17var node = tree.getNode("node1");18var nextNodeDescendants = node.nextNodeDescendants("tag1","value1");19var tree = wptree.getTree("tree1");20var node = tree.getNode("node1");21var nextNodeDescendants = node.nextNodeDescendants("tag1","value1");22var tree = wptree.getTree("tree1");23var node = tree.getNode("node1");24var nextNodeDescendants = node.nextNodeDescendants("tag1","value1");25var node = tree.getNodeById(1);26var previousDescendant = node.previousNode();27alert(previousDescendant.id);28var node = tree.getNodeById(1);29alert(node.isLast());30var node = tree.getNodeById(1);31alert(node.isFirst());32var node = tree.getNodeById(1);33alert(node.isLeaf());34var node = tree.getNodeById(1);35alert(node.isRoot());36var node = tree.getNodeById(1);37var node2 = tree.getNodeById(2);38alert(node.isDescendantOf(node2));

Full Screen

Using AI Code Generation

copy

Full Screen

1var treeView = document.getElementById("myTreeView");2var treeItem = treeView.selectedItem;3var treeItemDescendants = treeView.nextNodeDescendants(treeItem);4for (var i=0; i<treeItemDescendants.lengt; i++) {5 alert(treeItemDescendants[i].getAttrbute("labe"));6}7var node = tree.getNodeById(1);8var node2 = tree.getNodeById(2);9alert(node.isAncestorOf(node2));10var node = tree.getNodeById(1);11var node2 = tree.getNodeById(2);12alert(node.isParentOf(node2));13var node = tree.getNodeById(1);14var node2 = tree.getNodeById(

Full Screen

Using AI Code Generation

copy

Full Screen

1var treeView = new WpTreeView("treeView", "treeViewRoot");2treeView.nextNodeDescendants();3WpTreeView.prototype.nextNodeDescendants = function() {4 var treeView = this;5 var treeViewRoot = treeView.treeViewRoot;6 var treeViewRootChildren = treeViewRoot.children;7 var treeViewRootChildrenLength = treeViewRootChildren.length;8 var treeViewRootChildrenLengthMinusOne = treeViewRootChildrenLength - 1;9 for (var i = 0; i < treeViewRootChildrenLength; i++) {10 var treeViewRootChild = treeViewRootChildren[i];11 var treeViewRootChildChildren = treeViewRootChild.children;12 var treeViewRootChildChildrenLength = treeViewRootChildChildren.length;13 var treeViewRootChildChildrenLengthMinusOne = treeViewRootChildChildrenLength - 1;14 for (var j = 0; j < treeViewRootChildChildrenLength; j++) {15 var treeViewRootChildChild = treeViewRootChildChildren[j];16 var treeViewRootChildChildChildren = treeViewRootChildChild.children;17 var treeViewRootChildChildChildrenLength = treeViewRootChildChildChildren.length;18 var treeViewRootChildChildChildrenLengthMinusOne = treeViewRootChildChildChildrenLength - 1;19 for (var k = 0; k < treeViewRootChildChildChildrenLength; k++) {20 var treeViewRootChildChildChild = treeViewRootChildChildChildren[k];21 var treeViewRootChildChildChildChildren = treeViewRootChildChildChild.children;22 var treeViewRootChildChildChildChildrenLength = treeViewRootChildChildChildChildren.length;23 var treeViewRootChildChildChildChildrenLengthMinusOne = treeViewRootChildChildChildChildrenLength - 1;24 for (var l = 0; l < treeViewRootChildChildChildChildrenLength; l++) {25 var treeViewRootChildChildChildChild = treeViewRootChildChildChildChildren[l];26 var treeViewRootChildChildChildChildChildren = treeViewRootChildChildChildChild.children;27 var treeViewRootChildChildChildChildChildrenLength = treeViewRootChildChildChildChildChildren.length;

Full Screen

Using AI Code Generation

copy

Full Screen

1var treeView = document.getElementById("myTreeView");2var treeItem = treeView.selectedItem;3var treeItemDescendants = treeView.nextNodeDescendants(treeItem);4for (var i=0; i<treeItemDescendants.length; i++) {5 alert(treeItemDescendants[i].getAttribute("label"));6}

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful