SVGHMI: Allow toggling fulscreen mode my right click or long press. svghmi
authorEdouard Tisserant
Fri, 27 Aug 2021 11:31:32 +0200
branchsvghmi
changeset 3299 8b45d8494fae
parent 3298 e6131894be1d
child 3300 95fe62bfe920
SVGHMI: Allow toggling fulscreen mode my right click or long press.
svghmi/gen_index_xhtml.xslt
svghmi/svghmi.js
--- a/svghmi/gen_index_xhtml.xslt	Tue Aug 24 11:12:41 2021 +0200
+++ b/svghmi/gen_index_xhtml.xslt	Fri Aug 27 11:31:32 2021 +0200
@@ -8226,12 +8226,38 @@
 </xsl:text>
           <xsl:text>
 </xsl:text>
+          <xsl:text>function toggleFullscreen() {
+</xsl:text>
+          <xsl:text>  let elem = document.documentElement;
+</xsl:text>
+          <xsl:text>
+</xsl:text>
+          <xsl:text>  if (!document.fullscreenElement) {
+</xsl:text>
+          <xsl:text>    elem.requestFullscreen().catch(err =&gt; {
+</xsl:text>
+          <xsl:text>      console.log("Error attempting to enable full-screen mode: "+err.message+" ("+err.name+")");
+</xsl:text>
+          <xsl:text>    });
+</xsl:text>
+          <xsl:text>  } else {
+</xsl:text>
+          <xsl:text>    document.exitFullscreen();
+</xsl:text>
+          <xsl:text>  }
+</xsl:text>
+          <xsl:text>}
+</xsl:text>
+          <xsl:text>
+</xsl:text>
           <xsl:text>function prepare_svg() {
 </xsl:text>
           <xsl:text>    // prevents context menu from appearing on right click and long touch
 </xsl:text>
           <xsl:text>    document.body.addEventListener('contextmenu', e =&gt; {
 </xsl:text>
+          <xsl:text>        toggleFullscreen();
+</xsl:text>
           <xsl:text>        e.preventDefault();
 </xsl:text>
           <xsl:text>    });
--- a/svghmi/svghmi.js	Tue Aug 24 11:12:41 2021 +0200
+++ b/svghmi/svghmi.js	Fri Aug 27 11:31:32 2021 +0200
@@ -367,9 +367,22 @@
 var current_page_index;
 var page_node_local_index = hmi_local_index("page_node");
 
+function toggleFullscreen() {
+  let elem = document.documentElement;
+
+  if (!document.fullscreenElement) {
+    elem.requestFullscreen().catch(err => {
+      console.log("Error attempting to enable full-screen mode: "+err.message+" ("+err.name+")");
+    });
+  } else {
+    document.exitFullscreen();
+  }
+}
+
 function prepare_svg() {
     // prevents context menu from appearing on right click and long touch
     document.body.addEventListener('contextmenu', e => {
+        toggleFullscreen();
         e.preventDefault();
     });