Minimal support for "sticky" machines (ie, machines that can't be scrolled off the top of the page)

This commit is contained in:
Jeff Parsons 2017-01-02 21:56:10 -08:00 committed by Jeff Parsons
commit ae4d3196ef
3 changed files with 26 additions and 15 deletions

View file

@ -103,7 +103,7 @@ of our Markdown or XML documents. Examples: 'automount' becomes 'autoMount', 'a
{% capture machine_parms %}{{ site.left_brace }}autoMount:{{ machine_autoMount }}{{ machine_autoPower }}{{ machine_autoStart }}{{ machine_drives }},state:"{{ machine.state }}",messages:"{{ machine.messages }}",connection:"{{ machine.connection }}"{{ site.right_brace }}{% endcapture %} {% capture machine_parms %}{{ site.left_brace }}autoMount:{{ machine_autoMount }}{{ machine_autoPower }}{{ machine_autoStart }}{{ machine_drives }},state:"{{ machine.state }}",messages:"{{ machine.messages }}",connection:"{{ machine.connection }}"{{ site.right_brace }}{% endcapture %}
{% if site.pcjs.compiled == true and machine.uncompiled != true %} {% if site.pcjs.compiled == true and machine.uncompiled != true %}
{% capture machine_script %}<!--suppress BadExpressionStatementJS --> {% capture machine_script %}<!--suppress BadExpressionStatementJS -->
<script type="text/javascript" src="{{ site.baseurl }}/versions/{{ machine_app }}/{{ site.pcjs.version }}/{{ machine_file }}.js"></script>{% endcapture %} <script type="text/javascript" src="{{ site.baseurl }}/versions/{{ machine_app }}/{{ site.pcjs.version }}/{{ machine_file }}.js"></script>{% endcapture %}
{% unless machine_scripts contains machine_script %} {% unless machine_scripts contains machine_script %}
{{ machine_script }} {{ machine_script }}
{% endunless %} {% endunless %}
@ -144,24 +144,35 @@ of our Markdown or XML documents. Examples: 'automount' becomes 'autoMount', 'a
{% endif %} {% endif %}
{% endif %} {% endif %}
<script type="text/javascript">{{ machine_embed }}('{{ machine.id }}','{{ machine_config }}','{{ machine_template }}','{{ machine_parms }}');</script> <script type="text/javascript">{{ machine_embed }}('{{ machine.id }}','{{ machine_config }}','{{ machine_template }}','{{ machine_parms }}');</script>
{% if machine.cling == "top" } {% if machine.sticky == "top" %}
<script type="text/javascript"> <script type="text/javascript">
var startMachinePos=-1; var startMachinePos = -1;
window.onscroll=function(){ window.onscroll = function() {
var machine = document.getElementById('{{ machine.id }}'); var machine = document.getElementById('{{ machine.id }}');
if (startMachinePos < 0) { if (machine) {
startMachinePos = findTop(machine); var machineFooter = document.getElementById('{{ machine.id }}.footer');
} if (startMachinePos < 0) {
if (window.pageYOffset > startMachinePos) { startMachinePos = findTop(machine);
machine.style.position = 'fixed'; }
machine.style.top = 0; if (window.pageYOffset <= startMachinePos) {
} else { machine.style.position = 'relative';
machine.style.position = 'relative'; machine.style.zIndex = 'auto';
machine.style.backgroundColor = '';
machine.style.paddingRight = 0;
if (machineFooter) machineFooter.style.paddingTop = 0;
} else {
machine.style.position = 'fixed';
machine.style.zIndex = 1;
machine.style.backgroundColor = 'white';
machine.style.paddingRight = '30px';
machine.style.top = 0;
if (machineFooter) machineFooter.style.paddingTop = machine.offsetHeight + 'px';
}
} }
}; };
function findTop(obj) { function findTop(obj) {
var curTop = 0; var curTop = 0;
if (typeof (obj.offsetParent) != 'undefined' && obj.offsetParent) { if (typeof obj.offsetParent != 'undefined' && obj.offsetParent) {
while (obj.offsetParent) { while (obj.offsetParent) {
curTop += obj.offsetTop; curTop += obj.offsetTop;
obj = obj.offsetParent; obj = obj.offsetParent;
@ -174,7 +185,7 @@ of our Markdown or XML documents. Examples: 'automount' becomes 'autoMount', 'a
return curTop; return curTop;
} }
</script> </script>
{% endif } {% endif %}
{% if page.build %} {% if page.build %}
<script type="text/javascript" src="{{ site.baseurl }}/modules/build/lib/build.js"></script> <script type="text/javascript" src="{{ site.baseurl }}/modules/build/lib/build.js"></script>
<script type="text/javascript">buildPC("{{ page.build }}");</script> <script type="text/javascript">buildPC("{{ page.build }}");</script>

View file

@ -8,3 +8,4 @@
{% endfor %} {% endfor %}
[{{ machine_name }}] [{{ machine_name }}]
</div> </div>
<p id="{{ include.id }}.footer"></p>

View file

@ -13,7 +13,6 @@ machines:
type: pc8080 type: pc8080
config: /devices/pc8080/machine/vt100/machine.xml config: /devices/pc8080/machine/vt100/machine.xml
connection: serialPort->test1170.dl11 connection: serialPort->test1170.dl11
cling: top
--- ---
[PDPjs](/devices/pdp11/machine/) is the newest addition to the PCjs family of emulators, joining PCx86, PC8080, and C1Pjs. [PDPjs](/devices/pdp11/machine/) is the newest addition to the PCjs family of emulators, joining PCx86, PC8080, and C1Pjs.