Created
August 12, 2014 05:00
-
-
Save JamsMendez/c6f2012830b127d6070d to your computer and use it in GitHub Desktop.
Directiva de Angular.js para subir archivos Drag on Drop
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
directives.uploadDrop = function (){ | |
return { | |
require: '?ngModel', | |
restrict: 'E', | |
template: '<div class="input-file" style="width: 150px;"><span class="glyphicon glyphicon-picture"></span></div>', | |
link: function (scope, element, attrs, ngModel){ | |
if (!ngModel) return; | |
element.bind('drop', function (event) { | |
event.stopPropagation(); | |
event.preventDefault(); | |
event.originalEvent.dataTransfer.dropEffect = 'copy'; | |
var file = event.originalEvent.dataTransfer.files[0]; | |
reader = new FileReader(); | |
reader.onload = function (event) { | |
var dataURL = reader.result; | |
var image = file; | |
scope.$apply(function() { | |
ngModel.$setViewValue({ src: dataURL, file: file }); | |
}); | |
}; | |
reader.readAsDataURL(file); | |
return false; | |
}); | |
element.bind('dragover', function (event) { | |
event.stopPropagation(); | |
event.preventDefault(); | |
event.originalEvent.dataTransfer.dropEffect = 'copy'; | |
}); | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment