diff options
Diffstat (limited to 'assets')
-rwxr-xr-x | assets/icons/bubble.svg | 6 | ||||
-rwxr-xr-x | assets/icons/film.svg | 6 | ||||
-rw-r--r-- | assets/icons/muted.svg | 14 | ||||
-rw-r--r-- | assets/icons/pause.svg | 8 | ||||
-rw-r--r-- | assets/js/docs.js | 20 | ||||
-rw-r--r-- | assets/js/simple-media.js | 1197 | ||||
-rw-r--r-- | assets/less/simple-media.less | 200 | ||||
-rw-r--r-- | assets/templates/controls.html | 57 |
8 files changed, 857 insertions, 651 deletions
diff --git a/assets/icons/bubble.svg b/assets/icons/bubble.svg new file mode 100755 index 00000000..7090121a --- /dev/null +++ b/assets/icons/bubble.svg @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Generated by IcoMoon.io --> +<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> +<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="18" height="18" viewBox="0 0 18 18"> +<path d="M9.016 3c2.748 0 4.984 2.243 4.984 5s-2.236 5-4.97 5l-0.060-0.004c-0.055-0.004-0.11-0.007-0.165-0.010l-0.336-0.014-3.665 1.098 0.629-2.483-0.517-0.747c-0.58-0.839-0.886-1.822-0.886-2.842 0-2.757 2.236-5 4.984-5zM9.016 1c-3.857 0-6.984 3.134-6.984 7 0 1.479 0.46 2.848 1.241 3.978l-1.272 5.022 6.722-2.015c0.098 0.004 0.194 0.015 0.293 0.015 3.857 0 6.984-3.134 6.984-7s-3.127-7-6.984-7v0z"></path> +</svg> diff --git a/assets/icons/film.svg b/assets/icons/film.svg deleted file mode 100755 index ad3d3551..00000000 --- a/assets/icons/film.svg +++ /dev/null @@ -1,6 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- Generated by IcoMoon.io --> -<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> -<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="18" height="18" viewBox="0 0 18 18"> -<path d="M17 2h-16c-0.552 0-1 0.448-1 1v12c0 0.552 0.448 1 1 1h16c0.552 0 1-0.448 1-1v-12c0-0.552-0.448-1-1-1zM2 4h2v2h-2v-2zM2 8h2v2h-2v-2zM2 14v-2h2v2h-2zM6 14v-10h6v10h-6zM16 14h-2v-2h2v2zM16 10h-2v-2h2v2zM16 6h-2v-2h2v2z"></path> -</svg> diff --git a/assets/icons/muted.svg b/assets/icons/muted.svg new file mode 100644 index 00000000..031da8d1 --- /dev/null +++ b/assets/icons/muted.svg @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg width="18px" height="18px" viewBox="0 0 18 18" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sketch="http://www.bohemiancoding.com/sketch/ns"> + <!-- Generator: Sketch 3.2.2 (9983) - http://www.bohemiancoding.com/sketch --> + <title>muted</title> + <desc>Created with Sketch.</desc> + <defs></defs> + <g id="Page-1" stroke="none" stroke-width="1" sketch:type="MSPage"> + <g id="sound" sketch:type="MSLayerGroup" transform="translate(0.000000, 2.000000)"> + <path d="M9.214,0 C9.103,0 8.989,0.032 8.88,0.101 L4.832,2.911 C4.749,2.969 4.65,3 4.549,3 L0.996,3 C0.446,3 1.33226763e-15,3.448 1.33226763e-15,4 L1.33226763e-15,10 C1.33226763e-15,10.552 0.446,11 0.996,11 L4.549,11 C4.651,11 4.749,11.031 4.832,11.089 L8.88,13.899 C8.989,13.968 9.103,14 9.214,14 C9.606,14 9.961,13.6 9.961,13.051 L9.961,0.95 C9.961,0.4 9.606,0.001 9.214,0.001 L9.214,0 Z M7.969,10.834 L5.582,9.177 C5.416,9.062 5.218,8.999 5.016,8.999 L2.491,8.999 C2.216,8.999 1.993,8.775 1.993,8.499 L1.993,5.499 C1.993,5.223 2.216,4.999 2.491,4.999 L5.016,4.999 C5.218,4.999 5.416,4.937 5.582,4.821 L7.969,3.164 L7.969,10.833 L7.969,10.834 Z" id="Shape" sketch:type="MSShapeGroup"></path> + <path d="M14.934,6.799 C14.848,5.051 13.42,3.808 12.427,3.15 C11.957,2.838 11.333,3.028 11.102,3.558 L11.064,3.644 C10.876,4.075 11.019,4.583 11.4,4.838 C12.106,5.311 12.986,6.085 13.024,6.903 C13.056,7.579 12.471,8.371 11.361,9.173 C10.963,9.461 10.832,10.012 11.076,10.448 L11.118,10.523 C11.384,10.998 11.984,11.147 12.418,10.835 C14.158,9.584 15.004,8.229 14.934,6.798 L14.934,6.799 Z" id="Shape" sketch:type="MSShapeGroup"></path> + <path d="M17.934,6.799 C17.848,5.051 16.42,3.808 15.427,3.15 C14.957,2.838 14.333,3.028 14.102,3.558 L14.064,3.644 C13.876,4.075 14.019,4.583 14.4,4.838 C15.106,5.311 15.986,6.085 16.024,6.903 C16.056,7.579 15.471,8.371 14.361,9.173 C13.963,9.461 13.832,10.012 14.076,10.448 L14.118,10.523 C14.384,10.998 14.984,11.147 15.418,10.835 C17.158,9.584 18.004,8.229 17.934,6.798 L17.934,6.799 Z" id="Shape-2" sketch:type="MSShapeGroup" transform="translate(15.945467, 6.999165) rotate(-180.000000) translate(-15.945467, -6.999165) "></path> + </g> + </g> +</svg>
\ No newline at end of file diff --git a/assets/icons/pause.svg b/assets/icons/pause.svg index d451beca..ea2efe98 100644 --- a/assets/icons/pause.svg +++ b/assets/icons/pause.svg @@ -4,10 +4,10 @@ <title>pause</title> <desc>Created with Sketch.</desc> <defs></defs> - <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage"> - <g id="pause" sketch:type="MSLayerGroup" transform="translate(3.000000, 3.000000)" stroke="#FFFFFF" stroke-width="2"> - <rect id="Rectangle-1" sketch:type="MSShapeGroup" x="8" y="0" width="4" height="12" rx="1"></rect> - <rect id="Rectangle-2" sketch:type="MSShapeGroup" x="0" y="0" width="4" height="12" rx="1"></rect> + <g id="Page-1" stroke="none" stroke-width="1" sketch:type="MSPage"> + <g id="pause" sketch:type="MSLayerGroup" transform="translate(2.000000, 2.000000)"> + <path d="M0,2 L0,12 C5.24848613e-17,14 2,14 2,14 L4,14 C4,14 6,14 6,12 C6,11.786438 6,11.572876 6,11 L6,2 C6,3.17446247e-09 4,0 4,0 L2,0 C2,0 0,0 0,2 Z M2,2 L4,2 L4,12 L2,12 L2,2 Z" id="Path-1" sketch:type="MSShapeGroup"></path> + <path d="M8,2 L8,12 C8,14 10,14 10,14 L12,14 C12,14 14,14 14,12 C14,11.786438 14,11.572876 14,11 L14,2 C14,3.17446247e-09 12,0 12,0 L10,0 C10,0 8,0 8,2 Z M10,2 L12,2 L12,12 L10,12 L10,2 Z" id="Path-2" sketch:type="MSShapeGroup"></path> </g> </g> </svg>
\ No newline at end of file diff --git a/assets/js/docs.js b/assets/js/docs.js index f80fe696..fcb05868 100644 --- a/assets/js/docs.js +++ b/assets/js/docs.js @@ -2,16 +2,16 @@ // Docs example // ========================================================================== -/*global InitPxVideo, Mustache, templates */ +/*global simpleMedia, templates */ -// Initialize -var video = new InitPxVideo({ - "videoId": "myvid", - "captionsOnDefault": true, - "seekInterval": 20, - "videoTitle": "PayPal Austin promo", - "debug": true, - "html": templates.controls.render({}) +// Register a callback +simpleMedia.on("setup", function() { + console.log(this); }); -console.log(video);
\ No newline at end of file +//execute shout +simpleMedia.setup({ + debug: true, + title: "PayPal demo", + html: templates.controls.render({}) +});
\ No newline at end of file diff --git a/assets/js/simple-media.js b/assets/js/simple-media.js index 09d67ce3..e188893b 100644 --- a/assets/js/simple-media.js +++ b/assets/js/simple-media.js @@ -6,167 +6,57 @@ // Credits: http://paypal.github.io/accessible-html5-video-player/ // ========================================================================== -// Fullscreen API -(function() { - var - fullscreen = { - supportsFullScreen: false, - isFullScreen: function() { return false; }, - requestFullScreen: function() {}, - cancelFullScreen: function() {}, - fullScreenEventName: "", - element: null, - prefix: "" - }, - browserPrefixes = "webkit moz o ms khtml".split(" "); - - // check for native support - if (typeof document.cancelFullScreen != "undefined") { - fullscreen.supportsFullScreen = true; - } - else { - // check for fullscreen support by vendor prefix - for (var i = 0, il = browserPrefixes.length; i < il; i++ ) { - fullscreen.prefix = browserPrefixes[i]; - - if (typeof document[fullscreen.prefix + "CancelFullScreen" ] != "undefined" ) { - fullscreen.supportsFullScreen = true; - - break; - } - } - } - - // Safari doesn't support the ALLOW_KEYBOARD_INPUT flag so set it to not supported - // https://bugs.webkit.org/show_bug.cgi?id=121496 - if(fullscreen.prefix === "webkit" && !!navigator.userAgent.match(/Version\/[\d\.]+.*Safari/)) { - fullscreen.supportsFullScreen = false; - } - - // Update methods to do something useful - if (fullscreen.supportsFullScreen) { - fullscreen.fullScreenEventName = fullscreen.prefix + "fullscreenchange"; - - fullscreen.isFullScreen = function() { - switch (this.prefix) { - case "": - return document.fullScreen; - case "webkit": - return document.webkitIsFullScreen; - default: - return document[this.prefix + "FullScreen"]; - } - }; - fullscreen.requestFullScreen = function(element) { - return (this.prefix === "") ? element.requestFullScreen() : element[this.prefix + "RequestFullScreen"](this.prefix === "webkit" ? element.ALLOW_KEYBOARD_INPUT : null); - }; - fullscreen.cancelFullScreen = function() { - return (this.prefix === "") ? document.cancelFullScreen() : document[this.prefix + "CancelFullScreen"](); - }; - fullscreen.element = function() { - return (this.prefix === "") ? document.fullscreenElement : document[this.prefix + "FullscreenElement"]; - }; - } - - // Export api - window.fullscreen = fullscreen; -})(); - -function InitPxVideo(options) { +/*global ActiveXObject*/ +(function(api){ "use strict"; - // Replace all - // --------------------------------- - if (!String.prototype.replaceAll) { - Object.defineProperty(String.prototype, "replaceAll", { - value: function(find, replace) { - return this.replace(new RegExp(find.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"), "g"), replace); - } - }); - } - - // Get click position relative to parent - // http://www.kirupa.com/html5/getting_mouse_click_position.htm - // --------------------------------- - function getClickPosition(e) { - var parentPosition = window.fullscreen.isFullScreen() ? { x: 0, y: 0 } : getPosition(e.currentTarget); - - return { - x: e.clientX - parentPosition.x, - y: e.clientY - parentPosition.y - }; - } - - // Get element position - // http://www.kirupa.com/html5/getting_mouse_click_position.htm - // --------------------------------- - function getPosition(element) { - var xPosition = 0; - var yPosition = 0; - - while (element) { - xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft); - yPosition += (element.offsetTop - element.scrollTop + element.clientTop); - element = element.offsetParent; - } - - return { - x: xPosition, - y: yPosition - }; - } - - // Utilities for caption time codes - function video_timecode_min(tc) { - var tcpair = []; - tcpair = tc.split(" --> "); - return videosub_tcsecs(tcpair[0]); - } - - function video_timecode_max(tc) { - var tcpair = []; - tcpair = tc.split(" --> "); - return videosub_tcsecs(tcpair[1]); - } - - function videosub_tcsecs(tc) { - if (tc === null || tc === undefined) { - return 0; - } - else { - var tc1 = [], - tc2 = [], - seconds; - tc1 = tc.split(","); - tc2 = tc1[0].split(":"); - seconds = Math.floor(tc2[0]*60*60) + Math.floor(tc2[1]*60) + Math.floor(tc2[2]); - return seconds; - } - } - - // For "manual" captions, adjust caption position when play time changed (via rewind, clicking progress bar, etc.) - function adjustManualCaptions(obj) { - obj.subcount = 0; - while (video_timecode_max(obj.captions[obj.subcount][0]) < obj.movie.currentTime.toFixed(1)) { - obj.subcount++; - if (obj.subcount > obj.captions.length-1) { - obj.subcount = obj.captions.length-1; - break; - } - } - } - - // Display captions container and button (for initialization) - function showCaptionContainerAndButton(obj) { - //obj.captionsBtnContainer.className = "px-video-captions-btn-container show"; - if (obj.isCaptionDefault) { - obj.captionsContainer.className = "px-video-captions show"; - obj.captionsBtn.setAttribute("checked", "checked"); - } - } + // Globals + var fullscreen, config; + + // Handler cache + var handlers = {}; + + // Object cache + var player = {}; + + // Default config + var defaults = { + debug: false, + seekInterval: 10, + selectors: { + container: ".player", + videoContainer: ".player-video", + controls: ".player-controls", + buttons: { + play: "[data-player='play']", + pause: "[data-player='pause']", + restart: "[data-player='restart']", + rewind: "[data-player='restart']", + forward: "[data-player='fast-forward']", + mute: "[data-player='mute']", + volume: "[data-player='volume']", + captions: "[data-player='captions']", + fullscreen: "[data-player='fullscreen']" + }, + progress: ".player-progress", + captions: ".player-captions", + duration: ".player-duration", + seekTime: ".player-seek-time" + }, + classes: { + stopped: "stopped", + playing: "playing", + muted: "muted", + captions: "captions" + }, + captions: { + default: true + } + }; // Unfortunately, due to scattered support, browser sniffing is required + // http://paypal.github.io/accessible-html5-video-player/ function browserSniff() { var nAgt = navigator.userAgent, browserName = navigator.appName, @@ -229,430 +119,707 @@ function InitPxVideo(options) { return [browserName, majorVersion]; } - // Global variable - var obj = {}; - - obj.arBrowserInfo = browserSniff(); - obj.browserName = obj.arBrowserInfo[0]; - obj.browserMajorVersion = obj.arBrowserInfo[1]; - - // If IE8, stop customization (use fallback) - // If IE9, stop customization (use native controls) - if (obj.browserName === "IE" && (obj.browserMajorVersion === 8 || obj.browserMajorVersion === 9) ) { - return false; + // Utilities for caption time codes + // http://paypal.github.io/accessible-html5-video-player/ + function video_timecode_min(tc) { + var tcpair = []; + tcpair = tc.split(" --> "); + return videosub_tcsecs(tcpair[0]); } - - // If smartphone or tablet, stop customization as video (and captions in latest devices) are handled natively - obj.isSmartphoneOrTablet = /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent); - if (obj.isSmartphoneOrTablet) { - return false; + function video_timecode_max(tc) { + var tcpair = []; + tcpair = tc.split(" --> "); + return videosub_tcsecs(tcpair[1]); } - - // Set debug mode - if (typeof(options.debug)==="undefined") { - options.debug = false; + function videosub_tcsecs(tc) { + if (tc === null || tc === undefined) { + return 0; + } + else { + var tc1 = [], + tc2 = [], + seconds; + tc1 = tc.split(","); + tc2 = tc1[0].split(":"); + seconds = Math.floor(tc2[0]*60*60) + Math.floor(tc2[1]*60) + Math.floor(tc2[2]); + return seconds; + } } - obj.debug = options.debug; - - // Output browser info to log if debug on - if (options.debug) { - console.log(obj.browserName + " " + obj.browserMajorVersion); + // For "manual" captions, adjust caption position when play time changed (via rewind, clicking progress bar, etc.) + // http://paypal.github.io/accessible-html5-video-player/ + function adjustManualCaptions(player) { + player.subcount = 0; + while (video_timecode_max(player.captions[player.subcount][0]) < player.media.currentTime.toFixed(1)) { + player.subcount++; + if (player.subcount > player.captions.length-1) { + player.subcount = player.captions.length-1; + break; + } + } } - - // Set up aria-label for Play button with the videoTitle option - if ((typeof(options.videoTitle)==="undefined") || (options.videoTitle==="")) { - obj.playAriaLabel = "Play"; + // Display captions container and button (for initialization) + function showCaptionContainerAndButton(player) { + if (config.captions.default) { + player.container.className += " " + config.classes.captions; + player.buttons.captions.setAttribute("checked", "checked"); + } } - else { - obj.playAriaLabel = "Play video, " + options.videoTitle; + + // Replace all + function replaceAll(string, find, replace) { + return string.replace(new RegExp(find.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"), "g"), replace); } - // Get the container and video element - obj.container = document.getElementById(options.videoId); - obj.container.className = obj.container.className + " stopped"; - obj.movie = obj.container.getElementsByTagName("video")[0]; - - // Remove native video controls - obj.movie.removeAttribute("controls"); - - // Generate random number for ID/FOR attribute values for controls - obj.randomNum = Math.floor(Math.random() * (10000)); - - // Insert custom video controls - if (options.debug) { - console.log("Inserting custom controls..."); + // Get click position relative to parent + // http://www.kirupa.com/html5/getting_mouse_click_position.htm + function getClickPosition(e) { + var parentPosition = fullscreen.isFullScreen() ? { x: 0, y: 0 } : getPosition(e.currentTarget); + + return { + x: e.clientX - parentPosition.x, + y: e.clientY - parentPosition.y + }; } - obj.container.insertAdjacentHTML("beforeend", options.html - .replaceAll("{aria-label}", obj.playAriaLabel) - .replaceAll("{id}", obj.randomNum)); - - // Store reference - obj.controls = obj.container.querySelector(".player-controls"); - - // Responsive ffs - // ---- - // Adjust layout per width of video - container - //obj.movieWidth = obj.movie.width; - //if (obj.movieWidth < 360) { - // obj.movieWidth = 360; - //} - //obj.container.setAttribute("style", "width:" + obj.movieWidth + "px"); - - // Adjust layout per width of video - controls/mute offset - obj.labelMute = document.getElementById("labelMute" + obj.randomNum); - obj.labelMuteOffset = obj.movieWidth - 390; - if (obj.labelMuteOffset < 0) { - obj.labelMuteOffset = 0; + + // Get element position + // http://www.kirupa.com/html5/getting_mouse_click_position.htm + function getPosition(element) { + var xPosition = 0; + var yPosition = 0; + + while (element) { + xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft); + yPosition += (element.offsetTop - element.scrollTop + element.clientTop); + element = element.offsetParent; + } + + return { + x: xPosition, + y: yPosition + }; } - obj.labelMute.setAttribute("style", "margin-left:" + obj.labelMuteOffset + "px"); - - // Get URL of caption file if exists - var captionSrc = "", - kind, - children = obj.movie.childNodes; - - for (var i = 0; i < children.length; i++) { - if (children[i].nodeName.toLowerCase() === "track") { - kind = children[i].getAttribute("kind"); - if (kind === "captions") { - captionSrc = children[i].getAttribute("src"); + + // Deep extend/merge two Objects + // http://andrewdupont.net/2009/08/28/deep-extending-objects-in-javascript/ + // Removed call to arguments.callee (used explicit function name instead) + function extend(destination, source) { + for (var property in source) { + if (source[property] && source[property].constructor && source[property].constructor === Object) { + destination[property] = destination[property] || {}; + extend(destination[property], source[property]); + } + else { + destination[property] = source[property]; } } + return destination; } - // Record if caption file exists or not - obj.captionExists = true; - if (captionSrc === "") { - obj.captionExists = false; - if (options.debug) { - console.log("No caption track found."); + // Our internal function that executes handlers with a given name + function executeHandlers(eventName){ + // Get all handlers with the selected name + var handler = handlers[eventName] || [], + len = handler.length, + i; + + // Execute each + for(i = 0; i< len; i++){ + // You can use apply to specify what "this" and parameters the callback gets + handler[i].apply(player.media,[]); } } - else { - if (options.debug) { - console.log("Caption track found; URI: " + captionSrc); + + // Fullscreen API + function fullscreenApi() { + var fullscreen = { + supportsFullScreen: false, + isFullScreen: function() { return false; }, + requestFullScreen: function() {}, + cancelFullScreen: function() {}, + fullScreenEventName: "", + element: null, + prefix: "" + }, + browserPrefixes = "webkit moz o ms khtml".split(" "); + + // check for native support + if (typeof document.cancelFullScreen != "undefined") { + fullscreen.supportsFullScreen = true; } - } + else { + // check for fullscreen support by vendor prefix + for (var i = 0, il = browserPrefixes.length; i < il; i++ ) { + fullscreen.prefix = browserPrefixes[i]; + + if (typeof document[fullscreen.prefix + "CancelFullScreen" ] != "undefined" ) { + fullscreen.supportsFullScreen = true; + + break; + } + } + } + + // Safari doesn't support the ALLOW_KEYBOARD_INPUT flag so set it to not supported + // https://bugs.webkit.org/show_bug.cgi?id=121496 + if(fullscreen.prefix === "webkit" && !!navigator.userAgent.match(/Version\/[\d\.]+.*Safari/)) { + fullscreen.supportsFullScreen = false; + } + + // Update methods to do something useful + if (fullscreen.supportsFullScreen) { + fullscreen.fullScreenEventName = fullscreen.prefix + "fullscreenchange"; - // Set captions on/off - on by default - if (typeof(options.captionsOnDefault) === "undefined") { - options.captionsOnDefault = true; + fullscreen.isFullScreen = function() { + switch (this.prefix) { + case "": + return document.fullScreen; + case "webkit": + return document.webkitIsFullScreen; + default: + return document[this.prefix + "FullScreen"]; + } + }; + fullscreen.requestFullScreen = function(element) { + return (this.prefix === "") ? element.requestFullScreen() : element[this.prefix + "RequestFullScreen"](this.prefix === "webkit" ? element.ALLOW_KEYBOARD_INPUT : null); + }; + fullscreen.cancelFullScreen = function() { + return (this.prefix === "") ? document.cancelFullScreen() : document[this.prefix + "CancelFullScreen"](); + }; + fullscreen.element = function() { + return (this.prefix === "") ? document.fullscreenElement : document[this.prefix + "FullscreenElement"]; + }; + } + + return fullscreen; } - obj.isCaptionDefault = options.captionsOnDefault; - // Number of seconds for rewind and forward buttons - if (typeof(options.seekInterval) === "undefined") { - options.seekInterval = 10; + // Insert controls + function injectControls() { + // Insert custom video controls + if (config.debug) { + console.log("Injecting custom controls"); + } + + // Use specified html + // Need to do a default? + var html = config.html; + + // Replace aria label instances + html = replaceAll(html, "{aria-label}", config.playAriaLabel); + + // Replace all id references + html = replaceAll(html, "{id}", player.random); + + // Inject into the container + player.container.insertAdjacentHTML("beforeend", html); } - obj.seekInterval = options.seekInterval; - - // Get the elements for the controls - obj.btnPlay = obj.container.getElementsByClassName("px-video-play")[0]; - obj.btnPause = obj.container.getElementsByClassName("px-video-pause")[0]; - obj.btnRestart = obj.container.getElementsByClassName("px-video-restart")[0]; - obj.btnRewind = obj.container.getElementsByClassName("px-video-rewind")[0]; - obj.btnForward = obj.container.getElementsByClassName("px-video-forward")[0]; - obj.btnVolume = obj.container.getElementsByClassName("px-video-volume")[0]; - obj.btnMute = obj.container.getElementsByClassName("px-video-mute")[0]; - obj.progressBar = obj.container.getElementsByClassName("px-video-progress")[0]; - obj.progressBarSpan = obj.progressBar.getElementsByTagName("span")[0]; - obj.captionsContainer = obj.container.getElementsByClassName("px-video-captions")[0]; - obj.captionsBtn = obj.container.getElementsByClassName("px-video-btnCaptions")[0]; - obj.captionsBtnContainer = obj.container.getElementsByClassName("px-video-captions-btn-container")[0]; - obj.duration = obj.container.getElementsByClassName("px-video-duration")[0]; - obj.txtSeconds = obj.container.getElementsByClassName("px-seconds"); - - obj.toggleFullscreen = obj.container.querySelector("[data-player='toggle-fullscreen']"); - obj.videoContainer = obj.container.querySelector(".player-video"); - - // Update number of seconds in rewind and fast forward buttons - obj.txtSeconds[0].innerHTML = obj.seekInterval; - obj.txtSeconds[1].innerHTML = obj.seekInterval; - - // Determine if HTML5 textTracks is supported (for captions) - obj.isTextTracks = false; - if (obj.movie.textTracks) { - obj.isTextTracks = true; + + // Find all elements + function getElements(selector) { + return player.container.querySelectorAll(selector); } - // Fullscreen - obj.toggleFullscreen.addEventListener("click", function() { - if(!window.fullscreen.isFullScreen()) { - window.fullscreen.requestFullScreen(obj.container); - } - else { - window.fullscreen.cancelFullScreen(); - } - }, false); + // Find a single element + function getElement(selector) { + return getElements(selector)[0]; + } - // Click video - obj.videoContainer.addEventListener("click", function() { - if(obj.movie.paused) { - play(); - } - else if(obj.movie.ended) { - restart(); - } - else { - pause(); - } - }, false); + // Find the UI controls and store references + function findElements() { + player.controls = getElement(config.selectors.controls); + + // Buttons + player.buttons = {}; + player.buttons.play = getElement(config.selectors.buttons.play); + player.buttons.pause = getElement(config.selectors.buttons.pause); + player.buttons.restart = getElement(config.selectors.buttons.restart); + player.buttons.rewind = getElement(config.selectors.buttons.rewind); + player.buttons.forward = getElement(config.selectors.buttons.forward); + player.buttons.mute = getElement(config.selectors.buttons.mute); + player.buttons.volume = getElement(config.selectors.buttons.volume); + player.buttons.captions = getElement(config.selectors.buttons.captions); + player.buttons.fullscreen = getElement(config.selectors.buttons.fullscreen); + + // Progress + player.progress = {}; + player.progress.bar = getElement(config.selectors.progress); + player.progress.text = player.progress.bar.getElementsByTagName("span")[0]; + + // Timing + player.duration = getElement(config.selectors.duration); + player.seekTime = getElements(config.selectors.seekTime); + } + // Play media function play() { - obj.movie.play(); - obj.container.className = obj.container.className.replace("stopped", "playing"); - + player.media.play(); + player.container.className = player.container.className.replace(config.classes.stopped, config.classes.playing); } + // Pause media function pause() { - obj.movie.pause(); - obj.container.className = obj.container.className.replace("playing", "stopped"); + player.media.pause(); + player.container.className = player.container.className.replace(config.classes.playing, config.classes.stopped); } + // Restart playback function restart() { // Move to beginning - obj.movie.currentTime = 0; + player.media.currentTime = 0; // Special handling for "manual" captions - if (!obj.isTextTracks) { - obj.subcount = 0; + if (!player.isTextTracks) { + player.subcount = 0; } // Play and ensure the play button is in correct state play(); } - // Play - obj.btnPlay.addEventListener("click", function() { play(); obj.btnPause.focus(); }, false); - - // Pause - obj.btnPause.addEventListener("click", function() { pause(); obj.btnPlay.focus(); }, false); + // Setup media + function setupMedia() { + player.media = player.container.querySelectorAll("audio, video")[0]; - // Restart - obj.btnRestart.addEventListener("click", restart, false); - - // Rewind - obj.btnRewind.addEventListener("click", function() { - var targetTime = obj.movie.currentTime - obj.seekInterval; - if (targetTime < 0) { - obj.movie.currentTime = 0; - } - else { - obj.movie.currentTime = targetTime; - } - // Special handling for "manual" captions - if (!obj.isTextTracks) { - adjustManualCaptions(obj); + // If there's no media, bail + if(!player.media) { + console.warn("No audio or video element found!"); + return false; } - }, false); - // Fast forward - obj.btnForward.addEventListener("click", function() { - var targetTime = obj.movie.currentTime + obj.seekInterval; - if (targetTime > obj.movie.duration) { - obj.movie.currentTime = obj.movie.duration; + // If there's no autoplay attribute, assume the video is stopped + if(player.media.getAttribute("autoplay") === null) { + player.container.className += " " + config.classes.stopped; } - else { - obj.movie.currentTime = targetTime; - } - // Special handling for "manual" captions - if (!obj.isTextTracks) { - adjustManualCaptions(obj); - } - }, false); - - // Get the HTML5 range input element and append audio volume adjustment on change - obj.btnVolume.addEventListener("change", function() { - obj.movie.volume = parseFloat(this.value / 10); - }, false); - // Mute - obj.btnMute.addEventListener("click", function() { - if (obj.movie.muted === true) { - obj.movie.muted = false; - } - else { - obj.movie.muted = true; - } - }, false); - - // Duration - obj.movie.addEventListener("timeupdate", function() { - obj.secs = parseInt(obj.movie.currentTime % 60); - obj.mins = parseInt((obj.movie.currentTime / 60) % 60); - - // Ensure it"s two digits. For example, 03 rather than 3. - obj.secs = ("0" + obj.secs).slice(-2); - obj.mins = ("0" + obj.mins).slice(-2); - - // Render - obj.duration.innerHTML = obj.mins + ":" + obj.secs; - }, false); - - // Progress bar - obj.movie.addEventListener("timeupdate", function() { - obj.percent = (100 / obj.movie.duration) * obj.movie.currentTime; - if (obj.percent > 0) { - obj.progressBar.value = obj.percent; - obj.progressBarSpan.innerHTML = obj.percent; - } - }, false); - - // Skip when clicking progress bar - obj.progressBar.addEventListener("click", function(e) { - obj.pos = getClickPosition(e).x / this.offsetWidth; - obj.movie.currentTime = obj.pos * obj.movie.duration; - - // Special handling for "manual" captions - if (!obj.isTextTracks) { - adjustManualCaptions(obj); - } - }); + // Remove native video controls + player.media.removeAttribute("controls"); - // Clear captions at end of video - obj.movie.addEventListener("ended", function() { - obj.captionsContainer.innerHTML = ""; - }); + // Set type + player.type = (player.media.tagName.toLowerCase() == "video" ? "video" : "audio"); + } - // *** - // Captions - // *** + // Setup captions + function setupCaptions() { + if(player.type == "video") { + // Inject the container + player.videoContainer.insertAdjacentHTML("afterbegin", "<div class='" + config.selectors.captions.replace(".", "") + "'></div>"); - // Toggle display of captions via captions button - obj.captionsBtn.addEventListener("click", function() { - if (this.checked) { - obj.captionsContainer.className = "px-video-captions show"; - } else { - obj.captionsContainer.className = "px-video-captions hide"; - } - }, false); + // Cache selector + player.captionsContainer = getElement(config.selectors.captions); - // If no caption file exists, hide container for caption text - if (!obj.captionExists) { - obj.captionsContainer.className = "px-video-captions hide"; - } + // Determine if HTML5 textTracks is supported + player.isTextTracks = false; + if (player.media.textTracks) { + player.isTextTracks = true; + } - // If caption file exists, process captions - else { + // Get URL of caption file if exists + var captionSrc = "", + kind, + children = player.media.childNodes; - // If IE 10/11 or Firefox 31+ or Safari 7+, don"t use native captioning (still doesn"t work although they claim it"s now supported) - if ((obj.browserName==="IE" && obj.browserMajorVersion===10) || - (obj.browserName==="IE" && obj.browserMajorVersion===11) || - (obj.browserName==="Firefox" && obj.browserMajorVersion>=31) || - (obj.browserName==="Safari" && obj.browserMajorVersion>=7)) { - if (options.debug) { - console.log("Detected IE 10/11 or Firefox 31+ or Safari 7+"); - } - // set to false so skips to "manual" captioning - obj.isTextTracks = false; - - // turn off native caption rendering to avoid double captions [doesn"t work in Safari 7; see patch below] - var track = {}; - var tracks = obj.movie.textTracks; - for (var j=0; j < tracks.length; j++) { - track = obj.movie.textTracks[j]; - track.mode = "hidden"; + for (var i = 0; i < children.length; i++) { + if (children[i].nodeName.toLowerCase() === "track") { + kind = children[i].getAttribute("kind"); + if (kind === "captions") { + captionSrc = children[i].getAttribute("src"); + } + } } - } - // Rendering caption tracks - native support required - http://caniuse.com/webvtt - if (obj.isTextTracks) { - if (options.debug) { - console.log("textTracks supported"); + // Record if caption file exists or not + player.captionExists = true; + if (captionSrc === "") { + player.captionExists = false; + if (config.debug) { + console.log("No caption track found."); + } } - showCaptionContainerAndButton(obj); - - var track = {}; - var tracks = obj.movie.textTracks; - for (var j=0; j < tracks.length; j++) { - track = obj.movie.textTracks[j]; - track.mode = "hidden"; - if (track.kind === "captions") { - track.addEventListener("cuechange",function() { - if (this.activeCues[0]) { - if (this.activeCues[0].hasOwnProperty("text")) { - obj.captionsContainer.innerHTML = this.activeCues[0].text; - } - } - },false); + else { + if (config.debug) { + console.log("Caption track found; URI: " + captionSrc); } } - } - // Caption tracks not natively supported - else { - if (options.debug) { - console.log("textTracks not supported so rendering captions manually"); + + // If no caption file exists, hide container for caption text + if (!player.captionExists) { + player.container.className = player.container.className.replace(config.classes.captions, ""); } - showCaptionContainerAndButton(obj); - - // Render captions from array at appropriate time - obj.currentCaption = ""; - obj.subcount = 0; - obj.captions = []; - - obj.movie.addEventListener("timeupdate", function() { - // Check if the next caption is in the current time range - if (obj.movie.currentTime.toFixed(1) > video_timecode_min(obj.captions[obj.subcount][0]) && - obj.movie.currentTime.toFixed(1) < video_timecode_max(obj.captions[obj.subcount][0])) { - obj.currentCaption = obj.captions[obj.subcount][1]; - } - // Is there a next timecode? - if (obj.movie.currentTime.toFixed(1) > video_timecode_max(obj.captions[obj.subcount][0]) && - obj.subcount < (obj.captions.length-1)) { - obj.subcount++; - } - // Render the caption - obj.captionsContainer.innerHTML = obj.currentCaption; - }, false); - - if (captionSrc !== "") { - // Create XMLHttpRequest object - var xhr; - if (window.XMLHttpRequest) { - xhr = new XMLHttpRequest(); - } else if (window.ActiveXObject) { // IE8 - xhr = new ActiveXObject("Microsoft.XMLHTTP"); + + // If caption file exists, process captions + else { + var track = {}, tracks, j; + + // If IE 10/11 or Firefox 31+ or Safari 7+, don"t use native captioning (still doesn"t work although they claim it"s now supported) + if ((player.browserName === "IE" && player.browserMajorVersion === 10) || + (player.browserName === "IE" && player.browserMajorVersion === 11) || + (player.browserName === "Firefox" && player.browserMajorVersion >= 31) || + (player.browserName === "Safari" && player.browserMajorVersion >= 7)) { + if (config.debug) { + console.log("Detected IE 10/11 or Firefox 31+ or Safari 7+"); + } + // set to false so skips to "manual" captioning + player.isTextTracks = false; + + // turn off native caption rendering to avoid double captions [doesn"t work in Safari 7; see patch below] + track = {}; + tracks = player.media.textTracks; + for (j=0; j < tracks.length; j++) { + track = player.media.textTracks[j]; + track.mode = "hidden"; + } } - xhr.onreadystatechange = function() { - if (xhr.readyState === 4) { - if (xhr.status === 200) { - if (options.debug) { - console.log("xhr = 200"); - } - - obj.captions = []; - var records = [], - record, - req = xhr.responseText; - records = req.split("\n\n"); - for (var r=0; r < records.length; r++) { - record = records[r]; - obj.captions[r] = []; - obj.captions[r] = record.split("\n"); - } - // Remove first element ("VTT") - obj.captions.shift(); - if (options.debug) { - console.log("Successfully loaded the caption file via ajax."); - } - } else { - if (options.debug) { - console.log("There was a problem loading the caption file via ajax."); + // Rendering caption tracks - native support required - http://caniuse.com/webvtt + if (player.isTextTracks) { + if (config.debug) { + console.log("textTracks supported"); + } + showCaptionContainerAndButton(player); + + track = {}; + tracks = player.media.textTracks; + for (j=0; j < tracks.length; j++) { + track = player.media.textTracks[j]; + track.mode = "hidden"; + if (track.kind === "captions") { + track.addEventListener("cuechange",function() { + if (this.activeCues[0]) { + if (this.activeCues[0].hasOwnProperty("text")) { + player.captionsContainer.innerHTML = this.activeCues[0].text; + } + } + },false); + } + } + } + // Caption tracks not natively supported + else { + if (config.debug) { + console.log("textTracks not supported so rendering captions manually"); + } + showCaptionContainerAndButton(player); + + // Render captions from array at appropriate time + player.currentCaption = ""; + player.subcount = 0; + player.captions = []; + + player.media.addEventListener("timeupdate", function() { + // Check if the next caption is in the current time range + if (player.media.currentTime.toFixed(1) > video_timecode_min(player.captions[player.subcount][0]) && + player.media.currentTime.toFixed(1) < video_timecode_max(player.captions[player.subcount][0])) { + player.currentCaption = player.captions[player.subcount][1]; + } + // Is there a next timecode? + if (player.media.currentTime.toFixed(1) > video_timecode_max(player.captions[player.subcount][0]) && + player.subcount < (player.captions.length-1)) { + player.subcount++; + } + // Render the caption + player.captionsContainer.innerHTML = player.currentCaption; + }, false); + + if (captionSrc !== "") { + // Create XMLHttpRequest Object + var xhr; + if (window.XMLHttpRequest) { + xhr = new XMLHttpRequest(); + } + else if (window.ActiveXObject) { // IE8 + xhr = new ActiveXObject("Microsoft.XMLHTTP"); + } + xhr.onreadystatechange = function() { + if (xhr.readyState === 4) { + if (xhr.status === 200) { + if (config.debug) { + console.log("xhr = 200"); + } + + player.captions = []; + var records = [], + record, + req = xhr.responseText; + records = req.split("\n\n"); + for (var r=0; r < records.length; r++) { + record = records[r]; + player.captions[r] = []; + player.captions[r] = record.split("\n"); + } + // Remove first element ("VTT") + player.captions.shift(); + + if (config.debug) { + console.log("Successfully loaded the caption file via ajax."); + } + } else { + if (config.debug) { + console.log("There was a problem loading the caption file via ajax."); + } + } } } + xhr.open("get", captionSrc, true); + xhr.send(); } } - xhr.open("get", captionSrc, true); - xhr.send(); + + // If Safari 7, removing track from DOM [see "turn off native caption rendering" above] + if (player.browserName === "Safari" && player.browserMajorVersion === 7) { + console.log("Safari 7 detected; removing track from DOM"); + tracks = player.media.getElementsByTagName("track"); + player.media.removeChild(tracks[0]); + } } } + } - // If Safari 7, removing track from DOM [see "turn off native caption rendering" above] - if (obj.browserName === "Safari" && obj.browserMajorVersion === 7) { - console.log("Safari 7 detected; removing track from DOM"); - var tracks = obj.movie.getElementsByTagName("track"); - obj.movie.removeChild(tracks[0]); + // Setup seeking + function setupSeeking() { + // Update number of seconds in rewind and fast forward buttons + player.seekTime[0].innerHTML = config.seekInterval; + player.seekTime[1].innerHTML = config.seekInterval; + } + + // Listen for events + function listeners() { + + // Fullscreen + player.buttons.fullscreen.addEventListener("click", function() { + if(!fullscreen.isFullScreen()) { + fullscreen.requestFullScreen(player.container); + } + else { + fullscreen.cancelFullScreen(); + } + }, false); + + // Click video + player.videoContainer.addEventListener("click", function() { + if(player.media.paused) { + play(); + } + else if(player.media.ended) { + restart(); + } + else { + pause(); + } + }, false); + + // Play + player.buttons.play.addEventListener("click", function() { + play(); + player.buttons.pause.focus(); + }, false); + + // Pause + player.buttons.pause.addEventListener("click", function() { + pause(); + player.buttons.play.focus(); + }, false); + + // Restart + player.buttons.restart.addEventListener("click", restart, false); + + // Rewind + player.buttons.rewind.addEventListener("click", function() { + var targetTime = player.media.currentTime - config.seekInterval; + + if (targetTime < 0) { + player.media.currentTime = 0; + } + else { + player.media.currentTime = targetTime; + } + // Special handling for "manual" captions + if (!player.isTextTracks) { + adjustManualCaptions(player); + } + }, false); + + // Fast forward + player.buttons.forward.addEventListener("click", function() { + var targetTime = player.media.currentTime + config.seekInterval; + + if (targetTime > player.media.duration) { + player.media.currentTime = player.media.duration; + } + else { + player.media.currentTime = targetTime; + } + // Special handling for "manual" captions + if (!player.isTextTracks) { + adjustManualCaptions(player); + } + }, false); + + // Get the HTML5 range input element and append audio volume adjustment on change + player.buttons.volume.addEventListener("change", function() { + player.media.volume = parseFloat(this.value / 10); + }, false); + + // Mute + player.buttons.mute.addEventListener("click", function() { + if (player.media.muted === true) { + player.media.muted = false; + player.container.className = player.container.className.replace(config.classes.muted, ""); + } + else { + player.media.muted = true; + player.container.className += " " + config.classes.muted; + } + }, false); + + // Duration + player.media.addEventListener("timeupdate", function() { + player.secs = parseInt(player.media.currentTime % 60); + player.mins = parseInt((player.media.currentTime / 60) % 60); + + // Ensure it"s two digits. For example, 03 rather than 3. + player.secs = ("0" + player.secs).slice(-2); + player.mins = ("0" + player.mins).slice(-2); + + // Render + player.duration.innerHTML = player.mins + ":" + player.secs; + }, false); + + // Progress bar + player.media.addEventListener("timeupdate", function() { + player.percent = (100 / player.media.duration) * player.media.currentTime; + + if (player.percent > 0) { + player.progress.bar.value = player.percent; + player.progress.text.innerHTML = player.percent; + } + }, false); + + // Skip when clicking progress bar + player.progress.bar.addEventListener("click", function(e) { + player.pos = getClickPosition(e).x / this.offsetWidth; + player.media.currentTime = player.pos * player.media.duration; + + // Special handling for "manual" captions + if (!player.isTextTracks) { + adjustManualCaptions(player); + } + }); + + // Captions + player.buttons.captions.addEventListener("click", function() { + if (this.checked) { + player.container.className += " " + config.classes.captions; + } + else { + player.container.className = player.container.className.replace(config.classes.captions, ""); + } + }, false); + + // Clear captions at end of video + player.media.addEventListener("ended", function() { + player.captionsContainer.innerHTML = ""; + player.container.className = player.container.className.replace(config.classes.playing, config.classes.stopped); + }); + } + + // Our "on" function which collects handlers + api.on = function(eventName, handler){ + // If no handler collection exists, create one + if(!handlers[eventName]){ + handlers[eventName] = []; + } + handlers[eventName].push(handler); + } + + function setupPlayer(element) { + player.container = element; + player.videoContainer = getElement(config.selectors.videoContainer); + + // Setup media + setupMedia(); + + // Generate random number for id/for attribute values for controls + player.random = Math.floor(Math.random() * (10000)); + + // Inject custom controls + injectControls(); + + // Find the elements + findElements(); + + // Captions + setupCaptions(); + + // Seeking + setupSeeking(); + + // Listeners + listeners(); + } + + // Expose setup function + api.setup = function(options){ + // Extend the default options with user specified + config = extend(defaults, options); + + // Setup the fullscreen api + // Check for support to hide/show the button + fullscreen = fullscreenApi(); + + // Sniff + player.browserInfo = browserSniff(); + player.browserName = player.browserInfo[0]; + player.browserMajorVersion = player.browserInfo[1]; + + // Debug info + if(config.debug) { + console.log(config); + console.log("fullscreen support: " + fullscreen.supportsFullScreen); + console.log(player.browserName + " " + player.browserMajorVersion); } + + // If IE8, stop customization (use fallback) + // If IE9, stop customization (use native controls) + if (player.browserName === "IE" && (player.browserMajorVersion === 8 || player.browserMajorVersion === 9) ) { + console.warn("Browser not suppported."); + return false; + } + + // If smartphone or tablet, stop customization as video (and captions in latest devices) are handled natively + player.isSmartphoneOrTablet = /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent); + if (player.isSmartphoneOrTablet) { + console.warn("Browser not suppported."); + return false; + } + + // Set up aria-label for Play button with the title option + if (typeof(config.title) === "undefined" || !config.title.length) { + config.playAriaLabel = "Play"; + } + else { + config.playAriaLabel = "Play " + config.title; + } + + // Get the container and video container + var elements = document.querySelectorAll(config.selectors.container); + for (var i = elements.length - 1; i >= 0; i--) { + setupPlayer(elements[i]); + } + + //now we execute callbacks registered to shout + executeHandlers("setup"); } -}
\ No newline at end of file + +}(this.simpleMedia = this.simpleMedia || {})); + +/*function InitPxVideo(options) { + + "use strict"; + + + // *** + // Captions + // *** + + +}*/
\ No newline at end of file diff --git a/assets/less/simple-media.less b/assets/less/simple-media.less index edf9b059..338a4706 100644 --- a/assets/less/simple-media.less +++ b/assets/less/simple-media.less @@ -5,26 +5,21 @@ // Variables // ------------------------------- // Colors -@base-color: #2E3C44; -@green: #1ABC9C; -@red: #D44334; -@blue: #3498DB; - -// Grays -@gray-dark: #343f4a; -@gray: #565d64; -@gray-light: #6f7e86; -@gray-lighter: #859093; -@gray-lightest: #cbd0d3; -@gray-light-mega: #dadfe2; -@off-white: #f9fafb; +@blue: #3498DB; +@gray-dark: #343f4a; +@gray: #565d64; +@gray-light: #cbd0d3; // Controls -@control-color: @gray-lightest; -@control-color-active: @blue; -@control-color-inactive: @gray; -@control-spacing: 10px; +@controls-bg: @gray-dark; +@control-color: @gray-light; +@control-color-active: @blue; +@control-color-inactive: @gray; +@control-spacing: 10px; +// Progress +@progress-bg: @gray; +@progress-value-bg: @blue; // BORDER-BOX ALL THE THINGS! (http://paulirish.com/2012/box-sizing-border-box-ftw/) // ------------------------------- @@ -37,6 +32,7 @@ // Utility classes & mixins // ------------------------------- +// Screen reader only .sr-only { position: absolute !important; clip: rect(1px, 1px, 1px, 1px); @@ -46,12 +42,6 @@ width: 1px !important; overflow: hidden; } -.hide { - display: none; -} -.show-inline { - display: inline-block; -} // Contain floats: nicolasgallagher.com/micro-clearfix-hack/ .clearfix() { zoom: 1; @@ -59,6 +49,13 @@ &:after { content: ""; display: table; } &:after { clear: both; } } + +// Tab focus styles +.tab-focus() { + outline: thin dotted #000; + outline-offset: 1px; +} + // Font smoothing // --------------------------------------- .font-smoothing(@mode: on) when (@mode = on) { @@ -79,47 +76,21 @@ overflow: hidden; // For the controls background: #000; + // For video &-video { position: relative; } - &:fullscreen { - height: 100%; - width: 100%; - - &-video { - position: absolute; - top: 50%; - left: 0; - right: 0; - transform: translateY(-50%); - } - &-controls { - position: absolute; - bottom: 0; - left: 0; - right: 0; - - .icon-exit-fullscreen { - display: block; - - & + svg { - display: none; - } - } - } - } video { width: 100%; height: auto; vertical-align: middle; } - svg { - width: 18px; - height: 18px; - } - .px-video-captions { + + // Captions + &-captions { + display: none; position: absolute; bottom: 0; left: 0; @@ -132,13 +103,26 @@ text-align: center; .font-smoothing(); } + &.captions &-captions { + display: block; + } + // Player controls &-controls { .clearfix(); + .font-smoothing(); position: relative; padding: (@control-spacing * 2) @control-spacing @control-spacing; - background: @gray-dark; + background: @controls-bg; line-height: 1; + + // Layout + &-playback { + float: left; + } + &-sound { + float: right; + } input + label, button { @@ -152,6 +136,8 @@ cursor: pointer; svg { + width: 18px; + height: 18px; display: block; fill: currentColor; transition: fill .3s ease; @@ -170,25 +156,28 @@ border: 0; background: transparent; overflow: hidden; - - &:focus { - outline: 0; - } } button:hover, - button:focus, - label:hover, - input:focus + label { + label:hover { background: @control-color-active; svg { fill: #fff; } } - .icon-exit-fullscreen { + input:focus + label, + button:focus { + .tab-focus(); + + svg { + fill: #fff; + } + } + .icon-exit-fullscreen, + .icon-muted { display: none; } - .px-video-time { + .player-time { display: inline-block; vertical-align: middle; margin-left: @control-spacing; @@ -198,7 +187,9 @@ .font-smoothing(); } } - progress { + + // Player progress + &-progress { position: absolute; top: 0; left: 0; @@ -211,45 +202,48 @@ &[value] { -webkit-appearance: none; border: none; - background: @gray; + background: @progress-bg; cursor: pointer; &::-webkit-progress-bar { - background: @gray; + background: @progress-bg; } // The value &::-webkit-progress-value { - background: @control-color-active; + background: @progress-value-bg; } &::-moz-progress-bar { - background: @control-color-active; + background: @progress-value-bg; } } } - .play-controls { - float: left; - } - .sound-controls { - float: right; - } - &-controls .px-video-pause, - &.playing .player-controls .px-video-play { + // States + &-controls [data-player='pause'], + &.playing .player-controls [data-player='play'] { display: none; } - &.playing .player-controls .px-video-pause { + &.playing .player-controls [data-player='pause'] { display: inline-block; } + // Muted + &.muted .player-controls .icon-muted { + display: block; + + & + svg { + display: none; + } + } + // Volume control - input[type='range'] { + &-volume { -webkit-appearance: none; height: 6px; width: 100px; margin-right: @control-spacing; background: @gray; - outline: 0; border-radius: 10px; &::-moz-range-track { @@ -274,27 +268,59 @@ background: @control-color; border-radius: 100%; } - &:focus::-webkit-slider-thumb { - background: @control-color-active; + &:focus { + outline: 0; + + &::-webkit-slider-thumb { + background: @control-color-active; + } + &::-moz-range-thumb { + background: @control-color-active; + } } - &:focus::-moz-range-thumb { - background: @control-color-active; + } + + // Full screen mode + &:fullscreen { + height: 100%; + width: 100%; + + .player-video { + position: absolute; + top: 50%; + left: 0; + right: 0; + transform: translateY(-50%); + } + .player-controls { + position: absolute; + bottom: 0; + left: 0; + right: 0; + + .icon-exit-fullscreen { + display: block; + + & + svg { + display: none; + } + } } } } /* fixing display for IE10+ */ @media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) { - .px-video-controls input[type='range'] { + .video-controls .player-volume { position: relative; padding: 0; height: 8px; top: -3px; } - .px-video-time { + .player-time { margin-top: 4px; } - .px-video-captions { + .player-captions { padding: 8px; min-height: 36px; } diff --git a/assets/templates/controls.html b/assets/templates/controls.html index 3b1c6735..3109d795 100644 --- a/assets/templates/controls.html +++ b/assets/templates/controls.html @@ -1,54 +1,53 @@ <div class="player-controls"> - <progress class="px-video-progress" max="100" value="0"><span>0</span>% played</progress> + <progress class="player-progress" max="100" value="0"> + <span>0</span>% played + </progress> - <div class="play-controls"> - <button class="px-video-restart" data-player="restart"> + <div class="player-controls-playback"> + <button data-player="restart"> <svg><use xlink:href="#icon-refresh"></use></svg> <span class="sr-only">Restart</span> </button> - <button class="px-video-rewind" data-player="rewind"> + <button data-player="rewind"> <svg><use xlink:href="#icon-rewind"></use></svg> - <span class="sr-only">Rewind <span class="px-seconds">10</span> seconds</span> + <span class="sr-only">Rewind <span class="player-seek-time">10</span> seconds</span> </button> - <button class="px-video-play" aria-label="{aria-label}" data-player="play"> + <button aria-label="{aria-label}" data-player="play"> <svg><use xlink:href="#icon-play"></use></svg> <span class="sr-only">Play</span> </button> - <button class="px-video-pause" data-player="pause"> + <button data-player="pause"> <svg><use xlink:href="#icon-pause"></use></svg> <span class="sr-only">Pause</span> </button> - <button class="px-video-forward" data-player="fast-forward"> + <button data-player="fast-forward"> <svg><use xlink:href="#icon-fast-forward"></use></svg> - <span class="sr-only">Fast forward <span class="px-seconds">10</span> seconds</span> + <span class="sr-only">Fast forward <span class="player-seek-time">10</span> seconds</span> </button> - <div class="px-video-time"> + <span class="player-time"> <span class="sr-only">Time</span> - <span class="px-video-duration">00:00</span> - </div> + <span class="player-duration">00:00</span> + </span> </div> - <div class="sound-controls"> - <!--<div class="px-video-mute-btn-container">--> - <input class="px-video-mute inverted sr-only" id="btnMute{id}" type="checkbox"> - <label id="labelMute{id}" for="btnMute{id}"> - <svg><use xlink:href="#icon-sound"></use></svg> - <span class="sr-only">Mute</span> - </label> - <!--</div>--> + <div class="player-controls-sound"> + <input class="inverted sr-only" id="mute{id}" type="checkbox" data-player="mute"> + <label id="mute{id}" for="mute{id}"> + <svg class="icon-muted"><use xlink:href="#icon-muted"></use></svg> + <svg><use xlink:href="#icon-sound"></use></svg> + <span class="sr-only">Mute</span> + </label> <label for="volume{id}" class="sr-only">Volume:</label> - <input id="volume{id}" class="px-video-volume" type="range" min="0" max="10" value="5"> + <input id="volume{id}" class="player-volume" type="range" min="0" max="10" value="5" data-player="volume"> - <!--<div class="px-video-captions-btn-container hide">--> - <input class="px-video-btnCaptions sr-only" id="btnCaptions{id}" type="checkbox"> - <label for="btnCaptions{id}"> - <svg><use xlink:href="#icon-film"></use></svg> - <span class="sr-only">Captions</span> - </label> - <!--</div>--> + <input class="sr-only" id="captions{id}" type="checkbox" data-player="captions"> + <label for="captions{id}"> + <svg><use xlink:href="#icon-bubble"></use></svg> + <span class="sr-only">Captions</span> + </label> - <button class="player-toggle-fullscreen" data-player="toggle-fullscreen"> + <button data-player="fullscreen"> <svg class="icon-exit-fullscreen"><use xlink:href="#icon-collapse"></use></svg> <svg><use xlink:href="#icon-expand"></use></svg> <span class="sr-only">Toggle fullscreen</span> |