Make image uploadable by paste from clipboard

This commit is contained in:
JungEon Kim 2018-04-13 09:47:24 +09:00
parent 005f9f6f5c
commit 3d39a3c138
2 changed files with 19 additions and 1 deletions

View File

@ -1,6 +1,6 @@
<form class="form form-horizontal" id="inputform" ng-submit="sendMessage()" imgur-drop>
<div class="input-group">
<textarea id="{{inputId}}" class="form-control favorite-font" ng-trim="false" rows="1" ng-change="inputChanged()" autocomplete="on" ng-model="command" ng-focus="hideSidebar()">
<textarea id="{{inputId}}" class="form-control favorite-font" ng-trim="false" rows="1" ng-change="inputChanged()" autocomplete="on" ng-model="command" ng-focus="hideSidebar()" ng-paste="inputPasted($event)">
</textarea>
<span class="input-group-btn">
<button class="btn btn-complete-nick unselectable mobile" title="Complete nick" ng-click="handleCompleteNickButton($event)"><i class="glyphicon glyphicon-bullhorn"></i></button>

View File

@ -592,6 +592,24 @@ weechat.directive('inputBar', function() {
return true;
};
$scope.inputPasted = function(e) {
if (e.clipboardData && e.clipboardData.files && e.clipboardData.files.length) {
e.stopPropagation();
e.preventDefault();
var sendImageUrl = function(imageUrl) {
if(imageUrl !== undefined && imageUrl !== '') {
$rootScope.insertAtCaret(String(imageUrl));
}
};
for (var i = 0; i < e.clipboardData.files.length; i++) {
imgur.process(e.clipboardData.files[i], sendImageUrl);
}
return false;
}
return true;
};
}]
};
});