Pony.fm/public/scripts/app/directives/uploader.coffee

20 lines
535 B
CoffeeScript
Raw Normal View History

2013-07-25 23:33:04 +02:00
angular.module('ponyfm').directive 'uploader', [
'upload'
(upload) -> (scope, element) ->
$dropzone = $(element)
2013-07-25 23:33:04 +02:00
$dropzone[0].addEventListener 'dragover', (e) ->
2013-07-25 23:33:04 +02:00
e.preventDefault()
$dropzone.addClass 'file-over'
2013-07-25 23:33:04 +02:00
$dropzone[0].addEventListener 'dragleave', (e) ->
2013-07-25 23:33:04 +02:00
e.preventDefault()
$dropzone.removeClass 'file-over'
2013-07-25 23:33:04 +02:00
$dropzone[0].addEventListener 'drop', (e) ->
2013-07-25 23:33:04 +02:00
e.preventDefault()
$dropzone.removeClass 'file-over'
2013-07-25 23:33:04 +02:00
files = e.target.files || e.dataTransfer.files
scope.$apply -> upload.upload files
]