|
410 | 410 | do {
|
411 | 411 | if (!node || !node.tagName) return false;
|
412 | 412 | let pathSplit = node.tagName.toLowerCase();
|
413 |
| - // if (node.tagName == "DOM-PARSER" || node.hasAttribute('contenteditable')){ |
414 |
| - // pathSplit = "[contenteditable]"; |
415 |
| - // node = ''; |
416 |
| - // } |
| 413 | + |
417 | 414 | if (node.id) {
|
418 | 415 | pathSplit += "#" + node.id;
|
419 | 416 | node = '';
|
420 |
| - } |
421 |
| - else { |
422 |
| - // let eid = node.getAttribute('eid'); |
423 |
| - // if (/{{\s*([\w\W]+)\s*}}/g.test(eid)) { |
424 |
| - // eid = false; |
425 |
| - // } |
426 |
| - // if (eid) { |
427 |
| - // pathSplit += `[eid="${eid}"]`; |
428 |
| - // node = ''; |
429 |
| - // } |
430 |
| - // else { |
431 |
| - // if (node.classList.length) { |
432 |
| - // node.classList.forEach((item) => { |
433 |
| - // if (item.indexOf(":") === -1) pathSplit += "." + item; |
434 |
| - // }); |
435 |
| - // } |
436 |
| - |
437 |
| - if (node.parentNode && node.parentNode.children.length > 1) { |
438 |
| - // TODO: improve array logic so ignores javascript generated html?? |
439 |
| - let children = [] |
440 |
| - for (let child of node.parentNode.children) { |
441 |
| - // if (!child.matches('.mirror')) |
442 |
| - // children.push(child); |
443 |
| - if (child.tagName == node.tagName) |
444 |
| - children.push(child); |
| 417 | + } else { |
| 418 | + let eid = node.getAttribute('eid'); |
| 419 | + if (eid && !(/{{\s*([\w\W]+)\s*}}/g.test(eid))) { |
| 420 | + pathSplit += `[eid="${eid}"]`; |
| 421 | + node = ''; |
| 422 | + } else |
| 423 | + // if (node.classList.length) { |
| 424 | + // node.classList.forEach((item) => { |
| 425 | + // if (item.indexOf(":") === -1) pathSplit += "." + item; |
| 426 | + // }); |
| 427 | + // } |
| 428 | + |
| 429 | + if (node.parentNode && node.parentNode.children.length > 1) { |
| 430 | + // TODO: improve array logic so ignores javascript generated html?? |
| 431 | + let children = [] |
| 432 | + for (let child of node.parentNode.children) { |
| 433 | + if (child.tagName == node.tagName) |
| 434 | + children.push(child); |
| 435 | + } |
| 436 | + let index = Array.prototype.indexOf.call( |
| 437 | + children, |
| 438 | + node |
| 439 | + ); |
| 440 | + |
| 441 | + pathSplit += `:nth-of-type(${index + 1})`; |
445 | 442 | }
|
446 |
| - let index = Array.prototype.indexOf.call( |
447 |
| - children, |
448 |
| - node |
449 |
| - ); |
450 |
| - // if (children.length > 1) |
451 |
| - // pathSplit += `:nth-child(${index + 1})`; |
452 |
| - pathSplit += `:nth-of-type(${index + 1})`; |
453 |
| - } |
454 | 443 |
|
455 |
| - // pathSplits.unshift(pathSplit); |
456 | 444 | node = node.parentNode;
|
457 |
| - if (node == null || node.tagName == "HTML" || node.tagName == "DOM-PARSER" || node.nodeName == "#document" || node.hasAttribute('contenteditable')) |
| 445 | + if (node == null || node.tagName == "HTML" || node.tagName == "BODY" || node.tagName == "DOM-PARSER" || node.nodeName == "#document" || node.hasAttribute('contenteditable')) |
458 | 446 | node = '';
|
459 | 447 | }
|
460 |
| - // } |
| 448 | + |
461 | 449 | pathSplits.unshift(pathSplit);
|
462 | 450 | } while (node);
|
463 | 451 | let path = pathSplits.join(" > ")
|
|
0 commit comments