Skip to content

Commit

Permalink
ExportFile : better management for IE. Work properly on IE >= 10 and …
Browse files Browse the repository at this point in the history
…could work on some IE 9
  • Loading branch information
jcornet committed May 17, 2015
1 parent 9ad155d commit 4e09b7a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
1 change: 1 addition & 0 deletions Widget.html
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ <h4 class="title">${nls.exportTitle}</h4>
<div class="list-draw-actions">
<a data-dojo-attach-point="exportButton" target="_BLANK" data-dojo-attach-event="ondijitclick:export" download="myDraw.json" href="#"><span class="export blue-button"></span></a>
<iframe data-dojo-attach-point="exportIframeForIE" style="display:none;"></iframe>
<a data-dojo-attach-point="exportButton" target="_BLANK" data-dojo-attach-event="ondijitclick:exportFile" download="myDraw.json" href="#"><span class="export blue-button"></span></a>
</div>
</td></tr>
<tr><td>
Expand Down
55 changes: 31 additions & 24 deletions Widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -711,39 +711,46 @@ define([
importOnFileLoad : function (evt) {
var content = evt.target.result;
this.importJsonContent(content);
this.importFile.files[0] = "";
this.importFileInput.files[0] = "";
},

export : function () {
exportFile : function () {
// Be sure the link will not open if not asked :
this.exportButton.href = "#";
this.exportButton.target = "_self";

// Control if there are drawings
if (this.drawBox.drawLayer.graphics.length < 1) {
this.showMessage(this.nls.importWarningNoExport0Draw, 'warning');
return false;
} else {
//If not IE
if (!has("ie") && (!navigator.appName || navigator.appName != 'Microsoft Internet Explorer')) {
this.exportButton.href = 'data:application/json;charset=utf-8,' + this.drawingsGetJson(true);
this.exportButton.target = "_BLANK";
this.exportButton.download = (this.config.exportFileName) ? (this.config.exportFileName) : 'myDrawings.json';
return true;
}

//if IE, specific. (ie doesn't accept data in link href)
this.exportButton.href = "#";
this.exportButton.target = "";

var iframe = this.exportIframeForIE;
iframe = iframe.contentWindow || iframe.contentDocument;

iframe.document.open("application/octet-stream", "replace");
iframe.document.write(this.drawingsGetJson(true));
iframe.document.close();
iframe.focus();
iframe.document.execCommand('SaveAs', true, this.config.exportFileName);

}

var export_name = (this.config.exportFileName) ? (this.config.exportFileName) : 'myDrawings.json';

// Case IE with blob support (IE >= 10) : use MS save blob
if(window.navigator && window.navigator.msSaveOrOpenBlob) {
var fileData = [this.drawingsGetJson(true)];
blobObject = new Blob(fileData, { type: 'application/octet-stream' });
window.navigator.msSaveOrOpenBlob(blobObject, export_name);
return false;
}

// Case IE without blob support : write in tab. Doesn't allways work....
if(has("ie")){
var exportWin = window.top.open("about:blank", "_blank");
exportWin.document.write(this.drawingsGetJson(true));
exportWin.document.close();
exportWin.focus();
exportWin.document.execCommand('SaveAs', true, export_name);
exportWin.close();
return false;
}

// Case HTML5 (Firefox > 25, Chrome > 30....) : use data link with download attribute
this.exportButton.href = 'data:application/octet-stream;charset=utf-8,' + this.drawingsGetJson(true);
this.exportButton.target = "_blank";
this.exportButton.download = export_name;
return true;
},


Expand Down

0 comments on commit 4e09b7a

Please sign in to comment.