$(function () {
var $current = null;
$('body')
.delegate('[contextmenu2]', 'contextmenu', function (e) {
$('.contextmenu').hide();
$current = $(this);
var contextmenu = $(this).attr('contextmenu2');
var $contextmenu = $('#' + contextmenu);
if ($contextmenu.length == 0) {
return;
}
e.preventDefault();
e.stopPropagation();
$contextmenu.show();
$contextmenu.css({
'top' : e.pageY + 'px',
'left' : e.pageX + 'px',
'bottom' : null,
'right' : null
});
if (e.pageY > (window.innerHeight - 200)) {
$contextmenu.css({
'bottom' : (window.innerHeight - e.pageY) + 'px',
'top' : null
});
}
if (e.pageX > (window.innerWidth - 200)) {
$contextmenu.css({
'right': (window.innerWidth - e.pageX) + 'px',
'left' : null
});
}
return false;
})
.delegate('.contextmenu li', 'click', function () {
window.location.href = '?action=' + $(this).data('type') + $(this).data('page') + '&id=' + $current.data('id');
})
.on('click', function () {
$('.contextmenu').hide();
})
.on('keydown', function (e) {
if (e.which == 27) {
$('.contextmenu').hide();
}
});
});