Переглянути джерело

allow demos without scripts (silly)

Heydon Pickering 7 роки тому
батько
коміт
b7d0f50487

+ 8 - 5
docs/patterns/coding/writing-inline-demos/index.html

@@ -512,7 +512,9 @@ toggle.addEventListener('click', function () {
       var demoDiv = document.createElement('div');
       demoDiv.innerHTML = template.innerHTML;
       var standaloneScript = demoDiv.querySelector('script');
-      standaloneScript.textContent = '(function() { document.getElementsByTagName(\'html\')[0].setAttribute(\'lang\', \'en\'); var demo = document; ' + standaloneScript.textContent + ' })();';
+      if (standaloneScript) {
+        standaloneScript.textContent = '(function() { document.getElementsByTagName(\'html\')[0].setAttribute(\'lang\', \'en\'); var demo = document; ' + standaloneScript.textContent + ' })();';
+      }
 
       if (document.head.attachShadow) {
         var templateScript = template.content.querySelector('script');
@@ -534,10 +536,11 @@ toggle.addEventListener('click', function () {
         
         var newScript = standalone.document.createElement('script');
         var oldScript = standalone.document.querySelector('script');
-        newScript.textContent = oldScript.textContent;
-        oldScript.parentNode.removeChild(oldScript);
-        standalone.document.body.appendChild(newScript);
-
+        if (oldScript) {
+          newScript.textContent = oldScript.textContent;
+          oldScript.parentNode.removeChild(oldScript);
+          standalone.document.body.appendChild(newScript);
+        }
         
 
         standalone.document.title = 'demo ' + "285170a1c0812ad34ac4b853a052c8bd";

+ 8 - 5
docs/print-version/index.html

@@ -1879,7 +1879,9 @@ toggle.addEventListener('click', function () {
       var demoDiv = document.createElement('div');
       demoDiv.innerHTML = template.innerHTML;
       var standaloneScript = demoDiv.querySelector('script');
-      standaloneScript.textContent = '(function() { document.getElementsByTagName(\'html\')[0].setAttribute(\'lang\', \'en\'); var demo = document; ' + standaloneScript.textContent + ' })();';
+      if (standaloneScript) {
+        standaloneScript.textContent = '(function() { document.getElementsByTagName(\'html\')[0].setAttribute(\'lang\', \'en\'); var demo = document; ' + standaloneScript.textContent + ' })();';
+      }
 
       if (document.head.attachShadow) {
         var templateScript = template.content.querySelector('script');
@@ -1901,10 +1903,11 @@ toggle.addEventListener('click', function () {
         
         var newScript = standalone.document.createElement('script');
         var oldScript = standalone.document.querySelector('script');
-        newScript.textContent = oldScript.textContent;
-        oldScript.parentNode.removeChild(oldScript);
-        standalone.document.body.appendChild(newScript);
-
+        if (oldScript) {
+          newScript.textContent = oldScript.textContent;
+          oldScript.parentNode.removeChild(oldScript);
+          standalone.document.body.appendChild(newScript);
+        }
         
 
         standalone.document.title = 'demo ' + "285170a1c0812ad34ac4b853a052c8bd";

Різницю між файлами не показано, бо вона завелика
+ 0 - 0
docs/service-worker.js


+ 8 - 5
themes/infusion/layouts/shortcodes/demo.html

@@ -25,7 +25,9 @@
       var demoDiv = document.createElement('div');
       demoDiv.innerHTML = template.innerHTML;
       var standaloneScript = demoDiv.querySelector('script');
-      standaloneScript.textContent = '(function() { document.getElementsByTagName(\'html\')[0].setAttribute(\'lang\', \'en\'); var demo = document; ' + standaloneScript.textContent + ' })();';
+      if (standaloneScript) {
+        standaloneScript.textContent = '(function() { document.getElementsByTagName(\'html\')[0].setAttribute(\'lang\', \'en\'); var demo = document; ' + standaloneScript.textContent + ' })();';
+      }
 
       if (document.head.attachShadow) {
         var templateScript = template.content.querySelector('script');
@@ -47,10 +49,11 @@
         // For activating the script :-(
         var newScript = standalone.document.createElement('script');
         var oldScript = standalone.document.querySelector('script');
-        newScript.textContent = oldScript.textContent;
-        oldScript.parentNode.removeChild(oldScript);
-        standalone.document.body.appendChild(newScript);
-
+        if (oldScript) {
+          newScript.textContent = oldScript.textContent;
+          oldScript.parentNode.removeChild(oldScript);
+          standalone.document.body.appendChild(newScript);
+        }
         {{ if .Get "backgroundColor" }}
           standalone.document.body.style.backgroundColor = {{ .Get "backgroundColor" | safeCSS }};
         {{ end }}

Деякі файли не було показано, через те що забагато файлів було змінено