FIX: Better `metaKey` support for menu panels
This commit is contained in:
parent
e53d9f0e8b
commit
12e0225c51
|
@ -1,9 +1,10 @@
|
|||
import computed from 'ember-addons/ember-computed-decorators';
|
||||
import { iconHTML } from 'discourse/helpers/fa-icon';
|
||||
import DiscourseURL from 'discourse/lib/url';
|
||||
import interceptClick from 'discourse/lib/intercept-click';
|
||||
|
||||
export default Ember.Component.extend({
|
||||
tagName: 'a',
|
||||
classNames: ['d-link'],
|
||||
attributeBindings: ['translatedTitle:title', 'translatedTitle:aria-title', 'href'],
|
||||
|
||||
@computed('path')
|
||||
|
@ -27,18 +28,14 @@ export default Ember.Component.extend({
|
|||
if (text) return I18n.t(text);
|
||||
},
|
||||
|
||||
click() {
|
||||
click(e) {
|
||||
const action = this.get('action');
|
||||
if (action) {
|
||||
this.sendAction('action');
|
||||
return false;
|
||||
}
|
||||
const href = this.get('href');
|
||||
if (href) {
|
||||
DiscourseURL.routeTo(href);
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
|
||||
return interceptClick(e);
|
||||
},
|
||||
|
||||
render(buffer) {
|
||||
|
|
|
@ -156,7 +156,8 @@ export default Ember.Component.extend({
|
|||
|
||||
@on('didInsertElement')
|
||||
_bindEvents() {
|
||||
this.$().on('click.discourse-menu-panel', 'a', (e) => {
|
||||
this.$().on('click.discourse-menu-panel', 'a', e => {
|
||||
if (e.metaKey) { return; }
|
||||
if ($(e.target).data('ember-action')) { return; }
|
||||
this.hide();
|
||||
});
|
||||
|
@ -164,7 +165,7 @@ export default Ember.Component.extend({
|
|||
this.appEvents.on('dropdowns:closeAll', this, this.hide);
|
||||
this.appEvents.on('dom:clean', this, this.hide);
|
||||
|
||||
$('body').on('keydown.discourse-menu-panel', (e) => {
|
||||
$('body').on('keydown.discourse-menu-panel', e => {
|
||||
if (e.which === 27) {
|
||||
this.hide();
|
||||
}
|
||||
|
|
|
@ -1,37 +1,8 @@
|
|||
import DiscourseURL from 'discourse/lib/url';
|
||||
import interceptClick from 'discourse/lib/intercept-click';
|
||||
|
||||
/**
|
||||
Discourse does some server side rendering of HTML, such as the `cooked` contents of
|
||||
posts. The downside of this in an Ember app is the links will not go through the router.
|
||||
This jQuery code intercepts clicks on those links and routes them properly.
|
||||
**/
|
||||
export default {
|
||||
name: "click-interceptor",
|
||||
initialize: function() {
|
||||
$('#main').on('click.discourse', 'a', function(e) {
|
||||
if (e.isDefaultPrevented() || e.shiftKey || e.metaKey || e.ctrlKey) { return; }
|
||||
|
||||
var $currentTarget = $(e.currentTarget),
|
||||
href = $currentTarget.attr('href');
|
||||
|
||||
if (!href ||
|
||||
href === '#' ||
|
||||
$currentTarget.attr('target') ||
|
||||
$currentTarget.data('ember-action') ||
|
||||
$currentTarget.data('auto-route') ||
|
||||
$currentTarget.data('share-url') ||
|
||||
$currentTarget.data('user-card') ||
|
||||
$currentTarget.hasClass('mention') ||
|
||||
$currentTarget.hasClass('ember-view') ||
|
||||
$currentTarget.hasClass('lightbox') ||
|
||||
href.indexOf("mailto:") === 0 ||
|
||||
(href.match(/^http[s]?:\/\//i) && !href.match(new RegExp("^http:\\/\\/" + window.location.hostname, "i")))) {
|
||||
return;
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
DiscourseURL.routeTo(href);
|
||||
return false;
|
||||
});
|
||||
initialize() {
|
||||
$('#main').on('click.discourse', 'a', interceptClick);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
import DiscourseURL from 'discourse/lib/url';
|
||||
|
||||
/**
|
||||
Discourse does some server side rendering of HTML, such as the `cooked` contents of
|
||||
posts. The downside of this in an Ember app is the links will not go through the router.
|
||||
This jQuery code intercepts clicks on those links and routes them properly.
|
||||
**/
|
||||
export default function interceptClick(e) {
|
||||
if (e.isDefaultPrevented() || e.shiftKey || e.metaKey || e.ctrlKey) { return; }
|
||||
|
||||
const $currentTarget = $(e.currentTarget),
|
||||
href = $currentTarget.attr('href');
|
||||
|
||||
if (!href ||
|
||||
href === '#' ||
|
||||
$currentTarget.attr('target') ||
|
||||
$currentTarget.data('ember-action') ||
|
||||
$currentTarget.data('auto-route') ||
|
||||
$currentTarget.data('share-url') ||
|
||||
$currentTarget.data('user-card') ||
|
||||
$currentTarget.hasClass('mention') ||
|
||||
(!$currentTarget.hasClass('d-link') && $currentTarget.hasClass('ember-view')) ||
|
||||
$currentTarget.hasClass('lightbox') ||
|
||||
href.indexOf("mailto:") === 0 ||
|
||||
(href.match(/^http[s]?:\/\//i) && !href.match(new RegExp("^http:\\/\\/" + window.location.hostname, "i")))) {
|
||||
return;
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
DiscourseURL.routeTo(href);
|
||||
return false;
|
||||
}
|
Loading…
Reference in New Issue