fix #1852
This commit is contained in:
@@ -772,7 +772,7 @@ $(function() {
|
||||
if ($("#c-posts").length && $("#a-show").length && $("#image").length && !$("video#image").length) {
|
||||
if ($("#note-locked-notice").length == 0) {
|
||||
$("#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.load_all();
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
$(function() {
|
||||
if ($(".paginator").length && (Danbooru.meta("enable-js-navigation") === "true")) {
|
||||
$(document).bind("keypress", "d", Danbooru.Paginator.next_page);
|
||||
$(document).bind("keypress", "a", Danbooru.Paginator.prev_page);
|
||||
$(document).bind("keydown", "d", Danbooru.Paginator.next_page);
|
||||
$(document).bind("keydown", "a", Danbooru.Paginator.prev_page);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
@@ -22,12 +22,12 @@
|
||||
Danbooru.PostPopular.initialize_all = function() {
|
||||
if ($("#c-explore-posts").length) {
|
||||
if (Danbooru.meta("enable-js-navigation") === "true") {
|
||||
$(document).bind("keypress", "a", function(e) {
|
||||
$(document).bind("keydown", "a", function(e) {
|
||||
Danbooru.PostPopular.nav_prev();
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$(document).bind("keypress", "d", function(e) {
|
||||
$(document).bind("keydown", "d", function(e) {
|
||||
Danbooru.PostPopular.nav_next();
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
@@ -169,23 +169,23 @@
|
||||
|
||||
Danbooru.Post.initialize_shortcuts = function() {
|
||||
if ($("#a-show").length) {
|
||||
$(document).bind("keypress", "e", function(e) {
|
||||
$(document).bind("keydown", "e", function(e) {
|
||||
$("#post-edit-link").trigger("click");
|
||||
$("#post_tag_string").focus();
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$(document).bind("keypress", "a", function(e) {
|
||||
$(document).bind("keydown", "a", function(e) {
|
||||
Danbooru.Post.nav_prev();
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$(document).bind("keypress", "d", function(e) {
|
||||
$(document).bind("keydown", "d", function(e) {
|
||||
Danbooru.Post.nav_next();
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$(document).bind("keypress", "f", function(e) {
|
||||
$(document).bind("keydown", "f", function(e) {
|
||||
if ($("#add-to-favorites").is(":visible")) {
|
||||
$("#add-to-favorites").click();
|
||||
} else {
|
||||
@@ -322,7 +322,7 @@
|
||||
});
|
||||
|
||||
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")) {
|
||||
$("#image-resize-link").click();
|
||||
} else {
|
||||
|
||||
@@ -2,21 +2,21 @@
|
||||
Danbooru.Shortcuts = {};
|
||||
|
||||
Danbooru.Shortcuts.initialize = function() {
|
||||
$(document).bind("keypress", "s", function(e) {
|
||||
$(document).bind("keydown", "s", function(e) {
|
||||
Danbooru.Shortcuts.nav_scroll_down();
|
||||
});
|
||||
|
||||
$(document).bind("keypress", "w", function(e) {
|
||||
$(document).bind("keydown", "w", function(e) {
|
||||
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();
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
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) {
|
||||
$("#edit").show();
|
||||
$("#comments").hide();
|
||||
@@ -32,17 +32,17 @@
|
||||
}
|
||||
|
||||
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"));
|
||||
});
|
||||
|
||||
$(document).bind("keypress", "r", function(e) {
|
||||
$(document).bind("keydown", "r", function(e) {
|
||||
$("#random-post")[0].click();
|
||||
});
|
||||
}
|
||||
|
||||
if ($("#c-posts").length && $("#a-index").length) {
|
||||
$(document).bind("keypress", "r", function(e) {
|
||||
$(document).bind("keydown", "r", function(e) {
|
||||
$("#random-post")[0].click();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
|
||||
Danbooru.WikiPage.initialize_shortcuts = function() {
|
||||
if ($("#a-show").length) {
|
||||
$(document).bind("keypress", "e", function(e) {
|
||||
$(document).bind("keydown", "e", function(e) {
|
||||
$("#wiki-page-edit-link")[0].click();
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
257
vendor/assets/javascripts/jquery.hotkeys.js
vendored
257
vendor/assets/javascripts/jquery.hotkeys.js
vendored
@@ -1,111 +1,204 @@
|
||||
/*jslint browser: true*/
|
||||
/*jslint jquery: true*/
|
||||
|
||||
/*
|
||||
* jQuery Hotkeys Plugin
|
||||
* Copyright 2010, John Resig
|
||||
* Dual licensed under the MIT or GPL Version 2 licenses.
|
||||
*
|
||||
* Based upon the plugin by Tzury Bar Yochay:
|
||||
* http://github.com/tzuryby/hotkeys
|
||||
* https://github.com/tzuryby/jquery.hotkeys
|
||||
*
|
||||
* Original idea by:
|
||||
* Binny V A, http://www.openjs.com/scripts/events/keyboard_shortcuts/
|
||||
*/
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
(function(jQuery){
|
||||
|
||||
jQuery.hotkeys = {
|
||||
version: "0.8",
|
||||
(function(jQuery) {
|
||||
|
||||
specialKeys: {
|
||||
8: "backspace", 9: "tab", 10: "return", 13: "return", 16: "shift", 17: "ctrl", 18: "alt", 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",
|
||||
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", 186: ";", 191: "/",
|
||||
220: "\\", 222: "'", 224: "meta"
|
||||
},
|
||||
|
||||
shiftNums: {
|
||||
"`": "~", "1": "!", "2": "@", "3": "#", "4": "$", "5": "%", "6": "^", "7": "&",
|
||||
"8": "*", "9": "(", "0": ")", "-": "_", "=": "+", ";": ": ", "'": "\"", ",": "<",
|
||||
".": ">", "/": "?", "\\": "|"
|
||||
}
|
||||
};
|
||||
jQuery.hotkeys = {
|
||||
version: "0.8",
|
||||
|
||||
function keyHandler( handleObj ) {
|
||||
if ( typeof handleObj.data === "string" ) {
|
||||
handleObj.data = { keys: handleObj.data };
|
||||
}
|
||||
specialKeys: {
|
||||
8: "backspace",
|
||||
9: "tab",
|
||||
10: "return",
|
||||
13: "return",
|
||||
16: "shift",
|
||||
17: "ctrl",
|
||||
18: "alt",
|
||||
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: "'"
|
||||
},
|
||||
|
||||
// Only care when a possible input has been specified
|
||||
if ( !handleObj.data || !handleObj.data.keys || typeof handleObj.data.keys !== "string" ) {
|
||||
return;
|
||||
}
|
||||
shiftNums: {
|
||||
"`": "~",
|
||||
"1": "!",
|
||||
"2": "@",
|
||||
"3": "#",
|
||||
"4": "$",
|
||||
"5": "%",
|
||||
"6": "^",
|
||||
"7": "&",
|
||||
"8": "*",
|
||||
"9": "(",
|
||||
"0": ")",
|
||||
"-": "_",
|
||||
"=": "+",
|
||||
";": ": ",
|
||||
"'": "\"",
|
||||
",": "<",
|
||||
".": ">",
|
||||
"/": "?",
|
||||
"\\": "|"
|
||||
},
|
||||
|
||||
var origHandler = handleObj.handler,
|
||||
keys = handleObj.data.keys.toLowerCase().split(" "),
|
||||
textAcceptingInputTypes = ["text", "password", "number", "email", "url", "range", "date", "month", "week", "time", "datetime", "datetime-local", "search", "color", "tel"];
|
||||
|
||||
handleObj.handler = function( event ) {
|
||||
// Don't fire in text-accepting inputs that we didn't directly bind to
|
||||
if ( this !== event.target && (/textarea|select/i.test( event.target.nodeName ) ||
|
||||
jQuery.inArray(event.target.type, textAcceptingInputTypes) > -1 ) ) {
|
||||
return;
|
||||
}
|
||||
// excludes: button, checkbox, file, hidden, image, password, radio, reset, search, submit, url
|
||||
textAcceptingInputTypes: [
|
||||
"text", "password", "number", "email", "url", "range", "date", "month", "week", "time", "datetime",
|
||||
"datetime-local", "search", "color", "tel"],
|
||||
|
||||
var special = jQuery.hotkeys.specialKeys[ event.keyCode ],
|
||||
// character codes are available only in keypress
|
||||
character = event.type === "keypress" && String.fromCharCode( event.which ).toLowerCase(),
|
||||
modif = "", possible = {};
|
||||
// default input types not to bind to unless bound directly
|
||||
textInputTypes: /textarea|input|select/i,
|
||||
|
||||
// check combinations (alt|ctrl|shift+anything)
|
||||
if ( event.altKey && special !== "alt" ) {
|
||||
modif += "alt+";
|
||||
}
|
||||
options: {
|
||||
filterInputAcceptingElements: true,
|
||||
filterTextInputs: true,
|
||||
filterContentEditable: true
|
||||
}
|
||||
};
|
||||
|
||||
if ( event.ctrlKey && special !== "ctrl" ) {
|
||||
modif += "ctrl+";
|
||||
}
|
||||
|
||||
// TODO: Need to make sure this works consistently across platforms
|
||||
if ( event.metaKey && !event.ctrlKey && special !== "meta" ) {
|
||||
modif += "meta+";
|
||||
}
|
||||
function keyHandler(handleObj) {
|
||||
if (typeof handleObj.data === "string") {
|
||||
handleObj.data = {
|
||||
keys: handleObj.data
|
||||
};
|
||||
}
|
||||
|
||||
if ( event.shiftKey && special !== "shift" ) {
|
||||
modif += "shift+";
|
||||
}
|
||||
// Only care when a possible input has been specified
|
||||
if (!handleObj.data || !handleObj.data.keys || typeof handleObj.data.keys !== "string") {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( special ) {
|
||||
possible[ modif + special ] = true;
|
||||
}
|
||||
var origHandler = handleObj.handler,
|
||||
keys = handleObj.data.keys.toLowerCase().split(" ");
|
||||
|
||||
if ( character ) {
|
||||
possible[ modif + character ] = true;
|
||||
possible[ modif + jQuery.hotkeys.shiftNums[ character ] ] = true;
|
||||
handleObj.handler = function(event) {
|
||||
// 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;
|
||||
}
|
||||
|
||||
// "$" can be triggered as "Shift+4" or "Shift+$" or just "$"
|
||||
if ( modif === "shift+" ) {
|
||||
possible[ jQuery.hotkeys.shiftNums[ character ] ] = true;
|
||||
}
|
||||
}
|
||||
var special = event.type !== "keypress" && jQuery.hotkeys.specialKeys[event.which],
|
||||
character = String.fromCharCode(event.which).toLowerCase(),
|
||||
modif = "",
|
||||
possible = {};
|
||||
|
||||
for ( var i = 0, l = keys.length; i < l; i++ ) {
|
||||
if ( possible[ keys[i] ] ) {
|
||||
return origHandler.apply( this, arguments );
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
jQuery.each(["alt", "ctrl", "shift"], function(index, specialKey) {
|
||||
|
||||
jQuery.each([ "keydown", "keyup", "keypress" ], function() {
|
||||
jQuery.event.special[ this ] = { add: keyHandler };
|
||||
});
|
||||
if (event[specialKey + 'Key'] && special !== specialKey) {
|
||||
modif += specialKey + '+';
|
||||
}
|
||||
});
|
||||
|
||||
})( this.jQuery );
|
||||
// metaKey is triggered off ctrlKey erronously
|
||||
if (event.metaKey && !event.ctrlKey && special !== "meta") {
|
||||
modif += "meta+";
|
||||
}
|
||||
|
||||
if (event.metaKey && special !== "meta" && modif.indexOf("alt+ctrl+shift+") > -1) {
|
||||
modif = modif.replace("alt+ctrl+shift+", "hyper+");
|
||||
}
|
||||
|
||||
if (special) {
|
||||
possible[modif + special] = true;
|
||||
}
|
||||
else {
|
||||
possible[modif + character] = true;
|
||||
possible[modif + jQuery.hotkeys.shiftNums[character]] = true;
|
||||
|
||||
// "$" can be triggered as "Shift+4" or "Shift+$" or just "$"
|
||||
if (modif === "shift+") {
|
||||
possible[jQuery.hotkeys.shiftNums[character]] = true;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user