Fixed problem with keyboard shortcuts on Flash

Previous attempt - f226c3eb0c.
Approach introduced in this commit is theoretically much better, but it still
might not be perfect.
This commit is contained in:
Marcin Kurczewski 2014-03-05 22:14:30 +01:00
parent f7837dc190
commit 4879ba94b0
2 changed files with 77 additions and 9 deletions

View file

@ -304,15 +304,59 @@ function attachTagIt(element)
//prevent keybindings from executing when flash posts are focused
var oldMousetrapBind = Mousetrap.bind;
Mousetrap.bind = function(key, func, args)
{
oldMousetrapBind(key, function()
{
if ($(document.activeElement).parents('.post-type-flash').length > 0)
return false;
func();
}, args);
};
//hotkeys //hotkeys
$(function() $(function()
{ {
Mousetrap.bind('q', function() { $('#top-nav input').focus(); return false; }, 'keyup'); Mousetrap.bind('q', function()
Mousetrap.bind('w', function() { $('body,html').animate({scrollTop: '-=150px'}, 200); }); {
Mousetrap.bind('s', function() { $('body,html').animate({scrollTop: '+=150px'}, 200); }); $('#top-nav input').focus();
Mousetrap.bind('a', function() { var url = $('.paginator:visible .prev:not(.disabled) a').attr('href'); if (typeof url !== 'undefined') window.location.href = url; }, 'keyup'); return false;
Mousetrap.bind('d', function() { var url = $('.paginator:visible .next:not(.disabled) a').attr('href'); if (typeof url !== 'undefined') window.location.href = url; }, 'keyup'); }, 'keyup');
Mousetrap.bind('p', function() { $('.post a').eq(0).focus(); return false; }, 'keyup');
Mousetrap.bind('w', function()
{
$('body,html').animate({scrollTop: '-=150px'}, 200);
});
Mousetrap.bind('s', function()
{
$('body,html').animate({scrollTop: '+=150px'}, 200);
});
Mousetrap.bind('a', function()
{
var url = $('.paginator:visible .prev:not(.disabled) a').attr('href');
if (typeof url !== 'undefined')
window.location.href = url;
}, 'keyup');
Mousetrap.bind('d', function()
{
var url = $('.paginator:visible .next:not(.disabled) a').attr('href');
if (typeof url !== 'undefined')
window.location.href = url;
}, 'keyup');
Mousetrap.bind('p', function()
{
$('.post a').eq(0).focus();
return false;
}, 'keyup');
}); });

View file

@ -140,7 +140,31 @@ $(function()
$.ajax(ajaxData); $.ajax(ajaxData);
}); });
Mousetrap.bind('a', function() { var a = $('#sidebar .left a'); var url = a.attr('href'); if (typeof url !== 'undefined') { a.click(); window.location.href = url; } }, 'keyup'); Mousetrap.bind('a', function()
Mousetrap.bind('d', function() { var a = $('#sidebar .right a'); var url = a.attr('href'); if (typeof url !== 'undefined') { a.click(); window.location.href = url; } }, 'keyup'); {
Mousetrap.bind('e', function() { $('a.edit-post').trigger('click'); return false; }, 'keyup'); var a = $('#sidebar .left a');
var url = a.attr('href');
if (typeof url !== 'undefined')
{
a.click();
window.location.href = url;
}
}, 'keyup');
Mousetrap.bind('d', function()
{
var a = $('#sidebar .right a');
var url = a.attr('href');
if (typeof url !== 'undefined')
{
a.click();
window.location.href = url;
}
}, 'keyup');
Mousetrap.bind('e', function()
{
$('a.edit-post').trigger('click');
return false;
}, 'keyup');
}); });