UNPKG

@gravatar-com/quick-editor

Version:

A lightweight library to provide seamless Gravatar profile management for third-party sites

2 lines 3.3 kB
(()=>{var e={d:(t,o)=>{for(var r in o)e.o(o,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:o[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};(()=>{"use strict";e.r(t),e.d(t,{GravatarQuickEditor:()=>n,GravatarQuickEditorCore:()=>r});var o=["about","avatars","verified-accounts","links","interests","contact-info","wallet","photos","design","privacy"],r=function(){function e(e){var t=this,r=e.email,n=e.scope,a=void 0===n?[]:n,i=e.locale,s=e.onProfileUpdated,d=e.onOpened,c=e.onClosed,l=e.utm;this._window=null,this.open=function(e){if(!(e=e||t._email))return console.error("Gravatar Quick Editor: Email not provided"),!1;e=encodeURIComponent(e);var o=encodeURIComponent(t._scope.join(",")),r=window.screenLeft+(window.outerWidth-400)/2,n="popup,width=400,height=720,top="+(window.screenTop+(window.outerHeight-720)/2)+",left="+r,a=(t._locale?"https://"+t._locale+".gravatar.com":"https://gravatar.com")+"/profile?email="+e+"&scope="+o+"&is_quick_editor=true"+(t._utm?"&utm="+encodeURIComponent(t._utm):"");if(t._window=window.open(a,t._name,n),null===t._window)return console.error("Gravatar Quick Editor: Could not open window"),!1;if(t._onOpened&&t._onOpened(),t._onClosed)var i=setInterval((function(){t._window.closed&&(clearInterval(i),t._onClosed())}),500);return!0},this.close=function(){t._window&&t._window.close()},this.isOpen=function(){return null!==t._window&&!t._window.closed},this._name=this._getName(),this._email=r,this._scope=a,this._locale=i,this._onProfileUpdated=s,this._onOpened=d,this._onClosed=c,this._utm=l,this._scope.every((function(e){return o.includes(e)}))||(console.error("Gravatar Quick Editor: Invalid scope definition. Available scope: "+o.join(", ")),this._scope=this._scope.filter((function(e){return o.includes(e)}))),window.addEventListener("message",this._onMessage.bind(this))}var t=e.prototype;return t._getName=function(){return"GravatarQuickEditor_"+(new Date).getTime()+Math.floor(8999*Math.random()+1e3)},t._onMessage=function(e){var t;this._onProfileUpdated&&e.origin.match(/https:\/\/([a-z\-]{2,5}\.)?gravatar.com/)&&(null==(t=e.data)?void 0:t.name)===this._name&&this._onProfileUpdated(e.data.type)},e}(),n=function(){function e(e){var t=e.email,o=e.editorTriggerSelector,n=e.avatarSelector,a=e.scope,i=e.locale,s=e.avatarRefreshDelay;this._avatarList=document.querySelectorAll(n),this._avatarRefreshDelay=s||1e3;var d=document.querySelector(o),c=new r({email:t,scope:a,locale:i,onProfileUpdated:this._onProfileUpdated.bind(this)});null==d||d.addEventListener("click",(function(){return c.open()}))}return e.prototype._onProfileUpdated=function(e){var t=this;"avatar_updated"===e&&0!==this._avatarList.length&&this._avatarList.forEach((function(e){if(URL.canParse(e.src)&&e.src.includes("gravatar.com/avatar")){var o=new URL(e.src);o.searchParams.set("t",(new Date).getTime().toString()),setTimeout((function(){e.src=o.toString()}),t._avatarRefreshDelay)}}))},e}()})();var o=Gravatar="undefined"==typeof Gravatar?{}:Gravatar;for(var r in t)o[r]=t[r];t.__esModule&&Object.defineProperty(o,"__esModule",{value:!0})})(); //# sourceMappingURL=index.umd.js.map