Skip to content

Commit

Permalink
removed jquery dependency, added FileAPI.jsPath param to set the js l…
Browse files Browse the repository at this point in the history
…oad path for FileAPI
  • Loading branch information
danialfarid committed Oct 16, 2013
1 parent 98f45d0 commit f5b9280
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 61 deletions.
50 changes: 23 additions & 27 deletions angular-file-upload.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**!
* AngularJS file upload/drop directive with http post and progress
* @author Danial <[email protected]>
* @version 1.0.1
* @version 1.0.2
*/
(function() {

Expand All @@ -10,38 +10,34 @@ var angularFileUpload = angular.module('angularFileUpload', []);
angularFileUpload.html5 = !!window.FormData;

if (!angularFileUpload.html5) {
(function() {
//load jquery
if (!window.jQuery) {
var script = document.createElement('script');
script.setAttribute('src', '//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js');
document.getElementsByTagName('head')[0].appendChild(script);
}
})();

(function () {
//load FileAPI
var base = '', script = document.createElement('script'), allScripts = document.getElementsByTagName('script'), i, index;

for (i = 0; i < allScripts.length; i++) {
index = allScripts[i].src.indexOf('angular-file-upload.js')
if (index == -1) {
index = allScripts[i].src.indexOf('angular-file-upload.min.js');
}
if (index > -1) {
base = allScripts[i].src.substring(0, index);
break;
if (!window.FileAPI || !FileAPI.upload) {
var base = '', script = document.createElement('script'), allScripts = document.getElementsByTagName('script'), i, index;
if (window.FileAPI && window.FileAPI.jsPath) {
base = window.FileAPI.jsPath;
} else {
for (i = 0; i < allScripts.length; i++) {
index = allScripts[i].src.indexOf('angular-file-upload.js')
if (index == -1) {
index = allScripts[i].src.indexOf('angular-file-upload.min.js');
}
if (index > -1) {
base = allScripts[i].src.substring(0, index);
break;
}
}
}
}

if (!window.FileAPI || FileAPI.staticPath == null) {
FileAPI = {
staticPath : base
if (!window.FileAPI || FileAPI.staticPath == null) {
FileAPI = {
staticPath: base
}
}

script.setAttribute('src', base + 'FileAPI.min.js');
document.getElementsByTagName('head')[0].appendChild(script);
}

script.setAttribute('src', base + 'FileAPI.min.js');
document.getElementsByTagName('head')[0].appendChild(script);
})();
}

Expand Down
4 changes: 2 additions & 2 deletions angular-file-upload.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions war/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<title>Angular file upload sample</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js"></script>
<!-- <script src="http://cdn.jsdelivr.net/angular.file-upload/1.0.0/angular-file-upload.min.js"></script> -->
<script src="js/angular-file-upload.min.js"></script>
<script src="js/angular-file-upload.js"></script>
</head>

<body>
Expand Down Expand Up @@ -46,7 +46,7 @@ <h3>
<script type="text/javascript">
angular.module('fileUpload', [ 'angularFileUpload' ]);

var MyCtrl = [ '$scope', '$http', '$injector', function($scope, $http, $injector) {
var MyCtrl = [ '$scope', '$http', '$timeout', function($scope, $http, $timeout) {

$scope.selectedFiles = [];
$scope.progress = 0;
Expand All @@ -72,7 +72,7 @@ <h3>
}
}).success(function(data, status, headers, config) {
$scope.uploadResult.push(data.toString());
// to fix IE not refreshing the model
// to fix IE not updating the dom
if (!$scope.$$phase) {
$scope.$apply();
}
Expand Down
50 changes: 23 additions & 27 deletions war/js/angular-file-upload.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**!
* AngularJS file upload/drop directive with http post and progress
* @author Danial <[email protected]>
* @version 1.0.1
* @version 1.0.2
*/
(function() {

Expand All @@ -10,38 +10,34 @@ var angularFileUpload = angular.module('angularFileUpload', []);
angularFileUpload.html5 = !!window.FormData;

if (!angularFileUpload.html5) {
(function() {
//load jquery
if (!window.jQuery) {
var script = document.createElement('script');
script.setAttribute('src', '//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js');
document.getElementsByTagName('head')[0].appendChild(script);
}
})();

(function () {
//load FileAPI
var base = '', script = document.createElement('script'), allScripts = document.getElementsByTagName('script'), i, index;

for (i = 0; i < allScripts.length; i++) {
index = allScripts[i].src.indexOf('angular-file-upload.js')
if (index == -1) {
index = allScripts[i].src.indexOf('angular-file-upload.min.js');
}
if (index > -1) {
base = allScripts[i].src.substring(0, index);
break;
if (!window.FileAPI || !FileAPI.upload) {
var base = '', script = document.createElement('script'), allScripts = document.getElementsByTagName('script'), i, index;
if (window.FileAPI && window.FileAPI.jsPath) {
base = window.FileAPI.jsPath;
} else {
for (i = 0; i < allScripts.length; i++) {
index = allScripts[i].src.indexOf('angular-file-upload.js')
if (index == -1) {
index = allScripts[i].src.indexOf('angular-file-upload.min.js');
}
if (index > -1) {
base = allScripts[i].src.substring(0, index);
break;
}
}
}
}

if (!window.FileAPI || FileAPI.staticPath == null) {
FileAPI = {
staticPath : base
if (!window.FileAPI || FileAPI.staticPath == null) {
FileAPI = {
staticPath: base
}
}

script.setAttribute('src', base + 'FileAPI.min.js');
document.getElementsByTagName('head')[0].appendChild(script);
}

script.setAttribute('src', base + 'FileAPI.min.js');
document.getElementsByTagName('head')[0].appendChild(script);
})();
}

Expand Down
Loading

0 comments on commit f5b9280

Please sign in to comment.