UNPKG

embed-plugin-facebook

Version:

An embed-js plugin to embed facebook posts and videos.

3 lines (2 loc) 4.96 kB
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):n.embedPluginFacebook=e()}(this,function(){"use strict";function n(){var e=[].slice.call(arguments),r=!1;"boolean"==typeof e[0]&&(r=e.shift());var t=e[0];if(!t||"object"!=typeof t&&"function"!=typeof t)throw new Error("extendee must be an object");for(var u=e.slice(1),o=u.length,i=0;i<o;i++){var c=u[i];for(var f in c)if(c.hasOwnProperty(f)){var a=c[f];if(r&&function(n){return Array.isArray(n)||"[object Object]"=={}.toString.call(n)}(a)){var s=Array.isArray(a)?[]:{};t[f]=n(!0,t.hasOwnProperty(f)?t[f]:s,a)}else t[f]=a}}return t}function e(n,e){var r=n.map(function(n){return function(n,e){var r=n.concat([n.index,n.input]);return e.apply(null,r).then(function(e){return a({},n,{replacement:e})})}(n,e)});return Promise.all(r)}function r(n,r,t){r.lastIndex=0;try{return Promise.resolve(function(n,r,t){return e(function(n,e){for(var r=[],t=e.exec(n);t&&(r.push(t),e.global);)t=e.exec(n);return r}(n,r),t).then(function(e){return function(n,r){return e.reverse().reduce(function(n,e){var r=n.slice(0,e.index),t=n.slice(e.index+e[0].length);return r+e.replacement+t},n)}(n)})}(n,r,t))}catch(n){return Promise.reject(n)}}function t(n,e,r){return void 0===r&&(r=!1),r?n.test(e):e.match(n)}function u(n,e){var r=n.result,t=n.plugins;void 0===t&&(t=[]);return function(n){return new RegExp("<a[^>]*>("+n.source+")<\\/a>","gi")}(e.regex).test(r)||t.filter(function(n){return"url"===n.id}).length}function o(n,e,r){var t=n._services,u=e.id;t.filter(function(n){return n.match===r}).length||t.push({id:u,match:r})}function i(n,e,t,u){return new Promise(function(i,f){var a,s;return s=t,a=s.regex,r(n,a,function(){for(var n=[],r=arguments.length;r--;)n[r]=arguments[r];return new Promise(function(r,i){return c(n,e,t).then(function(c){try{return e._embeds.push({content:c,index:u||n.find(function(n){return"number"==typeof n})}),o(e,t,n[0]),r()}catch(n){return i(n)}},i)})}).then(function(n){try{return i(e)}catch(n){return f(n)}},f)})}function c(n,e,r){var t=this;return new Promise(function(u,o){function i(){return u(f(n,e,r,a))}var c,f,a,s;return s=r,c=s._process,f=s.template,c?c(n,e,r).then(function(n){try{return a=n,i.call(t)}catch(n){return o(n)}},o):i.call(t)})}function f(n){var e=a({},{id:p,regex:/(https?:\/\/)?www\.facebook\.com\/(?:(videos|posts)\.php\?v=\d+|.*?\/(videos|posts)\/\d+\/?)/gi,height:225,template:function(n,e,r){var t=r.height,u=n[0],o=u.indexOf("/videos/")<0?"post":"video";return h("https://www.facebook.com/plugins/"+o+".php?href="+u,t,p)}},n);return d(e)}var a=n,s=/<a[^>]*>([^<]+)<\/a>/gi,l=function(n,e){return new Promise(function(f,l){var h,d,p,m,v;h=n.inlineEmbed;var g;return g=e,d=g._ignoreAnchorCheck,p=g._ignoreInlineCheck,m=g.regex,h||p?new Promise(function(i,f){return u(n,{regex:m})&&!d?function(n,e){return new Promise(function(u,i){var f=n.result,a=n.replaceUrl,l=e.regex,h=e._replaceAnyways;return u(r(f,s,function(u,i){return new Promise(function(f,s){var d,p;return t(l,i,!0)?a||h?f(r(i,l,function(){for(var r=[],t=arguments.length;t--;)r[t]=arguments[t];return new Promise(function(t,u){return o(n,e,r[0]),t(c(r,n,e))})})):(d=function(n,e){n.lastIndex=0;var r=n.exec(e);return n.lastIndex=0,r}(l,i),o(n,e,d[0]),c(d,n,e).then(function(n){try{return p=n,f(d?u+p:u)}catch(n){return s(n)}},s)):f(u)})}))})}(n,e).then(i,f):function(n,e){return new Promise(function(t,u){var i=n.result,f=n.replaceUrl,a=e.regex,s=e._replaceAnyways;return t(r(i,a,function(){for(var r=[],t=arguments.length;t--;)r[t]=arguments[t];return new Promise(function(t,u){return o(n,e,r[0]),new Promise(function(t,u){return f||s?t(c(r,n,e)):c(r,n,e).then(function(n){try{return t(r[0]+" "+n)}catch(n){return u(n)}},u)}).then(t,u)})}))})}(n,e).then(i,f)}).then(function(e){try{return v=e,f(a({},n,{result:v}))}catch(n){return l(n)}},l):f(function(n,e){var c=this;return new Promise(function(f,l){function h(){return f(p)}var d,p,m;return m=e,d=m.regex,p=a({},n),u(p,{regex:d})?r(p.result,s,function(n,r,u){return new Promise(function(c,f){return t(d,n,!0)?(o(p,e,n),i(r,p,e,u).then(function(e){try{return p=e,c(n)}catch(n){return f(n)}},f)):c(n)})}).then(function(n){try{return h.call(c)}catch(n){return l(n)}},l):(p=i(p.result,p,e),h.call(c))})}(n,e))})},h=function(n,e,r){return'<iframe class="ejs-embed ejs-'+r+'" src="'+n+'" frameBorder="0" height="'+e+'"></iframe>'},d=function(n){var e=a({},{_replaceAnyways:!1,_ignoreAnchorCheck:!1,_ignoreInlineCheck:!1,onLoad:function(){}},n),r=e._onLoadInternal,t=e.onLoad,u=e.regex,o=e.template,i=e.id;if(!u)throw new Error("regex not passed.");if(!o)throw new Error("template not passed.");return{id:i,transform:function(n){return new Promise(function(r,t){return l(n,e).then(function(e){try{return r(a({},n,e))}catch(n){return t(n)}},t)})},onLoad:function(n){r&&r(n,e),t&&t(n,e)}}},p="facebook";return f.id=p,f}); //# sourceMappingURL=embed-plugin-facebook.min.js.map