2017-08-22 10:53:26 +03:00
|
|
|
import Component from '@ember/component';
|
2019-06-18 13:47:21 +03:00
|
|
|
import ShortcutsMixin from 'ghost-admin/mixins/shortcuts';
|
2017-05-29 21:50:03 +03:00
|
|
|
import calculatePosition from 'ember-basic-dropdown/utils/calculate-position';
|
2019-06-18 13:47:21 +03:00
|
|
|
import ctrlOrCmd from 'ghost-admin/utils/ctrl-or-cmd';
|
2019-06-24 18:33:21 +03:00
|
|
|
import {and, equal, match} from '@ember/object/computed';
|
2020-03-02 08:06:54 +03:00
|
|
|
import {computed} from '@ember/object';
|
2019-03-21 20:55:58 +03:00
|
|
|
import {getOwner} from '@ember/application';
|
2017-08-22 10:53:26 +03:00
|
|
|
import {htmlSafe} from '@ember/string';
|
2017-10-30 12:38:01 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2015-10-28 14:36:45 +03:00
|
|
|
|
2019-06-18 13:47:21 +03:00
|
|
|
export default Component.extend(ShortcutsMixin, {
|
2020-04-21 09:54:29 +03:00
|
|
|
billing: service(),
|
2017-10-30 12:38:01 +03:00
|
|
|
config: service(),
|
2020-01-30 18:35:36 +03:00
|
|
|
customViews: service(),
|
2017-10-30 12:38:01 +03:00
|
|
|
feature: service(),
|
|
|
|
ghostPaths: service(),
|
2020-01-30 18:35:36 +03:00
|
|
|
navigation: service(),
|
2019-03-21 20:55:58 +03:00
|
|
|
router: service(),
|
2017-10-30 12:38:01 +03:00
|
|
|
session: service(),
|
|
|
|
ui: service(),
|
2019-08-23 12:01:27 +03:00
|
|
|
whatsNew: service(),
|
2017-04-19 19:57:56 +03:00
|
|
|
|
2015-05-24 08:47:23 +03:00
|
|
|
tagName: 'nav',
|
|
|
|
classNames: ['gh-nav'],
|
|
|
|
|
2017-04-19 19:57:56 +03:00
|
|
|
iconStyle: '',
|
2015-05-24 08:47:23 +03:00
|
|
|
|
2019-06-18 13:47:21 +03:00
|
|
|
showSearchModal: false,
|
|
|
|
shortcuts: null,
|
|
|
|
|
2019-06-24 18:33:21 +03:00
|
|
|
isIntegrationRoute: match('router.currentRouteName', /^settings\.integration/),
|
|
|
|
isSettingsRoute: match('router.currentRouteName', /^settings/),
|
2019-06-18 13:47:21 +03:00
|
|
|
|
2019-03-21 21:08:57 +03:00
|
|
|
// HACK: {{link-to}} should be doing this automatically but there appears to
|
|
|
|
// be a bug in Ember that's preventing it from working immediately after login
|
2019-06-24 18:33:21 +03:00
|
|
|
isOnSite: equal('router.currentRouteName', 'site'),
|
|
|
|
|
|
|
|
showMenuExtension: and('config.clientExtensions.menu', 'session.user.isOwner'),
|
|
|
|
showDropdownExtension: and('config.clientExtensions.dropdown', 'session.user.isOwner'),
|
|
|
|
showScriptExtension: and('config.clientExtensions.script', 'session.user.isOwner'),
|
2020-03-02 08:06:54 +03:00
|
|
|
showBilling: computed.reads('config.billingUrl'),
|
2019-03-21 21:08:57 +03:00
|
|
|
|
2019-06-18 13:47:21 +03:00
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
2019-06-24 18:33:21 +03:00
|
|
|
|
2019-06-18 13:47:21 +03:00
|
|
|
let shortcuts = {};
|
|
|
|
|
|
|
|
shortcuts[`${ctrlOrCmd}+k`] = {action: 'toggleSearchModal'};
|
|
|
|
this.shortcuts = shortcuts;
|
|
|
|
},
|
|
|
|
|
2018-01-11 20:43:23 +03:00
|
|
|
// the menu has a rendering issue (#8307) when the the world is reloaded
|
|
|
|
// during an import which we have worked around by not binding the icon
|
|
|
|
// style directly. However we still need to keep track of changing icons
|
|
|
|
// so that we can refresh when a new icon is uploaded
|
|
|
|
didReceiveAttrs() {
|
|
|
|
this._setIconStyle();
|
|
|
|
},
|
|
|
|
|
2019-06-18 13:47:21 +03:00
|
|
|
didInsertElement() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this.registerShortcuts();
|
|
|
|
},
|
|
|
|
|
|
|
|
willDestroyElement() {
|
|
|
|
this.removeShortcuts();
|
|
|
|
this._super(...arguments);
|
|
|
|
},
|
|
|
|
|
2019-03-21 20:55:58 +03:00
|
|
|
actions: {
|
|
|
|
transitionToOrRefreshSite() {
|
|
|
|
let {currentRouteName} = this.router;
|
|
|
|
if (currentRouteName === 'site') {
|
|
|
|
getOwner(this).lookup(`route:${currentRouteName}`).refresh();
|
|
|
|
} else {
|
|
|
|
this.router.transitionTo('site');
|
|
|
|
}
|
2019-06-18 13:47:21 +03:00
|
|
|
},
|
|
|
|
toggleSearchModal() {
|
|
|
|
this.toggleProperty('showSearchModal');
|
2020-04-09 08:26:11 +03:00
|
|
|
},
|
|
|
|
toggleBillingModal() {
|
2020-05-22 05:44:37 +03:00
|
|
|
this.billing.openBillingWindow(this.router.currentURL);
|
2019-03-21 20:55:58 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-04-05 17:26:01 +03:00
|
|
|
// equivalent to "left: auto; right: -20px"
|
|
|
|
userDropdownPosition(trigger, dropdown) {
|
|
|
|
let {horizontalPosition, verticalPosition, style} = calculatePosition(...arguments);
|
|
|
|
let {width: dropdownWidth} = dropdown.firstElementChild.getBoundingClientRect();
|
|
|
|
|
|
|
|
style.right += (dropdownWidth - 20);
|
|
|
|
style['z-index'] = 1100;
|
|
|
|
|
|
|
|
return {horizontalPosition, verticalPosition, style};
|
|
|
|
},
|
|
|
|
|
2017-04-19 19:57:56 +03:00
|
|
|
_setIconStyle() {
|
2019-03-06 16:53:54 +03:00
|
|
|
let icon = this.icon;
|
2017-04-19 19:57:56 +03:00
|
|
|
|
|
|
|
if (icon === this._icon) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-25 13:55:25 +03:00
|
|
|
this._icon = icon;
|
|
|
|
|
|
|
|
if (icon && icon.match(/^https?:\/\//i)) {
|
|
|
|
this.set('iconStyle', htmlSafe(`background-image: url(${icon})`));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-19 19:57:56 +03:00
|
|
|
let subdirRegExp = new RegExp(`^${this.get('ghostPaths.subdir')}`);
|
|
|
|
let blogIcon = icon ? icon : 'favicon.ico';
|
|
|
|
let iconUrl;
|
|
|
|
|
|
|
|
blogIcon = blogIcon.replace(subdirRegExp, '');
|
|
|
|
|
|
|
|
iconUrl = this.get('ghostPaths.url').join(this.get('config.blogUrl'), blogIcon).replace(/\/$/, '');
|
|
|
|
iconUrl += `?t=${(new Date()).valueOf()}`;
|
|
|
|
|
|
|
|
this.set('iconStyle', htmlSafe(`background-image: url(${iconUrl})`));
|
2015-05-24 08:47:23 +03:00
|
|
|
}
|
|
|
|
});
|