Insert URL at caret when dropping image into GB

unfortunately this pollutes the root scope a bit more
This commit is contained in:
Lorenz Hübschle-Schneider 2015-11-10 19:40:30 +01:00
parent 3f661ded6c
commit a6c2e6f387
2 changed files with 28 additions and 26 deletions

View file

@ -3,7 +3,7 @@
var weechat = angular.module('weechat');
weechat.directive('imgurDrop', ['connection','imgur', function(connection, imgur) {
weechat.directive('imgurDrop', ['connection','imgur','$rootScope', function(connection, imgur, $rootScope) {
return {
restrict: 'A',
link: function($scope, element, attr) {
@ -26,7 +26,7 @@ weechat.directive('imgurDrop', ['connection','imgur', function(connection, imgur
// Send image
if(imageUrl !== undefined && imageUrl !== '') {
connection.sendMessage(String(imageUrl));
$rootScope.insertAtCaret(String(imageUrl));
}
};

View file

@ -70,12 +70,7 @@ weechat.directive('inputBar', function() {
}, 0);
};
$scope.uploadImage = function($event, files) {
// Send image url after upload
var sendImageUrl = function(imageUrl) {
// Send image
if(imageUrl !== undefined && imageUrl !== '') {
$rootScope.insertAtCaret = function(toInsert) {
// caret position in the input bar
var inputNode = $scope.getInputNode(),
caretPos = inputNode.selectionStart;
@ -89,7 +84,7 @@ weechat.directive('inputBar', function() {
if (suffix.length > 0 && suffix[0] !== ' ') {
suffix = ' '.concat(suffix);
}
$scope.command = prefix + String(imageUrl) + suffix;
$scope.command = prefix + toInsert + suffix;
setTimeout(function() {
inputNode.focus();
@ -98,8 +93,15 @@ weechat.directive('inputBar', function() {
// force refresh?
$scope.$apply();
}, 0);
}
};
$scope.uploadImage = function($event, files) {
// Send image url after upload
var sendImageUrl = function(imageUrl) {
// Send image
if(imageUrl !== undefined && imageUrl !== '') {
$rootScope.insertAtCaret(String(imageUrl));
}
};
if(typeof files !== "undefined" && files.length > 0) {