This file defines several tools for loading Lurch documents from URLs on the web, specified in a dialog box or specified in the query string of the app on launch.
Source
Members
loadFromURL
Download a file from the web asynchronously, returning a Promise that resolves when the download completes (passing the content of the file as a string) or rejects if the download fails. Note that many servers have cross-origin restrictions that will prevent this, but servers whose purpose is to share files publicly (e.g., GitHub) do not have this problem. So this may fail not only because the URL is invalid or the network is unreachable, but also because the server may reject the request.
Source
openFileInNewWindow
Open a new browser tab, and in that tab load another copy of the Lurch application, and have that copy load into its editor the document whose content is given as argument. This is done by saving that content to a temporary file in the browser's local storage, and using the query string of the new tab to direct it to that temporary file, which that new tab will also delete once it has read it.
Source
Methods
autoOpenLink(source, andDeleteopt) → {string}
Create a URL that will load the Lurch app and then import a document from a given source immediately.
Parameters
-
source
string
the URL or local filename referring to the document that should be opened ("local filename" means in the browser's local storage)
-
andDelete
boolean
<optional>
falsewhether to delete the file after opening it (which makes sense only for local files, not URLs)
Returns
-
string
a URL that points to this Lurch app, but with the given source embedded in the query string, as an instruction to open it
Source
loadFromQueryString(editor)
Check to see if the query string for the current page contains an instruction for loading a file. This can be in one of two formats.
If the query string contains a "load=..." parameter, treat its value as either an URL (and try to load a Lurch document from that URL) or a filename in the browser's local storage (and try to load a Lurch document from there). Place the document in the given editor on success, and report an error with a notification on failure. The priority for how to treat the parameter is as follows.
- If it is a file in the user's browser's local storage, load it and stop.
- If it is a valid URL, load it and stop.
- Try treating it as a relative URL and use the current page's URL as the base from which to make it into an absolute URL. If that produced a valid absolute URL, load it and stop.
- Give up with an error notification.
If the query string contains a "data=..." parameter, treat its value as the base-64 encoding of a document. Decode it into a string containing HTML, and load that document into the given editor.
If the query string has both parameters (which it should not), the "load=..." parameter takes precedence and the "data=..." parameter is ignored.
Parameters
-
editor
tinymce.Editor
the TinyMCE editor instance into which to load the document specified in the query string, if there is one