jqSimpleConnect

Basic example for Issue #1

HTML

<script src="https://code.jquery.com/jquery-1.12.3.min.js"></script>
<div class="title">jqSimpleConnect - Select demo</div>
        
        <button id="hide_first">
        Hide first connector
        </button>
        
        <button id="hide_last">
        Hide last connector
        </button>
        
        <button id="hide_all">
        Hide all connectors
        </button>
        
        <br><br><br>
        
        <div>
            <div style="position:relative; height: 80px;">
                <div id="div_a" style="position:absolute; top:5px; left:5px; border:1px solid black; background-color:white; padding:5px;">Div A</div>
                <div id="div_b" style="position:absolute; top:50px; left:150px; border:1px solid black; background-color:white; padding:5px;">Div B</div>
                <div id="div_c" style="position:absolute; top:25px; left:250px; border:1px solid black; background-color:white; padding:5px;">Div C</div>
                <div id="div_d" style="position:absolute; top:25px; left:400px; border:1px solid black; background-color:white; padding:5px;">Div D</div>
            </div>
        </div>

        <br>
        
        <div>
            <div style="position:relative; height: 110px;">
                <div id="div_e" style="position:absolute; top:5px; left:5px; border:1px solid black; background-color:white; padding:5px;">Div E</div>
                <div id="div_f" style="position:absolute; top:75px; left:150px; border:1px solid black; background-color:white; padding:5px;">Div F</div>
                <div id="div_g" style="position:absolute; top:5px; left:250px; border:1px solid black; background-color:white; padding:5px;">Div G</div>
                <div id="div_h" style="position:absolute; top:75px; left:400px; border:1px solid black; background-color:white; padding:5px;">Div H</div>
            </div>
        </div>

        <br>
        
        <div>
            <div style="position:relative; height: 110px;">
            ...

CSS

root { 
    display: block;
}

body {
    font-size: 11pt;
    font-family: Arial,Verdana;
}

span.highlight {
    text-decoration:underline;
}

div.title {
    font-size: 16pt;
    font-weight: bold;
    text-align: center;
    color: blueviolet;
}

h1 {
    color: darkgreen;
    font-size: 13pt;
    text-decoration: underline;
}

h2 {
    color: teal;
    font-size: 12pt;
}

h2.method {
    color: #600000;
    border-bottom: 1px solid lightgray;
}


div.method div.title {
    font-size: 11pt;
    text-align: left;
    color: black;
    margin-top: 16px;
    margin-left: 8px;
    margin-bottom: 4px;
}

div.method div.definition,
div.method div.description {
    margin-left: 50px;
}
div.method div.definition {
    margin-bottom: 24px;
}

div.method div.definition span {
    padding: 8px;
    font-size: 10pt;
    border: 1px solid gray;
    background-color: #f0f0f0;
    font-family: "Courier New";
}

div.method td {
    padding: 4px;
    vertical-align: top;
    text-align: left;
}

div.method td.name {
    color: #808080;
}

div.method td.description strong {
    font-weight: normal;
    color: #808080;
}


div.method td.description ul {
    margin-top: 4px;
    margin-left: 5px;
}

JavaScript

// jqSimpleConnect
jqSimpleConnect=new Object;jqSimpleConnect._idGenerator=0;jqSimpleConnect._connections=new Object;jqSimpleConnect._positionConnection=function(a){var b=a.elementA.offset();b.left=parseInt(b.left,10)+parseInt(a.elementA.outerWidth()/2,10);b.top=parseInt(b.top,10)+parseInt(a.elementA.outerHeight()/2,10);var c=a.elementB.offset();c.left=parseInt(c.left,10)+parseInt(a.elementB.outerWidth()/2,10);c.top=parseInt(c.top,10)+parseInt(a.elementB.outerHeight()/2,10);var d=jQuery("#"+a.id+"_1");var e=jQuery("#"+a.id+"_2");var f=jQuery("#"+a.id+"_3");if(b.left==c.left||b.top==c.top){d.show();e.hide();f.hide();if(b.left==c.left){jqSimpleConnect._positionVerticalLine(d,b,c,a.radius,a.roundedCorners)}else{jqSimpleConnect._positionHorizontalLine(d,b,c,a.radius,a.roundedCorners)}}else{if(a.anchorA!=a.anchorB){d.show();e.show();f.hide();var g=new Object;if(a.anchorA=="vertical"){g.left=b.left;g.top=c.top;jqSimpleConnect._positionVerticalLine(d,b,g,a.radius,a.roundedCorners);jqSimpleConnect._positionHorizontalLine(e,c,g,a.radius,a.roundedCorners)}else{g.left=c.left;g.top=b.top;jqSimpleConnect._positionVerticalLine(d,c,g,a.radius,a.roundedCorners);jqSimpleConnect._positionHorizontalLine(e,b,g,a.radius,a.roundedCorners)}}else{d.show();e.show();f.show();var h=new Object;var i=new Object;if(a.anchorA=="vertical"){h.top=parseInt((b.top+c.top)/2,10);i.top=h.top;h.left=b.left;i.left=c.left;jqSimpleConnect._positionVerticalLine(d,b,h,a.radius,a.roundedCorners);jqSimpleConnect._positionVerticalLine(e,c,i,a.radius,a.roundedCorners);jqSimpleConnect._positionHorizontalLine(f,h,i,a.radius,a.roundedCorners)}else{h.left=parseInt((b.left+c.left)/2,10);i.left=h.left;h.top=b.top;i.top=c.top;jqSimpleConnect._positionHorizontalLine(d,b,h,a.radius,a.roundedCorners);jqSimpleConnect._positionHorizontalLine(e,c,i,a.radius,a.roundedCorners);jqSimpleConnect._positionVerticalLine(f,h,i,a.radius,a.roundedCorners)}}}};jqSimpleConnect._positionVerticalLine=function(a,b,c,d,e){var...