Forum Discussion

RyanZwicker's avatar
RyanZwicker
Community Member
4 years ago

touch screen interface on 360 content.

Hello everyone, 

We have created a some of the new 360 image content with clickable nodes to fire open images and titles of items around the 360 photo's. We found out after we started developing that the client is using touch screens. When launching the content on the touch screens, the clickable nodes do not seem to function by touching them on the screen, only by clicking with a mouse, or the pad. 

Trying to search for help on touch screen capabilities is not turning anything up specific to the new 360 content. Just trying to see if this functionality is left out of those specific nodes, or did i miss a step.

Any help or links would be appreciated. 

18 Replies

    • WesleyAdams's avatar
      WesleyAdams
      Community Member

      I haven't heard of Rive. Thanks! I'll take a look and post if I find anything. 

      I've also been looking into "Pannellum" for 360 tours as it's open source:
      https://pannellum.org/

      If it works with touch commands, we may be able to embed as a web object into SL360.  

  • HarryT's avatar
    HarryT
    Community Member

    Hi all

    I've found the same issue and have been working with 360 images as a key part of a couple of projects. This morning I found a solution (via CoPilot) that works on both my organisation's Lenovo touchscreen ThinkPads and tru Digital touch screens (only devices I was having issues with). I have execute Javascript prompts on each page that uses a 360 image viewer and converts screen touches into a mouse input for panning movement. This code also allows hotspots to view layers (via sewt triggers within the 360 viewer) although I have not tested if these still work for labels and tooltips that appear on hover will not work.

    Unfortunately I am unable to share this working in practice in the form of a review or source files due to NDA's and corporate ownership but please feel free to give it a go.

    Hope this helps (I know theres a lot to digest here) and best of luck with your projects. Hope Articulate can work on this for a built in and less demanding solution.

    (function () {
      // ============================================================
      // Storyline 360 Touch -> Mouse bridge (viewer-scoped version)
      // Only handles touch interactions that begin inside a detected
      // 360 viewer container. Ignores all other slide objects.
      // ============================================================
    
      // ------------------------------------------------------------
      // CONFIGURATION
      // ------------------------------------------------------------
    
      // Add / adjust selectors here if your published Storyline output
      // uses a more specific wrapper for the 360 image object.
      var VIEWER_SELECTORS = [
        // Generic Storyline / HTML object possibilities
        '[data-acc-text*="360"]',
        '[aria-label*="360"]',
        '[title*="360"]',
        '[alt*="360"]',
        '[class*="360"]',
        '[id*="360"]',
    
        // Media / object wrappers that may contain the viewer
        '.slide-object',
        '.storyline-object',
        '.html-object',
        '.video-object',
        '.media-object'
      ];
    
      // Treat movement under this threshold as a tap/click
      var DRAG_THRESHOLD = 10;
    
      // Retry detecting the viewer for a short time after the slide starts
      // in case Storyline builds the object slightly after timeline start.
      var DETECTION_RETRIES = 40;
      var DETECTION_INTERVAL = 250;
    
      // ------------------------------------------------------------
      // SHARED STATE
      // ------------------------------------------------------------
    
      if (!window.__storyline360ScopedBridge) {
        window.__storyline360ScopedBridge = {
          installed: false,
          enabled: false,
          viewerRoot: null,
          touchSession: null,
          observer: null
        };
      }
    
      var bridge = window.__storyline360ScopedBridge;
    
      // ------------------------------------------------------------
      // HELPER FUNCTIONS
      // ------------------------------------------------------------
    
      function uniqueSelectors(list) {
        return list.filter(function (item, index) {
          return list.indexOf(item) === index;
        });
      }
    
      function getCustomSelectors() {
        // Optional: allow a slide-specific selector override
        // Example:
        // window.__storyline360CustomSelectors = ['#my360Object'];
        if (Array.isArray(window.__storyline360CustomSelectors)) {
          return window.__storyline360CustomSelectors;
        }
        return [];
      }
    
      function getAllViewerSelectors() {
        return uniqueSelectors(getCustomSelectors().concat(VIEWER_SELECTORS));
      }
    
      function isVisible(el) {
        if (!el) return false;
        var style = window.getComputedStyle(el);
        return (
          style.display !== "none" &&
          style.visibility !== "hidden" &&
          el.offsetWidth > 0 &&
          el.offsetHeight > 0
        );
      }
    
      function closestMatchingAncestor(el, selectors) {
        if (!el || !selectors.length) return null;
    
        for (var i = 0; i < selectors.length; i++) {
          try {
            var match = el.closest(selectors[i]);
            if (match && isVisible(match)) {
              return match;
            }
          } catch (err) {
            // Ignore invalid selector errors just in case
          }
        }
    
        return null;
      }
    
      function getElementAtPoint(x, y) {
        return document.elementFromPoint(x, y);
      }
    
      function detectViewerRoot() {
        var selectors = getAllViewerSelectors();
    
        // First pass: query all possible candidates
        for (var i = 0; i < selectors.length; i++) {
          var nodes;
          try {
            nodes = document.querySelectorAll(selectors[i]);
          } catch (err) {
            continue;
          }
    
          for (var j = 0; j < nodes.length; j++) {
            var node = nodes[j];
            if (!isVisible(node)) continue;
    
            // Heuristic: prefer bigger interactive display areas
            var rect = node.getBoundingClientRect();
            if (rect.width > 120 && rect.height > 120) {
              return node;
            }
          }
        }
    
        return null;
      }
    
      function setViewerInteractionStyles(viewerRoot) {
        if (!viewerRoot) return;
    
        viewerRoot.style.touchAction = "none";
        viewerRoot.style.msTouchAction = "none";
        viewerRoot.style.webkitUserSelect = "none";
        viewerRoot.style.userSelect = "none";
        viewerRoot.style.webkitTouchCallout = "none";
      }
    
      function pointWithinElement(x, y, el) {
        if (!el) return false;
        var rect = el.getBoundingClientRect();
        return (
          x >= rect.left &&
          x <= rect.right &&
          y >= rect.top &&
          y <= rect.bottom
        );
      }
    
      function getInjectedTargetForTouch(touch, viewerRoot) {
        var rawTarget = getElementAtPoint(touch.clientX, touch.clientY);
    
        if (!rawTarget || !viewerRoot) return viewerRoot;
    
        // If the touched element is inside the viewer, allow it
        if (viewerRoot === rawTarget || viewerRoot.contains(rawTarget)) {
          return rawTarget;
        }
    
        // If elementAtPoint returns something nested oddly, walk up to a matching ancestor
        var matchedAncestor = closestMatchingAncestor(rawTarget, getAllViewerSelectors());
        if (matchedAncestor && (matchedAncestor === viewerRoot || viewerRoot.contains(matchedAncestor))) {
          return matchedAncestor;
        }
    
        // Otherwise, force events to the viewer container to support dragging
        return viewerRoot;
      }
    
      function createMouseEvent(type, touch) {
        return new MouseEvent(type, {
          bubbles: true,
          cancelable: true,
          view: window,
          clientX: touch.clientX,
          clientY: touch.clientY,
          screenX: touch.screenX || 0,
          screenY: touch.screenY || 0,
          button: 0,
          buttons: 1
        });
      }
    
      function dispatchMouse(type, touch, target) {
        if (!touch || !target) return;
        target.dispatchEvent(createMouseEvent(type, touch));
      }
    
      function clearTouchSession() {
        bridge.touchSession = null;
      }
    
      function beginTouchSession(touch, viewerRoot, target) {
        bridge.touchSession = {
          startX: touch.clientX,
          startY: touch.clientY,
          lastX: touch.clientX,
          lastY: touch.clientY,
          viewerRoot: viewerRoot,
          startTarget: target,
          lastTarget: target
        };
      }
    
      function updateTouchSession(touch, target) {
        if (!bridge.touchSession) return;
        bridge.touchSession.lastX = touch.clientX;
        bridge.touchSession.lastY = touch.clientY;
        bridge.touchSession.lastTarget = target;
      }
    
      function isTapGesture(touchSession, touch) {
        if (!touchSession || !touch) return false;
        var deltaX = Math.abs(touch.clientX - touchSession.startX);
        var deltaY = Math.abs(touch.clientY - touchSession.startY);
        return deltaX < DRAG_THRESHOLD && deltaY < DRAG_THRESHOLD;
      }
    
      function enableBridgeForViewer(viewerRoot) {
        bridge.viewerRoot = viewerRoot;
        bridge.enabled = true;
        setViewerInteractionStyles(viewerRoot);
      }
    
      function disableBridge() {
        bridge.enabled = false;
        bridge.viewerRoot = null;
        clearTouchSession();
      }
    
      function scanAndEnableViewer() {
        var viewer = detectViewerRoot();
        if (viewer) {
          enableBridgeForViewer(viewer);
          return true;
        }
        return false;
      }
    
      function watchForViewerChanges() {
        if (bridge.observer) {
          bridge.observer.disconnect();
          bridge.observer = null;
        }
    
        bridge.observer = new MutationObserver(function () {
          if (!bridge.viewerRoot || !document.body.contains(bridge.viewerRoot)) {
            var found = detectViewerRoot();
            if (found) {
              enableBridgeForViewer(found);
            } else {
              disableBridge();
            }
          }
        });
    
        bridge.observer.observe(document.body, {
          childList: true,
          subtree: true,
          attributes: true
        });
      }
    
      // ------------------------------------------------------------
      // EVENT HANDLERS
      // ------------------------------------------------------------
    
      function onTouchStart(e) {
        if (!bridge.enabled || !bridge.viewerRoot) return;
        if (!e.changedTouches || !e.changedTouches.length) return;
        if (e.touches && e.touches.length > 1) return; // ignore multi-touch
    
        var touch = e.changedTouches[0];
    
        // Only start handling if touch begins inside the 360 viewer
        if (!pointWithinElement(touch.clientX, touch.clientY, bridge.viewerRoot)) {
          return;
        }
    
        var target = getInjectedTargetForTouch(touch, bridge.viewerRoot);
    
        beginTouchSession(touch, bridge.viewerRoot, target);
    
        // Prevent native browser gestures only for the viewer touch interaction
        e.preventDefault();
    
        dispatchMouse("mouseover", touch, target);
        dispatchMouse("mousemove", touch, target);
        dispatchMouse("mousedown", touch, target);
      }
    
      function onTouchMove(e) {
        if (!bridge.enabled || !bridge.viewerRoot || !bridge.touchSession) return;
        if (!e.changedTouches || !e.changedTouches.length) return;
    
        var touch = e.changedTouches[0];
        var target = getInjectedTargetForTouch(touch, bridge.touchSession.viewerRoot);
    
        updateTouchSession(touch, target);
    
        e.preventDefault();
        dispatchMouse("mousemove", touch, target);
      }
    
      function onTouchEnd(e) {
        if (!bridge.enabled || !bridge.viewerRoot || !bridge.touchSession) return;
        if (!e.changedTouches || !e.changedTouches.length) return;
    
        var touch = e.changedTouches[0];
        var target = getInjectedTargetForTouch(touch, bridge.touchSession.viewerRoot);
    
        e.preventDefault();
    
        dispatchMouse("mouseup", touch, target);
    
        // Only click if gesture remained essentially a tap
        if (isTapGesture(bridge.touchSession, touch)) {
          dispatchMouse("click", touch, target);
        }
    
        clearTouchSession();
      }
    
      function onTouchCancel(e) {
        if (!bridge.enabled || !bridge.touchSession) return;
        if (!e.changedTouches || !e.changedTouches.length) return;
    
        var touch = e.changedTouches[0];
        var target = bridge.touchSession.lastTarget || bridge.touchSession.viewerRoot;
    
        dispatchMouse("mouseup", touch, target);
        clearTouchSession();
      }
    
      // ------------------------------------------------------------
      // INSTALL GLOBAL LISTENERS ONCE
      // ------------------------------------------------------------
    
      if (!bridge.installed) {
        document.addEventListener("touchstart", onTouchStart, {
          passive: false,
          capture: true
        });
    
        document.addEventListener("touchmove", onTouchMove, {
          passive: false,
          capture: true
        });
    
        document.addEventListener("touchend", onTouchEnd, {
          passive: false,
          capture: true
        });
    
        document.addEventListener("touchcancel", onTouchCancel, {
          passive: false,
          capture: true
        });
    
        bridge.installed = true;
      }
    
      // ------------------------------------------------------------
      // ACTIVATE ONLY IF A VIEWER EXISTS ON THIS SLIDE
      // ------------------------------------------------------------
    
      disableBridge();
    
      var attempts = 0;
      var timer = setInterval(function () {
        attempts++;
    
        if (scanAndEnableViewer() || attempts >= DETECTION_RETRIES) {
          clearInterval(timer);
          watchForViewerChanges();
        }
      }, DETECTION_INTERVAL);
    })();

    Many thanks,
    Harry