diff --git a/corsscripts/stackjsxgraph.js b/corsscripts/stackjsxgraph.js index e7bddefccfc..072144b24a6 100644 --- a/corsscripts/stackjsxgraph.js +++ b/corsscripts/stackjsxgraph.js @@ -254,6 +254,10 @@ export const stack_jxg = { } else { objectinput[object.id] = [input]; } + if (!(input in serializers)) { + /* If someone does registrations before other bindings to that input. */ + _commonsetup(input); + } serializers[input][object.id] = serializer; registerobject(object); diff --git a/corsscripts/stackjsxgraph.min.js b/corsscripts/stackjsxgraph.min.js index 54671d72c61..98cc63e2323 100644 --- a/corsscripts/stackjsxgraph.min.js +++ b/corsscripts/stackjsxgraph.min.js @@ -1 +1 @@ -"use strict";var serializers={},deserializers={},initials={},objectgroups=[],objectinput={},registeredobjects={},active=!1;function _commonsetup(e){var i;e in serializers||(serializers[e]={},deserializers[e]=[],(i=document.getElementById(e)).addEventListener("input",()=>generalinputupdatehandler(e)),i.addEventListener("change",()=>generalinputupdatehandler(e)))}function registerobject(e){e.id in registeredobjects||(e.board.on("update",()=>generalobjectupdatehandlerid(e.id)),registeredobjects[e.id]=e)}function pointserializer(e){return JSON.stringify([e.X(),e.Y()])}function pointdeserializer(e,i){try{var t=JSON.parse(i);"number"==typeof t[0]&&"number"==typeof t[1]&&(e.setPosition(JXG.COORDS_BY_USER,t),e.board.update(),e.update())}catch(e){}}function pointdeserializerparsed(e,i){try{"number"==typeof i[0]&&"number"==typeof i[1]&&(e.setPosition(JXG.COORDS_BY_USER,i),e.board.update(),e.update())}catch(e){}}function sliderserializer(e){return JSON.stringify(e.Value())}function sliderdeserializer(e,i){try{e.setValue(JSON.parse(i)),e.board.update(),e.update()}catch(e){}}function generalobjectupdatehandler(e){generalobjectupdatehandlerid(e.id)}function generalobjectupdatehandlerid(e){if(!active){active=!0;try{var i=[];if(e in objectinput)for(var t=0;tpointserializer(i),e=>pointdeserializer(i,e),[i])},bind_point_dual:function(e,i,t){this.custom_bind(e,()=>JSON.stringify([[i.X(),i.Y()],[t.X(),t.Y()]]),e=>{e=JSON.parse(e);pointdeserializerparsed(i,e[0]),pointdeserializerparsed(t,e[1])},[i,t])},bind_point_relative:function(e,i,t){this.custom_bind(e,()=>JSON.stringify([[i.X(),i.Y()],[t.X()-i.X(),t.Y()-i.Y()]]),e=>{e=JSON.parse(e);pointdeserializerparsed(i,e[0]),e[1][0]=e[1][0]+e[0][0],e[1][1]=e[1][1]+e[0][1],pointdeserializerparsed(t,e[1])},[i,t])},bind_point_direction:function(e,r,n){this.custom_bind(e,()=>JSON.stringify([[r.X(),r.Y()],[Math.atan2(n.Y()-r.Y(),n.X()-r.X()),Math.sqrt((n.X()-r.X())*(n.X()-r.X())+(n.Y()-r.Y())*(n.Y()-r.Y()))]]),e=>{var e=JSON.parse(e),i=(pointdeserializerparsed(r,e[0]),e[1][0]),t=e[1][1];e[1][0]=e[0][0]+t*Math.cos(i),e[1][1]=e[0][1]+t*Math.sin(i),pointdeserializerparsed(n,e[1])},[r,n])},bind_slider:function(e,i){this.custom_bind(e,()=>sliderserializer(i),e=>sliderdeserializer(i,e),[i])},bind_list_of:function(e,n){this.custom_bind(e,()=>{for(var e="[",i=0;i{for(var i=JSON.parse(e),t=0;tgeneralinputupdatehandler(inputname));input.addEventListener("change",()=>generalinputupdatehandler(inputname))}}function registerobject(object){if(!(object.id in registeredobjects)){object.board.on("update",()=>generalobjectupdatehandlerid(object.id));registeredobjects[object.id]=object}}function pointserializer(point){return JSON.stringify([point.X(),point.Y()])}function pointdeserializer(point,data){try{var tmp=JSON.parse(data);if(typeof tmp[0]=="number"&&typeof tmp[1]=="number"){point.setPosition(JXG.COORDS_BY_USER,tmp);point.board.update();point.update()}}catch(err){}}function pointdeserializerparsed(point,data){try{if(typeof data[0]=="number"&&typeof data[1]=="number"){point.setPosition(JXG.COORDS_BY_USER,data);point.board.update();point.update()}}catch(err){}}function sliderserializer(slider){return JSON.stringify(slider.Value())}function sliderdeserializer(slider,data){try{slider.setValue(JSON.parse(data));slider.board.update();slider.update()}catch(err){}}function generalobjectupdatehandler(object){generalobjectupdatehandlerid(object.id)}function generalobjectupdatehandlerid(id){if(!active){active=true;try{var handledinputs=[];if(id in objectinput){for(var i=0;ipointserializer(point);var deserializer=value=>pointdeserializer(point,value);this.custom_bind(inputRef,serializer,deserializer,[point])},bind_point_dual:function(inputRef,p1,p2){var serializer=()=>{return JSON.stringify([[p1.X(),p1.Y()],[p2.X(),p2.Y()]])};var deserializer=value=>{var tmp=JSON.parse(value);pointdeserializerparsed(p1,tmp[0]);pointdeserializerparsed(p2,tmp[1])};this.custom_bind(inputRef,serializer,deserializer,[p1,p2])},bind_point_relative:function(inputRef,p1,p2){var serializer=()=>{return JSON.stringify([[p1.X(),p1.Y()],[p2.X()-p1.X(),p2.Y()-p1.Y()]])};var deserializer=value=>{var tmp=JSON.parse(value);pointdeserializerparsed(p1,tmp[0]);tmp[1][0]=tmp[1][0]+tmp[0][0];tmp[1][1]=tmp[1][1]+tmp[0][1];pointdeserializerparsed(p2,tmp[1])};this.custom_bind(inputRef,serializer,deserializer,[p1,p2])},bind_point_direction:function(inputRef,p1,p2){var serializer=()=>{return JSON.stringify([[p1.X(),p1.Y()],[Math.atan2(p2.Y()-p1.Y(),p2.X()-p1.X()),Math.sqrt((p2.X()-p1.X())*(p2.X()-p1.X())+(p2.Y()-p1.Y())*(p2.Y()-p1.Y()))]])};var deserializer=value=>{var tmp=JSON.parse(value);pointdeserializerparsed(p1,tmp[0]);var angle=tmp[1][0];var len=tmp[1][1];tmp[1][0]=tmp[0][0]+len*Math.cos(angle);tmp[1][1]=tmp[0][1]+len*Math.sin(angle);pointdeserializerparsed(p2,tmp[1])};this.custom_bind(inputRef,serializer,deserializer,[p1,p2])},bind_slider:function(inputRef,slider){var serializer=()=>sliderserializer(slider);var deserializer=value=>sliderdeserializer(slider,value);this.custom_bind(inputRef,serializer,deserializer,[slider])},bind_list_of:function(inputRef,list_of_objects){var serializer=()=>{var r="[";for(var i=0;i{var tmp=JSON.parse(value);for(var i=0;i