Support for control bindings with user-defined values (eg, for Keyboard "test" button)

This commit is contained in:
Jeff Parsons 2016-02-02 10:21:45 -08:00
commit 4ab2c21043
32 changed files with 2374 additions and 2253 deletions

View file

@ -60,6 +60,11 @@
"use strict";
if (NODE) {
var web = require("../../shared/lib/weblib");
var Component = require("../../shared/lib/component");
}
/**
* C1PComputer(parmsComputer, modules)
*
@ -166,9 +171,10 @@ C1PComputer.prototype.stop = function(msStart, nCycles)
* @param {string|null} sHTMLType is the type of the HTML control (eg, "button", "list", "text", "submit", "textarea")
* @param {string} sBinding is the value of the 'binding' parameter stored in the HTML control's "data-value" attribute (eg, "reset")
* @param {Object} control is the HTML control DOM object (eg, HTMLButtonElement)
* @param {string} [sValue] optional data value
* @return {boolean} true if binding was successful, false if unrecognized binding request
*/
C1PComputer.prototype.setBinding = function(sHTMLType, sBinding, control)
C1PComputer.prototype.setBinding = function(sHTMLType, sBinding, control, sValue)
{
switch(sBinding) {
case "reset":
@ -186,13 +192,15 @@ C1PComputer.prototype.setBinding = function(sHTMLType, sBinding, control)
};
/**
* NOTE: If there are multiple components for a given type, we may need to provide a means of discriminating.
*
* @this {C1PComputer}
* @param {string} sType
* @return {Component}
*
* NOTE: If there are multiple components for a given type, we may need to provide a means of discriminating.
* @param {string} [idRelated] of related component
* @param {Component|null} [componentPrev] of previously returned component, if any
* @return {Component|null}
*/
C1PComputer.prototype.getComponentByType = function(sType)
C1PComputer.prototype.getComponentByType = function(sType, idRelated, componentPrev)
{
if (this.modules[sType]) {
return this.modules[sType][0];

View file

@ -32,6 +32,13 @@
"use strict";
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");
}
/**
* C1PCPU(parmsCPU)
*
@ -506,9 +513,10 @@ C1PCPU.prototype.reset = function(fPowerOn)
* @param {string|null} sHTMLType is the type of the HTML control (eg, "button", "list", "text", "submit", "textarea")
* @param {string} sBinding is the value of the 'binding' parameter stored in the HTML control's "data-value" attribute (eg, "run")
* @param {Object} control is the HTML control DOM object (eg, HTMLButtonElement)
* @param {string} [sValue] optional data value
* @return {boolean} true if binding was successful, false if unrecognized binding request
*/
C1PCPU.prototype.setBinding = function(sHTMLType, sBinding, control)
C1PCPU.prototype.setBinding = function(sHTMLType, sBinding, control, sValue)
{
var fBound = false;
switch(sBinding) {

View file

@ -32,6 +32,13 @@
"use strict";
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");
}
/**
* C1PDebugger(parmsDbg)
*
@ -491,9 +498,10 @@ if (DEBUGGER) {
* @param {string|null} sHTMLType is the type of the HTML control (eg, "button", "list", "text", "submit", "textarea", "canvas")
* @param {string} sBinding is the value of the 'binding' parameter stored in the HTML control's "data-value" attribute (eg, "reset")
* @param {Object} control is the HTML control DOM object (eg, HTMLButtonElement)
* @param {string} [sValue] optional data value
* @return {boolean} true if binding was successful, false if unrecognized binding request
*/
C1PDebugger.prototype.setBinding = function(sHTMLType, sBinding, control)
C1PDebugger.prototype.setBinding = function(sHTMLType, sBinding, control, sValue)
{
var dbg = this;
switch(sBinding) {

View file

@ -32,6 +32,12 @@
"use strict";
if (NODE) {
var str = require("../../shared/lib/strlib");
var web = require("../../shared/lib/weblib");
var Component = require("../../shared/lib/component");
}
/**
* C1PDiskController(parmsDC)
*
@ -660,9 +666,10 @@ C1PDiskController.prototype.resetDrive = function(iDrive, iDriveType, nMaxTracks
* @param {string|null} sHTMLType is the type of the HTML control (eg, "button", "list", "text", "submit", "textarea")
* @param {string} sBinding is the value of the 'binding' parameter stored in the HTML control's "data-value" attribute (eg, "listDisk")
* @param {Object} control is the HTML control DOM object (eg, HTMLButtonElement)
* @param {string} [sValue] optional data value
* @return {boolean} true if binding was successful, false if unrecognized binding request
*/
C1PDiskController.prototype.setBinding = function(sHTMLType, sBinding, control)
C1PDiskController.prototype.setBinding = function(sHTMLType, sBinding, control, sValue)
{
switch(sBinding) {

View file

@ -32,6 +32,12 @@
"use strict";
if (NODE) {
var str = require("../../shared/lib/strlib");
var web = require("../../shared/lib/weblib");
var Component = require("../../shared/lib/component");
}
/**
* C1PKeyboard(parmsKbd)
*
@ -352,7 +358,7 @@ C1PKeyboard.prototype.reset = function()
*/
if (this.aKeyTimers) {
for (var i in this.aKeyTimers) {
if (isNaN(i)) continue; // ignore any non-numeric properties, if any
if (isNaN(+i)) continue; // ignore any non-numeric properties, if any
if (this.aKeyTimers[i]) clearTimeout(this.aKeyTimers[i]);
}
}
@ -391,9 +397,10 @@ C1PKeyboard.prototype.reset = function()
* @param {string|null} sHTMLType is the type of the HTML control (eg, "button", "list", "text", "submit", "textarea")
* @param {string} sBinding is the value of the 'binding' parameter stored in the HTML control's "data-value" attribute (eg, "esc", "ctrl-c")
* @param {Object} control is the HTML control DOM object (eg, HTMLButtonElement)
* @param {string} [sValue] optional data value
* @return {boolean} true if binding was successful, false if unrecognized binding request
*/
C1PKeyboard.prototype.setBinding = function(sHTMLType, sBinding, control)
C1PKeyboard.prototype.setBinding = function(sHTMLType, sBinding, control, sValue)
{
/*
* I want to bind to the first caller (ie, the Screen), not subsequent ones (eg, the Panel)
@ -524,8 +531,9 @@ C1PKeyboard.prototype.setPower = function(fOn, cmp)
/**
* @this {C1PKeyboard}
* @param {boolean} [fReady] is assumed to indicate "ready" unless EXPLICITLY set to false
*/
C1PKeyboard.prototype.setReady = function()
C1PKeyboard.prototype.setReady = function(fReady)
{
this.iOS = web.isUserAgent("iOS");
this.fMobile = (this.iOS || web.isUserAgent("Android"));
@ -536,7 +544,7 @@ C1PKeyboard.prototype.setReady = function()
};
/**
* calcReleaseDelay(fRepeat
* calcReleaseDelay(fRepeat)
*
* This attempts to scale our default "release" delay appropriately for the current CPU speed.
*

View file

@ -32,6 +32,11 @@
"use strict";
if (NODE) {
var web = require("../../shared/lib/weblib");
var Component = require("../../shared/lib/component");
}
/**
* C1PPanel(parmsPanel)
*
@ -58,15 +63,16 @@ Component.subclass(C1PPanel);
* @param {string|null} sHTMLType is the type of the HTML control (eg, "button", "list", "text", "submit", "textarea", "canvas")
* @param {string} sBinding is the value of the 'binding' parameter stored in the HTML control's "data-value" attribute (eg, "reset")
* @param {Object} control is the HTML control DOM object (eg, HTMLButtonElement)
* @param {string} [sValue] optional data value
* @return {boolean} true if binding was successful, false if unrecognized binding request
*/
C1PPanel.prototype.setBinding = function(sHTMLType, sBinding, control)
C1PPanel.prototype.setBinding = function(sHTMLType, sBinding, control, sValue)
{
if (this.cmp && this.cmp.setBinding(sHTMLType, sBinding, control)) return true;
if (this.cpu && this.cpu.setBinding(sHTMLType, sBinding, control)) return true;
if (this.kbd && this.kbd.setBinding(sHTMLType, sBinding, control)) return true;
if (DEBUGGER && this.dbg && this.dbg.setBinding(sHTMLType, sBinding, control)) return true;
return Component.prototype.setBinding.call(this, sHTMLType, sBinding, control);
if (this.cmp && this.cmp.setBinding(sHTMLType, sBinding, control, sValue)) return true;
if (this.cpu && this.cpu.setBinding(sHTMLType, sBinding, control, sValue)) return true;
if (this.kbd && this.kbd.setBinding(sHTMLType, sBinding, control, sValue)) return true;
if (DEBUGGER && this.dbg && this.dbg.setBinding(sHTMLType, sBinding, control, sValue)) return true;
return Component.prototype.setBinding.call(this, sHTMLType, sBinding, control, sValue);
};
/**

View file

@ -32,6 +32,11 @@
"use strict";
if (NODE) {
var web = require("../../shared/lib/weblib");
var Component = require("../../shared/lib/component");
}
/**
* C1PRAM(parmsRAM)
*

View file

@ -32,6 +32,13 @@
"use strict";
if (NODE) {
var str = require("../../shared/lib/strlib");
var web = require("../../shared/lib/weblib");
var DumpAPI = require("../../shared/lib/dumpapi");
var Component = require("../../shared/lib/component");
}
/**
* C1PROM(parmsROM)
*

View file

@ -32,6 +32,12 @@
"use strict";
if (NODE) {
var str = require("../../shared/lib/strlib");
var web = require("../../shared/lib/weblib");
var Component = require("../../shared/lib/component");
}
/**
* C1PSerialPort(parmsSerial)
*
@ -103,9 +109,10 @@ C1PSerialPort.prototype.start = function()
* @param {string|null} sHTMLType is the type of the HTML control (eg, "button", "list", "text", "submit", "textarea")
* @param {string} sBinding is the value of the 'binding' parameter stored in the HTML control's "data-value" attribute (eg, "listSerial")
* @param {Object} control is the HTML control DOM object (eg, HTMLButtonElement)
* @param {string} [sValue] optional data value
* @return {boolean} true if binding was successful, false if unrecognized binding request
*/
C1PSerialPort.prototype.setBinding = function(sHTMLType, sBinding, control)
C1PSerialPort.prototype.setBinding = function(sHTMLType, sBinding, control, sValue)
{
var serial = this;
@ -162,7 +169,7 @@ C1PSerialPort.prototype.setBinding = function(sHTMLType, sBinding, control)
}
else {
if (DEBUG) this.log("Local file support not available");
control.parentNode.removeChild(control);
control.parentNode.removeChild(/** @type {Node} */ (control));
}
return true;

View file

@ -32,6 +32,11 @@
"use strict";
if (NODE) {
var web = require("../../shared/lib/weblib");
var Component = require("../../shared/lib/component");
}
/**
* C1PVideo(parmsVideo, eCanvas, context, imgChars)
*
@ -183,9 +188,10 @@ C1PVideo.prototype.reset = function(fPowerOn)
* @param {string|null} sHTMLType is the type of the HTML control (eg, "button", "list", "text", "submit", "textarea")
* @param {string} sBinding is the value of the 'binding' parameter stored in the HTML control's "data-value" attribute (eg, "refresh")
* @param {Object} control is the HTML control DOM object (eg, HTMLButtonElement)
* @param {string} [sValue] optional data value
* @return {boolean} true if binding was successful, false if unrecognized binding request
*/
C1PVideo.prototype.setBinding = function(sHTMLType, sBinding, control)
C1PVideo.prototype.setBinding = function(sHTMLType, sBinding, control, sValue)
{
switch(sBinding) {
case "refresh":
@ -345,15 +351,16 @@ C1PVideo.prototype.setPower = function(fOn, cmp)
};
/**
* @this {C1PVideo}
*
* cxChar and cyChar are the source cell size. Originally, those values came strictly from the parmsVideo
* 'charWidth' and 'charHeight' properties. Now, if those aren't defined (which is normally the case now),
* then we infer the source cell size from the dimensions of imgChars, which is expected to be a 16x16 array of
* character bitmaps. We could be even more flexible, by allowing imgChars to be any rectangular dimension
* (eg, 1x256) as long as we can assume it contains exactly 256 characters, but there's no need to get carried away....
*
* @this {C1PVideo}
* @param {boolean} [fReady] is assumed to indicate "ready" unless EXPLICITLY set to false
*/
C1PVideo.prototype.setReady = function()
C1PVideo.prototype.setReady = function(fReady)
{
if (!this.cxChar) this.cxChar = Math.floor(this.imgChars.width / 16);
if (!this.cyChar) this.cyChar = Math.floor(this.imgChars.height / 16);

View file

@ -21,7 +21,7 @@
<xsl:template name="componentScripts">
<xsl:param name="component"/>
<script type="text/javascript" src="/versions/{$APPCLASS}/{$APPVERSION}/{$component}.js"></script>
<script type="text/javascript" src="/versions/{$APPCLASS}/{$APPVERSION}/{$component}.js"> </script>
</xsl:template>
<xsl:template name="componentIncludes">
@ -157,7 +157,7 @@
</xsl:if>
<div class="{$APPCLASS}-container" style="{$border}{$style}">
<xsl:if test="$class != '' and $component != 'machine'">
<div class="{$APPCLASS}-{$class}-object" data-value="{{id:'{$id}',name:'{$name}'{$parms}}}"></div>
<div class="{$APPCLASS}-{$class}-object" data-value="{{id:'{$id}',name:'{$name}'{$parms}}}"> </div>
</xsl:if>
<xsl:if test="control">
<div class="{$APPCLASS}-controls">
@ -174,7 +174,7 @@
<div class="{$APPCLASS}-copyright">
<a href="http://{$SITEHOST}/{$APPCLASS}" target="_blank">C1Pjs</a> v<xsl:value-of select="$APPVERSION"/> © 2012-2016 by <a href="http://twitter.com/jeffpar" target="_blank">@jeffpar</a>
</div>
<div style="clear:both"></div>
<div style="clear:both"> </div>
</xsl:if>
</div>
</xsl:template>
@ -284,7 +284,7 @@
<input class="{$APPCLASS}-binding" type="submit" style="{$border}{$fontsize}{$style}" data-value="{{{$type},{$binding}}}" value="{.}"/>
</xsl:when>
<xsl:when test="@type = 'textarea'">
<textarea class="{$APPCLASS}-binding" style="{$border}{$width}{$height}{$style}" data-value="{{{$type},{$binding}}}" readonly="readonly"></textarea>
<textarea class="{$APPCLASS}-binding" style="{$border}{$width}{$height}{$style}" data-value="{{{$type},{$binding}}}" readonly="readonly"> </textarea>
</xsl:when>
<xsl:when test="@type = 'heading'">
<div><xsl:value-of select="."/></div>
@ -301,7 +301,7 @@
<hr/>
</xsl:when>
<xsl:when test="not(@type)">
<div style="clear:both"></div><br/>
<div style="clear:both"> </div><br/>
</xsl:when>
<xsl:otherwise>
<div class="{$APPCLASS}-binding{$subclass}" style="{$border}{$width}{$height}{$style}" data-value="{{{$type},{$binding}}}"><xsl:apply-templates/></div>
@ -311,7 +311,7 @@
<xsl:if test="@labelpos = 'right'">
<div class="{$APPCLASS}-label" style="{$labelwidth}{$labelstyle}"><xsl:value-of select="@label"/></div>
</xsl:if>
<div style="clear:both"></div>
<div style="clear:both"> </div>
</xsl:if>
</div>
</xsl:template>