2016-07-13 12:44:24 -08:00
|
|
|
import React from 'react';
|
2016-09-21 06:27:11 -08:00
|
|
|
|
2016-07-13 12:44:24 -08:00
|
|
|
import Component from '../component';
|
2016-09-21 06:27:11 -08:00
|
|
|
import {decorate, getTabsProps} from '../utils/plugins';
|
|
|
|
|
|
|
|
|
|
import Tabs_ from './tabs';
|
2016-07-13 12:44:24 -08:00
|
|
|
|
|
|
|
|
const Tabs = decorate(Tabs_, 'Tabs');
|
|
|
|
|
|
|
|
|
|
export default class Header extends Component {
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
constructor() {
|
2016-07-13 12:44:24 -08:00
|
|
|
super();
|
|
|
|
|
this.onChangeIntent = this.onChangeIntent.bind(this);
|
2016-09-21 06:27:11 -08:00
|
|
|
this.handleHeaderClick = this.handleHeaderClick.bind(this);
|
|
|
|
|
this.handleHeaderMouseDown = this.handleHeaderMouseDown.bind(this);
|
2016-07-13 12:44:24 -08:00
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
onChangeIntent(active) {
|
2016-07-13 12:44:24 -08:00
|
|
|
// we ignore clicks if they're a byproduct of a drag
|
|
|
|
|
// motion to move the window
|
|
|
|
|
if (window.screenX !== this.headerMouseDownWindowX ||
|
|
|
|
|
window.screenY !== this.headerMouseDownWindowY) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.props.onChangeTab(active);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-03 18:00:50 -08:00
|
|
|
handleHeaderMouseDown(ev) {
|
|
|
|
|
// the hack of all hacks, this prevents the term
|
|
|
|
|
// iframe from losing focus, for example, when
|
|
|
|
|
// the user drags the nav around
|
|
|
|
|
ev.preventDefault();
|
|
|
|
|
|
|
|
|
|
// persist start positions of a potential drag motion
|
|
|
|
|
// to differentiate dragging from clicking
|
2016-07-13 12:44:24 -08:00
|
|
|
this.headerMouseDownWindowX = window.screenX;
|
|
|
|
|
this.headerMouseDownWindowY = window.screenY;
|
2016-08-06 02:01:01 -08:00
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
handleHeaderClick(event) {
|
2016-08-06 02:01:01 -08:00
|
|
|
this.clicks = this.clicks || 0;
|
2016-07-13 12:44:24 -08:00
|
|
|
|
2016-08-06 02:01:01 -08:00
|
|
|
// Reset clicks if mouse moved between clicks
|
|
|
|
|
if (this.headerClickPointerX !== event.clientX ||
|
|
|
|
|
this.headerClickPointerY !== event.clientY) {
|
|
|
|
|
this.clicks = 0;
|
|
|
|
|
clearTimeout(this.clickTimer);
|
2016-07-13 12:44:24 -08:00
|
|
|
|
2016-08-06 02:01:01 -08:00
|
|
|
this.headerClickPointerX = event.clientX;
|
|
|
|
|
this.headerClickPointerY = event.clientY;
|
|
|
|
|
}
|
|
|
|
|
if (++this.clicks === 2) {
|
|
|
|
|
if (this.props.maximized) {
|
|
|
|
|
this.props.unmaximize();
|
2016-07-13 12:44:24 -08:00
|
|
|
} else {
|
2016-08-06 02:01:01 -08:00
|
|
|
this.props.maximize();
|
2016-07-13 12:44:24 -08:00
|
|
|
}
|
|
|
|
|
this.clicks = 0;
|
2016-08-06 02:01:01 -08:00
|
|
|
clearTimeout(this.clickTimer);
|
2016-07-13 12:44:24 -08:00
|
|
|
} else {
|
|
|
|
|
// http://www.quirksmode.org/dom/events/click.html
|
|
|
|
|
// https://en.wikipedia.org/wiki/Double-click
|
|
|
|
|
this.clickTimer = setTimeout(() => {
|
|
|
|
|
this.clicks = 0;
|
|
|
|
|
}, 500);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
componentWillUnmount() {
|
2016-07-13 12:44:24 -08:00
|
|
|
delete this.clicks;
|
|
|
|
|
clearTimeout(this.clickTimer);
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
template(css) {
|
|
|
|
|
const {isMac} = this.props;
|
2016-07-13 12:44:24 -08:00
|
|
|
const props = getTabsProps(this.props, {
|
|
|
|
|
tabs: this.props.tabs,
|
|
|
|
|
borderColor: this.props.borderColor,
|
|
|
|
|
onClose: this.props.onCloseTab,
|
|
|
|
|
onChange: this.onChangeIntent
|
|
|
|
|
});
|
2016-09-21 06:27:11 -08:00
|
|
|
return (<header
|
|
|
|
|
className={css('header', isMac && 'headerRounded')}
|
|
|
|
|
onClick={this.handleHeaderClick}
|
|
|
|
|
onMouseDown={this.handleHeaderMouseDown}
|
|
|
|
|
>
|
|
|
|
|
{ this.props.customChildrenBefore }
|
|
|
|
|
<Tabs {...props}/>
|
|
|
|
|
{ this.props.customChildren }
|
|
|
|
|
</header>);
|
2016-07-13 12:44:24 -08:00
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
styles() {
|
2016-07-13 12:44:24 -08:00
|
|
|
return {
|
|
|
|
|
header: {
|
|
|
|
|
position: 'fixed',
|
|
|
|
|
top: '1px',
|
|
|
|
|
left: '1px',
|
|
|
|
|
right: '1px',
|
|
|
|
|
zIndex: '100'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
headerRounded: {
|
2016-07-21 10:54:53 -08:00
|
|
|
borderTopLeftRadius: '4px',
|
|
|
|
|
borderTopRightRadius: '4px'
|
2016-07-13 12:44:24 -08:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|