This PR adds a simple options object to the constructor, with one parameter: ready. This parameter is a function which takes two arguments: error and id. error is null or undefined if HRMViewer is ready, otherwise it contains the error message. The id argument echos back the DOM ID of the element to differentiate code viewers.
This should help end users with logical errors as detailed in #5.
Used like:
var hrmv;
function codeViewerLoaded(error, id) {
if (error) {
// present the error?
}
else {
hrmv.setActiveLine(5);
}
}
function fonts_loaded() {
hrmv = new HRMViewer('code', 'asm/program.asm', { ready: codeViewerLoaded });
}
WebFont.load({
google: { families: ['Passion One'] },
active: fonts_loaded,
inactive: fonts_loaded,
});
Another idea would be to have separate success/failure callbacks (success(id), failure(id, error)), or rather than id pass this to the callback.
This PR adds a simple options object to the constructor, with one parameter:
ready
. This parameter is a function which takes two arguments:error
andid
. error isnull
orundefined
if HRMViewer is ready, otherwise it contains the error message. Theid
argument echos back the DOM ID of the element to differentiate code viewers.This should help end users with logical errors as detailed in #5.
Used like:
Another idea would be to have separate success/failure callbacks (
success(id)
,failure(id, error)
), or rather thanid
passthis
to the callback.