Sprite loading improvements, touch controls

- SVG sprite loading automatically for an easier setup
- Touch devices now show controls on touch rather than pausing playback
This commit is contained in:
Sam 2016-05-23 19:16:48 +01:00
parent 98e4c5acea
commit 69194915d4
9 changed files with 112 additions and 102 deletions

View File

@ -1,5 +1,9 @@
# Changelog # Changelog
## v1.6.14
- SVG sprite loading automatically for an easier setup
- Touch devices now show controls on touch rather than pausing playback
## v1.6.13 ## v1.6.13
- Decreased sensitivity and inverted scroll on volume slider (scroll up to increase, down to decrease) - Decreased sensitivity and inverted scroll on volume slider (scroll up to increase, down to decrease)

4
dist/plyr.js vendored

File diff suppressed because one or more lines are too long

2
docs/dist/docs.js vendored
View File

@ -1 +1 @@
"document"in self&&("classList"in document.createElement("_")?!function(){"use strict";var e=document.createElement("_");if(e.classList.add("c1","c2"),!e.classList.contains("c2")){var t=function(e){var t=DOMTokenList.prototype[e];DOMTokenList.prototype[e]=function(e){var i,n=arguments.length;for(i=0;n>i;i++)e=arguments[i],t.call(this,e)}};t("add"),t("remove")}if(e.classList.toggle("c3",!1),e.classList.contains("c3")){var i=DOMTokenList.prototype.toggle;DOMTokenList.prototype.toggle=function(e,t){return 1 in arguments&&!this.contains(e)==!t?t:i.call(this,e)}}e=null}():!function(e){"use strict";if("Element"in e){var t="classList",i="prototype",n=e.Element[i],o=Object,s=String[i].trim||function(){return this.replace(/^\s+|\s+$/g,"")},r=Array[i].indexOf||function(e){for(var t=0,i=this.length;i>t;t++)if(t in this&&this[t]===e)return t;return-1},a=function(e,t){this.name=e,this.code=DOMException[e],this.message=t},c=function(e,t){if(""===t)throw new a("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(t))throw new a("INVALID_CHARACTER_ERR","String contains an invalid character");return r.call(e,t)},l=function(e){for(var t=s.call(e.getAttribute("class")||""),i=t?t.split(/\s+/):[],n=0,o=i.length;o>n;n++)this.push(i[n]);this._updateClassName=function(){e.setAttribute("class",this.toString())}},u=l[i]=[],d=function(){return new l(this)};if(a[i]=Error[i],u.item=function(e){return this[e]||null},u.contains=function(e){return e+="",-1!==c(this,e)},u.add=function(){var e,t=arguments,i=0,n=t.length,o=!1;do e=t[i]+"",-1===c(this,e)&&(this.push(e),o=!0);while(++i<n);o&&this._updateClassName()},u.remove=function(){var e,t,i=arguments,n=0,o=i.length,s=!1;do for(e=i[n]+"",t=c(this,e);-1!==t;)this.splice(t,1),s=!0,t=c(this,e);while(++n<o);s&&this._updateClassName()},u.toggle=function(e,t){e+="";var i=this.contains(e),n=i?t!==!0&&"remove":t!==!1&&"add";return n&&this[n](e),t===!0||t===!1?t:!i},u.toString=function(){return this.join(" ")},o.defineProperty){var p={get:d,enumerable:!0,configurable:!0};try{o.defineProperty(n,t,p)}catch(h){-2146823252===h.number&&(p.enumerable=!1,o.defineProperty(n,t,p))}}else o[i].__defineGetter__&&n.__defineGetter__(t,d)}}(self)),plyr.setup(".js-media-player",{debug:!0,title:"Video demo",tooltips:{controls:!0},captions:{defaultActive:!0}}),function(){function e(e,t,i){if(e)if(e.classList)e.classList[i?"add":"remove"](t);else{var n=(" "+e.className+" ").replace(/\s+/g," ").replace(" "+t+" ","");e.className=n+(i?" "+t:"")}}function t(t,s){if(t in n&&(s||t!=o)&&(o.length||t!=n.video)){var r=document.querySelector(".js-media-player").plyr;switch(t){case n.video:r.source({type:"video",title:"View From A Blue Moon",sources:[{src:"https://cdn.selz.com/plyr/1.5/View_From_A_Blue_Moon_Trailer-HD.mp4",type:"video/mp4"},{src:"https://cdn.selz.com/plyr/1.5/View_From_A_Blue_Moon_Trailer-HD.webm",type:"video/webm"}],poster:"https://cdn.selz.com/plyr/1.5/View_From_A_Blue_Moon_Trailer-HD.jpg",tracks:[{kind:"captions",label:"English",srclang:"en",src:"https://cdn.selz.com/plyr/1.5/View_From_A_Blue_Moon_Trailer-HD.en.vtt","default":!0}]});break;case n.audio:r.source({type:"audio",title:"Kishi Bashi &ndash; &ldquo;It All Began With A Burst&rdquo;",sources:[{src:"https://cdn.selz.com/plyr/1.5/Kishi_Bashi_-_It_All_Began_With_a_Burst.mp3",type:"audio/mp3"},{src:"https://cdn.selz.com/plyr/1.5/Kishi_Bashi_-_It_All_Began_With_a_Burst.ogg",type:"audio/ogg"}]});break;case n.youtube:r.source({type:"video",title:"View From A Blue Moon",sources:[{src:"bTqVqk7FSmY",type:"youtube"}]});break;case n.vimeo:r.source({type:"video",title:"View From A Blue Moon",sources:[{src:"143418951",type:"vimeo"}]})}o=t;for(var a=i.length-1;a>=0;a--)e(i[a].parentElement,"active",!1);e(document.querySelector('[data-source="'+t+'"]').parentElement,"active",!0)}}for(var i=document.querySelectorAll("[data-source]"),n={video:"video",audio:"audio",youtube:"youtube",vimeo:"vimeo"},o=window.location.hash.replace("#",""),s=window.history&&window.history.pushState,r=i.length-1;r>=0;r--)i[r].addEventListener("click",function(){var e=this.getAttribute("data-source");t(e),s&&history.pushState({type:e},"","#"+e)});if(window.addEventListener("popstate",function(e){e.state&&"type"in e.state&&t(e.state.type)}),s){var a=!o.length;a&&(o=n.video),o in n&&history.replaceState({type:o},"",a?"":"#"+o),o!==n.video&&t(o,!0)}}(),document.domain.indexOf("plyr.io")>-1&&(!function(e,t,i,n,o,s,r){e.GoogleAnalyticsObject=o,e[o]=e[o]||function(){(e[o].q=e[o].q||[]).push(arguments)},e[o].l=1*new Date,s=t.createElement(i),r=t.getElementsByTagName(i)[0],s.async=1,s.src=n,r.parentNode.insertBefore(s,r)}(window,document,"script","//www.google-analytics.com/analytics.js","ga"),ga("create","UA-40881672-11","auto"),ga("send","pageview")); "document"in self&&("classList"in document.createElement("_")?!function(){"use strict";var e=document.createElement("_");if(e.classList.add("c1","c2"),!e.classList.contains("c2")){var t=function(e){var t=DOMTokenList.prototype[e];DOMTokenList.prototype[e]=function(e){var i,s=arguments.length;for(i=0;s>i;i++)e=arguments[i],t.call(this,e)}};t("add"),t("remove")}if(e.classList.toggle("c3",!1),e.classList.contains("c3")){var i=DOMTokenList.prototype.toggle;DOMTokenList.prototype.toggle=function(e,t){return 1 in arguments&&!this.contains(e)==!t?t:i.call(this,e)}}e=null}():!function(e){"use strict";if("Element"in e){var t="classList",i="prototype",s=e.Element[i],o=Object,n=String[i].trim||function(){return this.replace(/^\s+|\s+$/g,"")},r=Array[i].indexOf||function(e){for(var t=0,i=this.length;i>t;t++)if(t in this&&this[t]===e)return t;return-1},a=function(e,t){this.name=e,this.code=DOMException[e],this.message=t},c=function(e,t){if(""===t)throw new a("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(t))throw new a("INVALID_CHARACTER_ERR","String contains an invalid character");return r.call(e,t)},l=function(e){for(var t=n.call(e.getAttribute("class")||""),i=t?t.split(/\s+/):[],s=0,o=i.length;o>s;s++)this.push(i[s]);this._updateClassName=function(){e.setAttribute("class",this.toString())}},u=l[i]=[],d=function(){return new l(this)};if(a[i]=Error[i],u.item=function(e){return this[e]||null},u.contains=function(e){return e+="",-1!==c(this,e)},u.add=function(){var e,t=arguments,i=0,s=t.length,o=!1;do e=t[i]+"",-1===c(this,e)&&(this.push(e),o=!0);while(++i<s);o&&this._updateClassName()},u.remove=function(){var e,t,i=arguments,s=0,o=i.length,n=!1;do for(e=i[s]+"",t=c(this,e);-1!==t;)this.splice(t,1),n=!0,t=c(this,e);while(++s<o);n&&this._updateClassName()},u.toggle=function(e,t){e+="";var i=this.contains(e),s=i?t!==!0&&"remove":t!==!1&&"add";return s&&this[s](e),t===!0||t===!1?t:!i},u.toString=function(){return this.join(" ")},o.defineProperty){var p={get:d,enumerable:!0,configurable:!0};try{o.defineProperty(s,t,p)}catch(h){-2146823252===h.number&&(p.enumerable=!1,o.defineProperty(s,t,p))}}else o[i].__defineGetter__&&s.__defineGetter__(t,d)}}(self)),plyr.setup(".js-media-player",{debug:!0,title:"Video demo",iconUrl:"../dist/plyr.svg",tooltips:{controls:!0},captions:{defaultActive:!0}}),plyr.loadSprite("dist/docs.svg"),function(){function e(e,t,i){if(e)if(e.classList)e.classList[i?"add":"remove"](t);else{var s=(" "+e.className+" ").replace(/\s+/g," ").replace(" "+t+" ","");e.className=s+(i?" "+t:"")}}function t(t,n){if(t in s&&(n||t!=o)&&(o.length||t!=s.video)){var r=document.querySelector(".js-media-player").plyr;switch(t){case s.video:r.source({type:"video",title:"View From A Blue Moon",sources:[{src:"https://cdn.selz.com/plyr/1.5/View_From_A_Blue_Moon_Trailer-HD.mp4",type:"video/mp4"},{src:"https://cdn.selz.com/plyr/1.5/View_From_A_Blue_Moon_Trailer-HD.webm",type:"video/webm"}],poster:"https://cdn.selz.com/plyr/1.5/View_From_A_Blue_Moon_Trailer-HD.jpg",tracks:[{kind:"captions",label:"English",srclang:"en",src:"https://cdn.selz.com/plyr/1.5/View_From_A_Blue_Moon_Trailer-HD.en.vtt","default":!0}]});break;case s.audio:r.source({type:"audio",title:"Kishi Bashi &ndash; &ldquo;It All Began With A Burst&rdquo;",sources:[{src:"https://cdn.selz.com/plyr/1.5/Kishi_Bashi_-_It_All_Began_With_a_Burst.mp3",type:"audio/mp3"},{src:"https://cdn.selz.com/plyr/1.5/Kishi_Bashi_-_It_All_Began_With_a_Burst.ogg",type:"audio/ogg"}]});break;case s.youtube:r.source({type:"video",title:"View From A Blue Moon",sources:[{src:"bTqVqk7FSmY",type:"youtube"}]});break;case s.vimeo:r.source({type:"video",title:"View From A Blue Moon",sources:[{src:"143418951",type:"vimeo"}]})}o=t;for(var a=i.length-1;a>=0;a--)e(i[a].parentElement,"active",!1);e(document.querySelector('[data-source="'+t+'"]').parentElement,"active",!0)}}for(var i=document.querySelectorAll("[data-source]"),s={video:"video",audio:"audio",youtube:"youtube",vimeo:"vimeo"},o=window.location.hash.replace("#",""),n=window.history&&window.history.pushState,r=i.length-1;r>=0;r--)i[r].addEventListener("click",function(){var e=this.getAttribute("data-source");t(e),n&&history.pushState({type:e},"","#"+e)});if(window.addEventListener("popstate",function(e){e.state&&"type"in e.state&&t(e.state.type)}),n){var a=!o.length;a&&(o=s.video),o in s&&history.replaceState({type:o},"",a?"":"#"+o),o!==s.video&&t(o,!0)}}(),document.domain.indexOf("plyr.io")>-1&&(!function(e,t,i,s,o,n,r){e.GoogleAnalyticsObject=o,e[o]=e[o]||function(){(e[o].q=e[o].q||[]).push(arguments)},e[o].l=1*new Date,n=t.createElement(i),r=t.getElementsByTagName(i)[0],n.async=1,n.src=s,r.parentNode.insertBefore(n,r)}(window,document,"script","//www.google-analytics.com/analytics.js","ga"),ga("create","UA-40881672-11","auto"),ga("send","pageview"));

View File

@ -74,47 +74,6 @@
</section> </section>
</main> </main>
<!-- Load SVG defs -->
<!-- You should bundle all SVG/Icons into one file using a build tool such as gulp and svg store -->
<script>
(function() {
[
'../dist/plyr.svg',
'dist/docs.svg'
]
.forEach(function(u) {
var x = new XMLHttpRequest(),
b = document.body;
// Check for CORS support
// If you're loading from same domain, you can remove the whole if/else statement
// XHR for Chrome/Firefox/Opera/Safari/IE10+
if ('withCredentials' in x) {
x.open('GET', u, true);
}
// XDomainRequest for IE8 & IE9
else if (typeof XDomainRequest == 'function') {
x = new XDomainRequest();
x.open('GET', u);
}
else { return; }
// Inject hidden div with sprite on load
x.onload = function() {
var c = document.createElement('div');
c.setAttribute('hidden', '');
c.innerHTML = x.responseText;
b.insertBefore(c, b.childNodes[0]);
}
// Timeout for IE9
setTimeout(function () {
x.send();
}, 0);
});
})();
</script>
<!-- Plyr core script --> <!-- Plyr core script -->
<script src="../dist/plyr.js"></script> <script src="../dist/plyr.js"></script>

View File

@ -8,6 +8,7 @@
plyr.setup('.js-media-player', { plyr.setup('.js-media-player', {
debug: true, debug: true,
title: 'Video demo', title: 'Video demo',
iconUrl: '../dist/plyr.svg',
tooltips: { tooltips: {
controls: true controls: true
}, },
@ -15,6 +16,7 @@ plyr.setup('.js-media-player', {
defaultActive: true defaultActive: true
} }
}); });
plyr.loadSprite('dist/docs.svg');
// General functions // General functions
(function() { (function() {

View File

@ -264,6 +264,7 @@ gulp.task("cdn", function () {
.pipe(rename(function (path) { .pipe(rename(function (path) {
path.dirname = path.dirname.replace(".", version); path.dirname = path.dirname.replace(".", version);
})) }))
.pipe(replace(localPath, versionPath))
.pipe(s3(aws.cdn, options.cdn)); .pipe(s3(aws.cdn, options.cdn));
}); });
@ -279,9 +280,10 @@ gulp.task("docs", function () {
// Replace versioned files in plyr.js // Replace versioned files in plyr.js
gulp.src(path.join(root, "src/js/plyr.js")) gulp.src(path.join(root, "src/js/plyr.js"))
.pipe(replace(semver, "v" + version)) .pipe(replace(semver, "v" + version))
.pipe(replace(cdnpath, aws.cdn.bucket + "/" + version))
.pipe(gulp.dest(path.join(root, "src/js/"))); .pipe(gulp.dest(path.join(root, "src/js/")));
// Replace local file paths with remote paths in docs // Replace local file paths with remote paths in docs HTML
// e.g. "../dist/plyr.js" to "https://cdn.plyr.io/x.x.x/plyr.js" // e.g. "../dist/plyr.js" to "https://cdn.plyr.io/x.x.x/plyr.js"
gulp.src([paths.docs.root + "*.html"]) gulp.src([paths.docs.root + "*.html"])
.pipe(replace(localPath, versionPath)) .pipe(replace(localPath, versionPath))

View File

@ -1,6 +1,6 @@
{ {
"name": "plyr", "name": "plyr",
"version": "1.6.13", "version": "1.6.14",
"description": "A simple, accessible and customizable HTML5, YouTube and Vimeo media player", "description": "A simple, accessible and customizable HTML5, YouTube and Vimeo media player",
"homepage": "http://plyr.io", "homepage": "http://plyr.io",
"main": "src/js/plyr.js", "main": "src/js/plyr.js",

View File

@ -40,7 +40,7 @@ If you have any cool ideas or features, please let me know by [creating an issue
## Implementation ## Implementation
Check `docs/index.html` and `docs/dist/docs.js` for an example setup. Check `docs/index.html` and `docs/dist/docs.js` for an example setup.
**Heads up:** the example `index.html` file needs to be served from a webserver (such as Apache, Nginx, IIS or similar) unless you change the file sources to include http or https. e.g. change `//cdn.plyr.io/1.6.13/plyr.js` to `https://cdn.plyr.io/1.6.13/plyr.js` **Heads up:** the example `index.html` file needs to be served from a webserver (such as Apache, Nginx, IIS or similar) unless you change the file sources to include http or https. e.g. change `//cdn.plyr.io/1.6.14/plyr.js` to `https://cdn.plyr.io/1.6.14/plyr.js`
### npm ### npm
@ -71,11 +71,11 @@ More info is on [npm](https://www.npmjs.com/package/ember-cli-plyr) and [GitHub]
If you want to use our CDN, you can use the following: If you want to use our CDN, you can use the following:
```html ```html
<link rel="stylesheet" href="https://cdn.plyr.io/1.6.13/plyr.css"> <link rel="stylesheet" href="https://cdn.plyr.io/1.6.14/plyr.css">
<script src="https://cdn.plyr.io/1.6.13/plyr.js"></script> <script src="https://cdn.plyr.io/1.6.14/plyr.js"></script>
``` ```
The SVG sprite/defs file can be found here: `https://cdn.plyr.io/1.6.13/plyr.svg`. The SVG sprite/defs file can be found here: `https://cdn.plyr.io/1.6.14/plyr.svg`.
### CSS & Styling ### CSS & Styling
If you want to use the default css, add the `plyr.css` file from `/dist` into your head, or even better use `plyr.less` or `plyr.scss` file included in `/src` in your build to save a request. If you want to use the default css, add the `plyr.css` file from `/dist` into your head, or even better use `plyr.less` or `plyr.scss` file included in `/src` in your build to save a request.
@ -87,35 +87,10 @@ If you want to use the default css, add the `plyr.css` file from `/dist` into yo
The default setup uses the BEM methodology with `plyr` as the block, e.g. `.plyr__controls`. You can change the class hooks in the options. Check out the source for more on this. The default setup uses the BEM methodology with `plyr` as the block, e.g. `.plyr__controls`. You can change the class hooks in the options. Check out the source for more on this.
### SVG ### SVG
The SVG sprite for the controls icons can be loaded two ways: The icons used in the Plyr controls are loaded in an SVG sprite. The icons can be used in your own SVG sprite build (see `/src/sprite` for source icons) or using the default settings which sprite from the CDN automatically for a hassle free setup.
- By passing the *relative* path to the sprite as the `iconUrl` option; or
- Using AJAX, injecting the sprite into a hidden div.
#### Using the `iconUrl` option #### Using the `iconUrl` option
This method requires the SVG sprite to be hosted on the *same domain* as your page hosting the player. Currently no browser supports cross origin SVG sprites due to XSS issues. Fingers crossed this will come soon though. An example value for this option would be: You can however specify your own `iconUrl` option and Plyr will determine if the url is absolute and requires loading by AJAX/CORS due to current browser limitations or if it's a relative path, just use the path directly.
```
/path/to/plyr.svg
```
#### Using AJAX
Using AJAX means you can load the sprite from a different origin. Avoiding the issues above. This is an example script to load an SVG sprite best added before the closing `</body>`, before any other scripts.
```html
<script>
(function(d, p){
var a = new XMLHttpRequest(),
b = d.body;
a.open('GET', p, true);
a.send();
a.onload = function() {
var c = d.createElement('div');
c.setAttribute('hidden', '');
c.innerHTML = a.responseText;
b.insertBefore(c, b.childNodes[0]);
};
})(document, 'https://cdn.plyr.io/1.6.13/plyr.svg');
</script>
```
If you're using the `<base>` tag on your site, you may need to use something like this: If you're using the `<base>` tag on your site, you may need to use something like this:
[svgfixer.js](https://gist.github.com/leonderijke/c5cf7c5b2e424c0061d2) [svgfixer.js](https://gist.github.com/leonderijke/c5cf7c5b2e424c0061d2)
@ -188,7 +163,7 @@ Be sure to [validate your caption files](https://quuz.org/webvtt/)
Here's an example of a default setup: Here's an example of a default setup:
```html ```html
<script src="https://cdn.plyr.io/1.6.13/plyr.js"></script> <script src="https://cdn.plyr.io/1.6.14/plyr.js"></script>
<script>plyr.setup();</script> <script>plyr.setup();</script>
``` ```
@ -258,16 +233,22 @@ Options must be passed as an object to the `setup()` method as above or as JSON
<td>Used for internationalization (i18n) of the tooltips/labels within the buttons.</td> <td>Used for internationalization (i18n) of the tooltips/labels within the buttons.</td>
</tr> </tr>
<tr> <tr>
<td><code>iconPrefix</code></td> <td><code>loadSprite</code></td>
<td>String</td> <td>Boolean</td>
<td><code>plyr</code></td> <td><code>true</code></td>
<td>Specify the id prefix for the icons used in the default controls (e.g. "plyr-play" would be "plyr"). This is to prevent clashes if you're using your own SVG defs file but with the default controls. Most people can ignore this option.</td> <td>Load the SVG sprite specified as the <code>iconUrl</code> option (if a URL). If <code>false</code>, it is assumed you are handling sprite loading yourself.</td>
</tr> </tr>
<tr> <tr>
<td><code>iconUrl</code></td> <td><code>iconUrl</code></td>
<td>String</td> <td>String</td>
<td><code>null</code></td> <td><code>null</code></td>
<td>Specify a relative path to the SVG sprite, hosted on the *same domain* as the page the player is hosted on. Using this menthod means no requirement for the AJAX sprite loading script. See the <a href="#svg">SVG section</a> for more info.</td> <td>Specify a URL or path to the SVG sprite. See the <a href="#svg">SVG section</a> for more info.</td>
</tr>
<tr>
<td><code>iconPrefix</code></td>
<td>String</td>
<td><code>plyr</code></td>
<td>Specify the id prefix for the icons used in the default controls (e.g. "plyr-play" would be "plyr"). This is to prevent clashes if you're using your own SVG sprite but with the default controls. Most people can ignore this option.</td>
</tr> </tr>
<tr> <tr>
<td><code>debug</code></td> <td><code>debug</code></td>

View File

@ -1,6 +1,6 @@
// ========================================================================== // ==========================================================================
// Plyr // Plyr
// plyr.js v1.6.13 // plyr.js v1.6.14
// https://github.com/selz/plyr // https://github.com/selz/plyr
// License: The MIT License (MIT) // License: The MIT License (MIT)
// ========================================================================== // ==========================================================================
@ -26,7 +26,7 @@
/*global YT,$f*/ /*global YT,$f*/
// Globals // Globals
var fullscreen, api = {}; var fullscreen;
// Default config // Default config
var defaults = { var defaults = {
@ -41,8 +41,9 @@
volumeStep: 1, volumeStep: 1,
duration: null, duration: null,
displayDuration: true, displayDuration: true,
loadSprite: true,
iconPrefix: 'plyr', iconPrefix: 'plyr',
iconUrl: '', iconUrl: 'https://cdn.plyr.io/1.6.14/plyr.svg',
clickToPlay: true, clickToPlay: true,
hideControls: true, hideControls: true,
showPosterOnEnd: false, showPosterOnEnd: false,
@ -657,11 +658,20 @@
} }
} }
// Get icon URL
function _getIconUrl() {
return {
url: config.iconUrl,
external: (config.iconUrl.indexOf("http") === 0)
};
}
// Build the default HTML // Build the default HTML
function _buildControls() { function _buildControls() {
// Create html array // Create html array
var html = [], var html = [],
iconPath = config.iconUrl + '#' + config.iconPrefix; iconUrl = _getIconUrl(),
iconPath = (!iconUrl.external ? iconUrl.url : '') + '#' + config.iconPrefix;
// Larger overlaid play button // Larger overlaid play button
if (_inArray(config.controls, 'play-large')) { if (_inArray(config.controls, 'play-large')) {
@ -1162,6 +1172,20 @@
// Insert controls // Insert controls
function _injectControls() { function _injectControls() {
// Sprite
if (config.loadSprite) {
var iconUrl = _getIconUrl();
// Only load external sprite using AJAX
if (iconUrl.external) {
_log('Loading external SVG sprite');
loadSprite(iconUrl.url);
}
else {
_log('Sprite will be used inline');
}
}
// Make a copy of the html // Make a copy of the html
var html = config.html; var html = config.html;
@ -2432,7 +2456,7 @@
} }
} }
else { else {
show = false; show = !_hasClass(plyr.container, config.classes.hideControls);
} }
} }
@ -2443,14 +2467,19 @@
if (show || plyr.media.paused) { if (show || plyr.media.paused) {
_toggleClass(plyr.container, config.classes.hideControls, false); _toggleClass(plyr.container, config.classes.hideControls, false);
// Always show controls when paused // Always show controls when paused or if touch
if (plyr.media.paused) { if (plyr.media.paused) {
return; return;
} }
// Delay for hiding on touch
if (plyr.browser.touch) {
delay = 3000;
}
} }
// If toggle is false or if we're playing (regardless of toggle), then // If toggle is false or if we're playing (regardless of toggle),
// set the timer to hide the controls // then set the timer to hide the controls
if (!show || !plyr.media.paused) { if (!show || !plyr.media.paused) {
plyr.timers.hover = window.setTimeout(function() { plyr.timers.hover = window.setTimeout(function() {
// If the mouse is over the controls (and not entering fullscreen), bail // If the mouse is over the controls (and not entering fullscreen), bail
@ -2554,7 +2583,7 @@
} }
// Check for support // Check for support
plyr.supported = api.supported(plyr.type); plyr.supported = supported(plyr.type);
// Create new markup // Create new markup
switch(plyr.type) { switch(plyr.type) {
@ -2863,6 +2892,11 @@
// On click play, pause ore restart // On click play, pause ore restart
_on(wrapper, 'click', function() { _on(wrapper, 'click', function() {
if (plyr.browser.touch && !plyr.media.paused) {
_toggleControls(true);
return;
}
if (plyr.media.paused) { if (plyr.media.paused) {
_play(); _play();
} }
@ -3000,7 +3034,7 @@
} }
// Check for support // Check for support
plyr.supported = api.supported(plyr.type); plyr.supported = supported(plyr.type);
// Add style hook // Add style hook
_toggleStyleHook(); _toggleStyleHook();
@ -3130,6 +3164,7 @@
toggleMute: _toggleMute, toggleMute: _toggleMute,
toggleCaptions: _toggleCaptions, toggleCaptions: _toggleCaptions,
toggleFullscreen: _toggleFullscreen, toggleFullscreen: _toggleFullscreen,
toggleControls: _toggleControls,
isFullscreen: function() { return plyr.isFullscreen || false; }, isFullscreen: function() { return plyr.isFullscreen || false; },
support: function(mimeType) { return _supportMime(plyr, mimeType); }, support: function(mimeType) { return _supportMime(plyr, mimeType); },
destroy: _destroy, destroy: _destroy,
@ -3137,8 +3172,31 @@
}; };
} }
// Load a sprite
function loadSprite(url) {
var x = new XMLHttpRequest();
// Check for CORS support
if ('withCredentials' in x) {
x.open('GET', url, true);
}
else {
return;
}
// Inject hidden div with sprite on load
x.onload = function() {
var c = document.createElement('div');
c.setAttribute('hidden', '');
c.innerHTML = x.responseText;
document.body.insertBefore(c, document.body.childNodes[0]);
}
x.send();
}
// Check for support // Check for support
api.supported = function(type) { function supported(type) {
var browser = _browserSniff(), var browser = _browserSniff(),
oldIE = (browser.name === 'IE' && browser.version <= 9), oldIE = (browser.name === 'IE' && browser.version <= 9),
iPhone = /iPhone|iPod/i.test(navigator.userAgent), iPhone = /iPhone|iPod/i.test(navigator.userAgent),
@ -3173,10 +3231,10 @@
basic: basic, basic: basic,
full: full full: full
}; };
}; }
// Expose setup function // Setup function
api.setup = function(elements, options) { function setup(elements, options) {
// Get the players // Get the players
var instances = []; var instances = [];
@ -3202,7 +3260,7 @@
// Bail if disabled or no basic support // Bail if disabled or no basic support
// You may want to disable certain UAs etc // You may want to disable certain UAs etc
if (!api.supported().basic || !elements.length) { if (!supported().basic || !elements.length) {
return false; return false;
} }
@ -3236,9 +3294,13 @@
} }
return instances; return instances;
}; }
return api; return {
setup: setup,
supported: supported,
loadSprite: loadSprite
};
})); }));
// Custom event polyfill // Custom event polyfill