issue23_test_mootools.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <!DOCTYPE html>
  2. <html><head>
  3. <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
  4. <title>jsPlumb - draggable connectors experiments - jQuery</title>
  5. <meta http-equiv="X-UA-Compatible" content="IE=7">
  6. <link rel="stylesheet" href="draggableConnectorsDemo_fichiers/mp.css">
  7. <link rel="stylesheet" href="draggableConnectorsDemo_fichiers/jsPlumbDemo.css">
  8. <style type="text/css">
  9. html,body{
  10. height:100%;
  11. }
  12. #el_container{
  13. border:1px solid pink;
  14. left:100px;
  15. position:absolute;
  16. top:100px;
  17. width:80%;
  18. height:80%;
  19. }
  20. #pos_info{
  21. position:absolute;
  22. bottom:10px;
  23. left:10px;
  24. }
  25. #window1 { top:6em;left:15%; }
  26. #window2 { top:6em; right:15%; }
  27. #window3 { top:24em; left:15%; }
  28. #window4 { top:24em; right:15%}
  29. .window { border:1px solid gray; width:9.7em; height:8em; z-index:20; position:absolute; color:gray;font-family:serif;font-style:italic;
  30. padding-top:0.9em; font-size:0.9em;text-align:center;z-index:40;background-color:white; }
  31. .drag-locked { border:1px solid red; }
  32. ._jsPlumb_endpoint { z-index:50; }
  33. ._jsPlumb_connector { z-index:1; }
  34. .dropHover { border:1px dotted red; }
  35. .dragActive { border:2px dotted orange; }
  36. #explanation { width:30%; background-color:transparent;z-index:2;font-size:1.2em;color:gray;border:none;position:relative;left:35%;right:auto;text-align:center; }
  37. .cmdLink { font-size:0.80em;}
  38. #clear { padding:0.3em; }
  39. #clear:hover { background-color:yellow; }
  40. #list { display:none; border-bottom:1px dotted grey; padding-bottom:1.5em; font-size:90%;}
  41. #list table { width:100%; text-align:left;}
  42. </style>
  43. </head>
  44. <body onunload="jsPlumb.unload();">
  45. <div class="menu"><a href="http://morrisonpitt.com/jsPlumb/html/index.html" class="mplink">jsPlumb home</a>&nbsp;|&nbsp;<a href="http://morrisonpitt.com/jsPlumb/doc/usage.html" class="mplink">view documentation</a>&nbsp;|&nbsp;<a href="mailto:simon.porritt@gmail.com" class="mplink">contact me</a>&nbsp;|&nbsp;<a href="http://code.google.com/p/jsplumb/" class="mplink">jsPlumb on Google code</a></div>
  46. <div id="el_container">
  47. <div class="window ui-draggable" id="window1">one<br><br><a href="#" class="cmdLink hide" rel="window1">toggle connections</a><br><a href="#" class="cmdLink drag" rel="window1">disable dragging</a><br><a href="#" class="cmdLink detach" rel="window1">detach all</a></div>
  48. <div class="window ui-draggable" id="window2">two<br><br><a href="#" class="cmdLink hide" rel="window2">toggle connections</a><br><a href="#" class="cmdLink drag" rel="window2">disable dragging</a><br><a href="#" class="cmdLink detach" rel="window2">detach all</a></div>
  49. <div class="window ui-draggable" id="window3">three<br><br><a href="#" class="cmdLink hide" rel="window3">toggle connections</a><br><a href="#" class="cmdLink drag" rel="window3">disable dragging</a><br><a href="#" class="cmdLink detach" rel="window3">detach all</a></div>
  50. <div class="window ui-draggable" id="window4">four<br><br><a href="#" class="cmdLink hide" rel="window4">toggle connections</a><br><a href="#" class="cmdLink drag" rel="window4">disable dragging</a><br><a href="#" class="cmdLink detach" rel="window4">detach all</a></div>
  51. <div id="pos_info">
  52. </div>
  53. <div id="explanation">
  54. <div id="list"></div>
  55. <p>this demo uses jsPlumb 1.2.2, jQuery 1.4.2 and jQuery UI 1.8.0.</p><p>drag between similar endpoints to create connections.</p><p>upon disconnection, yellow connections automatically reattach</p><p>the others are removed.</p><p>green endpoints support up to three connections.</p>
  56. <a id="clear" href="#">clear plumbing</a><br><br>
  57. <a href="http://morrisonpitt.com/jsPlumb/html/jquery/dragAnimDemo.html">next: animated dragging demo</a><br><br>
  58. </div>
  59. <script type="text/javascript" src="http://explorercanvas.googlecode.com/svn/trunk/excanvas.js"></script>
  60. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/mootools/1.2.4/mootools-yui-compressed.js"></script>
  61. <script type="text/javascript" src="../js/mootools-1.2.4.4-more.js"></script>
  62. <script type="text/javascript" src="../js/1.2.3/jsPlumb-defaults-1.2.3-RC1.js"></script>
  63. <script type="text/javascript" src="../js/1.2.3/mootools.jsPlumb-1.2.3-RC1.js"></script>
  64. <script>
  65. jQuery(function(){
  66. $("#el_container").draggable({
  67. drag:function(event,ui){
  68. var $this=ui.helper;
  69. $("#pos_info").empty()
  70. .append("Position:"+$this.css("position")).append("<br/>")
  71. .append("Left:"+ui.offset.left).append("<br/>")
  72. .append("Top:"+ui.offset.top);
  73. }
  74. }).trigger("drag");
  75. });
  76. </script>
  77. <script type="text/javascript">
  78. $(document).ready(function() {
  79. //Kaboom
  80. jsPlumb.Defaults.Container="el_container";
  81. jsPlumb.Defaults.DragOptions = { cursor: 'pointer', zIndex:2000 };
  82. jsPlumb.Defaults.PaintStyle = { strokeStyle:'#666' };
  83. jsPlumb.Defaults.EndpointStyle = { width:20, height:16, strokeStyle:'#666' };
  84. jsPlumb.Defaults.Endpoint = new jsPlumb.Endpoints.Rectangle();
  85. jsPlumb.Defaults.Anchors = [jsPlumb.Anchors.TopCenter, jsPlumb.Anchors.TopCenter];
  86. var showConnections = function() {
  87. var c = jsPlumb.getConnections();
  88. var foundSome = false;
  89. var s = "<span>current connections</span><br/><br/><table><tr><th>scope</th><th>source</th><th>target</th></tr>";
  90. for (var i in c) {
  91. var l = c[i];
  92. if (l && l.length > 0) {
  93. foundSome = true;
  94. for (var j = 0; j < l.length; j++) {
  95. s = s + "<tr><td>" + i + "</td>" + "<td>" + l[j].sourceId + "</td><td>" + l[j].targetId + "</td></tr>";
  96. }
  97. }
  98. }
  99. s = s + "</table>";
  100. if (foundSome) {
  101. $("#list").html(s);
  102. $("#list").fadeIn({complete:function() { jsPlumb.repaintEverything(); }});
  103. } else $("#list").fadeOut({complete:function() { jsPlumb.repaintEverything(); }});
  104. };
  105. // connection listener
  106. jsPlumb.addListener(["jsPlumbConnection","jsPlumbConnectionDetached"], {
  107. jsPlumbConnection : function(p) { showConnections(); },
  108. jsPlumbConnectionDetached : function(p) { showConnections(); }
  109. });
  110. var exampleDropOptions = {
  111. tolerance:'touch',
  112. hoverClass:'dropHover',
  113. activeClass:'dragActive'
  114. };
  115. /**
  116. first example endpoint. it's a 25x21 rectangle (the size is provided in the 'style' arg to the Endpoint), and it's both a source
  117. and target. the 'scope' of this Endpoint is 'exampleConnection', meaning any connection starting from this Endpoint is of type
  118. 'exampleConnection' and can only be dropped on an Endpoint target that declares 'exampleEndpoint' as its drop scope, and also that
  119. only 'exampleConnection' types can be dropped here.
  120. the connection style for this endpoint is a Bezier curve (we didn't provide one, so we use the default), with a lineWidth of
  121. 5 pixels, and a gradient.
  122. note the use of the '$.extend' function to setup generic connection types. this will save you a lot of typing, and probably
  123. errors.
  124. */
  125. var exampleColor = '#00f';
  126. var exampleEndpoint = {
  127. endpoint:new jsPlumb.Endpoints.Rectangle(),
  128. style:{ width:25, height:21, fillStyle:exampleColor },
  129. isSource:true,
  130. scope:'blue rectangle',
  131. connectorStyle : {
  132. gradient:{stops:[[0, exampleColor], [0.5, '#09098e'], [1, exampleColor]]},
  133. lineWidth:5,
  134. strokeStyle:exampleColor
  135. },
  136. isTarget:true,
  137. dropOptions : exampleDropOptions
  138. };
  139. /**
  140. the second example uses a Dot of radius 15 as the endpoint marker, is both a source and target, and has scope
  141. 'exampleConnection2'.
  142. */
  143. var color2 = '#316b31';
  144. var exampleEndpoint2 = {
  145. endpoint:new jsPlumb.Endpoints.Dot({radius:15}),
  146. style:{ strokeStyle:color2 },
  147. isSource:true,
  148. scope:'green dot',
  149. connectorStyle:{ strokeStyle:color2, lineWidth:8 },
  150. connector: new jsPlumb.Connectors.Bezier(63),
  151. maxConnections:3,
  152. isTarget:true,
  153. dropOptions : exampleDropOptions
  154. };
  155. /**
  156. the third example uses a Dot of radius 17 as the endpoint marker, is both a source and target, and has scope
  157. 'exampleConnection3'. it uses a Straight connector, and the Anchor is created here (bottom left corner) and never
  158. overriden, so it appears in the same place on every element.
  159. this example also sets the 'reattach' flag for the Endpoint, meaning that when you drag a
  160. connection off an endpoint and release it, it snaps back. the default behaviour in this case
  161. is to delete the connection.
  162. */
  163. var example3Color = "rgba(229,219,61,0.5)";
  164. var exampleEndpoint3 = {
  165. endpoint:new jsPlumb.Endpoints.Dot({radius:17}),
  166. reattach:true,
  167. anchor:jsPlumb.Anchors.BottomLeft,
  168. style:{ strokeStyle:example3Color, opacity:0.5 },
  169. isSource:true,
  170. scope:'yellow dot',
  171. connectorStyle:{ strokeStyle:example3Color, lineWidth:4 },
  172. connector : new jsPlumb.Connectors.Straight(),
  173. isTarget:true,
  174. dropOptions : exampleDropOptions
  175. };
  176. // setup some empty endpoints. again note the use of '$.extend' to reuse all the parameters except the location
  177. // of the anchor (purely because we want to move the anchor around here; you could set it one time and forget about it though.)
  178. jsPlumb.addEndpoints('window1', [
  179. $.extend({ anchor:jsPlumb.makeAnchor(1, 0.25, 1, 0) }, exampleEndpoint),
  180. $.extend({ anchor:jsPlumb.makeAnchor(1, 0.75, 0, 1) }, exampleEndpoint),
  181. $.extend({ anchor:jsPlumb.makeAnchor(0.5, 1, 0, 1) }, exampleEndpoint2)
  182. ]);
  183. jsPlumb.addEndpoints('window2', [
  184. $.extend({ anchor:jsPlumb.makeAnchor(0.5, 1, 0, 1) }, exampleEndpoint),
  185. $.extend({ anchor:jsPlumb.Anchors.RightMiddle }, exampleEndpoint2)
  186. ]);
  187. jsPlumb.addEndpoints('window3', [
  188. $.extend({ anchor:jsPlumb.makeAnchor(0.25, 0, 0, -1) }, exampleEndpoint),
  189. $.extend({ anchor:jsPlumb.makeAnchor(0.75, 0, 0, -1) }, exampleEndpoint2)
  190. ]);
  191. jsPlumb.addEndpoints('window4', [
  192. $.extend({ anchor:jsPlumb.makeAnchor(1, 0.5, 1, 0) }, exampleEndpoint),
  193. $.extend({ anchor:jsPlumb.makeAnchor(0.25, 0, 0, -1) }, exampleEndpoint2)
  194. ]);
  195. // three ways to do this - an id, a list of ids, or a selector (note the two different types of selectors shown here...anything that is valid jquery will work of course)
  196. //jsPlumb.draggable("window1");
  197. //jsPlumb.draggable(["window1", "window2"]);
  198. //jsPlumb.draggable($("#window1"));
  199. jsPlumb.draggable($(".window"));
  200. // add the third example using the '.window' class.
  201. $(".window").addEndpoint(exampleEndpoint3);
  202. $(".hide").click(function() {
  203. jsPlumb.toggle($(this).attr("rel"));
  204. });
  205. $(".drag").click(function() {
  206. var s = jsPlumb.toggleDraggable($(this).attr("rel"));
  207. $(this).html(s ? 'disable dragging' : 'enable dragging');
  208. if (!s) $("#" + $(this).attr("rel")).addClass('drag-locked'); else $("#" + $(this).attr("rel")).removeClass('drag-locked');
  209. $("#" + $(this).attr("rel")).css("cursor", s ? "pointer" : "default");
  210. });
  211. $(".detach").click(function() {
  212. jsPlumb.detachAll($(this).attr("rel"));
  213. });
  214. $("#clear").click(function() { jsPlumb.detachEverything(); showConnections(); });
  215. });
  216. </script>
  217. </body></html>