Skip to content
\n

Is this the best way to make such a page? Might need some help making it nice and modular/reusable.

","upvoteCount":2,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"

What you have is the right idea. Here is a snippet of javascript that creates a button to trigger an action:

\n
function createOpenSpaceButton(buttonTitle, actionIdentifier) {\n  // create a new button with title\n  let newButton = document.createElement(\"button\");\n  newButton.innerHTML = buttonTitle;\n  // assign click function to button\n  newButton.onclick = function () {\n    openspace.action.triggerAction(actionIdentifier);\n  };\n  //append the new button to the button container\n  var buttons = document.getElementById(\"buttons\");\n  buttons.appendChild(newButton);\n}\n// create buttons\ncreateOpenSpaceButton(\"Hello World\", \"profile.focus.earth\");\ncreateOpenSpaceButton(\"Toggle Zoom Friction\", \"os_default.toggle_zoom_friction\");\ncreateOpenSpaceButton(\"Goodnight\", \"os_default.fade_to_black\");
\n

And here is a gist to an example html page with this in action: https://gist.github.com/micahnyc/39f84b8d36e923a5aa03be9cc4cea1cb

","upvoteCount":1,"url":"https://github.com/OpenSpace/OpenSpace/discussions/2095#discussioncomment-2739741"}}}

Buttons for HTML/JS control page #2095

Answered by micahnyc
hedbergj asked this question in Q&A
Discussion options

You must be logged in to vote

What you have is the right idea. Here is a snippet of javascript that creates a button to trigger an action:

function createOpenSpaceButton(buttonTitle, actionIdentifier) {
  // create a new button with title
  let newButton = document.createElement("button");
  newButton.innerHTML = buttonTitle;
  // assign click function to button
  newButton.onclick = function () {
    openspace.action.triggerAction(actionIdentifier);
  };
  //append the new button to the button container
  var buttons = document.getElementById("buttons");
  buttons.appendChild(newButton);
}
// create buttons
createOpenSpaceButton("Hello World", "profile.focus.earth");
createOpenSpaceButton("Toggle Zoom Friction", "os_…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by alexanderbock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants