Skip to content

Commit 3469267

Browse files
committed
Merge pull request danialfarid#128 from destos/full-path
Add new fullPath property to FileAPI for specifying specific location of FileAPI.js library
2 parents cfbb185 + f1fc80c commit 3469267

File tree

4 files changed

+46
-31
lines changed

4 files changed

+46
-31
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,17 @@ You can put these two files beside `angular-file-upload-shim(.min).js` on your s
9999
<script src="angular-file-upload-shim.min.js"></script>...
100100
```
101101

102+
If you are using a CDN to host your files you can aslso specify the specific location of FileAPI.min.js and FileAPI.flash.swf by using jsUrl and flashUrl:
103+
```html
104+
<script>
105+
FileAPI = {
106+
jsUrl: 'yourcdn.com/js/FileAPI.min.js',
107+
flashUrl: 'yourcdn.com/js/FileAPI.flash.swf'
108+
}
109+
</script>
110+
<script src="angular-file-upload-shim.min.js"></script>...
111+
```
112+
102113
## Install
103114

104115
Download files from [/dist](https://github.com/danialfarid/angular-file-upload/blob/master/dist) or

demo/war/js/angular-file-upload-shim.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,17 @@ if (window.XMLHttpRequest) {
5757
})(xhr.open);
5858
xhr.getResponseHeader = (function(orig) {
5959
return function(h) {
60-
return xhr.__fileApiXHR ? xhr.__fileApiXHR.getResponseHeader(h) : orig.apply(xhr, [h]);
60+
return xhr.__fileApiXHR ? xhr.__fileApiXHR.getResponseHeader(h) : orig.apply(xhr, [h]);
6161
}
6262
})(xhr.getResponseHeader);
6363
xhr.getAllResponseHeaders = (function(orig) {
6464
return function() {
65-
return xhr.__fileApiXHR ? xhr.__fileApiXHR.getAllResponseHeaders() : orig.apply(xhr);
65+
return xhr.__fileApiXHR ? xhr.__fileApiXHR.getAllResponseHeaders() : orig.apply(xhr);
6666
}
6767
})(xhr.getAllResponseHeaders);
6868
xhr.abort = (function(orig) {
6969
return function() {
70-
return xhr.__fileApiXHR ? xhr.__fileApiXHR.abort() : (orig == null ? null : orig.apply(xhr));
70+
return xhr.__fileApiXHR ? xhr.__fileApiXHR.abort() : (orig == null ? null : orig.apply(xhr));
7171
}
7272
})(xhr.abort);
7373
xhr.setRequestHeader = (function(orig) {
@@ -83,7 +83,7 @@ if (window.XMLHttpRequest) {
8383
}
8484
}
8585
})(xhr.setRequestHeader);
86-
86+
8787
xhr.send = function() {
8888
if (arguments[0] && arguments[0].__isShim) {
8989
var formData = arguments[0];
@@ -116,7 +116,7 @@ if (window.XMLHttpRequest) {
116116
config.data[item.key] = item.val;
117117
}
118118
}
119-
119+
120120
setTimeout(function() {
121121
if (!hasFlash) {
122122
alert('Please install Adode Flash Player to upload files.');
@@ -169,19 +169,19 @@ if (!window.FormData) {
169169
return function(e, fn, b, d) {
170170
if (isFileChange(this, e)) {
171171
wrapFileApi(this);
172-
origAddEventListener.apply(this, [e, changeFnWrapper(fn), b, d]);
172+
origAddEventListener.apply(this, [e, changeFnWrapper(fn), b, d]);
173173
} else {
174174
origAddEventListener.apply(this, [e, fn, b, d]);
175175
}
176176
}
177-
})(HTMLInputElement.prototype.addEventListener);
177+
})(HTMLInputElement.prototype.addEventListener);
178178
}
179179
if (HTMLInputElement.prototype.attachEvent) {
180180
HTMLInputElement.prototype.attachEvent = (function(origAttachEvent) {
181181
return function(e, fn) {
182182
if (isFileChange(this, e)) {
183183
wrapFileApi(this);
184-
origAttachEvent.apply(this, [e, changeFnWrapper(fn)]);
184+
origAttachEvent.apply(this, [e, changeFnWrapper(fn)]);
185185
} else {
186186
origAttachEvent.apply(this, [e, fn]);
187187
}
@@ -202,13 +202,15 @@ if (!window.FormData) {
202202
__isShim: true
203203
};
204204
};
205-
205+
206206
(function () {
207207
//load FileAPI
208208
if (!window.FileAPI || !FileAPI.upload) {
209-
var base = '', script = document.createElement('script'), allScripts = document.getElementsByTagName('script'), i, index, src;
209+
var base = '', jsUrl = null, script = document.createElement('script'), allScripts = document.getElementsByTagName('script'), i, index, src;
210210
if (window.FileAPI && window.FileAPI.jsPath) {
211211
base = window.FileAPI.jsPath;
212+
} else if (window.FileAPI && window.FileAPI.jsUrl){
213+
jsUrl = window.FileAPI.jsUrl
212214
} else {
213215
for (i = 0; i < allScripts.length; i++) {
214216
src = allScripts[i].src;
@@ -228,8 +230,8 @@ if (!window.FormData) {
228230
staticPath: base
229231
}
230232
}
231-
232-
script.setAttribute('src', base + "FileAPI.min.js");
233+
234+
script.setAttribute('src', jsUrl || base + "FileAPI.min.js");
233235
document.getElementsByTagName('head')[0].appendChild(script);
234236
}
235237
})();
@@ -241,7 +243,7 @@ if (!window.FileReader) {
241243
var _this = this, loadStarted = false;
242244
this.listeners = {};
243245
this.addEventListener = function(type, fn) {
244-
_this.listeners[type] = _this.listeners[type] || [];
246+
_this.listeners[type] = _this.listeners[type] || [];
245247
_this.listeners[type].push(fn);
246248
};
247249
this.removeEventListener = function(type, fn) {
@@ -256,7 +258,7 @@ if (!window.FileReader) {
256258
}
257259
};
258260
this.onabort = this.onerror = this.onload = this.onloadstart = this.onloadend = this.onprogress = null;
259-
261+
260262
function constructEvent(type, evt) {
261263
var e = {type: type, target: _this, loaded: evt.loaded, total: evt.total, error: evt.error};
262264
if (evt.result != null) e.target.result = evt.result;
@@ -297,4 +299,4 @@ if (!window.FileReader) {
297299
}
298300
}
299301
*/
300-
})();
302+
})();

dist/angular-file-upload-shim.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,17 @@ if (window.XMLHttpRequest) {
5757
})(xhr.open);
5858
xhr.getResponseHeader = (function(orig) {
5959
return function(h) {
60-
return xhr.__fileApiXHR ? xhr.__fileApiXHR.getResponseHeader(h) : orig.apply(xhr, [h]);
60+
return xhr.__fileApiXHR ? xhr.__fileApiXHR.getResponseHeader(h) : orig.apply(xhr, [h]);
6161
}
6262
})(xhr.getResponseHeader);
6363
xhr.getAllResponseHeaders = (function(orig) {
6464
return function() {
65-
return xhr.__fileApiXHR ? xhr.__fileApiXHR.getAllResponseHeaders() : orig.apply(xhr);
65+
return xhr.__fileApiXHR ? xhr.__fileApiXHR.getAllResponseHeaders() : orig.apply(xhr);
6666
}
6767
})(xhr.getAllResponseHeaders);
6868
xhr.abort = (function(orig) {
6969
return function() {
70-
return xhr.__fileApiXHR ? xhr.__fileApiXHR.abort() : (orig == null ? null : orig.apply(xhr));
70+
return xhr.__fileApiXHR ? xhr.__fileApiXHR.abort() : (orig == null ? null : orig.apply(xhr));
7171
}
7272
})(xhr.abort);
7373
xhr.setRequestHeader = (function(orig) {
@@ -83,7 +83,7 @@ if (window.XMLHttpRequest) {
8383
}
8484
}
8585
})(xhr.setRequestHeader);
86-
86+
8787
xhr.send = function() {
8888
if (arguments[0] && arguments[0].__isShim) {
8989
var formData = arguments[0];
@@ -116,7 +116,7 @@ if (window.XMLHttpRequest) {
116116
config.data[item.key] = item.val;
117117
}
118118
}
119-
119+
120120
setTimeout(function() {
121121
if (!hasFlash) {
122122
alert('Please install Adode Flash Player to upload files.');
@@ -169,19 +169,19 @@ if (!window.FormData) {
169169
return function(e, fn, b, d) {
170170
if (isFileChange(this, e)) {
171171
wrapFileApi(this);
172-
origAddEventListener.apply(this, [e, changeFnWrapper(fn), b, d]);
172+
origAddEventListener.apply(this, [e, changeFnWrapper(fn), b, d]);
173173
} else {
174174
origAddEventListener.apply(this, [e, fn, b, d]);
175175
}
176176
}
177-
})(HTMLInputElement.prototype.addEventListener);
177+
})(HTMLInputElement.prototype.addEventListener);
178178
}
179179
if (HTMLInputElement.prototype.attachEvent) {
180180
HTMLInputElement.prototype.attachEvent = (function(origAttachEvent) {
181181
return function(e, fn) {
182182
if (isFileChange(this, e)) {
183183
wrapFileApi(this);
184-
origAttachEvent.apply(this, [e, changeFnWrapper(fn)]);
184+
origAttachEvent.apply(this, [e, changeFnWrapper(fn)]);
185185
} else {
186186
origAttachEvent.apply(this, [e, fn]);
187187
}
@@ -202,13 +202,15 @@ if (!window.FormData) {
202202
__isShim: true
203203
};
204204
};
205-
205+
206206
(function () {
207207
//load FileAPI
208208
if (!window.FileAPI || !FileAPI.upload) {
209-
var base = '', script = document.createElement('script'), allScripts = document.getElementsByTagName('script'), i, index, src;
209+
var base = '', jsUrl = null, script = document.createElement('script'), allScripts = document.getElementsByTagName('script'), i, index, src;
210210
if (window.FileAPI && window.FileAPI.jsPath) {
211211
base = window.FileAPI.jsPath;
212+
} else if (window.FileAPI && window.FileAPI.jsUrl){
213+
jsUrl = window.FileAPI.jsUrl
212214
} else {
213215
for (i = 0; i < allScripts.length; i++) {
214216
src = allScripts[i].src;
@@ -228,8 +230,8 @@ if (!window.FormData) {
228230
staticPath: base
229231
}
230232
}
231-
232-
script.setAttribute('src', base + "FileAPI.min.js");
233+
234+
script.setAttribute('src', jsUrl || base + "FileAPI.min.js");
233235
document.getElementsByTagName('head')[0].appendChild(script);
234236
}
235237
})();
@@ -241,7 +243,7 @@ if (!window.FileReader) {
241243
var _this = this, loadStarted = false;
242244
this.listeners = {};
243245
this.addEventListener = function(type, fn) {
244-
_this.listeners[type] = _this.listeners[type] || [];
246+
_this.listeners[type] = _this.listeners[type] || [];
245247
_this.listeners[type].push(fn);
246248
};
247249
this.removeEventListener = function(type, fn) {
@@ -256,7 +258,7 @@ if (!window.FileReader) {
256258
}
257259
};
258260
this.onabort = this.onerror = this.onload = this.onloadstart = this.onloadend = this.onprogress = null;
259-
261+
260262
function constructEvent(type, evt) {
261263
var e = {type: type, target: _this, loaded: evt.loaded, total: evt.total, error: evt.error};
262264
if (evt.result != null) e.target.result = evt.result;
@@ -297,4 +299,4 @@ if (!window.FileReader) {
297299
}
298300
}
299301
*/
300-
})();
302+
})();

dist/angular-file-upload-shim.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)