From eec10da1b73689f0b5fa9626bf7ab0a2ccce1dfd Mon Sep 17 00:00:00 2001 From: Jeff Parsons Date: Wed, 29 Oct 2014 15:23:35 -0700 Subject: [PATCH] Display progress messages as machine XML files are being loaded/processed --- docs/pcjs/README.md | 6 +-- docs/pcjs/demos/README.md | 12 +----- my_modules/markout/lib/markout.js | 2 +- my_modules/shared/lib/embed.js | 51 +++++++++++++++---------- my_modules/shared/templates/common.html | 2 +- my_modules/shared/templates/common.xsl | 2 +- 6 files changed, 39 insertions(+), 36 deletions(-) diff --git a/docs/pcjs/README.md b/docs/pcjs/README.md index 84014ea4f..14afedd29 100644 --- a/docs/pcjs/README.md +++ b/docs/pcjs/README.md @@ -1,7 +1,7 @@ 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") @@ -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. -A simple machine definition that's actually usable might look like: +A simple machine definition that actually works might look like: @@ -154,4 +154,4 @@ Remember that PC and PC XT machines supported only 160Kb diskettes (on any versi 320Kb diskettes (on PC-DOS 1.1 and higher), and 180Kb and 360Kb diskettes (on PC-DOS 2.0 and higher). The 1.2Mb diskette format was introduced with the PC AT, and 720Kb and 1.44Mb diskette formats were introduced with the PS/2; those formats will be supported in a future release of PCjs, when the necessary -hardware support has been added. \ No newline at end of file +hardware support has been added. diff --git a/docs/pcjs/demos/README.md b/docs/pcjs/demos/README.md index 1ea3edd52..0a966ad30 100644 --- a/docs/pcjs/demos/README.md +++ b/docs/pcjs/demos/README.md @@ -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) + 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.: - [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. - - [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 - - - -[Return to [PCjs Documentation](..)] \ No newline at end of file +[Return to [PCjs Documentation](..)] diff --git a/my_modules/markout/lib/markout.js b/my_modules/markout/lib/markout.js index ed26ab3d3..2eec1e1f0 100644 --- a/my_modules/markout/lib/markout.js +++ b/my_modules/markout/lib/markout.js @@ -926,7 +926,7 @@ MarkOut.prototype.convertMDMachineLinks = function(sBlock) var sMachineFunc = "embed" + sMachine; var sMachineClass = sMachine.toLowerCase(); 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 sMachineXSLFile = aMachineParms[1] || ""; diff --git a/my_modules/shared/lib/embed.js b/my_modules/shared/lib/embed.js index 310e78b89..612835330 100644 --- a/my_modules/shared/lib/embed.js +++ b/my_modules/shared/lib/embed.js @@ -45,7 +45,7 @@ if (typeof module !== 'undefined') { * 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 - * (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 * machine component init() handlers. * @@ -57,7 +57,7 @@ var cMachines = 0; 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() * 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} sStateFile * @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) */ -function loadXML(sXMLFile, idMachine, sStateFile, fResolve, done) +function loadXML(sXMLFile, idMachine, sStateFile, fResolve, display, done) { var doneLoadXML = function(sURLName, sXML, nErrorCode) { if (nErrorCode) { done(sXML, null); 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); } /** - * 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 * 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} sStateFile * @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) */ -function parseXML(sXML, sXMLFile, idMachine, sStateFile, fResolve, done) +function parseXML(sXML, sXMLFile, idMachine, sStateFile, fResolve, display, done) { var buildXML = function(sXML, sError) { if (sError) { @@ -165,7 +168,7 @@ function parseXML(sXML, sXMLFile, idMachine, sStateFile, fResolve, done) }; if (sXML) { if (fResolve) { - resolveXML(sXML, buildXML); + resolveXML(sXML, display, buildXML); return; } 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. * @@ -184,9 +187,10 @@ function parseXML(sXML, sXMLFile, idMachine, sStateFile, fResolve, done) * and 3) requiring the "ref" tag to be self-closing. * * @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) */ -function resolveXML(sXML, done) +function resolveXML(sXML, display, done) { var matchRef; var reRef = /<([a-z]+)\s+ref="(.*?)"(.*?)\/>/g; @@ -249,9 +253,10 @@ function resolveXML(sXML, done) sXML = sXML.replace(matchRef[0], sXMLRef); - resolveXML(sXML, done); + resolveXML(sXML, display, done); }; + display("Loading " + sRefFile + "..."); web.loadResource(sRefFile, fAsync, null, null, doneReadXML); return; } @@ -273,7 +278,7 @@ function resolveXML(sXML, done) */ function embedMachine(sName, sVersion, idElement, sXMLFile, sXSLFile, sStateFile) { - var eMachine, fSuccess = true; + var eMachine, eWarning, fSuccess = true; cMachines++; @@ -286,9 +291,15 @@ function embedMachine(sName, sVersion, idElement, sXMLFile, sXSLFile, sStateFile var displayError = function(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: * *

Embedded PC

* @@ -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 * include and then generates the embedPC() and/or embedC1P() calls. */ - var aeError = Component.getElementsByClass(eMachine, "machine-warning"); - if (aeError[0]) aeError[0].innerHTML = "Error: " + str.escapeHTML(sError); + var aeWarning = (eMachine && Component.getElementsByClass(eMachine, "machine-warning")); + eWarning = (aeWarning && aeWarning[0]) || null; } - if (fSuccess) doneMachine(); - fSuccess = false; + if (eWarning) eWarning.innerHTML = str.escapeHTML(sMessage); }; 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 * 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 var sFragment = xml['transformNode'](xsl); if (sFragment) { @@ -373,15 +384,15 @@ function embedMachine(sName, sVersion, idElement, sXMLFile, sXSLFile, sStateFile } }; if (xml) { - loadXML(sXSLFile, null, null, false, transformXML); + loadXML(sXSLFile, null, null, false, displayMessage, transformXML); } else { displayError("failed to load XML file: " + sXMLFile); } }; if (sXMLFile.substr(0, 1) != "<") { - loadXML(sXMLFile, idElement, sStateFile, true, loadXSL); + loadXML(sXMLFile, idElement, sStateFile, true, displayMessage, loadXSL); } else { - parseXML(sXMLFile, null, idElement, sStateFile, false, loadXSL); + parseXML(sXMLFile, null, idElement, sStateFile, false, displayMessage, loadXSL); } } else { displayError("failed to find machine element: " + idElement); diff --git a/my_modules/shared/templates/common.html b/my_modules/shared/templates/common.html index 0ead99976..4a012b996 100644 --- a/my_modules/shared/templates/common.html +++ b/my_modules/shared/templates/common.html @@ -23,7 +23,7 @@
  • Apps
  • Disks
  • Machines
  • -
  • Docs
  • +
  • Docs
  • Pubs
  • Blog
  • About
  • diff --git a/my_modules/shared/templates/common.xsl b/my_modules/shared/templates/common.xsl index 0ca98e305..a361eb211 100644 --- a/my_modules/shared/templates/common.xsl +++ b/my_modules/shared/templates/common.xsl @@ -23,7 +23,7 @@
  • Apps
  • Disks
  • Machines
  • -
  • Docs
  • +
  • Docs
  • Pubs
  • Blog
  • About