saver.min.js 5.7 KB

1
  1. var _global="object"==typeof window&&window.window===window?window:"object"==typeof self&&self.self===self?self:"object"==typeof global&&global.global===global?global:this;function bom(e,t){return void 0===t?t={autoBom:!1}:"object"!=typeof t&&(console.warn("Deprecated: Expected third argument to be a object"),t={autoBom:!t}),t.autoBom&&/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(e.type)?new Blob([String.fromCharCode(65279),e],{type:e.type}):e}function download(e,t,o){var n=new XMLHttpRequest;n.open("GET",e),n.responseType="blob",n.onload=function(){saveAs(n.response,t,o)},n.onerror=function(){console.error("could not download file")},n.send()}function corsEnabled(e){var t=new XMLHttpRequest;t.open("HEAD",e,!1);try{t.send()}catch(e){}return 200<=t.status&&t.status<=299}function click(t){try{t.dispatchEvent(new MouseEvent("click"))}catch(e){var o=document.createEvent("MouseEvents");o.initMouseEvent("click",!0,!0,window,0,0,0,80,20,!1,!1,!1,!1,0,null),t.dispatchEvent(o)}}var isMacOSWebView=_global.navigator&&/Macintosh/.test(navigator.userAgent)&&/AppleWebKit/.test(navigator.userAgent)&&!/Safari/.test(navigator.userAgent),saveAs=_global.saveAs||("object"!=typeof window||window!==_global?function(){}:"download"in HTMLAnchorElement.prototype&&!isMacOSWebView?function(e,t,o){var n=_global.URL||_global.webkitURL,a=document.createElement("a");t=t||e.name||"download",a.download=t,a.rel="noopener","string"==typeof e?(a.href=e,a.origin!==location.origin?corsEnabled(a.href)?download(e,t,o):click(a,a.target="_blank"):click(a)):(a.href=n.createObjectURL(e),setTimeout(function(){n.revokeObjectURL(a.href)},4e4),setTimeout(function(){click(a)},0))}:"msSaveOrOpenBlob"in navigator?function(e,t,o){var n;t=t||e.name||"download","string"==typeof e?corsEnabled(e)?download(e,t,o):((n=document.createElement("a")).href=e,n.target="_blank",setTimeout(function(){click(n)})):navigator.msSaveOrOpenBlob(bom(e,o),t)}:function(e,t,o,n){if((n=n||open("","_blank"))&&(n.document.title=n.document.body.innerText="downloading..."),"string"==typeof e)return download(e,t,o);var a,r,i,t="application/octet-stream"===e.type,o=/constructor/i.test(_global.HTMLElement)||_global.safari,l=/CriOS\/[\d]+/.test(navigator.userAgent);(l||t&&o||isMacOSWebView)&&"undefined"!=typeof FileReader?((a=new FileReader).onloadend=function(){var e=a.result,e=l?e:e.replace(/^data:[^;]*;/,"data:attachment/file;");n?n.location.href=e:location=e,n=null},a.readAsDataURL(e)):(r=_global.URL||_global.webkitURL,i=r.createObjectURL(e),n?n.location=i:location.href=i,n=null,setTimeout(function(){r.revokeObjectURL(i)},4e4))});_global.saveAs=saveAs.saveAs=saveAs,"undefined"!=typeof module&&(module.exports=saveAs),"undefined"!=typeof jQuery&&void 0!==saveAs?function(m){m.fn.wordExport=function(e){e=void 0!==e?e:"jQuery-Word-Export";for(var t={mhtml:{top:"Mime-Version: 1.0\nContent-Base: "+location.href+'\nContent-Type: Multipart/related; boundary="NEXT.ITEM-BOUNDARY";type="text/html"\n\n--NEXT.ITEM-BOUNDARY\nContent-Type: text/html; charset="utf-8"\nContent-Location: '+location.href+'\n\n<!DOCTYPE html>\n<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">\n_html_</html>',head:'<head>\n<meta http-equiv="Content-Type" content="text/html; charset=utf-8">\n<style>\n_styles_\n</style>\n\x3c!--[if gte mso 9]><xml><w:WordDocument><w:View>Print</w:View><w:TrackMoves>false</w:TrackMoves><w:TrackFormatting/><w:ValidateAgainstSchemas/><w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid><w:IgnoreMixedContent>false</w:IgnoreMixedContent><w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText><w:DoNotPromoteQF/><w:LidThemeOther>EN-US</w:LidThemeOther><w:LidThemeAsian>ZH-CN</w:LidThemeAsian><w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript><w:Compatibility><w:BreakWrappedTables/><w:SnapToGridInCell/><w:WrapTextWithPunct/><w:UseAsianBreakRules/><w:DontGrowAutofit/><w:SplitPgBreakAndParaMark/><w:DontVertAlignCellWithSp/><w:DontBreakConstrainedForcedTables/><w:DontVertAlignInTxbx/><w:Word11KerningPairs/><w:CachedColBalance/><w:UseFELayout/></w:Compatibility><w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel><m:mathPr><m:mathFont m:val="Cambria Math"/><m:brkBin m:val="before"/><m:brkBinSub m:val="--"/><m:smallFrac m:val="off"/><m:dispDef/><m:lMargin m:val="0"/> <m:rMargin m:val="0"/><m:defJc m:val="centerGroup"/><m:wrapIndent m:val="1440"/><m:intLim m:val="subSup"/><m:naryLim m:val="undOvr"/></m:mathPr></w:WordDocument></xml><![endif]--\x3e</head>\n',body:"<body>_body_</body>"}},o=624,n=m(this).clone(),a=(n.each(function(){var e=m(this);e.is(":hidden")&&e.remove()}),Array()),r=n.find("img"),i=0;i<r.length;i++){var l=Math.min(r[i].width,o),s=r[i].height*(l/r[i].width),c=document.createElement("CANVAS");c.width=l,c.height=s;c.getContext("2d").drawImage(r[i],0,0,l,s);c=c.toDataURL("image/png");m(r[i]).attr("src",r[i].src),r[i].width=l,r[i].height=s,a[i]={type:c.substring(c.indexOf(":")+1,c.indexOf(";")),encoding:c.substring(c.indexOf(";")+1,c.indexOf(",")),location:m(r[i]).attr("src"),data:c.substring(c.indexOf(",")+1)}}for(var d="\n",i=0;i<a.length;i++)d=(d=(d=(d=(d+="--NEXT.ITEM-BOUNDARY\n")+"Content-Location: "+a[i].location+"\n")+"Content-Type: "+a[i].type+"\n")+"Content-Transfer-Encoding: "+a[i].encoding+"\n\n")+a[i].data+"\n\n";d+="--NEXT.ITEM-BOUNDARY--";t=t.mhtml.top.replace("_html_",t.mhtml.head.replace("_styles_","")+t.mhtml.body.replace("_body_",n.html()))+d,n=new Blob([t],{type:"application/msword;charset=utf-8"});saveAs(n,e+".doc")}}(jQuery):("undefined"==typeof jQuery&&console.error("jQuery Word Export: missing dependency (jQuery)"),void 0===saveAs&&console.error("jQuery Word Export: missing dependency (FileSaver.js)"));