forked from shobhitsharma/embedo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
embedo.min.js
1 lines (1 loc) · 20 KB
/
embedo.min.js
1
!function(t,e){"use strict";"function"==typeof define&&define.amd?define(e):"object"==typeof module&&module.exports?module.exports=e():t.Embedo=window.Embedo=e()}(this,function(){"use strict";function t(e){return this.options=e||t.defaults.OPTIONS,this.requests=[],this.events=[],this.init(this.options),this}function e(e,i,n,r){l("facebook",function(o){if(o)return r(o);window.FB.XFBML.parse(e),window.FB.Event.subscribe("xfbml.render",function(){i.firstChild&&(!1!==n.centerize&&t.utils.centerize(e,i,n),"rendered"===i.firstChild.getAttribute("fb-xfbml-state")&&s(e,i,n,r))})})}function i(e,i,n,r){l("twitter",function(o){if(o)return r(o);window.twttr.widgets.load(i),window.twttr.events.bind("rendered",function(o){i.firstChild&&i.firstChild.getAttribute("id")===o.target.getAttribute("id")&&(!1!==n.centerize&&t.utils.centerize(e,i,n),s(e,i,n,r))})})}function n(e,i,n,r){l("instagram",function(o){if(o)return r(o);if(!window.instgrm.Embeds||!window.instgrm.Embeds)return r(new Error("instagram_sdk_missing"));window.instgrm.Embeds.process(i);var l=setInterval(function(){if(i.firstChild&&i.firstChild.className.match(/instagram-media-rendered/))return clearInterval(l),!1!==n.centerize&&t.utils.centerize(e,i,n),s(e,i,n,r)},250)})}function r(e,i,n,r){l("pinterest",function(o){if(o)return r(o);if(!(window.PinUtils&&window.PinUtils&&i&&i.firstChild))return r(new Error("pinterest_sdk_missing"));var l=setInterval(function(){return i.querySelector("[data-pin-href]")?(clearInterval(l),!1!==n.centerize&&t.utils.centerize(e,i,n),s(e,i,n,r)):l>=100?(clearInterval(l),r(new Error("pinterest_embed_failed"))):void 0},250);setTimeout(function(){i.querySelector("[data-pin-href]")||window.PinUtils.build(i)},750)})}function o(e,i,n,r){l("googlemaps",function(o){if(o)return r(o);!1!==n.centerize&&t.utils.centerize(e,i,n),i.style.width=n.width?n.width+"px":t.utils.compute(e,"width"),i.style.height=n.height?n.height+"px":t.utils.compute(e,"height"),r(null,{})})}function s(e,i,n,r){if(t.log("info","automagic",e,i,n),n=n||{},r=r||function(){},!t.utils.validateElement(e)||!t.utils.validateElement(i))return r(new Error("HTMLElement does not exist in DOM."));t.utils.watcher(n.id||t.utils.uuid(),function(){var o={width:n.width||t.utils.compute(e,"width"),height:n.height||t.utils.compute(e,"height")},s={width:t.utils.compute(i,"width"),height:t.utils.compute(i,"height")};if(n.strict)return r(null,{width:o.width,height:o.height});if(i.firstChild&&(i.firstChild.style.margin="0 auto !important",i.firstChild.style.padding="0 !important",i.firstChild.style.minWidth="none !important",i.firstChild.style.maxWidth="none !important",i.firstChild.style.minHeight="none !important",i.firstChild.style.maxHeight="none !important"),n.width&&n.height){var l=s.width>o.width||s.height>o.height;if(n.width&&(i.style.width=n.width+"px"),n.height&&(i.style.height=n.height+"px"),l){var u=Math.min(o.width/s.width,o.height/s.height);t.utils.transform(i,"scale("+u+")")}}r(null,{width:o.width,height:o.height})},500)}function l(e,i){if(i=i||function(){},!t.defaults.SOURCES[e])return i(new Error("unsupported_sdk_type"));var n=0;!function r(){return++n>15?i(new Error("sdk_not_available")):window[t.defaults.SOURCES[e].GLOBAL]?i(null,window[t.defaults.SOURCES[e].GLOBAL]):void setTimeout(r,10*n)}()}return t.log=function(e){t.debug&&"undefined"!=typeof console&&void 0!==console.log&&console[e]&&console[e].apply(console,Array.prototype.slice.call(arguments,1))},t.defaults={OPTIONS:{facebook:null,twitter:!1,instagram:!1,pinterest:!1,googlemaps:null},SOURCES:{facebook:{GLOBAL:"FB",SDK:"https://connect.facebook.net/en_US/all.js",oEmbed:"https://www.facebook.com/plugins/post/oembed.json",REGEX:/(?:(?:http|https):\/\/)?(?:www.)?facebook.com\/(?:(?:\w)*#!\/)?(?:pages\/)?([\w\-]*)?/g,PARAMS:{version:"v2.10",cookie:!0,appId:null,xfbml:!0}},twitter:{GLOBAL:"twttr",SDK:"https://platform.twitter.com/widgets.js",oEmbed:"https://publish.twitter.com/oembed",REGEX:/^http[s]*:\/\/[www.]*twitter(\.[a-z]+).*/i,PARAMS:{}},instagram:{GLOBAL:"instgrm",SDK:"https://platform.instagram.com/en_US/embeds.js",oEmbed:"https://api.instagram.com/oembed",REGEX:/instagram.com\/p\/[a-zA-Z0-9_\/\?\-\=]+/gi,PARAMS:{}},youtube:{GLOBAL:null,SDK:null,oEmbed:"https://www.youtube.com/embed/",REGEX:/^(?:(?:https?:)?\/\/)?(?:www\.)?(?:m\.)?(?:youtu(?:be)?\.com\/(?:v\/|embed\/|watch(?:\/|\?v=))|youtu\.be\/)((?:\w|-){11})(?:\S+)?$/,PARAMS:null},pinterest:{GLOBAL:"PinUtils",SDK:"https://assets.pinterest.com/js/pinit.js",oEmbed:null,REGEX:/(https?:\/\/(ww.)?)?pinterest(\.[a-z]+).*/i,PARAMS:{}},vimeo:{GLOBAL:null,SDK:null,oEmbed:"https://vimeo.com/api/oembed.json",REGEX:/(http|https)?:\/\/(www\.)?vimeo(\.[a-z]+)\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|)(\d+)(?:|\/\?)/,PARAMS:{}},googlemaps:{GLOBAL:"google",SDK:"https://maps.googleapis.com/maps/api/js",oEmbed:null,REGEX:/(http|https)?:\/\/(www\.|maps\.)?google(\.[a-z]+){1,2}\/maps\/.*/i,PARAMS:{}},github:{GLOBAL:null,SDK:null,oEmbed:null,REGEX:/https:\/\/gist\.github\.com\/(\w+)\/(\w+)/,PARAMS:{}}},RESTRICTED:["url","strict","height","width","centerize"]},t.utils=Object.create({uuid:function(){var t=46656*Math.random()|0,e=46656*Math.random()|0;return t=("000"+t.toString(36)).slice(-3),e=("000"+e.toString(36)).slice(-3),t+e},extend:function(t){t=t||{};for(var e=1;e<arguments.length;e++)if(arguments[e])for(var i in arguments[e])arguments[e].hasOwnProperty(i)&&(t[i]=arguments[e][i]);return t},merge:function(t,e,i){i=i||[];for(var n in e)-1===i.indexOf(n)&&(t[n]=e[n]);return t},sequencer:function(){var t=arguments;return{then:function(e){for(var i=0,n=0;n<t.length;n++)t[n](function(){++i===t.length&&e()})}}},observer:function(){function t(){this.resolved=[],this.rejected=[]}return t.prototype={execute:function(t,e){var i=t.length;for(e=Array.prototype.slice.call(e);i--;)t[i].apply(null,e)},resolve:function(){this.execute(this.resolved,arguments)},reject:function(){this.execute(this.rejected,arguments)},done:function(t){return this.resolved.push(t),this},fail:function(t){return this.rejected.push(t),this}},t}(),validateURL:function(t){return/(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/.test(t)},generateElement:function(t,e){var i=document.createElement(t);return Object.keys(e||{}).forEach(function(t){i.setAttribute(t,e[t])}),i},generateEmbed:function(e,i,n){e=e||t.utils.uuid();var r=document.createElement("div");return r.setAttribute("id",e),r.setAttribute("data-embedo-id",e),r.setAttribute("data-embedo-source",i),t.utils.validateElement(n)?r.appendChild(n):r.innerHTML=n||"",r},generateScript:function(t){var e=document.createElement("script");return e.type="text/javascript",e.src=encodeURI(t),e.setAttribute("async",""),e.setAttribute("charset","utf-8"),e},validateElement:function(t){return"object"==typeof HTMLElement?t instanceof window.HTMLElement:t&&"object"==typeof t&&null!==t&&1===t.nodeType&&"string"==typeof t.nodeName},querystring:function(t){var e=[];for(var i in t)t.hasOwnProperty(i)&&e.push(encodeURIComponent(i)+"="+encodeURIComponent(t[i]));return e.join("&")},fetch:function(e,i,n){function r(t,e){try{delete window[t]}catch(e){window[t]=void 0}e&&(o.removeChild(e),e=void 0)}"function"==typeof i&&(n=i,i={}),i=i||{};var o=document.head||document.getElementsByTagName("head")[0],s=document.createElement("script"),l="embedoFetch_"+t.utils.uuid();e=(e+=(~e.indexOf("?")?"&":"?")+"callback="+encodeURIComponent(l)).replace("?&","?"),window[l]=function(t){r(l,s),n(null,t)},s.type="text/javascript",s.charset="UTF-8",s.onerror=function(t){return r(l,s),n(t)},o.appendChild(s),s.src=e},transform:function(e,i){t.utils.validateElement(e)&&(e.style.webkitTransform=i,e.style.MozTransform=i,e.style.msTransform=i,e.style.OTransform=i,e.style.transform=i)},compute:function(e,i,n){if(t.utils.validateElement(e)&&i){var r=e.getBoundingClientRect()[i];return!n&&r||(document.defaultView&&document.defaultView.getComputedStyle?r=document.defaultView.getComputedStyle(e,"").getPropertyValue(i):e.currentStyle&&(i=i.replace(/\-(\w)/g,function(t,e){return e.toUpperCase()}),r=e.currentStyle[i])),"string"!=typeof r||/^\d+(\.\d+)?%$/.test(r)||(r=r.replace(/[^\d.-]/g,"")),isNaN(Number(r))?r:Number(r)}},convertToPx:function(e,i,n){return isNaN(Number(n))?/^\d+(\.\d+)?%$/.test(n)?function(e,i,n){var r=t.utils.compute(e.parentNode,i,!0);return n=parseFloat(n),r*(n/100)}(e,i,n):n.match(/(vh|vw)/)?function(t,e){var i=window,n=document,r=n.documentElement,o=n.body,s=i.innerWidth||r.clientWidth||o.clientWidth,l=i.innerHeight||r.clientHeight||o.clientHeight;return"vw"===t?s*parseFloat(e)/100:"vh"===t?l*parseFloat(e)/100:void 0}(n.replace(/[0-9]/g,""),n):void 0:Number(n)},watcher:function(t,e,i){return window.EMBEDO_WATCHER=window.EMBEDO_WATCHER||{},window.EMBEDO_WATCHER[t]=window.EMBEDO_WATCHER[t]||{id:t,count:0,request:null},window.EMBEDO_WATCHER[t].count>0&&window.EMBEDO_WATCHER[t].request&&(window.EMBEDO_WATCHER[t].count-=1,clearTimeout(window.EMBEDO_WATCHER[t].request)),window.EMBEDO_WATCHER[t].count+=1,window.EMBEDO_WATCHER[t].request=setTimeout(function(){window.EMBEDO_WATCHER[t].count-=1,0===window.EMBEDO_WATCHER[t].count&&e.call()},i),null},dimensions:function(e,i,n){var r=t.utils.compute(e,"width");return i=i||(r>0?r:t.utils.compute(e.parentNode,"width")),n=n||(r>0?r/1.5:t.utils.compute(e.parentNode,"height")),{width:i,height:n}},centerize:function(e,i,n){t.utils.validateElement(e)&&t.utils.validateElement(i)&&((n=n||{}).width&&(e.style.width=n.width,e.style.maxWidth=n.width),n.height&&(e.style.height=n.height,e.style.maxHeight=n.height),i.style.display="-moz-box",i.style.display="-ms-flexbox",i.style.display="-webkit-flex",i.style.display="-webkit-box",i.style.display="flex",i.style.textAlign="center",i.style["justify-content"]="center",i.style["align-items"]="center",i.style.margin="0 auto")},handleScriptValidation:function(t){if(t){t=t.split("#")[0];for(var e=document.getElementsByTagName("script"),i=e.length;i--;)if(e[i].src===t)return!0;return!1}}}),t.mixin=function(e){for(var i=["on","off","once","emit"],n=0;n<i.length;n++)e.prototype[i[n]]=t.prototype[i[n]]},t.prototype=Object.create({on:function(t,e){"object"!=typeof this.events[t]&&(this.events[t]=[]),this.events[t].push(e)},off:function(t,e){var i;"object"==typeof this.events[t]&&(i=this.events[t].indexOf(e))>-1&&this.events[t].splice(i,1)},emit:function(t){var e,i,n,r=[].slice.call(arguments,1);if("object"==typeof this.events[t])for(n=(i=this.events[t].slice()).length,e=0;e<n;e++)i[e].apply(this,r)},once:function(t,e){this.on(t,function i(){this.off(t,i),e.apply(this,arguments)})}}),t.prototype.init=function(e){function i(e,i){if(e&&i){var n=t.defaults.SOURCES[e.toLowerCase()].SDK;t.utils.handleScriptValidation(n)||(i&&"object"==typeof i&&(n+=("facebook"===e?"#":"?")+t.utils.querystring(i)),document.body.appendChild(t.utils.generateScript(n)))}}t.log("info","init",this.requests,e),i("facebook",e.facebook),i("twitter",e.twitter),i("instagram",e.instagram),i("pinterest",e.pinterest),i("googlemaps",e.googlemaps)},t.prototype.facebook=function(i,n,r,o,s){var l=t.defaults.SOURCES.facebook.oEmbed,u=t.utils.merge({url:encodeURI(r),omitscript:!0},o,t.defaults.RESTRICTED);("width"in o||"maxwidth"in o)&&(u.maxwidth=o.maxwidth||o.width),l+="?"+t.utils.querystring(u),t.utils.fetch(l,function(l,u){if(l)return t.log("error","facebook",l),s(l);var d=t.utils.generateEmbed(i,"facebook",u.html);n.appendChild(d),e(n,d,{id:i,url:r,strict:o.strict,width:o.width,height:o.height,centerize:o.centerize},function(t,e){if(t)return s(t);s(null,{id:i,el:n,width:e.width,height:e.height})})})},t.prototype.twitter=function(e,n,r,o,s){var l=t.defaults.SOURCES.twitter.oEmbed,u=t.utils.merge({url:encodeURI(r),omit_script:1},o,t.defaults.RESTRICTED);("width"in o||"maxwidth"in o)&&(u.maxwidth=o.maxwidth||o.width),("height"in o||"maxheight"in o)&&(u.maxheight=o.maxheight||o.height),l+="?"+t.utils.querystring(u),t.utils.fetch(l,function(l,u){if(l)return t.log("error","twitter",l),s(l);var d=t.utils.generateEmbed(e,"twitter",u.html);n.appendChild(d),i(n,d,{id:e,url:r,strict:o.strict,width:o.width,height:o.height,centerize:o.centerize},function(t,i){if(t)return s(t);s(null,{id:e,el:n,width:i.width,height:i.height})})})},t.prototype.instagram=function(e,i,r,o,s){var l=t.defaults.SOURCES.instagram.oEmbed,u=t.utils.merge({url:encodeURI(r),omitscript:!0,hidecaption:!0},o,t.defaults.RESTRICTED);("width"in o||"maxwidth"in o)&&(o.width=o.maxwidth?o.maxwidth:o.width,o.width>320&&(u.maxwidth=o.width)),l+="?"+t.utils.querystring(u),t.utils.fetch(l,function(l,u){if(l)return t.log("error","instagram",l),s(l);var d=t.utils.generateEmbed(e,"instagram",u.html);i.appendChild(d),n(i,d,{id:e,url:r,strict:o.strict,width:o.width,height:o.height,centerize:o.centerize},function(t,n){if(t)return s(t);s(null,{id:e,el:i,width:n.width,height:n.height})})})},t.prototype.youtube=function(e,i,n,r,o){function s(t){var e=/(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/ ]{11})/i,i=t.match(e);return!(!i||2!==i.length)&&i[1]}if(!s(n))return t.log("error","youtube","Unable to detect Youtube video id."),o("Unable to detect Youtube video id.");var l=t.defaults.SOURCES.youtube.oEmbed+s(n)+"?"+t.utils.querystring(t.utils.merge({modestbranding:1,autohide:1,showinfo:0},r,t.defaults.RESTRICTED));this.iframe(e,i,l,r,o)},t.prototype.vimeo=function(e,i,n,r,o){var s=t.utils.dimensions(i,r.width,r.height),l=t.utils.merge({url:n,width:s.width,height:s.height,autohide:1},r,t.defaults.RESTRICTED),u=t.defaults.SOURCES.vimeo.oEmbed+"?"+t.utils.querystring(l);t.utils.fetch(u,function(n,r){if(n)return t.log("error","vimeo",n),o(n);var l=t.utils.generateEmbed(e,"vimeo",r.html);i.appendChild(l),o(null,{id:e,el:i,width:s.width,height:s.height})})},t.prototype.pinterest=function(e,i,n,o,s){var l=t.utils.dimensions(i,o.width,o.height),u=l.width>600?"large":l.width<345?"small":"medium",d=t.utils.generateElement("a",t.utils.merge({href:n,"data-pin-do":o["data-pin-do"]||"embedPin","data-pin-lang":o["data-pin-lang"]||"en","data-pin-width":u},o)),h=t.utils.generateEmbed(e,"pinterest",d);i.appendChild(h),r(i,h,{id:e,url:n,strict:o.strict,width:l.width,height:l.height,centerize:o.centerize},function(n,r){if(n)return t.log("error","pinterest",n),s(n);s(null,{id:e,el:i,width:r.width,height:r.height})})},t.prototype.googlemaps=function(e,i,n,r,s){var l=t.utils.dimensions(i,r.width,r.height),u=function(t){var e=/@(-?\d+\.\d+),(-?\d+\.\d+),(\d+\.?\d?)+z/,i=t.match(e);return i&&i.length&&i[1]&&i[2]?{lat:parseFloat(i[1],0),lng:parseFloat(i[2],0)}:null}(n);if(!u)return s(new Error("unable_to_find_cordinates"));var d=t.utils.generateEmbed(e,"googlemaps");i.appendChild(d),o(i,d,{url:n,width:l.width,height:l.height,centerize:r.centerize},function(n){if(n)return t.log("error","googlemaps",n),s(n);var o=new window.google.maps.LatLng(u.lat,u.lng),h=new window.google.maps.Map(d,{zoom:r.zoom||12,center:o,mapTypeId:r.MapTypeId||window.google.maps.MapTypeId.ROADMAP}),a=new window.google.maps.Marker({map:h,draggable:!0,animation:window.google.maps.Animation.DROP,position:o});s(null,{id:e,el:i,width:l.width,height:l.height,marker:a})})},t.prototype.github=function(e,i,n,r,o){var s=t.utils.dimensions(i,r.width,r.height),l=t.utils.generateElement("iframe",t.utils.merge({width:s.width,height:s.height},r,t.defaults.RESTRICTED)),u=t.utils.generateEmbed(e,"github",l);i.appendChild(u),l.contentWindow.document.open(),l.contentWindow.document.write('<body><style type="text/css">body,html{margin:0;padding:0;border-radius:3px;}.gist .gist-file{margin:0 !important;padding:0;}</style><script src="'+n+'"><\/script></body>'),l.contentWindow.document.close(),l.onerror=function(t){o(t)},l.onload=function(){o(null,{id:e,el:i,width:t.utils.compute(u,"width"),height:t.utils.compute(u,"height")})}},t.prototype.iframe=function(e,i,n,r,o){var s=document.createDocumentFragment(),l=t.utils.dimensions(i,r.width,r.height),u=(n.substr(n.lastIndexOf("."))||"").replace(".","").toLowerCase(),d={csv:"text/csv",doc:"application/msword",docx:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",pdf:"application/pdf",gif:"image/gif",js:"application/javascript",json:"application/json",xhtml:"application/xhtml+xml",pps:"application/vnd.ms-powerpoint",ppsx:"application/vnd.openxmlformats-officedocument.presentationml.slideshow",xml:"application/xml",ogg:"video/ogg",mp4:"video/mp4",webm:"video/webm",html:"text/html"},h=d[u]||d.html,a=u.match(/(mp4|ogg|webm|ogv|ogm)/)?"video":r.tagName||"embed",c=t.utils.merge({},r,t.defaults.RESTRICTED),m=t.utils.generateElement(a,t.utils.merge({type:h,src:n,width:l.width,height:l.height},c));s.appendChild(t.utils.generateEmbed(e,"iframe",m)),i.appendChild(s),"video"===a?setTimeout(function(){o(null,{id:e,el:i,width:t.utils.compute(m,"width"),height:t.utils.compute(m,"height")})},250):(m.onerror=function(t){o(t)},m.onload=function(){o(null,{id:e,el:i,width:t.utils.compute(m,"width"),height:t.utils.compute(m,"height")})})},t.prototype.communicate=function(t){window.postMessage(["embedo","rendered",JSON.stringify(t)],"*")},t.prototype.render=function(e,i,n,r){if(t.log("info","render",e,i,n),n=n||{},r=r||function(){},!e||!t.utils.validateElement(e))return t.log("error","render","`element` is either missing or invalid"),this.emit("error",new Error("element_is_missing"));if("string"!=typeof i)return this.emit("error",new Error("invalid_url_string"));if(!i||!t.utils.validateURL(i))return t.log("error","render","`url` is either missing or invalid"),this.emit("error",new Error("invalid_or_missing_url"));var o=function(e){var i=/(http|https):\/\/(\w+:{0,1}\w*)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%!\-\/]))?/,n=Object.keys(t.defaults.SOURCES)||[];if(!i.test(e))return null;var r=n.filter(function(i){if(t.defaults.SOURCES[i]&&e.match(t.defaults.SOURCES[i].REGEX))return i}).filter(Boolean);return r&&r.length?r[0]:"iframe"}(i);if(!o)return t.log("error","render",new Error("Invalid or Unsupported URL")),this.emit("error",new Error("url_not_supported"));if(!this[o])return t.log("error","render",new Error("Requested source is not implemented or missing.")),this.emit("error",new Error("unrecognised_url"));"width"in n&&n.width&&(n.width=t.utils.convertToPx(e,"width",n.width)),"height"in n&&n.height&&(n.height=t.utils.convertToPx(e,"height",n.height));var s=t.utils.uuid(),l={id:s,el:e,source:o,url:i,attributes:n};this.requests.push(l),this.emit("watch","load",l),this[o](s,e,i,n,function(t,e){if(t)return this.emit("error",t),r(t);e.url=l.url,e.source=l.source,e.options=l.attributes,this.communicate(e),this.emit("watch","loaded",e),r(null,e)}.bind(this))},t.prototype.load=function(e,i,n){t.log("info","load",e,i,n),n=n||{};var r=new t.utils.observer;if(e&&t.utils.validateElement(e))if(i instanceof Array){var o={failed:[],finished:[]},s=i.map(function(t){return function(i){this.render(e,t,n,function(t,e){if(t)return o.failed.push(t),i(t);o.finished.push(e),i(null,e)})}.bind(this)}.bind(this));t.utils.sequencer.apply(this,s).then(function(){if(o.failed.length>0)return r.reject(o.failed);r.resolve(o.finished)})}else"string"==typeof i?this.render(e,i,n,function(t,e){if(t)return r.reject(t);r.resolve(e)}):this.emit("error",new Error("invalid_url_string"));else t.log("error","load","`element` is either missing or invalid"),this.emit("error",new Error("element_is_missing"));return r},t.prototype.refresh=function(e){if(t.log("info","refresh",this.requests,e),0!==this.requests.length)return this.requests.forEach(function(i){if(i.el){if("iframe"===i.source||"googlemaps"===i.source)return this.emit("refresh",i,{width:t.utils.compute(i.el,"width"),height:t.utils.compute(i.el,"height")});if(e){if(!t.utils.validateElement(e))return;e===i.el&&s(i.el,document.getElementById(i.id),i.attributes,function(t,e){e&&this.emit("refresh",i,e)}.bind(this))}else s(i.el,document.getElementById(i.id),i.attributes,function(t,e){e&&this.emit("refresh",i,e)}.bind(this))}}.bind(this)),this},t.prototype.destroy=function(e){if(t.log("warn","destroy",this.requests,e),0!==this.requests.length){var i=[];return this.requests.forEach(function(n){if(n.el&&t.utils.validateElement(n.el))if(e){if(!t.utils.validateElement(e))return;e===n.el&&(document.getElementById(n.id)&&document.getElementById(n.id).remove(),i.push(n.id),this.emit("destroy",n))}else document.getElementById(n.id)&&document.getElementById(n.id).remove(),i.push(n.id),this.emit("destroy",n)}.bind(this)),this.requests=this.requests.filter(function(t){return i.indexOf(t.id)<0}),this}},t});