JessieCode script files

16 views
Skip to first unread message

D. Brian Walton

unread,
May 29, 2021, 12:08:22 AM5/29/21
to jsxg...@googlegroups.com
Is it possible to attach JessieCode as a script element referencing an URI instead of having the text in the script as plain text.

For example, I tried the following:

<div id="jessie-slate" class="jxgbox" style="width:540px; height:540px;"></div>
<script type="text/jessiecode" container="jessie-slate" src="script/jessie-demo.jc"></script>

The file jessie-demo.jc contains the actual script I want to work with. But I don't think the browser ever loads the file because it knows it isn't javascript.

If this is not implemented, is there another way to accomplish this?

Thanks,
- Brian

dbrian...@gmail.com

unread,
Jun 1, 2021, 12:22:22 PM6/1/21
to JSXGraph
Following up on my earlier post. I think I have a workable solution using the fetch API. If there is a better way, I'd love to learn about it.

My solution is to include the following javascript:

<script type="text/javascript">
function parseJessie(code) {
  let board = JXG.JSXGraph.initBoard('jsxbox-name', {boundingbox: [-5, 5, 5, -5], keepaspectratio:true});
  board.jc = new JXG.JessieCode();
  board.jc.use(board);
  board.suspendUpdate();
  board.jc.parse(code);
  board.unsuspendUpdate();
}
fetch('myJessieCode.jc').then(function(response) { response.text().then( function(text) { parseJessie(text); }); });
</script>

- Brian

Alfred Wassermann

unread,
Jun 1, 2021, 3:43:16 PM6/1/21
to JSXGraph
Dear Brian,
this is a very interesting idea!
Up to now, JSXGraph parses the script tag and executes the content if the type is "text/jessiecode". In fact it does more or less what you are doning in your second post.
So, it is a good idea to look for a "src" attribute and fetch the code from there.
We will implement it soon.
Many thanks for the suggestion and the solution.
Best wishes,
Alfred


Reply all
Reply to author
Forward
0 new messages