koel/resources/assets/js/utils/supports.js

79 lines
1.4 KiB
JavaScript
Raw Normal View History

2016-11-26 03:25:35 +00:00
import isMobile from 'ismobilejs'
2016-06-25 05:24:55 +00:00
import Vue from 'vue'
2017-01-15 16:20:55 +00:00
import { each } from 'lodash'
/**
* Check if AudioContext is supported by the current browser.
*
* @return {Boolean}
*/
2016-11-26 03:25:35 +00:00
export function isAudioContextSupported () {
2016-06-25 16:05:24 +00:00
// Apple device just doesn't love AudioContext that much.
if (isMobile.apple.device) {
2016-11-26 03:25:35 +00:00
return false
2016-06-25 16:05:24 +00:00
}
2016-06-25 16:05:24 +00:00
const AudioContext = (window.AudioContext ||
window.webkitAudioContext ||
window.mozAudioContext ||
window.oAudioContext ||
2016-11-26 03:25:35 +00:00
window.msAudioContext)
2016-06-25 16:05:24 +00:00
if (!AudioContext) {
2016-11-26 03:25:35 +00:00
return false
2016-06-25 16:05:24 +00:00
}
2016-06-25 16:05:24 +00:00
// Safari (MacOS & iOS alike) has webkitAudioContext, but is buggy.
// @link http://caniuse.com/#search=audiocontext
if (!(new AudioContext()).createMediaElementSource) {
2016-11-26 03:25:35 +00:00
return false
2016-06-25 16:05:24 +00:00
}
2016-11-26 03:25:35 +00:00
return true
}
2016-06-25 05:24:55 +00:00
2016-07-07 13:54:20 +00:00
/**
* Checks if HTML5 clipboard can be used.
*
* @return {Boolean}
*/
2016-11-26 03:25:35 +00:00
export function isClipboardSupported () {
return 'execCommand' in document
}
2016-06-25 05:24:55 +00:00
2016-07-07 13:56:08 +00:00
/**
* A simple event bus.
*
* @type {Object}
*/
2016-06-25 05:24:55 +00:00
const event = {
2016-06-25 16:05:24 +00:00
bus: null,
2016-06-25 05:24:55 +00:00
2016-11-26 03:25:35 +00:00
init () {
2016-06-25 16:05:24 +00:00
if (!this.bus) {
2016-11-26 03:25:35 +00:00
this.bus = new Vue()
2016-06-25 16:05:24 +00:00
}
2016-06-25 05:24:55 +00:00
2016-11-26 03:25:35 +00:00
return this
2016-06-25 16:05:24 +00:00
},
2016-06-25 05:24:55 +00:00
2016-11-26 03:25:35 +00:00
emit (name, ...args) {
this.bus.$emit(name, ...args)
return this
2016-06-25 16:05:24 +00:00
},
2016-06-25 05:24:55 +00:00
2016-11-26 03:25:35 +00:00
on () {
2016-06-25 16:05:24 +00:00
if (arguments.length === 2) {
2016-11-26 03:25:35 +00:00
this.bus.$on(arguments[0], arguments[1])
2016-06-25 16:05:24 +00:00
} else {
2017-01-15 16:20:55 +00:00
each(Object.keys(arguments[0]), key => {
2016-11-26 03:25:35 +00:00
this.bus.$on(key, arguments[0][key])
})
2016-06-25 16:05:24 +00:00
}
2016-06-25 05:24:55 +00:00
2016-11-26 03:25:35 +00:00
return this
}
2016-06-25 05:24:55 +00:00
}
2016-11-26 03:25:35 +00:00
export { event }