Skip to content

Commit

Permalink
feat(createViewer): Add interpolation enabled observer method
Browse files Browse the repository at this point in the history
  • Loading branch information
thewtex committed Jul 29, 2018
1 parent 9c3418e commit 4cdf51c
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/createViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,34 @@ const createViewer = (
}


let interpolationEnabled = true;
publicAPI.setInterpolationEnabled = (interpolation) => {
const toggleInterpolationButton = document.getElementById(`${viewerDOMId}-toggleInterpolationButton`);
if (interpolation && !interpolationEnabled || !interpolation && interpolationEnabled) {
interpolationEnabled = !interpolationEnabled;
const toggleInterpolationButton = document.getElementById(`${viewerDOMId}-toggleInterpolationButton`);

const toggleInterpolationHandlers = [];
const toggleInterpolationButtonListener = (event) => {
const enabled = toggleInterpolationButton.checked;
toggleInterpolationHandlers.forEach((handler) => {
handler.call(null, enabled);
})
}
toggleInterpolationButton.addEventListener('click', toggleInterpolationButtonListener)

publicAPI.subscribeToggleInterpolation = (handler) => {
const index = toggleInterpolationHandlers.length;
toggleInterpolationHandlers.push(handler);
function unsubscribe() {
toggleInterpolationHandlers[index] = null;
}
return Object.freeze({ unsubscribe });
}

publicAPI.setInterpolationEnabled = (enabled) => {
const interpolation = toggleInterpolationButton.checked;
if (enabled && !interpolation || !enabled && interpolation) {
toggleInterpolationButton.click();
}
}


publicAPI.setViewMode = (mode) => {
switch(mode) {
case 'XPlane':
Expand Down

0 comments on commit 4cdf51c

Please sign in to comment.