Moved console methods out of the root of the object

This commit is contained in:
Sam Potts 2017-11-09 20:01:13 +11:00
parent 66917fd39b
commit 4879bea4a0
11 changed files with 41 additions and 36 deletions

2
dist/plyr.js vendored

File diff suppressed because one or more lines are too long

2
dist/plyr.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -183,7 +183,7 @@ const captions = {
// Set new caption text
this.elements.captions.appendChild(content);
} else {
this.warn('No captions element to render to');
this.console.warn('No captions element to render to');
}
},

4
src/js/controls.js vendored
View File

@ -542,13 +542,13 @@ const controls = {
// Unsupported value
if (!this.options[setting].includes(value)) {
this.warn(`Unsupported value of '${value}' for ${setting}`);
this.console.warn(`Unsupported value of '${value}' for ${setting}`);
return;
}
// Disabled value
if (!this.config[setting].options.includes(value)) {
this.warn(`Disabled value of '${value}' for ${setting}`);
this.console.warn(`Disabled value of '${value}' for ${setting}`);
return;
}

View File

@ -108,12 +108,12 @@ const fullscreen = {
const nativeSupport = fullscreen.enabled;
if (nativeSupport || (this.config.fullscreen.fallback && !utils.inFrame())) {
this.log(`${nativeSupport ? 'Native' : 'Fallback'} fullscreen enabled`);
this.console.log(`${nativeSupport ? 'Native' : 'Fallback'} fullscreen enabled`);
// Add styling hook to show button
utils.toggleClass(this.elements.container, this.config.classNames.fullscreen.enabled, true);
} else {
this.log('Fullscreen not supported and fallback disabled');
this.console.log('Fullscreen not supported and fallback disabled');
}
// Toggle state

View File

@ -101,7 +101,7 @@ const listeners = {
case 75:
// Space and K key
if (!held) {
this.warn('togglePlay', event.type);
this.console.warn('togglePlay', event.type);
this.togglePlay();
}
break;
@ -475,7 +475,7 @@ const listeners = {
// TODO: This should be done in the method itself I think
// var value = event.target.getAttribute('data-loop__value') || event.target.getAttribute('data-loop__type');
this.warn('Set loop');
this.console.warn('Set loop');
});
}
});

View File

@ -16,7 +16,7 @@ const media = {
setup() {
// If there's no media, bail
if (!this.media) {
this.warn('No media element found!');
this.console.warn('No media element found!');
return;
}
@ -105,7 +105,7 @@ const media = {
this.media.load();
// Debugging
this.log('Cancelled network requests');
this.console.log('Cancelled network requests');
},
};

View File

@ -97,42 +97,46 @@ class Plyr {
};
// Debugging
this.log = () => {};
this.warn = () => {};
this.error = () => {};
this.console = {
log() {},
warn() {},
error() {},
};
if (this.config.debug && 'console' in window) {
this.log = console.log; // eslint-disable-line
this.warn = console.warn; // eslint-disable-line
this.error = console.error; // eslint-disable-line
this.log('Debugging enabled');
this.console = {
log: console.log, // eslint-disable-line
warn: console.warn, // eslint-disable-line
error: console.error, // eslint-disable-line
};
this.console.log('Debugging enabled');
}
// Log config options and support
this.log('Config', this.config);
this.log('Support', support);
this.console.log('Config', this.config);
this.console.log('Support', support);
// We need an element to setup
if (this.media === null || utils.is.undefined(this.media) || !utils.is.htmlElement(this.media)) {
this.error('Setup failed: no suitable element passed');
this.console.error('Setup failed: no suitable element passed');
return;
}
// Bail if the element is initialized
if (this.media.plyr) {
this.warn('Target already setup');
this.console.warn('Target already setup');
return;
}
// Bail if not enabled
if (!this.config.enabled) {
this.error('Setup failed: disabled by config');
this.console.error('Setup failed: disabled by config');
return;
}
// Bail if disabled or no basic support
// You may want to disable certain UAs etc
if (!support.check().api) {
this.error('Setup failed: no support');
this.console.error('Setup failed: no support');
return;
}
@ -152,12 +156,12 @@ class Plyr {
this.embedId = this.media.getAttribute('data-video-id');
if (utils.is.empty(this.type)) {
this.error('Setup failed: embed type missing');
this.console.error('Setup failed: embed type missing');
return;
}
if (utils.is.empty(this.embedId)) {
this.error('Setup failed: video id missing');
this.console.error('Setup failed: video id missing');
return;
}
@ -189,7 +193,7 @@ class Plyr {
break;
default:
this.error('Setup failed: unsupported type');
this.console.error('Setup failed: unsupported type');
return;
}
@ -201,7 +205,7 @@ class Plyr {
// If no support for even API, bail
if (!this.supported.api) {
this.error('Setup failed: no support');
this.console.error('Setup failed: no support');
return;
}
@ -227,7 +231,7 @@ class Plyr {
// Listen for events if debugging
if (this.config.debug) {
utils.on(this.elements.container, this.config.events.join(' '), event => {
this.log(`event: ${event.type}`);
this.console.log(`event: ${event.type}`);
});
}
@ -352,7 +356,7 @@ class Plyr {
this.media.currentTime = targetTime.toFixed(4);
// Logging
this.log(`Seeking to ${this.currentTime} seconds`);
this.console.log(`Seeking to ${this.currentTime} seconds`);
}
get currentTime() {
@ -488,7 +492,7 @@ class Plyr {
}
if (!this.config.speed.options.includes(speed)) {
this.warn(`Unsupported speed (${speed})`);
this.console.warn(`Unsupported speed (${speed})`);
return;
}
@ -516,7 +520,7 @@ class Plyr {
}
if (!this.options.quality.includes(quality)) {
this.warn(`Unsupported quality option (${quality})`);
this.console.warn(`Unsupported quality option (${quality})`);
return;
}
@ -598,7 +602,7 @@ class Plyr {
// Poster image
set poster(input) {
if (this.type !== 'video') {
this.warn('Poster can only be set on HTML5 video');
this.console.warn('Poster can only be set on HTML5 video');
return;
}
@ -914,6 +918,7 @@ class Plyr {
// GC for embed
this.embed = null;
this.embedId = null;
// If it's a soft destroy, make minimal changes
if (soft) {

View File

@ -26,7 +26,7 @@ const source = {
// Sources are not checked for support so be careful
change(input) {
if (!utils.is.object(input) || !('sources' in input) || !input.sources.length) {
this.warn('Invalid source format');
this.console.warn('Invalid source format');
return;
}

View File

@ -31,7 +31,7 @@ const ui = {
// Don't setup interface if no support
if (!this.supported.ui) {
this.warn(`Basic support only for ${this.type}`);
this.console.warn(`Basic support only for ${this.type}`);
// Remove controls
utils.removeElement.call(this, 'controls');

View File

@ -418,7 +418,7 @@ const utils = {
return true;
} catch (error) {
// Log it
this.warn('It looks like there is a problem with your custom controls HTML', error);
this.console.warn('It looks like there is a problem with your custom controls HTML', error);
// Restore native video controls
this.toggleNativeControls(true);