diff --git a/directives/input.html b/directives/input.html index dcb7d2e..3fbeb64 100644 --- a/directives/input.html +++ b/directives/input.html @@ -1,4 +1,4 @@ -
+
diff --git a/index.html b/index.html index 566d133..223280e 100644 --- a/index.html +++ b/index.html @@ -34,6 +34,7 @@ + @@ -262,7 +263,7 @@ $ openssl req -nodes -newkey rsa:4096 -keyout relay.pem -x509 -days 365 -out rel
-
+
  • diff --git a/js/imgur-drop-directive.js b/js/imgur-drop-directive.js new file mode 100644 index 0000000..6d8ac36 --- /dev/null +++ b/js/imgur-drop-directive.js @@ -0,0 +1,44 @@ +(function() { +'use strict'; + +var weechat = angular.module('weechat'); + +weechat.directive('imgurDrop', ['connection','imgur', function(connection, imgur) { + return { + restrict: 'A', + link: function($scope, element, attr) { + var elem = element[0]; + elem.ondragover = function () { this.classList.add('imgur-drop-hover'); return false; }; + elem.ondragend = function () { this.classList.remove('imgur-drop-hover'); return false; }; + elem.ondrop = function(e) { + // Remove hover class + this.classList.remove('imgur-drop-hover'); + + // Get files + var files = e.dataTransfer.files; + + // Stop default behaviour + e.stopPropagation(); + e.preventDefault(); + + // Check files length + if (files.length > 0) { + // Sorry only one file + var file = files[0]; + + // Upload to imgur + imgur.process(file, function(imageUrl) { + + // Send image + if(imageUrl !== undefined && imageUrl !== '') { + connection.sendMessage( String(imageUrl) ); + } + + }); + } + }; + } + }; +}]); + +})();