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

[UI] Fix Navbar not closing on click getting started in mobile view #1889

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
12 changes: 11 additions & 1 deletion _includes/navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,14 @@
</ul>

</div>
</nav>
</nav>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move the js script to javascript file not in html file.Keep things seaparate

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hymmns thoughts on this feedback? Will you be incorporating?

We don't need javascript to accomplish this. We can keep this behavior within CSS.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least with respect to the function in this file, we can do it within CSS.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @sudhanshutech and @leecalcote.
Does the changes address your comments.
Please let me know if you have any further requests

<script>
function onClickGettingStarted(){
const stellarNav = document.querySelector(".stellarnav");
const navList = document.querySelector(".nav-list");

if (stellarNav.classList.contains("mobile")) {
navList.style.display = "none";
}
}
</script>
75 changes: 48 additions & 27 deletions js/stellarnav.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,33 +169,7 @@
}

// opens and closes menu
$('.menu-toggle, .stellarnav-open').on('click', function(e) {
e.preventDefault();

// if nav position is left or right, uses fadeToggle instead of slideToggle
if (settings.position == 'left' || settings.position == 'right') {
nav.find('ul:first').stop(true, true).fadeToggle(settings.openingSpeed);
nav.toggleClass('active');

if(nav.hasClass('active') && nav.hasClass('mobile')) {
// closes the menu when clicked outside of it
$(document).on('click', function(event) {
// ensures menu hides only on mobile nav
if(nav.hasClass('mobile')) {
if (!$(event.target).closest(nav).length) {
nav.find('ul:first').stop(true, true).fadeOut(settings.openingSpeed);
nav.removeClass('active');
}
}
});
}

} else {
// static position - normal open and close animation
nav.find('ul:first').stop(true, true).slideToggle(settings.openingSpeed);
nav.toggleClass('active');
}
});
$('.menu-toggle, .stellarnav-open').on('click', toggleMenu);

// activates the close button
$('.close-menu, .stellarnav-close').on('click', function() {
Expand Down Expand Up @@ -224,6 +198,25 @@
// expands the dropdown menu on each click of nav-text
nav.find('li .sub-list').on('click', navbarExpand);

nav.find('li.nav-item').not('.has-sub').on('click', (e) => {
if (nav.hasClass('mobile')){
toggleMenu(e);
}
var href = $(e.currentTarget).find('a').attr('href')

if (href.startsWith('/#') || href.startsWith('#')){
var targetId = href.startsWith('/#') ? href.substring(2) : href.substring(1)
var target = $('#' + targetId)

if (target.length){
$('html, body').animate({
scrollTop: target.offset().top
}, 800)
}
}
window.location.href = href;
} )

function navbarExpand(e) {
e.preventDefault();
$(this).parent('li').children('ul').stop(true, true).slideToggle(settings.openingSpeed);
Expand Down Expand Up @@ -269,6 +262,34 @@
});
}

function toggleMenu(e) {
e.preventDefault();

// if nav position is left or right, uses fadeToggle instead of slideToggle
if (settings.position == 'left' || settings.position == 'right') {
nav.find('ul:first').stop(true, true).fadeToggle(settings.openingSpeed);
nav.toggleClass('active');

if(nav.hasClass('active') && nav.hasClass('mobile')) {
// closes the menu when clicked outside of it
$(document).on('click', function(event) {
// ensures menu hides only on mobile nav
if(nav.hasClass('mobile')) {
if (!$(event.target).closest(nav).length) {
nav.find('ul:first').stop(true, true).fadeOut(settings.openingSpeed);
nav.removeClass('active');
}
}
});
}

} else {
// static position - normal open and close animation
nav.find('ul:first').stop(true, true).slideToggle(settings.openingSpeed);
nav.toggleClass('active');
}
}

windowCheck();

// check browser width in real-time
Expand Down
Loading