PageRenderTime 50ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/demo/js/archive/1.3.3/flowchartConnectorsDemo.js

http://jsplumb.googlecode.com/
JavaScript | 108 lines | 69 code | 9 blank | 30 comment | 2 complexity | 55967d430b6a5bf5c17bea602c67688c MD5 | raw file
  1. ;(function() {
  2. window.jsPlumbDemo = {
  3. init : function() {
  4. // default drag options
  5. jsPlumb.Defaults.DragOptions = { cursor: 'pointer', zIndex:2000 };
  6. // default to blue at one end and green at the other
  7. jsPlumb.Defaults.EndpointStyles = [{ fillStyle:'#225588' }, { fillStyle:'#558822' }];
  8. // blue endpoints 7 px; green endpoints 11.
  9. jsPlumb.Defaults.Endpoints = [ [ "Dot", {radius:7} ], [ "Dot", { radius:11 } ]];
  10. // enable mouse events
  11. jsPlumb.setMouseEventsEnabled(true);
  12. // the overlays to decorate each connection with. note that the label overlay uses a function to generate the label text; in this
  13. // case it returns the 'labelText' member that we set on each connection in the 'init' method below.
  14. jsPlumb.Defaults.Overlays = [
  15. [ "Arrow", { location:0.9 } ],
  16. [ "Label", {
  17. location:0.1,
  18. label:function(label) {
  19. return label.connection.labelText || "";
  20. },
  21. cssClass:"aLabel"
  22. }]
  23. ];
  24. // this is the paint style for the connecting lines..
  25. var connectorPaintStyle = {
  26. lineWidth:5,
  27. strokeStyle:"#deea18",
  28. joinstyle:"round"
  29. },
  30. // .. and this is the hover style.
  31. connectorHoverStyle = {
  32. lineWidth:7,
  33. strokeStyle:"#2e2aF8"
  34. },
  35. // the definition of source endpoints (the small blue ones)
  36. sourceEndpoint = {
  37. endpoint:"Dot",
  38. paintStyle:{ fillStyle:"#225588",radius:7 },
  39. isSource:true,
  40. connector:[ "Flowchart", { stub:40 } ],
  41. connectorStyle:connectorPaintStyle,
  42. hoverPaintStyle:connectorHoverStyle,
  43. connectorHoverStyle:connectorHoverStyle
  44. },
  45. // a source endpoint that sits at BottomCenter
  46. bottomSource = jsPlumb.extend( { anchor:"BottomCenter" }, sourceEndpoint),
  47. // the definition of target endpoints (will appear when the user drags a connection)
  48. targetEndpoint = {
  49. endpoint:"Dot",
  50. paintStyle:{ fillStyle:"#558822",radius:11 },
  51. hoverPaintStyle:connectorHoverStyle,
  52. maxConnections:-1,
  53. dropOptions:{ hoverClass:"hover", activeClass:"active" },
  54. isTarget:true,
  55. anchor:[ "LeftMiddle", "RightMiddle" ]
  56. },
  57. windows = ["window1", "window2", "window3", "window4"],
  58. init = function(connection) {
  59. connection.labelText = connection.sourceId.substring(6) + "-" + connection.targetId.substring(6);
  60. };
  61. //
  62. // add endpoints to all windows. note here we use a string array; that's just because this demo is framework-agnostic. you'd
  63. // probably use a selector in the real world, eg.
  64. //
  65. // jsPlumb.addEndpoint($(".window"), [ bottomSource ]);
  66. //
  67. var sourceEndpoints = jsPlumb.addEndpoint(windows, bottomSource),
  68. targetEndpoints = jsPlumb.addEndpoint(windows, targetEndpoint);
  69. // listen for new connections; initialise them the same way we initialise the connections at startup.
  70. jsPlumb.bind("jsPlumbConnection", function(connInfo) {
  71. init(connInfo.connection);
  72. });
  73. //
  74. // make all windows drop targets. again note the string array vs selector issue.
  75. //
  76. /*jsPlumb.makeTarget(windows, {
  77. endpoint:targetEndpoint,
  78. dropOptions:{ hoverClass:"hover", activeClass:"active" },
  79. deleteEndpointsOnDetach:true
  80. });*/
  81. // make a couple of connections. note that the return value of addEndpoints is an array of Endpoints,
  82. jsPlumb.connect({
  83. source:sourceEndpoints[0],
  84. target:targetEndpoints[1]
  85. });
  86. jsPlumb.connect({
  87. source:sourceEndpoints[3],
  88. target:targetEndpoints[2]
  89. });
  90. //
  91. // listen for clicks on connections, and offer to delete connections on click.
  92. //
  93. jsPlumb.bind("click", function(conn) {
  94. if (confirm("Delete connection from " + conn.sourceId + " to " + conn.targetId + "?"))
  95. jsPlumb.detach(conn);
  96. });
  97. }
  98. };
  99. })();