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

Commit

Permalink
Merge branch 'feature/target-button'
Browse files Browse the repository at this point in the history
* feature/target-button:
  Parse the file blob attributes rather than calling .data(); this ensures that we get the correct object in the event that the button is updated by new table data between downloads
  Unescape html when adding to an existing button
  Only set targets if they are defined
  • Loading branch information
Daniel Wilson committed Jan 10, 2017
2 parents 3c495a4 + 5d2d8f4 commit eba4197
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions dist/js/tableexport.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,9 @@
XLSX && key === 'xls' ? key = 'xlsm' : false;
!XLSX && key === 'xlsx' ? key = null : false;
var target;
key in self.settings['targets'] ? target = self.settings['targets'][key] : null;
if (self.settings['targets']) {
key in self.settings['targets'] ? target = self.settings['targets'][key] : null;
}
key && exporters[key](rowD, fileName, target);
}
);
Expand All @@ -298,6 +300,11 @@
}
}

function unescapeHtml(string) {
var doc = new DOMParser().parseFromString(string, "text/html");
return doc.documentElement.textContent;
}

function checkCaption(exportButton) {
var $caption = $el.find('caption:not(.head)');
$caption.length ? $caption.append(exportButton) : $el.prepend('<caption class="' + bootstrapSpacing + self.settings.position + '">' + exportButton + '</caption>');
Expand All @@ -310,14 +317,14 @@

function attachExportToButton(dataObject, target) {
var exportButton = $(target);
exportButton.attr('data-fileblob', dataObject)
exportButton.attr('data-fileblob', unescapeHtml(dataObject));
}
});

$("button[data-fileblob]")
.off("click")
.on("click", function () {
var object = $(this).data("fileblob"),
var object = JSON.parse($(this).attr('data-fileblob')),
data = object.data,
fileName = object.fileName,
mimeType = object.mimeType,
Expand Down

0 comments on commit eba4197

Please sign in to comment.