Skip to content
This repository has been archived by the owner on Oct 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #30 from minlare/magento1
Browse files Browse the repository at this point in the history
missing parent/child rendering fix
  • Loading branch information
davidwindell authored Nov 15, 2019
2 parents aed153d + e409fc9 commit 9f9f23e
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions skin/adminhtml/default/default/edge/menu/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ document.observe('dom:loaded', function(){
});
$('span[data-tab="' + activeTab + '"]').trigger('click');

function createMenuItem(data){
function createMenuItem(data, child){
var existingItem = menu.find('[data-id="' + data.id + '"]');
if (existingItem.length) {
return;
}

$('.first-item').remove();
var title = $('<span>', {class: 'title'}).html(data.title);
var item = $('<li>', {
Expand All @@ -35,8 +40,10 @@ document.observe('dom:loaded', function(){
)
.append($('<span>', {'data-drop': 'after'}));

if(data.image)
if(data.image) {
title.prepend($('<img>', {src: '/media/' + data.image}));
}


if(data.before) {
menu.find('[data-id="' + data.before + '"]').before(item);
Expand All @@ -45,8 +52,28 @@ document.observe('dom:loaded', function(){
menu.find('[data-id="' + data.after + '"]').after(item);
}
else {
var parent = data.parent ? menu.find('[data-id="' + data.parent + '"]') : menu;
parent.append(item);
var itemParent = data.parent ? menu.find('[data-id="' + data.parent + '"]') : menu;

// parent was not found but it might be in the list just not rendered yet
if (data.parent && !itemParent.length) {
// look for parent
for (var i = 0; i < items.length; i++) {
if (items[i].id === data.parent) {
// check item is not a child of itself
if (items[i].id !== items[i].parent) {
// check we dont have a closed loop
if (child && child.id === data.parent) {
break;
}
createMenuItem(items[i], data);
itemParent = menu.find('[data-id="' + data.parent + '"]');
break;
}
}
}
}

itemParent.append(item);
}
}

Expand Down Expand Up @@ -298,4 +325,4 @@ document.observe('dom:loaded', function(){
});

})(jQuery);
});
});

0 comments on commit 9f9f23e

Please sign in to comment.