From 63c1d04d72845ecaf82df14ca06300b0d220def9 Mon Sep 17 00:00:00 2001 From: Sam Potts Date: Sun, 15 Feb 2015 11:03:06 +1100 Subject: [PATCH] Improved plugin syntax, refactoring... --- assets/icons/bubble.svg | 6 + assets/icons/film.svg | 6 - assets/icons/muted.svg | 14 + assets/icons/pause.svg | 8 +- assets/js/docs.js | 20 +- assets/js/simple-media.js | 1231 ++++++++++------- assets/less/simple-media.less | 200 +-- assets/templates/controls.html | 57 +- design/IcoMoon/PNG/bubble.png | Bin 0 -> 420 bytes .../PNG/fast-forward.png | Bin .../PNG/film.png | Bin .../PNG/monitor.png | Bin .../PNG/play.png | Bin .../PNG/refresh.png | Bin .../PNG/sound.png | Bin .../{IcoMoon - 7 Icons => IcoMoon}/PNG/up.png | Bin .../Read Me.txt | 0 design/IcoMoon/SVG/bubble.svg | 6 + .../SVG/fast-forward.svg | 0 .../SVG/film.svg | 0 .../SVG/monitor.svg | 0 .../SVG/play.svg | 0 .../SVG/refresh.svg | 0 .../SVG/sound.svg | 0 .../{IcoMoon - 7 Icons => IcoMoon}/SVG/up.svg | 0 .../demo-files/demo.css | 0 .../{IcoMoon - 7 Icons => IcoMoon}/demo.html | 9 + .../{IcoMoon - 7 Icons => IcoMoon}/style.css | 0 .../svgdefs.svg | 4 + design/captions.sketch | Bin 0 -> 49152 bytes design/muted.sketch | Bin 0 -> 40960 bytes design/pause.sketch | Bin 32768 -> 40960 bytes dist/css/simple-media.css | 2 +- dist/js/docs.js | 2 +- dist/js/simple-media.js | 2 +- dist/js/templates.js | 2 +- dist/svg/sprite.svg | 2 +- docs/index.html | 3 +- gulpfile.js | 6 +- 39 files changed, 902 insertions(+), 678 deletions(-) create mode 100755 assets/icons/bubble.svg delete mode 100755 assets/icons/film.svg create mode 100644 assets/icons/muted.svg create mode 100755 design/IcoMoon/PNG/bubble.png rename design/{IcoMoon - 7 Icons => IcoMoon}/PNG/fast-forward.png (100%) rename design/{IcoMoon - 7 Icons => IcoMoon}/PNG/film.png (100%) rename design/{IcoMoon - 7 Icons => IcoMoon}/PNG/monitor.png (100%) rename design/{IcoMoon - 7 Icons => IcoMoon}/PNG/play.png (100%) rename design/{IcoMoon - 7 Icons => IcoMoon}/PNG/refresh.png (100%) rename design/{IcoMoon - 7 Icons => IcoMoon}/PNG/sound.png (100%) rename design/{IcoMoon - 7 Icons => IcoMoon}/PNG/up.png (100%) rename design/{IcoMoon - 7 Icons => IcoMoon}/Read Me.txt (100%) create mode 100755 design/IcoMoon/SVG/bubble.svg rename design/{IcoMoon - 7 Icons => IcoMoon}/SVG/fast-forward.svg (100%) rename design/{IcoMoon - 7 Icons => IcoMoon}/SVG/film.svg (100%) rename design/{IcoMoon - 7 Icons => IcoMoon}/SVG/monitor.svg (100%) rename design/{IcoMoon - 7 Icons => IcoMoon}/SVG/play.svg (100%) rename design/{IcoMoon - 7 Icons => IcoMoon}/SVG/refresh.svg (100%) rename design/{IcoMoon - 7 Icons => IcoMoon}/SVG/sound.svg (100%) rename design/{IcoMoon - 7 Icons => IcoMoon}/SVG/up.svg (100%) rename design/{IcoMoon - 7 Icons => IcoMoon}/demo-files/demo.css (100%) rename design/{IcoMoon - 7 Icons => IcoMoon}/demo.html (89%) rename design/{IcoMoon - 7 Icons => IcoMoon}/style.css (100%) rename design/{IcoMoon - 7 Icons => IcoMoon}/svgdefs.svg (89%) create mode 100644 design/captions.sketch create mode 100644 design/muted.sketch 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 @@ + + + + + + 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 @@ - - - - - - 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 @@ + + + + muted + Created with Sketch. + + + + + + + + + \ 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 @@ pause Created with Sketch. - - - - + + + + \ 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); - } - }); - } + // Globals + var fullscreen, config; - // 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); + // Handler cache + var handlers = {}; - return { - x: e.clientX - parentPosition.x, - y: e.clientY - parentPosition.y - }; - } + // Object cache + var player = {}; - // 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; + // 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 } - - 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"); - } - } + }; // 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); - } - - // Set up aria-label for Play button with the videoTitle option - if ((typeof(options.videoTitle)==="undefined") || (options.videoTitle==="")) { - obj.playAriaLabel = "Play"; - } - else { - obj.playAriaLabel = "Play video, " + options.videoTitle; - } - - // 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..."); - } - 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; - } - 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"); + // 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; } } } - - // Record if caption file exists or not - obj.captionExists = true; - if (captionSrc === "") { - obj.captionExists = false; - if (options.debug) { - console.log("No caption track found."); - } - } - else { - if (options.debug) { - console.log("Caption track found; URI: " + captionSrc); + // 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"); } } - // Set captions on/off - on by default - if (typeof(options.captionsOnDefault) === "undefined") { - options.captionsOnDefault = true; - } - obj.isCaptionDefault = options.captionsOnDefault; - - // Number of seconds for rewind and forward buttons - if (typeof(options.seekInterval) === "undefined") { - options.seekInterval = 10; - } - 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; + // Replace all + function replaceAll(string, find, replace) { + return string.replace(new RegExp(find.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"), "g"), replace); } - // Fullscreen - obj.toggleFullscreen.addEventListener("click", function() { - if(!window.fullscreen.isFullScreen()) { - window.fullscreen.requestFullScreen(obj.container); - } - else { - window.fullscreen.cancelFullScreen(); - } - }, false); + // 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); - // Click video - obj.videoContainer.addEventListener("click", function() { - if(obj.movie.paused) { - play(); - } - else if(obj.movie.ended) { - restart(); - } - else { - pause(); - } - }, false); + return { + x: e.clientX - parentPosition.x, + y: e.clientY - parentPosition.y + }; + } - function play() { - obj.movie.play(); - obj.container.className = obj.container.className.replace("stopped", "playing"); + // 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 + }; } + // 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; + } + + // 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,[]); + } + } + + // 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"; + + 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; + } + + // 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); + } + + // Find all elements + function getElements(selector) { + return player.container.querySelectorAll(selector); + } + + // Find a single element + function getElement(selector) { + return getElements(selector)[0]; + } + + // 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() { + 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); + // Setup media + function setupMedia() { + player.media = player.container.querySelectorAll("audio, video")[0]; - // Pause - obj.btnPause.addEventListener("click", function() { pause(); obj.btnPlay.focus(); }, false); - - // 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; + } + + // Remove native video controls + player.media.removeAttribute("controls"); + + // Set type + player.type = (player.media.tagName.toLowerCase() == "video" ? "video" : "audio"); + } + + // Setup captions + function setupCaptions() { + if(player.type == "video") { + // Inject the container + player.videoContainer.insertAdjacentHTML("afterbegin", "
"); + + // Cache selector + player.captionsContainer = getElement(config.selectors.captions); + + // Determine if HTML5 textTracks is supported + player.isTextTracks = false; + if (player.media.textTracks) { + player.isTextTracks = true; + } + + // Get URL of caption file if exists + var captionSrc = "", + kind, + children = player.media.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"); + } + } + } + + // Record if caption file exists or not + player.captionExists = true; + if (captionSrc === "") { + player.captionExists = false; + if (config.debug) { + console.log("No caption track found."); + } + } + else { + if (config.debug) { + console.log("Caption track found; URI: " + captionSrc); + } + } + + // If no caption file exists, hide container for caption text + if (!player.captionExists) { + player.container.className = player.container.className.replace(config.classes.captions, ""); + } + + // 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"; + } + } + + // 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(); + } + } + + // 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]); + } + } + } + } + + // 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 { - obj.movie.currentTime = targetTime; + config.playAriaLabel = "Play " + config.title; } - // Special handling for "manual" captions - if (!obj.isTextTracks) { - adjustManualCaptions(obj); + + // 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]); } - }, 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); + //now we execute callbacks registered to shout + executeHandlers("setup"); + } - // 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); +}(this.simpleMedia = this.simpleMedia || {})); - // Render - obj.duration.innerHTML = obj.mins + ":" + obj.secs; - }, false); +/*function InitPxVideo(options) { - // 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); + "use strict"; - // 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); - } - }); - - // Clear captions at end of video - obj.movie.addEventListener("ended", function() { - obj.captionsContainer.innerHTML = ""; - }); // *** // Captions // *** - // 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); - // If no caption file exists, hide container for caption text - if (!obj.captionExists) { - obj.captionsContainer.className = "px-video-captions hide"; - } - - // If caption file exists, process captions - else { - - // 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"; - } - } - - // Rendering caption tracks - native support required - http://caniuse.com/webvtt - if (obj.isTextTracks) { - if (options.debug) { - console.log("textTracks supported"); - } - 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); - } - } - } - // Caption tracks not natively supported - else { - if (options.debug) { - console.log("textTracks not supported so rendering captions manually"); - } - 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"); - } - 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."); - } - } - } - } - xhr.open("get", captionSrc, true); - xhr.send(); - } - } - - // 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]); - } - } -} \ No newline at end of file +}*/ \ 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 @@
- 0% played + + 0% played + -
- - - - - -
+ Time - 00:00 -
+ 00:00 +
-
- - - - +
+ + - + - - - - + + - "),s.b("\n"+e),s.b(' "),s.b("\n"+e),s.b(' "),s.b("\n"+e),s.b(' "),s.b("\n"+e),s.b(' "),s.b("\n"+e),s.b('
'),s.b("\n"+e),s.b(' Time'),s.b("\n"+e),s.b(' 00:00'),s.b("\n"+e),s.b("
"),s.b("\n"+e),s.b("
"),s.b("\n"),s.b("\n"+e),s.b('
'),s.b("\n"+e),s.b(' '),s.b("\n"+e),s.b(' '),s.b("\n"+e),s.b(' "),s.b("\n"+e),s.b(" "),s.b("\n"),s.b("\n"+e),s.b(' '),s.b("\n"+e),s.b(' '),s.b("\n"),s.b("\n"+e),s.b(' '),s.b("\n"+e),s.b(' '),s.b("\n"+e),s.b(' "),s.b("\n"+e),s.b(" "),s.b("\n"),s.b("\n"+e),s.b(' "),s.b("\n"+e),s.b("
"),s.b("\n"+e),s.b("
"),s.b("\n"),s.fl()},partials:{},subs:{}});var video=new InitPxVideo({videoId:"myvid",captionsOnDefault:!0,seekInterval:20,videoTitle:"PayPal Austin promo",debug:!0,html:templates.controls.render({})});console.log(video); \ No newline at end of file +var Hogan={};!function(t){function n(t,n,e){var s;return n&&"object"==typeof n&&(void 0!==n[t]?s=n[t]:e&&n.get&&"function"==typeof n.get&&(s=n.get(t))),s}function e(t,n,e,s,r,a){function i(){}function o(){}i.prototype=t,o.prototype=t.subs;var l,u=new i;u.subs=new o,u.subsText={},u.buf="",s=s||{},u.stackSubs=s,u.subsText=a;for(l in n)s[l]||(s[l]=n[l]);for(l in s)u.subs[l]=s[l];r=r||{},u.stackPartials=r;for(l in e)r[l]||(r[l]=e[l]);for(l in r)u.partials[l]=r[l];return u}function s(t){return String(null===t||void 0===t?"":t)}function r(t){return t=s(t),c.test(t)?t.replace(a,"&").replace(i,"<").replace(o,">").replace(l,"'").replace(u,"""):t}t.Template=function(t,n,e,s){t=t||{},this.r=t.code||this.r,this.c=e,this.options=s||{},this.text=n||"",this.partials=t.partials||{},this.subs=t.subs||{},this.buf=""},t.Template.prototype={r:function(){return""},v:r,t:s,render:function(t,n,e){return this.ri([t],n||{},e)},ri:function(t,n,e){return this.r(t,n,e)},ep:function(t,n){var s=this.partials[t],r=n[s.name];if(s.instance&&s.base==r)return s.instance;if("string"==typeof r){if(!this.c)throw new Error("No compiler available.");r=this.c.compile(r,this.options)}if(!r)return null;if(this.partials[t].base=r,s.subs){n.stackText||(n.stackText={});for(key in s.subs)n.stackText[key]||(n.stackText[key]=void 0!==this.activeSub&&n.stackText[this.activeSub]?n.stackText[this.activeSub]:this.text);r=e(r,s.subs,s.partials,this.stackSubs,this.stackPartials,n.stackText)}return this.partials[t].instance=r,r},rp:function(t,n,e,s){var r=this.ep(t,e);return r?r.ri(n,e,s):""},rs:function(t,n,e){var s=t[t.length-1];if(!p(s))return e(t,n,this),void 0;for(var r=0;r=0;u--)if(i=e[u],a=n(t,i,l),void 0!==a){o=!0;break}return o?(r||"function"!=typeof a||(a=this.mv(a,e,s)),a):r?!1:""},ls:function(t,n,e,r,a){var i=this.options.delimiters;return this.options.delimiters=a,this.b(this.ct(s(t.call(n,r)),n,e)),this.options.delimiters=i,!1},ct:function(t,n,e){if(this.options.disableLambda)throw new Error("Lambda features disabled.");return this.c.compile(t,this.options).render(n,e)},b:function(t){this.buf+=t},fl:function(){var t=this.buf;return this.buf="",t},ms:function(t,n,e,s,r,a,i){var o,l=n[n.length-1],u=t.call(l);return"function"==typeof u?s?!0:(o=this.activeSub&&this.subsText&&this.subsText[this.activeSub]?this.subsText[this.activeSub]:this.text,this.ls(u,l,e,o.substring(r,a),i)):u},mv:function(t,n,e){var r=n[n.length-1],a=t.call(r);return"function"==typeof a?this.ct(s(a.call(r)),r,e):a},sub:function(t,n,e,s){var r=this.subs[t];r&&(this.activeSub=t,r(n,e,this,s),this.activeSub=!1)}};var a=/&/g,i=//g,l=/\'/g,u=/\"/g,c=/[&<>\"\']/,p=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)}}("undefined"!=typeof exports?exports:Hogan),function(t){function n(t){"}"===t.n.substr(t.n.length-1)&&(t.n=t.n.substring(0,t.n.length-1))}function e(t){return t.trim?t.trim():t.replace(/^\s*|\s*$/g,"")}function s(t,n,e){if(n.charAt(e)!=t.charAt(0))return!1;for(var s=1,r=t.length;r>s;s++)if(n.charAt(e+s)!=t.charAt(s))return!1;return!0}function r(n,e,s,o){var l=[],u=null,c=null,p=null;for(c=s[s.length-1];n.length>0;){if(p=n.shift(),c&&"<"==c.tag&&!(p.tag in k))throw new Error("Illegal content in < super tag.");if(t.tags[p.tag]<=t.tags.$||a(p,o))s.push(p),p.nodes=r(n,p.tag,s,o);else{if("/"==p.tag){if(0===s.length)throw new Error("Closing tag without opener: /"+p.n);if(u=s.pop(),p.n!=u.n&&!i(p.n,u.n,o))throw new Error("Nesting error: "+u.n+" vs. "+p.n);return u.end=p.i,l}"\n"==p.tag&&(p.last=0==n.length||"\n"==n[0].tag)}l.push(p)}if(s.length>0)throw new Error("missing closing tag: "+s.pop().n);return l}function a(t,n){for(var e=0,s=n.length;s>e;e++)if(n[e].o==t.n)return t.tag="#",!0}function i(t,n,e){for(var s=0,r=e.length;r>s;s++)if(e[s].c==t&&e[s].o==n)return!0}function o(t){var n=[];for(var e in t)n.push('"'+u(e)+'": function(c,p,t,i) {'+t[e]+"}");return"{ "+n.join(",")+" }"}function l(t){var n=[];for(var e in t.partials)n.push('"'+u(e)+'":{name:"'+u(t.partials[e].name)+'", '+l(t.partials[e])+"}");return"partials: {"+n.join(",")+"}, subs: "+o(t.subs)}function u(t){return t.replace(m,"\\\\").replace(g,'\\"').replace(d,"\\n").replace(v,"\\r").replace(y,"\\u2028").replace(x,"\\u2029")}function c(t){return~t.indexOf(".")?"d":"f"}function p(t,n){var e="<"+(n.prefix||""),s=e+t.n+w++;return n.partials[s]={name:t.n,partials:{}},n.code+='t.b(t.rp("'+u(s)+'",c,p,"'+(t.indent||"")+'"));',s}function b(t,n){n.code+="t.b(t.t(t."+c(t.n)+'("'+u(t.n)+'",c,p,0)));'}function f(t){return"t.b("+t+");"}var h=/\S/,g=/\"/g,d=/\n/g,v=/\r/g,m=/\\/g,y=/\u2028/,x=/\u2029/;t.tags={"#":1,"^":2,"<":3,$:4,"/":5,"!":6,">":7,"=":8,_v:9,"{":10,"&":11,_t:12},t.scan=function(r,a){function i(){m.length>0&&(y.push({tag:"_t",text:new String(m)}),m="")}function o(){for(var n=!0,e=w;e"==e.tag&&(e.indent=y[s].text.toString()),y.splice(s,1));else n||y.push({tag:"\n"});x=!1,w=y.length}function u(t,n){var s="="+S,r=t.indexOf(s,n),a=e(t.substring(t.indexOf("=",n)+1,r)).split(" ");return T=a[0],S=a[a.length-1],r+s.length-1}var c=r.length,p=0,b=1,f=2,g=p,d=null,v=null,m="",y=[],x=!1,k=0,w=0,T="{{",S="}}";for(a&&(a=a.split(" "),T=a[0],S=a[1]),k=0;c>k;k++)g==p?s(T,r,k)?(--k,i(),g=b):"\n"==r.charAt(k)?l(x):m+=r.charAt(k):g==b?(k+=T.length-1,v=t.tags[r.charAt(k+1)],d=v?r.charAt(k+1):"_v","="==d?(k=u(r,k),g=p):(v&&k++,g=f),x=k):s(S,r,k)?(y.push({tag:d,n:e(m),otag:T,ctag:S,i:"/"==d?x-T.length:k+S.length}),m="",k+=S.length-1,g=p,"{"==d&&("}}"==S?k++:n(y[y.length-1]))):m+=r.charAt(k);return l(x,!0),y};var k={_t:!0,"\n":!0,$:!0,"/":!0};t.stringify=function(n){return"{code: function (c,p,i) { "+t.wrapMain(n.code)+" },"+l(n)+"}"};var w=0;t.generate=function(n,e,s){w=0;var r={code:"",subs:{},partials:{}};return t.walk(n,r),s.asString?this.stringify(r,e,s):this.makeTemplate(r,e,s)},t.wrapMain=function(t){return'var t=this;t.b(i=i||"");'+t+"return t.fl();"},t.template=t.Template,t.makeTemplate=function(t,n,e){var s=this.makePartials(t);return s.code=new Function("c","p","i",this.wrapMain(t.code)),new this.template(s,n,this,e)},t.makePartials=function(t){var n,e={subs:{},partials:t.partials,name:t.name};for(n in e.partials)e.partials[n]=this.makePartials(e.partials[n]);for(n in t.subs)e.subs[n]=new Function("c","p","t","i",t.subs[n]);return e},t.codegen={"#":function(n,e){e.code+="if(t.s(t."+c(n.n)+'("'+u(n.n)+'",c,p,1),c,p,0,'+n.i+","+n.end+',"'+n.otag+" "+n.ctag+'")){t.rs(c,p,function(c,p,t){',t.walk(n.nodes,e),e.code+="});c.pop();}"},"^":function(n,e){e.code+="if(!t.s(t."+c(n.n)+'("'+u(n.n)+'",c,p,1),c,p,1,0,0,"")){',t.walk(n.nodes,e),e.code+="};"},">":p,"<":function(n,e){var s={partials:{},code:"",subs:{},inPartial:!0};t.walk(n.nodes,s);var r=e.partials[p(n,e)];r.subs=s.subs,r.partials=s.partials},$:function(n,e){var s={subs:{},code:"",partials:e.partials,prefix:n.n};t.walk(n.nodes,s),e.subs[n.n]=s.code,e.inPartial||(e.code+='t.sub("'+u(n.n)+'",c,p,i);')},"\n":function(t,n){n.code+=f('"\\n"'+(t.last?"":" + i"))},_v:function(t,n){n.code+="t.b(t.v(t."+c(t.n)+'("'+u(t.n)+'",c,p,0)));'},_t:function(t,n){n.code+=f('"'+u(t.text)+'"')},"{":b,"&":b},t.walk=function(n,e){for(var s,r=0,a=n.length;a>r;r++)s=t.codegen[n[r].tag],s&&s(n[r],e);return e},t.parse=function(t,n,e){return e=e||{},r(t,"",[],e.sectionTags||[])},t.cache={},t.cacheKey=function(t,n){return[t,!!n.asString,!!n.disableLambda,n.delimiters,!!n.modelGet].join("||")},t.compile=function(n,e){e=e||{};var s=t.cacheKey(n,e),r=this.cache[s];if(r){var a=r.partials;for(var i in a)delete a[i].instance;return r}return r=this.generate(this.parse(this.scan(n,e.delimiters),n,e),n,e),this.cache[s]=r}}("undefined"!=typeof exports?exports:Hogan);var Mustache=function(t){function n(n,e,s,r){var a=this.f(n,e,s,0),i=e;return a&&(i=i.concat(a)),t.Template.prototype.rp.call(this,n,i,s,r)}var e=function(e,s,r){this.rp=n,t.Template.call(this,e,s,r)};e.prototype=t.Template.prototype;var s,r=function(){this.cache={},this.generate=function(t,n){return new e(new Function("c","p","i",t),n,s)}};return r.prototype=t,s=new r,{to_html:function(t,n,e,r){var a=s.compile(t),i=a.render(n,e);return r?(r(i),void 0):i}}}(Hogan),templates={};templates.controls=new Hogan.Template({code:function(t,n,e){var s=this;return s.b(e=e||""),s.b('
'),s.b("\n"+e),s.b(' '),s.b("\n"+e),s.b(" 0% played"),s.b("\n"+e),s.b(" "),s.b("\n"),s.b("\n"+e),s.b('
'),s.b("\n"+e),s.b(' "),s.b("\n"+e),s.b(' "),s.b("\n"+e),s.b(' "),s.b("\n"+e),s.b(' "),s.b("\n"+e),s.b(' "),s.b("\n"+e),s.b(' '),s.b("\n"+e),s.b(' Time'),s.b("\n"+e),s.b(' 00:00'),s.b("\n"+e),s.b(" "),s.b("\n"+e),s.b("
"),s.b("\n"),s.b("\n"+e),s.b('
'),s.b("\n"+e),s.b(' '),s.b("\n"+e),s.b(' "),s.b("\n"),s.b("\n"+e),s.b(' '),s.b("\n"+e),s.b(' '),s.b("\n"),s.b("\n"+e),s.b(' '),s.b("\n"+e),s.b(' "),s.b("\n"),s.b("\n"+e),s.b(' "),s.b("\n"+e),s.b("
"),s.b("\n"+e),s.b("
"),s.b("\n"),s.fl()},partials:{},subs:{}}),simpleMedia.on("setup",function(){console.log(this)}),simpleMedia.setup({debug:!0,title:"PayPal demo",html:templates.controls.render({})}); \ No newline at end of file diff --git a/dist/js/simple-media.js b/dist/js/simple-media.js index f048bd6d..ce6d9378 100644 --- a/dist/js/simple-media.js +++ b/dist/js/simple-media.js @@ -1 +1 @@ -function InitPxVideo(e){"use strict";function n(e){var n=window.fullscreen.isFullScreen()?{x:0,y:0}:t(e.currentTarget);return{x:e.clientX-n.x,y:e.clientY-n.y}}function t(e){for(var n=0,t=0;e;)n+=e.offsetLeft-e.scrollLeft+e.clientLeft,t+=e.offsetTop-e.scrollTop+e.clientTop,e=e.offsetParent;return{x:n,y:t}}function r(e){var n=[];return n=e.split(" --> "),o(n[0])}function i(e){var n=[];return n=e.split(" --> "),o(n[1])}function o(e){if(null===e||void 0===e)return 0;var n,t=[],r=[];return t=e.split(","),r=t[0].split(":"),n=Math.floor(60*r[0]*60)+Math.floor(60*r[1])+Math.floor(r[2])}function a(e){for(e.subcount=0;i(e.captions[e.subcount][0])e.captions.length-1){e.subcount=e.captions.length-1;break}}function s(e){e.isCaptionDefault&&(e.captionsContainer.className="px-video-captions show",e.captionsBtn.setAttribute("checked","checked"))}function c(){var e,n,t,r=navigator.userAgent,i=navigator.appName,o=""+parseFloat(navigator.appVersion),a=parseInt(navigator.appVersion,10);return-1!==navigator.appVersion.indexOf("Windows NT")&&-1!==navigator.appVersion.indexOf("rv:11")?(i="IE",o="11;"):-1!==(n=r.indexOf("MSIE"))?(i="IE",o=r.substring(n+5)):-1!==(n=r.indexOf("Chrome"))?(i="Chrome",o=r.substring(n+7)):-1!==(n=r.indexOf("Safari"))?(i="Safari",o=r.substring(n+7),-1!==(n=r.indexOf("Version"))&&(o=r.substring(n+8))):-1!==(n=r.indexOf("Firefox"))?(i="Firefox",o=r.substring(n+8)):(e=r.lastIndexOf(" ")+1)<(n=r.lastIndexOf("/"))&&(i=r.substring(e,n),o=r.substring(n+1),i.toLowerCase()==i.toUpperCase()&&(i=navigator.appName)),-1!==(t=o.indexOf(";"))&&(o=o.substring(0,t)),-1!==(t=o.indexOf(" "))&&(o=o.substring(0,t)),a=parseInt(""+o,10),isNaN(a)&&(o=""+parseFloat(navigator.appVersion),a=parseInt(navigator.appVersion,10)),[i,a]}function l(){p.movie.play(),p.container.className=p.container.className.replace("stopped","playing")}function u(){p.movie.pause(),p.container.className=p.container.className.replace("playing","stopped")}function d(){p.movie.currentTime=0,p.isTextTracks||(p.subcount=0),l()}String.prototype.replaceAll||Object.defineProperty(String.prototype,"replaceAll",{value:function(e,n){return this.replace(new RegExp(e.replace(/([.*+?^=!:${}()|\[\]\/\\])/g,"\\$1"),"g"),n)}});var p={};if(p.arBrowserInfo=c(),p.browserName=p.arBrowserInfo[0],p.browserMajorVersion=p.arBrowserInfo[1],"IE"===p.browserName&&(8===p.browserMajorVersion||9===p.browserMajorVersion))return!1;if(p.isSmartphoneOrTablet=/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent),p.isSmartphoneOrTablet)return!1;"undefined"==typeof e.debug&&(e.debug=!1),p.debug=e.debug,e.debug&&console.log(p.browserName+" "+p.browserMajorVersion),p.playAriaLabel="undefined"==typeof e.videoTitle||""===e.videoTitle?"Play":"Play video, "+e.videoTitle,p.container=document.getElementById(e.videoId),p.container.className=p.container.className+" stopped",p.movie=p.container.getElementsByTagName("video")[0],p.movie.removeAttribute("controls"),p.randomNum=Math.floor(1e4*Math.random()),e.debug&&console.log("Inserting custom controls..."),p.container.insertAdjacentHTML("beforeend",e.html.replaceAll("{aria-label}",p.playAriaLabel).replaceAll("{id}",p.randomNum)),p.controls=p.container.querySelector(".player-controls"),p.labelMute=document.getElementById("labelMute"+p.randomNum),p.labelMuteOffset=p.movieWidth-390,p.labelMuteOffset<0&&(p.labelMuteOffset=0),p.labelMute.setAttribute("style","margin-left:"+p.labelMuteOffset+"px");for(var m,f="",v=p.movie.childNodes,g=0;ge?0:e,p.isTextTracks||a(p)},!1),p.btnForward.addEventListener("click",function(){var e=p.movie.currentTime+p.seekInterval;p.movie.currentTime=e>p.movie.duration?p.movie.duration:e,p.isTextTracks||a(p)},!1),p.btnVolume.addEventListener("change",function(){p.movie.volume=parseFloat(this.value/10)},!1),p.btnMute.addEventListener("click",function(){p.movie.muted=p.movie.muted===!0?!1:!0},!1),p.movie.addEventListener("timeupdate",function(){p.secs=parseInt(p.movie.currentTime%60),p.mins=parseInt(p.movie.currentTime/60%60),p.secs=("0"+p.secs).slice(-2),p.mins=("0"+p.mins).slice(-2),p.duration.innerHTML=p.mins+":"+p.secs},!1),p.movie.addEventListener("timeupdate",function(){p.percent=100/p.movie.duration*p.movie.currentTime,p.percent>0&&(p.progressBar.value=p.percent,p.progressBarSpan.innerHTML=p.percent)},!1),p.progressBar.addEventListener("click",function(e){p.pos=n(e).x/this.offsetWidth,p.movie.currentTime=p.pos*p.movie.duration,p.isTextTracks||a(p)}),p.movie.addEventListener("ended",function(){p.captionsContainer.innerHTML=""}),p.captionsBtn.addEventListener("click",function(){p.captionsContainer.className=this.checked?"px-video-captions show":"px-video-captions hide"},!1),p.captionExists){if("IE"===p.browserName&&10===p.browserMajorVersion||"IE"===p.browserName&&11===p.browserMajorVersion||"Firefox"===p.browserName&&p.browserMajorVersion>=31||"Safari"===p.browserName&&p.browserMajorVersion>=7){e.debug&&console.log("Detected IE 10/11 or Firefox 31+ or Safari 7+"),p.isTextTracks=!1;for(var b={},x=p.movie.textTracks,T=0;Tr(p.captions[p.subcount][0])&&p.movie.currentTime.toFixed(1)i(p.captions[p.subcount][0])&&p.subcountt;t++)if(e.prefix=n[t],"undefined"!=typeof document[e.prefix+"CancelFullScreen"]){e.supportsFullScreen=!0;break}"webkit"===e.prefix&&navigator.userAgent.match(/Version\/[\d\.]+.*Safari/)&&(e.supportsFullScreen=!1),e.supportsFullScreen&&(e.fullScreenEventName=e.prefix+"fullscreenchange",e.isFullScreen=function(){switch(this.prefix){case"":return document.fullScreen;case"webkit":return document.webkitIsFullScreen;default:return document[this.prefix+"FullScreen"]}},e.requestFullScreen=function(e){return""===this.prefix?e.requestFullScreen():e[this.prefix+"RequestFullScreen"]("webkit"===this.prefix?e.ALLOW_KEYBOARD_INPUT:null)},e.cancelFullScreen=function(){return""===this.prefix?document.cancelFullScreen():document[this.prefix+"CancelFullScreen"]()},e.element=function(){return""===this.prefix?document.fullscreenElement:document[this.prefix+"FullscreenElement"]}),window.fullscreen=e}(); \ No newline at end of file +!function(e){"use strict";function t(){var e,t,n,r=navigator.userAgent,s=navigator.appName,a=""+parseFloat(navigator.appVersion),o=parseInt(navigator.appVersion,10);return-1!==navigator.appVersion.indexOf("Windows NT")&&-1!==navigator.appVersion.indexOf("rv:11")?(s="IE",a="11;"):-1!==(t=r.indexOf("MSIE"))?(s="IE",a=r.substring(t+5)):-1!==(t=r.indexOf("Chrome"))?(s="Chrome",a=r.substring(t+7)):-1!==(t=r.indexOf("Safari"))?(s="Safari",a=r.substring(t+7),-1!==(t=r.indexOf("Version"))&&(a=r.substring(t+8))):-1!==(t=r.indexOf("Firefox"))?(s="Firefox",a=r.substring(t+8)):(e=r.lastIndexOf(" ")+1)<(t=r.lastIndexOf("/"))&&(s=r.substring(e,t),a=r.substring(t+1),s.toLowerCase()==s.toUpperCase()&&(s=navigator.appName)),-1!==(n=a.indexOf(";"))&&(a=a.substring(0,n)),-1!==(n=a.indexOf(" "))&&(a=a.substring(0,n)),o=parseInt(""+a,10),isNaN(o)&&(a=""+parseFloat(navigator.appVersion),o=parseInt(navigator.appVersion,10)),[s,o]}function n(e){var t=[];return t=e.split(" --> "),s(t[0])}function r(e){var t=[];return t=e.split(" --> "),s(t[1])}function s(e){if(null===e||void 0===e)return 0;var t,n=[],r=[];return n=e.split(","),r=n[0].split(":"),t=Math.floor(60*r[0]*60)+Math.floor(60*r[1])+Math.floor(r[2])}function a(e){for(e.subcount=0;r(e.captions[e.subcount][0])e.captions.length-1){e.subcount=e.captions.length-1;break}}function o(e){L.captions.default&&(e.container.className+=" "+L.classes.captions,e.buttons.captions.setAttribute("checked","checked"))}function i(e,t,n){return e.replace(new RegExp(t.replace(/([.*+?^=!:${}()|\[\]\/\\])/g,"\\$1"),"g"),n)}function c(e){var t=N.isFullScreen()?{x:0,y:0}:l(e.currentTarget);return{x:e.clientX-t.x,y:e.clientY-t.y}}function l(e){for(var t=0,n=0;e;)t+=e.offsetLeft-e.scrollLeft+e.clientLeft,n+=e.offsetTop-e.scrollTop+e.clientTop,e=e.offsetParent;return{x:t,y:n}}function u(e,t){for(var n in t)t[n]&&t[n].constructor&&t[n].constructor===Object?(e[n]=e[n]||{},u(e[n],t[n])):e[n]=t[n];return e}function d(e){var t,n=F[e]||[],r=n.length;for(t=0;r>t;t++)n[t].apply(E.media,[])}function p(){var e={supportsFullScreen:!1,isFullScreen:function(){return!1},requestFullScreen:function(){},cancelFullScreen:function(){},fullScreenEventName:"",element:null,prefix:""},t="webkit moz o ms khtml".split(" ");if("undefined"!=typeof document.cancelFullScreen)e.supportsFullScreen=!0;else for(var n=0,r=t.length;r>n;n++)if(e.prefix=t[n],"undefined"!=typeof document[e.prefix+"CancelFullScreen"]){e.supportsFullScreen=!0;break}return"webkit"===e.prefix&&navigator.userAgent.match(/Version\/[\d\.]+.*Safari/)&&(e.supportsFullScreen=!1),e.supportsFullScreen&&(e.fullScreenEventName=e.prefix+"fullscreenchange",e.isFullScreen=function(){switch(this.prefix){case"":return document.fullScreen;case"webkit":return document.webkitIsFullScreen;default:return document[this.prefix+"FullScreen"]}},e.requestFullScreen=function(e){return""===this.prefix?e.requestFullScreen():e[this.prefix+"RequestFullScreen"]("webkit"===this.prefix?e.ALLOW_KEYBOARD_INPUT:null)},e.cancelFullScreen=function(){return""===this.prefix?document.cancelFullScreen():document[this.prefix+"CancelFullScreen"]()},e.element=function(){return""===this.prefix?document.fullscreenElement:document[this.prefix+"FullscreenElement"]}),e}function f(){L.debug&&console.log("Injecting custom controls");var e=L.html;e=i(e,"{aria-label}",L.playAriaLabel),e=i(e,"{id}",E.random),E.container.insertAdjacentHTML("beforeend",e)}function m(e){return E.container.querySelectorAll(e)}function b(e){return m(e)[0]}function g(){E.controls=b(L.selectors.controls),E.buttons={},E.buttons.play=b(L.selectors.buttons.play),E.buttons.pause=b(L.selectors.buttons.pause),E.buttons.restart=b(L.selectors.buttons.restart),E.buttons.rewind=b(L.selectors.buttons.rewind),E.buttons.forward=b(L.selectors.buttons.forward),E.buttons.mute=b(L.selectors.buttons.mute),E.buttons.volume=b(L.selectors.buttons.volume),E.buttons.captions=b(L.selectors.buttons.captions),E.buttons.fullscreen=b(L.selectors.buttons.fullscreen),E.progress={},E.progress.bar=b(L.selectors.progress),E.progress.text=E.progress.bar.getElementsByTagName("span")[0],E.duration=b(L.selectors.duration),E.seekTime=m(L.selectors.seekTime)}function v(){E.media.play(),E.container.className=E.container.className.replace(L.classes.stopped,L.classes.playing)}function x(){E.media.pause(),E.container.className=E.container.className.replace(L.classes.playing,L.classes.stopped)}function T(){E.media.currentTime=0,E.isTextTracks||(E.subcount=0),v()}function h(){return E.media=E.container.querySelectorAll("audio, video")[0],E.media?(null===E.media.getAttribute("autoplay")&&(E.container.className+=" "+L.classes.stopped),E.media.removeAttribute("controls"),E.type="video"==E.media.tagName.toLowerCase()?"video":"audio",void 0):(console.warn("No audio or video element found!"),!1)}function k(){if("video"==E.type){E.videoContainer.insertAdjacentHTML("afterbegin","
"),E.captionsContainer=b(L.selectors.captions),E.isTextTracks=!1,E.media.textTracks&&(E.isTextTracks=!0);for(var e,t="",s=E.media.childNodes,a=0;a=31||"Safari"===E.browserName&&E.browserMajorVersion>=7)for(L.debug&&console.log("Detected IE 10/11 or Firefox 31+ or Safari 7+"),E.isTextTracks=!1,l={},i=E.media.textTracks,c=0;cn(E.captions[E.subcount][0])&&E.media.currentTime.toFixed(1)r(E.captions[E.subcount][0])&&E.subcounte?0:e,E.isTextTracks||a(E)},!1),E.buttons.forward.addEventListener("click",function(){var e=E.media.currentTime+L.seekInterval;E.media.currentTime=e>E.media.duration?E.media.duration:e,E.isTextTracks||a(E)},!1),E.buttons.volume.addEventListener("change",function(){E.media.volume=parseFloat(this.value/10)},!1),E.buttons.mute.addEventListener("click",function(){E.media.muted===!0?(E.media.muted=!1,E.container.className=E.container.className.replace(L.classes.muted,"")):(E.media.muted=!0,E.container.className+=" "+L.classes.muted)},!1),E.media.addEventListener("timeupdate",function(){E.secs=parseInt(E.media.currentTime%60),E.mins=parseInt(E.media.currentTime/60%60),E.secs=("0"+E.secs).slice(-2),E.mins=("0"+E.mins).slice(-2),E.duration.innerHTML=E.mins+":"+E.secs},!1),E.media.addEventListener("timeupdate",function(){E.percent=100/E.media.duration*E.media.currentTime,E.percent>0&&(E.progress.bar.value=E.percent,E.progress.text.innerHTML=E.percent)},!1),E.progress.bar.addEventListener("click",function(e){E.pos=c(e).x/this.offsetWidth,E.media.currentTime=E.pos*E.media.duration,E.isTextTracks||a(E)}),E.buttons.captions.addEventListener("click",function(){this.checked?E.container.className+=" "+L.classes.captions:E.container.className=E.container.className.replace(L.classes.captions,"")},!1),E.media.addEventListener("ended",function(){E.captionsContainer.innerHTML="",E.container.className=E.container.className.replace(L.classes.playing,L.classes.stopped)})}function S(e){E.container=e,E.videoContainer=b(L.selectors.videoContainer),h(),E.random=Math.floor(1e4*Math.random()),f(),g(),k(),w(),y()}var N,L,F={},E={},M={debug:!1,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":!0}};e.on=function(e,t){F[e]||(F[e]=[]),F[e].push(t)},e.setup=function(e){if(L=u(M,e),N=p(),E.browserInfo=t(),E.browserName=E.browserInfo[0],E.browserMajorVersion=E.browserInfo[1],L.debug&&(console.log(L),console.log("fullscreen support: "+N.supportsFullScreen),console.log(E.browserName+" "+E.browserMajorVersion)),"IE"===E.browserName&&(8===E.browserMajorVersion||9===E.browserMajorVersion))return console.warn("Browser not suppported."),!1;if(E.isSmartphoneOrTablet=/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent),E.isSmartphoneOrTablet)return console.warn("Browser not suppported."),!1;L.playAriaLabel="undefined"!=typeof L.title&&L.title.length?"Play "+L.title:"Play";for(var n=document.querySelectorAll(L.selectors.container),r=n.length-1;r>=0;r--)S(n[r]);d("setup")}}(this.simpleMedia=this.simpleMedia||{}); \ No newline at end of file diff --git a/dist/js/templates.js b/dist/js/templates.js index 1bef66c8..af5f7eac 100644 --- a/dist/js/templates.js +++ b/dist/js/templates.js @@ -1,2 +1,2 @@ var templates = {}; - templates['controls'] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("
");t.b("\n" + i);t.b(" 0% played");t.b("\n");t.b("\n" + i);t.b("
");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b("
");t.b("\n" + i);t.b(" Time");t.b("\n" + i);t.b(" 00:00");t.b("\n" + i);t.b("
");t.b("\n" + i);t.b("
");t.b("\n");t.b("\n" + i);t.b("
");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b("
");t.b("\n" + i);t.b("
");t.b("\n");return t.fl(); },partials: {}, subs: { }}); \ No newline at end of file + templates['controls'] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("
");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" 0% played");t.b("\n" + i);t.b(" ");t.b("\n");t.b("\n" + i);t.b("
");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" Time");t.b("\n" + i);t.b(" 00:00");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b("
");t.b("\n");t.b("\n" + i);t.b("
");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b(" ");t.b("\n");t.b("\n" + i);t.b(" ");t.b("\n" + i);t.b("
");t.b("\n" + i);t.b("
");t.b("\n");return t.fl(); },partials: {}, subs: { }}); \ No newline at end of file diff --git a/dist/svg/sprite.svg b/dist/svg/sprite.svg index 7d0efdcd..1c3e7031 100644 --- a/dist/svg/sprite.svg +++ b/dist/svg/sprite.svg @@ -1 +1 @@ -collapseexpandpauserewind \ No newline at end of file +collapseexpandmutedpauserewind \ No newline at end of file diff --git a/docs/index.html b/docs/index.html index 598774e0..f139e58f 100644 --- a/docs/index.html +++ b/docs/index.html @@ -17,9 +17,8 @@

A simple HTML5 media player

-
+
-