350e3d1481
closes https://github.com/TryGhost/Ghost/issues/8859, requires https://github.com/TryGhost/Ghost/pull/8895 - adds Unsplash app to app settings - enable/disable toggle - validation and testing of Unsplash App ID - Unsplash App ID field hidden if provided via Ghost config - adds `fetchPrivate` method to `config` service to pull config that requires authentication and updates authentication routines to fetch private config - adds Unsplash buttons to editor toolbar and `{{gh-image-uploader}}` - only present when Unsplash app is enabled - opens Unsplash image selector when clicked - `{{gh-image-uploader}}` has a new `allowUnsplash` attribute to control display of the unsplash button on a per-uploader basis - adds Unsplash image selector (`{{gh-unsplash}}`) - uses new `unsplash` service to handle API requests and maintain state - search - infinite scroll - zoom image - insert image - download image - adds `{{gh-scroll-trigger}}` that will fire an event when the component is rendered into or enters the visible screen area via scrolling - updates `ui` service - adds `isFullscreen` property and updates `gh-editor` so that it gets set/unset when toggling editor fullscreen mode - adds `hasSideNav` and `isSideNavHidden` properties - updates `media-queries` service so that it fires an event each time a breakpoint is entered/exited - removes the need for observers in certain circumstances
50 lines
1.3 KiB
JavaScript
50 lines
1.3 KiB
JavaScript
import Evented from '@ember/object/evented';
|
|
import Service from '@ember/service';
|
|
import {run} from '@ember/runloop';
|
|
|
|
const MEDIA_QUERIES = {
|
|
maxWidth600: '(max-width: 600px)',
|
|
isMobile: '(max-width: 800px)',
|
|
maxWidth900: '(max-width: 900px)',
|
|
maxWidth1000: '(max-width: 1000px)'
|
|
};
|
|
|
|
export default Service.extend(Evented, {
|
|
init() {
|
|
this._super(...arguments);
|
|
this._handlers = [];
|
|
this.loadQueries(MEDIA_QUERIES);
|
|
},
|
|
|
|
loadQueries(queries) {
|
|
Object.keys(queries).forEach((key) => {
|
|
this.loadQuery(key, queries[key]);
|
|
});
|
|
},
|
|
|
|
loadQuery(key, queryString) {
|
|
let query = window.matchMedia(queryString);
|
|
|
|
this.set(key, query.matches);
|
|
|
|
let handler = run.bind(this, () => {
|
|
let lastValue = this.get(key);
|
|
let newValue = query.matches;
|
|
if (lastValue !== newValue) {
|
|
this.set(key, newValue);
|
|
this.trigger('change', key, newValue);
|
|
}
|
|
});
|
|
query.addListener(handler);
|
|
this._handlers.push([query, handler]);
|
|
},
|
|
|
|
willDestroy() {
|
|
this._handlers.forEach(([query, handler]) => {
|
|
query.removeListener(handler);
|
|
});
|
|
this._super(...arguments);
|
|
}
|
|
|
|
});
|