Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uploader.bind('FilesAdded', function(up, files) {
- //uploader.start();
- //First of all, we are going to add more info to the files
- for(var i = 0; i < files.length; i++) {
- var file = files[i];
- var inputFile = file.getNative();
- file.lastModified = inputFile.lastModified;
- file.lastModifiedDate = inputFile.lastModifiedDate;
- file.type = inputFile.type;
- file.image_thumb = undefined;
- file.response = undefined;
- //If is an image
- if(file.type && file.type.split('/')[0].indexOf('image') > -1) {
- //While we are loading just set up a default mime
- file.image_thumb = mimeService.getUrl(file);
- var fr = new FileReader();
- /* jshint -W083 */
- fr.onload = (function(file) {
- return function(evt) {
- //Retrieve an image, set up a canvas and crop the image
- var image = new Image();
- image.src = evt.target.result;
- image.onload = function() {
- var newWidth = image.width;
- var newHeight = image.height;
- if(newWidth > newHeight) {
- if(newWidth > MAX_IMAGE_WIDTH) {
- newHeight = Math.ceil(newHeight * MAX_IMAGE_WIDTH / newWidth);
- newWidth = MAX_IMAGE_WIDTH;
- }
- } else {
- if(newHeight > MAX_IMAGE_HEIGHT) {
- newWidth = Math.ceil(newWidth * MAX_IMAGE_HEIGHT / newHeight);
- newHeight = MAX_IMAGE_HEIGHT;
- }
- }
- var canvas = document.createElement('canvas');
- canvas.width = newWidth;
- canvas.height = newHeight;
- var ctx = canvas.getContext('2d');
- ctx.drawImage(image, 0, 0, newWidth, newHeight);
- scope.$apply(function() {
- file.image_thumb = canvas.toDataURL(file.type);
- });
- };
- };
- })(file);
- /* jshint +W083 */
- fr.readAsDataURL(inputFile);
- } else {
- //Here we set up one image that will represent the file
- file.image_thumb = mimeService.getUrl(file);
- }
- }
- scope.$apply(function() {
- if(iAttrs.plFilesModel) {
- angular.forEach(files, function(file, key) {
- scope.plFilesModel.push(file);
- });
- }
- if(iAttrs.onFileAdded) {
- scope.$parent.$eval(iAttrs.onFileAdded, {$files: files});
- }
- });
- if(iAttrs.plAutoUpload == 'true') {
- uploader.start();
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement