Added support for special autoType sequences (eg, $date and $time, which generate current date and time strings accepted by the PC-DOS date and time prompts)
This commit is contained in:
parent
45b4dea546
commit
991e924d01
38 changed files with 3324 additions and 3009 deletions
|
|
@ -357,14 +357,7 @@ class Computer extends Component {
|
|||
*/
|
||||
getMachineParm(sParm, parmsComponent)
|
||||
{
|
||||
/*
|
||||
* When using getURLParm(), the check is allowed be a bit looser, because URL parameters are
|
||||
* user-supplied, whereas most other parameters are developer-supplied. Granted, a developer
|
||||
* may also be sloppy and neglect to use correct case (eg, 'automount' instead of 'autoMount'),
|
||||
* but there are limits to my paranoia.
|
||||
*/
|
||||
var sParmLC = sParm.toLowerCase();
|
||||
var value = Web.getURLParm(sParm) || Web.getURLParm(sParmLC);
|
||||
var value = Web.getURLParm(sParm);
|
||||
|
||||
if (value === undefined && this.parmsMachine) {
|
||||
value = this.parmsMachine[sParm];
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@
|
|||
|
||||
if (NODE) {
|
||||
var Str = require("../../shared/lib/strlib");
|
||||
var Usr = require("../../shared/lib/usrlib");
|
||||
var Web = require("../../shared/lib/weblib");
|
||||
var Component = require("../../shared/lib/component");
|
||||
var Keys = require("../../shared/lib/keys");
|
||||
|
|
@ -400,6 +401,54 @@ class Keyboard extends Component {
|
|||
if (fAllDown !== undefined) this.fAllDown = fAllDown;
|
||||
}
|
||||
|
||||
/**
|
||||
* parseAutoType(sKeys)
|
||||
*
|
||||
* The following special sequences are recognized:
|
||||
*
|
||||
* $date: converted to MM-DD-YYYY
|
||||
* $time: converted to HH:MM
|
||||
*
|
||||
* If you want any of those sequences to be typed as-is, then you must specify two "$" (ie, "$$").
|
||||
*
|
||||
* WARNING: the JavaScript replace() function ALWAYS interprets "$" specially in replacement strings, even when
|
||||
* the search string is NOT a RegExp, and since we build machine definitions on a page from a potentially
|
||||
* indeterminate number of string replace() operations, multiple dollar signs could eventually get reduced to a
|
||||
* single dollar sign BEFORE we get here.
|
||||
*
|
||||
* To compensate, I've attempted add 'replace(/\$/g, "$$$$")' operations where currently needed; eg, in the
|
||||
* markout.js convertMDMachineLinks() function, the htmlout.js addFilesToHTML() function, and the embed.js
|
||||
* parseXML() function. Unfortunately, this is something that will be extremely difficult to prevent from breaking
|
||||
* down the road. So, heads up to future me....
|
||||
*
|
||||
* @this {Keyboard}
|
||||
* @param {string|undefined} sKeys
|
||||
* @return {string|undefined}
|
||||
*/
|
||||
parseAutoType(sKeys)
|
||||
{
|
||||
if (sKeys) {
|
||||
var match, reSpecial = /(?:^|[^$])\$([a-z]+)/g;
|
||||
while (match = reSpecial.exec(sKeys)) {
|
||||
var sReplace = "";
|
||||
switch (match[1]) {
|
||||
case 'date':
|
||||
sReplace = Usr.formatDate("n-j-Y");
|
||||
break;
|
||||
case 'time':
|
||||
sReplace = Usr.formatDate("h:i:s");
|
||||
break;
|
||||
default:
|
||||
this.notice("unrecognized autoType sequence: $" + match[1]);
|
||||
break;
|
||||
}
|
||||
sKeys = sKeys.replace('$' + match[1], sReplace);
|
||||
}
|
||||
sKeys = sKeys.replace(/\$\$/g, "$$");
|
||||
}
|
||||
return sKeys;
|
||||
}
|
||||
|
||||
/**
|
||||
* setModel(sModel)
|
||||
*
|
||||
|
|
@ -782,7 +831,7 @@ class Keyboard extends Component {
|
|||
data = [];
|
||||
this.autoInject = null;
|
||||
} else {
|
||||
this.autoInject = this.autoType;
|
||||
this.autoInject = this.parseAutoType(this.autoType);
|
||||
}
|
||||
this.fClock = this.fAdvance = data[i++];
|
||||
this.fData = data[i];
|
||||
|
|
@ -877,7 +926,7 @@ class Keyboard extends Component {
|
|||
injectInit()
|
||||
{
|
||||
if (!this.autoInject && this.autoType) {
|
||||
this.autoInject = this.autoType;
|
||||
this.autoInject = this.parseAutoType(this.autoType);
|
||||
this.injectKeys(this.autoInject);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue