Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • 1.31
  • master
  • 1.10.0
  • 1.30.1
  • 1.31.0
  • 1.8.0
  • 1.9.0
  • 3.100.0
  • 3.100.1
  • 3.100.10
  • 3.100.11
  • 3.100.12
  • 3.100.13
  • 3.100.14
  • 3.100.15
  • 3.100.16
  • 3.100.17
  • 3.100.18
  • 3.100.19
  • 3.100.2
  • 3.100.20
  • 3.100.3
  • 3.100.4
  • 3.100.5
  • 3.100.6
  • 3.100.7
  • 3.100.8
  • 3.100.9
  • 3.101.0
  • 3.101.1
  • 3.101.2
  • 3.101.3
  • 3.102.0
  • 3.102.1
  • 3.102.2
  • 3.102.3
  • 3.102.4
  • 3.102.5
  • 3.102.6
  • 3.103.0
  • 3.103.1
  • 3.104.0
  • 3.104.1
  • 3.105.0
  • 3.105.1
  • 3.105.2
  • 3.106.0
  • 3.106.1
  • 3.107.0
  • 3.108.0
  • 3.108.1
  • 3.108.2
  • 3.108.3
  • 3.108.4
  • 3.108.5
  • 3.109.0
  • 3.110.0
  • 3.110.1
  • 3.110.2
  • 3.110.3
  • 3.110.4
  • 3.111.0
  • 3.112.0
  • 3.112.1
  • 3.112.2
  • 3.112.3
  • 3.112.4
  • 3.113.0
  • 3.114.0
  • 3.114.1
  • 3.114.2
  • 3.114.3
  • 3.114.4
  • 3.114.5
  • 3.114.6
  • 3.114.7
  • 3.115.0
  • 3.115.1
  • 3.115.2
  • 3.115.3
  • 3.115.4
  • 3.116.0
  • 3.116.1
  • 3.117.0
  • 3.117.1
  • 3.117.2
  • 3.117.3
  • 3.118.0
  • 3.118.1
  • 3.119.0
  • 3.120.0
  • 3.121.0
  • 3.51.5
  • 3.52.0
  • 3.52.1
  • 3.53.0
  • 3.54.0
  • 3.55.0
  • 3.55.1
  • 3.55.2
  • 3.55.3
  • 3.55.4
102 results

Target

Select target project
  • oss/libraries/javascript/monster
1 result
Select Git revision
  • 1.31
  • master
  • 1.10.0
  • 1.30.1
  • 1.31.0
  • 1.8.0
  • 1.9.0
  • 3.100.0
  • 3.100.1
  • 3.100.10
  • 3.100.11
  • 3.100.12
  • 3.100.13
  • 3.100.14
  • 3.100.15
  • 3.100.16
  • 3.100.17
  • 3.100.18
  • 3.100.19
  • 3.100.2
  • 3.100.20
  • 3.100.3
  • 3.100.4
  • 3.100.5
  • 3.100.6
  • 3.100.7
  • 3.100.8
  • 3.100.9
  • 3.101.0
  • 3.101.1
  • 3.101.2
  • 3.101.3
  • 3.102.0
  • 3.102.1
  • 3.102.2
  • 3.102.3
  • 3.102.4
  • 3.102.5
  • 3.102.6
  • 3.103.0
  • 3.103.1
  • 3.104.0
  • 3.104.1
  • 3.105.0
  • 3.105.1
  • 3.105.2
  • 3.106.0
  • 3.106.1
  • 3.107.0
  • 3.108.0
  • 3.108.1
  • 3.108.2
  • 3.108.3
  • 3.108.4
  • 3.108.5
  • 3.109.0
  • 3.110.0
  • 3.110.1
  • 3.110.2
  • 3.110.3
  • 3.110.4
  • 3.111.0
  • 3.112.0
  • 3.112.1
  • 3.112.2
  • 3.112.3
  • 3.112.4
  • 3.113.0
  • 3.114.0
  • 3.114.1
  • 3.114.2
  • 3.114.3
  • 3.114.4
  • 3.114.5
  • 3.114.6
  • 3.114.7
  • 3.115.0
  • 3.115.1
  • 3.115.2
  • 3.115.3
  • 3.115.4
  • 3.116.0
  • 3.116.1
  • 3.117.0
  • 3.117.1
  • 3.117.2
  • 3.117.3
  • 3.118.0
  • 3.118.1
  • 3.119.0
  • 3.120.0
  • 3.121.0
  • 3.51.5
  • 3.52.0
  • 3.52.1
  • 3.53.0
  • 3.54.0
  • 3.55.0
  • 3.55.1
  • 3.55.2
  • 3.55.3
  • 3.55.4
