From e254030760a916b633bd6289f323f79792078b5b Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 17 Sep 2015 13:05:14 +1000 Subject: [PATCH] FIX: header undocking when opening mobile view FIX: make it possible to upload an image on iphone FIX: mobile can now upload more than 1 image --- .../javascripts/discourse/lib/safari-hacks.js.es6 | 15 ++------------- .../javascripts/discourse/templates/composer.hbs | 4 +--- .../javascripts/discourse/views/composer.js.es6 | 4 ++-- .../javascripts/discourse/views/header.js.es6 | 2 +- app/assets/stylesheets/mobile/compose.scss | 1 + 5 files changed, 7 insertions(+), 19 deletions(-) diff --git a/app/assets/javascripts/discourse/lib/safari-hacks.js.es6 b/app/assets/javascripts/discourse/lib/safari-hacks.js.es6 index cc93ebdd68d..f549bc39ccd 100644 --- a/app/assets/javascripts/discourse/lib/safari-hacks.js.es6 +++ b/app/assets/javascripts/discourse/lib/safari-hacks.js.es6 @@ -1,5 +1,4 @@ function applicable() { - // This will apply hack on all iDevices return navigator.userAgent.match(/(iPad|iPhone|iPod)/g) && navigator.userAgent.match(/Safari/g); @@ -15,7 +14,6 @@ function positioningWorkaround($fixedElement) { var done = false; var originalScrollTop = 0; - var wasDocked; var blurredNow = function(evt) { if (!done && _.include($(document.activeElement).parents(), fixedElement)) { @@ -27,17 +25,12 @@ function positioningWorkaround($fixedElement) { fixedElement.parentElement.style.height = ''; $('#main-outlet').show(); - $('header').show(); fixedElement.style.position = ''; fixedElement.style.top = ''; fixedElement.style.height = ''; $(window).scrollTop(originalScrollTop); - if (wasDocked) { - $('body').addClass('docked'); - } - if (evt) { evt.target.removeEventListener('blur', blurred); } @@ -63,12 +56,8 @@ function positioningWorkaround($fixedElement) { originalScrollTop = $(window).scrollTop(); - wasDocked = $('body').hasClass('docked'); - // take care of body $('#main-outlet').hide(); - $('header').hide(); - fixedElement.style.position = 'absolute'; // get out of the way while opening keyboard @@ -93,7 +82,7 @@ function positioningWorkaround($fixedElement) { } const checkForInputs = _.debounce(function(){ - $fixedElement.find('button,a:not(.autocomplete)').each(function(idx, elem){ + $fixedElement.find('button,a:not(.mobile-file-upload)').each(function(idx, elem){ if ($(elem).parents('.autocomplete').length > 0) { return; } @@ -105,7 +94,7 @@ function positioningWorkaround($fixedElement) { $(this).click(); }); }); - $fixedElement.find('input,textarea').each(function(){ + $fixedElement.find('input[type=text],textarea').each(function(){ attachTouchStart(this, positioningHack); }); }, 100); diff --git a/app/assets/javascripts/discourse/templates/composer.hbs b/app/assets/javascripts/discourse/templates/composer.hbs index 9bfcc61bc1a..64967312079 100644 --- a/app/assets/javascripts/discourse/templates/composer.hbs +++ b/app/assets/javascripts/discourse/templates/composer.hbs @@ -91,9 +91,7 @@
{{#if site.mobileView}} - {{#unless view.isUploading}} - {{i18n 'upload'}} - {{/unless}} + {{i18n 'upload'}} {{else}} {{{model.toggleText}}} {{/if}} diff --git a/app/assets/javascripts/discourse/views/composer.js.es6 b/app/assets/javascripts/discourse/views/composer.js.es6 index 093af41741a..008f537135a 100644 --- a/app/assets/javascripts/discourse/views/composer.js.es6 +++ b/app/assets/javascripts/discourse/views/composer.js.es6 @@ -374,7 +374,7 @@ const ComposerView = Ember.View.extend(Ember.Evented, { // add upload placeholder const markdown = Discourse.Utilities.getUploadPlaceholder(data.files[0].name); this.addMarkdown(markdown); - // + if (data["xhr"]) { const jqHXR = data.xhr(); if (jqHXR) { @@ -496,7 +496,7 @@ const ComposerView = Ember.View.extend(Ember.Evented, { } if (Discourse.Mobile.mobileView) { - $(".mobile-file-upload").on("click", function () { + $(".mobile-file-upload").on("click.uploader", function () { // redirect the click on the hidden file input $("#mobile-uploader").click(); }); diff --git a/app/assets/javascripts/discourse/views/header.js.es6 b/app/assets/javascripts/discourse/views/header.js.es6 index add2ce107e2..eb5ebec50fe 100644 --- a/app/assets/javascripts/discourse/views/header.js.es6 +++ b/app/assets/javascripts/discourse/views/header.js.es6 @@ -10,7 +10,7 @@ export default Ember.View.extend({ // Check the dock after the current run loop. While rendering, // it's much slower to calculate `outlet.offset()` Ember.run.next(() => { - if (!this.docAt) { + if (this.docAt === undefined) { const outlet = $('#main-outlet'); if (!(outlet && outlet.length === 1)) return; this.docAt = outlet.offset().top; diff --git a/app/assets/stylesheets/mobile/compose.scss b/app/assets/stylesheets/mobile/compose.scss index 592fa4b27d4..d63afa772de 100644 --- a/app/assets/stylesheets/mobile/compose.scss +++ b/app/assets/stylesheets/mobile/compose.scss @@ -26,6 +26,7 @@ input { line-height: 3em; } #mobile-uploader { display: none; } + .mobile-file-upload.hidden { display: none; } #draft-status, #file-uploading, .mobile-file-upload { display: inline-block; } transition: height .4s ease; width: 100%;