@@ -77,10 +77,10 @@ angular.module('imageupload', [])
7777 restrict : 'A' ,
7878 scope : {
7979 image : '=' ,
80- resizeMaxHeight : '@? ' ,
81- resizeMaxWidth : '@? ' ,
82- resizeQuality : '@? ' ,
83- resizeType : '@? ' ,
80+ resizeMaxHeight : '@' ,
81+ resizeMaxWidth : '@' ,
82+ resizeQuality : '@' ,
83+ resizeType : '@' ,
8484 } ,
8585 link : function postLink ( scope , element , attrs , ctrl ) {
8686
@@ -101,10 +101,30 @@ angular.module('imageupload', [])
101101 if ( attrs . multiple )
102102 scope . image . push ( imageResult ) ;
103103 else
104- scope . image = imageResult ;
104+ scope . image = imageResult ;
105105 } ) ;
106106 } ;
107107
108+ var processImage = function ( file ) {
109+ //create a result object for each file in files
110+ var imageResult = {
111+ file : file ,
112+ url : URL . createObjectURL ( file )
113+ } ;
114+
115+ fileToDataURL ( file ) . then ( function ( dataURL ) {
116+ imageResult . dataURL = dataURL ;
117+ } ) ;
118+
119+ if ( scope . resizeMaxHeight || scope . resizeMaxWidth ) { //resize image
120+ doResizing ( imageResult , function ( imageResult ) {
121+ applyScope ( imageResult ) ;
122+ } ) ;
123+ }
124+ else { //no resizing
125+ applyScope ( imageResult ) ;
126+ }
127+ } ;
108128
109129 element . bind ( 'change' , function ( evt ) {
110130 //when multiple always return an array of images
@@ -113,26 +133,9 @@ angular.module('imageupload', [])
113133
114134 var files = evt . target . files ;
115135 for ( var i = 0 ; i < files . length ; i ++ ) {
116- //create a result object for each file in files
117- var imageResult = {
118- file : files [ i ] ,
119- url : URL . createObjectURL ( files [ i ] )
120- } ;
121-
122- fileToDataURL ( files [ i ] ) . then ( function ( dataURL ) {
123- imageResult . dataURL = dataURL ;
124- } ) ;
125-
126- if ( scope . resizeMaxHeight || scope . resizeMaxWidth ) { //resize image
127- doResizing ( imageResult , function ( imageResult ) {
128- applyScope ( imageResult ) ;
129- } ) ;
130- }
131- else { //no resizing
132- applyScope ( imageResult ) ;
133- }
136+ processImage ( files [ i ] ) ;
134137 }
135138 } ) ;
136139 }
137140 } ;
138- } ) ;
141+ } ) ;
0 commit comments