2019-02-07 12:39:55 +03:00
|
|
|
import { Component } from 'preact';
|
2019-02-26 06:09:16 +03:00
|
|
|
import { IconClose, GhostLogo } from './icons';
|
2019-02-07 12:39:55 +03:00
|
|
|
|
|
|
|
export default class Pages extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = this.getStateFromBrowser();
|
|
|
|
window.addEventListener("hashchange", () => this.onHashChange(), false);
|
2019-02-15 11:35:03 +03:00
|
|
|
this.handleChange = props.onChange || (() => { });
|
2019-02-07 12:39:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
getStateFromBrowser() {
|
|
|
|
const [fullMatch, hash, query] = window.location.hash.match(/^#([^?]+)\??(.*)$/) || ['#', '', ''];
|
|
|
|
return {
|
|
|
|
hash,
|
|
|
|
query,
|
|
|
|
fullMatch
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
onHashChange() {
|
|
|
|
this.setState(this.getStateFromBrowser());
|
|
|
|
this.handleChange();
|
|
|
|
}
|
|
|
|
|
|
|
|
filterChildren(children, state) {
|
|
|
|
return children.filter((child) => {
|
|
|
|
return child.attributes.hash === state.hash;
|
|
|
|
}).map((child) => {
|
|
|
|
child.attributes.frameLocation = { ...this.state };
|
|
|
|
return child;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-02-26 06:09:16 +03:00
|
|
|
render({ children, className, onClick, stripeConfig, siteConfig }, state) {
|
2019-02-15 11:35:03 +03:00
|
|
|
let modalClassName = "gm-modal gm-auth-modal";
|
|
|
|
if (state.hash === 'signup' && stripeConfig) {
|
|
|
|
modalClassName += " gm-subscribe-modal"
|
|
|
|
}
|
2019-02-26 06:09:16 +03:00
|
|
|
let iconUrl = siteConfig && siteConfig.icon;
|
|
|
|
let title = (siteConfig && siteConfig.title) || "Ghost Publication";
|
|
|
|
let iconStyle = iconUrl ? {
|
|
|
|
backgroundImage: `url(${iconUrl})`,
|
|
|
|
backgroundSize: `38px`
|
|
|
|
} : {};
|
2019-02-07 12:39:55 +03:00
|
|
|
return (
|
2019-04-17 17:34:14 +03:00
|
|
|
<div className={ className } onClick={ onClick }>
|
2019-02-26 06:09:16 +03:00
|
|
|
<div className="gm-modal-header">
|
|
|
|
<div className="gm-logo" style={iconStyle}></div>
|
|
|
|
<h2>{title}</h2>
|
|
|
|
</div>
|
|
|
|
<div className="gm-modal-close" onClick={ onClick }>{IconClose}</div>
|
2019-02-15 11:35:03 +03:00
|
|
|
<div className="gm-modal-container">
|
|
|
|
<div className={modalClassName} onClick={(e) => e.stopPropagation()}>
|
|
|
|
{this.filterChildren(children, state)}
|
|
|
|
</div>
|
2019-04-16 18:36:37 +03:00
|
|
|
<div className="gm-powered-by">
|
|
|
|
<a href="https://ghost.org" target="_blank"><span>Powered by</span> { GhostLogo }</a>
|
|
|
|
</div>
|
2019-02-26 06:09:16 +03:00
|
|
|
</div>
|
2019-02-07 12:39:55 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|