Project

General

Profile

Adding custom JavaScript libraries

Added by Tassilo Glander over 11 years ago

Hi,

I want to add custom interaction in WGLWidget, which means custom JavaScript. What is the best (clean & performant) way to do this?

My goal is to use the interaction handling of http://osgjs.org/. The stock implementation does not have smoothed animation and does not offer to change all parameters (look from, to, up).

  • What I have done so far is adding the additional Javascript files in WGLWidget::defineJavaScript() using require() and adding another setLookAtParams() method in WGLWidget.js to call osgJS methods. This works, but the problem is that I have to change a WGLWidget, copy the additional js files into each application directory, and the JS files have to be read everytime the application starts. I cannot derive from WGLWidget because defineJavaScript() is private and I cannot override it.
  • If I would load it with the macro LOAD_JAVASCRIPT, I would need to use DECLARE_WT_MEMBER in the Javascript. I do not understand this completely and do not want to change the external library so much.

Ideally I want to subclass WGLWidget and have some way to load a custom Javascript into the preamble, either everytime on application start from a file (e.g. for debugging) or from a string constant (e.g. from a minified js file read at compile time).

Is this or something similar possible already?

Cheers,

Tassilo


Replies (1)

RE: Adding custom JavaScript libraries - Added by Tassilo Glander over 11 years ago

just for the record: I subclassed WGLWidget and overrode the protected render() method

void render(Wt::WFlagsWt::RenderFlag flags);

to call a customized defineJavaScript() method, where I could point to my Javascript files.

Cheers,

Tassilo

    (1-1/1)