How to use getSpecifiedCommandValue method in wpt

Best JavaScript code snippet using wpt

Command.ts

Source:Command.ts Github

copy

Full Screen

...146 }147 return editCommandMethod(command, range, callback)148 }149 // 获得指定的命令的值150 function getSpecifiedCommandValue(element, command) {151 // 如果 command 是 ['backColor', 'hiliteColor'] 并且这个元素不是'inline', 返回 null152 if ((command == "backcolor" || command == "hilitecolor")153 && getComputedStyle(element).display != "inline") {154 return null;155 }156 // command 是 'createLink' or 'unlink'157 if (command == "createlink" || command == "unlink") {158 // 如果是一个 Element 元素,并且拥有 href 属性,就 return 这个值159 if (utils.isHtmlElement(element)160 && element.tagName == "A"161 && element.hasAttribute("href")) {162 return element.getAttribute("href");163 }164 return null;165 }166 // 如果 command 是 subscript or superscript167 if (command == "subscript" || command == "superscript") {168 // 如果 element 是 "sup", return "superscript"169 if (utils.isHtmlElement(element, "sup")) {170 return "superscript";171 }172 // 如果 elelment 是 sub,return "subscript"173 if (utils.isHtmlElement(element, "sub")) {174 return "subscript";175 }176 return null;177 }178 // 如果 command 是 "strikethrough", 并且 element 设置了 style 属性,并且属性中设置了 text-decoration179 if (command == "strikethrough"180 && element.style.textDecoration != "") {181 // 如果 element 元素 style 中设置了 text-decoration 并且包含 line-through 属性,返回该属性182 if (element.style.textDecoration.indexOf("line-through") != -1) {183 return "line-through";184 }185 return null;186 }187 // 如果 command 是 "strikethrough" 并且 element 是 s or strike,直接返回 line-through188 if (command == "strikethrough"189 && utils.isHtmlElement(element, ["S", "STRIKE"])) {190 return "line-through";191 }192 // 如果 command 是 "underline", 并且 element 设置了 style 并且还设置了 text-decoration193 if (command == "underline"194 && element.style.textDecoration != "") {195 // 如果 element 元素 style 中设置了 text-decoration 并且包含 underline 属性,返回该属性196 if (element.style.textDecoration.indexOf("underline") != -1) {197 return "underline";198 }199 return null;200 }201 // 如果 command is "underline" 并且 element 是 [u] 直接返回 underline202 if (command == "underline"203 && utils.isHtmlElement(element, "U")) {204 return "underline";205 }206 // 获得 command 相关的属性 property207 let property = commands.get(command).relevantCssProperty;208 if (property === null) {209 return null;210 }211 // 如果 element 有相关属性设置,返回相关属性212 if (element.style[property] != "") {213 return element.style[property];214 }215 // 如果 element 是一个 font element,返回当前默认的有效属性216 if (utils.isHtmlNamespace(element.namespaceURI)217 && element.tagName == "FONT") {218 if (property == "color" && element.hasAttribute("color")) {219 return element.color;220 }221 if (property == "fontFamily" && element.hasAttribute("face")) {222 return element.face;223 }224 if (property == "fontSize" && element.hasAttribute("size")) {225 // This is not even close to correct in general.226 let size = parseInt(element.size);227 if (size < 1) {228 size = 1;229 }230 if (size > 7) {231 size = 7;232 }233 return {234 1: "x-small",235 2: "small",236 3: "medium",237 4: "large",238 5: "x-large",239 6: "xx-large",240 7: "xxx-large"241 }[size];242 }243 }244 // 如果是 fontWeight / fontStyle 则有两种情况, ['b', 'strong'] / ['i', 'em'],都返回正确的结果245 if (property == "fontWeight"246 && (element.tagName == "B" || element.tagName == "STRONG")) {247 return "bold";248 }249 if (property == "fontStyle"250 && (element.tagName == "I" || element.tagName == "EM")) {251 return "italic";252 }253 return null;254 }255 // 获得有效的命令值256 function getEffectiveCommandValue(node, command) {257 // 如果 node 不是 element 并且父节点也不是258 if (node.nodeType != Node.ELEMENT_NODE259 && (!node.parentNode || node.parentNode.nodeType != Node.ELEMENT_NODE)) {260 return null;261 }262 // 获得生效的父节点的命令值263 if (node.nodeType != Node.ELEMENT_NODE) {264 return getEffectiveCommandValue(node.parentNode, command);265 }266 // 如果命令是 command 是 "createlink" or "unlink"267 if (command == "createlink" || command == "unlink") {268 // 获得有效的 href 属性的 node269 while (node270 && (!utils.isHtmlElement(node)271 || node.tagName != "A"272 || !node.hasAttribute("href"))) {273 node = node.parentNode;274 }275 if (!node) {276 return null;277 }278 return node.getAttribute("href");279 }280 // 如果 command 是 "backColor" or "hiliteColor"281 if (command == "backcolor"282 || command == "hilitecolor") {283 // 获得有效的 backgroundColor 元素284 while ((getComputedStyle(node).backgroundColor == "rgba(0, 0, 0, 0)"285 || getComputedStyle(node).backgroundColor === ""286 || getComputedStyle(node).backgroundColor == "transparent")287 && node.parentNode288 && node.parentNode.nodeType == Node.ELEMENT_NODE) {289 node = node.parentNode;290 }291 return getComputedStyle(node).backgroundColor;292 }293 // 如果命令是 is "subscript" or "superscript"294 if (command == "subscript" || command == "superscript") {295 // 初始化 "subscript" or "superscript" 都为 false296 let affectedBySubscript = false;297 let affectedBySuperscript = false;298 // 如果 node 是 inline 类型299 while (utils.isInlineNode(node)) {300 let verticalAlign = getComputedStyle(node).verticalAlign;301 // 如果 node 是 sub, 设置 affectedBySubscript = true 如果是sub,设置 affectedBySuperscript = true;302 if (utils.isHtmlElement(node, "sub")) {303 affectedBySubscript = true;304 } else if (utils.isHtmlElement(node, "sup")) {305 affectedBySuperscript = true;306 }307 node = node.parentNode;308 }309 // 如果 affectedBySubscript affectedBySuperscript 都为 true 返回 mixed310 if (affectedBySubscript && affectedBySuperscript) {311 return "mixed";312 }313 // 如果 affectedBySubscript 为 true 返回 subscript314 if (affectedBySubscript) {315 return "subscript";316 }317 // 如果 affectedBySuperscript 为 true 返回 superscript318 if (affectedBySuperscript) {319 return "superscript";320 }321 return null;322 }323 // 如果 command 是 "strikethrough", 并且设置了 "text-decoration" 属性,并且包含 line-through 就立即返回,如果没有,返回 null324 if (command == "strikethrough") {325 do {326 if (getComputedStyle(node).textDecoration.indexOf("line-through") != -1) {327 return "line-through";328 }329 node = node.parentNode;330 } while (node && node.nodeType == Node.ELEMENT_NODE);331 return null;332 }333 // 如果 command 是 "strikethrough", 并且设置了 "text-decoration" 属性,并且包含 underline 就立即返回,如果没有,返回 null334 if (command == "underline") {335 do {336 if (getComputedStyle(node).textDecoration.indexOf("underline") != -1) {337 return "underline";338 }339 node = node.parentNode;340 } while (node && node.nodeType == Node.ELEMENT_NODE);341 return null;342 }343 if (!("relevantCssProperty" in commands.get(command))) {344 throw "Bug: no relevantCssProperty for " + command + " in getEffectiveCommandValue";345 }346 // 返回相关的 CSS 属性的值347 return getComputedStyle(node)[commands.get(command).relevantCssProperty];348 }349 // 清除元素设定的样式350 function clearValue(element, command) {351 // 如果 element 不可编辑,返回 []352 if (!utils.isEditable(element)) {353 return [];354 }355 // 如果 element 是特殊的命令,并且验证结果为空,返回 []356 if (getSpecifiedCommandValue(element, command) === null) {357 return [];358 }359 // 是一个简单的可以被修改的 element360 if (utils.isSimpleModifiableElement(element)) {361 // 获得子节点362 let children = Array.prototype.slice.call(element.childNodes);363 // 对于 children 中的每个孩子,在 element 之前将 child 插入元素的父元素,立即保留范围。364 for (let i = 0; i < children.length; i++) {365 selection.movePreservingRanges(children[i], element.parentNode, utils.getNodeIndex(element));366 }367 element.parentNode.removeChild(element);368 return children;369 }370 // 如果命令是 "strikethrough" 删除其 style 属性中的样式371 if (command == "strikethrough"372 && element.style.textDecoration.indexOf("line-through") != -1) {373 if (element.style.textDecoration == "line-through") {374 element.style.textDecoration = "";375 } else {376 element.style.textDecoration = element.style.textDecoration.replace("line-through", "");377 }378 if (element.getAttribute("style") == "") {379 element.removeAttribute("style");380 }381 }382 // 如果是 undeline 删除其 style 等属性中的样式383 if (command == "underline"384 && element.style.textDecoration.indexOf("underline") != -1) {385 if (element.style.textDecoration == "underline") {386 element.style.textDecoration = "";387 } else {388 element.style.textDecoration = element.style.textDecoration.replace("underline", "");389 }390 if (element.getAttribute("style") == "") {391 element.removeAttribute("style");392 }393 }394 // 如果是其他的类似的 CSS 属性,直接移出 style 属性395 if (commands.get(command).relevantCssProperty !== null) {396 element.style[commands.get(command).relevantCssProperty] = '';397 if (element.getAttribute("style") == "") {398 element.removeAttribute("style");399 }400 }401 // 如果是 font 标签402 if (utils.isHtmlNamespace(element.namespaceURI) && element.tagName == "FONT") {403 // 如果设置了 foreColor 移出设定值404 if (command == "forecolor") {405 element.removeAttribute("color");406 }407 // 如果设置了 fontname 移出设定值408 if (command == "fontname") {409 element.removeAttribute("face");410 }411 // 如果设置了 fontSize 移出设定值412 if (command == "fontsize") {413 element.removeAttribute("size");414 }415 }416 // 如果是 a 标签,并且 command 是 "createLink" or "unlink", 取消 href 属性417 if (utils.isHtmlElement(element, "A")418 && (command == "createlink" || command == "unlink")) {419 element.removeAttribute("href");420 }421 // 再次校验特殊命令,并且验证结果为空,返回 []422 if (getSpecifiedCommandValue(element, command) === null) {423 return [];424 }425 // 返回由 span 包裹的节点426 return [selection.setTagName(element, "span")];427 }428 // 是否是两个相同的变量429 // 两个量都是命令的等效值,如果两个均为空430 // 或者都是字符串并且相等,并且命令没有定义任何 equivalentValues,431 // 或者两个都是字符串,并且命令定义了 equivalentValues 并且它们与定义匹配。432 function areEquivalentValues(command, val1, val2) {433 if (val1 === null && val2 === null) {434 return true;435 }436 if (typeof val1 == "string"437 && typeof val2 == "string"438 && val1 == val2439 && !("equivalentValues" in commands.get(command))) {440 return true;441 }442 if (typeof val1 == "string"443 && typeof val2 == "string"444 && "equivalentValues" in commands.get(command)445 && commands.get(command).equivalentValues(val1, val2)) {446 return true;447 }448 return false;449 }450 // 松散比较两个值451 function areLooselyEquivalentValues(command, val1, val2) {452 const sizeMap = new Map();453 if (areEquivalentValues(command, val1, val2)) {454 return true;455 }456 if (command != "fontsize"457 || typeof val1 != "string"458 || typeof val2 != "string") {459 return false;460 }461 let font = document.createElement("font");462 document.body.appendChild(font);463 ["x-small", "small", "medium", "large", "x-large", "xx-large", "xxx-large"].forEach(function(keyword) {464 font.size = utils.cssSizeToLegacy(keyword);465 sizeMap.set(keyword, getComputedStyle(font).fontSize)466 });467 document.body.removeChild(font);468 return val1 === sizeMap.get(val2)469 || val2 === sizeMap.get(val1);470 }471 // 强制设置值472 function forceValue(node, command, newValue) {473 // "If node's parent is null, abort this algorithm."474 // 如果节点的父级不是元素,则中止该算法。475 if (!node.parentNode) {476 return;477 }478 // "If new value is null, abort this algorithm."479 if (newValue === null) {480 return;481 }482 // "If node is an allowed child of "span":"483 if (utils.isAllowedChild(node, "span")) {484 // "Reorder modifiable descendants of node's previousSibling."485 reorderModifiableDescendants(node.previousSibling, command, newValue);486 // "Reorder modifiable descendants of node's nextSibling."487 reorderModifiableDescendants(node.nextSibling, command, newValue);488 // "Wrap the one-node list consisting of node, with sibling criteria489 // returning true for a simple modifiable element whose specified490 // command value is equivalent to new value and whose effective command491 // value is loosely equivalent to new value and false otherwise, and492 // with new parent instructions returning null."493 wrap([node],494 function(node) {495 return utils.isSimpleModifiableElement(node)496 && areEquivalentValues(command, getSpecifiedCommandValue(node, command), newValue)497 && areLooselyEquivalentValues(command, getEffectiveCommandValue(node, command), newValue);498 },499 function() { return null }500 );501 }502 // "If node is invisible, abort this algorithm."503 if (utils.isInvisible(node)) {504 return;505 }506 // "If the effective command value of command is loosely equivalent to new507 // value on node, abort this algorithm."508 if (areLooselyEquivalentValues(command, getEffectiveCommandValue(node, command), newValue)) {509 return;510 }511 // "If node is not an allowed child of "span":"512 if (!utils.isAllowedChild(node, "span")) {513 // "Let children be all children of node, omitting any that are514 // Elements whose specified command value for command is neither null515 // nor equivalent to new value."516 let children = [];517 for (let i = 0; i < node.childNodes.length; i++) {518 if (node.childNodes[i].nodeType == Node.ELEMENT_NODE) {519 let specifiedValue = getSpecifiedCommandValue(node.childNodes[i], command);520 if (specifiedValue !== null521 && !areEquivalentValues(command, newValue, specifiedValue)) {522 continue;523 }524 }525 children.push(node.childNodes[i]);526 }527 // "Force the value of each Node in children, with command and new528 // value as in this invocation of the algorithm."529 for (let i = 0; i < children.length; i++) {530 forceValue(children[i], command, newValue);531 }532 // "Abort this algorithm."533 return;534 }535 // "If the effective command value of command is loosely equivalent to new536 // value on node, abort this algorithm."537 if (areLooselyEquivalentValues(command, getEffectiveCommandValue(node, command), newValue)) {538 return;539 }540 // "Let new parent be null."541 let newParent = null;542 // "If the CSS styling flag is false:"543 if (!cssStylingFlag) {544 // "If command is "bold" and new value is "bold", let new parent be the545 // result of calling createElement("b") on the ownerDocument of node."546 if (command == "bold" && (newValue == "bold" || newValue == "700")) {547 newParent = node.ownerDocument.createElement("b");548 }549 // "If command is "italic" and new value is "italic", let new parent be550 // the result of calling createElement("i") on the ownerDocument of551 // node."552 if (command == "italic" && newValue == "italic") {553 newParent = node.ownerDocument.createElement("i");554 }555 // "If command is "strikethrough" and new value is "line-through", let556 // new parent be the result of calling createElement("s") on the557 // ownerDocument of node."558 if (command == "strikethrough" && newValue == "line-through") {559 newParent = node.ownerDocument.createElement("s");560 }561 // "If command is "underline" and new value is "underline", let new562 // parent be the result of calling createElement("u") on the563 // ownerDocument of node."564 if (command == "underline" && newValue == "underline") {565 newParent = node.ownerDocument.createElement("u");566 }567 // "If command is "foreColor", and new value is fully opaque with red,568 // green, and blue components in the range 0 to 255:"569 if (command == "forecolor" && utils.parseSimpleColor(newValue)) {570 // "Let new parent be the result of calling createElement("font")571 // on the ownerDocument of node."572 newParent = node.ownerDocument.createElement("font");573 // "Set the color attribute of new parent to the result of applying574 // the rules for serializing simple color values to new value575 // (interpreted as a simple color)."576 newParent.setAttribute("color", utils.parseSimpleColor(newValue));577 }578 // "If command is "fontName", let new parent be the result of calling579 // createElement("font") on the ownerDocument of node, then set the580 // face attribute of new parent to new value."581 if (command == "fontname") {582 newParent = node.ownerDocument.createElement("font");583 newParent.face = newValue;584 }585 }586 // "If command is "createLink" or "unlink":"587 if (command == "createlink" || command == "unlink") {588 // "Let new parent be the result of calling createElement("a") on the589 // ownerDocument of node."590 newParent = node.ownerDocument.createElement("a");591 // "Set the href attribute of new parent to new value."592 newParent.setAttribute("href", newValue);593 // "Let ancestor be node's parent."594 let ancestor = node.parentNode;595 // "While ancestor is not null:"596 while (ancestor) {597 // "If ancestor is an a, set the tag name of ancestor to "span",598 // and let ancestor be the result."599 if (utils.isHtmlElement(ancestor, "A")) {600 ancestor = selection.setTagName(ancestor, "span");601 }602 // "Set ancestor to its parent."603 ancestor = ancestor.parentNode;604 }605 }606 // "If command is "fontSize"; and new value is one of "x-small", "small",607 // "medium", "large", "x-large", "xx-large", or "xxx-large"; and either the608 // CSS styling flag is false, or new value is "xxx-large": let new parent609 // be the result of calling createElement("font") on the ownerDocument of610 // node, then set the size attribute of new parent to the number from the611 // following table based on new value: [table omitted]"612 if (command == "fontsize"613 && ["x-small", "small", "medium", "large", "x-large", "xx-large", "xxx-large"].indexOf(newValue) != -1614 && (!cssStylingFlag || newValue == "xxx-large")) {615 newParent = node.ownerDocument.createElement("font");616 newParent.size = utils.cssSizeToLegacy(newValue);617 }618 // "If command is "subscript" or "superscript" and new value is619 // "subscript", let new parent be the result of calling620 // createElement("sub") on the ownerDocument of node."621 if ((command == "subscript" || command == "superscript")622 && newValue == "subscript") {623 newParent = node.ownerDocument.createElement("sub");624 }625 // "If command is "subscript" or "superscript" and new value is626 // "superscript", let new parent be the result of calling627 // createElement("sup") on the ownerDocument of node."628 if ((command == "subscript" || command == "superscript")629 && newValue == "superscript") {630 newParent = node.ownerDocument.createElement("sup");631 }632 // "If new parent is null, let new parent be the result of calling633 // createElement("span") on the ownerDocument of node."634 if (!newParent) {635 newParent = node.ownerDocument.createElement("span");636 }637 // "Insert new parent in node's parent before node."638 node.parentNode.insertBefore(newParent, node);639 // "If the effective command value of command for new parent is not loosely640 // equivalent to new value, and the relevant CSS property for command is641 // not null, set that CSS property of new parent to new value (if the new642 // value would be valid)."643 let property = commands.get(command).relevantCssProperty;644 if (property !== null645 && !areLooselyEquivalentValues(command, getEffectiveCommandValue(newParent, command), newValue)) {646 newParent.style[property] = newValue;647 }648 // "If command is "strikethrough", and new value is "line-through", and the649 // effective command value of "strikethrough" for new parent is not650 // "line-through", set the "text-decoration" property of new parent to651 // "line-through"."652 if (command == "strikethrough"653 && newValue == "line-through"654 && getEffectiveCommandValue(newParent, "strikethrough") != "line-through") {655 newParent.style.textDecoration = "line-through";656 }657 // "If command is "underline", and new value is "underline", and the658 // effective command value of "underline" for new parent is not659 // "underline", set the "text-decoration" property of new parent to660 // "underline"."661 if (command == "underline"662 && newValue == "underline"663 && getEffectiveCommandValue(newParent, "underline") != "underline") {664 newParent.style.textDecoration = "underline";665 }666 // "Append node to new parent as its last child, preserving ranges."667 selection.movePreservingRanges(node, newParent, newParent.childNodes.length);668 // "If node is an Element and the effective command value of command for669 // node is not loosely equivalent to new value:"670 if (node.nodeType == Node.ELEMENT_NODE671 && !areEquivalentValues(command, getEffectiveCommandValue(node, command), newValue)) {672 // "Insert node into the parent of new parent before new parent,673 // preserving ranges."674 selection.movePreservingRanges(node, newParent.parentNode, utils.getNodeIndex(newParent));675 // "Remove new parent from its parent."676 newParent.parentNode.removeChild(newParent);677 // "Let children be all children of node, omitting any that are678 // Elements whose specified command value for command is neither null679 // nor equivalent to new value."680 let children = [];681 for (let i = 0; i < node.childNodes.length; i++) {682 if (node.childNodes[i].nodeType == Node.ELEMENT_NODE) {683 let specifiedValue = getSpecifiedCommandValue(node.childNodes[i], command);684 if (specifiedValue !== null685 && !areEquivalentValues(command, newValue, specifiedValue)) {686 continue;687 }688 }689 children.push(node.childNodes[i]);690 }691 // "Force the value of each Node in children, with command and new692 // value as in this invocation of the algorithm."693 for (let i = 0; i < children.length; i++) {694 forceValue(children[i], command, newValue);695 }696 }697 }698 // 重新排列可修改的后代699 function reorderModifiableDescendants(node, command, newValue) {700 // "Let candidate equal node."701 let candidate = node;702 // "While candidate is a modifiable element, and candidate has exactly one703 // child, and that child is also a modifiable element, and candidate is not704 // a simple modifiable element or candidate's specified command value for705 // command is not equivalent to new value, set candidate to its child."706 while (utils.isModifiableElement(candidate)707 && candidate.childNodes.length == 1708 && utils.isModifiableElement(candidate.firstChild)709 && (!utils.isSimpleModifiableElement(candidate)710 || !areEquivalentValues(command, getSpecifiedCommandValue(candidate, command), newValue))) {711 candidate = candidate.firstChild;712 }713 // "If candidate is node, or is not a simple modifiable element, or its714 // specified command value is not equivalent to new value, or its effective715 // command value is not loosely equivalent to new value, abort these716 // steps."717 if (candidate == node718 || !utils.isSimpleModifiableElement(candidate)719 || !areEquivalentValues(command, getSpecifiedCommandValue(candidate, command), newValue)720 || !areLooselyEquivalentValues(command, getEffectiveCommandValue(candidate, command), newValue)) {721 return;722 }723 // "While candidate has children, insert the first child of candidate into724 // candidate's parent immediately before candidate, preserving ranges."725 while (candidate.hasChildNodes()) {726 selection.movePreservingRanges(candidate.firstChild, candidate.parentNode, utils.getNodeIndex(candidate));727 }728 // "Insert candidate into node's parent immediately after node."729 node.parentNode.insertBefore(candidate, node.nextSibling);730 // "Append the node as the last child of candidate, preserving ranges."731 selection.movePreservingRanges(node, candidate, -1);732 }733 function wrap(nodeList, siblingCriteria, newParentInstructions) {734 // "If not provided, sibling criteria returns false and new parent735 // instructions returns null."736 //“如果未提供,则同级条件返回false和新的父级737 //指令传回null。”738 if (typeof siblingCriteria == "undefined") {739 siblingCriteria = function() { return false };740 }741 if (typeof newParentInstructions == "undefined") {742 newParentInstructions = function() { return null };743 }744 // "If every member of node list is invisible, and none is a br, return745 // null and abort these steps."746 if (nodeList.every(utils.isInvisible)747 && !nodeList.some(function(node) { return utils.isHtmlElement(node, "br") })) {748 return null;749 }750 // "If node list's first member's parent is null, return null and abort751 // these steps."752 if (!nodeList[0].parentNode) {753 return null;754 }755 // "If node list's last member is an inline node that's not a br, and node756 // list's last member's nextSibling is a br, append that br to node list."757 if (utils.isInlineNode(nodeList[nodeList.length - 1])758 && !utils.isHtmlElement(nodeList[nodeList.length - 1], "br")759 && utils.isHtmlElement(nodeList[nodeList.length - 1].nextSibling, "br")) {760 nodeList.push(nodeList[nodeList.length - 1].nextSibling);761 }762 // "While node list's first member's previousSibling is invisible, prepend763 // it to node list."764 while (utils.isInvisible(nodeList[0].previousSibling)) {765 nodeList.unshift(nodeList[0].previousSibling);766 }767 // "While node list's last member's nextSibling is invisible, append it to768 // node list."769 while (utils.isInvisible(nodeList[nodeList.length - 1].nextSibling)) {770 nodeList.push(nodeList[nodeList.length - 1].nextSibling);771 }772 // "If the previousSibling of the first member of node list is editable and773 // running sibling criteria on it returns true, let new parent be the774 // previousSibling of the first member of node list."775 let newParent;776 if (utils.isEditable(nodeList[0].previousSibling)777 && siblingCriteria(nodeList[0].previousSibling)) {778 newParent = nodeList[0].previousSibling;779 // "Otherwise, if the nextSibling of the last member of node list is780 // editable and running sibling criteria on it returns true, let new parent781 // be the nextSibling of the last member of node list."782 } else if (utils.isEditable(nodeList[nodeList.length - 1].nextSibling)783 && siblingCriteria(nodeList[nodeList.length - 1].nextSibling)) {784 newParent = nodeList[nodeList.length - 1].nextSibling;785 // "Otherwise, run new parent instructions, and let new parent be the786 // result."787 } else {788 newParent = newParentInstructions();789 }790 // "If new parent is null, abort these steps and return null."791 if (!newParent) {792 return null;793 }794 // "If new parent's parent is null:"795 if (!newParent.parentNode) {796 // "Insert new parent into the parent of the first member of node list797 // immediately before the first member of node list."798 nodeList[0].parentNode.insertBefore(newParent, nodeList[0]);799 // "If any range has a boundary point with node equal to the parent of800 // new parent and offset equal to the index of new parent, add one to801 // that boundary point's offset."802 //803 // Only try to fix the global range.804 if (selection.range.startContainer == newParent.parentNode805 && selection.range.startOffset == utils.getNodeIndex(newParent)) {806 selection.range.setStart(selection.range.startContainer, selection.range.startOffset + 1);807 }808 if (selection.range.endContainer == newParent.parentNode809 && selection.range.endOffset == utils.getNodeIndex(newParent)) {810 selection.range.setEnd(selection.range.endContainer, selection.range.endOffset + 1);811 }812 }813 // "Let original parent be the parent of the first member of node list."814 let originalParent = nodeList[0].parentNode;815 // "If new parent is before the first member of node list in tree order:"816 if (utils.isBefore(newParent, nodeList[0])) {817 // "If new parent is not an inline node, but the last visible child of818 // new parent and the first visible member of node list are both inline819 // nodes, and the last child of new parent is not a br, call820 // createElement("br") on the ownerDocument of new parent and append821 // the result as the last child of new parent."822 if (!utils.isInlineNode(newParent)823 && utils.isInlineNode([].filter.call(newParent.childNodes, utils.isVisible).slice(-1)[0])824 && utils.isInlineNode(nodeList.filter(utils.isVisible)[0])825 && !utils.isHtmlElement(newParent.lastChild, "BR")) {826 newParent.appendChild(newParent.ownerDocument.createElement("br"));827 }828 // "For each node in node list, append node as the last child of new829 // parent, preserving ranges."830 for (let i = 0; i < nodeList.length; i++) {831 selection.movePreservingRanges(nodeList[i], newParent, -1);832 }833 // "Otherwise:"834 } else {835 // "If new parent is not an inline node, but the first visible child of836 // new parent and the last visible member of node list are both inline837 // nodes, and the last member of node list is not a br, call838 // createElement("br") on the ownerDocument of new parent and insert839 // the result as the first child of new parent."840 if (!utils.isInlineNode(newParent)841 && utils.isInlineNode([].filter.call(newParent.childNodes, utils.isVisible)[0])842 && utils.isInlineNode(nodeList.filter(utils.isVisible).slice(-1)[0])843 && !utils.isHtmlElement(nodeList[nodeList.length - 1], "BR")) {844 newParent.insertBefore(newParent.ownerDocument.createElement("br"), newParent.firstChild);845 }846 // "For each node in node list, in reverse order, insert node as the847 // first child of new parent, preserving ranges."848 for (let i = nodeList.length - 1; i >= 0; i--) {849 selection.movePreservingRanges(nodeList[i], newParent, 0);850 }851 }852 // "If original parent is editable and has no children, remove it from its853 // parent."854 if (utils.isEditable(originalParent) && !originalParent.hasChildNodes()) {855 originalParent.parentNode.removeChild(originalParent);856 }857 // "If new parent's nextSibling is editable and running sibling criteria on858 // it returns true:"859 if (utils.isEditable(newParent.nextSibling)860 && siblingCriteria(newParent.nextSibling)) {861 // "If new parent is not an inline node, but new parent's last child862 // and new parent's nextSibling's first child are both inline nodes,863 // and new parent's last child is not a br, call createElement("br") on864 // the ownerDocument of new parent and append the result as the last865 // child of new parent."866 if (!utils.isInlineNode(newParent)867 && utils.isInlineNode(newParent.lastChild)868 && utils.isInlineNode(newParent.nextSibling.firstChild)869 && !utils.isHtmlElement(newParent.lastChild, "BR")) {870 newParent.appendChild(newParent.ownerDocument.createElement("br"));871 }872 // "While new parent's nextSibling has children, append its first child873 // as the last child of new parent, preserving ranges."874 while (newParent.nextSibling.hasChildNodes()) {875 selection.movePreservingRanges(newParent.nextSibling.firstChild, newParent, -1);876 }877 // "Remove new parent's nextSibling from its parent."878 newParent.parentNode.removeChild(newParent.nextSibling);879 }880 // "Remove extraneous line breaks from new parent."881 utils.removeExtraneousLineBreaksFrom(newParent);882 // "Return new parent."883 return newParent;884 }885 // 应用当前结果886 function pushDownValues(node, command, newValue) {887 // 如果节点的父级不是元素,则中止该算法。888 if (!node.parentNode889 || node.parentNode.nodeType != Node.ELEMENT_NODE) {890 return;891 }892 // 如果当前命令有效,并且和旧的元素上的值通过松散匹配相等,就不设置893 if (areLooselyEquivalentValues(command, getEffectiveCommandValue(node, command), newValue)) {894 return;895 }896 // 获得公共祖先897 let currentAncestor = node.parentNode;898 // 初始化 ancestor list 为空899 let ancestorList = [];900 // 递归找到最远的父节点,如果当前新的 command 不等于旧值,则将父节点加入到 ancestorList901 while (utils.isEditable(currentAncestor)902 && currentAncestor.nodeType == Node.ELEMENT_NODE903 && !areLooselyEquivalentValues(command, getEffectiveCommandValue(currentAncestor, command), newValue)) {904 ancestorList.push(currentAncestor);905 currentAncestor = currentAncestor.parentNode;906 }907 // 如果没有待更新至,返回908 if (!ancestorList.length) {909 return;910 }911 // 因为 dom 节点样式都是继承的。所以返回 ancestorList 最后一个元素即最远的祖先节点912 let propagatedValue = getSpecifiedCommandValue(ancestorList[ancestorList.length - 1], command);913 // 如果 propagatedValue 是 null 并且不等于新的值,就终止914 if (propagatedValue === null && propagatedValue != newValue) {915 return;916 }917 // 如果命令的值有效,并且公共的祖先节点松散匹配不等于新的结果,这时新的结果也不是空值,就终止918 if (newValue !== null919 && !areLooselyEquivalentValues(command, getEffectiveCommandValue(ancestorList[ancestorList.length - 1].parentNode, command), newValue)) {920 return;921 }922 // 清空 ancestorList 栈923 while (ancestorList.length) {924 let currentAncestor = ancestorList.pop();925 // 出栈过程中,如果某个节点含有指定的样式,就设置指定的传播值926 if (getSpecifiedCommandValue(currentAncestor, command) !== null) {927 propagatedValue = getSpecifiedCommandValue(currentAncestor, command);928 }929 let children = Array.prototype.slice.call(currentAncestor.childNodes);930 // 如果command的当前祖先的指定命令值不为空,则清除当前祖先的值。931 if (getSpecifiedCommandValue(currentAncestor, command) !== null) {932 clearValue(currentAncestor, command);933 }934 // 处理每个 children935 for (let i = 0; i < children.length; i++) {936 let child = children[i];937 // 如果 chide == node, 跳过当前处理938 if (child == node) {939 continue;940 }941 // 如果 child 是一个 Element,其 command 的指定命令值既不为空也不等同于 propagatedVale,则继续下一个 child。942 if (child.nodeType == Node.ELEMENT_NODE943 && getSpecifiedCommandValue(child, command) !== null944 && !areEquivalentValues(command, propagatedValue, getSpecifiedCommandValue(child, command))) {945 continue;946 }947 // 如果 child == ancestorList[ancestorList.length - 1],跳过948 if (child == ancestorList[ancestorList.length - 1]) {949 continue;950 }951 // 强制使用 child 的值,并且更新 新值等于传播的值。952 forceValue(child, command, propagatedValue);953 }954 }955 }956 function recordCurrentOverrides() {957 // 初始化overrides958 let overrides = [];...

