hotkeys: refactor to use .on(), namespaces.
* Use .on() instead of .bind() because bind is deprecated in jquery 3.0.
* Ensure enable-js-navigation is always respected.
* Namespace keybindings so they may be disabled by userscripts with
e.g. $(document).off("keydown.danbooru") or $(document).off("next_page").
This commit is contained in:
@@ -1,41 +1,36 @@
|
||||
(function() {
|
||||
Danbooru.PostPopular = {};
|
||||
|
||||
Danbooru.PostPopular.nav_prev = function() {
|
||||
Danbooru.PostPopular.nav_prev = function(e) {
|
||||
if ($("#popular-nav-links").length) {
|
||||
var href = $("#popular-nav-links a[rel=prev]").attr("href");
|
||||
if (href) {
|
||||
location.href = href;
|
||||
}
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
Danbooru.PostPopular.nav_next = function() {
|
||||
Danbooru.PostPopular.nav_next = function(e) {
|
||||
if ($("#popular-nav-links").length) {
|
||||
var href = $("#popular-nav-links a[rel=next]").attr("href");
|
||||
if (href) {
|
||||
location.href = href;
|
||||
}
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
Danbooru.PostPopular.initialize_all = function() {
|
||||
if ($("#c-explore-posts").length) {
|
||||
if (Danbooru.meta("enable-js-navigation") === "true") {
|
||||
$(document).bind("keydown", "a", function(e) {
|
||||
Danbooru.PostPopular.nav_prev();
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$(document).bind("keydown", "d", function(e) {
|
||||
Danbooru.PostPopular.nav_next();
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
Danbooru.keydown("a", "prev_page", Danbooru.PostPopular.nav_prev);
|
||||
Danbooru.keydown("d", "next_page", Danbooru.PostPopular.nav_next);
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
$(document).ready(function() {
|
||||
Danbooru.PostPopular.initialize_all();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user