PluginProbe
Extendify / 1.9.3
Extendify v1.9.3
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 / Library / buttons.js

buttons.js in Extendify 1.9.3, at src/Library/buttons.js

54 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { subscribe } from '@wordpress/data'
2 import { render } from '@wordpress/element'
3 import { CtaButton, MainButtonWrapper } from '@library/components/MainButtons'
4
5 const userState = window.extendifyData?.user?.state
6 const isAdmin = () => window.extendifyData.user === null || userState?.isAdmin
7
8 // Add the MAIN button when Gutenberg is available and ready
9 subscribe(() => {
10 requestAnimationFrame(() => {
11 if (document.getElementById('extendify-templates-inserter')) {
12 return
13 }
14 if (
15 !document.querySelector('.edit-post-header-toolbar') &&
16 !document.querySelector('.edit-site-header-edit-mode__start') // FSE
17 ) {
18 return
19 }
20 const buttonContainer = Object.assign(document.createElement('div'), {
21 id: 'extendify-templates-inserter',
22 })
23 // Standard block editor
24 document
25 .querySelector('.edit-post-header-toolbar')
26 ?.append(buttonContainer)
27 // FSE block editor
28 document
29 .querySelector('.edit-site-header-edit-mode__start')
30 ?.append(buttonContainer)
31
32 render(<MainButtonWrapper />, buttonContainer)
33 })
34 })
35
36 // The CTA button inside patterns
37 subscribe(() => {
38 requestAnimationFrame(() => {
39 if (!isAdmin()) return
40 if (!document.querySelector('[id$=patterns-view]')) return
41 if (document.getElementById('extendify-cta-button')) return
42
43 const ctaButtonContainer = Object.assign(
44 document.createElement('div'),
45 { id: 'extendify-cta-button-container' },
46 )
47
48 document
49 .querySelector('[id$=patterns-view]')
50 .prepend(ctaButtonContainer)
51 render(<CtaButton />, ctaButtonContainer)
52 })
53 })
54