From 0a3bdffc937a641d48932d0f647a7195ea7c77f9 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Fri, 27 May 2016 15:22:00 +0200 Subject: [PATCH] Improved pasting images on retina devices. --- .../app/lib/app_post/image_service.coffee | 5 +++-- .../app/lib/base/jquery.contenteditable.js | 16 ++++++++++++++-- test/browser_test_helper.rb | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/app/lib/app_post/image_service.coffee b/app/assets/javascripts/app/lib/app_post/image_service.coffee index 481bce703..eb8eba5c6 100644 --- a/app/assets/javascripts/app/lib/app_post/image_service.coffee +++ b/app/assets/javascripts/app/lib/app_post/image_service.coffee @@ -19,6 +19,7 @@ class App.ImageService imageObject.onload = -> imageWidth = imageObject.width imageHeight = imageObject.height + console.log('ImageService', 'current size', imageWidth, imageHeight) if y is 'auto' && x is 'auto' x = imageWidth y = imageHeight @@ -68,10 +69,10 @@ class App.ImageService newDataUrl = canvas.toDataURL(type, quallity) if resize console.log('ImageService', 'resize', x/sizeFactor, y/sizeFactor, quallity, (newDataUrl.length * 0.75)/1024/1024, 'in mb') - callback(newDataUrl, x/sizeFactor, y/sizeFactor) + callback(newDataUrl, x/sizeFactor, y/sizeFactor, true) return console.log('ImageService', 'no resize', x, y, quallity, (newDataUrl.length * 0.75)/1024/1024, 'in mb') - callback(newDataUrl, x, y) + callback(newDataUrl, x, y, false) # load image from data url imageObject.src = dataURL diff --git a/app/assets/javascripts/app/lib/base/jquery.contenteditable.js b/app/assets/javascripts/app/lib/base/jquery.contenteditable.js index 1d9b70204..5ba540694 100644 --- a/app/assets/javascripts/app/lib/base/jquery.contenteditable.js +++ b/app/assets/javascripts/app/lib/base/jquery.contenteditable.js @@ -221,8 +221,14 @@ var img = document.createElement('img') img.src = result - insert = function(dataUrl, width, height) { + insert = function(dataUrl, width, height, isRetina) { //console.log('dataUrl', dataUrl) + + // adapt image if we are on retina devices + if (!isRetina && window.isRetina && window.isRetina()) { + width = width / 2 + height = height / 2 + } _this.log('image inserted') result = dataUrl img = "" @@ -330,7 +336,13 @@ img.src = result //Insert the image at the carat - insert = function(dataUrl, width, height) { + insert = function(dataUrl, width, height, isRetina) { + + // adapt image if we are on retina devices + if (!isRetina && window.isRetina && window.isRetina()) { + width = width / 2 + height = height / 2 + } //console.log('dataUrl', dataUrl) _this.log('image inserted') diff --git a/test/browser_test_helper.rb b/test/browser_test_helper.rb index a24ad808a..09d8fca43 100644 --- a/test/browser_test_helper.rb +++ b/test/browser_test_helper.rb @@ -1677,7 +1677,7 @@ wait untill text in selector disabppears ) found = false - (1..4).each { + (1..8).each { element = instance.find_elements(css: '.active .newTicket')[0] if element found = true