之前写了利用jsPDF和html2canvas做多页PDF导出,但是发现在IE下面不行,存在BUG,也就是Promise未定义的问题,于是也一起处理了一下。
起先我想打算用bluebird.js,但是发现与现有项目代码存在冲突,所以先放弃了,然后采用了第二种方式通过引用polyfill.js可以解决这个问题:
polyfill.js:
(function(t){
"use strict";if(!t.matches&&t.matchesSelector){
t.matches=t.matchesSelector}if(!t.matches&&!t.matchesSelector){
t.matches=function(t){
var e=document.querySelectorAll(t),n=this;return Array.prototype.some.call(e,function(t){
return t===n})}}})(Element.prototype);(function(t){
"use strict";if(typeof t.Promise==="undefined"||t.Promise.toString().indexOf("[native code]")===-1){
var e="[[PromiseStatus]]";var n="[[PromiseValue]]";var r="pending";var i="internal pending";var o="resolved";var s="rejected";var c=function(t,s){
if(t[e]===i){
t=t[n]}if(t[e]===r){
t.deferreds.push(s)}else{
t.handled=true;setTimeout(function(){
var r=t[e]===o?s.onFulfilled:s.onRejected;if(r){
try{
a(s.promise,r(t[n]))}catch(t){
u(s.promise,t)}}else{
if(t[e]===o){
a(s.promise,t[n])}else{
u(s.promise,t[n])}}},0)}};var a=function(t,r){
if(r===t){
throw new TypeError("A promise cannot be resolved with it promise.")}try{
if(r&&(typeof r==="object"||typeof r==="function")){
if(r instanceof p){
t[e]=i;t[n]=r;f(t);return}else if(typeof r.then==="function"){
h(r.then.bind(r),t);return}}t[e]=o;t[n]=r;f(t)}catch(e){
u(t,e)}};var u=function(t,r){
t[e]=s;t[n]=r;f(t)};var f=function(t){
if(t[e]===s&&t.deferreds.length===0){
setTimeout(function(){
if(!t.handled){
console.error("Unhandled Promise Rejection: "+t[n])}},0)}t.deferreds.forEach(function(e){
c(t,e)});t.deferreds=null};var h=function(t,e){
var n=false;try{
t(r,i)}catch(t){
if(!n){
n=true;u(e,t)}}function r(t){
if(!n){
n=true;a(e,t)}}function i(t){
if(!n){
n=true;u(e,t)}}};var l=function(t,e,n){
this.onFulfilled=typeof t==="function"?t:null;this.onRejected=typeof e==="function"?e:null;this.promise=n};var p=function(t){
this[e]=r;this[n]=null;this.handled=false;this.deferreds=[];h(t,this)};p.prototype["catch"]=function(t){
return this.then(null,t)};p.prototype.then=function(t,e){
var n=new p(function(){
});c(this,new l(t,e,n));return n};p.all=function(t){
var e=[].slice.call(t);return new p(function(t,n){
if(e.length===0){
t(e)}else{
var r=e.length;var i=function(o,s){
try{
if(s&&(typeof s==="object"||typeof s==="function")){
if(typeof s.then==="function"<