Skip to content
This repository has been archived by the owner on Jul 25, 2021. It is now read-only.

Commit

Permalink
v5.0.0-rc.3 - fix handle{Row,Col}Span ordering and terminating condit…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
clarketm committed Jun 2, 2017
1 parent ff3dd50 commit aece6ca
Show file tree
Hide file tree
Showing 15 changed files with 88 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/assets
/index.html
/search
/test
test
/module
/docs/_book
rollup.config.js
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# [TableExport](https://tableexport.v4.travismclarke.com)   [![Build Status](https://travis-ci.org/clarketm/TableExport.svg?branch=master)](https://travis-ci.org/clarketm/TableExport)
[![Build Status](https://travis-ci.org/clarketm/TableExport.svg?branch=master)](https://travis-ci.org/clarketm/TableExport)

# [TableExport](https://tableexport.v4.travismclarke.com)
The simple, easy-to-implement library to export HTML tables to `xlsx`, `xls`, `csv`, and `txt` files.

## Docs
Expand Down Expand Up @@ -328,6 +330,7 @@ When used alongside Bootstrap, there are four custom classes **`.xlsx`, `.xls`,
- [x] Reimplement and test the `update`, `reset`, and `remove` **TableExport** prototype properties without requiring jQuery.
- [x] Make jQuery as *peer dependency* and ensure proper **TableExport** rendering in browser, AMD, and CommonJS environments.
- [x] Force jQuery to be an optionally loaded module.
- [ ] Use the enhanced [SheetJS](https://github.com/SheetJS/js-xlsx#supported-output-formats) `csv` and `txt` formats when the library is available.
- [ ] Allow `ignoreCSS` and `emptyCSS` to work with any `selector|selector[]` instead of solely a single CSS class.
- [ ] Ensure (via testing) full consistency and backwards-compatibility for jQuery.
- [ ] Add **Export as PDF** support.
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tableexport.js",
"version": "5.0.0-rc.2",
"version": "5.0.0-rc.3",
"authors": [
"clarketm <[email protected]>"
],
Expand Down
2 changes: 1 addition & 1 deletion dist/css/tableexport.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* TableExport.js v5.0.0-rc.2 (https://www.travismclarke.com)
* TableExport.js v5.0.0-rc.3 (https://www.travismclarke.com)
*
* Copyright (c) 2017 - Travis Clarke - https://www.travismclarke.com
*
Expand Down
2 changes: 1 addition & 1 deletion dist/css/tableexport.min.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* TableExport.js v5.0.0-rc.2 (https://www.travismclarke.com)
* TableExport.js v5.0.0-rc.3 (https://www.travismclarke.com)
*
* Copyright (c) 2017 - Travis Clarke - https://www.travismclarke.com
*
Expand Down
54 changes: 33 additions & 21 deletions dist/js/tableexport.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* TableExport.js v5.0.0-rc.2 (https://www.travismclarke.com)
* TableExport.js v5.0.0-rc.3 (https://www.travismclarke.com)
*
* Copyright (c) 2017 - Travis Clarke - https://www.travismclarke.com
*
Expand Down Expand Up @@ -106,7 +106,7 @@
};
})();

context.rcMap = new RowColMap().build.call(self, context);
context.rcMap = new RowColMap().build(context, settings);

var formatMap = {};
for (var type in _FORMAT) {
Expand Down Expand Up @@ -142,7 +142,7 @@
* Version.
* @memberof TableExport.prototype
*/
version: '5.0.0-rc.2',
version: '5.0.0-rc.3',
/**
* Default library options.
* @memberof TableExport.prototype
Expand Down Expand Up @@ -811,13 +811,15 @@
};
this.getRowColMapProp = function (ir, ic, key) {
if (this.rcMap[ir]) {
if (typeof ic === 'undefined') {
if (typeof key === 'undefined') {
return this.rcMap[ir][ic];
} else if (typeof ic === 'undefined') {
return this.rcMap[ir][key];
} else if (this.rcMap[ir][ic]) {
return this.rcMap[ir][ic][key];
}
}
return false;
return undefined;
};
this.setRowColMapProp = function (ir, ic, key, value) {
this.rcMap[ir] = this.rcMap[ir] || [];
Expand Down Expand Up @@ -880,38 +882,48 @@
SPAN: 'span',
DEFAULT: 'default'
},
build: function (context) {
build: function (context, settings) {
var self = this;
var settings = self.settings;

var OFFSET = 1;

var _RowColMap = new RowColMap();
var OFFSET = self.OFFSET;
var rowLength = self.rowLength = context.rows.length;
// var colLength = self.colLength = Math.max.apply(null,
// _nodesArray(context.rows).map(function (val) {
// return val.querySelectorAll('th, td').length
// }));

var handleIgnoreRow = function (ir) {
_RowColMap.setRowColMapProp(ir, undefined, _RowColMap.TYPE.IGNORE, true);

self.setRowColMapProp(ir, undefined, self.TYPE.IGNORE, true);
};
var handleIgnoreCol = function (ir, ic) {
_RowColMap.setRowColMapProp(ir, ic, _RowColMap.TYPE.IGNORE, true);
self.setRowColMapProp(ir, ic, self.TYPE.IGNORE, true);
};
var handleEmpty = function (ir, ic) {
_RowColMap.setRowColMapProp(ir, ic, _RowColMap.TYPE.EMPTY, true);
self.setRowColMapProp(ir, ic, self.TYPE.EMPTY, true);
};
var handleRowSpan = function (val, ir, ic) {
var rowSpan = val.getAttribute('rowspan');
var hasColSpan = val.hasAttribute('colspan');
hasColSpan && handleColSpan(val, ir, ic);
for (var _row = 1; _row < rowSpan; _row++) {
_RowColMap.setRowColMapProp(_row + ir, undefined, _RowColMap.TYPE.SPAN, true);
_RowColMap.setRowColMapProp(_row + ir, ic, undefined, 1);

for (var _row = 0; _row < rowSpan; _row++) {
if (_row + ir >= rowLength) {
return;
}
hasColSpan && handleColSpan(val, _row + ir, ic);
if (_row >= 1) {
self.setRowColMapProp(_row + ir, undefined, self.TYPE.SPAN, true);
self.setRowColMapProp(_row + ir, ic, undefined, 1);
}
}
};
var handleColSpan = function (val, ir, ic) {
var colSpan = val.getAttribute('colspan');
_RowColMap.setRowColMapProp(ir, undefined, _RowColMap.TYPE.SPAN, true);
_RowColMap.setRowColMapProp(ir, ic + OFFSET, undefined, colSpan - OFFSET);

if (colSpan <= 1) {
return;
}
self.setRowColMapProp(ir, undefined, self.TYPE.SPAN, true);
self.setRowColMapProp(ir, ic + OFFSET, undefined, colSpan - OFFSET);
};

_nodesArray(context.rows).map(function (val, ir) {
Expand All @@ -934,7 +946,7 @@
});
});

return _RowColMap;
return self;
}
};

Expand Down
4 changes: 2 additions & 2 deletions dist/js/tableexport.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/tableexport.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Type definitions for TableExport v5.0.0-rc.2
// Type definitions for TableExport v5.0.0-rc.3
// Project: https://tableexport.v4.travismclarke.com
// Definitions by: Travis Clarke <https://github.com/clarketm>

/*!
* TableExport.js v5.0.0-rc.2 (https://www.travismclarke.com)
* TableExport.js v5.0.0-rc.3 (https://www.travismclarke.com)
*
* Copyright (c) 2017 - Travis Clarke - https://www.travismclarke.com
*
Expand Down
5 changes: 4 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# [TableExport](https://tableexport.v4.travismclarke.com) &nbsp; [![Build Status](https://travis-ci.org/clarketm/TableExport.svg?branch=master)](https://travis-ci.org/clarketm/TableExport)
[![Build Status](https://travis-ci.org/clarketm/TableExport.svg?branch=master)](https://travis-ci.org/clarketm/TableExport)

# [TableExport](https://tableexport.v4.travismclarke.com)
The simple, easy-to-implement library to export HTML tables to `xlsx`, `xls`, `csv`, and `txt` files.

## Docs
Expand Down Expand Up @@ -328,6 +330,7 @@ When used alongside Bootstrap, there are four custom classes **`.xlsx`, `.xls`,
- [x] Reimplement and test the `update`, `reset`, and `remove` **TableExport** prototype properties without requiring jQuery.
- [x] Make jQuery as *peer dependency* and ensure proper **TableExport** rendering in browser, AMD, and CommonJS environments.
- [x] Force jQuery to be an optionally loaded module.
- [ ] Use the enhanced [SheetJS](https://github.com/SheetJS/js-xlsx#supported-output-formats) `csv` and `txt` formats when the library is available.
- [ ] Allow `ignoreCSS` and `emptyCSS` to work with any `selector|selector[]` instead of solely a single CSS class.
- [ ] Ensure (via testing) full consistency and backwards-compatibility for jQuery.
- [ ] Add **Export as PDF** support.
Expand Down
2 changes: 1 addition & 1 deletion gitbook
Submodule gitbook updated from 08c78f to 783ac8
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tableexport",
"version": "5.0.0-rc.2",
"version": "5.0.0-rc.3",
"authors": [
"clarketm <[email protected]>"
],
Expand Down
2 changes: 1 addition & 1 deletion src/stable/css/tableexport.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* TableExport.js v5.0.0-rc.2 (https://www.travismclarke.com)
* TableExport.js v5.0.0-rc.3 (https://www.travismclarke.com)
*
* Copyright (c) 2017 - Travis Clarke - https://www.travismclarke.com
*
Expand Down
2 changes: 1 addition & 1 deletion src/stable/css/tableexport.min.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* TableExport.js v5.0.0-rc.2 (https://www.travismclarke.com)
* TableExport.js v5.0.0-rc.3 (https://www.travismclarke.com)
*
* Copyright (c) 2017 - Travis Clarke - https://www.travismclarke.com
*
Expand Down
54 changes: 33 additions & 21 deletions src/stable/js/tableexport.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* TableExport.js v5.0.0-rc.2 (https://www.travismclarke.com)
* TableExport.js v5.0.0-rc.3 (https://www.travismclarke.com)
*
* Copyright (c) 2017 - Travis Clarke - https://www.travismclarke.com
*
Expand Down Expand Up @@ -106,7 +106,7 @@
};
})();

context.rcMap = new RowColMap().build.call(self, context);
context.rcMap = new RowColMap().build(context, settings);

var formatMap = {};
for (var type in _FORMAT) {
Expand Down Expand Up @@ -142,7 +142,7 @@
* Version.
* @memberof TableExport.prototype
*/
version: '5.0.0-rc.2',
version: '5.0.0-rc.3',
/**
* Default library options.
* @memberof TableExport.prototype
Expand Down Expand Up @@ -811,13 +811,15 @@
};
this.getRowColMapProp = function (ir, ic, key) {
if (this.rcMap[ir]) {
if (typeof ic === 'undefined') {
if (typeof key === 'undefined') {
return this.rcMap[ir][ic];
} else if (typeof ic === 'undefined') {
return this.rcMap[ir][key];
} else if (this.rcMap[ir][ic]) {
return this.rcMap[ir][ic][key];
}
}
return false;
return undefined;
};
this.setRowColMapProp = function (ir, ic, key, value) {
this.rcMap[ir] = this.rcMap[ir] || [];
Expand Down Expand Up @@ -880,38 +882,48 @@
SPAN: 'span',
DEFAULT: 'default'
},
build: function (context) {
build: function (context, settings) {
var self = this;
var settings = self.settings;

var OFFSET = 1;

var _RowColMap = new RowColMap();
var OFFSET = self.OFFSET;
var rowLength = self.rowLength = context.rows.length;
// var colLength = self.colLength = Math.max.apply(null,
// _nodesArray(context.rows).map(function (val) {
// return val.querySelectorAll('th, td').length
// }));

var handleIgnoreRow = function (ir) {
_RowColMap.setRowColMapProp(ir, undefined, _RowColMap.TYPE.IGNORE, true);

self.setRowColMapProp(ir, undefined, self.TYPE.IGNORE, true);
};
var handleIgnoreCol = function (ir, ic) {
_RowColMap.setRowColMapProp(ir, ic, _RowColMap.TYPE.IGNORE, true);
self.setRowColMapProp(ir, ic, self.TYPE.IGNORE, true);
};
var handleEmpty = function (ir, ic) {
_RowColMap.setRowColMapProp(ir, ic, _RowColMap.TYPE.EMPTY, true);
self.setRowColMapProp(ir, ic, self.TYPE.EMPTY, true);
};
var handleRowSpan = function (val, ir, ic) {
var rowSpan = val.getAttribute('rowspan');
var hasColSpan = val.hasAttribute('colspan');
hasColSpan && handleColSpan(val, ir, ic);
for (var _row = 1; _row < rowSpan; _row++) {
_RowColMap.setRowColMapProp(_row + ir, undefined, _RowColMap.TYPE.SPAN, true);
_RowColMap.setRowColMapProp(_row + ir, ic, undefined, 1);

for (var _row = 0; _row < rowSpan; _row++) {
if (_row + ir >= rowLength) {
return;
}
hasColSpan && handleColSpan(val, _row + ir, ic);
if (_row >= 1) {
self.setRowColMapProp(_row + ir, undefined, self.TYPE.SPAN, true);
self.setRowColMapProp(_row + ir, ic, undefined, 1);
}
}
};
var handleColSpan = function (val, ir, ic) {
var colSpan = val.getAttribute('colspan');
_RowColMap.setRowColMapProp(ir, undefined, _RowColMap.TYPE.SPAN, true);
_RowColMap.setRowColMapProp(ir, ic + OFFSET, undefined, colSpan - OFFSET);

if (colSpan <= 1) {
return;
}
self.setRowColMapProp(ir, undefined, self.TYPE.SPAN, true);
self.setRowColMapProp(ir, ic + OFFSET, undefined, colSpan - OFFSET);
};

_nodesArray(context.rows).map(function (val, ir) {
Expand All @@ -934,7 +946,7 @@
});
});

return _RowColMap;
return self;
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/stable/js/tableexport.min.js

Large diffs are not rendered by default.

0 comments on commit aece6ca

Please sign in to comment.