Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

corrected code #7351

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 48 additions & 51 deletions scripts/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,37 @@ const menu = {
'Home': {
'text': 'Contribute here',
'href': 'https://github.com/fineanmol/Hacktoberfest2022/blob/master/contributors/contributorsList.js#L1934'
},'hacktoberfest1':{
'text':'HacktoberFest Project 1',
'href':'https://github.com/fineanmol/Annoying-submit-button'

},'hacktoberfest2':{
'text':'HacktoberFest Project 2',
'href':'https://github.com/fineanmol/hacktoberfest'

},
//'Others': {
},
'Hacktoberfest1': {
'text': 'HacktoberFest Project 1',
'href': 'https://github.com/fineanmol/Annoying-submit-button'
},
'Hacktoberfest2': {
'text': 'HacktoberFest Project 2',
'href': 'https://github.com/fineanmol/hacktoberfest'
},
'Social': {
'Instagram': {
'text': 'Instagram Connect',
'href': 'https://instagram.com/fineanmol'
},
'Instagram': {
'text': 'Connect on <i class="fa fa-instagram" style="font-size:22px"></i>',
'text': 'Connect on <i class="fa fa-instagram" style="font-size:22px;"></i>',
'href': 'https://instagram.com/fineanmol'
},
'Facebook': {
'text': '<i class="fa fa-facebook" style="font-size:20px"></i>acebook',
'text': '<i class="fa fa-facebook" style="font-size:20px;"></i> Facebook',
'href': 'https://www.facebook.com/fineanmol',
'id': 'facebook'
},
'Linkedin': {
'text': 'Linked<i class="fa fa-linkedin" style="font-size:20px"></i>',
'text': 'Linked<i class="fa fa-linkedin" style="font-size:20px;"></i>',
'href': 'https://www.linkedin.com/in/fineanmol/',
'id': 'linkedin'
},
'NDC': {
'text': '<i class="fa fa-twitter" style="font-size:20px"></i>Twitter',
'Twitter': {
'text': '<i class="fa fa-twitter" style="font-size:20px;"></i> Twitter',
'href': 'https://twitter.com/fineanmol',
'id': 'tools'
},
}
},
'Github': {
'Stars': {
'text': '<a class="github-button" href="https://github.com/fineanmol/Hacktoberfest2022" data-icon="octicon-star" data-show-count="true" aria-label="Star fineanmol/Hacktoberfest2022 on GitHub">Stars</a>',
'href': 'https://github.com/fineanmol/Hacktoberfest2022',
Expand All @@ -45,45 +43,44 @@ const menu = {
'href': 'https://github.com/fineanmol/Hacktoberfest2022',
'id': 'tools'
}

}
};

}
function buildMenuHTML(obj = {}) {
let html = '';

function buildMenuHTML (obj = {}) {
let html = ''
let path = window.location.pathname.split('/')
let currentPage = path[path.length - 1] === '' ? '/' : path[path.length - 1]
// Handle both trailing and non-trailing slash in current path (consistently remove trailing slash)
const path = window.location.pathname.replace(/\/$/, ''); // Remove trailing slash
const currentPage = path.split('/').pop();

Object.entries(obj).forEach(([key, item]) => {
if (key == 'Others') {
html += '<li class="dropdown">'
html += '<a class="nav-link nested-dropdown" href="#" id="Others"> Others </a>'
html += '<div class="dropdown-content">'
Object.entries(item).forEach(([key, item]) => {
let isCurrent = (currentPage === item.href)

html += '<div class="nav-item' + (isCurrent ? ' active' : '') + '">'
html += '<a target="_blank" class="nav-link" href="' + item.href + '"' + (item.id ? ' id="' + item.id + '"' : '') + '>' + item.text + '</a>'
html += '</div>'
})
html += '</div>'
} else {
if (currentPage.indexOf('.html') == -1) {
currentPage = currentPage.concat('.html')
}
if (key === 'Social' || key === 'Github') { // Handle grouped menu items
html += '<li class="dropdown">';
html += `<a class="nav-link nested-dropdown" href="#" id="${key}">${key}</a>`;
html += '<div class="dropdown-content">';

let isCurrent = (currentPage === item.href)
Object.entries(item).forEach(([subKey, subItem]) => {
let isCurrent = currentPage === subItem.href;
html += '<div class="nav-item' + (isCurrent ? ' active' : '') + '">';
html += '<a target="_blank" class="nav-link" href="' + subItem.href + '"' + (subItem.id ? ' id="' + subItem.id + '"' : '') + '>' + subItem.text + '</a>';
html += '</div>';
});

html += '<li class="nav-item' + (isCurrent ? ' active' : '') + '">'
html += '<a target="_blank" class="nav-link" href="' + item.href + '"' + (item.id ? ' id="' + item.id + '"' : '') + '>' + item.text + '</a>'
html += '</li>'
html += '</div>'; // Close dropdown-content
html += '</li>'; // Close dropdown
} else {
let isCurrent = currentPage === item.href;
html += '<li class="nav-item' + (isCurrent ? ' active' : '') + '">';
html += '<a target="_blank" class="nav-link" href="' + item.href + '"' + (item.id ? ' id="' + item.id + '"' : '') + '>' + item.text + '</a>';
html += '</li>';
}
})
document.getElementById('menu').innerHTML = html
});

document.getElementById('menu').innerHTML = html;
}

function buildMenu () {
buildMenuHTML(menu)
function buildMenu() {
buildMenuHTML(menu);
}

buildMenu()
buildMenu();
Loading