Javascript in custom tools

Foobar shared this question 8 months ago
Answered

I am trying to develop some library in javascript for the in-browser Geogebra app.


It would be nice to package this library as a custom tool .ggt The problem is how to stuff javascript code into custom tool ggt somehow.


It is unclear how to get the ggt out of the in-browser version. In the desktop version you can design a custom tool with text objects as output and stuff javascript code into the onClick box and download the ggt. This javascript code will pass to the .ggt (one can unzip the ggt and edit the xml to find out this code).


However when you load this ggt and run the custom tool the created object (e.g. points, texts etc.) do not contain any clue of the javascript code packaged in the .ggt.


Thus AFAIK the only way to distribute a javascript library for Geogebra is to ask the user to copy and paste the javascript code into some object Scripting tab. Not a great deal.


Any idea for this?

Comments (6)

photo
1

Probably not useful in general?

photo
1

stuff javascript code into custom tool ggt somehow.

Sorry, not possible

photo
1

Maybe explain what you are trying to do overall

photo
1

Entiendo. La idea es que los usuarios puedan tener FUNCIONES DEFINIDAS POR EL USARIO. "UDF", esto debería estar en un archivo a parte y poder usarlo en cualquier construcción en geogebra:......

Sería grandioso que hubiera una facilidad de este tipo

photo
2

Dear Michael and LalitoM thanks for your prompt replies! Well since Michael asks I will explain a little bit more. I am a teacher and I worked for nine years in the network of European Schools that recently adopted Geogebra as a substitute to TiNspire. For such an environment is really interesting to have multilingual activities. Now that I am working in Italian schools most of these activities needs translation.

Putting the two things together I started working on a layer that can support both automatic translation and multilingual support. You can find here further details.


Is also compelling to see the waste of a large amount of wonderful resources scattered upon a disturbing variety of different languages. For instance I found this wonderful set of well conceived exercises integrated into Moodle that was just what I was looking for and is going to be the test bed of my translator.


So, basically I am trying to develop a automatic translator and a support for multi-language activities. Ideally user must upload an activity and have a tool that translates it. Possibly next step will be a filter for a CLI in order to batch add multilanguage support to a large number of .ggb with a .bat file.


Passing onClick scripts to the objects created by some custom tool seems just a matter of some writeXML calls since the related information is already in the ggt(s). If this is not possible I will distibute the translator as a ggb and ask the user to load it cut some translator buttons bearing some JS code in onClick scripting, load the activity to be translated, paste the translators button and start the translation. Not elegant but effective. For a CLI filter, presently, no idea. Hints are welcome.

photo
2

Most of the translation machine has been done in Javascript and is working. Unfortunately it was a bad design. It uses free online translators that run out of some free scheme quota. To correct this issue I moved toward a design that collects all terms that need translation (in GGBs) into an HTML document to be feed into translation services. Results are then applied into ggb. Much more complex design but needed. This has some added benefit because translation accuracy is enhanced by the context. For instance if "coordinates" is to be translated then in the same document "plane" is not misunderstood as airplane.


From this emerges the need of taking a bunch of ggb files and produce a bunch of htm files one for each ggb with terms to be translated. This leads me to the problem of handling i/o with a collection of files. An obvious facility in every programming environment (e.g. C++ and POSIX). I CANNOT UNDERSTAND how to tackle the filesystem problem in this context!


Shall I insist on programming in Javascript within GGB, shall I add JS code to an HTML page where GGB is embedded or shall I dwell into GGB codebase and modify my own fork in Java and hope for a join?


The goal is to automatically mass translate a large amount of GGB files (there is a world of resources that wait for multilanguage support) and JS security constraints makes so difficult to open files for reading (and worst for writing) in unattended operations.


Any idea is GREATLY welcome!

Comments have been locked on this page!

© 2021 International GeoGebra Institute