2016-06-24 15:55:44 +00:00
|
|
|
import isMobile from 'ismobilejs';
|
2016-06-25 05:24:55 +00:00
|
|
|
import Vue from 'vue'
|
2016-06-24 15:55:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if AudioContext is supported by the current browser.
|
|
|
|
*
|
|
|
|
* @return {Boolean}
|
|
|
|
*/
|
|
|
|
export function isAudioContextSupported() {
|
2016-06-25 16:05:24 +00:00
|
|
|
// Apple device just doesn't love AudioContext that much.
|
|
|
|
if (isMobile.apple.device) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-06-24 15:55:44 +00:00
|
|
|
|
2016-06-25 16:05:24 +00:00
|
|
|
const AudioContext = (window.AudioContext ||
|
|
|
|
window.webkitAudioContext ||
|
|
|
|
window.mozAudioContext ||
|
|
|
|
window.oAudioContext ||
|
|
|
|
window.msAudioContext);
|
2016-06-24 15:55:44 +00:00
|
|
|
|
2016-06-25 16:05:24 +00:00
|
|
|
if (!AudioContext) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-06-24 15:55:44 +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) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-06-24 15:55:44 +00:00
|
|
|
|
2016-06-25 16:05:24 +00:00
|
|
|
return true;
|
2016-06-24 15:55:44 +00:00
|
|
|
};
|
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}
|
|
|
|
*/
|
|
|
|
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-06-25 16:05:24 +00:00
|
|
|
init() {
|
|
|
|
if (!this.bus) {
|
|
|
|
this.bus = new Vue();
|
|
|
|
}
|
2016-06-25 05:24:55 +00:00
|
|
|
|
2016-06-25 16:05:24 +00:00
|
|
|
return this;
|
|
|
|
},
|
2016-06-25 05:24:55 +00:00
|
|
|
|
2016-06-25 16:05:24 +00:00
|
|
|
emit(name, ...args) {
|
|
|
|
this.bus.$emit(name, ...args);
|
|
|
|
return this;
|
|
|
|
},
|
2016-06-25 05:24:55 +00:00
|
|
|
|
2016-06-25 16:05:24 +00:00
|
|
|
on() {
|
|
|
|
if (arguments.length === 2) {
|
|
|
|
this.bus.$on(arguments[0], arguments[1]);
|
|
|
|
} else {
|
|
|
|
Object.keys(arguments[0]).forEach(key => {
|
|
|
|
this.bus.$on(key, arguments[0][key]);
|
|
|
|
});
|
|
|
|
}
|
2016-06-25 05:24:55 +00:00
|
|
|
|
2016-06-25 16:05:24 +00:00
|
|
|
return this;
|
|
|
|
},
|
2016-06-25 05:24:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export { event };
|