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