From 6289205e5dcd2ca2f3405aa8a518defc9f6f35c9 Mon Sep 17 00:00:00 2001 From: Mateiadrielrafael <39400800+Mateiadrielrafael@users.noreply.github.com> Date: Sun, 24 Jun 2018 11:27:48 +0300 Subject: [PATCH] Add files via upload Signed-off-by: prescientmoon --- scripts/and_gate.js | 1 + scripts/events.js | 39 ++++++++++++++++++++++++++++++++++++--- scripts/main.js | 34 ++++++---------------------------- scripts/not.js | 1 + 4 files changed, 44 insertions(+), 31 deletions(-) diff --git a/scripts/and_gate.js b/scripts/and_gate.js index a3e9c1e..9985026 100644 --- a/scripts/and_gate.js +++ b/scripts/and_gate.js @@ -76,6 +76,7 @@ function and(id){ function addclk(ob){ var rep = ob.rep; $((ob.img)).mousedown(function(e){ + e.preventDefault(); var svg = document.getElementById("svg1"); $(svg).append(ob.rep); $(svg).append($(ob.pin1.rep)); diff --git a/scripts/events.js b/scripts/events.js index 2bb49fc..d6914fc 100644 --- a/scripts/events.js +++ b/scripts/events.js @@ -63,14 +63,47 @@ var xbeg = 0; var ybeg = 0; var moveing = false; -$("#svg1").mousedown(function(e){ +$("svg").mousemove(function(e){ + if (moveing && selected == "yay"){ + if (!(zooming)){ + zooming = true; + + //setting our first mouse poitions + xbeg = e.pageX * zoomx/window.innerWidth; + ybeg = e.pageY * zoomy/window.innerHeight; + + xbeg += xvb; + ybeg += yvb; + console.log("started zooming"+xbeg+"and"+ybeg); + //moveing = (moveing +1)%2; + } + + var newx = e.pageX * zoomx/window.innerWidth; + var newy = e.pageY * zoomy/window.innerHeight; + + newx += xvb; + newy += yvb; + + xvb -= newx - xbeg; + yvb -= newy - ybeg; + updatescr(); + + console.log(xvb+"newx"+newx+"xbeg"+xbeg); + } +}); + + +$("svg").mousedown(function(e){ + //e.preventDefault(); moveing = true; }); -$("#svg1").mouseup(function(e){ + +$("svg").mouseup(function(e){ + e.preventDefault(); + selected = "yay"; zooming = false; moveing = false; - console.log("got a mouse up"); }); diff --git a/scripts/main.js b/scripts/main.js index 5371283..e89ad24 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -28,6 +28,9 @@ $(modal).mousedown(function(e){ //and 'addel' is the true id of the modal from DOM $("#addel").modal("show"); + //being sure we wont move the components + moveing = false; + //activatng the drag and drop for the blue box selected = "butt"; }); @@ -66,11 +69,12 @@ function addel(){ //================================preventing deafult actions========================== //nothing to say here -$("img,rect,circle,p").mousedown(function(e){ +$("img,rect,circle,p,foreignObject").mousedown(function(e){ e.preventDefault(); }); $("*").mouseup(function(e){ e.preventDefault(); + moveing = false; }); $("img").click(function(e){ e.preventDefault(); @@ -102,38 +106,12 @@ let snap = false; $("body").mousemove(function(e){ //calling the drag function drag(e,selected); - - if (moveing){ - if (!(zooming)){ - zooming = true; - - //setting our first mouse poitions - xbeg = e.pageX * zoomx/window.innerWidth; - ybeg = e.pageY * zoomy/window.innerHeight; - - xbeg += xvb; - ybeg += yvb; - console.log("started zooming"+xbeg+"and"+ybeg); - } - - var newx = e.pageX * zoomx/window.innerWidth; - var newy = e.pageY * zoomy/window.innerHeight; - - newx += xvb; - newy += yvb; - - xvb -= newx - xbeg; - yvb -= newy - ybeg; - updatescr(); - - console.log(xvb+"newx"+newx+"xbeg"+xbeg); - } }); $("body").mouseup(function(e){ selected = "yay"; + console.log("got a mouse up"); }); $("body").mousedown(function(e){ - //beeing sure that we actually want to drag something if (selected!="yay"){ diff --git a/scripts/not.js b/scripts/not.js index 2ba4a78..bec9c67 100644 --- a/scripts/not.js +++ b/scripts/not.js @@ -74,6 +74,7 @@ function not(id){ function addclk11(ob){ var rep = ob.rep; $((ob.img)).mousedown(function(e){ + e.preventDefault(); var svg = document.getElementById("svg1"); $(svg).append(ob.rep); $(svg).append($(ob.pin1.rep));