dugarab / jsplumb

Automatically exported from code.google.com/p/jsplumb
0 stars 0 forks source link

removeAllEndpoints #302

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
hello,I had a project 
in there I want to do that remove one node and repaintEverythis,so I  first 
removeAllEndpoints and then   jsPlumb.repaintEverything();
{
var id = currentObject.ID;
jsPlumb.removeAllEndpoints(id);
jsPlumb.repaintEverything();
}
but error.

In jsplumb,
this.removeAllEndpoints = function(el) {
            var elId = _getAttribute(el, "id"),
                ebe = endpointsByElement[elId];
            if (ebe) {
                for ( var i = 0; i < ebe.length; i++) 
                    _currentInstance.deleteEndpoint(ebe[i]);
            }
            endpointsByElement[elId] = [];
            //delete endpointsByElement[elId];//qiulijie
        };
endpointsByElement set endpoint null ,but i think we should delete 
endpointsByElement[elId],so repaintEverything() is right.

I think this way better,or you have another way to solve this problem.please 
tell me ,thank you ........my English is soso.sorry.

Original issue reported on code.google.com by 786350...@qq.com on 18 Dec 2012 at 9:16

GoogleCodeExporter commented 8 years ago
i tested this in the console of http://jsplumb.org:

jsPlumb.removeAllEndpoints("window1");
jsPlumb.repaintEverything();

and i don't see an error. what error are you seeing?

Original comment by simon.po...@gmail.com on 18 Dec 2012 at 10:47

GoogleCodeExporter commented 8 years ago
I think it only causes an error if the element has been removed from the page.

Repro on jsplumb.org:
jsPlumb.removeAllEndpoints("window1");
$('#window1').remove();
jsPlumb.repaintEverything();

TypeError: Cannot read property 'left' of undefined 
(jquery.jsPlumb-1.3.16-all.js:593)

repaintEverything tries to draw every key in endpointsByElement, even if there 
are no  endpoints and the element is gone. Not sure if there is any reason for 
it to be looking at elements with no endpoints left.

Maybe more proper place to fix is in deleteEndpoint, since you could remove the 
last endpoint that way.

Original comment by next...@gmail.com on 23 Dec 2012 at 6:33

GoogleCodeExporter commented 8 years ago
Here's an evil, terrible hack to work around the issue without changing library 
code:
// after deleting endpoints or before calling repaintEverything
var ep = jsPlumb.getTestHarness().endpointsByElement;
for(var k in ep) { if (ep.hasOwnProperty(k) && ep[k].length === 0) delete 
ep[k]; }

Original comment by next...@gmail.com on 23 Dec 2012 at 6:51

GoogleCodeExporter commented 8 years ago
I think probably there's a couple of things that need to be done - first the 
code should be hardened so as not to fail when drawing from endpointsByElement. 
but also jsPlumb should probably have a 'remove' method which takes care of 
cleaning up endpoints and then delegates to the underlying library's 'remove' 
method.

Original comment by simon.po...@gmail.com on 23 Dec 2012 at 10:22

GoogleCodeExporter commented 8 years ago
so i just took a look at this.  removeAllEndpoints was actually expecting a DOM 
element or a selector; an ID would not work.  I have fixed that, and I've also 
added a 'remove' method to jsPlumb.

this will be in 1.4.0.

Original comment by simon.po...@gmail.com on 24 Dec 2012 at 2:31

GoogleCodeExporter commented 8 years ago

Original comment by simon.po...@gmail.com on 7 Jan 2013 at 8:41