Skip to content

Commit 365e8fc

Browse files
committed
Oprava controlleru.
1 parent 069e59c commit 365e8fc

17 files changed

+4592
-4580
lines changed

src/www/fileupload/controller.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,24 +78,24 @@ var Renderer = function (token, components, inputHtmlId, removeLink) {
7878
return template[1];
7979
};
8080

81-
this.errorTemplate = function(file, message) {
81+
this.errorTemplate = function (file, message) {
8282
var template = this.getTemplate("upload-template-file-error");
8383

84-
if(this.components.filename != null) {
84+
if (this.components.filename != null) {
8585
var filename = template.querySelector(this.getSelector(this.components.filename));
86-
if(filename != null) {
86+
if (filename != null) {
8787
filename.textContent = file.name;
8888
}
8989
}
9090

91-
if(this.components.imagePreview != null && this.isImage(file.name)) {
91+
if (this.components.imagePreview != null && this.isImage(file.name)) {
9292
var imagePreview = template.querySelector(this.getSelector(this.components.imagePreview));
93-
if(imagePreview != null) {
93+
if (imagePreview != null) {
9494
this.setImagePreview(imagePreview, file);
9595
}
96-
} else if(this.components.filePreview != null) {
96+
} else if (this.components.filePreview != null) {
9797
var filePreview = template.querySelector(this.getSelector(this.components.filePreview));
98-
if(filePreview != null) {
98+
if (filePreview != null) {
9999
filePreview.textContent = this.getFileExtension(file.name);
100100
}
101101
}
@@ -132,7 +132,7 @@ Renderer.prototype = {
132132
document.querySelector(this.getSelector(this.components.container)).appendChild(template);
133133
},
134134

135-
addDefaultFile: function(file) {
135+
addDefaultFile: function (file, controller) {
136136
var template = this.getTemplate("upload-template-file-container");
137137
template.setAttribute("for", this.inputHtmlId);
138138

@@ -162,6 +162,8 @@ Renderer.prototype = {
162162
}).done(function () {
163163
$(template).fadeOut(400, function () {
164164
$(this).remove();
165+
controller.uploaded--;
166+
controller.addedFiles--;
165167
});
166168
});
167169
});
@@ -475,11 +477,11 @@ FileUploadController.prototype = {
475477
*
476478
* @param defaultFiles
477479
*/
478-
addDefaultFiles: function(defaultFiles) {
479-
for(var i = 0; i < defaultFiles.length; i++) {
480+
addDefaultFiles: function (defaultFiles) {
481+
for (var i = 0; i < defaultFiles.length; i++) {
480482
this.uploaded++;
481483
this.addedFiles++;
482-
this.renderer.addDefaultFile(defaultFiles[i]);
484+
this.renderer.addDefaultFile(defaultFiles[i], this);
483485
}
484486
}
485487
};

src/www/fileupload/functions.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(function(funcName, baseObj) {
1+
(function (funcName, baseObj) {
22
// The public function name defaults to window.docReady
33
// but you can pass in your own object and own function name and those will be used
44
// if you want to put them in a different namespace
@@ -29,7 +29,7 @@
2929
}
3030

3131
function readyStateChange() {
32-
if ( document.readyState === "complete" ) {
32+
if (document.readyState === "complete") {
3333
ready();
3434
}
3535
}
@@ -38,11 +38,13 @@
3838
// docReady(fn, context);
3939
// the context argument is optional - if present, it will be passed
4040
// as an argument to the callback
41-
baseObj[funcName] = function(callback, context) {
41+
baseObj[funcName] = function (callback, context) {
4242
// if ready has already fired, then just schedule the callback
4343
// to fire asynchronously, but right away
4444
if (readyFired) {
45-
setTimeout(function() {callback(context);}, 1);
45+
setTimeout(function () {
46+
callback(context);
47+
}, 1);
4648
return;
4749
} else {
4850
// add the function and context to the list
@@ -73,8 +75,9 @@
7375
* @param {Object} child
7476
* @param {Object} parent
7577
*/
76-
var extendsClass = function(child, parent) {
77-
var F = function() {};
78+
var extendsClass = function (child, parent) {
79+
var F = function () {
80+
};
7881
F.prototype = parent.prototype;
7982
child.prototype = new F();
8083
child._superClass = parent.prototype;

src/www/fileupload/js/app.js

Lines changed: 85 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -13,89 +13,89 @@
1313
/* global window, angular */
1414

1515
;(function () {
16-
'use strict';
17-
18-
var isOnGitHub = window.location.hostname === 'blueimp.github.io',
19-
url = isOnGitHub ? '//jquery-file-upload.appspot.com/' : 'server/php/';
20-
21-
angular.module('demo', [
22-
'blueimp.fileupload'
23-
])
24-
.config([
25-
'$httpProvider', 'fileUploadProvider',
26-
function ($httpProvider, fileUploadProvider) {
27-
delete $httpProvider.defaults.headers.common['X-Requested-With'];
28-
fileUploadProvider.defaults.redirect = window.location.href.replace(
29-
/\/[^\/]*$/,
30-
'/cors/result.html?%s'
31-
);
32-
if (isOnGitHub) {
33-
// Demo settings:
34-
angular.extend(fileUploadProvider.defaults, {
35-
// Enable image resizing, except for Android and Opera,
36-
// which actually support image resizing, but fail to
37-
// send Blob objects via XHR requests:
38-
disableImageResize: /Android(?!.*Chrome)|Opera/
39-
.test(window.navigator.userAgent),
40-
maxFileSize: 999000,
41-
acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i
42-
});
43-
}
44-
}
45-
])
46-
47-
.controller('DemoFileUploadController', [
48-
'$scope', '$http', '$filter', '$window',
49-
function ($scope, $http) {
50-
$scope.options = {
51-
url: url
52-
};
53-
if (!isOnGitHub) {
54-
$scope.loadingFiles = true;
55-
$http.get(url)
56-
.then(
57-
function (response) {
58-
$scope.loadingFiles = false;
59-
$scope.queue = response.data.files || [];
60-
},
61-
function () {
62-
$scope.loadingFiles = false;
63-
}
64-
);
65-
}
66-
}
67-
])
68-
69-
.controller('FileDestroyController', [
70-
'$scope', '$http',
71-
function ($scope, $http) {
72-
var file = $scope.file,
73-
state;
74-
if (file.url) {
75-
file.$state = function () {
76-
return state;
77-
};
78-
file.$destroy = function () {
79-
state = 'pending';
80-
return $http({
81-
url: file.deleteUrl,
82-
method: file.deleteType
83-
}).then(
84-
function () {
85-
state = 'resolved';
86-
$scope.clear(file);
87-
},
88-
function () {
89-
state = 'rejected';
90-
}
91-
);
92-
};
93-
} else if (!file.$cancel && !file._index) {
94-
file.$cancel = function () {
95-
$scope.clear(file);
96-
};
97-
}
98-
}
99-
]);
100-
16+
'use strict';
17+
18+
var isOnGitHub = window.location.hostname === 'blueimp.github.io',
19+
url = isOnGitHub ? '//jquery-file-upload.appspot.com/' : 'server/php/';
20+
21+
angular.module('demo', [
22+
'blueimp.fileupload'
23+
])
24+
.config([
25+
'$httpProvider', 'fileUploadProvider',
26+
function ($httpProvider, fileUploadProvider) {
27+
delete $httpProvider.defaults.headers.common['X-Requested-With'];
28+
fileUploadProvider.defaults.redirect = window.location.href.replace(
29+
/\/[^\/]*$/,
30+
'/cors/result.html?%s'
31+
);
32+
if (isOnGitHub) {
33+
// Demo settings:
34+
angular.extend(fileUploadProvider.defaults, {
35+
// Enable image resizing, except for Android and Opera,
36+
// which actually support image resizing, but fail to
37+
// send Blob objects via XHR requests:
38+
disableImageResize: /Android(?!.*Chrome)|Opera/
39+
.test(window.navigator.userAgent),
40+
maxFileSize: 999000,
41+
acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i
42+
});
43+
}
44+
}
45+
])
46+
47+
.controller('DemoFileUploadController', [
48+
'$scope', '$http', '$filter', '$window',
49+
function ($scope, $http) {
50+
$scope.options = {
51+
url: url
52+
};
53+
if (!isOnGitHub) {
54+
$scope.loadingFiles = true;
55+
$http.get(url)
56+
.then(
57+
function (response) {
58+
$scope.loadingFiles = false;
59+
$scope.queue = response.data.files || [];
60+
},
61+
function () {
62+
$scope.loadingFiles = false;
63+
}
64+
);
65+
}
66+
}
67+
])
68+
69+
.controller('FileDestroyController', [
70+
'$scope', '$http',
71+
function ($scope, $http) {
72+
var file = $scope.file,
73+
state;
74+
if (file.url) {
75+
file.$state = function () {
76+
return state;
77+
};
78+
file.$destroy = function () {
79+
state = 'pending';
80+
return $http({
81+
url: file.deleteUrl,
82+
method: file.deleteType
83+
}).then(
84+
function () {
85+
state = 'resolved';
86+
$scope.clear(file);
87+
},
88+
function () {
89+
state = 'rejected';
90+
}
91+
);
92+
};
93+
} else if (!file.$cancel && !file._index) {
94+
file.$cancel = function () {
95+
$scope.clear(file);
96+
};
97+
}
98+
}
99+
]);
100+
101101
}());

0 commit comments

Comments
 (0)