102 results
Show changes
Commits on Source (4)
<a name="v3.36.0"></a>
## [v3.36.0] - 2023-04-01
### Add Features
- new function getContainingDocument
<a name="v3.35.4"></a>
## [v3.35.4] - 2023-03-28
### Bug Fixes
......@@ -518,6 +524,7 @@
<a name="1.8.0"></a>
## 1.8.0 - 2021-08-15
[v3.36.0]: https://gitlab.schukai.com/oss/libraries/javascript/monster/compare/v3.35.4...v3.36.0
[v3.35.4]: https://gitlab.schukai.com/oss/libraries/javascript/monster/compare/v3.35.3...v3.35.4
[v3.35.3]: https://gitlab.schukai.com/oss/libraries/javascript/monster/compare/v3.35.2...v3.35.3
[v3.35.2]: https://gitlab.schukai.com/oss/libraries/javascript/monster/compare/v3.35.1...v3.35.2
......
{
"name": "@schukai/monster",
"version": "3.35.3",
"version": "3.35.4",
"description": "Monster is a simple library for creating fast, robust and lightweight websites.",
"keywords": [
"framework",
......
lockfileVersion: '6.0'
......@@ -8,7 +8,7 @@
import { getGlobal } from "../types/global.mjs";
import { validateString } from "../types/validate.mjs";
export { getDocument, getWindow, getDocumentFragmentFromString, findElementWithIdUpwards };
export { getDocument, getWindow, getDocumentFragmentFromString, findElementWithIdUpwards,getContainingDocument };
/**
* This method fetches the document object
......@@ -199,3 +199,48 @@ function findElementWithIdUpwards(element, targetId) {
// Otherwise, search the current element's parent
return findElementWithIdUpwards(element.parentElement, targetId);
}
/**
* @private
* @param {HTMLElement} element
* @returns {HTMLElement|null}
*/
function traverseShadowRoots(element) {
let currentRoot = element.shadowRoot;
let currentParent = element.parentNode;
while (currentParent && currentParent.nodeType !== Node.DOCUMENT_NODE && currentParent.nodeType !== Node.DOCUMENT_FRAGMENT_NODE) {
if (currentRoot && currentRoot.parentNode) {
currentParent = currentRoot.parentNode;
currentRoot = currentParent.shadowRoot;
} else if (currentParent.parentNode) {
currentParent = currentParent.parentNode;
currentRoot = null;
} else if (currentRoot && currentRoot.host && currentRoot.host.nodeType === Node.DOCUMENT_NODE) {
currentParent = currentRoot.host;
currentRoot = null;
} else {
currentParent = null;
currentRoot = null;
}
}
return currentParent;
}
/**
* Recursively searches upwards from a given element to find an ancestor element
*
* @param {HTMLElement} element
* @returns {*}
* @throws {Error} Invalid argument. Expected an HTMLElement.
* @memberOf Monster.DOM
* @since 3.36.0
*/
function getContainingDocument(element) {
if (!element || !(element instanceof HTMLElement || element instanceof element.ownerDocument.defaultView.HTMLElement)) {
throw new Error('Invalid argument. Expected an HTMLElement.');
}
return traverseShadowRoots(element) || null;
}
......@@ -142,7 +142,7 @@ function getMonsterVersion() {
}
/** don't touch, replaced by make with package.json version */
monsterVersion = new Version("3.35.3");
monsterVersion = new Version("3.35.4");
return monsterVersion;
}
{
"name": "monster",
"version": "3.35.3",
"version": "3.35.4",
"description": "monster",
"repository": {
"type": "git",
......
This diff is collapsed.
......@@ -2,6 +2,7 @@ import {
getDocument, getWindow, getDocumentFragmentFromString
} from "../../../../application/source/dom/util.mjs";
import {getContainingDocument} from "../../../../application/source/dom/util.mjs";
import {initJSDOM} from "../../util/jsdom.mjs";
......@@ -52,4 +53,63 @@ describe('DOM', function () {
});
});
describe('getContainingDocument', () => {
let jsDomDocument;
beforeEach(() => {
jsDomDocument = getDocument();
});
//
// afterEach(() => {
// dom.window.close();
// });
it('should throw an error when called with an invalid argument', () => {
expect(() => getContainingDocument(null)).to.throw('Invalid argument. Expected an HTMLElement.');
});
it('should return the correct containing document for an element in the main document', () => {
const element = jsDomDocument.createElement('div');
const containingDocument = getContainingDocument(element);
expect(containingDocument).to.null;
});
it('should return the correct containing document for an element inside a shadow root', () => {
const host = jsDomDocument.createElement('div');
const shadowRoot = host.attachShadow({ mode: 'open' });
const element = jsDomDocument.createElement('span');
shadowRoot.appendChild(element);
const containingDocument = getContainingDocument(element);
expect(containingDocument).to.not.null;
});
it('should return the correct containing document for an element inside a nested shadow root', () => {
const outerHost = jsDomDocument.createElement('div');
const outerShadowRoot = outerHost.attachShadow({ mode: 'open' });
const innerHost = jsDomDocument.createElement('div');
outerShadowRoot.appendChild(innerHost);
const innerShadowRoot = innerHost.attachShadow({ mode: 'open' });
const element = jsDomDocument.createElement('span');
innerShadowRoot.appendChild(element);
const containingDocument = getContainingDocument(element);
expect(containingDocument).to.not.null;
});
it('should return null when the element is not attached to any document', () => {
const detachedElement = jsDomDocument.createElement('div');
detachedElement.remove();
const containingDocument = getContainingDocument(detachedElement);
expect(containingDocument).to.be.null;
});
});
});
\ No newline at end of file
......@@ -7,7 +7,7 @@ describe('Monster', function () {
let monsterVersion
/** don´t touch, replaced by make with package.json version */
monsterVersion = new Version("3.35.3")
monsterVersion = new Version("3.35.4")
let m = getMonsterVersion();
......
......@@ -14,8 +14,8 @@
</head>
<body>
<div id="headline" style="display: flex;align-items: center;justify-content: center;flex-direction: column;">
<h1 style='margin-bottom: 0.1em;'>Monster 3.33.0</h1>
<div id="lastupdate" style='font-size:0.7em'>last update Mo 27. Mär 18:10:51 CEST 2023</div>
<h1 style='margin-bottom: 0.1em;'>Monster 3.35.4</h1>
<div id="lastupdate" style='font-size:0.7em'>last update Sa 1. Apr 17:29:43 CEST 2023</div>
</div>
<div id="mocks"></div>
<div id="mocha"></div>
......
This diff is collapsed.
{"version":"3.35.4"}
{"version":"3.36.0"}