This commit is contained in:
Toks
2015-04-23 11:20:14 -04:00
parent c56d16d336
commit a0baaea1b2
8 changed files with 194 additions and 101 deletions

View File

@@ -772,7 +772,7 @@ $(function() {
if ($("#c-posts").length && $("#a-show").length && $("#image").length && !$("video#image").length) { if ($("#c-posts").length && $("#a-show").length && $("#image").length && !$("video#image").length) {
if ($("#note-locked-notice").length == 0) { if ($("#note-locked-notice").length == 0) {
$("#translate").bind("click", Danbooru.Note.TranslationMode.toggle); $("#translate").bind("click", Danbooru.Note.TranslationMode.toggle);
$(document).bind("keypress", "n", Danbooru.Note.TranslationMode.toggle); $(document).bind("keydown", "n", Danbooru.Note.TranslationMode.toggle);
} }
Danbooru.Note.embed = (Danbooru.meta("post-has-embedded-notes") === "true"); Danbooru.Note.embed = (Danbooru.meta("post-has-embedded-notes") === "true");
Danbooru.Note.load_all(); Danbooru.Note.load_all();

View File

@@ -18,8 +18,8 @@
$(function() { $(function() {
if ($(".paginator").length && (Danbooru.meta("enable-js-navigation") === "true")) { if ($(".paginator").length && (Danbooru.meta("enable-js-navigation") === "true")) {
$(document).bind("keypress", "d", Danbooru.Paginator.next_page); $(document).bind("keydown", "d", Danbooru.Paginator.next_page);
$(document).bind("keypress", "a", Danbooru.Paginator.prev_page); $(document).bind("keydown", "a", Danbooru.Paginator.prev_page);
} }
}); });

View File

@@ -13,7 +13,7 @@
} }
Danbooru.PostModeMenu.initialize_shortcuts = function() { Danbooru.PostModeMenu.initialize_shortcuts = function() {
$(document).bind("keypress", "1 2 3 4 5 6 7 8 9 0", Danbooru.PostModeMenu.change_tag_script); $(document).bind("keydown", "1 2 3 4 5 6 7 8 9 0", Danbooru.PostModeMenu.change_tag_script);
} }
Danbooru.PostModeMenu.show_notice = function(i) { Danbooru.PostModeMenu.show_notice = function(i) {

View File

@@ -22,12 +22,12 @@
Danbooru.PostPopular.initialize_all = function() { Danbooru.PostPopular.initialize_all = function() {
if ($("#c-explore-posts").length) { if ($("#c-explore-posts").length) {
if (Danbooru.meta("enable-js-navigation") === "true") { if (Danbooru.meta("enable-js-navigation") === "true") {
$(document).bind("keypress", "a", function(e) { $(document).bind("keydown", "a", function(e) {
Danbooru.PostPopular.nav_prev(); Danbooru.PostPopular.nav_prev();
e.preventDefault(); e.preventDefault();
}); });
$(document).bind("keypress", "d", function(e) { $(document).bind("keydown", "d", function(e) {
Danbooru.PostPopular.nav_next(); Danbooru.PostPopular.nav_next();
e.preventDefault(); e.preventDefault();
}); });

View File

@@ -169,23 +169,23 @@
Danbooru.Post.initialize_shortcuts = function() { Danbooru.Post.initialize_shortcuts = function() {
if ($("#a-show").length) { if ($("#a-show").length) {
$(document).bind("keypress", "e", function(e) { $(document).bind("keydown", "e", function(e) {
$("#post-edit-link").trigger("click"); $("#post-edit-link").trigger("click");
$("#post_tag_string").focus(); $("#post_tag_string").focus();
e.preventDefault(); e.preventDefault();
}); });
$(document).bind("keypress", "a", function(e) { $(document).bind("keydown", "a", function(e) {
Danbooru.Post.nav_prev(); Danbooru.Post.nav_prev();
e.preventDefault(); e.preventDefault();
}); });
$(document).bind("keypress", "d", function(e) { $(document).bind("keydown", "d", function(e) {
Danbooru.Post.nav_next(); Danbooru.Post.nav_next();
e.preventDefault(); e.preventDefault();
}); });
$(document).bind("keypress", "f", function(e) { $(document).bind("keydown", "f", function(e) {
if ($("#add-to-favorites").is(":visible")) { if ($("#add-to-favorites").is(":visible")) {
$("#add-to-favorites").click(); $("#add-to-favorites").click();
} else { } else {
@@ -322,7 +322,7 @@
}); });
if ($("#image-resize-notice").length && Danbooru.meta("enable-js-navigation") === "true") { if ($("#image-resize-notice").length && Danbooru.meta("enable-js-navigation") === "true") {
$(document).bind("keypress", "v", function(e) { $(document).bind("keydown", "v", function(e) {
if ($("#image-resize-notice").is(":visible")) { if ($("#image-resize-notice").is(":visible")) {
$("#image-resize-link").click(); $("#image-resize-link").click();
} else { } else {

View File

@@ -2,21 +2,21 @@
Danbooru.Shortcuts = {}; Danbooru.Shortcuts = {};
Danbooru.Shortcuts.initialize = function() { Danbooru.Shortcuts.initialize = function() {
$(document).bind("keypress", "s", function(e) { $(document).bind("keydown", "s", function(e) {
Danbooru.Shortcuts.nav_scroll_down(); Danbooru.Shortcuts.nav_scroll_down();
}); });
$(document).bind("keypress", "w", function(e) { $(document).bind("keydown", "w", function(e) {
Danbooru.Shortcuts.nav_scroll_up(); Danbooru.Shortcuts.nav_scroll_up();
}); });
$(document).bind("keypress", "q", function(e) { $(document).bind("keydown", "q", function(e) {
$("#tags, #search_name, #search_name_matches, #query").trigger("focus").selectEnd(); $("#tags, #search_name, #search_name_matches, #query").trigger("focus").selectEnd();
e.preventDefault(); e.preventDefault();
}); });
if ($("#image").length) { // post page or bookmarklet upload page if ($("#image").length) { // post page or bookmarklet upload page
$(document).bind("keypress", "shift+e", function(e) { $(document).bind("keydown", "shift+e", function(e) {
if (!$("#edit-dialog").length) { if (!$("#edit-dialog").length) {
$("#edit").show(); $("#edit").show();
$("#comments").hide(); $("#comments").hide();
@@ -32,17 +32,17 @@
} }
if ($("#c-posts").length && $("#a-show").length) { if ($("#c-posts").length && $("#a-show").length) {
$(document).bind("keypress", "shift+o", function(e) { $(document).bind("keydown", "shift+o", function(e) {
Danbooru.Post.approve(Danbooru.meta("post-id")); Danbooru.Post.approve(Danbooru.meta("post-id"));
}); });
$(document).bind("keypress", "r", function(e) { $(document).bind("keydown", "r", function(e) {
$("#random-post")[0].click(); $("#random-post")[0].click();
}); });
} }
if ($("#c-posts").length && $("#a-index").length) { if ($("#c-posts").length && $("#a-index").length) {
$(document).bind("keypress", "r", function(e) { $(document).bind("keydown", "r", function(e) {
$("#random-post")[0].click(); $("#random-post")[0].click();
}); });
} }

View File

@@ -51,7 +51,7 @@
Danbooru.WikiPage.initialize_shortcuts = function() { Danbooru.WikiPage.initialize_shortcuts = function() {
if ($("#a-show").length) { if ($("#a-show").length) {
$(document).bind("keypress", "e", function(e) { $(document).bind("keydown", "e", function(e) {
$("#wiki-page-edit-link")[0].click(); $("#wiki-page-edit-link")[0].click();
e.preventDefault(); e.preventDefault();
}); });

View File

@@ -1,111 +1,204 @@
/*jslint browser: true*/
/*jslint jquery: true*/
/* /*
* jQuery Hotkeys Plugin * jQuery Hotkeys Plugin
* Copyright 2010, John Resig * Copyright 2010, John Resig
* Dual licensed under the MIT or GPL Version 2 licenses. * Dual licensed under the MIT or GPL Version 2 licenses.
* *
* Based upon the plugin by Tzury Bar Yochay: * Based upon the plugin by Tzury Bar Yochay:
* http://github.com/tzuryby/hotkeys * https://github.com/tzuryby/jquery.hotkeys
* *
* Original idea by: * Original idea by:
* Binny V A, http://www.openjs.com/scripts/events/keyboard_shortcuts/ * Binny V A, http://www.openjs.com/scripts/events/keyboard_shortcuts/
*/ */
/* /*
* One small change is: now keys are passed by object { keys: '...' } * One small change is: now keys are passed by object { keys: '...' }
* Might be useful, when you want to pass some other data to your handler * Might be useful, when you want to pass some other data to your handler
*/ */
(function(jQuery){ (function(jQuery) {
jQuery.hotkeys = { jQuery.hotkeys = {
version: "0.8", version: "0.8",
specialKeys: { specialKeys: {
8: "backspace", 9: "tab", 10: "return", 13: "return", 16: "shift", 17: "ctrl", 18: "alt", 19: "pause", 8: "backspace",
20: "capslock", 27: "esc", 32: "space", 33: "pageup", 34: "pagedown", 35: "end", 36: "home", 9: "tab",
37: "left", 38: "up", 39: "right", 40: "down", 45: "insert", 46: "del", 10: "return",
96: "0", 97: "1", 98: "2", 99: "3", 100: "4", 101: "5", 102: "6", 103: "7", 13: "return",
104: "8", 105: "9", 106: "*", 107: "+", 109: "-", 110: ".", 111 : "/", 16: "shift",
112: "f1", 113: "f2", 114: "f3", 115: "f4", 116: "f5", 117: "f6", 118: "f7", 119: "f8", 17: "ctrl",
120: "f9", 121: "f10", 122: "f11", 123: "f12", 144: "numlock", 145: "scroll", 186: ";", 191: "/", 18: "alt",
220: "\\", 222: "'", 224: "meta" 19: "pause",
}, 20: "capslock",
27: "esc",
32: "space",
33: "pageup",
34: "pagedown",
35: "end",
36: "home",
37: "left",
38: "up",
39: "right",
40: "down",
45: "insert",
46: "del",
59: ";",
61: "=",
96: "0",
97: "1",
98: "2",
99: "3",
100: "4",
101: "5",
102: "6",
103: "7",
104: "8",
105: "9",
106: "*",
107: "+",
109: "-",
110: ".",
111: "/",
112: "f1",
113: "f2",
114: "f3",
115: "f4",
116: "f5",
117: "f6",
118: "f7",
119: "f8",
120: "f9",
121: "f10",
122: "f11",
123: "f12",
144: "numlock",
145: "scroll",
173: "-",
186: ";",
187: "=",
188: ",",
189: "-",
190: ".",
191: "/",
192: "`",
219: "[",
220: "\\",
221: "]",
222: "'"
},
shiftNums: { shiftNums: {
"`": "~", "1": "!", "2": "@", "3": "#", "4": "$", "5": "%", "6": "^", "7": "&", "`": "~",
"8": "*", "9": "(", "0": ")", "-": "_", "=": "+", ";": ": ", "'": "\"", ",": "<", "1": "!",
".": ">", "/": "?", "\\": "|" "2": "@",
} "3": "#",
}; "4": "$",
"5": "%",
"6": "^",
"7": "&",
"8": "*",
"9": "(",
"0": ")",
"-": "_",
"=": "+",
";": ": ",
"'": "\"",
",": "<",
".": ">",
"/": "?",
"\\": "|"
},
function keyHandler( handleObj ) { // excludes: button, checkbox, file, hidden, image, password, radio, reset, search, submit, url
if ( typeof handleObj.data === "string" ) { textAcceptingInputTypes: [
handleObj.data = { keys: handleObj.data }; "text", "password", "number", "email", "url", "range", "date", "month", "week", "time", "datetime",
} "datetime-local", "search", "color", "tel"],
// Only care when a possible input has been specified // default input types not to bind to unless bound directly
if ( !handleObj.data || !handleObj.data.keys || typeof handleObj.data.keys !== "string" ) { textInputTypes: /textarea|input|select/i,
return;
}
var origHandler = handleObj.handler, options: {
keys = handleObj.data.keys.toLowerCase().split(" "), filterInputAcceptingElements: true,
textAcceptingInputTypes = ["text", "password", "number", "email", "url", "range", "date", "month", "week", "time", "datetime", "datetime-local", "search", "color", "tel"]; filterTextInputs: true,
filterContentEditable: true
}
};
handleObj.handler = function( event ) { function keyHandler(handleObj) {
// Don't fire in text-accepting inputs that we didn't directly bind to if (typeof handleObj.data === "string") {
if ( this !== event.target && (/textarea|select/i.test( event.target.nodeName ) || handleObj.data = {
jQuery.inArray(event.target.type, textAcceptingInputTypes) > -1 ) ) { keys: handleObj.data
return; };
} }
var special = jQuery.hotkeys.specialKeys[ event.keyCode ], // Only care when a possible input has been specified
// character codes are available only in keypress if (!handleObj.data || !handleObj.data.keys || typeof handleObj.data.keys !== "string") {
character = event.type === "keypress" && String.fromCharCode( event.which ).toLowerCase(), return;
modif = "", possible = {}; }
// check combinations (alt|ctrl|shift+anything) var origHandler = handleObj.handler,
if ( event.altKey && special !== "alt" ) { keys = handleObj.data.keys.toLowerCase().split(" ");
modif += "alt+";
}
if ( event.ctrlKey && special !== "ctrl" ) { handleObj.handler = function(event) {
modif += "ctrl+"; // Don't fire in text-accepting inputs that we didn't directly bind to
} if (this !== event.target &&
(jQuery.hotkeys.options.filterInputAcceptingElements &&
jQuery.hotkeys.textInputTypes.test(event.target.nodeName) ||
(jQuery.hotkeys.options.filterContentEditable && jQuery(event.target).attr('contenteditable')) ||
(jQuery.hotkeys.options.filterTextInputs &&
jQuery.inArray(event.target.type, jQuery.hotkeys.textAcceptingInputTypes) > -1))) {
return;
}
// TODO: Need to make sure this works consistently across platforms var special = event.type !== "keypress" && jQuery.hotkeys.specialKeys[event.which],
if ( event.metaKey && !event.ctrlKey && special !== "meta" ) { character = String.fromCharCode(event.which).toLowerCase(),
modif += "meta+"; modif = "",
} possible = {};
if ( event.shiftKey && special !== "shift" ) { jQuery.each(["alt", "ctrl", "shift"], function(index, specialKey) {
modif += "shift+";
}
if ( special ) { if (event[specialKey + 'Key'] && special !== specialKey) {
possible[ modif + special ] = true; modif += specialKey + '+';
} }
});
if ( character ) { // metaKey is triggered off ctrlKey erronously
possible[ modif + character ] = true; if (event.metaKey && !event.ctrlKey && special !== "meta") {
possible[ modif + jQuery.hotkeys.shiftNums[ character ] ] = true; modif += "meta+";
}
// "$" can be triggered as "Shift+4" or "Shift+$" or just "$" if (event.metaKey && special !== "meta" && modif.indexOf("alt+ctrl+shift+") > -1) {
if ( modif === "shift+" ) { modif = modif.replace("alt+ctrl+shift+", "hyper+");
possible[ jQuery.hotkeys.shiftNums[ character ] ] = true; }
}
}
for ( var i = 0, l = keys.length; i < l; i++ ) { if (special) {
if ( possible[ keys[i] ] ) { possible[modif + special] = true;
return origHandler.apply( this, arguments ); }
} else {
} possible[modif + character] = true;
}; possible[modif + jQuery.hotkeys.shiftNums[character]] = true;
}
jQuery.each([ "keydown", "keyup", "keypress" ], function() { // "$" can be triggered as "Shift+4" or "Shift+$" or just "$"
jQuery.event.special[ this ] = { add: keyHandler }; if (modif === "shift+") {
}); possible[jQuery.hotkeys.shiftNums[character]] = true;
}
}
})( this.jQuery ); for (var i = 0, l = keys.length; i < l; i++) {
if (possible[keys[i]]) {
return origHandler.apply(this, arguments);
}
}
};
}
jQuery.each(["keydown", "keyup", "keypress"], function() {
jQuery.event.special[this] = {
add: keyHandler
};
});
})(jQuery || this.jQuery || window.jQuery);