balzss/luxbar

Closing menu

Closed this issue · 4 comments

hello
this is great work you have done. thanks a lot.
I got a question: is there an easy way to have the menu which will close automatically when clicking on any of link on a portable device instead of having to close it manually?
thanks for your help

Hi,
Sorry for the late response. You have to use javascript in order to achive what you described. For example in JQuery:

$('.luxbar-item').click(function(event) {
    $('#luxbar-checkbox').prop('checked', false);
}

But it can be done in pure js as well. I hope this helped :)

My plain js proposal:
[...document.getElementsByClassName('luxbar-item')].forEach(item =>item.addEventListener('click', () => document.getElementById("luxbar-checkbox").checked = false));

Edit: @balzss thanks. I'd just noticed it doesn't work on mobile.

Thanks for adding this. I would slightly modify it like this:
document.querySelectorAll('.luxbar-item').forEach(item => item.addEventListener('click', () => document.querySelector('#luxbar-checkbox').checked = false));

IE11 don't allow i.e. arrow functions :(
This works also in IE11:

var forEach = function (array, callback, scope) {
	for (var i = 0; i < array.length; i++) {
		callback.call(scope, i, array[i]);
	}
};

var menuItems = document.querySelectorAll('.luxbar-item');
forEach(menuItems, function (index, item) {
	item.addEventListener('click', function () {
		document.querySelector('#luxbar-checkbox').checked = false;
	});
});