Full Screen

Full Screen

d549ba877ef2abdd028ad56f175ed0eccb0425c1_1_24.js

Source:d549ba877ef2abdd028ad56f175ed0eccb0425c1_1_24.js Github

copy

Full Screen

...28 return;29 }30 // "Let propagated value be the specified command value of command on the31 // last member of ancestor list."32 var propagatedValue = getSpecifiedCommandValue(ancestorList[ancestorList.length - 1], command);33 // "If propagated value is null and is not equal to new value, abort this34 // algorithm."35 if (propagatedValue === null && propagatedValue != newValue) {36 return;37 }38 // "If the effective command value for the parent of the last member of39 // ancestor list is not loosely equivalent to new value, and new value is40 // not null, abort this algorithm."41 if (newValue !== null42 && !areLooselyEquivalentValues(command, getEffectiveCommandValue(ancestorList[ancestorList.length - 1].parentNode, command), newValue)) {43 return;44 }45 // "While ancestor list is not empty:"46 while (ancestorList.length) {47 // "Let current ancestor be the last member of ancestor list."48 // "Remove the last member from ancestor list."49 var currentAncestor = ancestorList.pop();50 // "If the specified command value of current ancestor for command is51 // not null, set propagated value to that value."52 if (getSpecifiedCommandValue(currentAncestor, command) !== null) {53 propagatedValue = getSpecifiedCommandValue(currentAncestor, command);54 }55 // "Let children be the children of current ancestor."56 var children = Array.prototype.slice.call(toArray(currentAncestor.childNodes));57 // "If the specified command value of current ancestor for command is58 // not null, clear the value of current ancestor."59 if (getSpecifiedCommandValue(currentAncestor, command) !== null) {60 clearValue(currentAncestor, command, range);61 }62 // "For every child in children:"63 for (var i = 0; i < children.length; i++) {64 var child = children[i];65 // "If child is node, continue with the next child."66 if (child == node) {67 continue;68 }69 // "If child is an Element whose specified command value for70 // command is neither null nor equivalent to propagated value,71 // continue with the next child."72 if (child.nodeType == Node.ELEMENT_NODE73 && getSpecifiedCommandValue(child, command) !== null74 && !areEquivalentValues(command, propagatedValue, getSpecifiedCommandValue(child, command))) {75 continue;76 }77 // "If child is the last member of ancestor list, continue with the78 // next child."79 if (child == ancestorList[ancestorList.length - 1]) {80 continue;81 }82 // "Force the value of child, with command as in this algorithm83 // and new value equal to propagated value."84 forceValue(child, command, propagatedValue, range);85 }86 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require('wptoolkit');2var command = process.argv[2];3var value = wptoolkit.getSpecifiedCommandValue(command);4var wptoolkit = require('wptoolkit');5var command = process.argv[2];6var value = wptoolkit.getSpecifiedCommandValue(command);7var wptoolkit = require('wptoolkit');8var command = process.argv[2];9var value = wptoolkit.getSpecifiedCommandValue(command);10var wptoolkit = require('wptoolkit');11var command = process.argv[2];12var value = wptoolkit.getSpecifiedCommandValue(command);13var wptoolkit = require('wptoolkit');14var command = process.argv[2];15var value = wptoolkit.getSpecifiedCommandValue(command);16var wptoolkit = require('wptoolkit');17var command = process.argv[2];18var value = wptoolkit.getSpecifiedCommandValue(command);19var wptoolkit = require('wptoolkit');20var command = process.argv[2];21var value = wptoolkit.getSpecifiedCommandValue(command);22var wptoolkit = require('wptoolkit');23var command = process.argv[2];24var value = wptoolkit.getSpecifiedCommandValue(command);25var wptoolkit = require('wptoolkit');26var command = process.argv[2];27var value = wptoolkit.getSpecifiedCommandValue(command);28var wptoolkit = require('wptoolkit');29var command = process.argv[2];30var value = wptoolkit.getSpecifiedCommandValue(command);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2wpt.getSpecifiedCommandValue('test.js', 'wpt', 'getSpecifiedCommandValue', function (err, data) {3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var wpt = require('wpt');10wpt.getSpecifiedCommandValue('test.js', 'wpt', 'getSpecifiedCommandValue', function (err, data) {11 if (err) {12 console.log(err);13 } else {14 console.log(data);15 }16});17var wpt = require('wpt');18wpt.getSpecifiedCommandValue('test.js', 'wpt', 'getSpecifiedCommandValue', function (err, data) {19 if (err) {20 console.log(err);21 } else {22 console.log(data);23 }24});25var wpt = require('wpt');26wpt.getSpecifiedCommandValue('test.js', 'wpt', 'getSpecifiedCommandValue', function (err, data) {27 if (err) {28 console.log(err);29 } else {30 console.log(data);31 }32});33var wpt = require('wpt');34wpt.getSpecifiedCommandValue('test.js', 'wpt', 'getSpecifiedCommandValue', function (err, data) {35 if (err) {36 console.log(err);37 } else {38 console.log(data);39 }40});41var wpt = require('wpt');42wpt.getSpecifiedCommandValue('test.js', 'wpt', 'getSpecifiedCommandValue', function (err, data) {43 if (err) {44 console.log(err);45 } else {46 console.log(data);47 }48});49var wpt = require('wpt');50wpt.getSpecifiedCommandValue('test.js', 'wpt', 'getSpecifiedCommandValue', function (err, data) {51 if (err) {52 console.log(err

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require('wptoolkit');2var specifiedCommandValue = wptoolkit.getSpecifiedCommandValue('test');3console.log(specifiedCommandValue);4{5 "scripts": {6 },7 "dependencies": {8 }9}10var wptoolkit = require('wptoolkit');11var specifiedCommand = wptoolkit.getSpecifiedCommand();12console.log(specifiedCommand);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require("wptoolkit");2var path = require("path");3var commandLineArgument = "myArgument";4var commandLineArgumentValue = wptoolkit.getSpecifiedCommandValue(commandLineArgument);5console.log("The value of the command line argument " + commandLineArgument + " is " + commandLineArgumentValue);6var commandLineArgument = "myArgument";7var commandLineArgumentValue = wptoolkit.getSpecifiedCommandValue(commandLineArgument);8console.log("The value of the command line argument " + commandLineArgument + " is " + commandLineArgumentValue);9var commandLineArgument = "myArgument";10var commandLineArgumentValue = wptoolkit.getSpecifiedCommandValue(commandLineArgument);11console.log("The value of the command line argument " + commandLineArgument + " is " + commandLineArgumentValue);12var commandLineArgument = "myArgument";13var commandLineArgumentValue = wptoolkit.getSpecifiedCommandValue(commandLineArgument);14console.log("The value of the command line argument " + commandLineArgument + " is " + commandLineArgumentValue);15var commandLineArgument = "myArgument";16var commandLineArgumentValue = wptoolkit.getSpecifiedCommandValue(commandLineArgument);17console.log("The value of the command line argument " + commandLineArgument + " is " + commandLineArgumentValue);18var commandLineArgument = "myArgument";19var commandLineArgumentValue = wptoolkit.getSpecifiedCommandValue(commandLineArgument);20console.log("The value of the command line argument " + commandLineArgument + " is " + commandLineArgumentValue);21var commandLineArgument = "myArgument";22var commandLineArgumentValue = wptoolkit.getSpecifiedCommandValue(commandLineArgument);23console.log("The value of the command line argument " + commandLineArgument + " is " + commandLineArgumentValue);24var commandLineArgument = "myArgument";25var commandLineArgumentValue = wptoolkit.getSpecifiedCommandValue(commandLineArgument);26console.log("The value of the command line argument " + commandLineArgument + " is " + commandLineArgumentValue);27var commandLineArgument = "myArgument";28var commandLineArgumentValue = wptoolkit.getSpecifiedCommandValue(commandLineArgument);29console.log("The

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