2018-01-12 21:09:10 +03:00
|
|
|
/* global key */
|
2022-02-07 19:53:12 +03:00
|
|
|
import Component from '@glimmer/component';
|
|
|
|
import {action} from '@ember/object';
|
2017-10-30 12:38:01 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2022-02-07 19:53:12 +03:00
|
|
|
import {tracked} from '@glimmer/tracking';
|
2017-08-02 10:05:59 +03:00
|
|
|
|
|
|
|
const ONE_COLUMN_WIDTH = 540;
|
|
|
|
const TWO_COLUMN_WIDTH = 940;
|
|
|
|
|
2022-02-07 19:53:12 +03:00
|
|
|
export default class GhUnsplash extends Component {
|
|
|
|
@service unsplash;
|
|
|
|
@service ui;
|
2017-08-02 10:05:59 +03:00
|
|
|
|
2022-02-07 19:53:12 +03:00
|
|
|
@tracked zoomedPhoto = null;
|
|
|
|
@tracked searchTerm = null;
|
2017-08-02 10:05:59 +03:00
|
|
|
|
2022-02-07 19:53:12 +03:00
|
|
|
get sideNavHidden() {
|
|
|
|
return this.ui.isFullScreen || this.ui.showMobileMenu;
|
|
|
|
}
|
2017-08-02 10:05:59 +03:00
|
|
|
|
2022-02-07 19:53:12 +03:00
|
|
|
constructor() {
|
|
|
|
super(...arguments);
|
|
|
|
key.setScope('unsplash');
|
|
|
|
}
|
2017-08-02 10:05:59 +03:00
|
|
|
|
2022-02-07 19:53:12 +03:00
|
|
|
willDestroy() {
|
|
|
|
super.willDestroy(...arguments);
|
|
|
|
key.setScope('default');
|
|
|
|
}
|
2017-11-24 21:53:19 +03:00
|
|
|
|
2022-02-07 19:53:12 +03:00
|
|
|
@action
|
|
|
|
loadNextPage() {
|
|
|
|
this.unsplash.loadNextPage();
|
|
|
|
}
|
2017-11-24 21:53:19 +03:00
|
|
|
|
2022-02-07 19:53:12 +03:00
|
|
|
@action
|
|
|
|
search(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
const term = event.target.value;
|
|
|
|
this.unsplash.updateSearch(term);
|
|
|
|
this.closeZoom();
|
|
|
|
}
|
2018-08-09 19:55:11 +03:00
|
|
|
|
2022-02-07 19:53:12 +03:00
|
|
|
@action
|
|
|
|
clearSearch(event, ekEvent) {
|
|
|
|
if (event.target.value) {
|
|
|
|
ekEvent.stopPropagation();
|
|
|
|
this.unsplash.updateSearch('');
|
2018-08-09 19:55:11 +03:00
|
|
|
}
|
2022-02-07 19:53:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
zoomPhoto(photo) {
|
|
|
|
this.zoomedPhoto = photo;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
closeZoom(event) {
|
|
|
|
event?.preventDefault?.();
|
|
|
|
this.zoomedPhoto = null;
|
|
|
|
}
|
2018-08-09 19:55:11 +03:00
|
|
|
|
2022-02-07 19:53:12 +03:00
|
|
|
@action
|
|
|
|
select(photo) {
|
|
|
|
this.unsplash.triggerDownload(photo);
|
|
|
|
|
|
|
|
let selectParams = {
|
|
|
|
src: photo.urls.regular.replace(/&w=1080/, '&w=2000'),
|
|
|
|
width: photo.width,
|
|
|
|
height: photo.height,
|
|
|
|
alt: photo.description || '',
|
|
|
|
caption: `Photo by <a href="${photo.user.links.html}?utm_source=ghost&utm_medium=referral&utm_campaign=api-credit">${photo.user.name}</a> / <a href="https://unsplash.com/?utm_source=ghost&utm_medium=referral&utm_campaign=api-credit">Unsplash</a>`
|
|
|
|
};
|
|
|
|
this.args.select(selectParams);
|
|
|
|
|
|
|
|
this.args.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
retry(event) {
|
|
|
|
event?.preventDefault();
|
|
|
|
this.unsplash.retryLastRequest();
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
handleEscape(event) {
|
|
|
|
event?.preventDefault();
|
|
|
|
|
|
|
|
if (this.zoomedPhoto) {
|
|
|
|
return this.closeZoom();
|
2017-08-02 10:05:59 +03:00
|
|
|
}
|
|
|
|
|
2022-02-07 19:53:12 +03:00
|
|
|
this.args.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
handleResize(element) {
|
2017-08-02 10:05:59 +03:00
|
|
|
let width = element.clientWidth;
|
|
|
|
let columns = 3;
|
|
|
|
|
|
|
|
if (width <= ONE_COLUMN_WIDTH) {
|
|
|
|
columns = 1;
|
|
|
|
} else if (width <= TWO_COLUMN_WIDTH) {
|
|
|
|
columns = 2;
|
|
|
|
}
|
|
|
|
|
2019-03-06 16:53:54 +03:00
|
|
|
this.unsplash.changeColumnCount(columns);
|
2017-08-02 10:05:59 +03:00
|
|
|
}
|
2022-02-07 19:53:12 +03:00
|
|
|
}
|