Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML doc: navigate with left/right arrow keys #2064

Merged
merged 5 commits into from
Feb 8, 2016

Conversation

TimKam
Copy link
Member

@TimKam TimKam commented Oct 4, 2015

Adjusted basic theme's JS accordingly
Resolves #1970
Does not navigate by design when focus is on input field, i.e. the search field

Adjusted basic theme's JS accordingly
@birkenfeld
Copy link
Member

Sure, why not. Is binding the arrow keys for this purpose used anywhere else?

@TimKam
Copy link
Member Author

TimKam commented Oct 4, 2015

Sorry, I think I might not understand the question correctly, but let me try to answer:

  • There are no bindings for these keys in any Sphinx JS file.
  • There might be of course custom Sphinx themes implementing the same behavior.
  • There might also be custom templates that make use of the arrow keys for other actions.
  • From an UX point of view, I think it's pretty common behavior.

@keimlink
Copy link
Contributor

keimlink commented Oct 4, 2015

Great idea! 👍

if (!$(document.activeElement).is('input')) { //don't navigate when in search box
switch (event.keyCode) {
case 37: //left
var prevElement = $('link[rel="prev"]')[0];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be replaced by a call to $.prop('href')

@TimKam
Copy link
Member Author

TimKam commented Oct 9, 2015

Thanks for the feedback, I can follow/agree with all suggestions and will commit again later today or tomorrow.

@TimKam
Copy link
Member Author

TimKam commented Nov 7, 2015

@birkenfeld , @lehmannro : Can this be merged eventually?

@shimizukawa
Copy link
Member

I do not agree this feature by default.
Sometimes I face to such a page, but the navigation feature is bothering me because it is not intuitive to me.

@tk0miya
Copy link
Member

tk0miya commented Nov 15, 2015

I think this behavior is not common. I've never seen such pages.

@keimlink
Copy link
Contributor

Even if this may be an uncommon feature it will be helpful for users that know it exists. And it won't break any existing behavior. So it's primarily a question of people writing documentation to explain to their users that this feature exists and how it can be used. If someone uses a version of Sphinx that supports this feature and doesn't explain it nothing would break.

Because it doesn't break anything I would not recommend to deactivate it by default and introduce another setting to activate it. Sphinx has already a lot of quite useful options. So adding new ones should be carefully thought of to avoid getting a longer and longer options list.

initOnKeyListeners: function() {
$(document).keyup(function(event) {
var activeElementType = $(document.activeElement).prop('tagName');
if (activeElementType !== 'TEXTAREA' && activeElementType !== 'INPUT') { // don't navigate when in search box or textarea
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another thing that occurred to me: What about <select>?

Also: Please move the comment to another line to satisfy 80 columns requirement.

@lehmannro
Copy link
Contributor

I'm also in favor of merging this. I think we could easily make this configurable (move doctools.js to doctools.js_t for the templating engine to pick it up, only call the function if a default-True config value is set.)

I'll leave it to you if you want to do this, or if somebody else should take on making it configurable.

enable configuration via theme.conf
@shimizukawa
Copy link
Member

IMO, such behavior shouldn't be by default. I reluctantly agree if the feature is configurable and is disabled by default.

@jakobandersen
Copy link
Contributor

This is a quite nice feature for those that expect it. However it may be really annoying for those that are not used to it and accidentally hits left/right. Also, it breaks the normal sideways scrolling behaviour.
Therefore, please make it configurable for the user of the document, with the default set at build-time.

@TimKam
Copy link
Member Author

TimKam commented Jan 17, 2016

The navigation option is now non default and configurable in theme.conf.

Anything else that should be changed?

@lehmannro
Copy link
Contributor

LGTM! Thanks.

@shimizukawa shimizukawa added this to the 1.4 milestone Jan 19, 2016
@shimizukawa
Copy link
Member

LGTM. To merge into master, @TimKam please rebase to resolve conflict.

@tk0miya
Copy link
Member

tk0miya commented Feb 8, 2016

@shimizukawa It seems the confliction is already resolved.
Can I merge this?

@shimizukawa
Copy link
Member

@tk0miya Sure!

tk0miya added a commit that referenced this pull request Feb 8, 2016
HTML doc: navigate with left/right arrow keys
@tk0miya tk0miya merged commit 0b28ee7 into sphinx-doc:master Feb 8, 2016
@tk0miya
Copy link
Member

tk0miya commented Feb 8, 2016

Merged!
Thank you for contribution!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants