LambrechtsWouter / jsplumb

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

can not add endpoints to elemnts with index #317

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
the fiddle: http://jsfiddle.net/2hW84/3/

i can make elements draggable per jsPlumb, but not add endPoint to it

console error: Uncaught TypeError: Cannot read property 'left' of undefined 

escaping square brackets in jQuery selectors: 
http://api.jquery.com/category/selectors/

keep up the good work!

Original issue reported on code.google.com by oliver.e...@in2code.de on 5 Feb 2013 at 12:04

GoogleCodeExporter commented 8 years ago
hmm, i dont know about this.  i dont want to have to escape every id.

Original comment by simon.po...@gmail.com on 5 Feb 2013 at 1:01

GoogleCodeExporter commented 8 years ago
i'd like to help you with this problem, but i'm fairly new to javascript and 
jQuery.

is it possible to substitute the brackets with other chars (maybe '_sqbr_' for 
sqare brackets), so jsPlumb doesn't get confused with them. and at the and you 
convert them back

Original comment by oliver.e...@in2code.de on 5 Feb 2013 at 9:05

GoogleCodeExporter commented 8 years ago
i really dont want to add some code to jsplumb that runs a string replace every 
time it wants to use an id. 

if you really want to use brackets then you can override the jsplumb method 
that does a selector lookup - see this fiddle:

http://jsfiddle.net/2hW84/10/

the code you need is this (you would include this after jsplumb):

var gel = jsPlumb.CurrentLibrary.getElementObject;   // store ref to original
jsPlumb.CurrentLibrary.getElementObject = function(el) {
    // if given a string, perform replacement
    if (typeof el == "string")
        el = el.replace("[", "\\[").replace("]", "\\]");

    // now pass that id with escaped brackets to the original method
    return gel(el);
 };

Original comment by simon.po...@gmail.com on 5 Feb 2013 at 9:16

GoogleCodeExporter commented 8 years ago
a thousand thanks :)
works fine!

Original comment by oliver.e...@in2code.de on 5 Feb 2013 at 10:17

GoogleCodeExporter commented 8 years ago
ok cool. glad it works.  i'm gonna close the issue out as a wontfix.

Original comment by simon.po...@gmail.com on 5 Feb 2013 at 10:28

GoogleCodeExporter commented 8 years ago
if someone wants to use jsPlumb.addEnpoint with multiple index:
http://jsfiddle.net/2hW84/11/

or use:

var gel = jsPlumb.CurrentLibrary.getElementObject;
    jsPlumb.CurrentLibrary.getElementObject = function(el) {
       if (typeof el == "string")
           el = el.replace(/\[/g, "\\[").replace(/\]/g, "\\]");
        return gel(el);
    };

i just inserted a regular expression, so all occurences get replaced :D

Original comment by oliver.e...@in2code.de on 5 Feb 2013 at 1:23