From 707f4f9a58e8ace65c604686132a593a80cb19b3 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 25 Mar 2015 12:17:19 +1100 Subject: [PATCH] more nasty iPad Safari and iPhone Safari hacks --- .../discourse/lib/safari-hacks.js.es6 | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/lib/safari-hacks.js.es6 b/app/assets/javascripts/discourse/lib/safari-hacks.js.es6 index d03d756106d..07bd7db23e8 100644 --- a/app/assets/javascripts/discourse/lib/safari-hacks.js.es6 +++ b/app/assets/javascripts/discourse/lib/safari-hacks.js.es6 @@ -20,24 +20,46 @@ function positioningWorkaround($fixedElement) { var positioningHack = function(evt){ const self = this; + var done = false; + + // allow for keyboard in iPad portrait + var iPadOffset = 0; + if (window.innerHeight > window.innerWidth && navigator.userAgent.match(/iPad/)) { + // there is no way to get virtual keyboard height + iPadOffset = 640 - $(fixedElement).height(); + } + + var positionElement = _.debounce(function(){ + if (done) { + return; + } + fixedElement.style.top = window.scrollY + iPadOffset + 'px'; + }, 350); + if (fixedElement.style.position !== 'absolute') { evt.preventDefault(); fixedElement.style.position = 'absolute'; - fixedElement.style.top = (window.scrollY + $('.d-header').height() + 10) + 'px'; + // get out of the way while opening keyboard + fixedElement.style.top = '0px'; } + $(window).on('scroll', positionElement); + var blurred = function() { if (_.include($(document.activeElement).parents(), fixedElement)) { // something in focus so skip return; } + + done = true; fixedElement.style.position = ''; fixedElement.style.top = ''; self.removeEventListener('blur', blurred); + $(window).off('scroll', positionElement); }; - blurred = _.debounce(blurred, 300); + blurred = _.debounce(blurred, 250); if (this !== document.activeElement) { self.focus();