The library, called LoadForCompile, is invoked with a MIME type and a callback. It searches the DOM for script elements with the given MIME type, loads their sources, and passes them to the callback. There is a very simple demo page with a "compiler" that displays whatever source code it is provided. Following is the documentation for the library.
LoadForCompile will retrieve alternate-language source code and pass it (in order) to
onLoad. Any sources that cannot be retrieved will be ignored by default.
onFinish argument is provided, it will be called when all sources have been loaded and passed.
onError argument is provided, it will be called with
(src, k), where
src is the offending URL and
k is a continuation of the loading process, so the relying client may continue or entirely halt the loading process by calling
k or not calling it, respectively.
- Place script elements in your HTML document with desired MIME type.
- Each script element may have a
srcattribute, an inline body between the opening and closing tags, or both. The body is guaranteed to be called immediately after the associated remote source, or not at all.
- Finally, call LoadForCompile with the MIME type and callbacks.
LoadForCompile searches the DOM for any script nodes bearing the target MIME type. For each one, it records the src attribute and the contents of the text node, if any. It is an error to have non-text elements as children of the script node, and in such a situation the behavior of this library is unspecified.
The library uses asynchronous requests to load any remote resources specified by
src attributes. This loading occurs in an unspecified order. If any remote source fails to load, the library will mark that source (and any associated inline body) as invalid. If
onError is provided, it will be called with a continuation function that will resume progress. (If the continuation is not called, no additional callbacks will be made.)
Note that if
onError is provided and does not call the continuation,
onFinish will not be called.
The library is in version 0.2 and is licensed under the LGPL.