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; };
5 var HtmlTableImport =
function HtmlTableImport(table) {
11 HtmlTableImport.prototype.parseTable =
function () {
13 element =
self.table.element,
14 options =
self.table.options,
15 columns = options.columns,
16 headers = element.getElementsByTagName(
"th"),
17 rows = element.getElementsByTagName(
"tbody")[0],
21 self.hasIndex =
false;
23 self.table.options.htmlImporting.call(this.table);
25 rows = rows ? rows.getElementsByTagName(
"tr") : [];
28 self._extractOptions(element, options);
31 self._extractHeaders(headers, rows);
33 self._generateBlankHeaders(headers, rows);
37 for (var index = 0; index < rows.length; index++) {
38 var row = rows[index],
39 cells = row.getElementsByTagName(
"td"),
44 item[options.index] = index;
47 for (var i = 0; i < cells.length; i++) {
49 if (typeof this.fieldIndex[i] !==
"undefined") {
50 item[this.fieldIndex[i]] = cell.innerHTML;
59 var newElement = document.createElement(
"div");
62 var attributes = element.attributes;
66 for (var i in attributes) {
67 if (_typeof(attributes[i]) ==
"object") {
68 newElement.setAttribute(attributes[i].name, attributes[i].value);
73 element.parentNode.replaceChild(newElement, element);
77 self.table.options.htmlImported.call(this.table);
81 this.table.element = newElement;
85 HtmlTableImport.prototype._extractOptions =
function (element, options, defaultOptions) {
86 var attributes = element.attributes;
87 var optionsArr = defaultOptions ? Object.assign([], defaultOptions) : Object.keys(options);
90 optionsArr.forEach(
function (item) {
91 optionsList[item.toLowerCase()] = item;
94 for (var index in attributes) {
95 var attrib = attributes[index];
98 if (attrib && (typeof attrib ===
"undefined" ?
"undefined" : _typeof(attrib)) ==
"object" && attrib.name && attrib.name.indexOf(
"tabulator-") === 0) {
99 name = attrib.name.replace(
"tabulator-",
"");
101 if (typeof optionsList[name] !==
"undefined") {
102 options[optionsList[name]] = this._attribValue(attrib.value);
109 HtmlTableImport.prototype._attribValue =
function (value) {
110 if (value ===
"true") {
114 if (value ===
"false") {
122 HtmlTableImport.prototype._findCol =
function (title) {
123 var match = this.table.options.columns.find(
function (column) {
124 return column.title === title;
127 return match ||
false;
131 HtmlTableImport.prototype._extractHeaders =
function (headers, rows) {
132 for (var index = 0; index < headers.length; index++) {
133 var header = headers[index],
135 col = this._findCol(header.textContent),
142 col = { title: header.textContent.trim() };
146 col.field = header.textContent.trim().toLowerCase().replace(
" ",
"_");
149 width = header.getAttribute(
"width");
151 if (width && !col.width) {
156 attributes = header.attributes;
159 this._extractOptions(header, col, Column.prototype.defaultOptionList);
161 for (var i in attributes) {
162 var attrib = attributes[i],
165 if (attrib && (typeof attrib ===
"undefined" ?
"undefined" : _typeof(attrib)) ==
"object" && attrib.name && attrib.name.indexOf(
"tabulator-") === 0) {
167 name = attrib.name.replace(
"tabulator-",
"");
169 col[name] = this._attribValue(attrib.value);
173 this.fieldIndex[index] = col.field;
175 if (col.field ==
this.table.options.index) {
176 this.hasIndex =
true;
180 this.table.options.columns.push(col);
186 HtmlTableImport.prototype._generateBlankHeaders =
function (headers, rows) {
187 for (var index = 0; index < headers.length; index++) {
188 var header = headers[index],
189 col = { title:
"", field:
"col" + index };
191 this.fieldIndex[index] = col.field;
193 var width = header.getAttribute(
"width");
199 this.table.options.columns.push(col);
203 Tabulator.prototype.registerModule(
"htmlTableImport", HtmlTableImport);