Add file upload button to C1Pjs

This commit is contained in:
Stephan Mühlstrasser 2014-11-01 22:51:11 +01:00
commit 14944bb108
4 changed files with 18 additions and 0 deletions

View file

@ -21,4 +21,5 @@
<item ref="/sites/www.osiweb.org/programs/basic/OsiBas/spacewar.bas">SPACEWAR</item>
</control>
<control type="button" class="input" binding="loadSerial">Load File</control>
<control type="file" class="input" label="Upload File:" binding="uploadSerial"/>
</serial>

View file

@ -10,4 +10,5 @@
<item ref="/apps/c1p/BASIC/OSI/SAMPLE6.BAS">PRESIDENTS</item>
</control>
<control type="button" class="input" binding="loadSerial">Load File</control>
<control type="file" class="input" label="Upload File:" binding="uploadSerial"/>
</serial>

View file

@ -124,6 +124,19 @@ C1PSerialPort.prototype.setBinding = function(c, t, s, e)
};
}(this);
return true;
case "uploadSerial":
this.bindings[s] = e;
var serial = this;
e.addEventListener('change', function () {
var file = e.files[0];
var reader = new FileReader();
reader.onload = function () {
// serial.println("uploading " + file.name + "...");
serial.loadFile(file.name, reader.result, 0);
};
reader.readAsText(file);
});
return true;
default:
break;
}

View file

@ -285,6 +285,9 @@
<xsl:when test="@type = 'heading'">
<div><xsl:value-of select="."/></div>
</xsl:when>
<xsl:when test="@type = 'file'">
<input class="{$APPCLASS}-{@class}" type="file" data-value="{$type},{$binding}"/>
</xsl:when>
<xsl:when test="@type = 'separator'">
<hr/>
</xsl:when>