PluginProbe
Extendify / 3.1.5
Extendify v3.1.5
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 / Recommendations / recommendations.js

recommendations.js in Extendify 3.1.5, at src/Recommendations/recommendations.js

60 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { PluginSearchBanner } from '@recommendations/components/PluginSearchBanner';
2 import domReady from '@wordpress/dom-ready';
3 import '@recommendations/recommendations.css';
4 import { render } from '@shared/lib/dom';
5
6 domReady(() => {
7 // Check the current page to know what elements we need to insert.
8 const currentUrl = new URL(window.location.href);
9 const isPluginInstall = currentUrl.pathname.endsWith('plugin-install.php');
10 const isNewPost =
11 currentUrl.pathname.endsWith('post-new.php') &&
12 currentUrl.searchParams.get('post_type') !== 'page';
13 const isNewPage =
14 currentUrl.pathname.endsWith('post-new.php') &&
15 currentUrl.searchParams.get('post_type') === 'page';
16
17 // Returns early if we are not in a page that shows recommendations.
18 if (!isPluginInstall && !isNewPost && !isNewPage) {
19 return;
20 }
21
22 if (isPluginInstall) {
23 // The element `plugin-filter` wraps the search results,
24 const pluginResults = document.getElementById('plugin-filter');
25
26 if (pluginResults) {
27 const pluginSearchContainerId = 'ext-recommendations-plugin-search';
28
29 // If our component is already inserted, return early.
30 if (document.getElementById(pluginSearchContainerId)) {
31 return;
32 }
33
34 const pluginSearchContainer = Object.assign(
35 document.createElement('div'),
36 {
37 id: pluginSearchContainerId,
38 className: 'extendify-recommendations',
39 },
40 );
41
42 // Inserts our component just before the plugin search results.
43 pluginResults.parentNode.insertBefore(
44 pluginSearchContainer,
45 pluginResults,
46 );
47
48 return render(<PluginSearchBanner />, pluginSearchContainer);
49 }
50 }
51
52 if (isNewPost) {
53 // TODO: Implement injection of components in new post.
54 }
55
56 if (isNewPage) {
57 // TODO: Implement injection of components in new page.
58 }
59 });
60