Experiments with keyboard shortcuts

This commit is contained in:
Frederic Guillot
2015-01-30 23:11:30 -05:00
parent 746e1a4e3d
commit e1be338053
5 changed files with 87 additions and 41 deletions

View File

@@ -12,7 +12,7 @@ var Kanboard = (function() {
return false;
},
// Display a popup
// Open a popup on a link click
Popover: function(e, callback) {
e.preventDefault();
e.stopPropagation();
@@ -24,30 +24,40 @@ var Kanboard = (function() {
}
if (link) {
$.get(link, function(content) {
$("body").append('<div id="popover-container"><div id="popover-content">' + content + '</div></div>');
$("#popover-container").click(function() {
$(this).remove();
});
$("#popover-content").click(function(e) {
e.stopPropagation();
});
$(".close-popover").click(function(e) {
e.preventDefault();
$('#popover-container').remove();
});
if (callback) {
callback();
}
});
Kanboard.OpenPopover(link, callback);
}
},
// Display a popup
OpenPopover: function(link, callback) {
$.get(link, function(content) {
$("body").append('<div id="popover-container"><div id="popover-content">' + content + '</div></div>');
$("#popover-container").click(function() {
$(this).remove();
});
$("#popover-content").click(function(e) {
e.stopPropagation();
});
$(".close-popover").click(function(e) {
e.preventDefault();
$('#popover-container').remove();
});
Mousetrap.bind("esc", function() {
$('#popover-container').remove();
});
if (callback) {
callback();
}
});
},
// Return true if the page is visible
IsVisible: function() {
@@ -181,6 +191,10 @@ var Kanboard = (function() {
$(".auto-select").focus(function() {
$(this).select();
});
Mousetrap.bind("ctrl+enter", function() {
$("form").submit();
});
}
};

View File

@@ -7,6 +7,17 @@ Kanboard.Board = (function() {
Kanboard.Popover(e, Kanboard.Init);
}
function keyboard_shortcuts()
{
Mousetrap.bind("n", function() {
Kanboard.OpenPopover(
$(".task-creation-popover").attr('href'),
Kanboard.Init
);
});
}
// Setup the board
function board_load_events()
{
@@ -250,6 +261,7 @@ Kanboard.Board = (function() {
Init: function() {
board_load_events();
filter_load_events();
keyboard_shortcuts();
}
};