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
This commit is contained in:
Sam 2015-09-17 13:05:14 +10:00
parent faada383fa
commit e254030760
5 changed files with 7 additions and 19 deletions

View File

@ -1,5 +1,4 @@
function applicable() { function applicable() {
// This will apply hack on all iDevices // This will apply hack on all iDevices
return navigator.userAgent.match(/(iPad|iPhone|iPod)/g) && return navigator.userAgent.match(/(iPad|iPhone|iPod)/g) &&
navigator.userAgent.match(/Safari/g); navigator.userAgent.match(/Safari/g);
@ -15,7 +14,6 @@ function positioningWorkaround($fixedElement) {
var done = false; var done = false;
var originalScrollTop = 0; var originalScrollTop = 0;
var wasDocked;
var blurredNow = function(evt) { var blurredNow = function(evt) {
if (!done && _.include($(document.activeElement).parents(), fixedElement)) { if (!done && _.include($(document.activeElement).parents(), fixedElement)) {
@ -27,17 +25,12 @@ function positioningWorkaround($fixedElement) {
fixedElement.parentElement.style.height = ''; fixedElement.parentElement.style.height = '';
$('#main-outlet').show(); $('#main-outlet').show();
$('header').show();
fixedElement.style.position = ''; fixedElement.style.position = '';
fixedElement.style.top = ''; fixedElement.style.top = '';
fixedElement.style.height = ''; fixedElement.style.height = '';
$(window).scrollTop(originalScrollTop); $(window).scrollTop(originalScrollTop);
if (wasDocked) {
$('body').addClass('docked');
}
if (evt) { if (evt) {
evt.target.removeEventListener('blur', blurred); evt.target.removeEventListener('blur', blurred);
} }
@ -63,12 +56,8 @@ function positioningWorkaround($fixedElement) {
originalScrollTop = $(window).scrollTop(); originalScrollTop = $(window).scrollTop();
wasDocked = $('body').hasClass('docked');
// take care of body // take care of body
$('#main-outlet').hide(); $('#main-outlet').hide();
$('header').hide();
fixedElement.style.position = 'absolute'; fixedElement.style.position = 'absolute';
// get out of the way while opening keyboard // get out of the way while opening keyboard
@ -93,7 +82,7 @@ function positioningWorkaround($fixedElement) {
} }
const checkForInputs = _.debounce(function(){ 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) { if ($(elem).parents('.autocomplete').length > 0) {
return; return;
} }
@ -105,7 +94,7 @@ function positioningWorkaround($fixedElement) {
$(this).click(); $(this).click();
}); });
}); });
$fixedElement.find('input,textarea').each(function(){ $fixedElement.find('input[type=text],textarea').each(function(){
attachTouchStart(this, positioningHack); attachTouchStart(this, positioningHack);
}); });
}, 100); }, 100);

View File

@ -91,9 +91,7 @@
<div class="composer-bottom-right"> <div class="composer-bottom-right">
{{#if site.mobileView}} {{#if site.mobileView}}
<input type="file" id="mobile-uploader" /> <input type="file" id="mobile-uploader" />
{{#unless view.isUploading}} <a class="mobile-file-upload {{if view.isUploading 'hidden'}}">{{i18n 'upload'}}</a>
<a class="mobile-file-upload">{{i18n 'upload'}}</a>
{{/unless}}
{{else}} {{else}}
<a href {{action "togglePreview"}} class='toggle-preview'>{{{model.toggleText}}}</a> <a href {{action "togglePreview"}} class='toggle-preview'>{{{model.toggleText}}}</a>
{{/if}} {{/if}}

View File

@ -374,7 +374,7 @@ const ComposerView = Ember.View.extend(Ember.Evented, {
// add upload placeholder // add upload placeholder
const markdown = Discourse.Utilities.getUploadPlaceholder(data.files[0].name); const markdown = Discourse.Utilities.getUploadPlaceholder(data.files[0].name);
this.addMarkdown(markdown); this.addMarkdown(markdown);
//
if (data["xhr"]) { if (data["xhr"]) {
const jqHXR = data.xhr(); const jqHXR = data.xhr();
if (jqHXR) { if (jqHXR) {
@ -496,7 +496,7 @@ const ComposerView = Ember.View.extend(Ember.Evented, {
} }
if (Discourse.Mobile.mobileView) { 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 // redirect the click on the hidden file input
$("#mobile-uploader").click(); $("#mobile-uploader").click();
}); });

View File

@ -10,7 +10,7 @@ export default Ember.View.extend({
// Check the dock after the current run loop. While rendering, // Check the dock after the current run loop. While rendering,
// it's much slower to calculate `outlet.offset()` // it's much slower to calculate `outlet.offset()`
Ember.run.next(() => { Ember.run.next(() => {
if (!this.docAt) { if (this.docAt === undefined) {
const outlet = $('#main-outlet'); const outlet = $('#main-outlet');
if (!(outlet && outlet.length === 1)) return; if (!(outlet && outlet.length === 1)) return;
this.docAt = outlet.offset().top; this.docAt = outlet.offset().top;

View File

@ -26,6 +26,7 @@ input {
line-height: 3em; line-height: 3em;
} }
#mobile-uploader { display: none; } #mobile-uploader { display: none; }
.mobile-file-upload.hidden { display: none; }
#draft-status, #file-uploading, .mobile-file-upload { display: inline-block; } #draft-status, #file-uploading, .mobile-file-upload { display: inline-block; }
transition: height .4s ease; transition: height .4s ease;
width: 100%; width: 100%;