otsdaq_utilities  v2_05_02_indev
resize_rows.js
1 /* Tabulator v4.5.3 (c) Oliver Folkerd */
2 
3 var ResizeRows = function ResizeRows(table) {
4  this.table = table; //hold Tabulator object
5  this.startColumn = false;
6  this.startY = false;
7  this.startHeight = false;
8  this.handle = null;
9  this.prevHandle = null;
10 };
11 
12 ResizeRows.prototype.initializeRow = function (row) {
13  var self = this,
14  rowEl = row.getElement();
15 
16  var handle = document.createElement('div');
17  handle.className = "tabulator-row-resize-handle";
18 
19  var prevHandle = document.createElement('div');
20  prevHandle.className = "tabulator-row-resize-handle prev";
21 
22  handle.addEventListener("click", function (e) {
23  e.stopPropagation();
24  });
25 
26  var handleDown = function handleDown(e) {
27  self.startRow = row;
28  self._mouseDown(e, row, handle);
29  };
30 
31  handle.addEventListener("mousedown", handleDown);
32  handle.addEventListener("touchstart", handleDown, { passive: true });
33 
34  prevHandle.addEventListener("click", function (e) {
35  e.stopPropagation();
36  });
37 
38  var prevHandleDown = function prevHandleDown(e) {
39  var prevRow = self.table.rowManager.prevDisplayRow(row);
40 
41  if (prevRow) {
42  self.startRow = prevRow;
43  self._mouseDown(e, prevRow, prevHandle);
44  }
45  };
46 
47  prevHandle.addEventListener("mousedown", prevHandleDown);
48  prevHandle.addEventListener("touchstart", prevHandleDown, { passive: true });
49 
50  rowEl.appendChild(handle);
51  rowEl.appendChild(prevHandle);
52 };
53 
54 ResizeRows.prototype._mouseDown = function (e, row, handle) {
55  var self = this;
56 
57  self.table.element.classList.add("tabulator-block-select");
58 
59  function mouseMove(e) {
60  row.setHeight(self.startHeight + ((typeof e.screenY === "undefined" ? e.touches[0].screenY : e.screenY) - self.startY));
61  }
62 
63  function mouseUp(e) {
64 
65  // //block editor from taking action while resizing is taking place
66  // if(self.startColumn.modules.edit){
67  // self.startColumn.modules.edit.blocked = false;
68  // }
69 
70  document.body.removeEventListener("mouseup", mouseMove);
71  document.body.removeEventListener("mousemove", mouseMove);
72 
73  handle.removeEventListener("touchmove", mouseMove);
74  handle.removeEventListener("touchend", mouseUp);
75 
76  self.table.element.classList.remove("tabulator-block-select");
77 
78  self.table.options.rowResized.call(this.table, row.getComponent());
79  }
80 
81  e.stopPropagation(); //prevent resize from interfereing with movable columns
82 
83  //block editor from taking action while resizing is taking place
84  // if(self.startColumn.modules.edit){
85  // self.startColumn.modules.edit.blocked = true;
86  // }
87 
88  self.startY = typeof e.screenY === "undefined" ? e.touches[0].screenY : e.screenY;
89  self.startHeight = row.getHeight();
90 
91  document.body.addEventListener("mousemove", mouseMove);
92  document.body.addEventListener("mouseup", mouseUp);
93 
94  handle.addEventListener("touchmove", mouseMove, { passive: true });
95  handle.addEventListener("touchend", mouseUp);
96 };
97 
98 Tabulator.prototype.registerModule("resizeRows", ResizeRows);