From 424bb143dbc5c1805139b3277b9409f391e48d66 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 26 Jul 2016 15:08:04 -0400 Subject: [PATCH] FIX: Jump to post on iOS was broken - replace with prompt --- .../components/topic-progress.js.es6 | 41 +++++++++++-------- .../templates/components/topic-progress.hbs | 13 ++++-- app/assets/stylesheets/desktop/topic.scss | 4 ++ config/locales/client.en.yml | 2 + 4 files changed, 39 insertions(+), 21 deletions(-) diff --git a/app/assets/javascripts/discourse/components/topic-progress.js.es6 b/app/assets/javascripts/discourse/components/topic-progress.js.es6 index 94c99908af5..86533ed6a65 100644 --- a/app/assets/javascripts/discourse/components/topic-progress.js.es6 +++ b/app/assets/javascripts/discourse/components/topic-progress.js.es6 @@ -168,17 +168,29 @@ export default Ember.Component.extend({ } }, + _jumpTo(postIndex) { + postIndex = parseInt(postIndex, 10); + + // Validate the post index first + if (isNaN(postIndex) || postIndex < 1) { + postIndex = 1; + } + if (postIndex > this.get('postStream.filteredPostsCount')) { + postIndex = this.get('postStream.filteredPostsCount'); + } + this.set('toPostIndex', postIndex); + this._beforeJump(); + this.sendAction('jumpToIndex', postIndex); + }, + actions: { toggleExpansion(opts) { this.toggleProperty('expanded'); if (this.get('expanded')) { this.set('userWantsToJump', false); this.set('toPostIndex', this.get('progressPosition')); - if(opts && opts.highlight){ - // TODO: somehow move to view? - Em.run.next(function(){ - $('.jump-form input').select().focus(); - }); + if (opts && opts.highlight) { + Ember.run.next(() => $('.jump-form input').select().focus()); } if (!this.site.mobileView && !this.capabilities.isIOS) { Ember.run.schedule('afterRender', () => this.$('input').focus()); @@ -186,19 +198,14 @@ export default Ember.Component.extend({ } }, - jumpPost() { - let postIndex = parseInt(this.get('toPostIndex'), 10); + jumpPrompt() { + const postIndex = prompt(I18n.t('topic.progress.jump_prompt_long')); + if (postIndex === null) { return; } + this._jumpTo(postIndex); + }, - // Validate the post index first - if (isNaN(postIndex) || postIndex < 1) { - postIndex = 1; - } - if (postIndex > this.get('postStream.filteredPostsCount')) { - postIndex = this.get('postStream.filteredPostsCount'); - } - this.set('toPostIndex', postIndex); - this._beforeJump(); - this.sendAction('jumpToIndex', postIndex); + jumpPost() { + this._jumpTo(this.get('toPostIndex')); }, jumpTop() { diff --git a/app/assets/javascripts/discourse/templates/components/topic-progress.hbs b/app/assets/javascripts/discourse/templates/components/topic-progress.hbs index 55658fc3a40..a840c135645 100644 --- a/app/assets/javascripts/discourse/templates/components/topic-progress.hbs +++ b/app/assets/javascripts/discourse/templates/components/topic-progress.hbs @@ -6,10 +6,15 @@ class="full no-text" icon="caret-up" label="topic.progress.go_top"}} -
- {{input value=toPostIndex}} - {{d-button action="jumpPost" label="topic.progress.go"}} -
+ {{#unless capabilities.isIOS}} +
+ {{input value=toPostIndex}} + {{d-button action="jumpPost" label="topic.progress.go"}} +
+ {{else}} + {{d-button action="jumpPrompt" class="full jump-prompt" label="topic.progress.jump_prompt"}} + {{/unless}} + {{d-button action="jumpBottom" disabled=jumpBottomDisabled class="full no-text jump-bottom" diff --git a/app/assets/stylesheets/desktop/topic.scss b/app/assets/stylesheets/desktop/topic.scss index d14ca18d0ab..571649f60a7 100644 --- a/app/assets/stylesheets/desktop/topic.scss +++ b/app/assets/stylesheets/desktop/topic.scss @@ -133,6 +133,10 @@ width: 55px; } } + button.btn.jump-prompt { + margin: 0; + } + button.btn.jump-bottom { margin: 5px 0 0 0; } diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 1941b72499c..532b7777809 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -1349,6 +1349,8 @@ en: go_bottom: "bottom" go: "go" jump_bottom: "jump to last post" + jump_prompt: "jump to post" + jump_prompt_long: "What post would you like to jump to?" jump_bottom_with_number: "jump to post %{post_number}" total: total posts current: current post