Display progress messages as machine XML files are being loaded/processed

This commit is contained in:
Jeff Parsons 2014-10-29 15:23:35 -07:00 committed by jeffpar
commit eec10da1b7
6 changed files with 39 additions and 36 deletions

View file

@ -1,7 +1,7 @@
PCjs Documentation PCjs Documentation
--- ---
[PCjs](/docs/about/pcjs/) is a full-featured IBM PC and PC XT simulator written entirely in JavaScript. [PCjs](/docs/about/pcjs/) is a full-featured IBM PC, PC XT and PC AT emulator written entirely in JavaScript.
[IBM PC Model 5150](/configs/pc/machines/5150/mda/64kb/ "PCjs:ibm5150") [IBM PC Model 5150](/configs/pc/machines/5150/mda/64kb/ "PCjs:ibm5150")
@ -38,7 +38,7 @@ Here's a simple machine XML file that includes an 8088 CPU and 16Kb of RAM:
However, that machine isn't usable, since it lacks a keyboard, screen, or any code (ROMs) to execute. However, that machine isn't usable, since it lacks a keyboard, screen, or any code (ROMs) to execute.
A simple machine definition that's actually usable might look like: A simple machine definition that actually works might look like:
<machine id="ibm" class="pc" width="720px"> <machine id="ibm" class="pc" width="720px">
<computer id="pc" name="IBM PC"/> <computer id="pc" name="IBM PC"/>

View file

