From 200ade66666d0f88c7f0c0bfdcd05ecec0593f99 Mon Sep 17 00:00:00 2001 From: tairezzzz Date: Sat, 11 Jul 2015 17:31:12 +0300 Subject: [PATCH 1/4] init delay for uploader --- src/js/plupload-angular-directive.js | 248 ++++++++++++++------------- 1 file changed, 125 insertions(+), 123 deletions(-) diff --git a/src/js/plupload-angular-directive.js b/src/js/plupload-angular-directive.js index 02499ac..1adccb7 100755 --- a/src/js/plupload-angular-directive.js +++ b/src/js/plupload-angular-directive.js @@ -29,7 +29,7 @@ angular.module('plupload.directive', []) }]; }) - .directive('plUpload', ['$parse', '$log', 'plUploadService', function ($parse, $log, plUploadService) { + .directive('plUpload', ['$parse', '$log', 'plUploadService', '$timeout', function ($parse, $log, plUploadService, $timeout) { return { restrict: 'A', scope: { @@ -99,130 +99,132 @@ angular.module('plupload.directive', []) options.multipart_params = scope.plMultiParamsModel; } - - var uploader = new plupload.Uploader(options); - - uploader.settings.headers = plUploadService.getConfig('headers'); - - uploader.init(); - - uploader.bind('Error', function(up, err) { - if(iAttrs.onFileError){ - scope.$parent.$apply(iAttrs.onFileError); - } - - $log.error("Cannot upload, error: " + err.message + (err.file ? ", File: " + err.file.name : "") + ""); - - up.refresh(); // Reposition Flash/Silverlight - }); - - uploader.bind('FilesAdded', function(up,files) { - //uploader.start(); - scope.$apply(function() { - if(iAttrs.plFilesModel) { - angular.forEach(files, function(file,key) { - if (!scope.plFilesModel) scope.plFilesModel=[]; - scope.plFilesModel.push(file); - }); - } - - if(iAttrs.onFileAdded){ - var fn = $parse(iAttrs.onFileAdded); - fn(scope.$parent, {$files:files}); - } - }); - - if(iAttrs.plAutoUpload=="true"){ - uploader.start(); - } - }); - - uploader.bind('BeforeUpload', function(up, file) { - if(iAttrs.onBeforeUpload){ - var fn = $parse(iAttrs.onBeforeUpload); - fn(scope.$parent, {$file:file}); + var initDelay = iAttrs.plInitDelay.toLowerCase() == 'true'?300:0 + + $timeout(function(){ + var uploader = new plupload.Uploader(options); + + uploader.settings.headers = plUploadService.getConfig('headers'); + + uploader.init(); + + uploader.bind('Error', function(up, err) { + if(iAttrs.onFileError){ + scope.$parent.$apply(iAttrs.onFileError); + } + + $log.error("Cannot upload, error: " + err.message + (err.file ? ", File: " + err.file.name : "") + ""); + + up.refresh(); // Reposition Flash/Silverlight + }); + + uploader.bind('FilesAdded', function(up,files) { + //uploader.start(); + scope.$apply(function() { + if(iAttrs.plFilesModel) { + angular.forEach(files, function(file,key) { + if (!scope.plFilesModel) scope.plFilesModel=[]; + scope.plFilesModel.push(file); + }); + } + + if(iAttrs.onFileAdded){ + var fn = $parse(iAttrs.onFileAdded); + fn(scope.$parent, {$files:files}); + } + }); + + if(iAttrs.plAutoUpload=="true"){ + uploader.start(); + } + }); + + uploader.bind('BeforeUpload', function(up, file) { + if(iAttrs.onBeforeUpload){ + var fn = $parse(iAttrs.onBeforeUpload); + fn(scope.$parent, {$file:file}); + } + }); + + uploader.bind('FileUploaded', function(up, file, res) { + //We are going to make some refactor here. + //The idea behind is always update files with the server response value + //And also launch the eventi if neeed + + //If we have the model... + if(iAttrs.plFilesModel) { + //Apply on scope... + scope.$apply(function() { + + //All files are uploaded? + scope.allUploaded = false; + + angular.forEach(scope.plFilesModel, function($file, key) { + + //Bug FIX, this logic will set allUploaded right + if(file.percent != 100) { + scope.allUploaded = false; + } else if(file.id == $file.id) { //If the file is the same that we are reciving... + //Set response on the file + $file.response = JSON.parse(res.response); + + //Need throw event? throw it + if(iAttrs.onFileUploaded) { + var fn = $parse(iAttrs.onFileUploaded); + fn(scope.$parent, {$response:res, $file:file}); + } + } + + }); + }); + } + //We doesn't have model but we have the event + else if(!iAttrs.plFilesModel && iAttrs.onFileUploaded) { + var fn = $parse(iAttrs.onFileUploaded); + scope.$apply(function(){ + fn(scope.$parent, {$response:res, $file:file}); + }); + } + }); + + uploader.bind('UploadProgress',function(up,file){ + if(!iAttrs.plProgressModel){ + return; + } + + if(iAttrs.plFilesModel){ + scope.$apply(function() { + scope.sum = 0; + + angular.forEach(scope.plFilesModel, function(file,key) { + scope.sum = scope.sum + file.percent; + }); + + scope.plProgressModel = scope.sum/scope.plFilesModel.length; + }); + } else { + scope.$apply(function() { + scope.plProgressModel = file.percent; + }); + } + + + if(iAttrs.onFileProgress){ + var fn = $parse(iAttrs.onFileProgress); + scope.$apply(function(){ + fn(scope.$parent, {$file:file}); + }); + } + }); + + if(iAttrs.plInstance){ + scope.plInstance = uploader; } - }); - - uploader.bind('FileUploaded', function(up, file, res) { - //We are going to make some refactor here. - //The idea behind is always update files with the server response value - //And also launch the eventi if neeed - - //If we have the model... - if(iAttrs.plFilesModel) { - //Apply on scope... - scope.$apply(function() { - - //All files are uploaded? - scope.allUploaded = false; - - angular.forEach(scope.plFilesModel, function($file, key) { - - //Bug FIX, this logic will set allUploaded right - if(file.percent != 100) { - scope.allUploaded = false; - } else if(file.id == $file.id) { //If the file is the same that we are reciving... - //Set response on the file - $file.response = JSON.parse(res.response); - - //Need throw event? throw it - if(iAttrs.onFileUploaded) { - var fn = $parse(iAttrs.onFileUploaded); - fn(scope.$parent, {$response:res, $file:file}); - } - } - - }); - }); - } - //We doesn't have model but we have the event - else if(!iAttrs.plFilesModel && iAttrs.onFileUploaded) { - var fn = $parse(iAttrs.onFileUploaded); - scope.$apply(function(){ - fn(scope.$parent, {$response:res, $file:file}); - }); - } - }); - - uploader.bind('UploadProgress',function(up,file){ - if(!iAttrs.plProgressModel){ - return; - } - - if(iAttrs.plFilesModel){ - scope.$apply(function() { - scope.sum = 0; - - angular.forEach(scope.plFilesModel, function(file,key) { - scope.sum = scope.sum + file.percent; - }); - - scope.plProgressModel = scope.sum/scope.plFilesModel.length; - }); - } else { - scope.$apply(function() { - scope.plProgressModel = file.percent; - }); - } - - - if(iAttrs.onFileProgress){ - var fn = $parse(iAttrs.onFileProgress); - scope.$apply(function(){ - fn(scope.$parent, {$file:file}); - }); - } - }); - - if(iAttrs.plInstance){ - scope.plInstance = uploader; - } - scope.$on("$destroy", function(){ - uploader.destroy(); - }); - + scope.$on("$destroy", function(){ + uploader.destroy(); + }); + }, initDelay); } }; }]) From a25898e90707a7d438fc22f0afd55458910e4477 Mon Sep 17 00:00:00 2001 From: tairezzzz Date: Sat, 11 Jul 2015 17:41:41 +0300 Subject: [PATCH 2/4] adding resize model --- src/js/plupload-angular-directive.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/js/plupload-angular-directive.js b/src/js/plupload-angular-directive.js index 1adccb7..3befde5 100755 --- a/src/js/plupload-angular-directive.js +++ b/src/js/plupload-angular-directive.js @@ -37,7 +37,8 @@ angular.module('plupload.directive', []) 'plFilesModel': '=', 'plFiltersModel': '=', 'plMultiParamsModel':'=', - 'plInstance': '=' + 'plInstance': '=', + 'plResizeModel':'=' }, link: function (scope, iElement, iAttrs) { @@ -99,6 +100,10 @@ angular.module('plupload.directive', []) options.multipart_params = scope.plMultiParamsModel; } + if (scope.plResizeModel) { + options.resize = scope.plResizeModel; + } + var initDelay = iAttrs.plInitDelay.toLowerCase() == 'true'?300:0 $timeout(function(){ From 61cc4b2357e2c734c0eb004a0f0594694e55835d Mon Sep 17 00:00:00 2001 From: tairezzzz Date: Sat, 11 Jul 2015 18:50:38 +0300 Subject: [PATCH 3/4] builded with resize and delay --- dist/plupload-angular-directive.js | 242 ++++++++++++++----------- dist/plupload-angular-directive.min.js | 4 +- src/js/plupload-angular-directive.js | 6 +- 3 files changed, 146 insertions(+), 106 deletions(-) diff --git a/dist/plupload-angular-directive.js b/dist/plupload-angular-directive.js index 2d50dd7..254ad4f 100644 --- a/dist/plupload-angular-directive.js +++ b/dist/plupload-angular-directive.js @@ -29,7 +29,7 @@ angular.module('plupload.directive', []) }]; }) - .directive('plUpload', ['$parse', 'plUploadService', function ($parse, plUploadService) { + .directive('plUpload', ['$parse', '$log', 'plUploadService', '$timeout', function ($parse, $log, plUploadService, $timeout) { return { restrict: 'A', scope: { @@ -37,7 +37,8 @@ angular.module('plupload.directive', []) 'plFilesModel': '=', 'plFiltersModel': '=', 'plMultiParamsModel':'=', - 'plInstance': '=' + 'plInstance': '=', + 'plResizeModel':'=' }, link: function (scope, iElement, iAttrs) { @@ -49,7 +50,7 @@ angular.module('plupload.directive', []) randomString += charSet.substring(randomPoz,randomPoz+1); } return randomString; - } + }; if(!iAttrs.id){ var randomValue = scope.randomString(5); @@ -58,6 +59,9 @@ angular.module('plupload.directive', []) if(!iAttrs.plAutoUpload){ iAttrs.$set('plAutoUpload','true'); } + if(!iAttrs.plMultiSelection){ + iAttrs.$set('plMultiSelection','true'); + } if(!iAttrs.plMaxFileSize){ iAttrs.$set('plMaxFileSize','10mb'); } @@ -81,115 +85,151 @@ angular.module('plupload.directive', []) var options = { runtimes : 'html5,flash,silverlight', browse_button : iAttrs.id, - multi_selection: true, + multi_selection: iAttrs.plMultiSelection.toLowerCase() == 'true', // container : 'abc', max_file_size : iAttrs.plMaxFileSize, url : iAttrs.plUrl, flash_swf_url : iAttrs.plFlashSwfUrl, silverlight_xap_url : iAttrs.plSilverlightXapUrl, - filters : scope.filters - } + filters : scope.filters, + drop_element: iAttrs.plDropElement + }; if(scope.plMultiParamsModel){ options.multipart_params = scope.plMultiParamsModel; } - - var uploader = new plupload.Uploader(options); - - uploader.settings.headers = plUploadService.getConfig('headers'); - - uploader.init(); - - uploader.bind('Error', function(up, err) { - if(iAttrs.onFileError){ - scope.$parent.$apply(onFileError); - } - - alert("Cannot upload, error: " + err.message + (err.file ? ", File: " + err.file.name : "") + ""); - up.refresh(); // Reposition Flash/Silverlight - }); - - uploader.bind('FilesAdded', function(up,files) { - //uploader.start(); - scope.$apply(function() { - if(iAttrs.plFilesModel) { - angular.forEach(files, function(file,key) { - scope.plFilesModel.push(file); - }); - } - - if(iAttrs.onFileAdded){ - scope.$parent.$eval(iAttrs.onFileAdded); - } - }); - - if(iAttrs.plAutoUpload=="true"){ - uploader.start(); - } - }); - - uploader.bind('FileUploaded', function(up, file, res) { - if(iAttrs.onFileUploaded) { - if(iAttrs.plFilesModel) { - scope.$apply(function() { - angular.forEach(scope.plFilesModel, function(file,key) { - scope.allUploaded = false; - if(file.percent==100) - scope.allUploaded = true; - }); - - if(scope.allUploaded) { - var fn = $parse(iAttrs.onFileUploaded); - fn(scope.$parent, {$response:res}); - } - - }); - } else { - var fn = $parse(iAttrs.onFileUploaded); - scope.$apply(function(){ - fn(scope.$parent, {$response:res}); - }); - } - //scope.$parent.$apply(iAttrs.onFileUploaded); - } - }); - - uploader.bind('UploadProgress',function(up,file){ - if(!iAttrs.plProgressModel){ - return; - } - - if(iAttrs.plFilesModel){ - scope.$apply(function() { - scope.sum = 0; - - angular.forEach(scope.plFilesModel, function(file,key) { - scope.sum = scope.sum + file.percent; - }); - - scope.plProgressModel = scope.sum/scope.plFilesModel.length; - }); - } else { - scope.$apply(function() { - scope.plProgressModel = file.percent; - }); - } - - - if(iAttrs.onFileProgress){ - scope.$parent.$eval(iAttrs.onFileProgress); - } - }); - - if(iAttrs.plInstance){ - scope.plInstance = uploader; - } - - // scope.upload = function(){ - // uploader.start(); - // }; + if (scope.plResizeModel) { + options.resize = scope.plResizeModel; + } + + var initDelay = iAttrs.plInitDelay.toLowerCase() == 'true'?300:0; + + $timeout(function(){ + var uploader = new plupload.Uploader(options); + + uploader.settings.headers = plUploadService.getConfig('headers'); + + uploader.init(); + + uploader.bind('Error', function(up, err) { + if(iAttrs.onFileError){ + scope.$parent.$apply(iAttrs.onFileError); + } + + $log.error("Cannot upload, error: " + err.message + (err.file ? ", File: " + err.file.name : "") + ""); + + up.refresh(); // Reposition Flash/Silverlight + }); + + uploader.bind('FilesAdded', function(up,files) { + //uploader.start(); + scope.$apply(function() { + if(iAttrs.plFilesModel) { + angular.forEach(files, function(file,key) { + if (!scope.plFilesModel) scope.plFilesModel=[]; + scope.plFilesModel.push(file); + }); + } + + if(iAttrs.onFileAdded){ + var fn = $parse(iAttrs.onFileAdded); + fn(scope.$parent, {$files:files}); + } + }); + + if(iAttrs.plAutoUpload=="true"){ + uploader.start(); + } + }); + + uploader.bind('BeforeUpload', function(up, file) { + if(iAttrs.onBeforeUpload){ + var fn = $parse(iAttrs.onBeforeUpload); + fn(scope.$parent, {$file:file}); + } + }); + + uploader.bind('FileUploaded', function(up, file, res) { + //We are going to make some refactor here. + //The idea behind is always update files with the server response value + //And also launch the eventi if neeed + + //If we have the model... + if(iAttrs.plFilesModel) { + //Apply on scope... + scope.$apply(function() { + + //All files are uploaded? + scope.allUploaded = false; + + angular.forEach(scope.plFilesModel, function($file, key) { + + //Bug FIX, this logic will set allUploaded right + if(file.percent != 100) { + scope.allUploaded = false; + } else if(file.id == $file.id) { //If the file is the same that we are reciving... + //Set response on the file + $file.response = JSON.parse(res.response); + + //Need throw event? throw it + if(iAttrs.onFileUploaded) { + var fn = $parse(iAttrs.onFileUploaded); + fn(scope.$parent, {$response:res, $file:file}); + } + } + + }); + }); + } + //We doesn't have model but we have the event + else if(!iAttrs.plFilesModel && iAttrs.onFileUploaded) { + var fn = $parse(iAttrs.onFileUploaded); + scope.$apply(function(){ + fn(scope.$parent, {$response:res, $file:file}); + }); + } + }); + + uploader.bind('UploadProgress',function(up,file){ + if(!iAttrs.plProgressModel){ + return; + } + + if(iAttrs.plFilesModel){ + scope.$apply(function() { + scope.sum = 0; + + angular.forEach(scope.plFilesModel, function(file,key) { + scope.sum = scope.sum + file.percent; + }); + + scope.plProgressModel = scope.sum/scope.plFilesModel.length; + }); + } else { + scope.$apply(function() { + scope.plProgressModel = file.percent; + }); + } + + + if(iAttrs.onFileProgress){ + var fn = $parse(iAttrs.onFileProgress); + scope.$apply(function(){ + fn(scope.$parent, {$file:file}); + }); + } + }); + + if(iAttrs.plInstance){ + scope.plInstance = uploader; + } + + scope.$on("$destroy", function(){ + uploader.destroy(); + }); + }, initDelay); } }; }]) diff --git a/dist/plupload-angular-directive.min.js b/dist/plupload-angular-directive.min.js index 8655db3..f116acb 100644 --- a/dist/plupload-angular-directive.min.js +++ b/dist/plupload-angular-directive.min.js @@ -1,2 +1,2 @@ -/*! plupload-angular-directive 22-02-2015 */ -"use strict";angular.module("plupload.directive",[]).provider("plUploadService",function(){var a={flashPath:"bower_components/plupload-angular-directive/dist/plupload.flash.swf",silverLightPath:"bower_components/plupload-angular-directive/dist/plupload.silverlight.xap",uploadPath:"upload.php"};this.setConfig=function(b,c){a[b]=c},this.getConfig=function(b){return a[b]};var b=this;this.$get=[function(){return{getConfig:b.getConfig,setConfig:b.setConfig}}]}).directive("plUpload",["$parse","plUploadService",function(a,b){return{restrict:"A",scope:{plProgressModel:"=",plFilesModel:"=",plFiltersModel:"=",plMultiParamsModel:"=",plInstance:"="},link:function(c,d,e){if(c.randomString=function(a,b){b=b||"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";for(var c="",d=0;a>d;d++){var e=Math.floor(Math.random()*b.length);c+=b.substring(e,e+1)}return c},!e.id){var f=c.randomString(5);e.$set("id",f)}e.plAutoUpload||e.$set("plAutoUpload","true"),e.plMaxFileSize||e.$set("plMaxFileSize","10mb"),e.plUrl||e.$set("plUrl",b.getConfig("uploadPath")),e.plFlashSwfUrl||e.$set("plFlashSwfUrl",b.getConfig("flashPath")),e.plSilverlightXapUrl||e.$set("plSilverlightXapUrl",b.getConfig("silverLightPath")),c.filters="undefined"==typeof c.plFiltersModel?[{title:"Image files",extensions:"jpg,jpeg,gif,png,tiff,pdf"}]:c.plFiltersModel;var g={runtimes:"html5,flash,silverlight",browse_button:e.id,multi_selection:!0,max_file_size:e.plMaxFileSize,url:e.plUrl,flash_swf_url:e.plFlashSwfUrl,silverlight_xap_url:e.plSilverlightXapUrl,filters:c.filters};c.plMultiParamsModel&&(g.multipart_params=c.plMultiParamsModel);var h=new plupload.Uploader(g);h.settings.headers=b.getConfig("headers"),h.init(),h.bind("Error",function(a,b){e.onFileError&&c.$parent.$apply(onFileError),alert("Cannot upload, error: "+b.message+(b.file?", File: "+b.file.name:"")),a.refresh()}),h.bind("FilesAdded",function(a,b){c.$apply(function(){e.plFilesModel&&angular.forEach(b,function(a){c.plFilesModel.push(a)}),e.onFileAdded&&c.$parent.$eval(e.onFileAdded)}),"true"==e.plAutoUpload&&h.start()}),h.bind("FileUploaded",function(b,d,f){if(e.onFileUploaded)if(e.plFilesModel)c.$apply(function(){if(angular.forEach(c.plFilesModel,function(a){c.allUploaded=!1,100==a.percent&&(c.allUploaded=!0)}),c.allUploaded){var b=a(e.onFileUploaded);b(c.$parent,{$response:f})}});else{var g=a(e.onFileUploaded);c.$apply(function(){g(c.$parent,{$response:f})})}}),h.bind("UploadProgress",function(a,b){e.plProgressModel&&(c.$apply(e.plFilesModel?function(){c.sum=0,angular.forEach(c.plFilesModel,function(a){c.sum=c.sum+a.percent}),c.plProgressModel=c.sum/c.plFilesModel.length}:function(){c.plProgressModel=b.percent}),e.onFileProgress&&c.$parent.$eval(e.onFileProgress))}),e.plInstance&&(c.plInstance=h)}}}]); \ No newline at end of file +/*! plupload-angular-directive 11-07-2015 */ +"use strict";angular.module("plupload.directive",[]).provider("plUploadService",function(){var a={flashPath:"bower_components/plupload-angular-directive/dist/plupload.flash.swf",silverLightPath:"bower_components/plupload-angular-directive/dist/plupload.silverlight.xap",uploadPath:"upload.php"};this.setConfig=function(b,c){a[b]=c},this.getConfig=function(b){return a[b]};var b=this;this.$get=[function(){return{getConfig:b.getConfig,setConfig:b.setConfig}}]}).directive("plUpload",["$parse","$log","plUploadService","$timeout",function(a,b,c,d){return{restrict:"A",scope:{plProgressModel:"=",plFilesModel:"=",plFiltersModel:"=",plMultiParamsModel:"=",plInstance:"=",plResizeModel:"="},link:function(e,f,g){if(e.randomString=function(a,b){b=b||"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";for(var c="",d=0;a>d;d++){var e=Math.floor(Math.random()*b.length);c+=b.substring(e,e+1)}return c},!g.id){var h=e.randomString(5);g.$set("id",h)}g.plAutoUpload||g.$set("plAutoUpload","true"),g.plMultiSelection||g.$set("plMultiSelection","true"),g.plMaxFileSize||g.$set("plMaxFileSize","10mb"),g.plUrl||g.$set("plUrl",c.getConfig("uploadPath")),g.plFlashSwfUrl||g.$set("plFlashSwfUrl",c.getConfig("flashPath")),g.plSilverlightXapUrl||g.$set("plSilverlightXapUrl",c.getConfig("silverLightPath")),"undefined"==typeof e.plFiltersModel?e.filters=[{title:"Image files",extensions:"jpg,jpeg,gif,png,tiff,pdf"}]:e.filters=e.plFiltersModel;var i={runtimes:"html5,flash,silverlight",browse_button:g.id,multi_selection:"true"==g.plMultiSelection.toLowerCase(),max_file_size:g.plMaxFileSize,url:g.plUrl,flash_swf_url:g.plFlashSwfUrl,silverlight_xap_url:g.plSilverlightXapUrl,filters:e.filters,drop_element:g.plDropElement};e.plMultiParamsModel&&(i.multipart_params=e.plMultiParamsModel),e.plResizeModel&&(i.resize=e.plResizeModel);var j="true"==g.plInitDelay.toLowerCase()?300:0;d(function(){var d=new plupload.Uploader(i);d.settings.headers=c.getConfig("headers"),d.init(),d.bind("Error",function(a,c){g.onFileError&&e.$parent.$apply(g.onFileError),b.error("Cannot upload, error: "+c.message+(c.file?", File: "+c.file.name:"")),a.refresh()}),d.bind("FilesAdded",function(b,c){e.$apply(function(){if(g.plFilesModel&&angular.forEach(c,function(a,b){e.plFilesModel||(e.plFilesModel=[]),e.plFilesModel.push(a)}),g.onFileAdded){var b=a(g.onFileAdded);b(e.$parent,{$files:c})}}),"true"==g.plAutoUpload&&d.start()}),d.bind("BeforeUpload",function(b,c){if(g.onBeforeUpload){var d=a(g.onBeforeUpload);d(e.$parent,{$file:c})}}),d.bind("FileUploaded",function(b,c,d){if(g.plFilesModel)e.$apply(function(){e.allUploaded=!1,angular.forEach(e.plFilesModel,function(b,f){if(100!=c.percent)e.allUploaded=!1;else if(c.id==b.id&&(b.response=JSON.parse(d.response),g.onFileUploaded)){var h=a(g.onFileUploaded);h(e.$parent,{$response:d,$file:c})}})});else if(!g.plFilesModel&&g.onFileUploaded){var f=a(g.onFileUploaded);e.$apply(function(){f(e.$parent,{$response:d,$file:c})})}}),d.bind("UploadProgress",function(b,c){if(g.plProgressModel&&(g.plFilesModel?e.$apply(function(){e.sum=0,angular.forEach(e.plFilesModel,function(a,b){e.sum=e.sum+a.percent}),e.plProgressModel=e.sum/e.plFilesModel.length}):e.$apply(function(){e.plProgressModel=c.percent}),g.onFileProgress)){var d=a(g.onFileProgress);e.$apply(function(){d(e.$parent,{$file:c})})}}),g.plInstance&&(e.plInstance=d),e.$on("$destroy",function(){d.destroy()})},j)}}}]); \ No newline at end of file diff --git a/src/js/plupload-angular-directive.js b/src/js/plupload-angular-directive.js index 3befde5..254ad4f 100755 --- a/src/js/plupload-angular-directive.js +++ b/src/js/plupload-angular-directive.js @@ -50,7 +50,7 @@ angular.module('plupload.directive', []) randomString += charSet.substring(randomPoz,randomPoz+1); } return randomString; - } + }; if(!iAttrs.id){ var randomValue = scope.randomString(5); @@ -93,7 +93,7 @@ angular.module('plupload.directive', []) silverlight_xap_url : iAttrs.plSilverlightXapUrl, filters : scope.filters, drop_element: iAttrs.plDropElement - } + }; if(scope.plMultiParamsModel){ @@ -104,7 +104,7 @@ angular.module('plupload.directive', []) options.resize = scope.plResizeModel; } - var initDelay = iAttrs.plInitDelay.toLowerCase() == 'true'?300:0 + var initDelay = iAttrs.plInitDelay.toLowerCase() == 'true'?300:0; $timeout(function(){ var uploader = new plupload.Uploader(options); From acd50805c29f4cc518c9a0d4a0987f14f6daf94b Mon Sep 17 00:00:00 2001 From: tairezzzz Date: Sun, 12 Jul 2015 12:17:03 +0300 Subject: [PATCH 4/4] fix undefined pl-init delay --- dist/plupload-angular-directive.js | 3 +++ dist/plupload-angular-directive.min.js | 4 ++-- src/js/plupload-angular-directive.js | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/dist/plupload-angular-directive.js b/dist/plupload-angular-directive.js index 254ad4f..3c07f3e 100644 --- a/dist/plupload-angular-directive.js +++ b/dist/plupload-angular-directive.js @@ -62,6 +62,9 @@ angular.module('plupload.directive', []) if(!iAttrs.plMultiSelection){ iAttrs.$set('plMultiSelection','true'); } + if(!iAttrs.plInitDelay){ + iAttrs.$set('plInitDelay','false'); + } if(!iAttrs.plMaxFileSize){ iAttrs.$set('plMaxFileSize','10mb'); } diff --git a/dist/plupload-angular-directive.min.js b/dist/plupload-angular-directive.min.js index f116acb..f7b8fbc 100644 --- a/dist/plupload-angular-directive.min.js +++ b/dist/plupload-angular-directive.min.js @@ -1,2 +1,2 @@ -/*! plupload-angular-directive 11-07-2015 */ -"use strict";angular.module("plupload.directive",[]).provider("plUploadService",function(){var a={flashPath:"bower_components/plupload-angular-directive/dist/plupload.flash.swf",silverLightPath:"bower_components/plupload-angular-directive/dist/plupload.silverlight.xap",uploadPath:"upload.php"};this.setConfig=function(b,c){a[b]=c},this.getConfig=function(b){return a[b]};var b=this;this.$get=[function(){return{getConfig:b.getConfig,setConfig:b.setConfig}}]}).directive("plUpload",["$parse","$log","plUploadService","$timeout",function(a,b,c,d){return{restrict:"A",scope:{plProgressModel:"=",plFilesModel:"=",plFiltersModel:"=",plMultiParamsModel:"=",plInstance:"=",plResizeModel:"="},link:function(e,f,g){if(e.randomString=function(a,b){b=b||"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";for(var c="",d=0;a>d;d++){var e=Math.floor(Math.random()*b.length);c+=b.substring(e,e+1)}return c},!g.id){var h=e.randomString(5);g.$set("id",h)}g.plAutoUpload||g.$set("plAutoUpload","true"),g.plMultiSelection||g.$set("plMultiSelection","true"),g.plMaxFileSize||g.$set("plMaxFileSize","10mb"),g.plUrl||g.$set("plUrl",c.getConfig("uploadPath")),g.plFlashSwfUrl||g.$set("plFlashSwfUrl",c.getConfig("flashPath")),g.plSilverlightXapUrl||g.$set("plSilverlightXapUrl",c.getConfig("silverLightPath")),"undefined"==typeof e.plFiltersModel?e.filters=[{title:"Image files",extensions:"jpg,jpeg,gif,png,tiff,pdf"}]:e.filters=e.plFiltersModel;var i={runtimes:"html5,flash,silverlight",browse_button:g.id,multi_selection:"true"==g.plMultiSelection.toLowerCase(),max_file_size:g.plMaxFileSize,url:g.plUrl,flash_swf_url:g.plFlashSwfUrl,silverlight_xap_url:g.plSilverlightXapUrl,filters:e.filters,drop_element:g.plDropElement};e.plMultiParamsModel&&(i.multipart_params=e.plMultiParamsModel),e.plResizeModel&&(i.resize=e.plResizeModel);var j="true"==g.plInitDelay.toLowerCase()?300:0;d(function(){var d=new plupload.Uploader(i);d.settings.headers=c.getConfig("headers"),d.init(),d.bind("Error",function(a,c){g.onFileError&&e.$parent.$apply(g.onFileError),b.error("Cannot upload, error: "+c.message+(c.file?", File: "+c.file.name:"")),a.refresh()}),d.bind("FilesAdded",function(b,c){e.$apply(function(){if(g.plFilesModel&&angular.forEach(c,function(a,b){e.plFilesModel||(e.plFilesModel=[]),e.plFilesModel.push(a)}),g.onFileAdded){var b=a(g.onFileAdded);b(e.$parent,{$files:c})}}),"true"==g.plAutoUpload&&d.start()}),d.bind("BeforeUpload",function(b,c){if(g.onBeforeUpload){var d=a(g.onBeforeUpload);d(e.$parent,{$file:c})}}),d.bind("FileUploaded",function(b,c,d){if(g.plFilesModel)e.$apply(function(){e.allUploaded=!1,angular.forEach(e.plFilesModel,function(b,f){if(100!=c.percent)e.allUploaded=!1;else if(c.id==b.id&&(b.response=JSON.parse(d.response),g.onFileUploaded)){var h=a(g.onFileUploaded);h(e.$parent,{$response:d,$file:c})}})});else if(!g.plFilesModel&&g.onFileUploaded){var f=a(g.onFileUploaded);e.$apply(function(){f(e.$parent,{$response:d,$file:c})})}}),d.bind("UploadProgress",function(b,c){if(g.plProgressModel&&(g.plFilesModel?e.$apply(function(){e.sum=0,angular.forEach(e.plFilesModel,function(a,b){e.sum=e.sum+a.percent}),e.plProgressModel=e.sum/e.plFilesModel.length}):e.$apply(function(){e.plProgressModel=c.percent}),g.onFileProgress)){var d=a(g.onFileProgress);e.$apply(function(){d(e.$parent,{$file:c})})}}),g.plInstance&&(e.plInstance=d),e.$on("$destroy",function(){d.destroy()})},j)}}}]); \ No newline at end of file +/*! plupload-angular-directive 12-07-2015 */ +"use strict";angular.module("plupload.directive",[]).provider("plUploadService",function(){var a={flashPath:"bower_components/plupload-angular-directive/dist/plupload.flash.swf",silverLightPath:"bower_components/plupload-angular-directive/dist/plupload.silverlight.xap",uploadPath:"upload.php"};this.setConfig=function(b,c){a[b]=c},this.getConfig=function(b){return a[b]};var b=this;this.$get=[function(){return{getConfig:b.getConfig,setConfig:b.setConfig}}]}).directive("plUpload",["$parse","$log","plUploadService","$timeout",function(a,b,c,d){return{restrict:"A",scope:{plProgressModel:"=",plFilesModel:"=",plFiltersModel:"=",plMultiParamsModel:"=",plInstance:"=",plResizeModel:"="},link:function(e,f,g){if(e.randomString=function(a,b){b=b||"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";for(var c="",d=0;a>d;d++){var e=Math.floor(Math.random()*b.length);c+=b.substring(e,e+1)}return c},!g.id){var h=e.randomString(5);g.$set("id",h)}g.plAutoUpload||g.$set("plAutoUpload","true"),g.plMultiSelection||g.$set("plMultiSelection","true"),g.plInitDelay||g.$set("plInitDelay","false"),g.plMaxFileSize||g.$set("plMaxFileSize","10mb"),g.plUrl||g.$set("plUrl",c.getConfig("uploadPath")),g.plFlashSwfUrl||g.$set("plFlashSwfUrl",c.getConfig("flashPath")),g.plSilverlightXapUrl||g.$set("plSilverlightXapUrl",c.getConfig("silverLightPath")),"undefined"==typeof e.plFiltersModel?e.filters=[{title:"Image files",extensions:"jpg,jpeg,gif,png,tiff,pdf"}]:e.filters=e.plFiltersModel;var i={runtimes:"html5,flash,silverlight",browse_button:g.id,multi_selection:"true"==g.plMultiSelection.toLowerCase(),max_file_size:g.plMaxFileSize,url:g.plUrl,flash_swf_url:g.plFlashSwfUrl,silverlight_xap_url:g.plSilverlightXapUrl,filters:e.filters,drop_element:g.plDropElement};e.plMultiParamsModel&&(i.multipart_params=e.plMultiParamsModel),e.plResizeModel&&(i.resize=e.plResizeModel);var j="true"==g.plInitDelay.toLowerCase()?300:0;d(function(){var d=new plupload.Uploader(i);d.settings.headers=c.getConfig("headers"),d.init(),d.bind("Error",function(a,c){g.onFileError&&e.$parent.$apply(g.onFileError),b.error("Cannot upload, error: "+c.message+(c.file?", File: "+c.file.name:"")),a.refresh()}),d.bind("FilesAdded",function(b,c){e.$apply(function(){if(g.plFilesModel&&angular.forEach(c,function(a,b){e.plFilesModel||(e.plFilesModel=[]),e.plFilesModel.push(a)}),g.onFileAdded){var b=a(g.onFileAdded);b(e.$parent,{$files:c})}}),"true"==g.plAutoUpload&&d.start()}),d.bind("BeforeUpload",function(b,c){if(g.onBeforeUpload){var d=a(g.onBeforeUpload);d(e.$parent,{$file:c})}}),d.bind("FileUploaded",function(b,c,d){if(g.plFilesModel)e.$apply(function(){e.allUploaded=!1,angular.forEach(e.plFilesModel,function(b,f){if(100!=c.percent)e.allUploaded=!1;else if(c.id==b.id&&(b.response=JSON.parse(d.response),g.onFileUploaded)){var h=a(g.onFileUploaded);h(e.$parent,{$response:d,$file:c})}})});else if(!g.plFilesModel&&g.onFileUploaded){var f=a(g.onFileUploaded);e.$apply(function(){f(e.$parent,{$response:d,$file:c})})}}),d.bind("UploadProgress",function(b,c){if(g.plProgressModel&&(g.plFilesModel?e.$apply(function(){e.sum=0,angular.forEach(e.plFilesModel,function(a,b){e.sum=e.sum+a.percent}),e.plProgressModel=e.sum/e.plFilesModel.length}):e.$apply(function(){e.plProgressModel=c.percent}),g.onFileProgress)){var d=a(g.onFileProgress);e.$apply(function(){d(e.$parent,{$file:c})})}}),g.plInstance&&(e.plInstance=d),e.$on("$destroy",function(){d.destroy()})},j)}}}]); \ No newline at end of file diff --git a/src/js/plupload-angular-directive.js b/src/js/plupload-angular-directive.js index 254ad4f..3c07f3e 100755 --- a/src/js/plupload-angular-directive.js +++ b/src/js/plupload-angular-directive.js @@ -62,6 +62,9 @@ angular.module('plupload.directive', []) if(!iAttrs.plMultiSelection){ iAttrs.$set('plMultiSelection','true'); } + if(!iAttrs.plInitDelay){ + iAttrs.$set('plInitDelay','false'); + } if(!iAttrs.plMaxFileSize){ iAttrs.$set('plMaxFileSize','10mb'); }