jenkins-bot has submitted this change and it was merged. Change subject: Make comment(n) link scroll to and focus reply form, instead of jumping Bug: 61344 ......................................................................
Make comment(n) link scroll to and focus reply form, instead of jumping Bug: 61344 Change-Id: I60ef74dfa061126697bcadb8e83844a60e0aa55a --- M modules/discussion/ui.js 1 file changed, 35 insertions(+), 4 deletions(-) Approvals: EBernhardson: Looks good to me, approved jenkins-bot: Verified diff --git a/modules/discussion/ui.js b/modules/discussion/ui.js index 287c24d..ba121fc 100644 --- a/modules/discussion/ui.js +++ b/modules/discussion/ui.js @@ -57,6 +57,30 @@ }, /** + * Scrolls to $anchor.href's hash target element (a div), + * and then focus onto the textarea within it. + * @param {jQuery} $anchor + */ + followFormAnchor: function ( $anchor ) { + var target = $anchor.attr( 'href' ), + index = target.indexOf('#'), + $target; + + // Does this href contain a hash? + if ( index > -1 ) { + $target = this.$container.find( target.substr(index) ); + // Does this element exist within our container? + if ( $target.length ) { + // Great, scroll to it and then focus. + $target.conditionalScrollIntoView().queue( function () { + mw.flow.editor.focus( $( this ).find( 'textarea' ) ); + $( this ).dequeue(); + } ); + } + } + }, + + /** * Initializes Tipsy on Flow */ setupTipsy: function () { @@ -302,12 +326,19 @@ var ignore = [ '.flow-edit-title-form', '.flow-actions', - '.flow-icon-watchlist', - '.flow-topic-comments-link' + '.flow-icon-watchlist' ].join( ',' ), - $topicContainer, $topicContainerChildren; + $topicContainer, $topicContainerChildren, + $target = $( event.target ); - if ( $( event.target ).is( ignore ) || $( event.target ).closest( ignore ).length ) { + // If the clicked element is the comment count link, go to the form and focus it + if ( $target.is( '.flow-topic-comments-link' ) ) { + event.preventDefault(); + mw.flow.discussion.followFormAnchor( $target ); + return; + } + + if ( $target.is( ignore ) || $target.closest( ignore ).length ) { return; } -- To view, visit https://gerrit.wikimedia.org/r/116753 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I60ef74dfa061126697bcadb8e83844a60e0aa55a Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Flow Gerrit-Branch: master Gerrit-Owner: SG <shah...@gmail.com> Gerrit-Reviewer: EBernhardson <ebernhard...@wikimedia.org> Gerrit-Reviewer: Matthias Mullie <mmul...@wikimedia.org> Gerrit-Reviewer: Spage <sp...@wikimedia.org> Gerrit-Reviewer: Werdna <agarr...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits