Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding new post shortcut #34

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import domReady from "@wordpress/dom-ready";
* Internal dependencies.
*/
import QuickPostButton from "./quick-post";
import { listenForKeyboardShortcut } from "./utils";

/**
* Let's subscribe (because I finally understand what this does better)
Expand Down Expand Up @@ -49,3 +50,5 @@ subscribe(() => {
);
});
});

document.addEventListener('keydown', listenForKeyboardShortcut);
13 changes: 13 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { __ } from "@wordpress/i18n";
import { useSelect } from "@wordpress/data";
import { store as coreStore } from "@wordpress/core-data";
import { addQueryArgs } from "@wordpress/url";
kkoppenhaver marked this conversation as resolved.
Show resolved Hide resolved

/*
* We need to know two things:
Expand Down Expand Up @@ -69,3 +70,15 @@ export function getPostTypeRestBase(postType) {
});
return rest_base;
}

export function listenForKeyboardShortcut(event) {
if (
// Shortcut for Mac (Ctrl + Option + N)
(event.ctrlKey && event.altKey && 78 === event.keyCode) ||
// Shortcut for Windows (Alt + Shift + N)
(event.altKey && event.shiftKey && 78 === event.keyCode)
) {
event.preventDefault();
document.querySelector('#createwithrani-quick-post-button').click();
}
}
kkoppenhaver marked this conversation as resolved.
Show resolved Hide resolved