You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dropzone.controller.js 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * Created by robin on 4/22/16.
  3. */
  4. (function () {
  5. angular.module('app').directive("imageDropzone", function() {
  6. return {
  7. restrict : "A",
  8. scope: {
  9. 'imageDropzone': '&'
  10. },
  11. link: function (scope, elem) {
  12. function processEvent(evt)
  13. {
  14. if (evt != null) {
  15. evt.stopPropagation();
  16. evt.preventDefault();
  17. if (evt.dataTransfer) {
  18. evt.dataTransfer.effectAllowed = 'copy';
  19. evt.dataTransfer.dropEffect = 'copy';
  20. }
  21. else {
  22. evt.originalEvent.dataTransfer.effectAllowed = 'copy';
  23. evt.originalEvent.dataTransfer.dropEffect = 'copy';
  24. }
  25. }
  26. return false;
  27. }
  28. elem.bind('dragover', processEvent);
  29. elem.bind('dragenter', processEvent);
  30. elem.bind('dragstart', processEvent);
  31. elem.bind('drop', function(evt) {
  32. evt.stopPropagation();
  33. evt.preventDefault();
  34. var files = null;
  35. if (evt.dataTransfer) {
  36. files = evt.dataTransfer.files;
  37. }
  38. else {
  39. files = evt.originalEvent.dataTransfer.files;
  40. }
  41. for (var i = 0, f; f = files[i]; i++) {
  42. var reader = new FileReader();
  43. reader.readAsBinaryString(f);
  44. reader.onload = (function(file) {
  45. return function(e) {
  46. scope.$apply(function() {
  47. scope.imageDropzone({
  48. content: e.target.result,
  49. file: file
  50. });
  51. });
  52. };
  53. })(f);
  54. }
  55. return false;
  56. });
  57. }
  58. }
  59. })
  60. })();