PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 4.0.4
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v4.0.4
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 2.3.5 2.3.6 2.4.0 2.4.1 2.4.10 2.4.11 2.4.12 2.4.13 2.4.14 2.4.15 2.4.16 2.4.17 2.4.18 2.4.19 2.4.2 2.4.20 2.4.21 All 88 releases
post-carousel / src / blocks / explore-blocks.js

explore-blocks.js in Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News 4.0.4, at src/blocks/explore-blocks.js

84 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 window.addEventListener("load", function () {
2 const url = new URL(window.location.href);
3
4 // ====================
5 // Pattern Library Handler
6 // ====================
7
8 if (url.searchParams.has("sp_pcp_pattern_library")) {
9 function tryClickPatternButton() {
10 const patternButton = document.querySelector(
11 "#smart-post-library-modal-button"
12 );
13 if (patternButton) {
14 patternButton.click();
15 url.searchParams.delete("sp_pcp_pattern_library");
16 history.replaceState(null, "", url.toString());
17 return true;
18 }
19 return false;
20 }
21
22 // Try every 100ms for up to 2 seconds
23 let patternAttempts = 0;
24 const patternInterval = setInterval(() => {
25 patternAttempts++;
26 if (tryClickPatternButton() || patternAttempts > 20) {
27 clearInterval(patternInterval);
28 }
29 }, 100);
30 }
31
32 // ====================
33 // Block Inserter Handler
34 // ====================
35
36 if (!url.searchParams.has("spblock_inserter")) return;
37
38 function tryScroll() {
39 const headings = document.querySelectorAll(".block-editor-inserter__panel-title");
40 const smartPostHeading = Array.from(headings).find(
41 (h) => h.textContent.trim() === "SMART POST"
42 );
43 if (smartPostHeading) {
44 smartPostHeading.scrollIntoView({
45 behavior: "smooth",
46 block: "start",
47 inline: "nearest",
48 });
49 return true;
50 }
51 return false;
52 }
53
54 function tryClick() {
55 const btn = document.querySelector(".editor-document-tools__inserter-toggle");
56 if (btn) {
57 btn.click();
58 url.searchParams.delete("spblock_inserter");
59 history.replaceState(null, "", url.toString());
60
61 // Try to scroll every 100ms for up to 3 seconds
62 let scrollAttempts = 0;
63 const scrollInterval = setInterval(() => {
64 scrollAttempts++;
65 if (tryScroll() || scrollAttempts > 30) {
66 clearInterval(scrollInterval);
67 }
68 }, 100);
69
70 return true;
71 }
72 return false;
73 }
74
75 // Try every 100ms for up to 2 seconds
76 let attempts = 0;
77 const interval = setInterval(() => {
78 attempts++;
79 if (tryClick() || attempts > 20) {
80 clearInterval(interval);
81 }
82 }, 100);
83 });
84