From e56132ae3b5f735b4ae1f1d19327c92ba9d455ab Mon Sep 17 00:00:00 2001 From: Calvin Tam Date: Wed, 12 Aug 2015 22:58:33 -0700 Subject: [PATCH 01/10] Standardized syntax --- src/js/plyr.js | 222 +++++++++++++++++++++++++------------------------ 1 file changed, 112 insertions(+), 110 deletions(-) diff --git a/src/js/plyr.js b/src/js/plyr.js index 37405a23..09ffe956 100644 --- a/src/js/plyr.js +++ b/src/js/plyr.js @@ -118,7 +118,7 @@ ""]; // Restart button - if(_inArray(config.controls, "restart")) { + if (_inArray(config.controls, "restart")) { html.push( "" + '' ); } // Rewind button if (_inArray(config.controls, "rewind")) { html.push( - "" + '' ); } // Play/pause button if (_inArray(config.controls, "play")) { html.push( - "", - "" + '', + '' ); } // Fast forward button if (_inArray(config.controls, "fast-forward")) { html.push( - "" + '' ); } // Media current time display if (_inArray(config.controls, "current-time")) { html.push( - "", - "" + config.i18n.currentTime + "", - "00:00", - "" + '', + '' + config.i18n.currentTime + '', + '00:00', + '' ); } // Media duration display if (_inArray(config.controls, "duration")) { html.push( - "", - "" + config.i18n.duration + "", - "00:00", - "" + '', + '' + config.i18n.duration + '', + '00:00', + '' ); } // Close left controls html.push( - "", - "" + '', + '' ); // Toggle mute button if (_inArray(config.controls, "mute")) { html.push( - "" + '' ); } // Volume range control if (_inArray(config.controls, "volume")) { html.push( - "", - "" + '', + '' ); } // Toggle captions button if (_inArray(config.controls, "captions")) { html.push( - "" + '' ); } // Toggle fullscreen button if (_inArray(config.controls, "fullscreen")) { html.push( - "" + '' ); } // Close everything html.push( - "", - "" + '', + '' ); return html.join(""); @@ -346,7 +346,7 @@ // Inject a script function _injectScript(source) { - if (document.querySelectorAll("script[src='" + source + "']").length) { + if (document.querySelectorAll('script[src="' + source + '"]').length) { return; } @@ -777,7 +777,7 @@ // Inputs player.buttons.mute = _getElement(config.selectors.buttons.mute); player.buttons.captions = _getElement(config.selectors.buttons.captions); - player.checkboxes = _getElements("[type='checkbox']"); + player.checkboxes = _getElements('[type="checkbox"]'); // Progress player.progress = {}; @@ -882,7 +882,7 @@ // Setup YouTube function _setupYouTube(id) { // Remove old containers - var containers = _getElements("[id^='youtube']"); + var containers = _getElements('[id^="youtube"]'); for (var i = containers.length - 1; i >= 0; i--) { _remove(containers[i]); } @@ -1028,7 +1028,7 @@ function _setupCaptions() { if (player.type === "video") { // Inject the container - player.videoContainer.insertAdjacentHTML("afterbegin", "
"); + player.videoContainer.insertAdjacentHTML("afterbegin", '
'); // Cache selector player.captionsContainer = _getElement(config.selectors.captions).querySelector("span"); From 6b4175241599fe08fa11cbdd2246f659fd20c37d Mon Sep 17 00:00:00 2001 From: Calvin Tam Date: Thu, 13 Aug 2015 00:13:57 -0700 Subject: [PATCH 05/10] Use defined function instead of hard coding --- src/js/plyr.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/plyr.js b/src/js/plyr.js index 84a01225..04ac00cb 100644 --- a/src/js/plyr.js +++ b/src/js/plyr.js @@ -1666,7 +1666,7 @@ // If a single source is passed // .source("path/to/video.mp4") if (typeof sources === "string") { - player.media.setAttribute("src", sources); + _addSource({ src: sources }); } // An array of source objects From c4ca7fe0d2243b32d69712f30582a71b1b353cc0 Mon Sep 17 00:00:00 2001 From: Calvin Tam Date: Thu, 13 Aug 2015 00:38:30 -0700 Subject: [PATCH 06/10] Updated tag closing --- src/js/plyr.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/js/plyr.js b/src/js/plyr.js index 04ac00cb..4b724960 100644 --- a/src/js/plyr.js +++ b/src/js/plyr.js @@ -121,7 +121,7 @@ if (_inArray(config.controls, "restart")) { html.push( '' ); @@ -131,7 +131,7 @@ if (_inArray(config.controls, "rewind")) { html.push( '' ); @@ -141,11 +141,11 @@ if (_inArray(config.controls, "play")) { html.push( '', '' ); @@ -155,7 +155,7 @@ if (_inArray(config.controls, "fast-forward")) { html.push( '' ); @@ -191,8 +191,8 @@ if (_inArray(config.controls, "mute")) { html.push( '' ); @@ -210,8 +210,8 @@ if (_inArray(config.controls, "captions")) { html.push( '' ); @@ -221,8 +221,8 @@ if (_inArray(config.controls, "fullscreen")) { html.push( '' ); From 20090aee032b60c8f9733efc51f5c1febed97252 Mon Sep 17 00:00:00 2001 From: Calvin Tam Date: Thu, 13 Aug 2015 00:43:11 -0700 Subject: [PATCH 07/10] Fixed missing semicolons mentioned by JSHint --- src/js/plyr.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/js/plyr.js b/src/js/plyr.js index 4b724960..861c091e 100644 --- a/src/js/plyr.js +++ b/src/js/plyr.js @@ -607,7 +607,7 @@ return false; } })() - } + }; return storage; } @@ -904,7 +904,7 @@ _injectScript("https://www.youtube.com/iframe_api"); // Setup callback for the API - window.onYouTubeIframeAPIReady = function () { _YTReady(id, container); } + window.onYouTubeIframeAPIReady = function () { _YTReady(id, container); }; } } @@ -1148,7 +1148,7 @@ _log("There was a problem loading the caption file via AJAX.", true); } } - } + }; xhr.open("get", captionSrc, true); @@ -1573,7 +1573,7 @@ player.hours = parseInt(((time / 60) / 60) % 60); // Do we need to display hours? - var displayHours = (parseInt(((player.media.duration / 60) / 60) % 60) > 0) + var displayHours = (parseInt(((player.media.duration / 60) / 60) % 60) > 0); // Ensure it"s two digits. For example, 03 rather than 3. player.secs = ("0" + player.secs).slice(-2); @@ -1985,7 +1985,7 @@ support: function(mimeType) { return _supportMime(player, mimeType); }, destroy: _destroy, restore: _init - } + }; } // Check for support @@ -2022,7 +2022,7 @@ basic: basic, full: full }; - } + }; // Expose setup function api.setup = function(options) { @@ -2063,6 +2063,6 @@ } return players; - } + }; }(this.plyr = this.plyr || {})); \ No newline at end of file From a46e421bf63575da96f89fee34c75e86fa3d1d43 Mon Sep 17 00:00:00 2001 From: Calvin Tam Date: Thu, 13 Aug 2015 01:15:57 -0700 Subject: [PATCH 08/10] Fixed syntax; Fixed some JSHint errors (Not escaped character, etc.) --- src/js/plyr.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/js/plyr.js b/src/js/plyr.js index 861c091e..33deb397 100644 --- a/src/js/plyr.js +++ b/src/js/plyr.js @@ -323,7 +323,7 @@ // Only check video types for video players if (player.type == "video") { // Check type - switch(mimeType) { + switch (mimeType) { case "video/webm": return !!(media.canPlayType && media.canPlayType("video/webm; codecs=\"vp8, vorbis\"").replace(/no/, "")); case "video/mp4": return !!(media.canPlayType && media.canPlayType("video/mp4; codecs=\"avc1.42E01E, mp4a.40.2\"").replace(/no/, "")); case "video/ogg": return !!(media.canPlayType && media.canPlayType("video/ogg; codecs=\"theora\"").replace(/no/, "")); @@ -333,7 +333,7 @@ // Only check audio types for audio players else if (player.type == "audio") { // Check type - switch(mimeType) { + switch (mimeType) { case "audio/mpeg": return !!(media.canPlayType && media.canPlayType("audio/mpeg;").replace(/no/, "")); case "audio/ogg": return !!(media.canPlayType && media.canPlayType("audio/ogg; codecs=\"vorbis\"").replace(/no/, "")); case "audio/wav": return !!(media.canPlayType && media.canPlayType("audio/wav; codecs=\"1\"").replace(/no/, "")); @@ -363,7 +363,7 @@ // Replace all function _replaceAll(string, find, replace) { - return string.replace(new RegExp(find.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"), "g"), replace); + return string.replace(new RegExp(find.replace(/([.*+?\^=!:${}()|\[\]\/\\])/g, "\\$1"), "g"), replace); } // Wrap an element @@ -994,7 +994,7 @@ // 2 Paused // 3 Buffering // 5 Video cued - switch(event.data) { + switch (event.data) { case 0: player.media.paused = true; _triggerEvent(player.media, "ended"); @@ -1510,7 +1510,7 @@ value = 0; if (event) { - switch(event.type) { + switch (event.type) { // Video playing case "timeupdate": case "seeking": @@ -1889,13 +1889,11 @@ // Set media type var tagName = player.media.tagName.toLowerCase(); - switch(tagName) { - case "div": - player.type = player.media.getAttribute("data-type"); - break; - - default: - player.type = tagName; + if (tagName === "div") { + player.type = player.media.getAttribute("data-type"); + } + else { + player.type = tagName; } // Check for full support From 9fe6e5ffcb2ed0a1d6ec2e4eacab363aeb8c09e8 Mon Sep 17 00:00:00 2001 From: Calvin Tam Date: Thu, 13 Aug 2015 01:36:20 -0700 Subject: [PATCH 09/10] Converted double quote to single quote --- src/js/plyr.js | 576 ++++++++++++++++++++++++------------------------- 1 file changed, 288 insertions(+), 288 deletions(-) diff --git a/src/js/plyr.js b/src/js/plyr.js index 33deb397..32b538d9 100644 --- a/src/js/plyr.js +++ b/src/js/plyr.js @@ -8,7 +8,7 @@ // ========================================================================== (function (api) { - "use strict"; + 'use strict'; /*global YT*/ // Globals @@ -23,11 +23,11 @@ click: true, tooltips: false, displayDuration: true, - iconPrefix: "icon", + iconPrefix: 'icon', selectors: { - container: ".player", - controls: ".player-controls", - labels: "[data-player] .sr-only, label .sr-only", + container: '.player', + controls: '.player-controls', + labels: '[data-player] .sr-only, label .sr-only', buttons: { seek: '[data-player="seek"]', play: '[data-player="play"]', @@ -41,33 +41,33 @@ fullscreen: '[data-player="fullscreen"]' }, progress: { - container: ".player-progress", - buffer: ".player-progress-buffer", - played: ".player-progress-played" + container: '.player-progress', + buffer: '.player-progress-buffer', + played: '.player-progress-played' }, - captions: ".player-captions", - currentTime: ".player-current-time", - duration: ".player-duration" + captions: '.player-captions', + currentTime: '.player-current-time', + duration: '.player-duration' }, classes: { - videoWrapper: "player-video-wrapper", - embedWrapper: "player-video-embed", - type: "player-{0}", - stopped: "stopped", - playing: "playing", - muted: "muted", - loading: "loading", - tooltip: "player-tooltip", - hidden: "sr-only", - hover: "player-hover", + videoWrapper: 'player-video-wrapper', + embedWrapper: 'player-video-embed', + type: 'player-{0}', + stopped: 'stopped', + playing: 'playing', + muted: 'muted', + loading: 'loading', + tooltip: 'player-tooltip', + hidden: 'sr-only', + hover: 'player-hover', captions: { - enabled: "captions-enabled", - active: "captions-active" + enabled: 'captions-enabled', + active: 'captions-active' }, fullscreen: { - enabled: "fullscreen-enabled", - active: "fullscreen-active", - hideControls: "fullscreen-hide-controls" + enabled: 'fullscreen-enabled', + active: 'fullscreen-active', + hideControls: 'fullscreen-hide-controls' } }, captions: { @@ -80,23 +80,23 @@ }, storage: { enabled: true, - key: "plyr_volume" + key: 'plyr_volume' }, - controls: ["restart", "rewind", "play", "fast-forward", "current-time", "duration", "mute", "volume", "captions", "fullscreen"], + controls: ['restart', 'rewind', 'play', 'fast-forward', 'current-time', 'duration', 'mute', 'volume', 'captions', 'fullscreen'], i18n: { - restart: "Restart", - rewind: "Rewind {seektime} secs", - play: "Play", - pause: "Pause", - forward: "Forward {seektime} secs", - played: "played", - buffered: "buffered", - currentTime: "Current time", - duration: "Duration", - volume: "Volume", - toggleMute: "Toggle Mute", - toggleCaptions: "Toggle Captions", - toggleFullscreen: "Toggle Fullscreen" + restart: 'Restart', + rewind: 'Rewind {seektime} secs', + play: 'Play', + pause: 'Pause', + forward: 'Forward {seektime} secs', + played: 'played', + buffered: 'buffered', + currentTime: 'Current time', + duration: 'Duration', + volume: 'Volume', + toggleMute: 'Toggle Mute', + toggleCaptions: 'Toggle Captions', + toggleFullscreen: 'Toggle Fullscreen' } }; @@ -118,7 +118,7 @@ '']; // Restart button - if (_inArray(config.controls, "restart")) { + if (_inArray(config.controls, 'restart')) { html.push( '