I am sitting like hours in front of the following code snippet and can not get it running like I want.
Basically this code creates a navigation menu on right click, but a click on the switcher should turn off this function and on the next click it gets turned on again.
Everything works fine (like expected), just the little if statement on line 12 ( if ( switcher % 2 == 0 ) ) does not work like expected, meaning the code within it always gets executed whether var switcher is even or not even. I also tried other conditions like "> 0" and so on but the code within it always gets executed.
$(document).ready(function () {
/* Set switcher to zero */
switcher = 0;
/* If switch gets clicked increment var switcher*/
$('#guidenavschalter').click(function () {
switcher++;
return false;
});
/* If var switcher is even execute following code, if not do nothing of this*/
if (switcher % 2 == 0) {
/* do not display right click browser menu */
document.oncontextmenu = function () {
return false;
};
/* if click within #page excluding area of #newid */
$('#page:not(#newid)').mousedown(function (e) {
/* if right click */
if (e.button == 2) {
/* if #newid already exist display it again */
if ($('#newid').length) {
$('#newid').css({
"display": 'block'
});
$('#newid').css({
"top": e.pageY + 'px'
});
$('#newid').css({
"left": e.pageX + 'px'
});
/* if it does not exist create and display #newid */
} else {
var $div = $('#block-bookoblock-book-outline').clone().attr('id', 'newid');
$('body').append($div);
$('#newid').css({
"top": e.pageY + 'px'
});
$('#newid').css({
"left": e.pageX + 'px'
});
$('#newid').css({
"position": 'absolute'
});
return false;
}
}
/* if left click hide #newid */
if (e.button == 0) {
$('#newid').css({
"display": 'none'
});
}
return true;
});
}
});