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 // Set new caption text
this.elements.captions.appendChild(content); this.elements.captions.appendChild(content);
} else { } 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 // Unsupported value
if (!this.options[setting].includes(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; return;
} }
// Disabled value // Disabled value
if (!this.config[setting].options.includes(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; return;
} }

View File

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

View File

@ -101,7 +101,7 @@ const listeners = {
case 75: case 75:
// Space and K key // Space and K key
if (!held) { if (!held) {
this.warn('togglePlay', event.type); this.console.warn('togglePlay', event.type);
this.togglePlay(); this.togglePlay();
} }
break; break;
@ -475,7 +475,7 @@ const listeners = {
// TODO: This should be done in the method itself I think // 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'); // 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() { setup() {
// If there's no media, bail // If there's no media, bail
if (!this.media) { if (!this.media) {
this.warn('No media element found!'); this.console.warn('No media element found!');
return; return;
} }
@ -105,7 +105,7 @@ const media = {
this.media.load(); this.media.load();
// Debugging // Debugging
this.log('Cancelled network requests'); this.console.log('Cancelled network requests');
}, },
}; };

View File

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

View File

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

View File

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

View File

@ -418,7 +418,7 @@ const utils = {
return true; return true;
} catch (error) { } catch (error) {
// Log it // 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 // Restore native video controls
this.toggleNativeControls(true); this.toggleNativeControls(true);