demo.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. this is the JS for the main jsPlumb demo. it is shared between the YUI, jQuery and MooTools
  3. demo pages.
  4. */
  5. ;(function() {
  6. window.jsPlumbDemo = {
  7. init : function() {
  8. jsPlumb.DefaultDragOptions = { cursor: "pointer", zIndex:2000 };
  9. jsPlumb.setMouseEventsEnabled(true);
  10. var connectorStrokeColor = "rgba(50, 50, 200, 1)",
  11. connectorHighlightStrokeColor = "rgba(180, 180, 200, 1)",
  12. hoverPaintStyle = { lineWidth:13,strokeStyle:"#7ec3d9" };
  13. //
  14. // connect window1 to window2 with a 13 px wide olive colored Bezier, from the BottomCenter of
  15. // window1 to 3/4 of the way along the top edge of window2. give the connection a 1px black outline,
  16. // and allow the endpoint styles to derive their color and outline from the connection.
  17. // label it "Connection One" with a label at 0.7 of the length of the connection, and put an arrow that has a 50px
  18. // wide tail at a point 0.2 of the length of the connection. we use 'cssClass' and 'endpointClass' to assign
  19. // our own css classes, and the Label overlay has three css classes specified for it too. we also give this
  20. // connection a 'hoverPaintStyle', which defines the appearance when the mouse is hovering over it.
  21. //
  22. var connection1 = jsPlumb.connect({
  23. source:'window1',
  24. target:'window2',
  25. connector:"Bezier",
  26. cssClass:"c1",
  27. endpointClass:"c1Endpoint",
  28. anchors:["BottomCenter", [ 0.75, 0, 0, -1 ]],
  29. paintStyle:{
  30. lineWidth:13,
  31. strokeStyle:"#a7b04b",
  32. outlineWidth:1,
  33. outlineColor:"#666"/*,
  34. dashstyle:"2 2"*/
  35. },
  36. hoverPaintStyle:hoverPaintStyle,
  37. overlays : [ ["Label", {
  38. cssClass:"l1 component label",
  39. label : "Connection One",
  40. location:0.7,
  41. id:"label",
  42. events:{
  43. "click":function(label, evt) {
  44. alert("clicked on label for connection 1");
  45. }
  46. }
  47. } ],
  48. ["Arrow", {
  49. location:0.2, width:50,
  50. events : {
  51. "click":function(arrow, evt) {
  52. alert("clicked on arrow for connection 1");
  53. }
  54. }
  55. }]
  56. ]});
  57. var w23Stroke = "rgb(189,11,11)";
  58. var connection3 = jsPlumb.connect({
  59. source:"window2",
  60. target:"window3",
  61. paintStyle:{
  62. lineWidth:8,
  63. strokeStyle:w23Stroke,
  64. outlineColor:"#666",
  65. outlineWidth:1
  66. },
  67. hoverPaintStyle:hoverPaintStyle,
  68. anchors:[ [ 0.3 , 1, 0, 1 ], "TopCenter" ],
  69. endpoint:"Rectangle",
  70. endpointStyles:[
  71. { gradient : { stops:[[0, w23Stroke], [1, "#558822"]] }},
  72. { gradient : {stops:[[0, w23Stroke], [1, "#882255"]] }}
  73. ]
  74. });
  75. var connection2 = jsPlumb.connect({source:'window3', target:'window4',
  76. paintStyle:{
  77. lineWidth:10,
  78. strokeStyle:connectorStrokeColor,
  79. outlineColor:"#666",
  80. outlineWidth:1
  81. },
  82. hoverPaintStyle:hoverPaintStyle,
  83. anchors:["AutoDefault", "AutoDefault"],
  84. endpointStyle:{
  85. gradient : {
  86. stops:[[0, connectorStrokeColor], [1, connectorHighlightStrokeColor]],
  87. offset:17.5,
  88. innerRadius:15
  89. },
  90. radius:35
  91. },
  92. label : function(connection) {
  93. var d = new Date();
  94. var fmt = function(n) { return (n < 10 ? "0" : "") + n; };
  95. return (fmt(d.getHours()) + ":" + fmt(d.getMinutes()) + ":" + fmt(d.getSeconds())+ "." + fmt(d.getMilliseconds()));
  96. },
  97. labelStyle:{
  98. cssClass:"component label"
  99. }
  100. });
  101. var conn4Color = "rgba(46,164,26,0.8)";
  102. var connection4 = jsPlumb.connect({
  103. source:'window5',
  104. target:'window6',
  105. connector:"Flowchart",
  106. anchors:["Center", "Center"],
  107. paintStyle:{
  108. lineWidth:9,
  109. strokeStyle:conn4Color,
  110. outlineColor:"#666",
  111. outlineWidth:1
  112. },
  113. hoverPaintStyle:hoverPaintStyle,
  114. endpointsOnTop:false,
  115. endpointStyle:{ radius:95, fillStyle:conn4Color },
  116. labelStyle : { cssClass:"component label" },
  117. label : "big\nendpoints"
  118. });
  119. var connection5 = jsPlumb.connect({
  120. source:"window4",
  121. target:"window5",
  122. anchors:["BottomRight", "TopLeft"],
  123. paintStyle:{
  124. lineWidth:7,
  125. strokeStyle:"rgb(131,8,135)",
  126. outlineColor:"#666",
  127. outlineWidth:1
  128. },
  129. hoverPaintStyle:hoverPaintStyle,
  130. endpoint:["Image", {url:"../../img/endpointTest1.png"}],
  131. connector:"Straight",
  132. endpointsOnTop:true,
  133. overlays:[ ["Label", {
  134. cssClass:"component label",
  135. label : "4 - 5",
  136. location:0.3 } ]
  137. ]});
  138. jsPlumb.bind("dblclick", function(connection, originalEvent) { alert("double click on connection from " + connection.sourceId + " to " + connection.targetId); });
  139. jsPlumb.bind("endpointClick", function(endpoint, originalEvent) { alert("click on endpoint on element " + endpoint.elementId); });
  140. }
  141. };
  142. })();