'use strict' ; export const file = angular . module ( 'teambition' ) . directive ( 'openFile' , [ ( ) => { return { restrict : 'A' , scope : { onload : '&openFile' , multiple : '=openFileMultiple' , filter : '&openFileFilter' } , link : ( scope , element , attrs ) => { let imageChosen = function ( ) { let items = [ ] ; angular . forEach ( this . files , ( file , index ) => { let item ; item = { data : file } ; items . push ( item ) ; let reader = new FileReader ( ) ; reader . onload = ( ) => { item . url = URL . createObjectURL ( file ) ; scope . $apply ( ) ; } ; reader . readAsDataURL ( file ) ; } ) ; scope . $apply ( function ( ) { scope . onload ( { images : items } ) ; } ) ; } ; let chooseImage = ( e ) => { e . preventDefault ( ) ; let input = document . createElement ( 'INPUT' ) ; input . setAttribute ( 'type' , 'file' ) ; if ( scope . multiple ) { input . setAttribute ( 'multiple' , 'multiple' ) ; } input . addEventListener ( 'change' , imageChosen , false ) ; let evt = document . createEvent ( 'MouseEvent' ) ; evt . initMouseEvent ( 'click' , true , true , window , 0 , 0 , 0 , 0 , 0 , false , false , false , false , 0 , null ) ; input . dispatchEvent ( evt ) ; } ; element . on ( 'touchstart' , chooseImage ) . on ( 'click' , chooseImage ) ; } } ; } ] ) ;