Pony.fm/resources/assets/scripts/app/directives/uploader.coffee

20 lines
535 B
CoffeeScript
Raw Normal View History

2015-08-31 17:42:21 +02:00
angular.module('ponyfm').directive 'uploader', [
'upload'
(upload) -> (scope, element) ->
$dropzone = $(element)
$dropzone[0].addEventListener 'dragover', (e) ->
e.preventDefault()
$dropzone.addClass 'file-over'
$dropzone[0].addEventListener 'dragleave', (e) ->
e.preventDefault()
$dropzone.removeClass 'file-over'
$dropzone[0].addEventListener 'drop', (e) ->
e.preventDefault()
$dropzone.removeClass 'file-over'
files = e.target.files || e.dataTransfer.files
scope.$apply -> upload.upload files
]