SG has uploaded a new change for review. https://gerrit.wikimedia.org/r/116753
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(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow refs/changes/53/116753/1 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: newchange Gerrit-Change-Id: I60ef74dfa061126697bcadb8e83844a60e0aa55a Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Flow Gerrit-Branch: master Gerrit-Owner: SG <shah...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits