<!-- draw.io -->
{% if getConfig('crowi', 'app:drawioUri') %}
<script type="text/javascript">
  // refs: https://github.com/jgraph/drawio/blob/v13.4.3/etc/build/build.xml#L35-L38
  let url = new URL("{{ getConfig('crowi', 'app:drawioUri') }}");
  let origin = url.origin;
  window.DRAWIO_BASE_URL = origin;
  window.DRAWIO_LIGHTBOX_URL = origin;
  window.STENCIL_PATH = [origin, 'stencils'].join('/');
  window.SHAPES_PATH = [origin, 'shapes'].join('/');
  window.mxBasePath = [origin, 'mxgraph'].join('/');
</script>
{% endif %}

<script type="text/javascript">
  // define callback function invoked by viewer.min.js of draw.io
  // refs: https://github.com/jgraph/drawio/blob/v12.9.1/etc/build/build.xml#L219-L232
  window.onDrawioViewerLoad = function() {
    const DrawioViewer = window.GraphViewer;

    if (DrawioViewer != null) {
      // disable useResizeSensor and checkVisibleState
      //   for preventing resize event by viewer.min.js
      DrawioViewer.useResizeSensor = false;
      DrawioViewer.prototype.checkVisibleState = false;

      // Set responsive option.
      // refs: https://github.com/jgraph/drawio/blob/v13.9.1/src/main/webapp/js/diagramly/GraphViewer.js#L89-L95
      DrawioViewer.prototype.responsive = true;
    }
  };
</script>