@ -12,17 +12,9 @@ To use them, download [samples.zip](samples.zip), unzip it into a folder on your
- [sample3b.html](sample3b.html) and [sample3b.xml](sample3b.xml) - [sample3b.html](sample3b.html) and [sample3b.xml](sample3b.xml)
+ Feel free to copy/paste additional components from other machine XML files on [pcjs.org](http://www.pcjs.org/). + Feel free to copy/paste additional components from other machine XML files on [pcjs.org](http://www.pcjs.org/).
+ Please display the current version and appropriate attribution; e.g.: + Please display the current version and appropriate attribution; e.g.:
[PCjs Simulator](http://www.pcjs.org/) v1.15.3 © 2012-2014 by [@jeffpar](http://twitter.com/jeffpar) [PCjs](http://pcjs.org) © 2012-2014 by [Jeff Parsons](mailto:Jeff@pcjs.org) ([@jeffpar](http://twitter.com/jeffpar))
+ Remember to check the [pcjs.org](http://www.pcjs.org/) website periodically, to keep your copy of PCjs up-to-date. + Remember to check the [pcjs.org](http://www.pcjs.org/) website periodically, to keep your copy of PCjs up-to-date.
<!--BEGIN:EXCLUDE-->
[IBM PC](sample3b.xml "PCjs:sample3") [IBM PC](sample3b.xml "PCjs:sample3")
Before the final check-in for a new release, remember to do the following:
git update-index --no-assume-unchanged components.xsl pc.js pc-dbg.js samples.zip
<!--END:EXCLUDE-->
[Return to [PCjs Documentation](..)] [Return to [PCjs Documentation](..)]

View file

@ -926,7 +926,7 @@ MarkOut.prototype.convertMDMachineLinks = function(sBlock)
var sMachineFunc = "embed" + sMachine; var sMachineFunc = "embed" + sMachine;
var sMachineClass = sMachine.toLowerCase(); var sMachineClass = sMachine.toLowerCase();
var aMachineParms = aMatch[4].split(':'); var aMachineParms = aMatch[4].split(':');
var sMachineMessage = "Waiting for " + sMachine + "js to start"; var sMachineMessage = "Waiting for " + sMachine + "js to load";
var sMachineID = aMachineParms[0]; var sMachineID = aMachineParms[0];
var sMachineXSLFile = aMachineParms[1] || ""; var sMachineXSLFile = aMachineParms[1] || "";

View file

@ -45,7 +45,7 @@ if (typeof module !== 'undefined') {
* We now support asynchronous XML and XSL file loads; simply set fAsync (below) to true. * We now support asynchronous XML and XSL file loads; simply set fAsync (below) to true.
* *
* NOTE: For that support to work, we have to keep track of the number of machines on the page * NOTE: For that support to work, we have to keep track of the number of machines on the page
* (ie, how many embedMachine() calls were issued), reduce the count once the XML for each machine * (ie, how many embedMachine() calls were issued), reduce the count as each machine XML file
* is fully transformed into HTML, and when the count finally returns to zero, notify all the * is fully transformed into HTML, and when the count finally returns to zero, notify all the
* machine component init() handlers. * machine component init() handlers.
* *
@ -57,7 +57,7 @@ var cMachines = 0;
var fAsync = true; var fAsync = true;
/** /**
* loadXML(sFile, idMachine, sStateFile, fResolve, done) * loadXML(sFile, idMachine, sStateFile, fResolve, display, done)
* *
* This is the preferred way to load all XML and XSL files. It uses loadResource() * This is the preferred way to load all XML and XSL files. It uses loadResource()
* to load them as strings, which parseXML() can massage before parsing/transforming them. * to load them as strings, which parseXML() can massage before parsing/transforming them.
@ -84,22 +84,24 @@ var fAsync = true;
* @param {string|null|undefined} idMachine * @param {string|null|undefined} idMachine
* @param {string|null|undefined} sStateFile * @param {string|null|undefined} sStateFile
* @param {boolean} fResolve is true to resolve any "ref" attributes * @param {boolean} fResolve is true to resolve any "ref" attributes
* @param {function(string)} display
* @param {function(string,Object)} done (string contains the unparsed XML string data, and Object contains a parsed XML object) * @param {function(string,Object)} done (string contains the unparsed XML string data, and Object contains a parsed XML object)
*/ */
function loadXML(sXMLFile, idMachine, sStateFile, fResolve, done) function loadXML(sXMLFile, idMachine, sStateFile, fResolve, display, done)
{ {
var doneLoadXML = function(sURLName, sXML, nErrorCode) { var doneLoadXML = function(sURLName, sXML, nErrorCode) {
if (nErrorCode) { if (nErrorCode) {
done(sXML, null); done(sXML, null);
return; return;
} }
parseXML(sXML, sXMLFile, idMachine, sStateFile, fResolve, done); parseXML(sXML, sXMLFile, idMachine, sStateFile, fResolve, display, done);
}; };
display("Loading " + sXMLFile + "...");
web.loadResource(sXMLFile, fAsync, null, null, doneLoadXML); web.loadResource(sXMLFile, fAsync, null, null, doneLoadXML);
} }
/** /**
* parseXML(sXML, sXMLFile, idMachine, sStateFile, fResolve, done) * parseXML(sXML, sXMLFile, idMachine, sStateFile, fResolve, display, done)
* *
* Generates an XML document from an XML string. This function also provides a work-around for XSLT's * Generates an XML document from an XML string. This function also provides a work-around for XSLT's
* lack of support for the document() function (at least on some browsers), by replacing every reference * lack of support for the document() function (at least on some browsers), by replacing every reference
@ -110,9 +112,10 @@ function loadXML(sXMLFile, idMachine, sStateFile, fResolve, done)
* @param {string|null|undefined} idMachine * @param {string|null|undefined} idMachine
* @param {string|null|undefined} sStateFile * @param {string|null|undefined} sStateFile
* @param {boolean} fResolve is true to resolve any "ref" attributes; default is false * @param {boolean} fResolve is true to resolve any "ref" attributes; default is false
* @param {function(string)} display
* @param {function(string,Object)} done (string contains the unparsed XML string data, and Object contains a parsed XML object) * @param {function(string,Object)} done (string contains the unparsed XML string data, and Object contains a parsed XML object)
*/ */
function parseXML(sXML, sXMLFile, idMachine, sStateFile, fResolve, done) function parseXML(sXML, sXMLFile, idMachine, sStateFile, fResolve, display, done)
{ {
var buildXML = function(sXML, sError) { var buildXML = function(sXML, sError) {
if (sError) { if (sError) {
@ -165,7 +168,7 @@ function parseXML(sXML, sXMLFile, idMachine, sStateFile, fResolve, done)
}; };
if (sXML) { if (sXML) {
if (fResolve) { if (fResolve) {
resolveXML(sXML, buildXML); resolveXML(sXML, display, buildXML);
return; return;
} }
buildXML(sXML, null); buildXML(sXML, null);
@ -175,7 +178,7 @@ function parseXML(sXML, sXMLFile, idMachine, sStateFile, fResolve, done)
} }
/** /**
* resolveXML(sXML, done) * resolveXML(sXML, display, done)
* *
* Replaces every tag with a "ref" attribute with the contents of the corresponding file. * Replaces every tag with a "ref" attribute with the contents of the corresponding file.
* *
@ -184,9 +187,10 @@ function parseXML(sXML, sXMLFile, idMachine, sStateFile, fResolve, done)
* and 3) requiring the "ref" tag to be self-closing. * and 3) requiring the "ref" tag to be self-closing.
* *
* @param {string} sXML * @param {string} sXML
* @param {function(string)} display
* @param {function(string,(string|null))} done (the first string contains the resolved XML data, the second is for any error message) * @param {function(string,(string|null))} done (the first string contains the resolved XML data, the second is for any error message)
*/ */
function resolveXML(sXML, done) function resolveXML(sXML, display, done)
{ {
var matchRef; var matchRef;
var reRef = /<([a-z]+)\s+ref="(.*?)"(.*?)\/>/g; var reRef = /<([a-z]+)\s+ref="(.*?)"(.*?)\/>/g;
@ -249,9 +253,10 @@ function resolveXML(sXML, done)
sXML = sXML.replace(matchRef[0], sXMLRef); sXML = sXML.replace(matchRef[0], sXMLRef);
resolveXML(sXML, done); resolveXML(sXML, display, done);
}; };
display("Loading " + sRefFile + "...");
web.loadResource(sRefFile, fAsync, null, null, doneReadXML); web.loadResource(sRefFile, fAsync, null, null, doneReadXML);
return; return;
} }
@ -273,7 +278,7 @@ function resolveXML(sXML, done)
*/ */
function embedMachine(sName, sVersion, idElement, sXMLFile, sXSLFile, sStateFile) function embedMachine(sName, sVersion, idElement, sXMLFile, sXSLFile, sStateFile)
{ {
var eMachine, fSuccess = true; var eMachine, eWarning, fSuccess = true;
cMachines++; cMachines++;
@ -286,9 +291,15 @@ function embedMachine(sName, sVersion, idElement, sXMLFile, sXSLFile, sStateFile
var displayError = function(sError) { var displayError = function(sError) {
Component.log(sError); Component.log(sError);
if (eMachine) { displayMessage("Error: " + sError);
if (fSuccess) doneMachine();
fSuccess = false;
};
var displayMessage = function(sMessage) {
if (eWarning === undefined) {
/* /*
* Our MarkOut module (in convertMDMachineLinks()) creates machine containers that look like this: * Our MarkOut module (in convertMDMachineLinks()) creates machine containers that look like:
* *
* <div id="' + sMachineID + '" class="machine-placeholder"><p>Embedded PC</p><p class="machine-warning"></p></div> * <div id="' + sMachineID + '" class="machine-placeholder"><p>Embedded PC</p><p class="machine-warning"></p></div>
* *
@ -299,11 +310,10 @@ function embedMachine(sName, sVersion, idElement, sXMLFile, sXSLFile, sStateFile
* Note that it is the HTMLOut module (in processMachines()) that ultimately decides which scripts to * Note that it is the HTMLOut module (in processMachines()) that ultimately decides which scripts to
* include and then generates the embedPC() and/or embedC1P() calls. * include and then generates the embedPC() and/or embedC1P() calls.
*/ */
var aeError = Component.getElementsByClass(eMachine, "machine-warning"); var aeWarning = (eMachine && Component.getElementsByClass(eMachine, "machine-warning"));
if (aeError[0]) aeError[0].innerHTML = "Error: " + str.escapeHTML(sError); eWarning = (aeWarning && aeWarning[0]) || null;
} }
if (fSuccess) doneMachine(); if (eWarning) eWarning.innerHTML = str.escapeHTML(sMessage);
fSuccess = false;
}; };
try { try {
@ -341,6 +351,7 @@ function embedMachine(sName, sVersion, idElement, sXMLFile, sXSLFile, sStateFile
* "components.xsl" and not a "machine.xsl", because the latter will not produce valid * "components.xsl" and not a "machine.xsl", because the latter will not produce valid
* embeddable HTML (and is the most common cause of failure at this final stage). * embeddable HTML (and is the most common cause of failure at this final stage).
*/ */
displayMessage("Processing " + sXMLFile + "...");
if (window.ActiveXObject || "ActiveXObject" in window) { // second test is required for IE11 on Windows 8.1 if (window.ActiveXObject || "ActiveXObject" in window) { // second test is required for IE11 on Windows 8.1
var sFragment = xml['transformNode'](xsl); var sFragment = xml['transformNode'](xsl);
if (sFragment) { if (sFragment) {
@ -373,15 +384,15 @@ function embedMachine(sName, sVersion, idElement, sXMLFile, sXSLFile, sStateFile
} }
}; };
if (xml) { if (xml) {
loadXML(sXSLFile, null, null, false, transformXML); loadXML(sXSLFile, null, null, false, displayMessage, transformXML);
} else { } else {
displayError("failed to load XML file: " + sXMLFile); displayError("failed to load XML file: " + sXMLFile);
} }
}; };
if (sXMLFile.substr(0, 1) != "<") { if (sXMLFile.substr(0, 1) != "<") {
loadXML(sXMLFile, idElement, sStateFile, true, loadXSL); loadXML(sXMLFile, idElement, sStateFile, true, displayMessage, loadXSL);
} else { } else {
parseXML(sXMLFile, null, idElement, sStateFile, false, loadXSL); parseXML(sXMLFile, null, idElement, sStateFile, false, displayMessage, loadXSL);
} }
} else { } else {
displayError("failed to find machine element: " + idElement); displayError("failed to find machine element: " + idElement);

View file

@ -23,7 +23,7 @@
<li><a href="/apps/pc/">Apps</a></li> <li><a href="/apps/pc/">Apps</a></li>
<li><a href="/disks/pc/">Disks</a></li> <li><a href="/disks/pc/">Disks</a></li>
<li><a href="/configs/">Machines</a></li> <li><a href="/configs/">Machines</a></li>
<li><a href="/docs/pcjs/">Docs</a></li> <li><a href="/docs/">Docs</a></li>
<li><a href="/pubs/">Pubs</a></li> <li><a href="/pubs/">Pubs</a></li>
<li><a href="/blog/">Blog</a></li> <li><a href="/blog/">Blog</a></li>
<li><a href="/docs/about/">About</a></li> <li><a href="/docs/about/">About</a></li>

View file

@ -23,7 +23,7 @@
<li><a href="/apps/pc/">Apps</a></li> <li><a href="/apps/pc/">Apps</a></li>
<li><a href="/disks/pc/">Disks</a></li> <li><a href="/disks/pc/">Disks</a></li>
<li><a href="/configs/">Machines</a></li> <li><a href="/configs/">Machines</a></li>
<li><a href="/docs/pcjs/">Docs</a></li> <li><a href="/docs/">Docs</a></li>
<li><a href="/pubs/">Pubs</a></li> <li><a href="/pubs/">Pubs</a></li>
<li><a href="/blog/">Blog</a></li> <li><a href="/blog/">Blog</a></li>
<li><a href="/docs/about/">About</a></li> <li><a href="/docs/about/">About</a></li>