2012-07-22 17:29:26 +04:00
|
|
|
var contextMenuObserving;
|
|
|
|
var contextMenuUrl;
|
|
|
|
|
|
|
|
function contextMenuRightClick(event) {
|
|
|
|
var target = $(event.target);
|
|
|
|
if (target.is('a')) {return;}
|
|
|
|
var tr = target.parents('tr').first();
|
|
|
|
if (!tr.hasClass('hascontextmenu')) {return;}
|
|
|
|
event.preventDefault();
|
|
|
|
if (!contextMenuIsSelected(tr)) {
|
|
|
|
contextMenuUnselectAll();
|
|
|
|
contextMenuAddSelection(tr);
|
|
|
|
contextMenuSetLastSelected(tr);
|
2012-02-16 05:35:23 +04:00
|
|
|
}
|
2012-07-22 17:29:26 +04:00
|
|
|
contextMenuShow(event);
|
|
|
|
}
|
2012-02-16 05:35:52 +04:00
|
|
|
|
2012-07-22 17:29:26 +04:00
|
|
|
function contextMenuClick(event) {
|
|
|
|
var target = $(event.target);
|
|
|
|
var lastSelected;
|
2008-02-10 16:17:41 +03:00
|
|
|
|
2012-07-22 17:29:26 +04:00
|
|
|
if (target.is('a') && target.hasClass('submenu')) {
|
|
|
|
event.preventDefault();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
contextMenuHide();
|
|
|
|
if (target.is('a') || target.is('img')) { return; }
|
2012-11-18 14:02:07 +04:00
|
|
|
if (event.which == 1 || (navigator.appVersion.match(/\bMSIE\b/))) {
|
2012-07-22 17:29:26 +04:00
|
|
|
var tr = target.parents('tr').first();
|
|
|
|
if (tr.length && tr.hasClass('hascontextmenu')) {
|
|
|
|
// a row was clicked, check if the click was on checkbox
|
|
|
|
if (target.is('input')) {
|
|
|
|
// a checkbox may be clicked
|
|
|
|
if (target.attr('checked')) {
|
|
|
|
tr.addClass('context-menu-selection');
|
2008-02-10 16:17:41 +03:00
|
|
|
} else {
|
2012-07-22 17:29:26 +04:00
|
|
|
tr.removeClass('context-menu-selection');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (event.ctrlKey || event.metaKey) {
|
|
|
|
contextMenuToggleSelection(tr);
|
|
|
|
} else if (event.shiftKey) {
|
|
|
|
lastSelected = contextMenuLastSelected();
|
|
|
|
if (lastSelected.length) {
|
|
|
|
var toggling = false;
|
|
|
|
$('.hascontextmenu').each(function(){
|
|
|
|
if (toggling || $(this).is(tr)) {
|
|
|
|
contextMenuAddSelection($(this));
|
2008-02-10 16:17:41 +03:00
|
|
|
}
|
2012-07-22 17:29:26 +04:00
|
|
|
if ($(this).is(tr) || $(this).is(lastSelected)) {
|
|
|
|
toggling = !toggling;
|
|
|
|
}
|
|
|
|
});
|
2008-02-10 16:17:41 +03:00
|
|
|
} else {
|
2012-07-22 17:29:26 +04:00
|
|
|
contextMenuAddSelection(tr);
|
2008-02-10 16:17:41 +03:00
|
|
|
}
|
2010-03-04 22:09:14 +03:00
|
|
|
} else {
|
2012-07-22 17:29:26 +04:00
|
|
|
contextMenuUnselectAll();
|
|
|
|
contextMenuAddSelection(tr);
|
2008-02-10 16:17:41 +03:00
|
|
|
}
|
2012-07-22 17:29:26 +04:00
|
|
|
contextMenuSetLastSelected(tr);
|
2008-02-10 16:17:41 +03:00
|
|
|
}
|
|
|
|
} else {
|
2012-07-22 17:29:26 +04:00
|
|
|
// click is outside the rows
|
|
|
|
if (target.is('a') && (target.hasClass('disabled') || target.hasClass('submenu'))) {
|
|
|
|
event.preventDefault();
|
|
|
|
} else {
|
|
|
|
contextMenuUnselectAll();
|
|
|
|
}
|
2008-02-10 16:17:41 +03:00
|
|
|
}
|
2012-07-22 17:29:26 +04:00
|
|
|
}
|
|
|
|
}
|
2012-02-16 05:35:52 +04:00
|
|
|
|
2012-07-22 17:29:26 +04:00
|
|
|
function contextMenuCreate() {
|
|
|
|
if ($('#context-menu').length < 1) {
|
|
|
|
var menu = document.createElement("div");
|
|
|
|
menu.setAttribute("id", "context-menu");
|
|
|
|
menu.setAttribute("style", "display:none;");
|
|
|
|
document.getElementById("content").appendChild(menu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function contextMenuShow(event) {
|
|
|
|
var mouse_x = event.pageX;
|
|
|
|
var mouse_y = event.pageY;
|
|
|
|
var render_x = mouse_x;
|
|
|
|
var render_y = mouse_y;
|
|
|
|
var dims;
|
|
|
|
var menu_width;
|
|
|
|
var menu_height;
|
|
|
|
var window_width;
|
|
|
|
var window_height;
|
|
|
|
var max_width;
|
|
|
|
var max_height;
|
|
|
|
|
|
|
|
$('#context-menu').css('left', (render_x + 'px'));
|
|
|
|
$('#context-menu').css('top', (render_y + 'px'));
|
|
|
|
$('#context-menu').html('');
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: contextMenuUrl,
|
|
|
|
data: $(event.target).parents('form').first().serialize(),
|
|
|
|
success: function(data, textStatus, jqXHR) {
|
|
|
|
$('#context-menu').html(data);
|
|
|
|
menu_width = $('#context-menu').width();
|
|
|
|
menu_height = $('#context-menu').height();
|
|
|
|
max_width = mouse_x + 2*menu_width;
|
|
|
|
max_height = mouse_y + menu_height;
|
|
|
|
|
|
|
|
var ws = window_size();
|
|
|
|
window_width = ws.width;
|
|
|
|
window_height = ws.height;
|
|
|
|
|
|
|
|
/* display the menu above and/or to the left of the click if needed */
|
|
|
|
if (max_width > window_width) {
|
|
|
|
render_x -= menu_width;
|
|
|
|
$('#context-menu').addClass('reverse-x');
|
|
|
|
} else {
|
|
|
|
$('#context-menu').removeClass('reverse-x');
|
|
|
|
}
|
|
|
|
if (max_height > window_height) {
|
|
|
|
render_y -= menu_height;
|
|
|
|
$('#context-menu').addClass('reverse-y');
|
|
|
|
} else {
|
|
|
|
$('#context-menu').removeClass('reverse-y');
|
|
|
|
}
|
|
|
|
if (render_x <= 0) render_x = 1;
|
|
|
|
if (render_y <= 0) render_y = 1;
|
|
|
|
$('#context-menu').css('left', (render_x + 'px'));
|
|
|
|
$('#context-menu').css('top', (render_y + 'px'));
|
|
|
|
$('#context-menu').show();
|
|
|
|
|
|
|
|
//if (window.parseStylesheets) { window.parseStylesheets(); } // IE
|
2012-02-16 05:35:52 +04:00
|
|
|
|
2008-02-10 16:17:41 +03:00
|
|
|
}
|
2012-07-22 17:29:26 +04:00
|
|
|
});
|
|
|
|
}
|
2012-02-16 05:35:52 +04:00
|
|
|
|
2012-07-22 17:29:26 +04:00
|
|
|
function contextMenuSetLastSelected(tr) {
|
|
|
|
$('.cm-last').removeClass('cm-last');
|
|
|
|
tr.addClass('cm-last');
|
|
|
|
}
|
2012-02-16 05:35:52 +04:00
|
|
|
|
2012-07-22 17:29:26 +04:00
|
|
|
function contextMenuLastSelected() {
|
|
|
|
return $('.cm-last').first();
|
|
|
|
}
|
2012-02-16 05:35:52 +04:00
|
|
|
|
2012-07-22 17:29:26 +04:00
|
|
|
function contextMenuUnselectAll() {
|
|
|
|
$('.hascontextmenu').each(function(){
|
|
|
|
contextMenuRemoveSelection($(this));
|
|
|
|
});
|
|
|
|
$('.cm-last').removeClass('cm-last');
|
|
|
|
}
|
|
|
|
|
|
|
|
function contextMenuHide() {
|
|
|
|
$('#context-menu').hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
function contextMenuToggleSelection(tr) {
|
|
|
|
if (contextMenuIsSelected(tr)) {
|
|
|
|
contextMenuRemoveSelection(tr);
|
|
|
|
} else {
|
|
|
|
contextMenuAddSelection(tr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function contextMenuAddSelection(tr) {
|
|
|
|
tr.addClass('context-menu-selection');
|
|
|
|
contextMenuCheckSelectionBox(tr, true);
|
|
|
|
contextMenuClearDocumentSelection();
|
|
|
|
}
|
|
|
|
|
|
|
|
function contextMenuRemoveSelection(tr) {
|
|
|
|
tr.removeClass('context-menu-selection');
|
|
|
|
contextMenuCheckSelectionBox(tr, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
function contextMenuIsSelected(tr) {
|
|
|
|
return tr.hasClass('context-menu-selection');
|
|
|
|
}
|
|
|
|
|
|
|
|
function contextMenuCheckSelectionBox(tr, checked) {
|
|
|
|
tr.find('input[type=checkbox]').attr('checked', checked);
|
|
|
|
}
|
|
|
|
|
|
|
|
function contextMenuClearDocumentSelection() {
|
|
|
|
// TODO
|
|
|
|
if (document.selection) {
|
2013-05-01 16:53:10 +04:00
|
|
|
document.selection.empty(); // IE
|
2012-07-22 17:29:26 +04:00
|
|
|
} else {
|
|
|
|
window.getSelection().removeAllRanges();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function contextMenuInit(url) {
|
|
|
|
contextMenuUrl = url;
|
|
|
|
contextMenuCreate();
|
|
|
|
contextMenuUnselectAll();
|
|
|
|
|
|
|
|
if (!contextMenuObserving) {
|
|
|
|
$(document).click(contextMenuClick);
|
|
|
|
$(document).contextmenu(contextMenuRightClick);
|
|
|
|
contextMenuObserving = true;
|
2008-02-10 16:17:41 +03:00
|
|
|
}
|
|
|
|
}
|
2007-10-28 13:55:59 +03:00
|
|
|
|
2008-02-10 16:17:41 +03:00
|
|
|
function toggleIssuesSelection(el) {
|
2012-07-22 17:29:26 +04:00
|
|
|
var boxes = $(el).parents('form').find('input[type=checkbox]');
|
2012-02-16 05:35:23 +04:00
|
|
|
var all_checked = true;
|
2012-07-22 17:29:26 +04:00
|
|
|
boxes.each(function(){ if (!$(this).attr('checked')) { all_checked = false; } });
|
|
|
|
boxes.each(function(){
|
2012-02-16 05:35:23 +04:00
|
|
|
if (all_checked) {
|
2012-07-22 17:29:26 +04:00
|
|
|
$(this).removeAttr('checked');
|
|
|
|
$(this).parents('tr').removeClass('context-menu-selection');
|
|
|
|
} else if (!$(this).attr('checked')) {
|
|
|
|
$(this).attr('checked', true);
|
|
|
|
$(this).parents('tr').addClass('context-menu-selection');
|
2012-02-16 05:35:23 +04:00
|
|
|
}
|
2012-07-22 17:29:26 +04:00
|
|
|
});
|
2007-10-28 13:55:59 +03:00
|
|
|
}
|
2008-04-03 20:38:06 +04:00
|
|
|
|
|
|
|
function window_size() {
|
2012-02-16 05:35:23 +04:00
|
|
|
var w;
|
|
|
|
var h;
|
|
|
|
if (window.innerWidth) {
|
|
|
|
w = window.innerWidth;
|
|
|
|
h = window.innerHeight;
|
|
|
|
} else if (document.documentElement) {
|
|
|
|
w = document.documentElement.clientWidth;
|
|
|
|
h = document.documentElement.clientHeight;
|
|
|
|
} else {
|
|
|
|
w = document.body.clientWidth;
|
|
|
|
h = document.body.clientHeight;
|
|
|
|
}
|
|
|
|
return {width: w, height: h};
|
2008-04-03 20:38:06 +04:00
|
|
|
}
|