From 4d3e472a1942e355931be5770e1aec446b9e786f Mon Sep 17 00:00:00 2001 From: tamat Date: Sun, 27 Dec 2015 19:41:06 +0100 Subject: [PATCH] fixed two bugs --- build/litegraph.js | 10 +++++++--- build/litegraph.min.js | 6 +++--- src/litegraph.js | 10 +++++++--- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/build/litegraph.js b/build/litegraph.js index c55d96863..dfcb5b5f2 100644 --- a/build/litegraph.js +++ b/build/litegraph.js @@ -1884,6 +1884,7 @@ LGraphNode.prototype.disconnectOutput = function(slot, target_node) if(!output.links || output.links.length == 0) return false; + //one of the links if(target_node) { if(target_node.constructor === Number) @@ -1906,7 +1907,7 @@ LGraphNode.prototype.disconnectOutput = function(slot, target_node) } } } - else + else //all the links { for(var i = 0, l = output.links.length; i < l; i++) { @@ -1916,6 +1917,7 @@ LGraphNode.prototype.disconnectOutput = function(slot, target_node) var target_node = this.graph.getNodeById( link_info.target_id ); if(target_node) target_node.inputs[ link_info.target_slot ].link = null; //remove other side link + delete this.graph.links[ link_id ]; //remove the link from the links pool } output.links = null; } @@ -4779,11 +4781,13 @@ LiteGraph.createContextualMenu = function(values,options, ref_window) root.addEventListener("mouseout", function(e) { //console.log("OUT!"); - var aux = e.toElement; + //check if mouse leave a inner element + var aux = e.relatedTarget || e.toElement; while(aux != this && aux != ref_window.document) aux = aux.parentNode; - if(aux == this) return; + if(aux == this) + return; this.mouse_inside = false; if(!this.block_close) this.closeMenu(); diff --git a/build/litegraph.min.js b/build/litegraph.min.js index 91a6e727a..28e06fc92 100755 --- a/build/litegraph.min.js +++ b/build/litegraph.min.js @@ -48,7 +48,7 @@ LGraphNode.prototype.connect=function(a,b,c){c=c||0;if(a.constructor===String){i console.log("Connect: Error, no slot of name "+c),!1}else if(!b.inputs||c>=b.inputs.length)return LiteGraph.debug&&console.log("Connect: Error, slot number not found"),!1;-1!=c&&null!=b.inputs[c].link&&b.disconnectInput(c);this.setDirtyCanvas(!1,!0);this.graph.onConnectionChange();var d=this.outputs[a];if(b.onConnectInput&&!1===b.onConnectInput(c,d.type,d))return!1;-1==c?(null==d.links&&(d.links=[]),d.links.push({id:b.id,slot:-1})):d.type&&b.inputs[c].type&&d.type.toLowerCase()!=b.inputs[c].type.toLowerCase()|| (a={id:this.graph.last_link_id++,origin_id:this.id,origin_slot:a,target_id:b.id,target_slot:c},this.graph.links[a.id]=a,null==d.links&&(d.links=[]),d.links.push(a.id),b.inputs[c].link=a.id);return!0}; LGraphNode.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return LiteGraph.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return LiteGraph.debug&&console.log("Connect: Error, slot number not found"),!1;var c=this.outputs[a];if(!c.links||0==c.links.length)return!1;if(b){b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Target Node not found";for(var d=0,e=c.links.length;d< -e;d++){var f=c.links[d],g=this.graph.links[f];if(g.target_id==b.id){c.links.splice(d,1);b.inputs[g.target_slot].link=null;delete this.graph.links[f];break}}}else{d=0;for(e=c.links.length;d=this.inputs.length)return LiteGraph.debug&&console.log("Connect: Error, slot number not found"),!1;if(!this.inputs[a])return!1;var b=this.inputs[a].link;this.inputs[a].link=null;if(b=this.graph.links[b]){a=this.graph.getNodeById(b.origin_id);if(!a)return!1;a=a.outputs[b.origin_slot];if(!a|| !a.links||0==a.links.length)return!1;for(var c=0,d=a.links.length;cb&&this.inputs[b].pos?[this.pos[0]+this.inputs[b].pos[0],this.pos[1]+this.inputs[b].pos[1]]:!a&&this.outputs.length>b&&this.outputs[b].pos?[this.pos[0]+this.outputs[b].pos[0],this.pos[1]+this.outputs[b].pos[1]]: @@ -140,8 +140,8 @@ function isInsideBounding(a,b){return a[0]b[1][0]|| function num2hex(a){for(var b="#",c,d,e=0;3>e;e++)c=a[e]/16,d=a[e]%16,b+="0123456789ABCDEF".charAt(c)+"0123456789ABCDEF".charAt(d);return b} LiteGraph.createContextualMenu=function(a,b,c){function d(a){var c=!0;b.callback&&(a=b.callback.call(e,this.data,a),void 0!==a&&(c=a));c&&LiteGraph.closeAllContextualMenus()}this.options=b=b||{};c=c||window;b.from||LiteGraph.closeAllContextualMenus();var e=c.document.createElement("div");e.className="graphcontextualmenu graphmenubar-panel";this.root=e;var f=e.style;f.minWidth="100px";f.minHeight="20px";f.position="fixed";f.top="100px";f.left="100px";f.color="#AAF";f.padding="2px";f.borderBottom="2px solid #AAF"; f.backgroundColor="#444";b.title&&(f=document.createElement("div"),f.className="graphcontextualmenu-title",f.innerHTML=b.title,e.appendChild(f));e.addEventListener("contextmenu",function(a){a.preventDefault();return!1});for(var g in a){var h=a[g],f=c.document.createElement("div");f.className="graphmenu-entry";null==h?f.className="graphmenu-entry separator":(h.is_menu&&(f.className+=" submenu"),h.disabled&&(f.className+=" disabled"),f.style.cursor="pointer",f.dataset.value="string"==typeof h?h:h.value, -f.data=h,f.innerHTML="string"==typeof h?a.constructor==Array?a[g]:g:h.content?h.content:g,f.addEventListener("click",d));e.appendChild(f)}e.addEventListener("mouseover",function(a){this.mouse_inside=!0});e.addEventListener("mouseout",function(a){for(a=a.toElement;a!=this&&a!=c.document;)a=a.parentNode;a!=this&&(this.mouse_inside=!1,this.block_close||this.closeMenu())});c.document.body.appendChild(e);a=e.getClientRects()[0];b.from&&(b.from.block_close=!0);h=b.left||0;g=b.top||0;b.event&&(h=b.event.pageX- -10,g=b.event.pageY-10,b.left&&(h=b.left),f=c.document.body.getClientRects()[0],b.from&&(h=b.from.getClientRects()[0],h=h.left+h.width),h>f.width-a.width-10&&(h=f.width-a.width-10),g>f.height-a.height-10&&(g=f.height-a.height-10));e.style.left=h+"px";e.style.top=g+"px";e.closeMenu=function(){b.from&&(b.from.block_close=!1,b.from.mouse_inside||b.from.closeMenu());this.parentNode&&c.document.body.removeChild(this)};return e}; +f.data=h,f.innerHTML="string"==typeof h?a.constructor==Array?a[g]:g:h.content?h.content:g,f.addEventListener("click",d));e.appendChild(f)}e.addEventListener("mouseover",function(a){this.mouse_inside=!0});e.addEventListener("mouseout",function(a){for(a=a.relatedTarget||a.toElement;a!=this&&a!=c.document;)a=a.parentNode;a!=this&&(this.mouse_inside=!1,this.block_close||this.closeMenu())});c.document.body.appendChild(e);a=e.getClientRects()[0];b.from&&(b.from.block_close=!0);h=b.left||0;g=b.top||0;b.event&& +(h=b.event.pageX-10,g=b.event.pageY-10,b.left&&(h=b.left),f=c.document.body.getClientRects()[0],b.from&&(h=b.from.getClientRects()[0],h=h.left+h.width),h>f.width-a.width-10&&(h=f.width-a.width-10),g>f.height-a.height-10&&(g=f.height-a.height-10));e.style.left=h+"px";e.style.top=g+"px";e.closeMenu=function(){b.from&&(b.from.block_close=!1,b.from.mouse_inside||b.from.closeMenu());this.parentNode&&c.document.body.removeChild(this)};return e}; LiteGraph.closeAllContextualMenus=function(){var a=document.querySelectorAll(".graphcontextualmenu");if(a.length){for(var b=[],c=0;c