1 var ResizeColumns =
function(table){
3 this.startColumn =
false;
5 this.startWidth =
false;
7 this.prevHandle = null;
10 ResizeColumns.prototype.initializeColumn =
function(type, column, element){
12 variableHeight =
false,
13 mode = this.table.options.resizableColumns;
16 if(type ===
"header"){
17 variableHeight = column.definition.formatter ==
"textarea" || column.definition.variableHeight;
18 column.modules.resize = {variableHeight:variableHeight};
21 if(mode ===
true || mode == type){
23 var handle = document.createElement(
'div');
24 handle.className =
"tabulator-col-resize-handle";
27 var prevHandle = document.createElement(
'div');
28 prevHandle.className =
"tabulator-col-resize-handle prev";
30 handle.addEventListener(
"click",
function(e){
34 var handleDown =
function(e){
35 var nearestColumn = column.getLastColumn();
37 if(nearestColumn &&
self._checkResizability(nearestColumn)){
38 self.startColumn = column;
39 self._mouseDown(e, nearestColumn, handle);
43 handle.addEventListener(
"mousedown", handleDown);
44 handle.addEventListener(
"touchstart", handleDown, {passive:
true});
47 handle.addEventListener(
"dblclick",
function(e){
48 var col = column.getLastColumn();
50 if(col &&
self._checkResizability(col)){
52 col.reinitializeWidth(
true);
57 prevHandle.addEventListener(
"click",
function(e){
61 var prevHandleDown =
function(e){
62 var nearestColumn, colIndex, prevColumn;
64 nearestColumn = column.getFirstColumn();
67 colIndex =
self.table.columnManager.findColumnIndex(nearestColumn);
68 prevColumn = colIndex > 0 ?
self.table.columnManager.getColumnByIndex(colIndex - 1) :
false;
70 if(prevColumn &&
self._checkResizability(prevColumn)){
71 self.startColumn = column;
72 self._mouseDown(e, prevColumn, prevHandle);
77 prevHandle.addEventListener(
"mousedown", prevHandleDown);
78 prevHandle.addEventListener(
"touchstart", prevHandleDown, {passive:
true});
81 prevHandle.addEventListener(
"dblclick",
function(e){
82 var nearestColumn, colIndex, prevColumn;
84 nearestColumn = column.getFirstColumn();
87 colIndex =
self.table.columnManager.findColumnIndex(nearestColumn);
88 prevColumn = colIndex > 0 ?
self.table.columnManager.getColumnByIndex(colIndex - 1) :
false;
90 if(prevColumn &&
self._checkResizability(prevColumn)){
92 prevColumn.reinitializeWidth(
true);
97 element.appendChild(handle);
98 element.appendChild(prevHandle);
103 ResizeColumns.prototype._checkResizability =
function(column){
104 return typeof column.definition.resizable !=
"undefined" ? column.definition.resizable : this.table.options.resizableColumns;
107 ResizeColumns.prototype._mouseDown =
function(e, column, handle){
110 self.table.element.classList.add(
"tabulator-block-select");
112 function mouseMove(e){
115 column.setWidth(
self.startWidth + ((typeof e.screenX ===
"undefined" ? e.touches[0].screenX : e.screenX) -
self.startX));
117 if(!
self.table.browserSlow && column.modules.resize && column.modules.resize.variableHeight){
118 column.checkCellHeights();
125 if(
self.startColumn.modules.edit){
126 self.startColumn.modules.edit.blocked =
false;
129 if(
self.table.browserSlow && column.modules.resize && column.modules.resize.variableHeight){
130 column.checkCellHeights();
133 document.body.removeEventListener(
"mouseup", mouseUp);
134 document.body.removeEventListener(
"mousemove", mouseMove);
136 handle.removeEventListener(
"touchmove", mouseMove);
137 handle.removeEventListener(
"touchend", mouseUp);
139 self.table.element.classList.remove(
"tabulator-block-select");
141 if(
self.table.options.persistence &&
self.table.modExists(
"persistence",
true) &&
self.table.modules.persistence.config.columns){
142 self.table.modules.persistence.save(
"columns");
145 self.table.options.columnResized.call(
self.table, column.getComponent());
151 if(
self.startColumn.modules.edit){
152 self.startColumn.modules.edit.blocked =
true;
155 self.startX = typeof e.screenX ===
"undefined" ? e.touches[0].screenX : e.screenX;
156 self.startWidth = column.getWidth();
158 document.body.addEventListener(
"mousemove", mouseMove);
159 document.body.addEventListener(
"mouseup", mouseUp);
160 handle.addEventListener(
"touchmove", mouseMove, {passive:
true});
161 handle.addEventListener(
"touchend", mouseUp);
164 Tabulator.prototype.registerModule(
"resizeColumns", ResizeColumns);