Added the condition to removeItems, that the to be removedItem be direct child of the menus HTML element.
Change-Id: Ife934e340ab30ed5d497a40659e6a48f8d3922ff
diff --git a/Changes b/Changes
index 6a3ed5a..c2c6e60 100755
--- a/Changes
+++ b/Changes
@@ -6,11 +6,16 @@
response.
- Added utility funcition to menu that gets all direct
childNodes by a tag. Used in menu-style specs. (lerepp)
+<<<<<<< HEAD
- Remove 'X-Frame-Options' in favor of 'frame-ancestors'
as a CSP rule.
- Fix CSS compression for new SASS compiler.
- Support dynamic menu extensions.
- Dynamically extend buttongroup menus.
+=======
+ - Update to menu.js's removeItems function to only delete
+ direct childNodes aswell as a specification to test for it (lerepp)
+>>>>>>> Added the condition to removeItems, that the to be removedItem be direct child of the menus HTML element.
0.42 2021-06-18
- Added GitHub based CI for perl.
diff --git a/dev/js/spec/menuSpec.js b/dev/js/spec/menuSpec.js
index e1c6fc8..883a71d 100644
--- a/dev/js/spec/menuSpec.js
+++ b/dev/js/spec/menuSpec.js
@@ -410,6 +410,21 @@
menu = KorAP.HintMenu.create("cnx/", list);
expect(menu.element().menu).toEqual(menu);
});
+
+ it('should only remove direct descendants with removeItems', function () {
+ var menu = KorAP.HintMenu.create("cnx/", list);
+ var newUL = document.createElement("ul");
+ var newLI = document.createElement("li");
+ newUL.appendChild(newLI);
+ //This is a very constructed example, but this actually happens within containerMenu
+ menu.element().appendChild(newUL);
+ expect(menu.element().childNodes[3].nodeName).toEqual("UL");
+ expect(menu.element().childNodes[3].childNodes[0]).toEqual(newLI);
+ menu.prefix("a"); //to call show
+ expect(menu.element().childNodes[3].nodeName).toEqual("UL");
+ expect(menu.element().childNodes[3].childNodes[0]).toEqual(newLI);
+
+ });
it('should be visible', function () {
diff --git a/dev/js/src/menu.js b/dev/js/src/menu.js
index 6aff7fa..4e93390 100644
--- a/dev/js/src/menu.js
+++ b/dev/js/src/menu.js
@@ -637,10 +637,12 @@
* Delete all visible items from the menu element
*/
- removeItems : function () {
+ removeItems : function () {
const liElements=this._el.getElementsByTagName("LI");
- while (liElements.length>0){
- this._el.removeChild(liElements[0]);
+ for (let ii = liElements.length-1; ii >= 0; ii-- ) {
+ if (liElements[ii].parentNode === this._el){
+ this._el.removeChild(liElements[ii]);
+ };
};
},