Built files from Bizgaze WebServer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  1. var flowy = function (canvas, grab, release, snapping, rearrange, spacing_x, spacing_y) {
  2. try {
  3. if (!grab) {
  4. grab = function () { };
  5. }
  6. if (!release) {
  7. release = function () { };
  8. }
  9. if (!snapping) {
  10. snapping = function () {
  11. return true;
  12. }
  13. }
  14. if (!rearrange) {
  15. rearrange = function () {
  16. return false;
  17. }
  18. }
  19. if (!spacing_x) {
  20. spacing_x = 20;
  21. }
  22. if (!spacing_y) {
  23. spacing_y = 80;
  24. }
  25. if (!Element.prototype.matches) {
  26. Element.prototype.matches = Element.prototype.msMatchesSelector ||
  27. Element.prototype.webkitMatchesSelector;
  28. }
  29. if (!Element.prototype.closest) {
  30. Element.prototype.closest = function (s) {
  31. var el = this;
  32. do {
  33. if (Element.prototype.matches.call(el, s)) return el;
  34. el = el.parentElement || el.parentNode;
  35. } while (el !== null && el.nodeType === 1);
  36. return null;
  37. };
  38. }
  39. var loaded = false;
  40. flowy.load = function () {
  41. if (!loaded)
  42. loaded = true;
  43. else
  44. return;
  45. var blocks = [];
  46. var blockstemp = [];
  47. var canvas_div = canvas;
  48. var absx = 0;
  49. var absy = 0;
  50. if (window.getComputedStyle(canvas_div).position == "absolute" || window.getComputedStyle(canvas_div).position == "fixed") {
  51. absx = canvas_div.getBoundingClientRect().left;
  52. absy = canvas_div.getBoundingClientRect().top;
  53. }
  54. var active = false;
  55. var paddingx = spacing_x;
  56. var paddingy = spacing_y;
  57. var offsetleft = 0;
  58. var rearrange = false;
  59. var drag, dragx, dragy, original;
  60. var mouse_x, mouse_y;
  61. var dragblock = false;
  62. var prevblock = 0;
  63. var el = document.createElement("DIV");
  64. el.classList.add('indicator');
  65. el.classList.add('invisible');
  66. canvas_div.appendChild(el);
  67. flowy.import = function (output) {
  68. debugger
  69. canvas_div.innerHTML = output.html;
  70. for (var a = 0; a < output.blockarr.length; a++) {
  71. blocks.push({
  72. childwidth: parseFloat(output.blockarr[a].childwidth),
  73. parent: parseFloat(output.blockarr[a].parent),
  74. id: parseFloat(output.blockarr[a].id),
  75. x: parseFloat(output.blockarr[a].x),
  76. y: parseFloat(output.blockarr[a].y),
  77. width: parseFloat(output.blockarr[a].width),
  78. height: parseFloat(output.blockarr[a].height)
  79. })
  80. }
  81. if (blocks.length > 1) {
  82. rearrangeMe();
  83. checkOffset();
  84. }
  85. }
  86. flowy.output = function () {
  87. var html_ser = canvas_div.innerHTML;
  88. var json_data = {
  89. html: html_ser,
  90. blockarr: blocks,
  91. blocks: []
  92. };
  93. if (blocks.length > 0) {
  94. for (var i = 0; i < blocks.length; i++) {
  95. json_data.blocks.push({
  96. id: blocks[i].id,
  97. parent: blocks[i].parent,
  98. data: [],
  99. attr: []
  100. });
  101. var blockParent = document.querySelector(".blockid[value='" + blocks[i].id + "']").parentNode;
  102. blockParent.querySelectorAll("input").forEach(function (block) {
  103. var json_name = block.getAttribute("name");
  104. var json_value = block.value;
  105. json_data.blocks[i].data.push({
  106. name: json_name,
  107. value: json_value
  108. });
  109. });
  110. //Customized To Get Block Id of Class .blockyinfo
  111. blockParent.querySelectorAll(".blockyinfo").forEach(function (block) {
  112. var json_name = block.innerHTML;
  113. var json_value = block.id;
  114. json_data.blocks[i].data.push({
  115. name: json_name,
  116. value: json_value
  117. });
  118. });
  119. Array.prototype.slice.call(blockParent.attributes).forEach(function (attribute) {
  120. var jsonobj = {};
  121. jsonobj[attribute.name] = attribute.value;
  122. json_data.blocks[i].attr.push(jsonobj);
  123. });
  124. }
  125. return json_data;
  126. }
  127. }
  128. //flowy.deleteBlocks = function () {
  129. // blocks = [];
  130. // canvas_div.innerHTML = "<div class='indicator invisible'></div>";
  131. //}
  132. flowy.deleteBlock = function (id, removeChildren) {
  133. //Track orginal parent
  134. let newParentId;
  135. if (!Number.isInteger(id)) {
  136. id = parseInt(id);
  137. }
  138. for (var i = 0; i < blocks.length; i++) {
  139. if (blocks[i].id === id) {
  140. newParentId = blocks[i].parent;
  141. removeBlockEls(blocks[i].id, blocks[i].parent);
  142. blocks.splice(i, 1);
  143. modifyChildBlocks(id);
  144. break;
  145. }
  146. }
  147. rearrangeMe();
  148. function modifyChildBlocks(parentId) {
  149. let children = [];
  150. for (var i = blocks.length - 1; i >= 0; i--) {
  151. if (blocks[i].parent === parentId) {
  152. children.push(blocks[i].id);
  153. if (removeChildren === true) {
  154. removeBlockEls(blocks[i].id, blocks[i].parent);
  155. blocks.splice(i, 1);
  156. } else {
  157. blocks[i].parent = newParentId;
  158. rearrange = true;
  159. document.querySelector(".arrowid[value='" + blocks[i].id + "']").parentNode.remove();
  160. blockstemp = [];
  161. blockstemp.push(blocks.filter(a => a.id == blocks[i].id)[0]);
  162. snap(document.querySelector(".blockid[value='" + blocks[i].id + "']").parentNode, newParentId, blocks.map(a => a.id));
  163. rearrange = false;
  164. }
  165. }
  166. }
  167. //Only call repeat of function if removing children
  168. if (removeChildren === true) {
  169. for (var i = 0; i < children.length; i++) {
  170. modifyChildBlocks(children[i]);
  171. }
  172. }
  173. }
  174. function removeBlockEls(id, parentid) {
  175. if (parentid == -1) {
  176. document.querySelector(".blockid[value='" + id + "']").parentNode.remove();
  177. }
  178. else {
  179. document.querySelector(".blockid[value='" + id + "']").parentNode.remove();
  180. document.querySelector(".arrowid[value='" + id + "']").parentNode.remove();
  181. }
  182. }
  183. };
  184. flowy.beginDrag = function (event) {
  185. if (window.getComputedStyle(canvas_div).position == "absolute" || window.getComputedStyle(canvas_div).position == "fixed") {
  186. absx = canvas_div.getBoundingClientRect().left;
  187. absy = canvas_div.getBoundingClientRect().top;
  188. }
  189. if (event.targetTouches) {
  190. mouse_x = event.changedTouches[0].clientX;
  191. mouse_y = event.changedTouches[0].clientY;
  192. } else {
  193. mouse_x = event.clientX;
  194. mouse_y = event.clientY;
  195. }
  196. if (event.which != 3 && event.target.closest(".create-flowy")) {
  197. original = event.target.closest(".create-flowy");
  198. var newNode = event.target.closest(".create-flowy").cloneNode(true);
  199. event.target.closest(".create-flowy").classList.add("dragnow");
  200. newNode.classList.add("block");
  201. newNode.classList.remove("create-flowy");
  202. if (blocks.length === 0) {
  203. newNode.innerHTML += "<input type='hidden' name='blockid' class='blockid' value='" + blocks.length + "'>";
  204. //document.body.appendChild(newNode);
  205. $('._bizgaze_popup_container').append(newNode);
  206. drag = document.querySelector(".blockid[value='" + blocks.length + "']").parentNode;
  207. } else {
  208. newNode.innerHTML += "<input type='hidden' name='blockid' class='blockid' value='" + (Math.max.apply(Math, blocks.map(a => a.id)) + 1) + "'>";
  209. //document.body.appendChild(newNode);
  210. $('._bizgaze_popup_container').append(newNode);
  211. drag = document.querySelector(".blockid[value='" + (parseInt(Math.max.apply(Math, blocks.map(a => a.id))) + 1) + "']").parentNode;
  212. }
  213. blockGrabbed(event.target.closest(".create-flowy"));
  214. drag.classList.add("dragging");
  215. active = true;
  216. dragx = mouse_x - (event.target.closest(".create-flowy").getBoundingClientRect().left);
  217. dragy = mouse_y - (event.target.closest(".create-flowy").getBoundingClientRect().top);
  218. drag.style.left = mouse_x - dragx + "px";
  219. drag.style.top = mouse_y - dragy + "px";
  220. }
  221. }
  222. flowy.endDrag = function (event) {
  223. if (event.which != 3 && (active || rearrange)) {
  224. dragblock = false;
  225. blockReleased(event);
  226. if (!document.querySelector(".indicator").classList.contains("invisible")) {
  227. document.querySelector(".indicator").classList.add("invisible");
  228. }
  229. if (active) {
  230. original.classList.remove("dragnow");
  231. drag.classList.remove("dragging");
  232. }
  233. if (parseInt(drag.querySelector(".blockid").value) === 0 && rearrange) {
  234. firstBlock("rearrange")
  235. } else if (active && blocks.length == 0 && (drag.getBoundingClientRect().top + window.scrollY) > (canvas_div.getBoundingClientRect().top + window.scrollY) && (drag.getBoundingClientRect().left + window.scrollX) > (canvas_div.getBoundingClientRect().left + window.scrollX)) {
  236. firstBlock("drop");
  237. } else if (active && blocks.length == 0) {
  238. removeSelection();
  239. } else if (active) {
  240. var blocko = blocks.map(a => a.id);
  241. for (var i = 0; i < blocks.length; i++) {
  242. if (checkAttach(blocko[i])) {
  243. active = false;
  244. if (blockSnap(drag, false, document.querySelector(".blockid[value='" + blocko[i] + "']").parentNode)) {
  245. snap(drag, i, blocko);
  246. } else {
  247. active = false;
  248. removeSelection();
  249. }
  250. break;
  251. } else if (i == blocks.length - 1) {
  252. active = false;
  253. removeSelection();
  254. }
  255. }
  256. } else if (rearrange) {
  257. var blocko = blocks.map(a => a.id);
  258. for (var i = 0; i < blocks.length; i++) {
  259. if (checkAttach(blocko[i])) {
  260. active = false;
  261. drag.classList.remove("dragging");
  262. snap(drag, i, blocko);
  263. break;
  264. } else if (i == blocks.length - 1) {
  265. if (beforeDelete(drag, blocks.filter(id => id.id == blocko[i])[0])) {
  266. active = false;
  267. drag.classList.remove("dragging");
  268. snap(drag, blocko.indexOf(prevblock), blocko);
  269. break;
  270. } else {
  271. rearrange = false;
  272. blockstemp = [];
  273. active = false;
  274. removeSelection();
  275. break;
  276. }
  277. }
  278. }
  279. }
  280. }
  281. eval("bizgaze_automation_flow_main.Deleteblock()");
  282. }
  283. function checkAttach(id) {
  284. const xpos = (drag.getBoundingClientRect().left + window.scrollX) + (parseInt(window.getComputedStyle(drag).width) / 2) + canvas_div.scrollLeft - canvas_div.getBoundingClientRect().left;
  285. const ypos = (drag.getBoundingClientRect().top + window.scrollY) + canvas_div.scrollTop - canvas_div.getBoundingClientRect().top;
  286. if (xpos >= blocks.filter(a => a.id == id)[0].x - (blocks.filter(a => a.id == id)[0].width / 2) - paddingx && xpos <= blocks.filter(a => a.id == id)[0].x + (blocks.filter(a => a.id == id)[0].width / 2) + paddingx && ypos >= blocks.filter(a => a.id == id)[0].y - (blocks.filter(a => a.id == id)[0].height / 2) && ypos <= blocks.filter(a => a.id == id)[0].y + blocks.filter(a => a.id == id)[0].height) {
  287. return true;
  288. } else {
  289. return false;
  290. }
  291. }
  292. function removeSelection() {
  293. canvas_div.appendChild(document.querySelector(".indicator"));
  294. drag.parentNode.removeChild(drag);
  295. }
  296. function firstBlock(type) {
  297. if (type == "drop") {
  298. blockSnap(drag, true, undefined);
  299. active = false;
  300. drag.style.top = (drag.getBoundingClientRect().top + window.scrollY) - (absy + window.scrollY) + canvas_div.scrollTop + "px";
  301. drag.style.left = (drag.getBoundingClientRect().left + window.scrollX) - (absx + window.scrollX) + canvas_div.scrollLeft + "px";
  302. canvas_div.appendChild(drag);
  303. blocks.push({
  304. parent: -1,
  305. childwidth: 0,
  306. id: parseInt(drag.querySelector(".blockid").value),
  307. x: (drag.getBoundingClientRect().left + window.scrollX) + (parseInt(window.getComputedStyle(drag).width) / 2) + canvas_div.scrollLeft - canvas_div.getBoundingClientRect().left,
  308. y: (drag.getBoundingClientRect().top + window.scrollY) + (parseInt(window.getComputedStyle(drag).height) / 2) + canvas_div.scrollTop - canvas_div.getBoundingClientRect().top,
  309. width: parseInt(window.getComputedStyle(drag).width),
  310. height: parseInt(window.getComputedStyle(drag).height)
  311. });
  312. } else if (type == "rearrange") {
  313. drag.classList.remove("dragging");
  314. rearrange = false;
  315. for (var w = 0; w < blockstemp.length; w++) {
  316. if (blockstemp[w].id != parseInt(drag.querySelector(".blockid").value)) {
  317. const blockParent = document.querySelector(".blockid[value='" + blockstemp[w].id + "']").parentNode;
  318. const arrowParent = document.querySelector(".arrowid[value='" + blockstemp[w].id + "']").parentNode;
  319. blockParent.style.left = (blockParent.getBoundingClientRect().left + window.scrollX) - (window.scrollX) + canvas_div.scrollLeft - 1 - absx + "px";
  320. blockParent.style.top = (blockParent.getBoundingClientRect().top + window.scrollY) - (window.scrollY) + canvas_div.scrollTop - absy - 1 + "px";
  321. arrowParent.style.left = (arrowParent.getBoundingClientRect().left + window.scrollX) - (window.scrollX) + canvas_div.scrollLeft - absx - 1 + "px";
  322. arrowParent.style.top = (arrowParent.getBoundingClientRect().top + window.scrollY) + canvas_div.scrollTop - 1 - absy + "px";
  323. canvas_div.appendChild(blockParent);
  324. canvas_div.appendChild(arrowParent);
  325. blockstemp[w].x = (blockParent.getBoundingClientRect().left + window.scrollX) + (parseInt(blockParent.offsetWidth) / 2) + canvas_div.scrollLeft - canvas_div.getBoundingClientRect().left - 1;
  326. blockstemp[w].y = (blockParent.getBoundingClientRect().top + window.scrollY) + (parseInt(blockParent.offsetHeight) / 2) + canvas_div.scrollTop - canvas_div.getBoundingClientRect().top - 1;
  327. }
  328. }
  329. blockstemp.filter(a => a.id == 0)[0].x = (drag.getBoundingClientRect().left + window.scrollX) + (parseInt(window.getComputedStyle(drag).width) / 2) + canvas_div.scrollLeft - canvas_div.getBoundingClientRect().left;
  330. blockstemp.filter(a => a.id == 0)[0].y = (drag.getBoundingClientRect().top + window.scrollY) + (parseInt(window.getComputedStyle(drag).height) / 2) + canvas_div.scrollTop - canvas_div.getBoundingClientRect().top;
  331. blocks = blocks.concat(blockstemp);
  332. blockstemp = [];
  333. }
  334. }
  335. function drawArrow(arrow, x, y, id) {
  336. if (x < 0) {
  337. canvas_div.innerHTML += '<div class="arrowblock"><input type="hidden" class="arrowid" value="' + drag.querySelector(".blockid").value + '"><svg preserveaspectratio="none" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M' + (blocks.filter(a => a.id == id)[0].x - arrow.x + 5) + ' 0L' + (blocks.filter(a => a.id == id)[0].x - arrow.x + 5) + ' ' + (paddingy / 2) + 'L5 ' + (paddingy / 2) + 'L5 ' + y + '" stroke="#C5CCD0" stroke-width="2px"/><path d="M0 ' + (y - 5) + 'H10L5 ' + y + 'L0 ' + (y - 5) + 'Z" fill="#C5CCD0"/></svg></div>';
  338. document.querySelector('.arrowid[value="' + drag.querySelector(".blockid").value + '"]').parentNode.style.left = (arrow.x - 5) - (absx + window.scrollX) + canvas_div.scrollLeft + canvas_div.getBoundingClientRect().left + "px";
  339. } else {
  340. canvas_div.innerHTML += '<div class="arrowblock"><input type="hidden" class="arrowid" value="' + drag.querySelector(".blockid").value + '"><svg preserveaspectratio="none" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M20 0L20 ' + (paddingy / 2) + 'L' + (x) + ' ' + (paddingy / 2) + 'L' + x + ' ' + y + '" stroke="#C5CCD0" stroke-width="2px"/><path d="M' + (x - 5) + ' ' + (y - 5) + 'H' + (x + 5) + 'L' + x + ' ' + y + 'L' + (x - 5) + ' ' + (y - 5) + 'Z" fill="#C5CCD0"/></svg></div>';
  341. document.querySelector('.arrowid[value="' + parseInt(drag.querySelector(".blockid").value) + '"]').parentNode.style.left = blocks.filter(a => a.id == id)[0].x - 20 - (absx + window.scrollX) + canvas_div.scrollLeft + canvas_div.getBoundingClientRect().left + "px";
  342. }
  343. document.querySelector('.arrowid[value="' + parseInt(drag.querySelector(".blockid").value) + '"]').parentNode.style.top = blocks.filter(a => a.id == id)[0].y + (blocks.filter(a => a.id == id)[0].height / 2) + canvas_div.getBoundingClientRect().top - absy + "px";
  344. }
  345. function updateArrow(arrow, x, y, children) {
  346. if (x < 0) {
  347. document.querySelector('.arrowid[value="' + children.id + '"]').parentNode.style.left = (arrow.x - 5) - (absx + window.scrollX) + canvas_div.getBoundingClientRect().left + "px";
  348. document.querySelector('.arrowid[value="' + children.id + '"]').parentNode.innerHTML = '<input type="hidden" class="arrowid" value="' + children.id + '"><svg preserveaspectratio="none" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M' + (blocks.filter(id => id.id == children.parent)[0].x - arrow.x + 5) + ' 0L' + (blocks.filter(id => id.id == children.parent)[0].x - arrow.x + 5) + ' ' + (paddingy / 2) + 'L5 ' + (paddingy / 2) + 'L5 ' + y + '" stroke="#C5CCD0" stroke-width="2px"/><path d="M0 ' + (y - 5) + 'H10L5 ' + y + 'L0 ' + (y - 5) + 'Z" fill="#C5CCD0"/></svg>';
  349. } else {
  350. document.querySelector('.arrowid[value="' + children.id + '"]').parentNode.style.left = blocks.filter(id => id.id == children.parent)[0].x - 20 - (absx + window.scrollX) + canvas_div.getBoundingClientRect().left + "px";
  351. document.querySelector('.arrowid[value="' + children.id + '"]').parentNode.innerHTML = '<input type="hidden" class="arrowid" value="' + children.id + '"><svg preserveaspectratio="none" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M20 0L20 ' + (paddingy / 2) + 'L' + (x) + ' ' + (paddingy / 2) + 'L' + x + ' ' + y + '" stroke="#C5CCD0" stroke-width="2px"/><path d="M' + (x - 5) + ' ' + (y - 5) + 'H' + (x + 5) + 'L' + x + ' ' + y + 'L' + (x - 5) + ' ' + (y - 5) + 'Z" fill="#C5CCD0"/></svg>';
  352. }
  353. }
  354. function snap(drag, i, blocko) {
  355. if (!rearrange) {
  356. canvas_div.appendChild(drag);
  357. }
  358. var totalwidth = 0;
  359. var totalremove = 0;
  360. var maxheight = 0;
  361. for (var w = 0; w < blocks.filter(id => id.parent == blocko[i]).length; w++) {
  362. var children = blocks.filter(id => id.parent == blocko[i])[w];
  363. if (children.childwidth > children.width) {
  364. totalwidth += children.childwidth + paddingx;
  365. } else {
  366. totalwidth += children.width + paddingx;
  367. }
  368. }
  369. totalwidth += parseInt(window.getComputedStyle(drag).width);
  370. for (var w = 0; w < blocks.filter(id => id.parent == blocko[i]).length; w++) {
  371. var children = blocks.filter(id => id.parent == blocko[i])[w];
  372. if (children.childwidth > children.width) {
  373. document.querySelector(".blockid[value='" + children.id + "']").parentNode.style.left = blocks.filter(a => a.id == blocko[i])[0].x - (totalwidth / 2) + totalremove + (children.childwidth / 2) - (children.width / 2) + "px";
  374. children.x = blocks.filter(id => id.parent == blocko[i])[0].x - (totalwidth / 2) + totalremove + (children.childwidth / 2);
  375. totalremove += children.childwidth + paddingx;
  376. } else {
  377. document.querySelector(".blockid[value='" + children.id + "']").parentNode.style.left = blocks.filter(a => a.id == blocko[i])[0].x - (totalwidth / 2) + totalremove + "px";
  378. children.x = blocks.filter(id => id.parent == blocko[i])[0].x - (totalwidth / 2) + totalremove + (children.width / 2);
  379. totalremove += children.width + paddingx;
  380. }
  381. }
  382. drag.style.left = blocks.filter(id => id.id == blocko[i])[0].x - (totalwidth / 2) + totalremove - (window.scrollX + absx) + canvas_div.scrollLeft + canvas_div.getBoundingClientRect().left + "px";
  383. drag.style.top = blocks.filter(id => id.id == blocko[i])[0].y + (blocks.filter(id => id.id == blocko[i])[0].height / 2) + paddingy - (window.scrollY + absy) + canvas_div.getBoundingClientRect().top + "px";
  384. if (rearrange) {
  385. blockstemp.filter(a => a.id == parseInt(drag.querySelector(".blockid").value))[0].x = (drag.getBoundingClientRect().left + window.scrollX) + (parseInt(window.getComputedStyle(drag).width) / 2) + canvas_div.scrollLeft - canvas_div.getBoundingClientRect().left;
  386. blockstemp.filter(a => a.id == parseInt(drag.querySelector(".blockid").value))[0].y = (drag.getBoundingClientRect().top + window.scrollY + absy) + (parseInt(window.getComputedStyle(drag).height) / 2) + canvas_div.scrollTop - canvas_div.getBoundingClientRect().top;
  387. blockstemp.filter(a => a.id == drag.querySelector(".blockid").value)[0].parent = blocko[i];
  388. for (var w = 0; w < blockstemp.length; w++) {
  389. if (blockstemp[w].id != parseInt(drag.querySelector(".blockid").value)) {
  390. const blockParent = document.querySelector(".blockid[value='" + blockstemp[w].id + "']").parentNode;
  391. const arrowParent = document.querySelector(".arrowid[value='" + blockstemp[w].id + "']").parentNode;
  392. blockParent.style.left = (blockParent.getBoundingClientRect().left + window.scrollX) - (window.scrollX + canvas_div.getBoundingClientRect().left) + canvas_div.scrollLeft + "px";
  393. blockParent.style.top = (blockParent.getBoundingClientRect().top + window.scrollY) - (window.scrollY + canvas_div.getBoundingClientRect().top) + canvas_div.scrollTop + "px";
  394. arrowParent.style.left = (arrowParent.getBoundingClientRect().left + window.scrollX) - (window.scrollX + canvas_div.getBoundingClientRect().left) + canvas_div.scrollLeft + 20 + "px";
  395. arrowParent.style.top = (arrowParent.getBoundingClientRect().top + window.scrollY) - (window.scrollY + canvas_div.getBoundingClientRect().top) + canvas_div.scrollTop + "px";
  396. canvas_div.appendChild(blockParent);
  397. canvas_div.appendChild(arrowParent);
  398. blockstemp[w].x = (blockParent.getBoundingClientRect().left + window.scrollX) + (parseInt(window.getComputedStyle(blockParent).width) / 2) + canvas_div.scrollLeft - canvas_div.getBoundingClientRect().left;
  399. blockstemp[w].y = (blockParent.getBoundingClientRect().top + window.scrollY) + (parseInt(window.getComputedStyle(blockParent).height) / 2) + canvas_div.scrollTop - canvas_div.getBoundingClientRect().top;
  400. }
  401. }
  402. blocks = blocks.concat(blockstemp);
  403. blockstemp = [];
  404. } else {
  405. blocks.push({
  406. childwidth: 0,
  407. parent: blocko[i],
  408. id: parseInt(drag.querySelector(".blockid").value),
  409. x: (drag.getBoundingClientRect().left + window.scrollX) + (parseInt(window.getComputedStyle(drag).width) / 2) + canvas_div.scrollLeft - canvas_div.getBoundingClientRect().left,
  410. y: (drag.getBoundingClientRect().top + window.scrollY) + (parseInt(window.getComputedStyle(drag).height) / 2) + canvas_div.scrollTop - canvas_div.getBoundingClientRect().top,
  411. width: parseInt(window.getComputedStyle(drag).width),
  412. height: parseInt(window.getComputedStyle(drag).height)
  413. });
  414. }
  415. var arrowblock = blocks.filter(a => a.id == parseInt(drag.querySelector(".blockid").value))[0];
  416. var arrowx = arrowblock.x - blocks.filter(a => a.id == blocko[i])[0].x + 20;
  417. var arrowy = paddingy;
  418. drawArrow(arrowblock, arrowx, arrowy, blocko[i]);
  419. if (blocks.filter(a => a.id == blocko[i])[0].parent != -1) {
  420. var flag = false;
  421. var idval = blocko[i];
  422. while (!flag) {
  423. if (blocks.filter(a => a.id == idval)[0].parent == -1) {
  424. flag = true;
  425. } else {
  426. var zwidth = 0;
  427. for (var w = 0; w < blocks.filter(id => id.parent == idval).length; w++) {
  428. var children = blocks.filter(id => id.parent == idval)[w];
  429. if (children.childwidth > children.width) {
  430. if (w == blocks.filter(id => id.parent == idval).length - 1) {
  431. zwidth += children.childwidth;
  432. } else {
  433. zwidth += children.childwidth + paddingx;
  434. }
  435. } else {
  436. if (w == blocks.filter(id => id.parent == idval).length - 1) {
  437. zwidth += children.width;
  438. } else {
  439. zwidth += children.width + paddingx;
  440. }
  441. }
  442. }
  443. blocks.filter(a => a.id == idval)[0].childwidth = zwidth;
  444. idval = blocks.filter(a => a.id == idval)[0].parent;
  445. }
  446. }
  447. blocks.filter(id => id.id == idval)[0].childwidth = totalwidth;
  448. }
  449. if (rearrange) {
  450. rearrange = false;
  451. drag.classList.remove("dragging");
  452. }
  453. rearrangeMe();
  454. checkOffset();
  455. }
  456. function touchblock(event) {
  457. dragblock = false;
  458. if (hasParentClass(event.target, "block")) {
  459. var theblock = event.target.closest(".block");
  460. if (event.targetTouches) {
  461. mouse_x = event.targetTouches[0].clientX;
  462. mouse_y = event.targetTouches[0].clientY;
  463. } else {
  464. mouse_x = event.clientX;
  465. mouse_y = event.clientY;
  466. }
  467. if (event.type !== "mouseup" && hasParentClass(event.target, "block")) {
  468. if (event.which != 3) {
  469. if (!active && !rearrange) {
  470. dragblock = true;
  471. drag = theblock;
  472. dragx = mouse_x - (drag.getBoundingClientRect().left + window.scrollX);
  473. dragy = mouse_y - (drag.getBoundingClientRect().top + window.scrollY);
  474. }
  475. }
  476. }
  477. }
  478. }
  479. function hasParentClass(element, classname) {
  480. if (element.className) {
  481. if (element.className.split(' ').indexOf(classname) >= 0) return true;
  482. }
  483. return element.parentNode && hasParentClass(element.parentNode, classname);
  484. }
  485. flowy.moveBlock = function (event) {
  486. if (event.targetTouches) {
  487. mouse_x = event.targetTouches[0].clientX;
  488. mouse_y = event.targetTouches[0].clientY;
  489. } else {
  490. mouse_x = event.clientX;
  491. mouse_y = event.clientY;
  492. }
  493. if (dragblock) {
  494. rearrange = true;
  495. drag.classList.add("dragging");
  496. var blockid = parseInt(drag.querySelector(".blockid").value);
  497. prevblock = blocks.filter(a => a.id == blockid)[0].parent;
  498. blockstemp.push(blocks.filter(a => a.id == blockid)[0]);
  499. blocks = blocks.filter(function (e) {
  500. return e.id != blockid
  501. });
  502. if (blockid != 0) {
  503. document.querySelector(".arrowid[value='" + blockid + "']").parentNode.remove();
  504. }
  505. var layer = blocks.filter(a => a.parent == blockid);
  506. var flag = false;
  507. var foundids = [];
  508. var allids = [];
  509. while (!flag) {
  510. for (var i = 0; i < layer.length; i++) {
  511. if (layer[i] != blockid) {
  512. blockstemp.push(blocks.filter(a => a.id == layer[i].id)[0]);
  513. const blockParent = document.querySelector(".blockid[value='" + layer[i].id + "']").parentNode;
  514. const arrowParent = document.querySelector(".arrowid[value='" + layer[i].id + "']").parentNode;
  515. blockParent.style.left = (blockParent.getBoundingClientRect().left + window.scrollX) - (drag.getBoundingClientRect().left + window.scrollX) + "px";
  516. blockParent.style.top = (blockParent.getBoundingClientRect().top + window.scrollY) - (drag.getBoundingClientRect().top + window.scrollY) + "px";
  517. arrowParent.style.left = (arrowParent.getBoundingClientRect().left + window.scrollX) - (drag.getBoundingClientRect().left + window.scrollX) + "px";
  518. arrowParent.style.top = (arrowParent.getBoundingClientRect().top + window.scrollY) - (drag.getBoundingClientRect().top + window.scrollY) + "px";
  519. drag.appendChild(blockParent);
  520. drag.appendChild(arrowParent);
  521. foundids.push(layer[i].id);
  522. allids.push(layer[i].id);
  523. }
  524. }
  525. if (foundids.length == 0) {
  526. flag = true;
  527. } else {
  528. layer = blocks.filter(a => foundids.includes(a.parent));
  529. foundids = [];
  530. }
  531. }
  532. for (var i = 0; i < blocks.filter(a => a.parent == blockid).length; i++) {
  533. var blocknumber = blocks.filter(a => a.parent == blockid)[i];
  534. blocks = blocks.filter(function (e) {
  535. return e.id != blocknumber
  536. });
  537. }
  538. for (var i = 0; i < allids.length; i++) {
  539. var blocknumber = allids[i];
  540. blocks = blocks.filter(function (e) {
  541. return e.id != blocknumber
  542. });
  543. }
  544. if (blocks.length > 1) {
  545. rearrangeMe();
  546. }
  547. dragblock = false;
  548. }
  549. if (active) {
  550. drag.style.left = mouse_x - dragx + "px";
  551. drag.style.top = mouse_y - dragy + "px";
  552. } else if (rearrange) {
  553. drag.style.left = mouse_x - dragx - (window.scrollX + absx) + canvas_div.scrollLeft + "px";
  554. drag.style.top = mouse_y - dragy - (window.scrollY + absy) + canvas_div.scrollTop + "px";
  555. blockstemp.filter(a => a.id == parseInt(drag.querySelector(".blockid").value)).x = (drag.getBoundingClientRect().left + window.scrollX) + (parseInt(window.getComputedStyle(drag).width) / 2) + canvas_div.scrollLeft;
  556. blockstemp.filter(a => a.id == parseInt(drag.querySelector(".blockid").value)).y = (drag.getBoundingClientRect().top + window.scrollY) + (parseInt(window.getComputedStyle(drag).height) / 2) + canvas_div.scrollTop;
  557. }
  558. if (active || rearrange) {
  559. if (mouse_x > canvas_div.getBoundingClientRect().width + canvas_div.getBoundingClientRect().left - 10 && mouse_x < canvas_div.getBoundingClientRect().width + canvas_div.getBoundingClientRect().left + 10) {
  560. canvas_div.scrollLeft += 10;
  561. } else if (mouse_x < canvas_div.getBoundingClientRect().left + 10 && mouse_x > canvas_div.getBoundingClientRect().left - 10) {
  562. canvas_div.scrollLeft -= 10;
  563. } else if (mouse_y > canvas_div.getBoundingClientRect().height + canvas_div.getBoundingClientRect().top - 10 && mouse_y < canvas_div.getBoundingClientRect().height + canvas_div.getBoundingClientRect().top + 10) {
  564. canvas_div.scrollTop += 10;
  565. } else if (mouse_y < canvas_div.getBoundingClientRect().top + 10 && mouse_y > canvas_div.getBoundingClientRect().top - 10) {
  566. canvas_div.scrollLeft -= 10;
  567. }
  568. var xpos = (drag.getBoundingClientRect().left + window.scrollX) + (parseInt(window.getComputedStyle(drag).width) / 2) + canvas_div.scrollLeft - canvas_div.getBoundingClientRect().left;
  569. var ypos = (drag.getBoundingClientRect().top + window.scrollY) + canvas_div.scrollTop - canvas_div.getBoundingClientRect().top;
  570. var blocko = blocks.map(a => a.id);
  571. for (var i = 0; i < blocks.length; i++) {
  572. if (checkAttach(blocko[i])) {
  573. document.querySelector(".blockid[value='" + blocko[i] + "']").parentNode.appendChild(document.querySelector(".indicator"));
  574. document.querySelector(".indicator").style.left = (document.querySelector(".blockid[value='" + blocko[i] + "']").parentNode.offsetWidth / 2) - 5 + "px";
  575. document.querySelector(".indicator").style.top = document.querySelector(".blockid[value='" + blocko[i] + "']").parentNode.offsetHeight + "px";
  576. document.querySelector(".indicator").classList.remove("invisible");
  577. break;
  578. } else if (i == blocks.length - 1) {
  579. if (!document.querySelector(".indicator").classList.contains("invisible")) {
  580. document.querySelector(".indicator").classList.add("invisible");
  581. }
  582. }
  583. }
  584. }
  585. }
  586. function checkOffset() {
  587. offsetleft = blocks.map(a => a.x);
  588. var widths = blocks.map(a => a.width);
  589. var mathmin = offsetleft.map(function (item, index) {
  590. return item - (widths[index] / 2);
  591. })
  592. offsetleft = Math.min.apply(Math, mathmin);
  593. if (offsetleft < (canvas_div.getBoundingClientRect().left + window.scrollX - absx)) {
  594. var blocko = blocks.map(a => a.id);
  595. for (var w = 0; w < blocks.length; w++) {
  596. document.querySelector(".blockid[value='" + blocks.filter(a => a.id == blocko[w])[0].id + "']").parentNode.style.left = blocks.filter(a => a.id == blocko[w])[0].x - (blocks.filter(a => a.id == blocko[w])[0].width / 2) - offsetleft + canvas_div.getBoundingClientRect().left - absx + 20 + "px";
  597. if (blocks.filter(a => a.id == blocko[w])[0].parent != -1) {
  598. var arrowblock = blocks.filter(a => a.id == blocko[w])[0];
  599. var arrowx = arrowblock.x - blocks.filter(a => a.id == blocks.filter(a => a.id == blocko[w])[0].parent)[0].x;
  600. if (arrowx < 0) {
  601. document.querySelector('.arrowid[value="' + blocko[w] + '"]').parentNode.style.left = (arrowblock.x - offsetleft + 20 - 5) + canvas_div.getBoundingClientRect().left - absx + "px";
  602. } else {
  603. document.querySelector('.arrowid[value="' + blocko[w] + '"]').parentNode.style.left = blocks.filter(id => id.id == blocks.filter(a => a.id == blocko[w])[0].parent)[0].x - 20 - offsetleft + canvas_div.getBoundingClientRect().left - absx + 20 + "px";
  604. }
  605. }
  606. }
  607. for (var w = 0; w < blocks.length; w++) {
  608. blocks[w].x = (document.querySelector(".blockid[value='" + blocks[w].id + "']").parentNode.getBoundingClientRect().left + window.scrollX) + (canvas_div.scrollLeft) + (parseInt(window.getComputedStyle(document.querySelector(".blockid[value='" + blocks[w].id + "']").parentNode).width) / 2) - 20 - canvas_div.getBoundingClientRect().left;
  609. }
  610. }
  611. }
  612. function rearrangeMe() {
  613. var result = blocks.map(a => a.parent);
  614. for (var z = 0; z < result.length; z++) {
  615. if (result[z] == -1) {
  616. z++;
  617. }
  618. var totalwidth = 0;
  619. var totalremove = 0;
  620. var maxheight = 0;
  621. for (var w = 0; w < blocks.filter(id => id.parent == result[z]).length; w++) {
  622. var children = blocks.filter(id => id.parent == result[z])[w];
  623. if (blocks.filter(id => id.parent == children.id).length == 0) {
  624. children.childwidth = 0;
  625. }
  626. if (children.childwidth > children.width) {
  627. if (w == blocks.filter(id => id.parent == result[z]).length - 1) {
  628. totalwidth += children.childwidth;
  629. } else {
  630. totalwidth += children.childwidth + paddingx;
  631. }
  632. } else {
  633. if (w == blocks.filter(id => id.parent == result[z]).length - 1) {
  634. totalwidth += children.width;
  635. } else {
  636. totalwidth += children.width + paddingx;
  637. }
  638. }
  639. }
  640. if (result[z] != -1) {
  641. blocks.filter(a => a.id == result[z])[0].childwidth = totalwidth;
  642. }
  643. for (var w = 0; w < blocks.filter(id => id.parent == result[z]).length; w++) {
  644. var children = blocks.filter(id => id.parent == result[z])[w];
  645. const r_block = document.querySelector(".blockid[value='" + children.id + "']").parentNode;
  646. const r_array = blocks.filter(id => id.id == result[z]);
  647. r_block.style.top = r_array.y + paddingy + canvas_div.getBoundingClientRect().top - absy + "px";
  648. r_array.y = r_array.y + paddingy;
  649. if (children.childwidth > children.width) {
  650. r_block.style.left = r_array[0].x - (totalwidth / 2) + totalremove + (children.childwidth / 2) - (children.width / 2) - (absx + window.scrollX) + canvas_div.getBoundingClientRect().left + "px";
  651. children.x = r_array[0].x - (totalwidth / 2) + totalremove + (children.childwidth / 2);
  652. totalremove += children.childwidth + paddingx;
  653. } else {
  654. r_block.style.left = r_array[0].x - (totalwidth / 2) + totalremove - (absx + window.scrollX) + canvas_div.getBoundingClientRect().left + "px";
  655. children.x = r_array[0].x - (totalwidth / 2) + totalremove + (children.width / 2);
  656. totalremove += children.width + paddingx;
  657. }
  658. var arrowblock = blocks.filter(a => a.id == children.id)[0];
  659. var arrowx = arrowblock.x - blocks.filter(a => a.id == children.parent)[0].x + 20;
  660. var arrowy = paddingy;
  661. updateArrow(arrowblock, arrowx, arrowy, children);
  662. }
  663. }
  664. }
  665. document.addEventListener("mousedown", flowy.beginDrag);
  666. document.addEventListener("mousedown", touchblock, false);
  667. document.addEventListener("touchstart", flowy.beginDrag);
  668. document.addEventListener("touchstart", touchblock, false);
  669. document.addEventListener("mouseup", touchblock, false);
  670. document.addEventListener("mousemove", flowy.moveBlock, false);
  671. document.addEventListener("touchmove", flowy.moveBlock, false);
  672. document.addEventListener("mouseup", flowy.endDrag, false);
  673. document.addEventListener("touchend", flowy.endDrag, false);
  674. flowy.remove = function () {
  675. document.removeEventListener("touchstart", touchblock, false);
  676. document.removeEventListener("mouseup", touchblock, false);
  677. document.removeEventListener("mousedown", touchblock, false);
  678. }
  679. }
  680. function blockGrabbed(block) {
  681. grab(block);
  682. }
  683. function blockReleased(event) {
  684. release(event);
  685. }
  686. function blockSnap(drag, first, parent) {
  687. return snapping(drag, first, parent);
  688. }
  689. function beforeDelete(drag, parent) {
  690. return rearrange(drag, parent);
  691. }
  692. function addEventListenerMulti(type, listener, capture, selector) {
  693. var nodes = document.querySelectorAll(selector);
  694. for (var i = 0; i < nodes.length; i++) {
  695. nodes[i].addEventListener(type, listener, capture);
  696. }
  697. }
  698. function removeEventListenerMulti(type, listener, capture, selector) {
  699. var nodes = document.querySelectorAll(selector);
  700. for (var i = 0; i < nodes.length; i++) {
  701. nodes[i].removeEventListener(type, listener, capture);
  702. }
  703. }
  704. flowy.load();
  705. flowy.destroy = function () {
  706. document.removeEventListener("mousedown", flowy.beginDrag);
  707. document.removeEventListener("touchstart", flowy.beginDrag);
  708. document.removeEventListener("mousemove", flowy.moveBlock, false);
  709. document.removeEventListener("touchmove", flowy.moveBlock, false);
  710. document.removeEventListener("mouseup", flowy.endDrag, false);
  711. document.removeEventListener("touchend", flowy.endDrag, false);
  712. eval("flowy.remove()");
  713. }
  714. }
  715. catch (error) {
  716. flowy.destroy();
  717. }
  718. }