Created
February 8, 2013 19:32
-
-
Save aaronwhite/4741358 to your computer and use it in GitHub Desktop.
An AngularJS directive for quickly incorporate a drop-target that works with Filepicker.io
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.stepsApp.directive 'filepickerPane', ()-> | |
($scope, element, attrs)-> | |
initialHtml = element.html() | |
dragOverClass = attrs.dragOverClass | |
onUploadSuccess = attrs.onUploadSuccess | |
onUploadError = attrs.onUploadError | |
filepicker.makeDropPane element, | |
multiple: true | |
dragEnter: ()-> | |
element.html "Drop to upload" | |
element.addClass dragOverClass if dragOverClass | |
dragLeave: ()-> | |
element.html initialHtml | |
element.removeClass dragOverClass if dragOverClass | |
onSuccess: (fpfiles)-> | |
$scope.$apply ()-> | |
$scope[onUploadSuccess](fpfiles) if onUploadSuccess | |
onError: (type, message)-> | |
$scope.$apply ()-> | |
$scope[onUploadError](type, message) if onUploadError | |
onProgress: (percentage)-> | |
element.text "Uploading (#{percentage}%)" | |
if percentage >= 100 | |
setTimeout ()-> | |
element.html initialHtml | |
element.removeClass dragOverClass if dragOverClass | |
, 1000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.file_drop_panel{"filepicker_pane"=>true, "drag-over-class"=>"file_drop_drag_over", "on-upload-success"=>"filepickerUploadSuccess"} | |
Drop files here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment