koel/resources/assets/js/utils/common.js

60 lines
1.4 KiB
JavaScript
Raw Normal View History

2016-06-25 05:24:55 +00:00
/**
* Other common methods.
*/
2016-11-26 03:25:35 +00:00
import select from 'select'
2017-10-02 23:01:37 +00:00
import { event } from '@/utils'
2016-06-25 05:24:55 +00:00
/**
* 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
*/
2016-11-26 03:25:35 +00:00
export function loadMainView (view, ...args) {
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.
*/
2016-11-26 03:25:35 +00:00
export function forceReloadWindow () {
2017-12-16 22:57:32 +00:00
if (window.__UNIT_TESTING__) {
return
}
2016-11-26 03:25:35 +00:00
window.onbeforeunload = function () {}
window.location.reload()
}
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
*/
2016-11-26 03:25:35 +00:00
export function showOverlay (message = 'Just a little patience…', type = 'loading', dismissable = false) {
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
*/
2016-11-26 03:25:35 +00:00
export function hideOverlay () {
event.emit('overlay:hide')
}
2016-07-07 13:54:20 +00:00
/**
* Copy a text into clipboard.
*
* @param {string} txt
*/
2016-11-26 03:25:35 +00:00
export function copyText (txt) {
const copyArea = document.querySelector('#copyArea')
2017-05-04 12:55:27 +00:00
copyArea.style.top = `${window.pageYOffset || document.documentElement.scrollTop}px`
2016-11-26 03:25:35 +00:00
copyArea.value = txt
select(copyArea)
document.execCommand('copy')
}