Advertisement
Guest User

jsfile

a guest
Aug 29th, 2013
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;
  2. (function() {
  3.     window.jsPlumbDemo = {
  4.         init : function() {
  5.  
  6.             jsPlumb.importDefaults({
  7.                 Endpoint : [ "Dot", {
  8.                     radius : 2
  9.                 } ],
  10.                 HoverPaintStyle : {
  11.                     strokeStyle : "#1e8151",
  12.                     lineWidth : 2
  13.                 },
  14.                 ConnectionOverlays : [ [ "Arrow", {
  15.                     location : 1,
  16.                     id : "arrow",
  17.                     length : 14,
  18.                     foldback : 0.8
  19.                 } ], [ "Label", {
  20.                     label : "FOO",
  21.                     id : "label",
  22.                     cssClass : "aLabel"
  23.                 } ] ]
  24.             });
  25.  
  26.             var windows = $(".shape");
  27.  
  28.             // initialise draggable elements.
  29.             jsPlumb.draggable(windows);
  30.  
  31.             // bind a click listener to each connection; the connection is
  32.             // deleted. you could of course
  33.             // just do this: jsPlumb.bind("click", jsPlumb.detach), but I wanted
  34.             // to make it clear what was
  35.             // happening.
  36.             jsPlumb.bind("dblclick", function(coffee) {
  37.                 jsPlumb.detach(coffee);
  38.             });
  39.  
  40.             // make each ".ep" div a source and give it some parameters to work
  41.             // with. here we tell it
  42.             // to use a Continuous anchor and the StateMachine connectors, and
  43.             // also we give it the
  44.             // connector's paint style. note that in this demo the strokeStyle
  45.             // is dynamically generated,
  46.             // which prevents us from just setting a
  47.             // jsPlumb.Defaults.PaintStyle. but that is what i
  48.             // would recommend you do. Note also here that we use the 'filter'
  49.             // option to tell jsPlumb
  50.             // which parts of the element should actually respond to a drag
  51.             // start.
  52.             jsPlumb.makeSource(windows, {
  53.                 filter : ".ep", // only supported by jquery
  54.                 anchor : "Continuous",
  55.                 connector : [ "Flowchart", {
  56.                     curviness : 20
  57.                 } ],
  58.                 connectorStyle : {
  59.                     strokeStyle : "#5c96bc",
  60.                     lineWidth : 2,
  61.                     outlineColor : "transparent",
  62.                     outlineWidth : 4
  63.                 },
  64.                 maxConnections : 5,
  65.                 onMaxConnections : function(info, e) {
  66.                     alert("Maximum connections (" + info.maxConnections
  67.                             + ") reached");
  68.                 }
  69.             });
  70.  
  71.             // bind a connection listener. note that the parameter passed to
  72.             // this function contains more than
  73.             // just the new connection - see the documentation for a full list
  74.             // of what is included in 'info'.
  75.             // this listener sets the connection's internal
  76.             // id as the label overlay's text.
  77.             jsPlumb.bind("connection", function(info) {
  78.                 info.connection.getOverlay("label")
  79.                         .setLabel(info.connection.id);
  80.             });
  81.  
  82.             // initialise all '.w' elements as connection targets.
  83.             jsPlumb.makeTarget(windows, {
  84.                 dropOptions : {
  85.                     hoverClass : "dragHover"
  86.                 },
  87.                 anchor : "Continuous"
  88.             });
  89.  
  90.             function removeAnchor() {
  91.                 var ev = arguments[0] || window.event, origEl = ev.target
  92.                         || ev.srcElement;
  93.                 var ele = document.getElementById(origEl.id);
  94.                 jsPlumb.removeAllEndpoints(ele);
  95.                 ele.parentNode.removeChild(ele);
  96.  
  97.             }
  98.             document.ondblclick = removeAnchor;
  99.  
  100.             function save() {
  101.                 var anchors = $(".shape");
  102.                 if (anchors.length < 1) {
  103.                     return;
  104.                 }
  105.                 var sidebar = document.getElementById("explanation");
  106.                 var element = document.createElement("h4");
  107.                 var str = document.createTextNode("ANCHORS;");
  108.                 element.appendChild(str);
  109.                 sidebar.appendChild(element);
  110.                 var text = "sa";
  111.                 for ( var i = 0; i < anchors.length; i++) {
  112.  
  113.                     text = anchors[i].id;
  114.                     text = text + ";";
  115.                     text = text + anchors[i].getBoundingClientRect().left;
  116.                     text = text + ";";
  117.                     text = text + anchors[i].getBoundingClientRect().top;
  118.                     text = text + ";";
  119.                     text = text + anchors[i].getBoundingClientRect().height;
  120.                     text = text + ";";
  121.                     text = text + anchors[i].getBoundingClientRect().width
  122.                             + ";";
  123.                     text = text + anchors[i].getAttribute("data-shape") + ";";
  124.                     var elem = document.createElement("h4");
  125.                     var str2 = document.createTextNode(text);
  126.                     elem.appendChild(str2);
  127.                     sidebar.appendChild((elem));
  128.  
  129.                 }
  130.  
  131.                 var connections = jsPlumb.getAllConnections();
  132.  
  133.                 if (connections.length < 1)
  134.                     return;
  135.  
  136.                 var str3 = document.createTextNode("CONNECTIONS;");
  137.                 var element2 = document.createElement("h4");
  138.                 element2.appendChild(str3);
  139.                 sidebar.appendChild(element2);
  140.                 for ( var i = 0; i < connections.length; i++) {
  141.                     text = connections[i].source.id;
  142.                     text = text + ";";
  143.                     text = text + connections[i].target.id + ";";
  144.                     var elem2 = document.createElement("h4");
  145.                     var str4 = document.createTextNode(text);
  146.                     elem2.appendChild(str4);
  147.                     sidebar.appendChild((elem2));
  148.  
  149.                 }
  150.                 str3 = document.createTextNode("END");
  151.                 var elementx = document.createElement("h4");
  152.                 elementx.appendChild(str3);
  153.                 sidebar.appendChild(elementx);
  154.  
  155.             }
  156.  
  157.             var saveButton = document.getElementById("save");
  158.             saveButton.onclick = save;
  159.  
  160.             $("#save").on("submit", function(event) {
  161.                 alert(jsPlumb.AnchorPositionFinders("window1").toString());
  162.                 return false;
  163.             });
  164.         }
  165.     };
  166. })();
  167.  
  168. var counter = 1;
  169. function addAnchor(type) {
  170.  
  171.     var para = document.createElement("div");
  172.     para.className = "shape";
  173.     para.setAttribute("data-shape", type);
  174.     para.id = "w" + counter;
  175.     var ep = document.createElement("div");
  176.     ep.className = "ep";
  177.  
  178.     var node = document.createTextNode(counter);
  179.     para.appendChild(node);
  180.     para.appendChild(ep);
  181.     var element = document.getElementById("render");
  182.     element.appendChild(para);
  183.  
  184.     var windows = $(".shape");
  185.     jsPlumb.draggable(windows);
  186.  
  187.     jsPlumb.makeSource(windows, {
  188.         filter : ".ep", // only supported by jquery
  189.         anchor : "Continuous",
  190.         connector : [ "Flowchart", {
  191.             curviness : 20
  192.         } ],
  193.         connectorStyle : {
  194.             strokeStyle : "#5c96bc",
  195.             lineWidth : 2,
  196.             outlineColor : "transparent",
  197.             outlineWidth : 4
  198.         },
  199.         maxConnections : 5,
  200.         onMaxConnections : function(info, e) {
  201.             alert("Maximum connections (" + info.maxConnections + ") reached");
  202.         }
  203.     });
  204.  
  205.     jsPlumb.makeTarget(windows, {
  206.         dropOptions : {
  207.             hoverClass : "dragHover"
  208.         },
  209.         anchor : "Continuous"
  210.     });
  211.  
  212.     counter++;
  213.  
  214.     // _addEndpoints(para.id, ["TopCenter", "BottomCenter"], ["LeftMiddle",
  215.     // "RightMiddle"]);
  216.  
  217.     return false;
  218. }
  219. var reader = new FileReader();
  220.  
  221. function readText(that) {
  222.  
  223.     if (that.files && that.files[0]) {
  224.         var reader = new FileReader();
  225.         reader.onload = function(e) {
  226.             var output = e.target.result;
  227.  
  228.             // process text to show only lines with "@":
  229.             // output=output.split("\n").filter(/./.test, /\@/).join("\n");
  230.  
  231.             var i = 1;
  232.             var str = output.split(";" || "\s");
  233.  
  234.             while (str[i].localeCompare("CONNECTIONS") != 0) {
  235.  
  236.                 var id = str[i];
  237.                 var left = str[i + 1] + "px";
  238.                 var top = str[i + 2] + "px";
  239.                 var height = str[i + 3];
  240.                 var width = str[i + 4];
  241.                 var shape = str[i + 5];
  242.  
  243.                 // //
  244.  
  245.                 var para = document.createElement("div");
  246.                 para.className = "shape";
  247.                 para.id = id;
  248.                 para.setAttribute("data-shape", shape);
  249.  
  250.                 para.style.left = left;
  251.                 para.style.top = top;
  252.                 var ep = document.createElement("div");
  253.                 ep.className = "ep";
  254.  
  255.                 var node = document.createTextNode(id);
  256.                 para.appendChild(node);
  257.                 para.appendChild(ep);
  258.                 var element = document.getElementById("render");
  259.                 element.appendChild(para);
  260.                 i = i + 6;
  261.  
  262.             }
  263.             i++;
  264.  
  265.             var windows = $(".shape");
  266.             jsPlumb.draggable(windows);
  267.             jsPlumb.makeSource(windows, {
  268.                 filter : ".ep", // only supported by jquery
  269.                 anchor : "Continuous",
  270.                 connector : [ "Flowchart", {
  271.                     curviness : 20
  272.                 } ],
  273.                 connectorStyle : {
  274.                     strokeStyle : "#5c96bc",
  275.                     lineWidth : 2,
  276.                     outlineColor : "transparent",
  277.                     outlineWidth : 4
  278.                 },
  279.                 maxConnections : 5,
  280.                 onMaxConnections : function(info, e) {
  281.                     alert("Maximum connections (" + info.maxConnections
  282.                             + ") reached");
  283.                 }
  284.             });
  285.  
  286.             jsPlumb.makeTarget(windows, {
  287.                 dropOptions : {
  288.                     hoverClass : "dragHover"
  289.                 },
  290.                 anchor : "Continuous"
  291.             });
  292.  
  293.             while (str[i].localeCompare("END") != 0 && str[i] != null) {
  294.  
  295.                 var source = str[i];
  296.                 var target = str[i + 1];
  297.                 jsPlumb.connect({
  298.                     source : source,
  299.                     target : target
  300.                 });
  301.                 i = i + 2;
  302.  
  303.             }
  304.             jsPlumb.repaintEverything();
  305.  
  306.             // ///
  307.  
  308.             document.getElementById('explanation').innerHTML = str[2];
  309.         };// end onload()
  310.         reader.readAsText(that.files[0]);
  311.     }// end if html5 filelist support
  312. }
  313.  
  314. function preview() {
  315.  
  316.     var windows = $(".shape");
  317.     var x;
  318.     for ( var i = 0; i < windows.length; i++) {
  319.         x = windows[i].getElementsByClassName("ep");
  320.         windows[i].removeChild(x[0]);
  321.         jsPlumb.setDraggable(windows[i], false);
  322.     }
  323.  
  324.     jsPlumb.repaintEverything();
  325. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement