|
13 | 13 | /* global window, angular */ |
14 | 14 |
|
15 | 15 | ;(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 | + |
101 | 101 | }()); |
0 commit comments