From 65e35adc4c1eb7f165b6eb2a7cd30e408a6d5d5c Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Mon, 8 Feb 2016 18:27:09 +0000 Subject: [PATCH] Preview image before paste Closes #835 --- app/js/directives.js | 21 ++++++++++++++++----- app/less/app.less | 8 ++++++++ app/partials/desktop/confirm_modal.html | 5 ++++- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/app/js/directives.js b/app/js/directives.js index 4a4bfbf8..f49deb65 100755 --- a/app/js/directives.js +++ b/app/js/directives.js @@ -1430,7 +1430,7 @@ angular.module('myApp.directives', ['myApp.filters']) }) - .directive('mySendForm', function (_, $timeout, $compile, $modalStack, $http, $interpolate, Storage, AppStickersManager, AppDocsManager, ErrorService, AppInlineBotsManager, shouldFocusOnInteraction) { + .directive('mySendForm', function (_, $q, $timeout, $compile, $modalStack, $http, $interpolate, Storage, AppStickersManager, AppDocsManager, ErrorService, AppInlineBotsManager, FileManager, shouldFocusOnInteraction) { return { link: link, scope: { @@ -1685,10 +1685,18 @@ angular.module('myApp.directives', ['myApp.filters']) } function onFilePaste (blob) { - ErrorService.confirm({type: 'FILE_CLIPBOARD_PASTE'}).then(function () { - $scope.draftMessage.files = [blob]; - $scope.draftMessage.isMedia = true; - }); + var mimeType = blob.type || ''; + var fileUrlPromise = $q.when(false); + if (['image/jpeg', 'image/gif', 'image/png', 'image/bmp'].indexOf(mimeType) >= 0) { + fileUrlPromise = FileManager.getFileCorrectUrl(blob, mimeType); + } + fileUrlPromise.then(function (fileUrl) { + fileUrl = fileUrl || false; + ErrorService.confirm({type: 'FILE_CLIPBOARD_PASTE', fileUrl: fileUrl}).then(function () { + $scope.draftMessage.files = [blob]; + $scope.draftMessage.isMedia = true; + }); + }) }; function onPasteEvent (e) { @@ -1705,6 +1713,9 @@ angular.module('myApp.directives', ['myApp.filters']) } if (files.length > 0) { + if (files.length == 1) { + return onFilePaste(files[0]); + } ErrorService.confirm({type: 'FILES_CLIPBOARD_PASTE', files: files}).then(function () { $scope.draftMessage.files = files; $scope.draftMessage.isMedia = true; diff --git a/app/less/app.less b/app/less/app.less index 4769cec7..d6df681c 100644 --- a/app/less/app.less +++ b/app/less/app.less @@ -3301,6 +3301,14 @@ _:-ms-lang(x), .composer_rich_textarea:empty:focus:before { .confirm_modal_extlink_jump { word-break: break-all; } +.confirm_modal_paste_image { + max-width: 274px; + height: 274px; + background-position: 50% 50%; + background-size: cover; + background-repeat: no-repeat; + margin: 10px auto -10px; +} .photo_modal_window, .video_modal_window, diff --git a/app/partials/desktop/confirm_modal.html b/app/partials/desktop/confirm_modal.html index 055c2223..bc4babd0 100644 --- a/app/partials/desktop/confirm_modal.html +++ b/app/partials/desktop/confirm_modal.html @@ -14,7 +14,10 @@ when="confirm_modal_clipboard_X_files_send"> - +
+ +
+