|
29 | 29 | * exported functions. |
30 | 30 | */ |
31 | 31 | function RemoteFunctions(config = {}) { |
| 32 | + |
| 33 | + const GLOBALS = { |
| 34 | + // given to internal elements like info box, options box, image gallery and all other phcode internal elements |
| 35 | + // to distinguish between phoenix internal vs user created elements |
| 36 | + PHCODE_INTERNAL_ATTR: "data-phcode-internal-c15r5a9" |
| 37 | + }; |
| 38 | + |
32 | 39 | // this will store the element that was clicked previously (before the new click) |
33 | 40 | // we need this so that we can remove click styling from the previous element when a new element is clicked |
34 | 41 | let previouslyClickedElement = null; |
@@ -132,7 +139,7 @@ function RemoteFunctions(config = {}) { |
132 | 139 | if(element && // element should exist |
133 | 140 | element.tagName.toLowerCase() !== "body" && // shouldn't be the body tag |
134 | 141 | element.tagName.toLowerCase() !== "html" && // shouldn't be the HTML tag |
135 | | - !element.closest("[data-phcode-internal-c15r5a9]") && // this attribute is used by phoenix internal elements |
| 142 | + !element.closest(`[${GLOBALS.PHCODE_INTERNAL_ATTR}]`) && // this attribute is used by phoenix internal elements |
136 | 143 | !_isInsideHeadTag(element)) { // shouldn't be inside the head tag like meta tags and all |
137 | 144 | return true; |
138 | 145 | } |
@@ -1583,7 +1590,7 @@ function RemoteFunctions(config = {}) { |
1583 | 1590 |
|
1584 | 1591 | _style: function() { |
1585 | 1592 | this.body = window.document.createElement("div"); |
1586 | | - this.body.setAttribute("data-phcode-internal-c15r5a9", "true"); |
| 1593 | + this.body.setAttribute(GLOBALS.PHCODE_INTERNAL_ATTR, "true"); |
1587 | 1594 |
|
1588 | 1595 | // this is shadow DOM. |
1589 | 1596 | // we need it because if we add the box directly to the DOM then users style might override it. |
@@ -1789,7 +1796,7 @@ function RemoteFunctions(config = {}) { |
1789 | 1796 |
|
1790 | 1797 | // Create shadow DOM container |
1791 | 1798 | this.body = document.createElement('div'); |
1792 | | - this.body.setAttribute('data-phcode-internal-c15r5a9', '1'); |
| 1799 | + this.body.setAttribute(GLOBALS.PHCODE_INTERNAL_ATTR, "true"); |
1793 | 1800 | document.body.appendChild(this.body); |
1794 | 1801 |
|
1795 | 1802 | const shadow = this.body.attachShadow({ mode: 'open' }); |
@@ -2053,7 +2060,7 @@ function RemoteFunctions(config = {}) { |
2053 | 2060 |
|
2054 | 2061 | _style: function() { |
2055 | 2062 | this.body = window.document.createElement("div"); |
2056 | | - this.body.setAttribute("data-phcode-internal-c15r5a9", "true"); |
| 2063 | + this.body.setAttribute(GLOBALS.PHCODE_INTERNAL_ATTR, "true"); |
2057 | 2064 |
|
2058 | 2065 | const shadow = this.body.attachShadow({ mode: "open" }); |
2059 | 2066 |
|
@@ -2327,7 +2334,7 @@ function RemoteFunctions(config = {}) { |
2327 | 2334 |
|
2328 | 2335 | _style: function() { |
2329 | 2336 | this.body = window.document.createElement("div"); |
2330 | | - this.body.setAttribute("data-phcode-internal-c15r5a9", "true"); |
| 2337 | + this.body.setAttribute(GLOBALS.PHCODE_INTERNAL_ATTR, "true"); |
2331 | 2338 |
|
2332 | 2339 | // this is shadow DOM. |
2333 | 2340 | // we need it because if we add the box directly to the DOM then users style might override it. |
@@ -2541,7 +2548,7 @@ function RemoteFunctions(config = {}) { |
2541 | 2548 |
|
2542 | 2549 | _style: function() { |
2543 | 2550 | this.body = window.document.createElement("div"); |
2544 | | - this.body.setAttribute("data-phcode-internal-c15r5a9", "true"); |
| 2551 | + this.body.setAttribute(GLOBALS.PHCODE_INTERNAL_ATTR, "true"); |
2545 | 2552 | // using shadow dom so that user styles doesn't override it |
2546 | 2553 | const shadow = this.body.attachShadow({ mode: "open" }); |
2547 | 2554 |
|
@@ -2911,7 +2918,7 @@ function RemoteFunctions(config = {}) { |
2911 | 2918 | ImageRibbonGallery.prototype = { |
2912 | 2919 | _style: function () { |
2913 | 2920 | this.body = window.document.createElement("div"); |
2914 | | - this.body.setAttribute("data-phcode-internal-c15r5a9", "true"); |
| 2921 | + this.body.setAttribute(GLOBALS.PHCODE_INTERNAL_ATTR, "true"); |
2915 | 2922 | this._shadow = this.body.attachShadow({ mode: 'open' }); |
2916 | 2923 |
|
2917 | 2924 | this._shadow.innerHTML = ` |
@@ -4303,7 +4310,7 @@ function RemoteFunctions(config = {}) { |
4303 | 4310 |
|
4304 | 4311 | const makeDiv = () => { |
4305 | 4312 | const el = document.createElement("div"); |
4306 | | - el.setAttribute("data-phcode-internal-c15r5a9", "true"); |
| 4313 | + el.setAttribute(GLOBALS.PHCODE_INTERNAL_ATTR, "true"); |
4307 | 4314 | return el; |
4308 | 4315 | }; |
4309 | 4316 |
|
@@ -4449,7 +4456,7 @@ function RemoteFunctions(config = {}) { |
4449 | 4456 |
|
4450 | 4457 | // create overlay container |
4451 | 4458 | const overlay = window.document.createElement('div'); |
4452 | | - overlay.setAttribute('data-phcode-internal-c15r5a9', 'true'); |
| 4459 | + overlay.setAttribute(GLOBALS.PHCODE_INTERNAL_ATTR, 'true'); |
4453 | 4460 |
|
4454 | 4461 | const styles = ` |
4455 | 4462 | <style> |
@@ -4806,7 +4813,7 @@ function RemoteFunctions(config = {}) { |
4806 | 4813 | const element = event.target; |
4807 | 4814 |
|
4808 | 4815 | // WHITELIST: Allow Phoenix internal UI elements to work normally |
4809 | | - if (element.closest("[data-phcode-internal-c15r5a9]")) { |
| 4816 | + if (element.closest(`[${GLOBALS.PHCODE_INTERNAL_ATTR}]`)) { |
4810 | 4817 | return; |
4811 | 4818 | } |
4812 | 4819 |
|
@@ -5520,7 +5527,7 @@ function RemoteFunctions(config = {}) { |
5520 | 5527 | // create a new fresh toast container |
5521 | 5528 | const toast = window.document.createElement('div'); |
5522 | 5529 | toast.id = 'phoenix-toast-notification'; |
5523 | | - toast.setAttribute("data-phcode-internal-c15r5a9", "true"); |
| 5530 | + toast.setAttribute(GLOBALS.PHCODE_INTERNAL_ATTR, "true"); |
5524 | 5531 | const shadow = toast.attachShadow({ mode: 'open' }); |
5525 | 5532 |
|
5526 | 5533 | const styles = ` |
|
0 commit comments