otsdaq_utilities  v2_05_02_indev
edit.js
1 var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
2 
3 /* Tabulator v4.5.3 (c) Oliver Folkerd */
4 
5 var Edit = function Edit(table) {
6  this.table = table; //hold Tabulator object
7  this.currentCell = false; //hold currently editing cell
8  this.mouseClick = false; //hold mousedown state to prevent click binding being overriden by editor opening
9  this.recursionBlock = false; //prevent focus recursion
10  this.invalidEdit = false;
11 };
12 
13 //initialize column editor
14 Edit.prototype.initializeColumn = function (column) {
15  var self = this,
16  config = {
17  editor: false,
18  blocked: false,
19  check: column.definition.editable,
20  params: column.definition.editorParams || {}
21  };
22 
23  //set column editor
24  switch (_typeof(column.definition.editor)) {
25  case "string":
26 
27  if (column.definition.editor === "tick") {
28  column.definition.editor = "tickCross";
29  console.warn("DEPRECATION WARNING - the tick editor has been deprecated, please use the tickCross editor");
30  }
31 
32  if (self.editors[column.definition.editor]) {
33  config.editor = self.editors[column.definition.editor];
34  } else {
35  console.warn("Editor Error - No such editor found: ", column.definition.editor);
36  }
37  break;
38 
39  case "function":
40  config.editor = column.definition.editor;
41  break;
42 
43  case "boolean":
44 
45  if (column.definition.editor === true) {
46 
47  if (typeof column.definition.formatter !== "function") {
48 
49  if (column.definition.formatter === "tick") {
50  column.definition.formatter = "tickCross";
51  console.warn("DEPRECATION WARNING - the tick editor has been deprecated, please use the tickCross editor");
52  }
53 
54  if (self.editors[column.definition.formatter]) {
55  config.editor = self.editors[column.definition.formatter];
56  } else {
57  config.editor = self.editors["input"];
58  }
59  } else {
60  console.warn("Editor Error - Cannot auto lookup editor for a custom formatter: ", column.definition.formatter);
61  }
62  }
63  break;
64  }
65 
66  if (config.editor) {
67  column.modules.edit = config;
68  }
69 };
70 
71 Edit.prototype.getCurrentCell = function () {
72  return this.currentCell ? this.currentCell.getComponent() : false;
73 };
74 
75 Edit.prototype.clearEditor = function () {
76  var cell = this.currentCell,
77  cellEl;
78 
79  this.invalidEdit = false;
80 
81  if (cell) {
82  this.currentCell = false;
83 
84  cellEl = cell.getElement();
85  cellEl.classList.remove("tabulator-validation-fail");
86  cellEl.classList.remove("tabulator-editing");
87  while (cellEl.firstChild) {
88  cellEl.removeChild(cellEl.firstChild);
89  }cell.row.getElement().classList.remove("tabulator-row-editing");
90  }
91 };
92 
93 Edit.prototype.cancelEdit = function () {
94 
95  if (this.currentCell) {
96  var cell = this.currentCell;
97  var component = this.currentCell.getComponent();
98 
99  this.clearEditor();
100  cell.setValueActual(cell.getValue());
101 
102  if (cell.column.cellEvents.cellEditCancelled) {
103  cell.column.cellEvents.cellEditCancelled.call(this.table, component);
104  }
105 
106  this.table.options.cellEditCancelled.call(this.table, component);
107  }
108 };
109 
110 //return a formatted value for a cell
111 Edit.prototype.bindEditor = function (cell) {
112  var self = this,
113  element = cell.getElement();
114 
115  element.setAttribute("tabindex", 0);
116 
117  element.addEventListener("click", function (e) {
118  if (!element.classList.contains("tabulator-editing")) {
119  element.focus();
120  }
121  });
122 
123  element.addEventListener("mousedown", function (e) {
124  self.mouseClick = true;
125  });
126 
127  element.addEventListener("focus", function (e) {
128  if (!self.recursionBlock) {
129  self.edit(cell, e, false);
130  }
131  });
132 };
133 
134 Edit.prototype.focusCellNoEvent = function (cell, block) {
135  this.recursionBlock = true;
136  if (!(block && this.table.browser === "ie")) {
137  cell.getElement().focus();
138  }
139  this.recursionBlock = false;
140 };
141 
142 Edit.prototype.editCell = function (cell, forceEdit) {
143  this.focusCellNoEvent(cell);
144  this.edit(cell, false, forceEdit);
145 };
146 
147 Edit.prototype.edit = function (cell, e, forceEdit) {
148  var self = this,
149  allowEdit = true,
150  rendered = function rendered() {},
151  element = cell.getElement(),
152  cellEditor,
153  component,
154  params;
155 
156  //prevent editing if another cell is refusing to leave focus (eg. validation fail)
157  if (this.currentCell) {
158  if (!this.invalidEdit) {
159  this.cancelEdit();
160  }
161  return;
162  }
163 
164  //handle successfull value change
165  function success(value) {
166 
167  if (self.currentCell === cell) {
168  var valid = true;
169 
170  if (cell.column.modules.validate && self.table.modExists("validate")) {
171  valid = self.table.modules.validate.validate(cell.column.modules.validate, cell.getComponent(), value);
172  }
173 
174  if (valid === true) {
175  self.clearEditor();
176  cell.setValue(value, true);
177 
178  if (self.table.options.dataTree && self.table.modExists("dataTree")) {
179  self.table.modules.dataTree.checkForRestyle(cell);
180  }
181 
182  return true;
183  } else {
184  self.invalidEdit = true;
185  element.classList.add("tabulator-validation-fail");
186  self.focusCellNoEvent(cell, true);
187  rendered();
188  self.table.options.validationFailed.call(self.table, cell.getComponent(), value, valid);
189 
190  return false;
191  }
192  } else {
193  // console.warn("Edit Success Error - cannot call success on a cell that is no longer being edited");
194  }
195  }
196 
197  //handle aborted edit
198  function cancel() {
199  if (self.currentCell === cell) {
200  self.cancelEdit();
201 
202  if (self.table.options.dataTree && self.table.modExists("dataTree")) {
203  self.table.modules.dataTree.checkForRestyle(cell);
204  }
205  } else {
206  // console.warn("Edit Success Error - cannot call cancel on a cell that is no longer being edited");
207  }
208  }
209 
210  function onRendered(callback) {
211  rendered = callback;
212  }
213 
214  if (!cell.column.modules.edit.blocked) {
215  if (e) {
216  e.stopPropagation();
217  }
218 
219  switch (_typeof(cell.column.modules.edit.check)) {
220  case "function":
221  allowEdit = cell.column.modules.edit.check(cell.getComponent());
222  break;
223 
224  case "boolean":
225  allowEdit = cell.column.modules.edit.check;
226  break;
227  }
228 
229  if (allowEdit || forceEdit) {
230 
231  self.cancelEdit();
232 
233  self.currentCell = cell;
234 
235  component = cell.getComponent();
236 
237  if (this.mouseClick) {
238  this.mouseClick = false;
239 
240  if (cell.column.cellEvents.cellClick) {
241  cell.column.cellEvents.cellClick.call(this.table, e, component);
242  }
243  }
244 
245  if (cell.column.cellEvents.cellEditing) {
246  cell.column.cellEvents.cellEditing.call(this.table, component);
247  }
248 
249  self.table.options.cellEditing.call(this.table, component);
250 
251  params = typeof cell.column.modules.edit.params === "function" ? cell.column.modules.edit.params(component) : cell.column.modules.edit.params;
252 
253  cellEditor = cell.column.modules.edit.editor.call(self, component, onRendered, success, cancel, params);
254 
255  //if editor returned, add to DOM, if false, abort edit
256  if (cellEditor !== false) {
257 
258  if (cellEditor instanceof Node) {
259  element.classList.add("tabulator-editing");
260  cell.row.getElement().classList.add("tabulator-row-editing");
261  while (element.firstChild) {
262  element.removeChild(element.firstChild);
263  }element.appendChild(cellEditor);
264 
265  //trigger onRendered Callback
266  rendered();
267 
268  //prevent editing from triggering rowClick event
269  var children = element.children;
270 
271  for (var i = 0; i < children.length; i++) {
272  children[i].addEventListener("click", function (e) {
273  e.stopPropagation();
274  });
275  }
276  } else {
277  console.warn("Edit Error - Editor should return an instance of Node, the editor returned:", cellEditor);
278  element.blur();
279  return false;
280  }
281  } else {
282  element.blur();
283  return false;
284  }
285 
286  return true;
287  } else {
288  this.mouseClick = false;
289  element.blur();
290  return false;
291  }
292  } else {
293  this.mouseClick = false;
294  element.blur();
295  return false;
296  }
297 };
298 
299 //default data editors
300 Edit.prototype.editors = {
301 
302  //input element
303  input: function input(cell, onRendered, success, cancel, editorParams) {
304 
305  //create and style input
306  var cellValue = cell.getValue(),
307  input = document.createElement("input");
308 
309  input.setAttribute("type", editorParams.search ? "search" : "text");
310 
311  input.style.padding = "4px";
312  input.style.width = "100%";
313  input.style.boxSizing = "border-box";
314 
315  if (editorParams.elementAttributes && _typeof(editorParams.elementAttributes) == "object") {
316  for (var key in editorParams.elementAttributes) {
317  if (key.charAt(0) == "+") {
318  key = key.slice(1);
319  input.setAttribute(key, input.getAttribute(key) + editorParams.elementAttributes["+" + key]);
320  } else {
321  input.setAttribute(key, editorParams.elementAttributes[key]);
322  }
323  }
324  }
325 
326  input.value = typeof cellValue !== "undefined" ? cellValue : "";
327 
328  onRendered(function () {
329  input.focus();
330  input.style.height = "100%";
331  });
332 
333  function onChange(e) {
334  if ((cellValue === null || typeof cellValue === "undefined") && input.value !== "" || input.value != cellValue) {
335 
336  if (success(input.value)) {
337  cellValue = input.value; //persist value if successfully validated incase editor is used as header filter
338  }
339  } else {
340  cancel();
341  }
342  }
343 
344  //submit new value on blur or change
345  input.addEventListener("change", onChange);
346  input.addEventListener("blur", onChange);
347 
348  //submit new value on enter
349  input.addEventListener("keydown", function (e) {
350  switch (e.keyCode) {
351  case 13:
352  onChange(e);
353  break;
354 
355  case 27:
356  cancel();
357  break;
358  }
359  });
360 
361  return input;
362  },
363 
364  //resizable text area element
365  textarea: function textarea(cell, onRendered, success, cancel, editorParams) {
366  var self = this,
367  cellValue = cell.getValue(),
368  vertNav = editorParams.verticalNavigation || "hybrid",
369  value = String(cellValue !== null && typeof cellValue !== "undefined" ? cellValue : ""),
370  count = (value.match(/(?:\r\n|\r|\n)/g) || []).length + 1,
371  input = document.createElement("textarea"),
372  scrollHeight = 0;
373 
374  //create and style input
375  input.style.display = "block";
376  input.style.padding = "2px";
377  input.style.height = "100%";
378  input.style.width = "100%";
379  input.style.boxSizing = "border-box";
380  input.style.whiteSpace = "pre-wrap";
381  input.style.resize = "none";
382 
383  if (editorParams.elementAttributes && _typeof(editorParams.elementAttributes) == "object") {
384  for (var key in editorParams.elementAttributes) {
385  if (key.charAt(0) == "+") {
386  key = key.slice(1);
387  input.setAttribute(key, input.getAttribute(key) + editorParams.elementAttributes["+" + key]);
388  } else {
389  input.setAttribute(key, editorParams.elementAttributes[key]);
390  }
391  }
392  }
393 
394  input.value = value;
395 
396  onRendered(function () {
397  input.focus();
398  input.style.height = "100%";
399  });
400 
401  function onChange(e) {
402 
403  if ((cellValue === null || typeof cellValue === "undefined") && input.value !== "" || input.value != cellValue) {
404 
405  if (success(input.value)) {
406  cellValue = input.value; //persist value if successfully validated incase editor is used as header filter
407  }
408 
409  setTimeout(function () {
410  cell.getRow().normalizeHeight();
411  }, 300);
412  } else {
413  cancel();
414  }
415  }
416 
417  //submit new value on blur or change
418  input.addEventListener("change", onChange);
419  input.addEventListener("blur", onChange);
420 
421  input.addEventListener("keyup", function () {
422 
423  input.style.height = "";
424 
425  var heightNow = input.scrollHeight;
426 
427  input.style.height = heightNow + "px";
428 
429  if (heightNow != scrollHeight) {
430  scrollHeight = heightNow;
431  cell.getRow().normalizeHeight();
432  }
433  });
434 
435  input.addEventListener("keydown", function (e) {
436 
437  switch (e.keyCode) {
438  case 27:
439  cancel();
440  break;
441 
442  case 38:
443  //up arrow
444  if (vertNav == "editor" || vertNav == "hybrid" && input.selectionStart) {
445  e.stopImmediatePropagation();
446  e.stopPropagation();
447  }
448 
449  break;
450 
451  case 40:
452  //down arrow
453  if (vertNav == "editor" || vertNav == "hybrid" && input.selectionStart !== input.value.length) {
454  e.stopImmediatePropagation();
455  e.stopPropagation();
456  }
457  break;
458  }
459  });
460 
461  return input;
462  },
463 
464  //input element with type of number
465  number: function number(cell, onRendered, success, cancel, editorParams) {
466 
467  var cellValue = cell.getValue(),
468  vertNav = editorParams.verticalNavigation || "editor",
469  input = document.createElement("input");
470 
471  input.setAttribute("type", "number");
472 
473  if (typeof editorParams.max != "undefined") {
474  input.setAttribute("max", editorParams.max);
475  }
476 
477  if (typeof editorParams.min != "undefined") {
478  input.setAttribute("min", editorParams.min);
479  }
480 
481  if (typeof editorParams.step != "undefined") {
482  input.setAttribute("step", editorParams.step);
483  }
484 
485  //create and style input
486  input.style.padding = "4px";
487  input.style.width = "100%";
488  input.style.boxSizing = "border-box";
489 
490  if (editorParams.elementAttributes && _typeof(editorParams.elementAttributes) == "object") {
491  for (var key in editorParams.elementAttributes) {
492  if (key.charAt(0) == "+") {
493  key = key.slice(1);
494  input.setAttribute(key, input.getAttribute(key) + editorParams.elementAttributes["+" + key]);
495  } else {
496  input.setAttribute(key, editorParams.elementAttributes[key]);
497  }
498  }
499  }
500 
501  input.value = cellValue;
502 
503  var blurFunc = function blurFunc(e) {
504  onChange();
505  };
506 
507  onRendered(function () {
508  //submit new value on blur
509  input.removeEventListener("blur", blurFunc);
510 
511  input.focus();
512  input.style.height = "100%";
513 
514  //submit new value on blur
515  input.addEventListener("blur", blurFunc);
516  });
517 
518  function onChange() {
519  var value = input.value;
520 
521  if (!isNaN(value) && value !== "") {
522  value = Number(value);
523  }
524 
525  if (value != cellValue) {
526  if (success(value)) {
527  cellValue = value; //persist value if successfully validated incase editor is used as header filter
528  }
529  } else {
530  cancel();
531  }
532  }
533 
534  //submit new value on enter
535  input.addEventListener("keydown", function (e) {
536  switch (e.keyCode) {
537  case 13:
538  // case 9:
539  onChange();
540  break;
541 
542  case 27:
543  cancel();
544  break;
545 
546  case 38: //up arrow
547  case 40:
548  //down arrow
549  if (vertNav == "editor") {
550  e.stopImmediatePropagation();
551  e.stopPropagation();
552  }
553  break;
554  }
555  });
556 
557  return input;
558  },
559 
560  //input element with type of number
561  range: function range(cell, onRendered, success, cancel, editorParams) {
562 
563  var cellValue = cell.getValue(),
564  input = document.createElement("input");
565 
566  input.setAttribute("type", "range");
567 
568  if (typeof editorParams.max != "undefined") {
569  input.setAttribute("max", editorParams.max);
570  }
571 
572  if (typeof editorParams.min != "undefined") {
573  input.setAttribute("min", editorParams.min);
574  }
575 
576  if (typeof editorParams.step != "undefined") {
577  input.setAttribute("step", editorParams.step);
578  }
579 
580  //create and style input
581  input.style.padding = "4px";
582  input.style.width = "100%";
583  input.style.boxSizing = "border-box";
584 
585  if (editorParams.elementAttributes && _typeof(editorParams.elementAttributes) == "object") {
586  for (var key in editorParams.elementAttributes) {
587  if (key.charAt(0) == "+") {
588  key = key.slice(1);
589  input.setAttribute(key, input.getAttribute(key) + editorParams.elementAttributes["+" + key]);
590  } else {
591  input.setAttribute(key, editorParams.elementAttributes[key]);
592  }
593  }
594  }
595 
596  input.value = cellValue;
597 
598  onRendered(function () {
599  input.focus();
600  input.style.height = "100%";
601  });
602 
603  function onChange() {
604  var value = input.value;
605 
606  if (!isNaN(value) && value !== "") {
607  value = Number(value);
608  }
609 
610  if (value != cellValue) {
611  if (success(value)) {
612  cellValue = value; //persist value if successfully validated incase editor is used as header filter
613  }
614  } else {
615  cancel();
616  }
617  }
618 
619  //submit new value on blur
620  input.addEventListener("blur", function (e) {
621  onChange();
622  });
623 
624  //submit new value on enter
625  input.addEventListener("keydown", function (e) {
626  switch (e.keyCode) {
627  case 13:
628  case 9:
629  onChange();
630  break;
631 
632  case 27:
633  cancel();
634  break;
635  }
636  });
637 
638  return input;
639  },
640 
641  //select
642  select: function select(cell, onRendered, success, cancel, editorParams) {
643  var self = this,
644  cellEl = cell.getElement(),
645  initialValue = cell.getValue(),
646  vertNav = editorParams.verticalNavigation || "editor",
647  initialDisplayValue = typeof initialValue !== "undefined" || initialValue === null ? initialValue : typeof editorParams.defaultValue !== "undefined" ? editorParams.defaultValue : "",
648  input = document.createElement("input"),
649  listEl = document.createElement("div"),
650  dataItems = [],
651  displayItems = [],
652  currentItem = {},
653  blurable = true;
654 
655  this.table.rowManager.element.addEventListener("scroll", cancelItem);
656 
657  if (Array.isArray(editorParams) || !Array.isArray(editorParams) && (typeof editorParams === "undefined" ? "undefined" : _typeof(editorParams)) === "object" && !editorParams.values) {
658  console.warn("DEPRECATION WANRING - values for the select editor must now be passed into the values property of the editorParams object, not as the editorParams object");
659  editorParams = { values: editorParams };
660  }
661 
662  function getUniqueColumnValues(field) {
663  var output = {},
664  data = self.table.getData(),
665  column;
666 
667  if (field) {
668  column = self.table.columnManager.getColumnByField(field);
669  } else {
670  column = cell.getColumn()._getSelf();
671  }
672 
673  if (column) {
674  data.forEach(function (row) {
675  var val = column.getFieldValue(row);
676 
677  if (val !== null && typeof val !== "undefined" && val !== "") {
678  output[val] = true;
679  }
680  });
681 
682  if (editorParams.sortValuesList) {
683  if (editorParams.sortValuesList == "asc") {
684  output = Object.keys(output).sort();
685  } else {
686  output = Object.keys(output).sort().reverse();
687  }
688  } else {
689  output = Object.keys(output);
690  }
691  } else {
692  console.warn("unable to find matching column to create select lookup list:", field);
693  }
694 
695  return output;
696  }
697 
698  function parseItems(inputValues, curentValue) {
699  var dataList = [];
700  var displayList = [];
701 
702  function processComplexListItem(item) {
703  var item = {
704  label: editorParams.listItemFormatter ? editorParams.listItemFormatter(item.value, item.label) : item.label,
705  value: item.value,
706  element: false
707  };
708 
709  if (item.value === curentValue || !isNaN(parseFloat(item.value)) && !isNaN(parseFloat(item.value)) && parseFloat(item.value) === parseFloat(curentValue)) {
710  setCurrentItem(item);
711  }
712 
713  dataList.push(item);
714  displayList.push(item);
715 
716  return item;
717  }
718 
719  if (typeof inputValues == "function") {
720  inputValues = inputValues(cell);
721  }
722 
723  if (Array.isArray(inputValues)) {
724  inputValues.forEach(function (value) {
725  var item;
726 
727  if ((typeof value === "undefined" ? "undefined" : _typeof(value)) === "object") {
728 
729  if (value.options) {
730  item = {
731  label: value.label,
732  group: true,
733  element: false
734  };
735 
736  displayList.push(item);
737 
738  value.options.forEach(function (item) {
739  processComplexListItem(item);
740  });
741  } else {
742  processComplexListItem(value);
743  }
744  } else {
745 
746  item = {
747  label: editorParams.listItemFormatter ? editorParams.listItemFormatter(value, value) : value,
748  value: value,
749  element: false
750  };
751 
752  if (item.value === curentValue || !isNaN(parseFloat(item.value)) && !isNaN(parseFloat(item.value)) && parseFloat(item.value) === parseFloat(curentValue)) {
753  setCurrentItem(item);
754  }
755 
756  dataList.push(item);
757  displayList.push(item);
758  }
759  });
760  } else {
761  for (var key in inputValues) {
762  var item = {
763  label: editorParams.listItemFormatter ? editorParams.listItemFormatter(key, inputValues[key]) : inputValues[key],
764  value: key,
765  element: false
766  };
767 
768  if (item.value === curentValue || !isNaN(parseFloat(item.value)) && !isNaN(parseFloat(item.value)) && parseFloat(item.value) === parseFloat(curentValue)) {
769  setCurrentItem(item);
770  }
771 
772  dataList.push(item);
773  displayList.push(item);
774  }
775  }
776 
777  dataItems = dataList;
778  displayItems = displayList;
779 
780  fillList();
781  }
782 
783  function fillList() {
784  while (listEl.firstChild) {
785  listEl.removeChild(listEl.firstChild);
786  }displayItems.forEach(function (item) {
787  var el = item.element;
788 
789  if (!el) {
790 
791  if (item.group) {
792  el = document.createElement("div");
793  el.classList.add("tabulator-edit-select-list-group");
794  el.tabIndex = 0;
795  el.innerHTML = item.label === "" ? "&nbsp;" : item.label;
796  } else {
797  el = document.createElement("div");
798  el.classList.add("tabulator-edit-select-list-item");
799  el.tabIndex = 0;
800  el.innerHTML = item.label === "" ? "&nbsp;" : item.label;
801 
802  el.addEventListener("click", function () {
803  setCurrentItem(item);
804  chooseItem();
805  });
806 
807  if (item === currentItem) {
808  el.classList.add("active");
809  }
810  }
811 
812  el.addEventListener("mousedown", function () {
813  blurable = false;
814 
815  setTimeout(function () {
816  blurable = true;
817  }, 10);
818  });
819 
820  item.element = el;
821  }
822 
823  listEl.appendChild(el);
824  });
825  }
826 
827  function setCurrentItem(item) {
828 
829  if (currentItem && currentItem.element) {
830  currentItem.element.classList.remove("active");
831  }
832 
833  currentItem = item;
834  input.value = item.label === "&nbsp;" ? "" : item.label;
835 
836  if (item.element) {
837  item.element.classList.add("active");
838  }
839  }
840 
841  function chooseItem() {
842  hideList();
843 
844  if (initialValue !== currentItem.value) {
845  initialValue = currentItem.value;
846  success(currentItem.value);
847  } else {
848  cancel();
849  }
850  }
851 
852  function cancelItem() {
853  hideList();
854  cancel();
855  }
856 
857  function showList() {
858  if (!listEl.parentNode) {
859 
860  if (editorParams.values === true) {
861  parseItems(getUniqueColumnValues(), initialDisplayValue);
862  } else if (typeof editorParams.values === "string") {
863  parseItems(getUniqueColumnValues(editorParams.values), initialDisplayValue);
864  } else {
865  parseItems(editorParams.values || [], initialDisplayValue);
866  }
867 
868  var offset = Tabulator.prototype.helpers.elOffset(cellEl);
869 
870  listEl.style.minWidth = cellEl.offsetWidth + "px";
871 
872  listEl.style.top = offset.top + cellEl.offsetHeight + "px";
873  listEl.style.left = offset.left + "px";
874  document.body.appendChild(listEl);
875  }
876  }
877 
878  function hideList() {
879  if (listEl.parentNode) {
880  listEl.parentNode.removeChild(listEl);
881  }
882 
883  removeScrollListener();
884  }
885 
886  function removeScrollListener() {
887  self.table.rowManager.element.removeEventListener("scroll", cancelItem);
888  }
889 
890  //style input
891  input.setAttribute("type", "text");
892 
893  input.style.padding = "4px";
894  input.style.width = "100%";
895  input.style.boxSizing = "border-box";
896  input.style.cursor = "default";
897  input.readOnly = this.currentCell != false;
898 
899  if (editorParams.elementAttributes && _typeof(editorParams.elementAttributes) == "object") {
900  for (var key in editorParams.elementAttributes) {
901  if (key.charAt(0) == "+") {
902  key = key.slice(1);
903  input.setAttribute(key, input.getAttribute(key) + editorParams.elementAttributes["+" + key]);
904  } else {
905  input.setAttribute(key, editorParams.elementAttributes[key]);
906  }
907  }
908  }
909 
910  input.value = typeof initialValue !== "undefined" || initialValue === null ? initialValue : "";
911 
912  // if(editorParams.values === true){
913  // parseItems(getUniqueColumnValues(), initialValue);
914  // }else if(typeof editorParams.values === "string"){
915  // parseItems(getUniqueColumnValues(editorParams.values), initialValue);
916  // }else{
917  // parseItems(editorParams.values || [], initialValue);
918  // }
919 
920  //allow key based navigation
921  input.addEventListener("keydown", function (e) {
922  var index;
923 
924  switch (e.keyCode) {
925  case 38:
926  //up arrow
927  index = dataItems.indexOf(currentItem);
928 
929  if (vertNav == "editor" || vertNav == "hybrid" && index) {
930  e.stopImmediatePropagation();
931  e.stopPropagation();
932  e.preventDefault();
933 
934  if (index > 0) {
935  setCurrentItem(dataItems[index - 1]);
936  }
937  }
938  break;
939 
940  case 40:
941  //down arrow
942  index = dataItems.indexOf(currentItem);
943 
944  if (vertNav == "editor" || vertNav == "hybrid" && index < dataItems.length - 1) {
945  e.stopImmediatePropagation();
946  e.stopPropagation();
947  e.preventDefault();
948 
949  if (index < dataItems.length - 1) {
950  if (index == -1) {
951  setCurrentItem(dataItems[0]);
952  } else {
953  setCurrentItem(dataItems[index + 1]);
954  }
955  }
956  }
957  break;
958 
959  case 37: //left arrow
960  case 39:
961  //right arrow
962  e.stopImmediatePropagation();
963  e.stopPropagation();
964  e.preventDefault();
965  break;
966 
967  case 13:
968  //enter
969  chooseItem();
970  break;
971 
972  case 27:
973  //escape
974  cancelItem();
975  break;
976  }
977  });
978 
979  input.addEventListener("blur", function (e) {
980  if (blurable) {
981  cancelItem();
982  }
983  });
984 
985  input.addEventListener("focus", function (e) {
986  showList();
987  });
988 
989  //style list element
990  listEl = document.createElement("div");
991  listEl.classList.add("tabulator-edit-select-list");
992 
993  onRendered(function () {
994  input.style.height = "100%";
995  input.focus();
996  });
997 
998  return input;
999  },
1000 
1001  //autocomplete
1002  autocomplete: function autocomplete(cell, onRendered, success, cancel, editorParams) {
1003  var self = this,
1004  cellEl = cell.getElement(),
1005  initialValue = cell.getValue(),
1006  vertNav = editorParams.verticalNavigation || "editor",
1007  initialDisplayValue = typeof initialValue !== "undefined" || initialValue === null ? initialValue : typeof editorParams.defaultValue !== "undefined" ? editorParams.defaultValue : "",
1008  input = document.createElement("input"),
1009  listEl = document.createElement("div"),
1010  allItems = [],
1011  displayItems = [],
1012  values = [],
1013  currentItem = {},
1014  blurable = true;
1015 
1016  this.table.rowManager.element.addEventListener("scroll", cancelItem);
1017 
1018  function getUniqueColumnValues(field) {
1019  var output = {},
1020  data = self.table.getData(),
1021  column;
1022 
1023  if (field) {
1024  column = self.table.columnManager.getColumnByField(field);
1025  } else {
1026  column = cell.getColumn()._getSelf();
1027  }
1028 
1029  if (column) {
1030  data.forEach(function (row) {
1031  var val = column.getFieldValue(row);
1032 
1033  if (val !== null && typeof val !== "undefined" && val !== "") {
1034  output[val] = true;
1035  }
1036  });
1037 
1038  if (editorParams.sortValuesList) {
1039  if (editorParams.sortValuesList == "asc") {
1040  output = Object.keys(output).sort();
1041  } else {
1042  output = Object.keys(output).sort().reverse();
1043  }
1044  } else {
1045  output = Object.keys(output);
1046  }
1047  } else {
1048  console.warn("unable to find matching column to create autocomplete lookup list:", field);
1049  }
1050 
1051  return output;
1052  }
1053 
1054  function parseItems(inputValues, curentValue) {
1055  var itemList = [];
1056 
1057  if (Array.isArray(inputValues)) {
1058  inputValues.forEach(function (value) {
1059  var item = {
1060  title: editorParams.listItemFormatter ? editorParams.listItemFormatter(value, value) : value,
1061  value: value,
1062  element: false
1063  };
1064 
1065  if (item.value === curentValue || !isNaN(parseFloat(item.value)) && !isNaN(parseFloat(item.value)) && parseFloat(item.value) === parseFloat(curentValue)) {
1066  setCurrentItem(item);
1067  }
1068 
1069  itemList.push(item);
1070  });
1071  } else {
1072  for (var key in inputValues) {
1073  var item = {
1074  title: editorParams.listItemFormatter ? editorParams.listItemFormatter(key, inputValues[key]) : inputValues[key],
1075  value: key,
1076  element: false
1077  };
1078 
1079  if (item.value === curentValue || !isNaN(parseFloat(item.value)) && !isNaN(parseFloat(item.value)) && parseFloat(item.value) === parseFloat(curentValue)) {
1080  setCurrentItem(item);
1081  }
1082 
1083  itemList.push(item);
1084  }
1085  }
1086 
1087  if (editorParams.searchFunc) {
1088  itemList.forEach(function (item) {
1089  item.search = {
1090  title: item.title,
1091  value: item.value
1092  };
1093  });
1094  }
1095 
1096  allItems = itemList;
1097  }
1098 
1099  function filterList(term, intialLoad) {
1100  var matches = [],
1101  searchObjs = [],
1102  searchResults = [];
1103 
1104  if (editorParams.searchFunc) {
1105 
1106  allItems.forEach(function (item) {
1107  searchObjs.push(item.search);
1108  });
1109 
1110  searchResults = editorParams.searchFunc(term, searchObjs);
1111 
1112  searchResults.forEach(function (result) {
1113  var match = allItems.find(function (item) {
1114  return item.search === result;
1115  });
1116 
1117  if (match) {
1118  matches.push(match);
1119  }
1120  });
1121  } else {
1122  if (term === "") {
1123 
1124  if (editorParams.showListOnEmpty) {
1125  allItems.forEach(function (item) {
1126  matches.push(item);
1127  });
1128  }
1129  } else {
1130  allItems.forEach(function (item) {
1131 
1132  if (item.value !== null || typeof item.value !== "undefined") {
1133  if (String(item.value).toLowerCase().indexOf(String(term).toLowerCase()) > -1 || String(item.title).toLowerCase().indexOf(String(term).toLowerCase()) > -1) {
1134  matches.push(item);
1135  }
1136  }
1137  });
1138  }
1139  }
1140 
1141  displayItems = matches;
1142 
1143  fillList(intialLoad);
1144  }
1145 
1146  function fillList(intialLoad) {
1147  var current = false;
1148 
1149  while (listEl.firstChild) {
1150  listEl.removeChild(listEl.firstChild);
1151  }displayItems.forEach(function (item) {
1152  var el = item.element;
1153 
1154  if (!el) {
1155  el = document.createElement("div");
1156  el.classList.add("tabulator-edit-select-list-item");
1157  el.tabIndex = 0;
1158  el.innerHTML = item.title;
1159 
1160  el.addEventListener("click", function () {
1161  setCurrentItem(item);
1162  chooseItem();
1163  });
1164 
1165  el.addEventListener("mousedown", function () {
1166  blurable = false;
1167 
1168  setTimeout(function () {
1169  blurable = true;
1170  }, 10);
1171  });
1172 
1173  item.element = el;
1174 
1175  if (intialLoad && item.value == initialValue) {
1176  input.value = item.title;
1177  item.element.classList.add("active");
1178  current = true;
1179  }
1180 
1181  if (item === currentItem) {
1182  item.element.classList.add("active");
1183  current = true;
1184  }
1185  }
1186 
1187  listEl.appendChild(el);
1188  });
1189 
1190  if (!current) {
1191  setCurrentItem(false);
1192  }
1193  }
1194 
1195  function setCurrentItem(item, showInputValue) {
1196  if (currentItem && currentItem.element) {
1197  currentItem.element.classList.remove("active");
1198  }
1199 
1200  currentItem = item;
1201 
1202  if (item && item.element) {
1203  item.element.classList.add("active");
1204  }
1205  }
1206 
1207  function chooseItem() {
1208  hideList();
1209 
1210  if (currentItem) {
1211  if (initialValue !== currentItem.value) {
1212  initialValue = currentItem.value;
1213  input.value = currentItem.title;
1214  success(currentItem.value);
1215  } else {
1216  cancel();
1217  }
1218  } else {
1219  if (editorParams.freetext) {
1220  initialValue = input.value;
1221  success(input.value);
1222  } else {
1223  if (editorParams.allowEmpty && input.value === "") {
1224  initialValue = input.value;
1225  success(input.value);
1226  } else {
1227  cancel();
1228  }
1229  }
1230  }
1231  }
1232 
1233  function cancelItem() {
1234  hideList();
1235  cancel();
1236  }
1237 
1238  function showList() {
1239  if (!listEl.parentNode) {
1240  while (listEl.firstChild) {
1241  listEl.removeChild(listEl.firstChild);
1242  }if (editorParams.values === true) {
1243  values = getUniqueColumnValues();
1244  } else if (typeof editorParams.values === "string") {
1245  values = getUniqueColumnValues(editorParams.values);
1246  } else {
1247  values = editorParams.values || [];
1248  }
1249 
1250  parseItems(values, initialValue);
1251 
1252  var offset = Tabulator.prototype.helpers.elOffset(cellEl);
1253 
1254  listEl.style.minWidth = cellEl.offsetWidth + "px";
1255 
1256  listEl.style.top = offset.top + cellEl.offsetHeight + "px";
1257  listEl.style.left = offset.left + "px";
1258  document.body.appendChild(listEl);
1259  }
1260  }
1261 
1262  function hideList() {
1263  if (listEl.parentNode) {
1264  listEl.parentNode.removeChild(listEl);
1265  }
1266 
1267  removeScrollListener();
1268  }
1269 
1270  function removeScrollListener() {
1271  self.table.rowManager.element.removeEventListener("scroll", cancelItem);
1272  }
1273 
1274  //style input
1275  input.setAttribute("type", "search");
1276 
1277  input.style.padding = "4px";
1278  input.style.width = "100%";
1279  input.style.boxSizing = "border-box";
1280 
1281  if (editorParams.elementAttributes && _typeof(editorParams.elementAttributes) == "object") {
1282  for (var key in editorParams.elementAttributes) {
1283  if (key.charAt(0) == "+") {
1284  key = key.slice(1);
1285  input.setAttribute(key, input.getAttribute(key) + editorParams.elementAttributes["+" + key]);
1286  } else {
1287  input.setAttribute(key, editorParams.elementAttributes[key]);
1288  }
1289  }
1290  }
1291 
1292  //allow key based navigation
1293  input.addEventListener("keydown", function (e) {
1294  var index;
1295 
1296  switch (e.keyCode) {
1297  case 38:
1298  //up arrow
1299  index = displayItems.indexOf(currentItem);
1300 
1301  if (vertNav == "editor" || vertNav == "hybrid" && index) {
1302  e.stopImmediatePropagation();
1303  e.stopPropagation();
1304  e.preventDefault();
1305 
1306  if (index > 0) {
1307  setCurrentItem(displayItems[index - 1]);
1308  } else {
1309  setCurrentItem(false);
1310  }
1311  }
1312  break;
1313 
1314  case 40:
1315  //down arrow
1316 
1317  index = displayItems.indexOf(currentItem);
1318 
1319  if (vertNav == "editor" || vertNav == "hybrid" && index < displayItems.length - 1) {
1320 
1321  e.stopImmediatePropagation();
1322  e.stopPropagation();
1323  e.preventDefault();
1324 
1325  if (index < displayItems.length - 1) {
1326  if (index == -1) {
1327  setCurrentItem(displayItems[0]);
1328  } else {
1329  setCurrentItem(displayItems[index + 1]);
1330  }
1331  }
1332  }
1333  break;
1334 
1335  case 37: //left arrow
1336  case 39:
1337  //right arrow
1338  e.stopImmediatePropagation();
1339  e.stopPropagation();
1340  e.preventDefault();
1341  break;
1342 
1343  case 13:
1344  //enter
1345  chooseItem();
1346  break;
1347 
1348  case 27:
1349  //escape
1350  cancelItem();
1351  break;
1352 
1353  case 36: //home
1354  case 35:
1355  //end
1356  //prevent table navigation while using input element
1357  e.stopImmediatePropagation();
1358  break;
1359  }
1360  });
1361 
1362  input.addEventListener("keyup", function (e) {
1363 
1364  switch (e.keyCode) {
1365  case 38: //up arrow
1366  case 37: //left arrow
1367  case 39: //up arrow
1368  case 40: //right arrow
1369  case 13: //enter
1370  case 27:
1371  //escape
1372  break;
1373 
1374  default:
1375  filterList(input.value);
1376  }
1377  });
1378 
1379  input.addEventListener("search", function (e) {
1380  filterList(input.value);
1381  });
1382 
1383  input.addEventListener("blur", function (e) {
1384  if (blurable) {
1385  chooseItem();
1386  }
1387  });
1388 
1389  input.addEventListener("focus", function (e) {
1390  var value = initialDisplayValue;
1391  showList();
1392  input.value = value;
1393  filterList(value, true);
1394  });
1395 
1396  //style list element
1397  listEl = document.createElement("div");
1398  listEl.classList.add("tabulator-edit-select-list");
1399 
1400  onRendered(function () {
1401  input.style.height = "100%";
1402  input.focus();
1403  });
1404 
1405  return input;
1406  },
1407 
1408  //start rating
1409  star: function star(cell, onRendered, success, cancel, editorParams) {
1410  var self = this,
1411  element = cell.getElement(),
1412  value = cell.getValue(),
1413  maxStars = element.getElementsByTagName("svg").length || 5,
1414  size = element.getElementsByTagName("svg")[0] ? element.getElementsByTagName("svg")[0].getAttribute("width") : 14,
1415  stars = [],
1416  starsHolder = document.createElement("div"),
1417  star = document.createElementNS('http://www.w3.org/2000/svg', "svg");
1418 
1419  //change star type
1420  function starChange(val) {
1421  stars.forEach(function (star, i) {
1422  if (i < val) {
1423  if (self.table.browser == "ie") {
1424  star.setAttribute("class", "tabulator-star-active");
1425  } else {
1426  star.classList.replace("tabulator-star-inactive", "tabulator-star-active");
1427  }
1428 
1429  star.innerHTML = '<polygon fill="#488CE9" stroke="#014AAE" stroke-width="37.6152" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" points="259.216,29.942 330.27,173.919 489.16,197.007 374.185,309.08 401.33,467.31 259.216,392.612 117.104,467.31 144.25,309.08 29.274,197.007 188.165,173.919 "/>';
1430  } else {
1431  if (self.table.browser == "ie") {
1432  star.setAttribute("class", "tabulator-star-inactive");
1433  } else {
1434  star.classList.replace("tabulator-star-active", "tabulator-star-inactive");
1435  }
1436 
1437  star.innerHTML = '<polygon fill="#010155" stroke="#686868" stroke-width="37.6152" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" points="259.216,29.942 330.27,173.919 489.16,197.007 374.185,309.08 401.33,467.31 259.216,392.612 117.104,467.31 144.25,309.08 29.274,197.007 188.165,173.919 "/>';
1438  }
1439  });
1440  }
1441 
1442  //build stars
1443  function buildStar(i) {
1444 
1445  var starHolder = document.createElement("span");
1446  var nextStar = star.cloneNode(true);
1447 
1448  stars.push(nextStar);
1449 
1450  starHolder.addEventListener("mouseenter", function (e) {
1451  e.stopPropagation();
1452  e.stopImmediatePropagation();
1453  starChange(i);
1454  });
1455 
1456  starHolder.addEventListener("mousemove", function (e) {
1457  e.stopPropagation();
1458  e.stopImmediatePropagation();
1459  });
1460 
1461  starHolder.addEventListener("click", function (e) {
1462  e.stopPropagation();
1463  e.stopImmediatePropagation();
1464  success(i);
1465  });
1466 
1467  starHolder.appendChild(nextStar);
1468  starsHolder.appendChild(starHolder);
1469  }
1470 
1471  //handle keyboard navigation value change
1472  function changeValue(val) {
1473  value = val;
1474  starChange(val);
1475  }
1476 
1477  //style cell
1478  element.style.whiteSpace = "nowrap";
1479  element.style.overflow = "hidden";
1480  element.style.textOverflow = "ellipsis";
1481 
1482  //style holding element
1483  starsHolder.style.verticalAlign = "middle";
1484  starsHolder.style.display = "inline-block";
1485  starsHolder.style.padding = "4px";
1486 
1487  //style star
1488  star.setAttribute("width", size);
1489  star.setAttribute("height", size);
1490  star.setAttribute("viewBox", "0 0 512 512");
1491  star.setAttribute("xml:space", "preserve");
1492  star.style.padding = "0 1px";
1493 
1494  if (editorParams.elementAttributes && _typeof(editorParams.elementAttributes) == "object") {
1495  for (var key in editorParams.elementAttributes) {
1496  if (key.charAt(0) == "+") {
1497  key = key.slice(1);
1498  starsHolder.setAttribute(key, starsHolder.getAttribute(key) + editorParams.elementAttributes["+" + key]);
1499  } else {
1500  starsHolder.setAttribute(key, editorParams.elementAttributes[key]);
1501  }
1502  }
1503  }
1504 
1505  //create correct number of stars
1506  for (var i = 1; i <= maxStars; i++) {
1507  buildStar(i);
1508  }
1509 
1510  //ensure value does not exceed number of stars
1511  value = Math.min(parseInt(value), maxStars);
1512 
1513  // set initial styling of stars
1514  starChange(value);
1515 
1516  starsHolder.addEventListener("mousemove", function (e) {
1517  starChange(0);
1518  });
1519 
1520  starsHolder.addEventListener("click", function (e) {
1521  success(0);
1522  });
1523 
1524  element.addEventListener("blur", function (e) {
1525  cancel();
1526  });
1527 
1528  //allow key based navigation
1529  element.addEventListener("keydown", function (e) {
1530  switch (e.keyCode) {
1531  case 39:
1532  //right arrow
1533  changeValue(value + 1);
1534  break;
1535 
1536  case 37:
1537  //left arrow
1538  changeValue(value - 1);
1539  break;
1540 
1541  case 13:
1542  //enter
1543  success(value);
1544  break;
1545 
1546  case 27:
1547  //escape
1548  cancel();
1549  break;
1550  }
1551  });
1552 
1553  return starsHolder;
1554  },
1555 
1556  //draggable progress bar
1557  progress: function progress(cell, onRendered, success, cancel, editorParams) {
1558  var element = cell.getElement(),
1559  max = typeof editorParams.max === "undefined" ? element.getElementsByTagName("div")[0].getAttribute("max") || 100 : editorParams.max,
1560  min = typeof editorParams.min === "undefined" ? element.getElementsByTagName("div")[0].getAttribute("min") || 0 : editorParams.min,
1561  percent = (max - min) / 100,
1562  value = cell.getValue() || 0,
1563  handle = document.createElement("div"),
1564  bar = document.createElement("div"),
1565  mouseDrag,
1566  mouseDragWidth;
1567 
1568  //set new value
1569  function updateValue() {
1570  var calcVal = percent * Math.round(bar.offsetWidth / (element.clientWidth / 100)) + min;
1571  success(calcVal);
1572  element.setAttribute("aria-valuenow", calcVal);
1573  element.setAttribute("aria-label", value);
1574  }
1575 
1576  //style handle
1577  handle.style.position = "absolute";
1578  handle.style.right = "0";
1579  handle.style.top = "0";
1580  handle.style.bottom = "0";
1581  handle.style.width = "5px";
1582  handle.classList.add("tabulator-progress-handle");
1583 
1584  //style bar
1585  bar.style.display = "inline-block";
1586  bar.style.position = "relative";
1587  // bar.style.top = "8px";
1588  // bar.style.bottom = "8px";
1589  // bar.style.left = "4px";
1590  // bar.style.marginRight = "4px";
1591  bar.style.height = "100%";
1592  bar.style.backgroundColor = "#488CE9";
1593  bar.style.maxWidth = "100%";
1594  bar.style.minWidth = "0%";
1595 
1596  if (editorParams.elementAttributes && _typeof(editorParams.elementAttributes) == "object") {
1597  for (var key in editorParams.elementAttributes) {
1598  if (key.charAt(0) == "+") {
1599  key = key.slice(1);
1600  bar.setAttribute(key, bar.getAttribute(key) + editorParams.elementAttributes["+" + key]);
1601  } else {
1602  bar.setAttribute(key, editorParams.elementAttributes[key]);
1603  }
1604  }
1605  }
1606 
1607  //style cell
1608  element.style.padding = "4px 4px";
1609 
1610  //make sure value is in range
1611  value = Math.min(parseFloat(value), max);
1612  value = Math.max(parseFloat(value), min);
1613 
1614  //workout percentage
1615  value = Math.round((value - min) / percent);
1616  // bar.style.right = value + "%";
1617  bar.style.width = value + "%";
1618 
1619  element.setAttribute("aria-valuemin", min);
1620  element.setAttribute("aria-valuemax", max);
1621 
1622  bar.appendChild(handle);
1623 
1624  handle.addEventListener("mousedown", function (e) {
1625  mouseDrag = e.screenX;
1626  mouseDragWidth = bar.offsetWidth;
1627  });
1628 
1629  handle.addEventListener("mouseover", function () {
1630  handle.style.cursor = "ew-resize";
1631  });
1632 
1633  element.addEventListener("mousemove", function (e) {
1634  if (mouseDrag) {
1635  bar.style.width = mouseDragWidth + e.screenX - mouseDrag + "px";
1636  }
1637  });
1638 
1639  element.addEventListener("mouseup", function (e) {
1640  if (mouseDrag) {
1641  e.stopPropagation();
1642  e.stopImmediatePropagation();
1643 
1644  mouseDrag = false;
1645  mouseDragWidth = false;
1646 
1647  updateValue();
1648  }
1649  });
1650 
1651  //allow key based navigation
1652  element.addEventListener("keydown", function (e) {
1653  switch (e.keyCode) {
1654  case 39:
1655  //right arrow
1656  bar.style.width = bar.clientWidth + element.clientWidth / 100 + "px";
1657  break;
1658 
1659  case 37:
1660  //left arrow
1661  bar.style.width = bar.clientWidth - element.clientWidth / 100 + "px";
1662  break;
1663 
1664  case 13:
1665  //enter
1666  updateValue();
1667  break;
1668 
1669  case 27:
1670  //escape
1671  cancel();
1672  break;
1673 
1674  }
1675  });
1676 
1677  element.addEventListener("blur", function () {
1678  cancel();
1679  });
1680 
1681  return bar;
1682  },
1683 
1684  //checkbox
1685  tickCross: function tickCross(cell, onRendered, success, cancel, editorParams) {
1686  var value = cell.getValue(),
1687  input = document.createElement("input"),
1688  tristate = editorParams.tristate,
1689  indetermValue = typeof editorParams.indeterminateValue === "undefined" ? null : editorParams.indeterminateValue,
1690  indetermState = false;
1691 
1692  input.setAttribute("type", "checkbox");
1693  input.style.marginTop = "5px";
1694  input.style.boxSizing = "border-box";
1695 
1696  if (editorParams.elementAttributes && _typeof(editorParams.elementAttributes) == "object") {
1697  for (var key in editorParams.elementAttributes) {
1698  if (key.charAt(0) == "+") {
1699  key = key.slice(1);
1700  input.setAttribute(key, input.getAttribute(key) + editorParams.elementAttributes["+" + key]);
1701  } else {
1702  input.setAttribute(key, editorParams.elementAttributes[key]);
1703  }
1704  }
1705  }
1706 
1707  input.value = value;
1708 
1709  if (tristate && (typeof value === "undefined" || value === indetermValue || value === "")) {
1710  indetermState = true;
1711  input.indeterminate = true;
1712  }
1713 
1714  if (this.table.browser != "firefox") {
1715  //prevent blur issue on mac firefox
1716  onRendered(function () {
1717  input.focus();
1718  });
1719  }
1720 
1721  input.checked = value === true || value === "true" || value === "True" || value === 1;
1722 
1723  function setValue(blur) {
1724  if (tristate) {
1725  if (!blur) {
1726  if (input.checked && !indetermState) {
1727  input.checked = false;
1728  input.indeterminate = true;
1729  indetermState = true;
1730  return indetermValue;
1731  } else {
1732  indetermState = false;
1733  return input.checked;
1734  }
1735  } else {
1736  if (indetermState) {
1737  return indetermValue;
1738  } else {
1739  return input.checked;
1740  }
1741  }
1742  } else {
1743  return input.checked;
1744  }
1745  }
1746 
1747  //submit new value on blur
1748  input.addEventListener("change", function (e) {
1749  success(setValue());
1750  });
1751 
1752  input.addEventListener("blur", function (e) {
1753  success(setValue(true));
1754  });
1755 
1756  //submit new value on enter
1757  input.addEventListener("keydown", function (e) {
1758  if (e.keyCode == 13) {
1759  success(setValue());
1760  }
1761  if (e.keyCode == 27) {
1762  cancel();
1763  }
1764  });
1765 
1766  return input;
1767  }
1768 };
1769 
1770 Tabulator.prototype.registerModule("edit", Edit);