2022-02-08 13:13:18 +03:00
|
|
|
import Component from '@glimmer/component';
|
|
|
|
import {action} from '@ember/object';
|
2021-05-12 14:33:36 +03:00
|
|
|
import {htmlSafe} from '@ember/template';
|
2022-02-08 13:13:18 +03:00
|
|
|
import {tracked} from '@glimmer/tracking';
|
2017-08-02 10:05:59 +03:00
|
|
|
|
2022-02-08 13:13:18 +03:00
|
|
|
export default class GhUnsplashPhoto extends Component {
|
|
|
|
@tracked height = 0;
|
|
|
|
@tracked width = 1200;
|
2017-08-02 10:05:59 +03:00
|
|
|
|
2022-02-08 13:13:18 +03:00
|
|
|
get style() {
|
|
|
|
return htmlSafe(this.args.zoomed ? 'width: auto; margin: 0;' : '');
|
|
|
|
}
|
2018-08-09 16:15:47 +03:00
|
|
|
|
2017-08-02 10:05:59 +03:00
|
|
|
// avoid "binding style attributes" warnings
|
2022-02-08 13:13:18 +03:00
|
|
|
get containerStyle() {
|
|
|
|
const styles = [];
|
|
|
|
const ratio = this.args.photo.ratio;
|
|
|
|
const zoomed = this.args.zoomed;
|
2017-08-02 10:05:59 +03:00
|
|
|
|
2022-02-08 13:13:18 +03:00
|
|
|
styles.push(`background-color: ${this.args.photo.color}`);
|
2017-08-02 10:05:59 +03:00
|
|
|
|
2018-08-09 16:15:47 +03:00
|
|
|
if (zoomed) {
|
|
|
|
styles.push(`cursor: zoom-out`);
|
|
|
|
} else {
|
2017-08-02 10:05:59 +03:00
|
|
|
styles.push(`padding-bottom: ${ratio * 100}%`);
|
|
|
|
}
|
|
|
|
|
|
|
|
return htmlSafe(styles.join('; '));
|
2022-02-08 13:13:18 +03:00
|
|
|
}
|
2017-08-02 10:05:59 +03:00
|
|
|
|
2022-02-08 13:13:18 +03:00
|
|
|
get imageUrl() {
|
|
|
|
let url = this.args.photo.urls.regular;
|
2017-08-02 10:05:59 +03:00
|
|
|
|
2019-08-29 11:41:43 +03:00
|
|
|
url = url.replace('&w=1080', '&w=1200');
|
2017-08-02 10:05:59 +03:00
|
|
|
|
|
|
|
return url;
|
2022-02-08 13:13:18 +03:00
|
|
|
}
|
2017-08-02 10:05:59 +03:00
|
|
|
|
2022-02-08 13:13:18 +03:00
|
|
|
constructor() {
|
|
|
|
super(...arguments);
|
|
|
|
this.height = this.width * this.args.photo.ratio;
|
|
|
|
}
|
2018-08-09 16:15:47 +03:00
|
|
|
|
2022-02-08 13:13:18 +03:00
|
|
|
@action
|
|
|
|
select(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
this.args.select(this.args.photo);
|
|
|
|
}
|
2018-08-09 16:15:47 +03:00
|
|
|
|
2022-02-08 13:13:18 +03:00
|
|
|
@action
|
|
|
|
zoom(event) {
|
|
|
|
const {target} = event;
|
2017-08-02 10:05:59 +03:00
|
|
|
|
2022-02-08 13:13:18 +03:00
|
|
|
// only zoom when it wasn't one of the child links clicked
|
|
|
|
if (!target.matches('a') && target.closest('a').classList.contains('gh-unsplash-photo')) {
|
2017-08-02 10:05:59 +03:00
|
|
|
event.preventDefault();
|
2022-02-08 13:13:18 +03:00
|
|
|
this.args.zoom(this.args.photo);
|
2017-08-02 10:05:59 +03:00
|
|
|
}
|
2018-08-09 16:15:47 +03:00
|
|
|
|
2022-02-08 13:13:18 +03:00
|
|
|
// don't propagate otherwise we can trigger the closeZoom action on the overlay
|
|
|
|
event.stopPropagation();
|
2017-08-02 10:05:59 +03:00
|
|
|
}
|
2022-02-08 13:13:18 +03:00
|
|
|
}
|