jqSimpleConnect

Basic examples

HTML

<script src="https://code.jquery.com/jquery-1.12.3.min.js"></script>
<div class="title">jqSimpleConnect - Basic examples</div>
        
        <h1>Requirements</h1>
        
        <div>In order to run the examples, the JavaScript libraries of <em>jqSimpleConnect</em> and <em>jQuery</em> must be included in the
        &lt;head&gt; of the HTML file:</div>
        
        <pre>
&lt;script type=&quot;text/javascript&quot; src=&quot;js/jquery-1.7.2.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;js/jqSimpleConnect-1.0.js&quot;&gt;&lt;/script&gt;
        </pre>
        
        <h1>Demo 1</h1>
        
        <h2>Code</h2>
        <pre>
&lt;div style=&quot;position:relative; height: 80px;&quot;&gt;
    &lt;div id=&quot;div_a&quot; style=&quot;position:absolute; top:5px; left:5px; border:1px solid black; background-color:white; padding:5px;&quot;&gt;Div A&lt;/div&gt;
    &lt;div id=&quot;div_b&quot; style=&quot;position:absolute; top:50px; left:150px; border:1px solid black; background-color:white; padding:5px;&quot;&gt;Div B&lt;/div&gt;
    &lt;div id=&quot;div_c&quot; style=&quot;position:absolute; top:25px; left:250px; border:1px solid black; background-color:white; padding:5px;&quot;&gt;Div C&lt;/div&gt;
    &lt;div id=&quot;div_d&quot; style=&quot;position:absolute; top:25px; left:400px; border:1px solid black; background-color:white; padding:5px;&quot;&gt;Div D&lt;/div&gt;
&lt;/div&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
    jqSimpleConnect.connect(&quot;#div_a&quot;, &quot;#div_b&quot;, {radius: 8, color: 'green'});
    jqSimpleConnect.connect(&quot;#div_c&quot;, &quot;#div_d&quot;, {radius: 10, color: '#0000ff'});
&lt;/script&gt;
        </pre>
        
        <h2>Result</h2>
        <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>
          ...

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...