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

View file

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