Skip to content

Commit

Permalink
Draft: Think of dialog to confirm whether to load JupyterLight
Browse files Browse the repository at this point in the history
This is not perfect, in particular the `confirm(...)` is a blocking
call, which is not supposed to be used in a OnClik handler as an onclick
handler need to respond fast.

I think this need to be refactored into utilities functions, and
setTimeout(0, callback), and/or Promises.

That way the onClick finishes immediately and does not violate the
timeout limit.

As noted in the comment, the navigator api is experimental, so it woudl
be good to test properly. In Web Inspector  (Firefox and Chome at
least), it is possible to artificially throttle the connection to test
the logic.
  • Loading branch information
Carreau committed Mar 6, 2024
1 parent 518686f commit 4a3b25c
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions jupyterlite_sphinx/jupyterlite_sphinx.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,38 @@ window.jupyterliteConcatSearchParams = (iframeSrc, params) => {
}
};

/*
* This is the callback that will be triggered when a user press the button
* to show this iframe.
*
*/
window.tryExamplesShowIframe = (
examplesContainerId,
iframeContainerId,
iframeParentContainerId,
iframeSrc,
iframeHeight,
) => {
// this is an experimental API
// https://developer.mozilla.org/en-US/docs/Web/API/Navigator/connection
const networkinfo = navigator.connection || {};
const connectiontype = networkinfo.effectiveType || "";
if (
networkinfo.saveData == true ||
connectiontype.indexOf("2g") !== -1 ||
connectiontype.indexOf("3g") !== -1
) {
console.log(
"We detected either a mettered or slow connection. Asking user if they are sure.",
);
const res = confirm(
"Opening JupyterLite may download several hundreds Mb of data. Do you wish to continue ?",
);
if (res === false) {
return;
}
}

const examplesContainer = document.getElementById(examplesContainerId);
const iframeParentContainer = document.getElementById(
iframeParentContainerId,
Expand Down

0 comments on commit 4a3b25c

Please sign in to comment.