Skip to content
This repository was archived by the owner on Jan 24, 2019. It is now read-only.

Commit 600b717

Browse files
author
AngularUI (via TravisCI)
committed
Travis commit : build 391
1 parent 84f458a commit 600b717

File tree

4 files changed

+172
-6
lines changed

4 files changed

+172
-6
lines changed

ui-utils-ieshiv.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* angular-ui-utils - Swiss-Army-Knife of AngularJS tools (with no external dependencies!)
3-
* @version v0.1.1 - 2014-12-01
3+
* @version v0.1.1 - 2014-12-17
44
* @link http://angular-ui.github.com
55
* @license MIT License, http://www.opensource.org/licenses/MIT
66
*/

ui-utils-ieshiv.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.

ui-utils.js

Lines changed: 168 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* angular-ui-utils - Swiss-Army-Knife of AngularJS tools (with no external dependencies!)
3-
* @version v0.1.1 - 2014-12-01
3+
* @version v0.1.1 - 2014-12-17
44
* @link http://angular-ui.github.com
55
* @license MIT License, http://www.opensource.org/licenses/MIT
66
*/
@@ -524,7 +524,7 @@ angular.module('ui.mask', [])
524524
controller.$viewValue = value.length ? maskValue(value) : '';
525525
controller.$setValidity('mask', isValid);
526526
if (value === '' && iAttrs.required) {
527-
controller.$setValidity('required', false);
527+
controller.$setValidity('required', !controller.$error.required);
528528
}
529529
return isValid ? value : undefined;
530530
}
@@ -2055,6 +2055,172 @@ angular.module('ui.unique',[]).filter('unique', ['$parse', function ($parse) {
20552055
};
20562056
}]);
20572057

2058+
(function () {
2059+
'use strict';
2060+
2061+
angular.module('myApp', ['ui.uploader']).controller('myController', demoController);
2062+
2063+
demoController.$inject = ['$log', 'uiUploader', '$scope'];
2064+
2065+
function demoController($log, $uiUploader, $scope) {
2066+
2067+
$scope.btn_remove = function(file){
2068+
$log.info('deleting='+file);
2069+
$uiUploader.removeFile(file);
2070+
};
2071+
2072+
$scope.btn_clean = function(){
2073+
$uiUploader.removeAll();
2074+
};
2075+
2076+
$scope.btn_upload = function() {
2077+
$log.info('uploading...');
2078+
$uiUploader.startUpload({
2079+
url: 'http://localhost:3000/welcome/ui_uploader',
2080+
concurrency: 2,
2081+
onProgress: function(file) {
2082+
$log.info(file.name+'='+file.humanSize);
2083+
//$log.info($scope.files.indexOf(file));
2084+
$scope.$apply();
2085+
},
2086+
onCompleted: function(file) {
2087+
$log.info(file);
2088+
}
2089+
});
2090+
};
2091+
2092+
$scope.files=[];
2093+
2094+
var element = document.getElementById('file1');
2095+
element.addEventListener('change', function(e) {
2096+
var files = e.target.files;
2097+
$uiUploader.addFiles(files);
2098+
$scope.files = $uiUploader.getFiles();
2099+
$scope.$apply();
2100+
// $log.info($uiUploader.files.length);
2101+
});
2102+
}
2103+
})();
2104+
'use strict';
2105+
/*
2106+
* Author: Remy Alain Ticona Carbajal http://realtica.org
2107+
* Description: The main objective of ng-uploader is to have a user control,
2108+
* clean, simple, customizable, and above all very easy to implement.
2109+
* Licence: MIT
2110+
*/
2111+
2112+
angular.module('ui.uploader', []).service('uiUploader', uiUploader);
2113+
2114+
uiUploader.$inject = ['$log'];
2115+
2116+
function uiUploader($log) {
2117+
/*jshint validthis: true */
2118+
var self = this;
2119+
self.files = [];
2120+
self.options = {};
2121+
self.activeUploads = 0;
2122+
$log.info('uiUploader loaded');
2123+
2124+
function addFiles(files) {
2125+
for (var i = 0; i < files.length; i++) {
2126+
self.files.push(files[i]);
2127+
}
2128+
}
2129+
2130+
function getFiles() {
2131+
return self.files;
2132+
}
2133+
2134+
function startUpload(options) {
2135+
self.options = options;
2136+
for (var i = 0; i < self.files.length; i++) {
2137+
if (self.activeUploads == self.options.concurrency) {
2138+
break;
2139+
}
2140+
if (self.files[i].active)
2141+
continue;
2142+
ajaxUpload(self.files[i], self.options.url);
2143+
}
2144+
}
2145+
2146+
function removeFile(file){
2147+
self.files.splice(self.files.indexOf(file),1);
2148+
}
2149+
2150+
function removeAll(){
2151+
self.files.splice(0,self.files.length);
2152+
}
2153+
2154+
return {
2155+
addFiles: addFiles,
2156+
getFiles: getFiles,
2157+
files: self.files,
2158+
startUpload: startUpload,
2159+
removeFile: removeFile,
2160+
removeAll:removeAll
2161+
};
2162+
2163+
function getHumanSize(bytes) {
2164+
var sizes = ['n/a', 'bytes', 'KiB', 'MiB', 'GiB', 'TB', 'PB', 'EiB', 'ZiB', 'YiB'];
2165+
var i = +Math.floor(Math.log(bytes) / Math.log(1024));
2166+
return (bytes / Math.pow(1024, i)).toFixed(i ? 1 : 0) + ' ' + sizes[isNaN(bytes) ? 0 : i + 1];
2167+
}
2168+
2169+
function ajaxUpload(file, url) {
2170+
var xhr, formData, prop, data = '',
2171+
key = '' || 'file';
2172+
self.activeUploads += 1;
2173+
file.active = true;
2174+
xhr = new window.XMLHttpRequest();
2175+
formData = new window.FormData();
2176+
xhr.open('POST', url);
2177+
2178+
// Triggered when upload starts:
2179+
xhr.upload.onloadstart = function() {};
2180+
2181+
// Triggered many times during upload:
2182+
xhr.upload.onprogress = function(event) {
2183+
if (!event.lengthComputable) {
2184+
return;
2185+
}
2186+
// Update file size because it might be bigger than reported by
2187+
// the fileSize:
2188+
//$log.info("progres..");
2189+
//console.info(event.loaded);
2190+
file.loaded = event.loaded;
2191+
file.humanSize = getHumanSize(event.loaded);
2192+
self.options.onProgress(file);
2193+
};
2194+
2195+
// Triggered when upload is completed:
2196+
xhr.onload = function() {
2197+
self.activeUploads -= 1;
2198+
startUpload(self.options);
2199+
self.options.onCompleted(file);
2200+
};
2201+
2202+
// Triggered when upload fails:
2203+
xhr.onerror = function() {};
2204+
2205+
// Append additional data if provided:
2206+
if (data) {
2207+
for (prop in data) {
2208+
if (data.hasOwnProperty(prop)) {
2209+
formData.append(prop, data[prop]);
2210+
}
2211+
}
2212+
}
2213+
2214+
// Append file data:
2215+
formData.append(key, file, file.name);
2216+
2217+
// Initiate upload:
2218+
xhr.send(formData);
2219+
2220+
return xhr;
2221+
}
2222+
2223+
}
20582224
'use strict';
20592225

20602226
/**

0 commit comments

Comments
 (0)