2016-06-25 05:24:55 +00:00
|
|
|
/**
|
|
|
|
* Other common methods.
|
|
|
|
*/
|
2016-07-07 13:54:20 +00:00
|
|
|
import select from 'select';
|
2016-06-25 05:24:55 +00:00
|
|
|
import { event } from '../utils'
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load (display) a main panel (view).
|
|
|
|
*
|
2016-06-25 16:05:24 +00:00
|
|
|
* @param {String} view The view, which can be found under components/main-wrapper/main-content.
|
|
|
|
* @param {...*} Extra data to attach to the view.
|
2016-06-25 05:24:55 +00:00
|
|
|
*/
|
|
|
|
export function loadMainView(view, ...args) {
|
2016-06-25 16:05:24 +00:00
|
|
|
event.emit('main-content-view:load', view, ...args);
|
2016-06-25 05:24:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Force reloading window regardless of "Confirm before reload" setting.
|
|
|
|
* This is handy for certain cases, for example Last.fm connect/disconnect.
|
|
|
|
*/
|
|
|
|
export function forceReloadWindow() {
|
2016-06-25 16:05:24 +00:00
|
|
|
window.onbeforeunload = function() {};
|
|
|
|
window.location.reload();
|
2016-06-25 05:24:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load a playlist into the main panel.
|
|
|
|
*
|
|
|
|
* @param {Object} playlist The playlist object
|
|
|
|
*/
|
|
|
|
export function loadPlaylistView(playlist) {
|
2016-06-25 16:05:24 +00:00
|
|
|
loadMainView('playlist', playlist);
|
2016-06-25 05:24:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load the Favorites view.
|
|
|
|
*/
|
|
|
|
export function loadFavoritesView() {
|
2016-06-25 16:05:24 +00:00
|
|
|
loadMainView('favorites');
|
2016-06-25 05:24:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load an album into the main panel.
|
|
|
|
*
|
|
|
|
* @param {Object} album The album object
|
|
|
|
*/
|
|
|
|
export function loadAlbumView(album) {
|
2016-06-25 16:05:24 +00:00
|
|
|
loadMainView('album', album);
|
2016-06-25 05:24:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load an artist into the main panel.
|
|
|
|
*
|
|
|
|
* @param {Object} artist The artist object
|
|
|
|
*/
|
|
|
|
export function loadArtistView(artist) {
|
2016-06-25 16:05:24 +00:00
|
|
|
loadMainView('artist', artist);
|
2016-06-25 05:24:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the overlay.
|
2016-07-07 13:56:08 +00:00
|
|
|
*
|
2016-06-25 05:24:55 +00:00
|
|
|
* @param {String} message
|
|
|
|
* @param {String} type
|
|
|
|
* @param {Boolean} dismissable
|
|
|
|
*/
|
|
|
|
export function showOverlay(message = 'Just a little patience…', type = 'loading', dismissable = false) {
|
2016-06-25 16:05:24 +00:00
|
|
|
event.emit('overlay:show', { message, type, dismissable });
|
2016-06-25 05:24:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2016-07-07 13:54:20 +00:00
|
|
|
* Hide the overlay.
|
2016-06-25 05:24:55 +00:00
|
|
|
*/
|
|
|
|
export function hideOverlay() {
|
2016-06-25 16:05:24 +00:00
|
|
|
event.emit('overlay:hide');
|
2016-06-25 05:24:55 +00:00
|
|
|
};
|
2016-07-07 13:54:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy a text into clipboard.
|
|
|
|
*
|
|
|
|
* @param {string} txt
|
|
|
|
*/
|
|
|
|
export function copyText(txt) {
|
|
|
|
const copyArea = document.querySelector('#copyArea');
|
|
|
|
copyArea.style.top = (window.pageYOffset || document.documentElement.scrollTop) + 'px';
|
|
|
|
copyArea.value = txt;
|
|
|
|
select(copyArea);
|
|
|
|
document.execCommand('copy');
|
|
|
|
};
|