.
*
* Placement of the addStickyMachine() call is irrelevant, because embed.js asynchronously
* reads all the XML files that define the machine *before* replacing the
.
*/
var machine = document.getElementById(idMachine);
if (machine) {
var machineSibling = machine.nextElementSibling;
if (machineSibling) {
if (topMachine < 0) {
topMachine = findTop(machine);
}
machine.className = machine.className.replace(/machine-(floating|sticky) /g, '');
if (window.pageYOffset <= topMachine) {
machine.className = 'machine-floating ' + machine.className;
if (machineSibling) machineSibling.style.paddingTop = 0;
} else {
machine.className = 'machine-sticky ' + machine.className;
if (machineSibling) machineSibling.style.paddingTop = machine.offsetHeight + 'px';
}
if (prevOnScroll) prevOnScroll();
}
}
};
}
/**
* commandMachine(idMachine, sType, sCommand, sValue)
*
* Note that this script is not compiled into any of the machines, since "sticky machines" are feature of the PCjs
* website rather than of the machines. And since the machines are compiled, all their code and data is completely
* opaque to us, except for those functions explicitly exported by embed.js.
*
* So now, in addition to the functions for embedding machines on a webpage, embed.js includes a new function:
*
* findMachineComponent()
*
* which uses existing Component methods to find the requested component type for a specific machine, and if a
* component is found, then its 'exports' table is checked for an entry matching the specified command string, and if
* an entry is found, then the corresponding function is called with the specified data.
*
* @param {string} idMachine
* @param {string} sType
* @param {string} sCommand
* @param {string} [sValue]
*/
function commandMachine(idMachine, sType, sCommand, sValue)
{
if (window.findMachineComponent) {
var component = window.findMachineComponent(idMachine, sType);
if (component) {
var exports = component['exports'];
if (exports) {
var fnCommand = exports[sCommand];
if (fnCommand) {
//noinspection JSUnresolvedFunction
fnCommand.call(component, sValue);
return;
}
}
}
}
console.log("unimplemented: commandMachine('" + idMachine + "','" + typeComponent + "','" + sCommand + "','" + sValue + "')");
}
/**
* findTop(obj)
*
* @param {Object} obj
*/
function findTop(obj)
{
var curTop = 0;
if (typeof obj.offsetParent != 'undefined' && obj.offsetParent) {
while (obj.offsetParent) {
curTop += obj.offsetTop;
obj = obj.offsetParent;
}
curTop += obj.offsetTop;
}
else if (obj.y) {
curTop += obj.y;
}
return curTop;
}