PluginProbe
Extendify / 2.2.0
Extendify v2.2.0
3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 0.7.0 All 126 releases
extendify / src / Agent / buttons.js

buttons.js in Extendify 2.2.0, at src/Agent/buttons.js

70 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import domReady from '@wordpress/dom-ready';
2 import { useEffect } from '@wordpress/element';
3 import { registerPlugin } from '@wordpress/plugins';
4 import { render } from '@shared/lib/dom';
5 import { isOnLaunch } from '@shared/lib/utils';
6 import { AdminBar } from '@agent/components/buttons/AdminBar';
7 import { Mobile } from '@agent/components/buttons/Mobile';
8 import { PostEditor } from '@agent/components/buttons/PostEditor';
9
10 // TODO: Sometimes the admin bar is crowded, so a smarter way would be to do some analysis first and position these accordingly.
11
12 // Global toolbar
13 domReady(() => {
14 if (isOnLaunch()) return;
15 const id = 'wp-admin-bar-extendify-agent-btn';
16 if (document.getElementById(id)) return;
17 const agent = Object.assign(document.createElement('li'), {
18 className: 'extendify-agent',
19 id,
20 });
21 agent.style.height = '1.75rem';
22 document.querySelector('#wp-admin-bar-my-account')?.before(agent);
23 render(<AdminBar />, agent);
24 });
25
26 // Mobile
27 domReady(() => {
28 if (isOnLaunch()) return;
29 const id = 'extendify-agent-mobile-btn';
30 if (document.getElementById(id)) return;
31 const agent = Object.assign(document.createElement('div'), {
32 className: 'extendify-agent',
33 id,
34 });
35 agent.style.position = 'sticky';
36 agent.style.top = 'calc(100% - var(--extendify-agent-mobile-btn-height))';
37 agent.style.bottom = '0';
38 agent.style.zIndex = '9999';
39 document.body.appendChild(agent);
40 render(<Mobile />, agent);
41 });
42
43 // In editor
44 registerPlugin('extendify-agent-buttons', {
45 render: () => <AgentButton />,
46 });
47 const AgentButton = () => {
48 useEffect(() => {
49 if (isOnLaunch()) return;
50 const id = 'extendify-agent-editor-btn';
51 if (document.getElementById(id)) return;
52
53 const agent = Object.assign(document.createElement('span'), {
54 className: 'extendify-agent',
55 id,
56 });
57 requestAnimationFrame(() => {
58 requestAnimationFrame(() => {
59 if (document.getElementById(id)) return;
60 const page = '[aria-controls="edit-post:document"]';
61 const fse = '[aria-controls="edit-site:template"]';
62 document.querySelector(page)?.after(agent);
63 document.querySelector(fse)?.after(agent);
64 render(<PostEditor />, agent);
65 });
66 });
67 }, []);
68 return null;
69 };
70