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

nsqadmin: allow ctrl/meta+click to open new tab #841

Merged
merged 2 commits into from
Jan 1, 2017

Conversation

jehiah
Copy link
Member

@jehiah jehiah commented Dec 30, 2016

Often when browsing nsqadmin i want to ctrl+click something to compare two topics or channels in different tabs, but the current behaviour disables that capability.

This causes clicks to be handled normally by the browser when ctrl/meta is pressed instead of doing any fancy SPA navigation.

RFR @rolyatmax @mreiferson

@jehiah jehiah added the chore label Dec 30, 2016
@mreiferson
Copy link
Member

is it any good?

@jehiah
Copy link
Member Author

jehiah commented Dec 30, 2016

I only play a javascript developer on TV, but it seems to work for me.

if (e.ctrlKey || e.metaKey) {
// allow ctrl+click to open in a new tab
return true
}
e.preventDefault();
e.stopPropagation();

Choose a reason for hiding this comment

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

If you were stopping the event propagation so that the click isn't registered on another element, I'm guessing you'll still want to do that even when ctrl+clicking. Maybe move the stopPropagation above the if clause?

@@ -136,6 +136,10 @@ var AppView = BaseView.extend({
},

onLinkClick: function(e) {
if (e.ctrlKey || e.metaKey) {
// allow ctrl+click to open in a new tab
return true
Copy link

@rolyatmax rolyatmax Dec 30, 2016

Choose a reason for hiding this comment

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

I don't know if you actually need to return true here.

Also, semicolon usage and indentation isn't consistent with rest of file.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure i follow. Are you implying an empty return?

return false should stop the browser navigation to the href. That would mean clicking does nothing. return true (from experimentation) allows the browser to navigate and do a full page load on the href target (though because ctrl or meta, i expect the browser to be doing that in a new tab)

Why would i want to stopPropagation?

Copy link
Member Author

Choose a reason for hiding this comment

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

(also good call on missing semicolon)

Choose a reason for hiding this comment

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

I'm not sure i follow. Are you implying an empty return?

Yeah, I think it can just be an empty return. I believe jQuery only cares if you return false - in which case it's the same as calling stopPropagation and preventDefault. This might be helpful.

Why would i want to stopPropagation?

I'm not sure why it's being called right now. I'm just saying if there's a good reason to call it, it probably should be called even when ctrl-clicking. I'm assuming it's there for some reason, but I may be wrong. I'm not too familiar with this codebase.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed to return; I don't think we actually need stopPropagation so going to choose to omit that.

@jehiah jehiah force-pushed the nsqadmin_click_841 branch from 6abf7e3 to becb682 Compare January 1, 2017 19:31
@jehiah
Copy link
Member Author

jehiah commented Jan 1, 2017

RFM @mreiferson

@mreiferson mreiferson merged commit d497852 into nsqio:master Jan 1, 2017
@mreiferson mreiferson deleted the nsqadmin_click_841 branch January 1, 2017 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants