npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@gravatar-com/quick-editor

v0.6.0

Published

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

Downloads

299

Readme

Gravatar Quick Editor

Gravatar Quick Editor is a JavaScript library that allows users to integrate the Gravatar Quick Editor into their web applications, enabling easy editing of Gravatar profiles via a popup window. The library provides both a core class for advanced control and a simplified class for quick setup.

Features

  • Simple integration with your web application.
  • Core functionality for advanced usage.
  • Simplified setup for quick integration.
  • Supports real-time updates to avatar images using the PostMessage API.
  • TypeScript support for type completion and validation.

Installation

Install with NPM or Yarn

Install the package using npm or yarn:

npm install @gravatar-com/quick-editor
yarn add @gravatar-com/quick-editor

Install with UNPKG

Import the library as shown below:

<!-- Import the library -->
<script src="https://unpkg.com/@gravatar-com/[email protected]" defer></script>

<script>
  // The library is accessible as a global variable
  console.log( Gravatar );
</script>

Replace x.x.x with the latest version number. Please refer to UNPKG's documentation for more information.

Usage

GravatarQuickEditor

The GravatarQuickEditor class simplifies the setup process by automatically setting up event handlers to open the popup and update avatar elements on the page.

Example

import { GravatarQuickEditor } from '@gravatar-com/quick-editor';

document.addEventListener( 'DOMContentLoaded', () => {
  new GravatarQuickEditor( {
    email: '[email protected]',
    editorTriggerSelector: '#edit-profile',
    avatarSelector: '#gravatar-avatar',
    scope: [ 'avatars' ],
  } );
} );

GravatarQuickEditorCore

The GravatarQuickEditorCore class provides advanced control over the Gravatar Quick Editor functionality, allowing developers to trigger popup events and set up profile update callbacks.

Core Example

import { GravatarQuickEditorCore } from '@gravatar-com/quick-editor';

document.addEventListener( 'DOMContentLoaded', () => {
  const quickEditorCore = new GravatarQuickEditorCore( {
    email: '[email protected]',
    scope: [ 'avatars', 'about' ],
    onProfileUpdated: () => {
      console.log( 'Profile updated!' );
    },
    onOpened: () => {
      console.log( 'Editor opened!' );
    },
  } );

  document.getElementById( 'edit-profile' ).addEventListener( 'click', () => {
    quickEditorCore.open();
  } );
} );

API

GravatarQuickEditor API

new GravatarQuickEditor(options: QuickEditorOptions);

QuickEditorOptions Type

type QuickEditorOptions = {
  email: string;
  editorTriggerSelector: string;
  avatarSelector?: string;
  scope?: Scope;
  locale?: string;
  avatarRefreshDelay?: number;
};
  • email: string: The email address associated with the Gravatar profile. This is used to identify the profile to be edited.

  • editorTriggerSelector: string: A CSS selector for the HTML element (e.g., button) that triggers the opening of the Gravatar Quick Editor popup.

  • avatarSelector: string: A CSS selector for the HTML image element(s) that displays the Gravatar avatar. When the avatar is updated, the image(s) will be refreshed automatically.

  • scope: Scope: An array specifying what sections of the profile can be edited in the popup. Check the list of valid scope values

  • locale: string: The locale setting for the Gravatar editor interface. This can be used to set the language for the editor UI.

  • avatarRefreshDelay: number: The delay in milliseconds before the avatar image is refreshed after an update. This can help ensure any cache can be busted before the new image is displayed.

While updating the avatar image, to bypass the browser's cache, the Quick Editor will add a t parameter with the current timestamp to the avatar URL.

GravatarQuickEditorCore API

new GravatarQuickEditorCore(options: QuickEditorCoreOptions);

QuickEditorCoreOptions Type

type QuickEditorCoreOptions = Partial< {
  email: string;
  scope: Scope;
  locale: string;
  onProfileUpdated: OnProfileUpdated;
  onOpened: OnOpened;
} >;
  • email: string: The email address associated with the Gravatar profile. This is used to identify the profile to be edited.

  • scope: Scope: An array specifying what sections of the profile can be edited in the popup. Check the list of valid scope values

  • locale: string: The locale setting for the Gravatar editor interface. This can be used to set the language for the editor UI.

  • onProfileUpdated: ( type: ProfileUpdatedType ) => void: A callback function that gets called when the profile is updated. This can be used to trigger additional actions in your application when the user saves changes to their profile. It will receive a parameter of type ProfileUpdatedType which can have one of the values: 'avatar_updated' | 'profile_updated'

  • onOpened: () => void: A callback function that gets called when the editor popup is opened. This can be used for logging, analytics, or other actions when the popup is triggered.

Public functions

  • open: ( email?: string ) => void: A function for triggering the Gravatar Quick Editor popup. It can receive an email address to identify the profile to be edited.

Valid Scope Values

  • about
  • avatars
  • verified-accounts
  • links
  • interests
  • contact-info
  • wallet
  • photos
  • design
  • privacy

Contribute to Gravatar Quick Editor

We welcome contributions to this project. Please follow the guidelines outlined in the CONTRIBUTING.md file.

License

Gravatar Hovercards is licensed under GNU General Public License v2 (or later).