@awinogrodzki/embed-plugin-youtube
Advanced tools
Comparing version 5.0.8 to 5.0.9
@@ -9,4 +9,22 @@ 'use strict'; | ||
var base = _interopDefault(require('embed-plugin-base')); | ||
var embedPluginUtilities = require('embed-plugin-utilities'); | ||
var justTruncate = truncate; | ||
function truncate(str, length, end) { | ||
if (length == null || length >= str.length) { | ||
return str; | ||
} | ||
if (end == null) { | ||
end = '...'; | ||
} | ||
return str.slice(0, Math.max(0, length - end.length)) + end; | ||
} | ||
var withDetailsTemplate = function ({url, title, embedUrl, description, thumbnail}, thumbClassName, showPlayIcon = false) { | ||
return `<div class="ejs-preview ejs-embed"><div class="ejs-thumb ${thumbClassName}" data-url="${embedUrl}" style="background-image:url(${thumbnail})">${showPlayIcon ? '<span>►</span>' : ''}</div><div class="ejs-info"><h4 class="ejs-title"><a href="${url}">${title}</a></h4><div class="ejs-desc">${justTruncate(description, 150)}</div></div></div>`; | ||
}; | ||
var withoutDetailsTemplate = function (embedUrl, height, name) { | ||
return `<iframe sandbox="allow-forms allow-scripts allow-pointer-lock allow-same-origin allow-top-navigation" class="ejs-embed ejs-${name}" src="${embedUrl}" frameBorder="0" height="${height}"></iframe>`; | ||
}; | ||
const id = "youtube"; | ||
@@ -74,3 +92,3 @@ const baseUrl = "https://www.youtube.com/"; | ||
url += "?autoplay=1"; | ||
this.parentNode.innerHTML = embedPluginUtilities.withoutDetailsTemplate(url, height, id); | ||
this.parentNode.innerHTML = withoutDetailsTemplate(url, height, id); | ||
}; | ||
@@ -100,3 +118,3 @@ } | ||
const embedUrl = `${baseUrl}embed/${args[1]}`; | ||
return $return(details ? embedPluginUtilities.withDetailsTemplate(formatData(data), clickClass, true) : embedPluginUtilities.withoutDetailsTemplate(embedUrl, height, id)); | ||
return $return(details ? withDetailsTemplate(formatData(data), clickClass, true) : withoutDetailsTemplate(embedUrl, height, id)); | ||
}); | ||
@@ -103,0 +121,0 @@ } |
{ | ||
"name": "@awinogrodzki/embed-plugin-youtube", | ||
"version": "5.0.8", | ||
"version": "5.0.9", | ||
"description": "An embed-js plugin to embed youtube videos.", | ||
@@ -25,4 +25,4 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@awinogrodzki/embed-plugin-utilities": "^5.0.9", | ||
"embed-plugin-base": "^5.0.4", | ||
"embed-plugin-utilities": "^5.0.4", | ||
"is-dom": "1.0.9", | ||
@@ -29,0 +29,0 @@ "just-extend": "4.0.2", |
@@ -360,3 +360,3 @@ (function (global, factory) { | ||
var withoutDetailsTemplate = function (embedUrl, height, name) { | ||
return ("<iframe sandbox=\"allow-forms allow-scripts allow-pointer-lock allow-same-origin allow-top-navigation\" class=\"ejs-embed ejs-" + name + "\" src=\"" + embedUrl + "\" frameBorder=\"0\" height=\"" + height + "\"></iframe>"); | ||
return ("<iframe class=\"ejs-embed ejs-" + name + "\" src=\"" + embedUrl + "\" frameBorder=\"0\" height=\"" + height + "\"></iframe>"); | ||
}; | ||
@@ -363,0 +363,0 @@ |
@@ -1,2 +0,2 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):e.embedPluginYoutube=n()}(this,function(){"use strict";function e(){var n=[].slice.call(arguments),t=!1;"boolean"==typeof n[0]&&(t=n.shift());var r=n[0];if(!r||"object"!=typeof r&&"function"!=typeof r)throw new Error("extendee must be an object");for(var o=n.slice(1),u=o.length,i=0;i<u;i++){var c=o[i];for(var a in c)if(c.hasOwnProperty(a)){var s=c[a];if(t&&function(e){return Array.isArray(e)||"[object Object]"=={}.toString.call(e)}(s)){var l=Array.isArray(s)?[]:{};r[a]=e(!0,r.hasOwnProperty(a)?r[a]:l,s)}else r[a]=s}}return r}function n(e,n){var t=e.map(function(e){return function(e,n){var t=e.concat([e.index,e.input]);return n.apply(null,t).then(function(n){return l({},e,{replacement:n})})}(e,n)});return Promise.all(t)}function t(e,t,r){t.lastIndex=0;try{return Promise.resolve(function(e,t,r){return n(function(e,n){for(var t=[],r=n.exec(e);r&&(t.push(r),n.global);)r=n.exec(e);return t}(e,t),r).then(function(n){return function(e,t){return n.reverse().reduce(function(e,n){var t=e.slice(0,n.index),r=e.slice(n.index+n[0].length);return t+n.replacement+r},e)}(e)})}(e,t,r))}catch(e){return Promise.reject(e)}}function r(e,n,t){return void 0===t&&(t=!1),t?e.test(n):n.match(e)}function o(e,n){var t=e.result,r=e.plugins;void 0===r&&(r=[]);return function(e){return new RegExp("<a[^>]*>("+e.source+")<\\/a>","gi")}(n.regex).test(t)||r.filter(function(e){return"url"===e.id}).length}function u(e,n,t){var r=e._services,o=n.id;r.filter(function(e){return e.match===t}).length||r.push({id:o,match:t})}function i(e,n,r,o){return new Promise(function(i,a){var s,l;return l=r,s=l.regex,t(e,s,function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];return new Promise(function(t,i){return c(e,n,r).then(function(c){try{return n._embeds.push({content:c,index:o||e.find(function(e){return"number"==typeof e})}),u(n,r,e[0]),t()}catch(e){return i(e)}},i)})}).then(function(e){try{return i(n)}catch(e){return a(e)}},a)})}function c(e,n,t){var r=this;return new Promise(function(o,u){function i(){return o(a(e,n,t,s))}var c,a,s,l;return l=t,c=l._process,a=l.template,c?c(e,n,t).then(function(e){try{return s=e,i.call(r)}catch(e){return u(e)}},u):i.call(r)})}function a(e,n,t){var r=n.fetch,o=t.gAuthKey;return t.details?function(e,n,t){return new Promise(function(r,o){var u,i,c=function(e){try{return console.log(e),r({})}catch(e){return o(e)}};try{return n("https://www.googleapis.com/youtube/v3/videos?id="+e+"&key="+t+"&part=snippet,statistics").then(function(e){try{return(u=e).json().then(function(e){try{return i=e,r(i.items[0])}catch(e){return c(e)}},c)}catch(e){return c(e)}},c)}catch(e){c(e)}})}(e[1],r,o):Promise.resolve()}function s(e){var n={id:g,regex:h(),gAuthKey:"",details:!0,height:300,clickClass:"ejs-video-thumb",onVideoShow:function(){},_onLoadInternal:function(e,n){!function(e,n){var t=e.input,r=n.clickClass,o=n.onVideoShow,u=n.height;if(!f(t))throw new Error("input should be a DOM Element.");for(var i=document.getElementsByClassName(r),c=0;c<i.length;c++)i[c].onclick=function(){var e=this.getAttribute("data-url");o(e),e+="?autoplay=1",this.parentNode.innerHTML=w(e,u,g)}}(e,n)},onLoad:function(){},template:function(e,n,t,r){var o=t.details,u=t.height,i=t.clickClass;return new Promise(function(n,t){var c=b+"embed/"+e[1];return n(o?v(function(e){var n=e.snippet,t=e.id;return{title:n.title,thumbnail:n.thumbnails.medium.url,description:n.description,url:b+"watch?v="+t,embedUrl:b+"embed/"+t}}(r),i,!0):w(c,u,g))})}};if(!e.gAuthKey)throw new Error("You need to pass google auth key.");var t=l({},n,e,{_process:a});return y(t)}var l=e,f=function(e){return!(!e||"object"!=typeof e)&&("object"==typeof window&&"object"==typeof window.Node?e instanceof window.Node:"number"==typeof e.nodeType&&"string"==typeof e.nodeName)},h=function(){return/(?:youtube\.com\/\S*(?:(?:\/e(?:mbed))?\/|watch\/?\?(?:\S*?&?v\=))|youtu\.be\/)([a-zA-Z0-9_-]{6,11})/g},d=/<a[^>]*>([^<]+)<\/a>/gi,m=function(e,n){return new Promise(function(a,s){var f,h,m,p,v;f=e.inlineEmbed;var w;return w=n,h=w._ignoreAnchorCheck,m=w._ignoreInlineCheck,p=w.regex,f||m?new Promise(function(i,a){return o(e,{regex:p})&&!h?function(e,n){return new Promise(function(o,i){var a=e.result,s=e.replaceUrl,l=n.regex,f=n._replaceAnyways;return o(t(a,d,function(o,i){return new Promise(function(a,h){var d,m;return r(l,i,!0)?s||f?a(t(i,l,function(){for(var t=[],r=arguments.length;r--;)t[r]=arguments[r];return new Promise(function(r,o){return u(e,n,t[0]),r(c(t,e,n))})})):(d=function(e,n){e.lastIndex=0;var t=e.exec(n);return e.lastIndex=0,t}(l,i),u(e,n,d[0]),c(d,e,n).then(function(e){try{return m=e,a(d?o+m:o)}catch(e){return h(e)}},h)):a(o)})}))})}(e,n).then(i,a):function(e,n){return new Promise(function(r,o){var i=e.result,a=e.replaceUrl,s=n.regex,l=n._replaceAnyways;return r(t(i,s,function(){for(var t=[],r=arguments.length;r--;)t[r]=arguments[r];return new Promise(function(r,o){return u(e,n,t[0]),new Promise(function(r,o){return a||l?r(c(t,e,n)):c(t,e,n).then(function(e){try{return r(t[0]+" "+e)}catch(e){return o(e)}},o)}).then(r,o)})}))})}(e,n).then(i,a)}).then(function(n){try{return v=n,a(l({},e,{result:v}))}catch(e){return s(e)}},s):a(function(e,n){var c=this;return new Promise(function(a,s){function f(){return a(m)}var h,m,p;return p=n,h=p.regex,m=l({},e),o(m,{regex:h})?t(m.result,d,function(e,t,o){return new Promise(function(c,a){return r(h,e,!0)?(u(m,n,e),i(t,m,n,o).then(function(n){try{return m=n,c(e)}catch(e){return a(e)}},a)):c(e)})}).then(function(e){try{return f.call(c)}catch(e){return s(e)}},s):(m=i(m.result,m,n),f.call(c))})}(e,n))})},p=function(e,n,t){return null==n||n>=e.length?e:(null==t&&(t="..."),e.slice(0,Math.max(0,n-t.length))+t)},v=function(e,n,t){var r=e.url,o=e.title,u=e.embedUrl,i=e.description,c=e.thumbnail;return void 0===t&&(t=!1),'<div class="ejs-preview ejs-embed"><div class="ejs-thumb '+n+'" data-url="'+u+'" style="background-image:url('+c+')">'+(t?"<span>►</span>":"")+'</div><div class="ejs-info"><h4 class="ejs-title"><a href="'+r+'">'+o+'</a></h4><div class="ejs-desc">'+p(i,150)+"</div></div></div>"},w=function(e,n,t){return'<iframe sandbox="allow-forms allow-scripts allow-pointer-lock allow-same-origin allow-top-navigation" class="ejs-embed ejs-'+t+'" src="'+e+'" frameBorder="0" height="'+n+'"></iframe>'},y=function(e){var n=l({},{_replaceAnyways:!1,_ignoreAnchorCheck:!1,_ignoreInlineCheck:!1,onLoad:function(){}},e),t=n._onLoadInternal,r=n.onLoad,o=n.regex,u=n.template,i=n.id;if(!o)throw new Error("regex not passed.");if(!u)throw new Error("template not passed.");return{id:i,transform:function(e){return new Promise(function(t,r){return m(e,n).then(function(n){try{return t(l({},e,n))}catch(e){return r(e)}},r)})},onLoad:function(e){t&&t(e,n),r&&r(e,n)}}},g="youtube",b="https://www.youtube.com/";return s.id=g,s}); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):e.embedPluginYoutube=n()}(this,function(){"use strict";function e(){var n=[].slice.call(arguments),t=!1;"boolean"==typeof n[0]&&(t=n.shift());var r=n[0];if(!r||"object"!=typeof r&&"function"!=typeof r)throw new Error("extendee must be an object");for(var u=n.slice(1),o=u.length,i=0;i<o;i++){var c=u[i];for(var a in c)if(c.hasOwnProperty(a)){var s=c[a];if(t&&function(e){return Array.isArray(e)||"[object Object]"=={}.toString.call(e)}(s)){var f=Array.isArray(s)?[]:{};r[a]=e(!0,r.hasOwnProperty(a)?r[a]:f,s)}else r[a]=s}}return r}function n(e,n){var t=e.map(function(e){return function(e,n){var t=e.concat([e.index,e.input]);return n.apply(null,t).then(function(n){return f({},e,{replacement:n})})}(e,n)});return Promise.all(t)}function t(e,t,r){t.lastIndex=0;try{return Promise.resolve(function(e,t,r){return n(function(e,n){for(var t=[],r=n.exec(e);r&&(t.push(r),n.global);)r=n.exec(e);return t}(e,t),r).then(function(n){return function(e,t){return n.reverse().reduce(function(e,n){var t=e.slice(0,n.index),r=e.slice(n.index+n[0].length);return t+n.replacement+r},e)}(e)})}(e,t,r))}catch(e){return Promise.reject(e)}}function r(e,n,t){return void 0===t&&(t=!1),t?e.test(n):n.match(e)}function u(e,n){var t=e.result,r=e.plugins;void 0===r&&(r=[]);return function(e){return new RegExp("<a[^>]*>("+e.source+")<\\/a>","gi")}(n.regex).test(t)||r.filter(function(e){return"url"===e.id}).length}function o(e,n,t){var r=e._services,u=n.id;r.filter(function(e){return e.match===t}).length||r.push({id:u,match:t})}function i(e,n,r,u){return new Promise(function(i,a){var s,f;return f=r,s=f.regex,t(e,s,function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];return new Promise(function(t,i){return c(e,n,r).then(function(c){try{return n._embeds.push({content:c,index:u||e.find(function(e){return"number"==typeof e})}),o(n,r,e[0]),t()}catch(e){return i(e)}},i)})}).then(function(e){try{return i(n)}catch(e){return a(e)}},a)})}function c(e,n,t){var r=this;return new Promise(function(u,o){function i(){return u(a(e,n,t,s))}var c,a,s,f;return f=t,c=f._process,a=f.template,c?c(e,n,t).then(function(e){try{return s=e,i.call(r)}catch(e){return o(e)}},o):i.call(r)})}function a(e,n,t){var r=n.fetch,u=t.gAuthKey;return t.details?function(e,n,t){return new Promise(function(r,u){var o,i,c=function(e){try{return console.log(e),r({})}catch(e){return u(e)}};try{return n("https://www.googleapis.com/youtube/v3/videos?id="+e+"&key="+t+"&part=snippet,statistics").then(function(e){try{return(o=e).json().then(function(e){try{return i=e,r(i.items[0])}catch(e){return c(e)}},c)}catch(e){return c(e)}},c)}catch(e){c(e)}})}(e[1],r,u):Promise.resolve()}function s(e){var n={id:w,regex:h(),gAuthKey:"",details:!0,height:300,clickClass:"ejs-video-thumb",onVideoShow:function(){},_onLoadInternal:function(e,n){!function(e,n){var t=e.input,r=n.clickClass,u=n.onVideoShow,o=n.height;if(!l(t))throw new Error("input should be a DOM Element.");for(var i=document.getElementsByClassName(r),c=0;c<i.length;c++)i[c].onclick=function(){var e=this.getAttribute("data-url");u(e),e+="?autoplay=1",this.parentNode.innerHTML=y(e,o,w)}}(e,n)},onLoad:function(){},template:function(e,n,t,r){var u=t.details,o=t.height,i=t.clickClass;return new Promise(function(n,t){var c=b+"embed/"+e[1];return n(u?p(function(e){var n=e.snippet,t=e.id;return{title:n.title,thumbnail:n.thumbnails.medium.url,description:n.description,url:b+"watch?v="+t,embedUrl:b+"embed/"+t}}(r),i,!0):y(c,o,w))})}};if(!e.gAuthKey)throw new Error("You need to pass google auth key.");var t=f({},n,e,{_process:a});return g(t)}var f=e,l=function(e){return!(!e||"object"!=typeof e)&&("object"==typeof window&&"object"==typeof window.Node?e instanceof window.Node:"number"==typeof e.nodeType&&"string"==typeof e.nodeName)},h=function(){return/(?:youtube\.com\/\S*(?:(?:\/e(?:mbed))?\/|watch\/?\?(?:\S*?&?v\=))|youtu\.be\/)([a-zA-Z0-9_-]{6,11})/g},d=/<a[^>]*>([^<]+)<\/a>/gi,m=function(e,n){return new Promise(function(a,s){var l,h,m,v,p;l=e.inlineEmbed;var y;return y=n,h=y._ignoreAnchorCheck,m=y._ignoreInlineCheck,v=y.regex,l||m?new Promise(function(i,a){return u(e,{regex:v})&&!h?function(e,n){return new Promise(function(u,i){var a=e.result,s=e.replaceUrl,f=n.regex,l=n._replaceAnyways;return u(t(a,d,function(u,i){return new Promise(function(a,h){var d,m;return r(f,i,!0)?s||l?a(t(i,f,function(){for(var t=[],r=arguments.length;r--;)t[r]=arguments[r];return new Promise(function(r,u){return o(e,n,t[0]),r(c(t,e,n))})})):(d=function(e,n){e.lastIndex=0;var t=e.exec(n);return e.lastIndex=0,t}(f,i),o(e,n,d[0]),c(d,e,n).then(function(e){try{return m=e,a(d?u+m:u)}catch(e){return h(e)}},h)):a(u)})}))})}(e,n).then(i,a):function(e,n){return new Promise(function(r,u){var i=e.result,a=e.replaceUrl,s=n.regex,f=n._replaceAnyways;return r(t(i,s,function(){for(var t=[],r=arguments.length;r--;)t[r]=arguments[r];return new Promise(function(r,u){return o(e,n,t[0]),new Promise(function(r,u){return a||f?r(c(t,e,n)):c(t,e,n).then(function(e){try{return r(t[0]+" "+e)}catch(e){return u(e)}},u)}).then(r,u)})}))})}(e,n).then(i,a)}).then(function(n){try{return p=n,a(f({},e,{result:p}))}catch(e){return s(e)}},s):a(function(e,n){var c=this;return new Promise(function(a,s){function l(){return a(m)}var h,m,v;return v=n,h=v.regex,m=f({},e),u(m,{regex:h})?t(m.result,d,function(e,t,u){return new Promise(function(c,a){return r(h,e,!0)?(o(m,n,e),i(t,m,n,u).then(function(n){try{return m=n,c(e)}catch(e){return a(e)}},a)):c(e)})}).then(function(e){try{return l.call(c)}catch(e){return s(e)}},s):(m=i(m.result,m,n),l.call(c))})}(e,n))})},v=function(e,n,t){return null==n||n>=e.length?e:(null==t&&(t="..."),e.slice(0,Math.max(0,n-t.length))+t)},p=function(e,n,t){var r=e.url,u=e.title,o=e.embedUrl,i=e.description,c=e.thumbnail;return void 0===t&&(t=!1),'<div class="ejs-preview ejs-embed"><div class="ejs-thumb '+n+'" data-url="'+o+'" style="background-image:url('+c+')">'+(t?"<span>►</span>":"")+'</div><div class="ejs-info"><h4 class="ejs-title"><a href="'+r+'">'+u+'</a></h4><div class="ejs-desc">'+v(i,150)+"</div></div></div>"},y=function(e,n,t){return'<iframe class="ejs-embed ejs-'+t+'" src="'+e+'" frameBorder="0" height="'+n+'"></iframe>'},g=function(e){var n=f({},{_replaceAnyways:!1,_ignoreAnchorCheck:!1,_ignoreInlineCheck:!1,onLoad:function(){}},e),t=n._onLoadInternal,r=n.onLoad,u=n.regex,o=n.template,i=n.id;if(!u)throw new Error("regex not passed.");if(!o)throw new Error("template not passed.");return{id:i,transform:function(e){return new Promise(function(t,r){return m(e,n).then(function(n){try{return t(f({},e,n))}catch(e){return r(e)}},r)})},onLoad:function(e){t&&t(e,n),r&&r(e,n)}}},w="youtube",b="https://www.youtube.com/";return s.id=w,s}); | ||
//# sourceMappingURL=embed-plugin-youtube.min.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
78243
721
+ Added@awinogrodzki/embed-plugin-utilities@5.0.9(transitive)
- Removedembed-plugin-utilities@^5.0.4