2015-10-09 20:11:30 +02:00
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var weechat = angular.module('weechat');
|
|
|
|
|
2015-11-10 19:40:30 +01:00
|
|
|
weechat.directive('imgurDrop', ['connection','imgur','$rootScope', function(connection, imgur, $rootScope) {
|
2015-10-09 20:11:30 +02:00
|
|
|
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();
|
|
|
|
|
2015-10-12 21:09:13 +02:00
|
|
|
// Send image url after upload
|
|
|
|
var sendImageUrl = function(imageUrl) {
|
2015-10-09 20:11:30 +02:00
|
|
|
|
2015-10-12 21:09:13 +02:00
|
|
|
// Send image
|
|
|
|
if(imageUrl !== undefined && imageUrl !== '') {
|
2015-11-10 19:40:30 +01:00
|
|
|
$rootScope.insertAtCaret(String(imageUrl));
|
2015-10-12 21:09:13 +02:00
|
|
|
}
|
2015-10-09 20:11:30 +02:00
|
|
|
|
2015-10-12 21:09:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Check files
|
|
|
|
if(typeof files !== "undefined" && files.length > 0) {
|
|
|
|
|
|
|
|
// Loop through files
|
|
|
|
for (var i = 0; i < files.length; i++) {
|
|
|
|
// Upload to imgur
|
|
|
|
imgur.process(files[i], sendImageUrl);
|
|
|
|
}
|
2015-10-09 20:11:30 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}]);
|
|
|
|
|
|
|
|
})();
|