Skip to content

Commit 94b4dd5

Browse files
added elementor editor support
1 parent 153e607 commit 94b4dd5

2 files changed

Lines changed: 27 additions & 9 deletions

File tree

plugin/handle-css-request.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,23 @@ function cache_everything_handle_css_request() {
1919
array_push($all_roles, 'guest', 'user');
2020

2121
foreach ($all_roles as $slug) {
22-
// Now $slug correctly represents each role slug
23-
// Added !important to ensure this rule overrides others
24-
echo ".$site_prefix-$slug { display: none !important; }\n";
25-
}
22+
// Only apply the rule when the Elementor editor is not active
23+
echo "body:not(.elementor-editor-active) .$site_prefix-$slug { display: none !important; }\n";
24+
25+
// Ensure the parent element is positioned relatively
26+
echo "body.elementor-editor-active .$site_prefix-$slug { position: relative; }\n";
2627

28+
// Apply the rule specifically when the Elementor editor is active
29+
echo "body.elementor-editor-active .$site_prefix-$slug::after {
30+
content: '👁️';
31+
position: absolute;
32+
top: 0;
33+
right: 0;
34+
font-size: 20px; /* Adjust size as needed */
35+
z-index: 1000; /* Ensure it's above other content */
36+
pointer-events: none; /* Allows clicking through the icon */
37+
}\n";
38+
}
2739
exit;
2840
}
2941
}

plugin/public/js/cache-everything.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ document.addEventListener('DOMContentLoaded', function() {
4242
* @param {string} stylesheetId - The ID of the stylesheet from which to delete the rules.
4343
*/
4444
function deleteCSSRules(selectorText, stylesheetId) {
45+
// Modify the selector to include the new condition
46+
const modifiedSelectorText = `body:not(.elementor-editor-active) ${selectorText}`;
47+
4548
// Find the specified stylesheet by ID
4649
const styleSheet = [...document.styleSheets].find(
4750
sheet => sheet.ownerNode.id === stylesheetId
@@ -58,7 +61,7 @@ function deleteCSSRules(selectorText, stylesheetId) {
5861

5962
// Since deleting a rule shifts subsequent rules' indices, iterate backwards
6063
for (let i = rules.length - 1; i >= 0; i--) {
61-
if (rules[i].selectorText === selectorText) {
64+
if (rules[i].selectorText === modifiedSelectorText) {
6265
// Log the rule that is about to be deleted
6366
debugPrint(`Deleting CSS rule: ${rules[i].cssText}`);
6467
// Delete the rule
@@ -68,7 +71,7 @@ function deleteCSSRules(selectorText, stylesheetId) {
6871
}
6972

7073
if (!found) {
71-
console.warn(`No CSS rule found for selector "${selectorText}" in stylesheet with ID "${stylesheetId}".`);
74+
console.warn(`No CSS rule found for selector "${modifiedSelectorText}" in stylesheet with ID "${stylesheetId}".`);
7275
}
7376
}
7477

@@ -83,6 +86,9 @@ function deleteCSSRules(selectorText, stylesheetId) {
8386
* @param {string} ruleContent - The content of the CSS rule to add.
8487
*/
8588
function addCSSRules(selectorText, stylesheetId, ruleContent) {
89+
// Modify the selector to include the new condition
90+
const modifiedSelectorText = `body:not(.elementor-editor-active) ${selectorText}`;
91+
8692
// Find the specified stylesheet by ID
8793
const styleSheet = [...document.styleSheets].find(
8894
sheet => sheet.ownerNode.id === stylesheetId
@@ -95,16 +101,16 @@ function addCSSRules(selectorText, stylesheetId, ruleContent) {
95101

96102
// Check if a rule with the given selector already exists
97103
const existingRuleIndex = Array.from(styleSheet.cssRules).findIndex(
98-
rule => rule.selectorText === selectorText
104+
rule => rule.selectorText === modifiedSelectorText
99105
);
100106

101107
// If the rule does not already exist, add it
102108
if (existingRuleIndex === -1) {
103-
const fullRule = `${selectorText} { ${ruleContent} }`;
109+
const fullRule = `${modifiedSelectorText} { ${ruleContent} }`;
104110
styleSheet.insertRule(fullRule, styleSheet.cssRules.length);
105111
debugPrint(`Added new CSS rule: ${fullRule}`);
106112
} else {
107-
debugPrint(`CSS rule for selector "${selectorText}" already exists. No action taken.`);
113+
debugPrint(`CSS rule for selector "${modifiedSelectorText}" already exists. No action taken.`);
108114
}
109115
}
110116

0 commit comments

Comments
 (0)