Skip to content

Commit 45e18f7

Browse files
author
Philipp Alferov
committed
Add more validations
1 parent babf768 commit 45e18f7

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

docs/dist/examples.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28908,15 +28908,29 @@ function isString (obj) {
2890828908
return typeof obj === 'string' || obj instanceof String;
2890928909
}
2891028910

28911-
function isBlobInstance (obj) {
28912-
return obj instanceof Blob;
28911+
function isUndefined (obj) {
28912+
return typeof obj == "undefined";
2891328913
}
2891428914

2891528915
angular
2891628916
.module('fileSaver', [])
28917-
.factory('SaveAs', SaveAs);
28917+
.factory('SaveAs', ['$window', SaveAs]);
2891828918

28919-
function SaveAs() {
28919+
function SaveAs ($window) {
28920+
var saveAs = $window.saveAs;
28921+
var Blob = $window.Blob;
28922+
28923+
if (isUndefined(saveAs)) {
28924+
handleErrors('saveAs is not supported. Please include saveAs polyfill');
28925+
}
28926+
28927+
if (isUndefined(Blob)) {
28928+
handleErrors('Blob is not supported. Please include blob polyfill');
28929+
}
28930+
28931+
function isBlobInstance (obj) {
28932+
return obj instanceof Blob;
28933+
}
2892028934

2892128935
function save(blob, filename) {
2892228936
try {

docs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>
1010

1111
<link rel="stylesheet" type="text/css" href="dist/examples.css" media="screen">
12-
<script src="dist/examples.min.js"></script>
12+
<script src="dist/examples.js"></script>
1313
</head>
1414

1515
<body ng-app="ngFileSaver">

src/angular-file-saver.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,29 @@ function isString (obj) {
2626
return typeof obj === 'string' || obj instanceof String;
2727
}
2828

29-
function isBlobInstance (obj) {
30-
return obj instanceof Blob;
29+
function isUndefined (obj) {
30+
return typeof obj == "undefined";
3131
}
3232

3333
angular
3434
.module('fileSaver', [])
35-
.factory('SaveAs', SaveAs);
35+
.factory('SaveAs', ['$window', SaveAs]);
3636

37-
function SaveAs() {
37+
function SaveAs ($window) {
38+
var saveAs = $window.saveAs;
39+
var Blob = $window.Blob;
40+
41+
if (isUndefined(saveAs)) {
42+
handleErrors('saveAs is not supported. Please include saveAs polyfill');
43+
}
44+
45+
if (isUndefined(Blob)) {
46+
handleErrors('Blob is not supported. Please include blob polyfill');
47+
}
48+
49+
function isBlobInstance (obj) {
50+
return obj instanceof Blob;
51+
}
3852

3953
function save(blob, filename) {
4054
try {

0 commit comments

Comments
 (0)