diff --git a/dist/openplayerjs-youtube.js b/dist/openplayerjs-youtube.js index 14abb18..12dd95b 100644 --- a/dist/openplayerjs-youtube.js +++ b/dist/openplayerjs-youtube.js @@ -638,8 +638,8 @@ var YouTube = function YouTube(element, media) { }); }; -if (OpenPlayer) { - OpenPlayer.addMedia('youtube', 'video/x-youtube', function (url) { +if (OpenPlayerJS) { + OpenPlayerJS.addMedia('youtube', 'video/x-youtube', function (url) { return /\/\/(www\.youtube|youtu\.?be)/i.test(url) ? 'video/x-youtube' : null; }, YouTube); } diff --git a/dist/openplayerjs-youtube.min.js b/dist/openplayerjs-youtube.min.js index 5d7e91a..273211c 100644 --- a/dist/openplayerjs-youtube.min.js +++ b/dist/openplayerjs-youtube.min.js @@ -1 +1 @@ -!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(window,(function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="/dist/",r(r.s=1)}([function(e,t,r){"use strict";function n(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var r=[],n=!0,o=!1,a=void 0;try{for(var i,u=e[Symbol.iterator]();!(n=(i=u.next()).done)&&(r.push(i.value),!t||r.length!==t);n=!0);}catch(e){o=!0,a=e}finally{try{n||null==u.return||u.return()}finally{if(o)throw a}}return r}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return o(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return o(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r0&&void 0!==arguments[0]?arguments[0]:{};if(arguments.length>1)return Promise.all(Array.prototype.slice.call(arguments).map(e));var r=s(t);return new Promise((function(e,o){if(l(t)&&t.url||r){r&&(t={url:t}),t=Object.assign({},m,t);var a=d(t);if(a){var i=f(t),u=t.removeScript;if(t.callBackName||t.jsonp){var c=n(v(t),3),s=c[0],b=c[1],h=c[2];t.url=s,b[h]=function(r){delete b[h],y(u,a,i),p(t),e(r||u?void 0:i)}}else i.addEventListener("load",(function(){y(u,a,i),p(t),e(u?void 0:i)}));i.addEventListener("error",(function(){a.removeChild(i),o("Error: loading script")})),i.src=t.url,a.appendChild(i)}else o("Error: no DOM element to append script")}else o("Error: object with url or url string needed")}))};var a=window,i="_$_".concat("simpleLoadScript","CallBacks_$_"),u=0,c=function(e){return Object.prototype.toString.call(e).slice(8,-1).toLowerCase()},l=function(e){return"object"===c(e)},s=function(e){return"string"===c(e)},d=function(e){return e.insertInto?document.querySelector(e.insertInto):e.inBody?document.body:document.head},f=function(e){var t=document.createElement("script");if(e.attrs&&l(e.attrs))for(var r=0,n=Object.keys(e.attrs);r2&&void 0!==arguments[2]&&arguments[2],u=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},c=1,l=!1,s=!0,d=new Promise((function(e){e()})),f="op-yt__".concat(e.id||(new Date).getTime()),p="AUDIO"===e.tagName,y={url:"https://www.youtube.com/iframe_api",autoplay:0,controls:0,disablekb:1,end:0,loop:0,modestbranding:0,playsinline:0,rel:0,showinfo:0,start:0,iv_load_policy:3,nocookie:!1},v=i(i({},y),u),m=v.url,b=v.nocookie;function h(e){return e.match(/(?:(?:youtu\.be\/)|(?:v=)|(?:\/v\/))(\w+)/)[1]}function g(){n=setInterval((function(){var t=new CustomEvent("timeupdate");e.dispatchEvent(t)}),250)}function w(){n&&clearInterval(n)}delete v.url,delete v.nocookie;var O={id:f,videoId:h(t.src),height:p?1:e.offsetHeight,width:p?1:e.offsetWidth,playerVars:v,origin:window.location.host,events:{onReady:function(t){var n=(r=t.target).getIframe();e.muted&&r.mute(),["mouseover","mouseout"].forEach((function(t){n.addEventListener(t,(function(t){var r=new CustomEvent(t.type);e.dispatchEvent(r)}))})),["loadedmetadata","loadeddata","canplay"].forEach((function(t){var r=new CustomEvent(t);e.dispatchEvent(r)}))},onStateChange:function(t){var r=[];switch(t.data){case 0:r=["ended"],s=!1,l=!v.loop,v.loop||w();break;case 1:r=["play","playing"],s=!1,l=!1,g();break;case 2:r=["pause"],s=!0,l=!1,w();break;case 3:r=["progress"],l=!1;break;case 5:r=["loadeddata","loadedmetadata","canplay"],s=!0,l=!1;break;default:r=["loadedmetadata"],s=!0,l=!1}for(var n=0,o=r.length;n-1)&&!v.playlist&&-1===t.src.indexOf("playlist=")&&(v.playlist=h(t.src)),v.controls=0,v.enablejsapi=1,"undefined"!=typeof YT&&YT.loaded||o()(m),this}}function j(){return null}function E(e){return"video/x-youtube"===e}function P(){r.playVideo()}function T(){r.pauseVideo()}function S(){r&&r.destroy()}return window.onYouTubeIframeAPIReady=function(){return k(),new YT.Player(f,O)},Object.freeze({promise:d,create:k,load:j,canPlayType:E,play:P,pause:T,destroy:S,set src(e){if(_source="string"==typeof e?e:e[0].src,r){var t=h(_source);a?r.loadVideoById(t):r.cueVideoById(t)}},get src(){return r?r.getVideoUrl():""},set volume(t){c=t,r&&(r.setVolume(100*t),setTimeout((function(){var t=new CustomEvent("volumechange");e.dispatchEvent(t)}),50))},get volume(){return r&&(c=r.getVolume()/100),c},set muted(t){r&&(t?r.mute():r.unMute(),setTimeout((function(){var t=new CustomEvent("volumechange");e.dispatchEvent(t)}),50))},get muted(){return!!r&&r.isMuted()},set playbackRate(e){r&&r.setPlaybackRate(e)},get playbackRate(){return r?r.getPlaybackRate():1},set defaultPlaybackRate(e){r&&r.setPlaybackRate(e)},get defaultPlaybackRate(){return r?r.getPlaybackRate():1},set currentTime(t){r&&(r.seekTo(t),setTimeout((function(){var t=new CustomEvent("timeupdate");e.dispatchEvent(t)}),50))},get currentTime(){return r?r.getCurrentTime():0},get duration(){return r?r.getDuration():0},get paused(){return s},get ended(){return l}})}))}]).default})); \ No newline at end of file +!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(window,(function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="/dist/",r(r.s=1)}([function(e,t,r){"use strict";function n(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var r=[],n=!0,o=!1,a=void 0;try{for(var i,u=e[Symbol.iterator]();!(n=(i=u.next()).done)&&(r.push(i.value),!t||r.length!==t);n=!0);}catch(e){o=!0,a=e}finally{try{n||null==u.return||u.return()}finally{if(o)throw a}}return r}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return o(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return o(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r0&&void 0!==arguments[0]?arguments[0]:{};if(arguments.length>1)return Promise.all(Array.prototype.slice.call(arguments).map(e));var r=s(t);return new Promise((function(e,o){if(l(t)&&t.url||r){r&&(t={url:t}),t=Object.assign({},m,t);var a=d(t);if(a){var i=f(t),u=t.removeScript;if(t.callBackName||t.jsonp){var c=n(v(t),3),s=c[0],b=c[1],h=c[2];t.url=s,b[h]=function(r){delete b[h],y(u,a,i),p(t),e(r||u?void 0:i)}}else i.addEventListener("load",(function(){y(u,a,i),p(t),e(u?void 0:i)}));i.addEventListener("error",(function(){a.removeChild(i),o("Error: loading script")})),i.src=t.url,a.appendChild(i)}else o("Error: no DOM element to append script")}else o("Error: object with url or url string needed")}))};var a=window,i="_$_".concat("simpleLoadScript","CallBacks_$_"),u=0,c=function(e){return Object.prototype.toString.call(e).slice(8,-1).toLowerCase()},l=function(e){return"object"===c(e)},s=function(e){return"string"===c(e)},d=function(e){return e.insertInto?document.querySelector(e.insertInto):e.inBody?document.body:document.head},f=function(e){var t=document.createElement("script");if(e.attrs&&l(e.attrs))for(var r=0,n=Object.keys(e.attrs);r2&&void 0!==arguments[2]&&arguments[2],u=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},c=1,l=!1,s=!0,d=new Promise((function(e){e()})),f="op-yt__".concat(e.id||(new Date).getTime()),p="AUDIO"===e.tagName,y={url:"https://www.youtube.com/iframe_api",autoplay:0,controls:0,disablekb:1,end:0,loop:0,modestbranding:0,playsinline:0,rel:0,showinfo:0,start:0,iv_load_policy:3,nocookie:!1},v=i(i({},y),u),m=v.url,b=v.nocookie;function h(e){return e.match(/(?:(?:youtu\.be\/)|(?:v=)|(?:\/v\/))(\w+)/)[1]}function g(){n=setInterval((function(){var t=new CustomEvent("timeupdate");e.dispatchEvent(t)}),250)}function w(){n&&clearInterval(n)}delete v.url,delete v.nocookie;var O={id:f,videoId:h(t.src),height:p?1:e.offsetHeight,width:p?1:e.offsetWidth,playerVars:v,origin:window.location.host,events:{onReady:function(t){var n=(r=t.target).getIframe();e.muted&&r.mute(),["mouseover","mouseout"].forEach((function(t){n.addEventListener(t,(function(t){var r=new CustomEvent(t.type);e.dispatchEvent(r)}))})),["loadedmetadata","loadeddata","canplay"].forEach((function(t){var r=new CustomEvent(t);e.dispatchEvent(r)}))},onStateChange:function(t){var r=[];switch(t.data){case 0:r=["ended"],s=!1,l=!v.loop,v.loop||w();break;case 1:r=["play","playing"],s=!1,l=!1,g();break;case 2:r=["pause"],s=!0,l=!1,w();break;case 3:r=["progress"],l=!1;break;case 5:r=["loadeddata","loadedmetadata","canplay"],s=!0,l=!1;break;default:r=["loadedmetadata"],s=!0,l=!1}for(var n=0,o=r.length;n-1)&&!v.playlist&&-1===t.src.indexOf("playlist=")&&(v.playlist=h(t.src)),v.controls=0,v.enablejsapi=1,"undefined"!=typeof YT&&YT.loaded||o()(m),this}}function j(){return null}function E(e){return"video/x-youtube"===e}function P(){r.playVideo()}function T(){r.pauseVideo()}function S(){r&&r.destroy()}return window.onYouTubeIframeAPIReady=function(){return k(),new YT.Player(f,O)},Object.freeze({promise:d,create:k,load:j,canPlayType:E,play:P,pause:T,destroy:S,set src(e){if(_source="string"==typeof e?e:e[0].src,r){var t=h(_source);a?r.loadVideoById(t):r.cueVideoById(t)}},get src(){return r?r.getVideoUrl():""},set volume(t){c=t,r&&(r.setVolume(100*t),setTimeout((function(){var t=new CustomEvent("volumechange");e.dispatchEvent(t)}),50))},get volume(){return r&&(c=r.getVolume()/100),c},set muted(t){r&&(t?r.mute():r.unMute(),setTimeout((function(){var t=new CustomEvent("volumechange");e.dispatchEvent(t)}),50))},get muted(){return!!r&&r.isMuted()},set playbackRate(e){r&&r.setPlaybackRate(e)},get playbackRate(){return r?r.getPlaybackRate():1},set defaultPlaybackRate(e){r&&r.setPlaybackRate(e)},get defaultPlaybackRate(){return r?r.getPlaybackRate():1},set currentTime(t){r&&(r.seekTo(t),setTimeout((function(){var t=new CustomEvent("timeupdate");e.dispatchEvent(t)}),50))},get currentTime(){return r?r.getCurrentTime():0},get duration(){return r?r.getDuration():0},get paused(){return s},get ended(){return l}})}))}]).default})); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 25e1973..4e7c9a7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1963,7 +1963,7 @@ }, "chalk": { "version": "1.1.3", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", + "resolved": "http://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", "dev": true, "requires": { @@ -7201,9 +7201,9 @@ }, "dependencies": { "ansi-regex": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", - "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==", + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.1.tgz", + "integrity": "sha512-ILlv4k/3f6vfQ4OoP2AGvirOktlQ98ZEL1k9FaQjxa3L1abBgbuTDAdPOpvbGncC0BTVQrl+OM8xZGK6tWXt7g==", "dev": true }, "strip-ansi": { @@ -10751,8 +10751,7 @@ "dependencies": { "ansi-regex": { "version": "4.1.0", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", - "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==", + "resolved": "", "dev": true }, "string-width": { diff --git a/src/youtube.js b/src/youtube.js index 09e3fd7..24efdc0 100644 --- a/src/youtube.js +++ b/src/youtube.js @@ -335,8 +335,8 @@ const YouTube = (element, media, autoplay = false, options = {}) => { }); }; -if (OpenPlayer) { - OpenPlayer.addMedia( +if (OpenPlayerJS) { + OpenPlayerJS.addMedia( 'youtube', 'video/x-youtube', url => (/\/\/(www\.youtube|youtu\.?be)/i.test(url) ? 'video/x-youtube' : null),