otsdaq_utilities  v2_05_02_indev
clipboard.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 Clipboard = function Clipboard(table) {
6  this.table = table;
7  this.mode = true;
8  this.copySelector = false;
9  this.copySelectorParams = {};
10  this.copyFormatter = false;
11  this.copyFormatterParams = {};
12  this.pasteParser = function () {};
13  this.pasteAction = function () {};
14  this.htmlElement = false;
15  this.config = {};
16 
17  this.blocked = true; //block copy actions not originating from this command
18 };
19 
20 Clipboard.prototype.initialize = function () {
21  var self = this;
22 
23  this.mode = this.table.options.clipboard;
24 
25  if (this.mode === true || this.mode === "copy") {
26  this.table.element.addEventListener("copy", function (e) {
27  var data;
28 
29  self.processConfig();
30 
31  if (!self.blocked) {
32  e.preventDefault();
33 
34  data = self.generateContent();
35 
36  if (window.clipboardData && window.clipboardData.setData) {
37  window.clipboardData.setData('Text', data);
38  } else if (e.clipboardData && e.clipboardData.setData) {
39  e.clipboardData.setData('text/plain', data);
40  if (self.htmlElement) {
41  e.clipboardData.setData('text/html', self.htmlElement.outerHTML);
42  }
43  } else if (e.originalEvent && e.originalEvent.clipboardData.setData) {
44  e.originalEvent.clipboardData.setData('text/plain', data);
45  if (self.htmlElement) {
46  e.originalEvent.clipboardData.setData('text/html', self.htmlElement.outerHTML);
47  }
48  }
49 
50  self.table.options.clipboardCopied.call(this.table, data);
51 
52  self.reset();
53  }
54  });
55  }
56 
57  if (this.mode === true || this.mode === "paste") {
58  this.table.element.addEventListener("paste", function (e) {
59  self.paste(e);
60  });
61  }
62 
63  this.setPasteParser(this.table.options.clipboardPasteParser);
64  this.setPasteAction(this.table.options.clipboardPasteAction);
65 };
66 
67 Clipboard.prototype.processConfig = function () {
68  var config = {
69  columnHeaders: "groups",
70  rowGroups: true,
71  columnCalcs: true
72  };
73 
74  if (typeof this.table.options.clipboardCopyHeader !== "undefined") {
75  config.columnHeaders = this.table.options.clipboardCopyHeader;
76  console.warn("DEPRECATION WARNING - clipboardCopyHeader option has been deprecated, please use the columnHeaders property on the clipboardCopyConfig option");
77  }
78 
79  if (this.table.options.clipboardCopyConfig) {
80  for (var key in this.table.options.clipboardCopyConfig) {
81  config[key] = this.table.options.clipboardCopyConfig[key];
82  }
83  }
84 
85  if (config.rowGroups && this.table.options.groupBy && this.table.modExists("groupRows")) {
86  this.config.rowGroups = true;
87  }
88 
89  if (config.columnHeaders) {
90  if ((config.columnHeaders === "groups" || config === true) && this.table.columnManager.columns.length != this.table.columnManager.columnsByIndex.length) {
91  this.config.columnHeaders = "groups";
92  } else {
93  this.config.columnHeaders = "columns";
94  }
95  } else {
96  this.config.columnHeaders = false;
97  }
98 
99  if (config.columnCalcs && this.table.modExists("columnCalcs")) {
100  this.config.columnCalcs = true;
101  }
102 };
103 
104 Clipboard.prototype.reset = function () {
105  this.blocked = false;
106  this.originalSelectionText = "";
107 };
108 
109 Clipboard.prototype.setPasteAction = function (action) {
110 
111  switch (typeof action === "undefined" ? "undefined" : _typeof(action)) {
112  case "string":
113  this.pasteAction = this.pasteActions[action];
114 
115  if (!this.pasteAction) {
116  console.warn("Clipboard Error - No such paste action found:", action);
117  }
118  break;
119 
120  case "function":
121  this.pasteAction = action;
122  break;
123  }
124 };
125 
126 Clipboard.prototype.setPasteParser = function (parser) {
127  switch (typeof parser === "undefined" ? "undefined" : _typeof(parser)) {
128  case "string":
129  this.pasteParser = this.pasteParsers[parser];
130 
131  if (!this.pasteParser) {
132  console.warn("Clipboard Error - No such paste parser found:", parser);
133  }
134  break;
135 
136  case "function":
137  this.pasteParser = parser;
138  break;
139  }
140 };
141 
142 Clipboard.prototype.paste = function (e) {
143  var data, rowData, rows;
144 
145  if (this.checkPaseOrigin(e)) {
146 
147  data = this.getPasteData(e);
148 
149  rowData = this.pasteParser.call(this, data);
150 
151  if (rowData) {
152  e.preventDefault();
153 
154  if (this.table.modExists("mutator")) {
155  rowData = this.mutateData(rowData);
156  }
157 
158  rows = this.pasteAction.call(this, rowData);
159  this.table.options.clipboardPasted.call(this.table, data, rowData, rows);
160  } else {
161  this.table.options.clipboardPasteError.call(this.table, data);
162  }
163  }
164 };
165 
166 Clipboard.prototype.mutateData = function (data) {
167  var self = this,
168  output = [];
169 
170  if (Array.isArray(data)) {
171  data.forEach(function (row) {
172  output.push(self.table.modules.mutator.transformRow(row, "clipboard"));
173  });
174  } else {
175  output = data;
176  }
177 
178  return output;
179 };
180 
181 Clipboard.prototype.checkPaseOrigin = function (e) {
182  var valid = true;
183 
184  if (e.target.tagName != "DIV" || this.table.modules.edit.currentCell) {
185  valid = false;
186  }
187 
188  return valid;
189 };
190 
191 Clipboard.prototype.getPasteData = function (e) {
192  var data;
193 
194  if (window.clipboardData && window.clipboardData.getData) {
195  data = window.clipboardData.getData('Text');
196  } else if (e.clipboardData && e.clipboardData.getData) {
197  data = e.clipboardData.getData('text/plain');
198  } else if (e.originalEvent && e.originalEvent.clipboardData.getData) {
199  data = e.originalEvent.clipboardData.getData('text/plain');
200  }
201 
202  return data;
203 };
204 
205 Clipboard.prototype.copy = function (selector, selectorParams, formatter, formatterParams, internal) {
206  var range, sel, textRange;
207  this.blocked = false;
208 
209  if (this.mode === true || this.mode === "copy") {
210 
211  if (typeof window.getSelection != "undefined" && typeof document.createRange != "undefined") {
212  range = document.createRange();
213  range.selectNodeContents(this.table.element);
214  sel = window.getSelection();
215 
216  if (sel.toString() && internal) {
217  selector = "userSelection";
218  formatter = "raw";
219  selectorParams = sel.toString();
220  }
221 
222  sel.removeAllRanges();
223  sel.addRange(range);
224  } else if (typeof document.selection != "undefined" && typeof document.body.createTextRange != "undefined") {
225  textRange = document.body.createTextRange();
226  textRange.moveToElementText(this.table.element);
227  textRange.select();
228  }
229 
230  this.setSelector(selector);
231  this.copySelectorParams = typeof selectorParams != "undefined" && selectorParams != null ? selectorParams : this.config.columnHeaders;
232  this.setFormatter(formatter);
233  this.copyFormatterParams = typeof formatterParams != "undefined" && formatterParams != null ? formatterParams : {};
234 
235  document.execCommand('copy');
236 
237  if (sel) {
238  sel.removeAllRanges();
239  }
240  }
241 };
242 
243 Clipboard.prototype.setSelector = function (selector) {
244  selector = selector || this.table.options.clipboardCopySelector;
245 
246  switch (typeof selector === "undefined" ? "undefined" : _typeof(selector)) {
247  case "string":
248  if (this.copySelectors[selector]) {
249  this.copySelector = this.copySelectors[selector];
250  } else {
251  console.warn("Clipboard Error - No such selector found:", selector);
252  }
253  break;
254 
255  case "function":
256  this.copySelector = selector;
257  break;
258  }
259 };
260 
261 Clipboard.prototype.setFormatter = function (formatter) {
262 
263  formatter = formatter || this.table.options.clipboardCopyFormatter;
264 
265  switch (typeof formatter === "undefined" ? "undefined" : _typeof(formatter)) {
266  case "string":
267  if (this.copyFormatters[formatter]) {
268  this.copyFormatter = this.copyFormatters[formatter];
269  } else {
270  console.warn("Clipboard Error - No such formatter found:", formatter);
271  }
272  break;
273 
274  case "function":
275  this.copyFormatter = formatter;
276  break;
277  }
278 };
279 
280 Clipboard.prototype.generateContent = function () {
281  var data;
282 
283  this.htmlElement = false;
284  data = this.copySelector.call(this, this.config, this.copySelectorParams);
285 
286  return this.copyFormatter.call(this, data, this.config, this.copyFormatterParams);
287 };
288 
289 Clipboard.prototype.generateSimpleHeaders = function (columns) {
290  var headers = [];
291 
292  columns.forEach(function (column) {
293  headers.push(column.definition.title);
294  });
295 
296  return headers;
297 };
298 
299 Clipboard.prototype.generateColumnGroupHeaders = function (columns) {
300  var _this = this;
301 
302  var output = [];
303 
304  this.table.columnManager.columns.forEach(function (column) {
305  var colData = _this.processColumnGroup(column);
306 
307  if (colData) {
308  output.push(colData);
309  }
310  });
311 
312  return output;
313 };
314 
315 Clipboard.prototype.processColumnGroup = function (column) {
316  var _this2 = this;
317 
318  var subGroups = column.columns;
319 
320  var groupData = {
321  type: "group",
322  title: column.definition.title,
323  column: column
324  };
325 
326  if (subGroups.length) {
327  groupData.subGroups = [];
328  groupData.width = 0;
329 
330  subGroups.forEach(function (subGroup) {
331  var subGroupData = _this2.processColumnGroup(subGroup);
332 
333  if (subGroupData) {
334  groupData.width += subGroupData.width;
335  groupData.subGroups.push(subGroupData);
336  }
337  });
338 
339  if (!groupData.width) {
340  return false;
341  }
342  } else {
343  if (column.field && (column.definition.clipboard || column.visible && column.definition.clipboard !== false)) {
344  groupData.width = 1;
345  } else {
346  return false;
347  }
348  }
349 
350  return groupData;
351 };
352 
353 Clipboard.prototype.groupHeadersToRows = function (columns) {
354 
355  var headers = [];
356 
357  function parseColumnGroup(column, level) {
358 
359  if (typeof headers[level] === "undefined") {
360  headers[level] = [];
361  }
362 
363  headers[level].push(column.title);
364 
365  if (column.subGroups) {
366  column.subGroups.forEach(function (subGroup) {
367  parseColumnGroup(subGroup, level + 1);
368  });
369  } else {
370  padColumnheaders();
371  }
372  }
373 
374  function padColumnheaders() {
375  var max = 0;
376 
377  headers.forEach(function (title) {
378  var len = title.length;
379  if (len > max) {
380  max = len;
381  }
382  });
383 
384  headers.forEach(function (title) {
385  var len = title.length;
386  if (len < max) {
387  for (var i = len; i < max; i++) {
388  title.push("");
389  }
390  }
391  });
392  }
393 
394  columns.forEach(function (column) {
395  parseColumnGroup(column, 0);
396  });
397 
398  return headers;
399 };
400 
401 Clipboard.prototype.rowsToData = function (rows, columns, config, params) {
402  var data = [];
403 
404  rows.forEach(function (row) {
405  var rowArray = [],
406  rowData = row instanceof RowComponent ? row.getData("clipboard") : row;
407 
408  columns.forEach(function (column) {
409  var value = column.getFieldValue(rowData);
410 
411  switch (typeof value === "undefined" ? "undefined" : _typeof(value)) {
412  case "object":
413  value = JSON.stringify(value);
414  break;
415 
416  case "undefined":
417  case "null":
418  value = "";
419  break;
420 
421  default:
422  value = value;
423  }
424 
425  rowArray.push(value);
426  });
427 
428  data.push(rowArray);
429  });
430 
431  return data;
432 };
433 
434 Clipboard.prototype.buildComplexRows = function (config) {
435  var _this3 = this;
436 
437  var output = [],
438  groups = this.table.modules.groupRows.getGroups();
439 
440  groups.forEach(function (group) {
441  output.push(_this3.processGroupData(group));
442  });
443 
444  return output;
445 };
446 
447 Clipboard.prototype.processGroupData = function (group) {
448  var _this4 = this;
449 
450  var subGroups = group.getSubGroups();
451 
452  var groupData = {
453  type: "group",
454  key: group.key
455  };
456 
457  if (subGroups.length) {
458  groupData.subGroups = [];
459 
460  subGroups.forEach(function (subGroup) {
461  groupData.subGroups.push(_this4.processGroupData(subGroup));
462  });
463  } else {
464  groupData.rows = group.getRows(true);
465  }
466 
467  return groupData;
468 };
469 
470 Clipboard.prototype.getCalcRow = function (calcs, columns, selector, pos) {
471  var calcData = calcs[selector];
472 
473  if (calcData) {
474  if (pos) {
475  calcData = calcData[pos];
476  }
477 
478  if (Object.keys(calcData).length) {
479  return this.rowsToData([calcData], columns);
480  }
481  }
482 
483  return [];
484 };
485 
486 Clipboard.prototype.buildOutput = function (rows, config, params) {
487  var _this5 = this;
488 
489  var output = [],
490  calcs,
491  columns = [],
492  columnsByIndex = [];
493 
494  this.table.columnManager.columnsByIndex.forEach(function (column) {
495  if (column.definition.clipboard || column.visible && column.definition.clipboard !== false) {
496  columnsByIndex.push(column);
497  }
498  });
499 
500  if (config.columnHeaders == "groups") {
501  columns = this.generateColumnGroupHeaders(this.table.columnManager.columns);
502  output = output.concat(this.groupHeadersToRows(columns));
503  } else {
504  columns = columnsByIndex;
505 
506  output.push(this.generateSimpleHeaders(columns));
507  }
508 
509  if (this.config.columnCalcs) {
510  calcs = this.table.getCalcResults();
511  }
512 
513  //generate styled content
514  if (this.table.options.clipboardCopyStyled) {
515  this.generateHTML(rows, columns, calcs, config, params);
516  }
517 
518  //generate unstyled content
519  if (config.rowGroups) {
520  rows.forEach(function (row) {
521  output = output.concat(_this5.parseRowGroupData(row, columnsByIndex, config, params, calcs || {}));
522  });
523  } else {
524  if (config.columnCalcs) {
525  output = output.concat(this.getCalcRow(calcs, columnsByIndex, "top"));
526  }
527 
528  output = output.concat(this.rowsToData(rows, columnsByIndex, config, params));
529 
530  if (config.columnCalcs) {
531  output = output.concat(this.getCalcRow(calcs, columnsByIndex, "bottom"));
532  }
533  }
534 
535  return output;
536 };
537 
538 Clipboard.prototype.parseRowGroupData = function (group, columns, config, params, calcObj) {
539  var _this6 = this;
540 
541  var groupData = [];
542 
543  groupData.push([group.key]);
544 
545  if (group.subGroups) {
546  group.subGroups.forEach(function (subGroup) {
547  groupData = groupData.concat(_this6.parseRowGroupData(subGroup, config, params, calcObj[group.key] ? calcObj[group.key].groups || {} : {}));
548  });
549  } else {
550  if (config.columnCalcs) {
551  groupData = groupData.concat(this.getCalcRow(calcObj, columns, group.key, "top"));
552  }
553 
554  groupData = groupData.concat(this.rowsToData(group.rows, columns, config, params));
555 
556  if (config.columnCalcs) {
557  groupData = groupData.concat(this.getCalcRow(calcObj, columns, group.key, "bottom"));
558  }
559  }
560 
561  return groupData;
562 };
563 
564 Clipboard.prototype.generateHTML = function (rows, columns, calcs, config, params) {
565  var self = this,
566  data = [],
567  headers = [],
568  body,
569  oddRow,
570  evenRow,
571  calcRow,
572  firstRow,
573  firstCell,
574  firstGroup,
575  lastCell,
576  styleCells;
577 
578  //create table element
579  this.htmlElement = document.createElement("table");
580  self.mapElementStyles(this.table.element, this.htmlElement, ["border-top", "border-left", "border-right", "border-bottom"]);
581 
582  function generateSimpleHeaders() {
583  var headerEl = document.createElement("tr");
584 
585  columns.forEach(function (column) {
586  var columnEl = document.createElement("th");
587  columnEl.innerHTML = column.definition.title;
588 
589  self.mapElementStyles(column.getElement(), columnEl, ["border-top", "border-left", "border-right", "border-bottom", "background-color", "color", "font-weight", "font-family", "font-size"]);
590 
591  headerEl.appendChild(columnEl);
592  });
593 
594  self.mapElementStyles(self.table.columnManager.getHeadersElement(), headerEl, ["border-top", "border-left", "border-right", "border-bottom", "background-color", "color", "font-weight", "font-family", "font-size"]);
595 
596  self.htmlElement.appendChild(document.createElement("thead").appendChild(headerEl));
597  }
598 
599  function generateHeaders(headers) {
600 
601  var headerHolderEl = document.createElement("thead");
602 
603  headers.forEach(function (columns) {
604  var headerEl = document.createElement("tr");
605 
606  columns.forEach(function (column) {
607  var columnEl = document.createElement("th");
608 
609  if (column.width > 1) {
610  columnEl.colSpan = column.width;
611  }
612 
613  if (column.height > 1) {
614  columnEl.rowSpan = column.height;
615  }
616 
617  columnEl.innerHTML = column.title;
618 
619  self.mapElementStyles(column.element, columnEl, ["border-top", "border-left", "border-right", "border-bottom", "background-color", "color", "font-weight", "font-family", "font-size"]);
620 
621  headerEl.appendChild(columnEl);
622  });
623 
624  self.mapElementStyles(self.table.columnManager.getHeadersElement(), headerEl, ["border-top", "border-left", "border-right", "border-bottom", "background-color", "color", "font-weight", "font-family", "font-size"]);
625 
626  headerHolderEl.appendChild(headerEl);
627  });
628 
629  self.htmlElement.appendChild(headerHolderEl);
630  }
631 
632  function parseColumnGroup(column, level) {
633 
634  var actualColumns = [];
635 
636  if (typeof headers[level] === "undefined") {
637  headers[level] = [];
638  }
639 
640  headers[level].push({
641  title: column.title,
642  width: column.width,
643  height: 1,
644  children: !!column.subGroups,
645  element: column.column.getElement()
646  });
647 
648  if (column.subGroups) {
649  column.subGroups.forEach(function (subGroup) {
650  actualColumns = actualColumns.concat(parseColumnGroup(subGroup, level + 1));
651  });
652 
653  return actualColumns;
654  } else {
655  return [column.column];
656  }
657  }
658 
659  function padVerticalColumnheaders() {
660  headers.forEach(function (row, index) {
661  row.forEach(function (header) {
662  if (!header.children) {
663  header.height = headers.length - index;
664  }
665  });
666  });
667  }
668 
669  function addCalcRow(calcs, selector, pos) {
670  var calcData = calcs[selector];
671 
672  if (calcData) {
673  if (pos) {
674  calcData = calcData[pos];
675  }
676 
677  if (Object.keys(calcData).length) {
678  // calcRowIndexs.push(body.length);
679  processRows([calcData]);
680  }
681  }
682  }
683 
684  //create headers if needed
685  if (config.columnHeaders) {
686  if (config.columnHeaders == "groups") {
687 
688  var actualColumns = [];
689 
690  columns.forEach(function (column) {
691  actualColumns = actualColumns.concat(parseColumnGroup(column, 0));
692  });
693 
694  columns = actualColumns;
695 
696  padVerticalColumnheaders();
697  generateHeaders(headers);
698  } else {
699  generateSimpleHeaders();
700  }
701  }
702 
703  // columns = this.table.columnManager.columnsByIndex;
704 
705  //create table body
706  body = document.createElement("tbody");
707 
708  //lookup row styles
709  if (window.getComputedStyle) {
710  oddRow = this.table.element.querySelector(".tabulator-row-odd:not(.tabulator-group):not(.tabulator-calcs)");
711  evenRow = this.table.element.querySelector(".tabulator-row-even:not(.tabulator-group):not(.tabulator-calcs)");
712  calcRow = this.table.element.querySelector(".tabulator-row.tabulator-calcs");
713  firstRow = this.table.element.querySelector(".tabulator-row:not(.tabulator-group):not(.tabulator-calcs)");
714  firstGroup = this.table.element.getElementsByClassName("tabulator-group")[0];
715 
716  if (firstRow) {
717  styleCells = firstRow.getElementsByClassName("tabulator-cell");
718  firstCell = styleCells[0];
719  lastCell = styleCells[styleCells.length - 1];
720  }
721  }
722 
723  function processRows(rowArray) {
724  //add rows to table
725  rowArray.forEach(function (row, i) {
726  var rowEl = document.createElement("tr"),
727  styleRow = firstRow,
728  isCalc = false,
729  rowData;
730 
731  if (row instanceof RowComponent) {
732  rowData = row.getData("clipboard");
733  } else {
734  rowData = row;
735  isCalc = true;
736  }
737 
738  columns.forEach(function (column, j) {
739  var cellEl = document.createElement("td"),
740  value = column.getFieldValue(rowData);
741 
742  switch (typeof value === "undefined" ? "undefined" : _typeof(value)) {
743  case "object":
744  value = JSON.stringify(value);
745  break;
746 
747  case "undefined":
748  case "null":
749  value = "";
750  break;
751 
752  default:
753  value = value;
754  }
755 
756  cellEl.innerHTML = value;
757 
758  if (column.definition.align) {
759  cellEl.style.textAlign = column.definition.align;
760  }
761 
762  if (j < columns.length - 1) {
763  if (firstCell) {
764  self.mapElementStyles(firstCell, cellEl, ["border-top", "border-left", "border-right", "border-bottom", "color", "font-weight", "font-family", "font-size"]);
765  }
766  } else {
767  if (firstCell) {
768  self.mapElementStyles(firstCell, cellEl, ["border-top", "border-left", "border-right", "border-bottom", "color", "font-weight", "font-family", "font-size"]);
769  }
770  }
771 
772  rowEl.appendChild(cellEl);
773  });
774 
775  if (isCalc) {
776  styleRow = calcRow;
777  } else {
778  if (!(i % 2) && oddRow) {
779  styleRow = oddRow;
780  }
781 
782  if (i % 2 && evenRow) {
783  styleRow = evenRow;
784  }
785  }
786 
787  if (styleRow) {
788  self.mapElementStyles(styleRow, rowEl, ["border-top", "border-left", "border-right", "border-bottom", "color", "font-weight", "font-family", "font-size", "background-color"]);
789  }
790 
791  body.appendChild(rowEl);
792  });
793  }
794 
795  function processGroup(group, calcObj) {
796  var groupEl = document.createElement("tr"),
797  groupCellEl = document.createElement("td");
798 
799  groupCellEl.colSpan = columns.length;
800 
801  groupCellEl.innerHTML = group.key;
802 
803  groupEl.appendChild(groupCellEl);
804  body.appendChild(groupEl);
805 
806  self.mapElementStyles(firstGroup, groupEl, ["border-top", "border-left", "border-right", "border-bottom", "color", "font-weight", "font-family", "font-size", "background-color"]);
807 
808  if (group.subGroups) {
809  group.subGroups.forEach(function (subGroup) {
810  processGroup(subGroup, calcObj[group.key] ? calcObj[group.key].groups || {} : {});
811  });
812  } else {
813  if (config.columnCalcs) {
814  addCalcRow(calcObj, group.key, "top");
815  }
816 
817  processRows(group.rows);
818 
819  if (config.columnCalcs) {
820  addCalcRow(calcObj, group.key, "bottom");
821  }
822  }
823  }
824 
825  if (config.rowGroups) {
826  rows.forEach(function (group) {
827  processGroup(group, calcs || {});
828  });
829  } else {
830  if (config.columnCalcs) {
831  addCalcRow(calcs, "top");
832  }
833 
834  processRows(rows);
835 
836  if (config.columnCalcs) {
837  addCalcRow(calcs, "bottom");
838  }
839  }
840 
841  this.htmlElement.appendChild(body);
842 };
843 
844 Clipboard.prototype.mapElementStyles = function (from, to, props) {
845 
846  var lookup = {
847  "background-color": "backgroundColor",
848  "color": "fontColor",
849  "font-weight": "fontWeight",
850  "font-family": "fontFamily",
851  "font-size": "fontSize",
852  "border-top": "borderTop",
853  "border-left": "borderLeft",
854  "border-right": "borderRight",
855  "border-bottom": "borderBottom"
856  };
857 
858  if (window.getComputedStyle) {
859  var fromStyle = window.getComputedStyle(from);
860 
861  props.forEach(function (prop) {
862  to.style[lookup[prop]] = fromStyle.getPropertyValue(prop);
863  });
864  }
865 
866  // return window.getComputedStyle ? window.getComputedStyle(element, null).getPropertyValue(property) : element.style[property.replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); })];
867 };
868 
869 Clipboard.prototype.copySelectors = {
870  userSelection: function userSelection(config, params) {
871  return params;
872  },
873  selected: function selected(config, params) {
874  var rows = [];
875 
876  if (this.table.modExists("selectRow", true)) {
877  rows = this.table.modules.selectRow.getSelectedRows();
878  }
879 
880  if (config.rowGroups) {
881  console.warn("Clipboard Warning - select coptSelector does not support row groups");
882  }
883 
884  return this.buildOutput(rows, config, params);
885  },
886  table: function table(config, params) {
887  if (config.rowGroups) {
888  console.warn("Clipboard Warning - table coptSelector does not support row groups");
889  }
890 
891  return this.buildOutput(this.table.rowManager.getComponents(), config, params);
892  },
893  active: function active(config, params) {
894  var rows;
895 
896  if (config.rowGroups) {
897  rows = this.buildComplexRows(config);
898  } else {
899  rows = this.table.rowManager.getComponents("active");
900  }
901 
902  return this.buildOutput(rows, config, params);
903  },
904  visible: function visible(config, params) {
905  var rows;
906 
907  if (config.rowGroups) {
908  rows = this.buildComplexRows(config);
909  } else {
910  rows = this.table.rowManager.getComponents("visible");
911  }
912 
913  return this.buildOutput(rows, config, params);
914  }
915 };
916 
917 Clipboard.prototype.copyFormatters = {
918  raw: function raw(data, params) {
919  return data;
920  },
921  table: function table(data, params) {
922  var output = [];
923 
924  data.forEach(function (row) {
925  var newRow = [];
926  row.forEach(function (value) {
927  if (typeof value == "undefined") {
928  value = "";
929  }
930 
931  value = typeof value == "undefined" || value === null ? "" : value.toString();
932 
933  if (value.match(/\r|\n/)) {
934  value = value.split('"').join('""');
935  value = '"' + value + '"';
936  }
937  newRow.push(value);
938  });
939 
940  output.push(newRow.join("\t"));
941  });
942 
943  return output.join("\n");
944  }
945 };
946 
947 Clipboard.prototype.pasteParsers = {
948  table: function table(clipboard) {
949  var data = [],
950  success = false,
951  headerFindSuccess = true,
952  columns = this.table.columnManager.columns,
953  columnMap = [],
954  rows = [];
955 
956  //get data from clipboard into array of columns and rows.
957  clipboard = clipboard.split("\n");
958 
959  clipboard.forEach(function (row) {
960  data.push(row.split("\t"));
961  });
962 
963  if (data.length && !(data.length === 1 && data[0].length < 2)) {
964  success = true;
965 
966  //check if headers are present by title
967  data[0].forEach(function (value) {
968  var column = columns.find(function (column) {
969  return value && column.definition.title && value.trim() && column.definition.title.trim() === value.trim();
970  });
971 
972  if (column) {
973  columnMap.push(column);
974  } else {
975  headerFindSuccess = false;
976  }
977  });
978 
979  //check if column headers are present by field
980  if (!headerFindSuccess) {
981  headerFindSuccess = true;
982  columnMap = [];
983 
984  data[0].forEach(function (value) {
985  var column = columns.find(function (column) {
986  return value && column.field && value.trim() && column.field.trim() === value.trim();
987  });
988 
989  if (column) {
990  columnMap.push(column);
991  } else {
992  headerFindSuccess = false;
993  }
994  });
995 
996  if (!headerFindSuccess) {
997  columnMap = this.table.columnManager.columnsByIndex;
998  }
999  }
1000 
1001  //remove header row if found
1002  if (headerFindSuccess) {
1003  data.shift();
1004  }
1005 
1006  data.forEach(function (item) {
1007  var row = {};
1008 
1009  item.forEach(function (value, i) {
1010  if (columnMap[i]) {
1011  row[columnMap[i].field] = value;
1012  }
1013  });
1014 
1015  rows.push(row);
1016  });
1017 
1018  return rows;
1019  } else {
1020  return false;
1021  }
1022  }
1023 };
1024 
1025 Clipboard.prototype.pasteActions = {
1026  replace: function replace(rows) {
1027  return this.table.setData(rows);
1028  },
1029  update: function update(rows) {
1030  return this.table.updateOrAddData(rows);
1031  },
1032  insert: function insert(rows) {
1033  return this.table.addData(rows);
1034  }
1035 };
1036 
1037 Tabulator.prototype.registerModule("clipboard", Clipboard);