mirror of
https://github.com/nasa/openmct.git
synced 2025-06-14 21:28:12 +00:00
[Enhancement] Add IE, Opera, Safari support for canvas.toBlob()
This is currently being used for exporting plots to PNG/JPG.
This commit is contained in:
@ -101,6 +101,30 @@ define(
|
|||||||
return defer.promise;
|
return defer.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* canvas.toBlob() not supported in IE < 10, Opera, and Safari. This polyfill
|
||||||
|
* implements the method in browsers that would not otherwise support it.
|
||||||
|
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob
|
||||||
|
*/
|
||||||
|
function polyfillToBlob() {
|
||||||
|
if (!HTMLCanvasElement.prototype.toBlob) {
|
||||||
|
Object.defineProperty(HTMLCanvasElement.prototype, "toBlob", {
|
||||||
|
value: function (callback, type, quality) {
|
||||||
|
|
||||||
|
var binStr = atob(this.toDataURL(type, quality).split(',')[1]),
|
||||||
|
len = binStr.length,
|
||||||
|
arr = new Uint8Array(len);
|
||||||
|
|
||||||
|
for (var i = 0; i < len; i++) {
|
||||||
|
arr[i] = binStr.charCodeAt(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(new Blob([arr], {type: type || "image/png"}));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ExportImageService.prototype.exportPDF = function (element, filename) {
|
ExportImageService.prototype.exportPDF = function (element, filename) {
|
||||||
return renderElement(element, "jpeg").then(function (img) {
|
return renderElement(element, "jpeg").then(function (img) {
|
||||||
var pdf = new self.jsPDF("l", "px", [element.offsetHeight, element.offsetWidth]);
|
var pdf = new self.jsPDF("l", "px", [element.offsetHeight, element.offsetWidth]);
|
||||||
@ -121,6 +145,8 @@ define(
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
polyfillToBlob();
|
||||||
|
|
||||||
return ExportImageService;
|
return ExportImageService;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user