<div id="plumb"> <div id="window1"> <a class="makesource" id="enableDisableSource">+</a> </div> <div class="smallWindow" id="b1" style="top:50%;left:50%"> <a class="enableDisableSource">+</a> </div> <div class="smallWindow" id="b2" style="top:75%;left:25%;"> <a class="enableDisableSource">+</a> </div> </div> <a id="add">+</a> <div class="switch has-switch switch-square"> <div class="switch-on switch-animate" style=""> <input type="checkbox" checked="" data-toggle="switch"/> <span class="switch-left">ON</span> <label> </label> <span class="switch-right">OFF</span> </div> </div>
body { background:#EEE; } #container0, #window1 { float: left; height: 100px; width: 300px; margin: 10px; background:#333; } .smallWindow { width:100px; height:50px; background:#333; top:100px; position:absolute; } #add { position:absolute; top:50px; color:#333; background:#fff; display:block; width:20px; height:20px; cursor:pointer; text-align:center; font-weight:bold; right:10px; }
jsPlumb.bind("ready", function () { // list of possible anchor locations for the blue source element var sourceAnchors = [ [0, 1, 0, 1], [0.25, 1, 0, 1], [0.5, 1, 0, 1], [0.75, 1, 0, 1], [1, 1, 0, 1], [1, 0.25, 1, 1] ]; jsPlumb.importDefaults({ // set default anchors. the 'connect' calls below will pick these up, and in fact setting these means // that you also do not need to supply anchor definitions to the makeSource or makeTarget functions. Anchors: [sourceAnchors, sourceAnchors], // drag options DragOptions: { cursor: "pointer", zIndex: 2000 }, // default to blue at source and green at target EndpointStyles: [{ fillStyle: "#00AFD7" }, { fillStyle: "#00AFD7" }], // blue endpoints 7 px; green endpoints 11. Endpoints: [ ["Dot", { radius: 7 }], ["Dot", { radius: 11 }] ], // default to a gradient stroke from blue to green. for IE provide all green fallback. PaintStyle: { /*gradient: { stops: [ [0, "#225588"], [1, "#558822"] ] },*/ strokeStyle: "#00AFD7", lineWidth: 10 } }); // make 'window1' a connection source. notice the filter parameter: it tells jsPlumb to ignore drags // that started on the 'enable/disable' link on the blue window. jsPlumb.makeSource("window1", { //anchor:sourceAnchors, // you could supply this if you want, but it was set in the defaults above. filter: function (evt, el) { var t = evt.target || evt.srcElement; return t.tagName !== "A"; } }); // get the list of ".smallWindow" elements. var smallWindows = $(".smallWindow"); // make them draggable jsPlumb.draggable(smallWindows); // configure them as targets. jsPlumb.makeTarget(smallWindows, { //anchor:"TopCenter", // you could supply this if you want, but it was set in the defaults above. dropOptions: { hoverClass: "hover" } }); jsPlumb.makeSource(smallWindows, { filter: function (evt, el) { var t = evt.target || evt.srcElement; return t.tagName !== "A"; } }); jsPlumb.toggleSourceEnabled(smallWindows); // and finally connect a couple of small windows, just so its obvious what's going on when this demo loads. jsPlumb.connect({ source: "window1", target: "b1" }); jsPlumb.connect({ source: "window1", target: "b2" }); // click listener for the enable/disable link. $(".enableDisableSource").bind("click", function () { var state = jsPlumb.toggleSourceEnabled($(this).parent('div')); $(this).html(state ? "-" : "+"); //var candrag = jsPlumb.toggleDraggable("window1"); //alert(state); //jsPlumb.draggable("window1"); jsPlumb.toggleDraggable($(this).parent('div')); }); }); $(document).ready(function () { $("[data-toggle='switch']").wrap('<div class="switch" />').parent().bootstrapSwitch(); $('#add').click(function () { //alert('rad'); $('#plumb').append('<div class="smallWindow" style="top:50%;left:50%"> <a class="enableDisableSource">+</a>'); var smallWindows = $(".smallWindow"); // make them draggable jsPlumb.draggable(smallWindows); // configure them as targets. jsPlumb.makeTarget(smallWindows, { //anchor:"TopCenter", // you could supply this if you want, but it was set in the defaults above. dropOptions: { hoverClass: "hover" } }); }); //alert('ready'); });