You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2022/01/31 16:40:04 UTC

[sling-org-apache-sling-dynamic-include] 03/03: SLING-11087: Added IIFE design pattern to isolate variable scope.

This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-dynamic-include.git

commit d72b485646c468396df03aa275261493859845ac
Author: Jakob Rosenlund <ja...@miracle.dk>
AuthorDate: Wed Jan 26 12:22:02 2022 +0100

    SLING-11087: Added IIFE design pattern to isolate variable scope.
---
 src/main/resources/generators/javascript.html | 29 ++++++++++++++-------------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/src/main/resources/generators/javascript.html b/src/main/resources/generators/javascript.html
index f4d8358..abd7f84 100755
--- a/src/main/resources/generators/javascript.html
+++ b/src/main/resources/generators/javascript.html
@@ -18,20 +18,21 @@
 -->
 <div id="${uniqueId}">
     <script type="text/javascript">
-        if (window.XMLHttpRequest) {
-            var xhr = new XMLHttpRequest();
-            xhr.open('GET', encodeURI("${url}"));
-            xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
-            xhr.timeout = 10000;
-            xhr.onload = function () {
-                if (xhr.status >= 200 && xhr.status < 300) {
-                    var elemId = document.getElementById('${uniqueId}');
-                    if (elemId) elemId.innerHTML = xhr.responseText;
-                }
-            };
-            xhr.send();
-        }
-
+		(function () {
+            if (window.XMLHttpRequest) {
+                var xhr = new XMLHttpRequest();
+                xhr.open('GET', encodeURI("${url}"));
+                xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
+                xhr.timeout = 10000;
+                xhr.onload = function () {
+                    if (xhr.status >= 200 && xhr.status < 300) {
+                        var elemId = document.getElementById('${uniqueId}');
+                        if (elemId) elemId.innerHTML = xhr.responseText;
+                    }
+                };
+                xhr.send();
+            }
+		})();
     </script>
     <noscript>Your browser does not support JavaScript. Some components may not be visible.</noscript>
 </div>